forked from NEO-SPECTRUMAN/SpecEmu
-
Notifications
You must be signed in to change notification settings - Fork 3
/
TimexRenderer.asm
503 lines (412 loc) · 18.6 KB
/
TimexRenderer.asm
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
ASSUME ESI: PTR SpectrumGfx
NEXTSCANLINEADDR macro
mov edi, [esi].TargetScanlineAddr
add edi, DIBWidth
mov [esi].TargetScanlineAddr, edi
endm
TimexPrepTopBorder:
mov [esi].ScreenVector, OFFSET TC_DrawTopBorder
mov [esi].UDCnt, 40
Align 16
TC_DrawTopBorder:
mov eax, [esi].TimexBorderColour
TC_DrawTopBorder_1:
add [esi].WaitTState, 4
cmp eax, [edi]
jne TC_DTB_Changed
cmp eax, [edi+4]
jne TC_DTB_Changed
cmp eax, [edi+8]
jne TC_DTB_Changed
cmp eax, [edi+12]
jne TC_DTB_Changed
add edi, 16
dec [esi].UDCnt
jz TC_NextTopBorderLine
cmp ebx, [esi].WaitTState
jnc TC_DrawTopBorder_1
ret
TC_DTB_Changed:
mov [esi].ScreenVector, OFFSET TC_DrawTopBorder_Write
mov byte ptr [ebp], 1
mov [esi].FrameChanged, TRUE
jmp TC_DTB_Write
Align 16
TC_DrawTopBorder_Write:
mov eax, [esi].TimexBorderColour
TC_DrawTopBorder_2:
add [esi].WaitTState, 4
TC_DTB_Write:
mov [edi], eax ; write 16 border bytes
mov [edi+4], eax
mov [edi+8], eax
mov [edi+12], eax
add edi, 16
dec [esi].UDCnt
jz TC_NextTopBorderLine
cmp ebx, [esi].WaitTState
jnc TC_DrawTopBorder_2
ret
Align 4
TC_NextTopBorderLine:
NEXTSCANLINEADDR
mov eax, [esi].ScanTState
add eax, MACHINE.ScanlineCycles
mov [esi].ScanTState, eax
mov [esi].WaitTState, eax
add ebp, 3
dec [esi].TopBorderCnt
jz TC_PrepLeftBorder ; top border finished
mov [esi].ScreenVector, OFFSET TimexPrepTopBorder
ret
; start actual screen area
Align 4
TC_PrepLeftBorder:
mov [esi].ScreenVector, OFFSET TC_DrawLeftBorder
mov [esi].UDCnt, 4
ret
Align 16
TC_DrawLeftBorder:
mov eax, [esi].TimexBorderColour
TC_DrawLeftBorder_1:
add [esi].WaitTState, 4
.if (eax != [edi]) || (eax != [edi+4]) || (eax != [edi+8]) || (eax != [edi+12])
mov [edi], eax ; write 16 border bytes
mov [edi+4], eax
mov [edi+8], eax
mov [edi+12], eax
mov byte ptr [ebp], 1
mov [esi].FrameChanged, TRUE
.endif
add edi, 16
dec [esi].UDCnt
jz TC_PrepDisplayLine
cmp ebx, [esi].WaitTState
jnc TC_DrawLeftBorder_1
ret
Align 4
TC_PrepDisplayLine:
inc ebp
sub [esi].WaitTState, 4
mov [esi].UDCnt, 16
mov [esi].FetchCycle, 0
mov [esi].ScreenVector, OFFSET TC_DrawDisplayLine
; prepare display/attr offsets for this scanline
mov eax, [DisplayTablePtr]
mov ecx, [eax]
mov eax, [eax+4]
add [DisplayTablePtr], 8
mov [esi].DisplayOffset, ecx
mov [esi].AttrOffset, eax
ret
FETCHVIDEOMEM macro
.if [esi].DoSnow == TRUE
and eax, 0FFFFFF80h
mov cl, z80registers.r
and cl, 7Fh
or al, cl
.endif
add eax, [esi].zxDisplayOrg
mov al, [eax]
endm
Align 16
TC_DrawDisplayLine:
switch [esi].FetchCycle
add [esi].FetchCycle, 1
add [esi].WaitTState, 1
FETCHCYCLEOFFSET = 2
FETCHCYCLEOFFSET = FETCHCYCLEOFFSET - 1 ; safe to assume that the ULA address bus is loaded one cycle before sampling the data bus?
case FETCHCYCLEOFFSET
switch Timex_Screen_Mode
case 1
; screen 1
mov eax, [esi].DisplayOffset
add eax, 2000h
FETCHVIDEOMEM
mov [esi].DisplayByte, al
.else
; screen 0
mov eax, [esi].DisplayOffset
FETCHVIDEOMEM
mov [esi].DisplayByte, al
endsw
case FETCHCYCLEOFFSET+1
switch Timex_Screen_Mode
case 1
; screen 1
mov eax, [esi].AttrOffset
add eax, 2000h
FETCHVIDEOMEM
mov [esi].AttrByte, al
call Render_Timex_Character
case 2
; hi-colour
mov eax, [esi].DisplayOffset
add eax, 2000h
FETCHVIDEOMEM
mov [esi].AttrByte, al
call Render_Timex_Character
case 6
; hi-res
mov eax, [esi].DisplayOffset
add eax, 2000h
FETCHVIDEOMEM
mov [esi].AttrByte, al
call Render_Timex_Character
.else
; screen 0
mov eax, [esi].AttrOffset
FETCHVIDEOMEM
mov [esi].AttrByte, al
call Render_Timex_Character
endsw
case FETCHCYCLEOFFSET+2
switch Timex_Screen_Mode
case 1
; screen 1
mov eax, [esi].DisplayOffset
add eax, 2000h
FETCHVIDEOMEM
mov [esi].DisplayByte, al
.else
; screen 0
mov eax, [esi].DisplayOffset
FETCHVIDEOMEM
mov [esi].DisplayByte, al
endsw
case FETCHCYCLEOFFSET+3
switch Timex_Screen_Mode
case 1
; screen 1
mov eax, [esi].AttrOffset
add eax, 2000h
FETCHVIDEOMEM
mov [esi].AttrByte, al
call Render_Timex_Character
case 2
; hi-colour
mov eax, [esi].DisplayOffset
add eax, 2000h
FETCHVIDEOMEM
mov [esi].AttrByte, al
call Render_Timex_Character
case 6
; hi-res
mov eax, [esi].DisplayOffset
add eax, 2000h
FETCHVIDEOMEM
mov [esi].AttrByte, al
call Render_Timex_Character
.else
; screen 0
mov eax, [esi].AttrOffset
FETCHVIDEOMEM
mov [esi].AttrByte, al
call Render_Timex_Character
endsw
case 7
mov [esi].FetchCycle, 0
dec [esi].UDCnt
jz TC_PrepRightBorder
endsw
cmp ebx, [esi].WaitTState
jnc TC_DrawDisplayLine
ret
Align 4
TC_PrepRightBorder:
inc ebp
add [esi].WaitTState, 4
mov [esi].ScreenVector, OFFSET TC_DrawRightBorder
mov [esi].UDCnt, 4
ret
Align 16
TC_DrawRightBorder:
mov eax, [esi].TimexBorderColour
TC_DrawRightBorder_1:
add [esi].WaitTState, 4
.if (eax != [edi]) || (eax != [edi+4]) || (eax != [edi+8]) || (eax != [edi+12])
mov [edi], eax ; write 16 border bytes
mov [edi+4], eax
mov [edi+8], eax
mov [edi+12], eax
mov byte ptr [ebp], 1
mov [esi].FrameChanged, TRUE
.endif
add edi, 16
dec [esi].UDCnt
jz TC_PrepNextDisplayLine
cmp ebx, [esi].WaitTState
jnc TC_DrawRightBorder_1
ret
Align 4
TC_PrepNextDisplayLine:
NEXTSCANLINEADDR
inc [esi].CurrDisplayLine
inc ebp
mov edx, [esi].ScanTState
add edx, MACHINE.ScanlineCycles
mov [esi].ScanTState, edx
mov [esi].WaitTState, edx
cmp [esi].CurrDisplayLine, 192
jnc TC_PrepBottomBorder
mov [esi].ScreenVector, OFFSET TC_PrepLeftBorder
ret
Align 4
TC_PrepBottomBorder:
mov [esi].ScreenVector, OFFSET TC_DrawBottomBorder
mov [esi].UDCnt, 40
ret
Align 16
TC_DrawBottomBorder:
mov eax, [esi].TimexBorderColour
TC_DrawBottomBorder_1:
add [esi].WaitTState, 4
cmp eax, [edi]
jne TC_DBB_Changed
cmp eax, [edi+4]
jne TC_DBB_Changed
cmp eax, [edi+8]
jne TC_DBB_Changed
cmp eax, [edi+12]
jne TC_DBB_Changed
add edi, 16
dec [esi].UDCnt
jz TC_NextBottomBorderLine
cmp ebx, [esi].WaitTState
jnc TC_DrawBottomBorder_1
ret
TC_DBB_Changed:
mov [esi].ScreenVector, OFFSET TC_DrawBottomBorder_Write
mov byte ptr [ebp], 1
mov [esi].FrameChanged, TRUE
jmp TC_DBB_Write
Align 16
TC_DrawBottomBorder_Write:
mov eax, [esi].TimexBorderColour
TC_DrawBottomBorder_2:
add [esi].WaitTState, 4
TC_DBB_Write:
mov [edi], eax ; write 16 border bytes
mov [edi+4], eax
mov [edi+8], eax
mov [edi+12], eax
add edi, 16
dec [esi].UDCnt
jz TC_NextBottomBorderLine
cmp ebx, [esi].WaitTState
jnc TC_DrawBottomBorder_2
ret
Align 4
TC_NextBottomBorderLine:
NEXTSCANLINEADDR
mov eax, [esi].ScanTState
add eax, MACHINE.ScanlineCycles
mov [esi].ScanTState, eax
mov [esi].WaitTState, eax
add ebp, 3
dec [esi].BottomBorderCnt
jz TC_VerticalRetrace ; bottom border finished
mov [esi].ScreenVector, OFFSET TC_PrepBottomBorder
ret
Align 4
TC_VerticalRetrace:
mov [esi].ScreenVector, OFFSET UScrExit
mov [esi].WaitTState, 180000
ret
Render_Timex_Character:
mov al, Timex_Screen_Mode
cmp al, 6
je Render_Timex_HiRes
.if [esi].ULA64_Active == TRUE
; temp fix for ULA+ colour cycling
or byte ptr [ebp], 1 + 128 ; set to use ULA+ palette in 'ColourDump' proc
mov [esi].FrameChanged, TRUE
; end temp fix for ULA+ colour cycling
movzx eax, [esi].AttrByte ; eax = attribute byte
movzx ecx, [esi].DisplayByte ; ecx = display byte
shl eax, 11 ; * 2048 (256 entries per colour * 8 bytes/entry)
lea eax, [eax+ecx*8] ; 8 bytes/entry
add eax, [esi].ptrULA64ColourTable ; offset into DirectDraw colour mapping table
align 16
SETLOOP 8
movzx ecx, byte ptr [eax]
mov dl, [ULAplusPalette+ecx]
mov [edi], dl
mov [edi+1], dl
add eax, 1
add edi, 2
ENDLOOP
add [esi].DisplayOffset, 1
add [esi].AttrOffset, 1
ret
.endif
movzx eax, [esi].AttrByte ; eax = attribute byte
movzx ecx, [esi].DisplayByte ; ecx = display byte
test eax, 128
je @F ; flash bit clear?
and eax, 127 ; clear Flash bit
xor cl, [esi].FlashInverterByte
@@: shl eax, 12 ; * 4096 (256 entries per colour * 16 bytes/entry)
shl ecx, 4 ; 16 bytes/entry
lea eax, [eax+ecx]
add eax, [esi].ptrTimexColourTable ; offset into DirectDraw colour mapping table
mov ecx, [eax] ; pick up 8 pixel colour values
mov edx, [eax+4]
.if ecx != [edi]
mov [edi], ecx
mov byte ptr [ebp], 1
mov [esi].FrameChanged, TRUE
.endif
.if edx != [edi+4]
mov [edi+4], edx
mov byte ptr [ebp], 1
mov [esi].FrameChanged, TRUE
.endif
add edi, 8
mov ecx, [eax+8] ; pick up next 8 pixel colour values
mov edx, [eax+12]
.if ecx != [edi]
mov [edi], ecx
mov byte ptr [ebp], 1
mov [esi].FrameChanged, TRUE
.endif
.if edx != [edi+4]
mov [edi+4], edx
mov byte ptr [ebp], 1
mov [esi].FrameChanged, TRUE
.endif
add edi, 8
add [esi].DisplayOffset, 1
add [esi].AttrOffset, 1
ret
Render_Timex_HiRes:
movzx ecx, [esi].DisplayByte ; ecx = display byte
movzx eax, Timex_Screen_Colour ; border/paper colour
call RenderTimexChar ; render as standard width Spectrum character
movzx ecx, [esi].AttrByte ; eax = 2nd display byte in hi-res mode
movzx eax, Timex_Screen_Colour ; border/paper colour
call RenderTimexChar ; render as standard width Spectrum character
sub [esi].DisplayOffset, 1 ; RenderTimexChar has incremented these twice so decrement by 1
sub [esi].AttrOffset, 1
ret
RenderTimexChar:
shl eax, 11 ; * 2048 (256 entries per colour * 8 bytes/entry)
lea eax, [eax+ecx*8] ; 8 bytes/entry
add eax, [esi].ptrSpecColourTable ; offset into DirectDraw colour mapping table
mov ecx, [eax] ; pick up 8 pixel colour values
mov edx, [eax+4]
.if ecx != [edi]
mov [edi], ecx
mov byte ptr [ebp], 1
mov [esi].FrameChanged, TRUE
.endif
.if edx != [edi+4]
mov [edi+4], edx
mov byte ptr [ebp], 1
mov [esi].FrameChanged, TRUE
.endif
add edi, 8
add [esi].DisplayOffset, 1
add [esi].AttrOffset, 1
ret
ASSUME ESI:NOTHING