File: i386sp.S

package info (click to toggle)
spectemu 0.94a-11
  • links: PTS
  • area: contrib
  • in suites: squeeze
  • size: 1,456 kB
  • ctags: 3,161
  • sloc: ansic: 15,419; asm: 5,160; sh: 2,942; cpp: 377; makefile: 190
file content (624 lines) | stat: -rw-r--r-- 10,494 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
/* 
 * Copyright (C) 1996-1998 Szeredi Miklos
 * Email: mszeredi@inf.bme.hu
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version. See the file COPYING. 
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

/* -*- asm -*- */

#ifndef COMPARISON	
#define SPT(s) NAME(sp_ ## s)
#else 
#define SPT(s) NAME(spx_ ## s)
#endif

#define LOAD_DI 0x0559

#define OS 80

#define EARBIT 0x40

#define NEXT_SCRI    DAT(OS,0)
#define INPORT_MASK  DAT(OS,4)
#define ULA_INPORT   DAT(OS,8)
#define ULA_OUTPORT  DAT(OS,12)
#define SOUND_SAM    DAT(OS,16)
#define SOUND_CHANGE DAT(OS,20)
#define IMP_CHANGE   DAT(OS,24)
	
#define JROM(addr, label) \
	testw $0xC000, addr	; \
	jz label

#define JNROM(addr, label) \
	testw $0xC000, addr	; \
	jnz label

#define JSCR(addr, label) \
	cmpw $0x5B00, addr	; \
	jb label
	
#define JNSCR(addr, label) \
	cmpw $0x5B00, addr	; \
	jnb label

	
#define JROMB(addr, label) \
	testb $0xC0, addr	; \
	jz label

#define JNROMB(addr, label) \
	testb $0xC0, addr	; \
	jnz label

#define JSCRB(addr, label) \
	cmpb $0x5B, addr	; \
	jb label
	
#define JNSCRB(addr, label) \
	cmpb $0x5B, addr	; \
	jnb label

	
#define MARK_SCR(addr) \
	xchgw RAF, addr	; \
	btsl SCRP, SPT(scr_mark)	; \
	xchgw RAF, addr

#define MARK_SCR_VWP(addr) \
	movzwl addr, VWP	; \
	btsl VWP, SPT(scr_mark)

#define MEM_DELAY(l) \
	cmpl $0, NEXT_SCRI	; \
	jl l			; \
	cmpl $86, TC		; \
	jle l			; \
	subl $2, TC

	
#define PUTMEM_REG(l, reg, regh, regp, val, endf) \
	JSCRB(regh, l ## _scr)	; \
	movb val, (regp)	; \
	endf			; \
l ## _scr:			; \
	JROMB(regh, l ## _rom)	; \
	movb val, (regp)	; \
	MARK_SCR_VWP(reg)	; \
	MEM_DELAY(l ## _rom)	; \
	endf			; \
l ## _rom:			; \
	endf

	
#define PUTMEM_REG_NE(l, reg, regh, regp, val) \
	JROMB(regh, l ## _mid)	; \
	movb val, (regp)	; \
	JNSCRB(regh, l ## _mid)	; \
	MARK_SCR(reg)		; \
	MEM_DELAY(l ## _mid)	; \
l ## _mid:


	
#define PUTMEM_DREG_NE(l, reg, regp, val) \
	JROM(reg, l ## _mid)	; \
	movb val, (regp)	; \
	JNSCR(reg, l ## _mid)	; \
	MARK_SCR(reg)		; \
	MEM_DELAY(l ## _mid)	; \
l ## _mid:
	
		
#define MODMEMF(l, func, endf) \
	JSCRB(RH, l ## _scr)	; \
	func((HLP))		; \
	endf			; \
l ## _scr:			; \
	JROMB(RH, l ## _rom)	; \
	func((HLP))		; \
	MARK_SCR_VWP(RHL)	; \
	MEM_DELAY(l ## _rend)	; \
	endf			; \
l ## _rom:			; \
	movb (HLP), RW		; \
	func(RW)		; \
l ## _rend:			; \
	endf

	
#define PUSH_CMPX(l, rh, rl) \
	decw RSP		; \
	PUTMEM_DREG_NE(l ## 1, RSP, SPP, rh); \
	decw RSP		; \
	PUTMEM_DREG_NE(l ## 2, RSP, SPP, rl)

	
#define PUSHT(l, rh, rl, t) \
	cmpw $0x5B01, RSP	; \
	jb l ## _cmpx		; \
	decw RSP		; \
	movb rh, (SPP)		; \
	decw RSP		; \
	movb rl, (SPP)		; \
	TIME(t)			; \
l ## _cmpx:			; \
	PUSH_CMPX(l, rh, rl)	; \
	TIME(t)			; \
	
#define PUSH(l, rh, rl) \
	cmpw $0x5B01, RSP	; \
	jb l ## _cmpx		; \
	decw RSP		; \
	movb rh, (SPP)		; \
	decw RSP		; \
	movb rl, (SPP)		; \
	jmp l ## _end		; \
	ALIGN			; \
l ## _cmpx:			; \
	PUSH_CMPX(l, rh, rl)	; \
l ## _end:	


#define TICKPERLINE 224
#define SOUNDPORT 0x10
	
#define IN(l, porth, portl, rd) \
	movl INPORT_MASK, VWP	; \
	testb RW, portl		; \
	jz l ## _in_active	; \
	testb $1, portl		; \
	jnz l ## _in_ulabus	; \
	cmpl TC,IMP_CHANGE	; \
	jg l ## _in_imp		; \
	movzbl porth, VWP	; \
	movb SPT(fe_inport_high)(VWP), rd; \
	andb ULA_INPORT, rd	; \
	decl TC			; \
	jmp l ## _in_end	; \
	ALIGN			; \
l ## _in_imp:			; \
	movl $0,IMP_CHANGE	; \
	xorb $EARBIT,ULA_INPORT	; \
	movzbl porth, VWP	; \
	movb SPT(fe_inport_high)(VWP), rd; \
	andb ULA_INPORT, rd	; \
	decl TC			; \
	jmp l ## _in_end	; \
	ALIGN			; \
l ## _in_active:		; \
	movzbl portl, VWP	; \
	movb Z80(inports)(VWP), rd; \
	jmp l ## _in_end	; \
	ALIGN			; \
l ## _in_ulabus:		; \
	movl PCP, VWP		; \
	movw NEXT_SCRI, RVW	; \
	cmpw $0, RVW		; \
	jl l ## _in_ulaidle	; \
	cmpl $96, TC		; \
	jle l ## _in_ulaidle	; \
	pushl TC		; \
	shrw $2, %di		; \
	shlw $5, RVW		; \
	addw $56, RVW		; \
	subw %di, RVW		; \
	popl TC			; \
	movb (VWP), rd		; \
	jmp l ## _in_end	; \
l ## _in_ulaidle:		; \
	movb $0xFF, rd		; \
	jmp l ## _in_end	; \
	ALIGN			; \
l ## _in_end:	
	
#define OUT(l, porth, portl, rs) \
	testb $1, portl		; \
	jnz l ## _out_nonfe	; \
	movb rs, RV		; \
	xorb ULA_OUTPORT, RV	; \
	decl TC			; \
	movb rs, ULA_OUTPORT	; \
	testb $SOUNDPORT, RV	; \
	jz l ## _out_end	; \
	movl $1, SOUND_CHANGE	; \
	testb $SOUNDPORT, rs	; \
	jz l ## _out_s_0	; \
	addl TC, SOUND_SAM	; \
	jmp l ## _out_end	; \
	ALIGN			; \
l ## _out_s_0:			; \
	subl TC, SOUND_SAM	; \
	jmp l ## _out_end	; \
	ALIGN			; \
l ## _out_nonfe:		; \
	movzbl portl, VWP	; \
	movb rs, Z80(outports)(VWP); \
l ## _out_end:	

#define DI_CHECK \
	cmpw $LOAD_DI+1, RPC	; \
	je load_point		; \
di_check_end:	

load_point:
	cmpl $0, SPT(quick_load)
	je di_check_end
	movl $1, SPT(load_trapped)
	movl $1, HALTSTATE
	movl $0, TC
	jmp loop_end
	
#define SCLINE %ebx

#define INC_SCLINE \
	incl SCLINE		; \
	andl $0x03FF, SCLINE	; \
	movl SCLINE, SPT(scline)

#define SCRPTR %edi

#define SPM %ecx
#define SPM0 %cl
#define SPM1 %ch

#define SPC %ebx
#define SPC0 %bl
#define SPC1 %bh

#define SPMP %esi
#define SPCP %ebp
	
#define SPI %edx
#define SPIW %dx
#define SPI0 %dl
#define SPI1 %dh

#define SCRI %ebx
	
#define COLI %edx
#define COLI0 %dl
		

#define TRANS_SCR \
	movl (SPI),%eax		; \
	stosl

	
#define SCR_8_PIXELS(spcx, spmx, aa) \
	movb spcx,SPI1		; \
	aa			; \
	movb spmx,SPI0		; \
	shrb $2,SPI0		; \
	andb $0x3C,SPI0		; \
	TRANS_SCR		; \
	movb spmx,SPI0		; \
	shlb $2,SPI0		; \
	andb $0x3C,SPI0		; \
	TRANS_SCR

#define SHRLSPC shrl $16, SPC

#define SCR_32_PIXELS \
	movl (SPMP),SPM		; \
	movl (SPCP),SPC		; \
	SCR_8_PIXELS(SPC0, SPM0, ); \
	addl $4, SPMP		; \
	SCR_8_PIXELS(SPC1, SPM1, SHRLSPC); \
	shrl $16, SPM		; \
	SCR_8_PIXELS(SPC0, SPM0, ); \
	addl $4, SPCP		; \
	SCR_8_PIXELS(SPC1, SPM1, ); \

	
#define GET_BORDER \
	movb SPT(colors)(,%ecx,1), %cl; \
	movb %cl, %ch		; \
	movw %cx, %ax		; \
	shll $16, %eax		; \
	movw %cx, %ax

	ALIGN
.globl SPT(halfframe)
/*	.type	 SPT(halfframe),@function */
SPT(halfframe):
	movl 8(%esp), %eax
	movl %eax, linesleft
	movl 4(%esp), %eax

	pushl %ebp
	pushl %edi
	pushl %esi
	pushl %ebx
	pushl %es

	cld
	
	movl %eax, TC
	movl SPT(image), %eax
	movl %eax, scrptr

#ifndef USE_DJGPP
	movw %ds, %ax
#else
	movw NAME(djsp_video_segment), %ax
#endif
	movw %ax, %es
	
	call load_regs
new_loop:	
	movl SPT(scline), %eax
	movl SPT(scri)(,%eax,4), %eax
	movl %eax, NEXT_SCRI
	
	call step_loop
	
	pushl SCLINE
	movl SPT(scline), SCLINE
	
/* store sound */
	movb SOUND_SAM, %al
	movb %al, SPT(sound_buf)(SCLINE)

	movb ULA_OUTPORT, %al
	testb $SOUNDPORT, %al
	jz sound_0
	movb $240, SOUND_SAM
	jmp sound_end
	ALIGN
sound_0:
	movb $16, SOUND_SAM
sound_end:

/* change EAR bit, store MIC bit*/

	movb %al, SPT(fe_outport_time)(SCLINE)

	cmpl $0,IMP_CHANGE
	je no_imp_change
	xorb $EARBIT, ULA_INPORT
	
no_imp_change:
	movzbl SPT(tape_impinfo)(SCLINE), %eax
	movl %eax, IMP_CHANGE

/* Check if updating screen */
	
	cmpl $0, SPT(updating)
	jz not_to_update

	movl NEXT_SCRI, %eax
	cmpl $-1, %eax
	jl not_to_update
	je only_border

scr_update:	
	pushl %ecx
	pushl %edx
	pushl %edi

	movl SPT(coli)(,SCLINE, 4), COLI
	INC_SCLINE

	movl %eax, SCRI

	movl scrptr, SCRPTR
	movl SCRPTR, %eax
	addl $320, %eax
	movl %eax, scrptr

	movzbl ULA_OUTPORT, %ecx
	andb $0x07, %cl
	cmpb %cl, SPT(lastborder)
	jne sbrd_change
	cmpl $0, SPT(border_update)
	jne sbrd_update

	addl $0x20, SCRPTR
sbrd_no_update:
	movl COLI, %eax
	shrl $3, %eax
		
	testb $0x07, COLI0
	jz clear_cm

	movl SPT(scr_mark)+(0x2C0*4)(,%eax,4), %ecx

no_clear_cm:	
	xorl %eax, %eax
	xchgl SPT(scr_mark)(,SCRI,4), %eax

	orl %eax, %ecx
	jz skip_update

	orl %ecx, SPT(imag_mark)(,COLI,4)
	orl %ecx, SPT(imag_horiz)

	shrl $3, COLI
	btsl COLI, SPT(imag_vert)
	
/* update screen line */
	
	pushl %esi
	pushl %ebp

/* %esi is PCP and SPMP ! */
	xorw %si, %si
	movl %esi, %eax
	
	shll $5, SCRI
	shll $5, COLI

	addl SCRI, SPMP
	leal 0x5800(%eax, COLI), SPCP
				
/* Draw pixels */
	movl  $0xF, %ebx
	pushl %ecx
	subl $4, %esp

	cmpl $0, SPT(flash_state)
	jnz scr_f1
	movl SPT(scr_f0_table), SPI
	jmp scr_32_pixels
	ALIGN

scr_f1:
	movl SPT(scr_f1_table), SPI
	jmp scr_32_pixels
	ALIGN

scr_32_pixels:
	testl %ebx, %ecx
	jz skip_32_pixels
	movl %ebx, (%esp)
	SCR_32_PIXELS
	movl (%esp), %ebx
	shll $4, %ebx
	jz end_screen_line
	movl 4(%esp), %ecx
	jmp scr_32_pixels
	ALIGN
	
skip_32_pixels:
	addl $4, SPMP
	addl $4, SPCP
	addl $32, SCRPTR
	shll $4, %ebx
	jz end_screen_line
	jmp scr_32_pixels
	ALIGN

end_screen_line:
	addl $8, %esp
	
	popl %ebp
	popl %esi

skip_update:	
	
	popl %edi
	popl %edx
	popl %ecx
	
	jmp update_end
		
	ALIGN		


sbrd_change:	
	movl $2, SPT(border_update)
	xchgb %cl, SPT(lastborder)
sbrd_update:	
	GET_BORDER
	
/* Draw border */
	xorl %ecx, %ecx
	movb $8, %cl
	rep
	stosl
	addl $0x100, SCRPTR
	movb $8, %cl
	rep
	stosl
	subl $0x120, SCRPTR
	jmp sbrd_no_update

	ALIGN
	
clear_cm:
	xorl %ecx, %ecx
	xchgl SPT(scr_mark)+(0x2C0*4)(,%eax,4), %ecx
	testl %ecx, %ecx
	jz no_clear_cm

	leal SPT(scr_mark)(,SCRI,4), %eax
	
	orl %ecx, (%eax)
	orl %ecx, 0x20(%eax)
	orl %ecx, 0x40(%eax)
	orl %ecx, 0x60(%eax)
	addl $0x80, %eax
	orl %ecx, (%eax)
	orl %ecx, 0x20(%eax)
	orl %ecx, 0x40(%eax)
	orl %ecx, 0x60(%eax)

	jmp no_clear_cm
	ALIGN

	
only_border:
	INC_SCLINE
	
	pushl %edi
	movl %ecx, %ebx

	movzbl ULA_OUTPORT, %ecx
	andb $0x07, %cl
	cmpb %cl, SPT(lastborder)
	je brd_no_change
	movl $2, SPT(border_update)
	xchgb %cl, SPT(lastborder)
brd_no_change:
	cmpl $0, SPT(border_update)
	je brd_no_update
	
	GET_BORDER
	
	movl scrptr, SCRPTR
	movl $80, %ecx
	rep
	stosl

brd_no_update:	
	addl $320, scrptr
	
	movl %ebx, %ecx
	popl %edi
	jmp update_end

	ALIGN
not_to_update:		
	INC_SCLINE

update_end:			
	popl SCLINE
	decl linesleft
	jz chunk_end
	addl $TICKPERLINE, TC
	jmp new_loop
	ALIGN

chunk_end:
	call store_regs
	movl TC, %eax

	popl %es
	popl %ebx
	popl %esi
	popl %edi
	popl %ebp
	ret
	ALIGN
	
	.data
linesleft:
	.long 0
scrptr:
	.long 0
	.text