forked from MrKWatkins/ZXSpectrumNextTests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.asm
2515 lines (2377 loc) · 73.7 KB
/
Main.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
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
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; This is general Z80 + DMA chip interactive test (trying to detect TBBlue board
; for convenience of user, but should work on regular ZX Spectrum too)
;
; This is fully interactive test intended for experiments with different
; init/command sequences of DMA and reporting its internal state after
; each step, as the Misc/ZilogDMA did show there are some quirks in real
; Zilog DMA chip, and testing them out without interactive tool turned out
; to be quite cumbersome and slow.
;
; This may be also useful to experiment with init sequences of DMA transfers
; for your own code.
;
; When using custom-byte values, or asking the test to do transfers outside
; of test areas, you risk the damage of the test itself. Generally don't enable
; transfers outside of test areas, or double check the values. The test itself
; resides in memory from address $8000 to $97FF.
; While the test will try to parse custom bytes sent to DMA and interpret them
; to keep the current state fresh, it will not try to protect itself.
; DEFINE BUILD_TAP
device zxspectrum48
org $8000
BinStart:
jp Start
INCLUDE "../../Constants.asm"
INCLUDE "../../Macros.asm"
INCLUDE "../../TestFunctions.asm"
INCLUDE "../../OutputFunctions.asm"
INCLUDE "../../controls.i.asm"
DMA_END_SEQUENCE EQU $FF ; will match as WR6 command, but doesn't exist (invalid)
LAST_CMD_BUF_SZ EQU 7
CUSTOM_CHAR_0 EQU 0
CUSTOM_CHAR_RRPTR EQU 1
CUSTOM_CHAR_WRPTR EQU 2
CUSTOM_CHAR_RRWRPTR EQU 3 ; WR+RR
CUSTOM_CHAR_AMM EQU 4 ; adjust --
CUSTOM_CHAR_APP EQU 5 ; adjust ++
CUSTOM_CHAR_AFIX EQU 6 ; adjust +0
CUSTOM_CHAR_SRCA EQU 7 ; src char for attribute
CUSTOM_CHAR_DSTA EQU 8 ; dst char for attribute
CUSTOM_CHAR_EPIX EQU 9 ; empty pixels char
CUSTOM_CHAR_DIRR EQU 10 ; ->
CUSTOM_CHAR_DIRL EQU 11 ; <-
CUSTOM_CHAR_STD EQU 12 ; standard value "S"
CUSTOM_CHAR_ENTER EQU 13
ATTR_UNCOMMITED EQU A_BRIGHT|P_BLUE|WHITE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; global state data
STRUCT StateData_Port
adjust BYTE 1 ; 0="--", 1="++", 2="+0"
timing BYTE $FF ; 0xFF is special value (standard timing)
adr WORD
ENDS
STRUCT StateData_Partial
a StateData_Port {,,MEM_ZX_ATTRIB_5800+$20*1+13}
b StateData_Port {,,MEM_ZX_ATTRIB_5800+$20*3+13}
mode BYTE %01 ; %00 = byte, %01 = continuous, %10 = burst
direction BYTE $0A ; $0A=A->B $0B=A<-B
length WORD $0002 ; 3-bytes transfers for test purposes
ENDS
STRUCT StateData
isEditMode BYTE 0 ; 0=normal UI, 0!=edit mode (cursor at position)
isCByteStandard BYTE 1 ; 1=custom byte is "standard" (dynamic per purpose)
customByte BYTE $00 ; specific custom byte entered (not standard)
isPixelTransfer BYTE 0 ; source/destination data are 1=pixels/0=attributes
edit StateData_Partial ; currently edited values by user (not committed)
wr StateData_Partial ; WR values (known to the test) (committed values)
diff WORD -1 ; bits from 8: mode, dir, length, B.tim, B.adj, B.adr, A.tim, A.adj, A.adr
portAtype BYTE 0 ; $00/$08 = mem/IO
portBtype BYTE 0 ; $00/$08 = mem/IO
rrStatus BYTE 0
rrCnt WORD 0
rrAadr WORD 0
rrBadr WORD 0
awaitingWriteBytes BYTE 0
writeScrAdr WORD 0
lastCmdBuffer BLOCK LAST_CMD_BUF_SZ, $FF
caps BYTE $FF ; $FF = regular key, $00 = caps shift
symbol BYTE $FF ; $FF = regular key, $00 = symbol shift
ENDS
s StateData ; working state of the test
stateInitSet StateData ; read-only init-data for test restarts (⌥p)
playSequence DW DmaEmptySequence
STRUCT WR6_CMD_DATA
name WORD ; name of command (string to display)
length BYTE 1 ; how many bytes the command has
ALIGN 4
ENDS
cmd_name_invalid DZ '!INVALID!'
cmd_name_83 DZ 'DISABLE' ; DMA_DISABLE
cmd_name_87 DZ 'ENABLE' ; DMA_ENABLE
cmd_name_8B DZ 'CL.STATUS' ; DMA_REINIT_STATUS_BYTE
cmd_name_A3 DZ 'RST D.INT' ; DMA_RESET_DISABLE_INTERUPTS
cmd_name_A7 DZ 'ST.RD.SEQ' ; DMA_START_READ_SEQUENCE
cmd_name_AB DZ 'INT ENABL' ; DMA_ENABLE_INTERUPTS
cmd_name_AF DZ 'INT DISAB' ; DMA_DISABLE_INTERUPTS
cmd_name_B3 DZ 'FORCE RDY' ; DMA_FORCE_READY
cmd_name_B7 DZ 'EN.A.RETI' ; DMA_ENABLE_AFTER_RETI
cmd_name_BB DZ 'RD MASK=' ; DMA_READ_MASK_FOLLOWS
cmd_name_BF DZ 'RD STATUS' ; DMA_READ_STATUS_BYTE
cmd_name_C3 DZ 'RESET' ; DMA_RESET
cmd_name_C7 DZ 'RESET A t' ; DMA_RESET_PORT_A_TIMING
cmd_name_CB DZ 'RESET B t' ; DMA_RESET_PORT_B_TIMING
cmd_name_CF DZ 'LOAD' ; DMA_LOAD
cmd_name_D3 DZ 'CONTINUE' ; DMA_CONTINUE
ALIGN 128
WR6_cmd_data_table:
WR6_CMD_DATA { cmd_name_83 }
WR6_CMD_DATA { cmd_name_87 }
WR6_CMD_DATA { cmd_name_8B }
WR6_CMD_DATA { cmd_name_invalid }
WR6_CMD_DATA { cmd_name_invalid }
WR6_CMD_DATA { cmd_name_invalid }
WR6_CMD_DATA { cmd_name_invalid }
WR6_CMD_DATA { cmd_name_invalid }
WR6_CMD_DATA { cmd_name_A3 }
WR6_CMD_DATA { cmd_name_A7 }
WR6_CMD_DATA { cmd_name_AB }
WR6_CMD_DATA { cmd_name_AF }
WR6_CMD_DATA { cmd_name_B3 }
WR6_CMD_DATA { cmd_name_B7 }
WR6_CMD_DATA { cmd_name_BB, 2 }
WR6_CMD_DATA { cmd_name_BF }
WR6_CMD_DATA { cmd_name_C3 }
WR6_CMD_DATA { cmd_name_C7 }
WR6_CMD_DATA { cmd_name_CB }
WR6_CMD_DATA { cmd_name_CF }
WR6_CMD_DATA { cmd_name_D3 }
WR6_CMD_DATA { cmd_name_invalid }
WR6_CMD_DATA { cmd_name_invalid }
WR6_CMD_DATA { cmd_name_invalid }
WR6_CMD_DATA { cmd_name_invalid }
WR6_CMD_DATA { cmd_name_invalid }
WR6_CMD_DATA { cmd_name_invalid }
WR6_CMD_DATA { cmd_name_invalid }
WR6_CMD_DATA { cmd_name_invalid }
WR6_CMD_DATA { cmd_name_invalid }
WR6_CMD_DATA { cmd_name_invalid }
WR6_CMD_DATA { cmd_name_invalid }
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; DMA logic utility functions
SendDmaByte:
;; TODO: this doesn't recognize some of the possible extra bytes (interrupt control byte)
; store the byte in the lastCmdBuffer
ld hl,(s.lastCmdBuffer+1)
ld (s.lastCmdBuffer),hl
ld hl,(s.lastCmdBuffer+3)
ld (s.lastCmdBuffer+2),hl
ld hl,(s.lastCmdBuffer+5)
ld (s.lastCmdBuffer+4),hl
ld (s.lastCmdBuffer+6),a
; check if this is first byte of new command/write
; if yes, scroll, init the new command/write, identify length, display, ...
ld b,a
ld a,(s.awaitingWriteBytes)
or a
jp nz,.nextGroupByte
; new command
call ScrollUpBottomTwoThirdsByRow
ld hl,MEM_ZX_SCREEN_4000+$1000+$20*7
ld (OutCurrentAdr),hl
; identify the command and print it's basic name, and get the count of bytes expected
ld a,b
xor %1000'0011
and %1000'0011
jr nz,.notWR6
; WR6 (command) detected - print name, setup expected bytes, set OutCurrentAdr
ld a,'c'
call OutChar
ld a,' '
call OutChar
ld a,b
cp DMA_RESET
jr nz,.notResetCommand
ld (ix + StateData.wr.a.timing),$FF
ld (ix + StateData.wr.b.timing),$FF
jr .stateUpdated
.notResetCommand:
cp DMA_RESET_PORT_A_TIMING
jr nz,.notResetPortACommand
ld (ix + StateData.wr.a.timing),$FF
jr .stateUpdated
.notResetPortACommand:
cp DMA_RESET_PORT_B_TIMING
jr nz,.stateUpdated
ld (ix + StateData.wr.b.timing),$FF
.stateUpdated:
and %0111'1100
add a,low WR6_cmd_data_table
ld l,a
ld h,high WR6_cmd_data_table
ld e,(hl)
inc hl
ld d,(hl)
inc hl
ex de,hl
call OutString
ld a,(de)
rlca
neg
add a,$20*7+14
ld (OutCurrentAdr),a
ld a,(de)
jp .finishNewCommand
.notWR6:
ld a,'W'
call OutChar
ld a,'R'
call OutChar
ld a,b
and %1000'0011
jr nz,.notWR1or2
; WR1 or WR2
ld a,b
rrca
rrca
rra ; A = %00006aaI ; CF=1 WR1, CF=0 WR2, 6 = D6 (+1B), aa=adjust, I=mem/IO
jr nc,.isWR2
; WR1
push af
ld a,1
ld (s.lastCmdBuffer+5),a ; create bytes 01 WR1 in buffer
ld a,b
and 8
ld (s.portAtype),a
ld a,'1'
call OutChar
pop af
rra
and 3
ld (s.wr.a.adjust),a
jr .finishWR1and2
.isWR2:
push af
ld a,2
ld (s.lastCmdBuffer+5),a ; create bytes 02 WR2 in buffer
ld a,b
and 8
ld (s.portBtype),a
ld a,'2'
call OutChar
pop af
rra
and 3
ld (s.wr.b.adjust),a
.finishWR1and2:
ld a,' '
call OutChar
ld a,b
rlca
rlca
and 1
inc a
jr .finishNewCommand
.notWR1or2:
bit 7,b
jr nz,.notWR0
; WR0
xor a
ld (s.lastCmdBuffer+5),a ; create bytes 00 WR0 in buffer
ld a,'0'
call OutChar
ld a,' '
call OutChar
ld a,CUSTOM_CHAR_DIRR
bit 2,b
jr nz,.dirAtoB
inc a
.dirAtoB:
ld (s.wr.direction),a
; calculate how many extra bytes are expected
ld l,b
ld a,1
rl l
rl l
adc a,0
rl l
adc a,0
rl l
adc a,0
rl l
adc a,0
jr .finishNewCommand
.notWR0:
; WR3, WR4, WR5 ; A = %1000'00xx (xx = 0,1,2)
add a,'3'+$80 ; -> '3', '4', '5'
call OutChar
ld a,' '
call OutChar
ld a,1 ; awaiting only this one byte
bit 0,b
jr z,.finishNewCommand ; WR3 and WR5 are done like this (no parsing)
; WR4
ld a,3
ld (s.lastCmdBuffer+5),a ; create bytes 03 WR4 in buffer
ld a,b
rlca
rlca
rlca
and 3
ld (s.wr.mode),a
ld a,1
bit 2,b
jr z,.noPortBadrLSB
inc a
.noPortBadrLSB:
bit 3,b
jr z,.finishNewCommand
inc a
.finishNewCommand:
ld hl,(OutCurrentAdr)
ld (s.writeScrAdr),hl
.nextGroupByte:
dec a
push af
ld (s.awaitingWriteBytes),a
ld hl,(s.writeScrAdr)
ld (OutCurrentAdr),hl
ld a,b
call OutHexaValue
ld hl,(OutCurrentAdr)
ld (s.writeScrAdr),hl
; send it to DMA port (immediately)
out (c),a
pop af
ret nz
;; this was the last byte of the command sequence - do the aftermath stuff
; if command was DMA_READ_STATUS_BYTE ... only status byte should be read. Ignored now
; scan the command sequence and if WR0124, refresh internal state accordingly
ld hl,s.lastCmdBuffer-1
ld a,$FF
.searchCmdByteLoop:
inc hl
cp (hl)
jr z,.searchCmdByteLoop
and (hl) ; $FF&value = value && ZF=1 when 0
inc hl
ld b,(hl) ; WRx itself
jr z,.updateWR0State
ld de,s.wr.a.timing
dec a
jr z,.updateWR12State
ld de,s.wr.b.timing
dec a
jr z,.updateWR12State
dec a
jr nz,.WRstateUpdated
; updateWR4State
bit 2,b
jr z,.updateWR4_adrMSB
inc hl
ld a,(hl) ; portB address LSB
ld (s.wr.b.adr),a
.updateWR4_adrMSB:
bit 3,b
jr z,.WRstateUpdated
inc hl
ld a,(hl) ; portB address MSB
ld (s.wr.b.adr+1),a
jr .WRstateUpdated
.updateWR0State:
bit 3,b
jr z,.updateWR0_adrMSB
inc hl
ld a,(hl) ; portA address LSB
ld (s.wr.a.adr),a
.updateWR0_adrMSB:
bit 4,b
jr z,.updateWR0_lenLSB
inc hl
ld a,(hl) ; portA address MSB
ld (s.wr.a.adr+1),a
.updateWR0_lenLSB:
bit 5,b
jr z,.updateWR0_lenMSB
inc hl
ld a,(hl) ; Length LSB
ld (s.wr.length),a
.updateWR0_lenMSB:
bit 6,b
jr z,.WRstateUpdated
inc hl
ld a,(hl) ; Length MSB
ld (s.wr.length+1),a
jr .WRstateUpdated
.updateWR12State
bit 6,b
jr z,.WRstateUpdated
inc hl
ld a,(hl) ; Timing byte
ld (de),a
.WRstateUpdated:
; clear the last command buffer
ld hl,$FFFF
ld (s.lastCmdBuffer),hl
ld (s.lastCmdBuffer+2),hl
ld (s.lastCmdBuffer+4),hl
ld (s.lastCmdBuffer+5),hl
; read the DMA internal state
ld a,DMA_START_READ_SEQUENCE
out (c),a
ld hl,s.rrStatus
ld b,7
inir
; output the DMA internal state to the end of line
ld hl,OutCurrentAdr+1
ld (hl),high (MEM_ZX_SCREEN_4000+$1000+$20*7+15)
dec hl
ld (hl),low (MEM_ZX_SCREEN_4000+$1000+$20*7+15)
ld a,(s.rrStatus)
call OutHexaValue
inc (hl)
ld a,(s.rrCnt+1)
call OutHexaValue
ld a,(s.rrCnt)
call OutHexaValue
inc (hl)
ld a,(s.rrAadr+1)
call OutHexaValue
ld a,(s.rrAadr)
call OutHexaValue
inc (hl)
ld a,(s.rrBadr+1)
call OutHexaValue
ld a,(s.rrBadr)
call OutHexaValue
; modify attributes of read values to use blue ink
ld hl,MEM_ZX_ATTRIB_5800+$20*23+15
ld b,32-15
.SetBlueInkLoop:
inc (hl) ; assumes black ink! :)
inc l
djnz .SetBlueInkLoop
; refresh the display with values in upper third of screen
jp RedrawValues
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; redraw whole screen (full init of top third)
RedrawScreen:
; will redraw upper third of screen fully, will also reset destination area bytes
; A mem.....v+....V+..............
; .##############################.
; B mem.......-V....-v............
; .%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%.
; ??↲↲ pix WR0124↲ A?t?Tt?? mburs
; WR3 WR5 Test:qwer B?y?Ty?? l1234
; LOAD F-RDY ENA RST-S RST-M a1234
; CONT DIS RST RST-A RST-B d?b1234
push bc
; clear+set attributes of upper third
ld hl,RedrawAttributeData
ld de,MEM_ZX_ATTRIB_5800
ld bc,8*32
call ScrollUpBottomTwoThirdsByRow.unrolled32LDI
jp pe,$-3
; clear pixels of first third
ld hl,MEM_ZX_SCREEN_4000
ld de,MEM_ZX_SCREEN_4000+1
ld (hl),l
ldi
ld bc,66*31 ; = 2046 + LDI above = 2047
call ScrollUpBottomTwoThirdsByRow.unrolled31LDI
jp pe,$-3
; create small line between top third and rest
ld hl,MEM_ZX_SCREEN_4000+$700+$20*7+0
ld b,32-7
.solidLineLoop:
ld (hl),%11111111
inc l
djnz .solidLineLoop
; print all default texts
ld hl,MEM_ZX_SCREEN_4000+$20*4
ld (OutCurrentAdr),hl ; also set address for OutChar
ld hl,RedrawTextData
ld b,4*32
.redrawText:
ld a,(hl)
inc hl
call OutCharWithCustomGfx
djnz .redrawText
pop bc
; reset source/destination areas
call RedrawTransferAreas
jp RedrawValues
RedrawTextData:
DB ' ',13,13,' Pix WR0124',13,' A T tT M '
DB 'WR3 WR5 Test:QWER B Y tY L '
DB 'LOAD F-RDY ENA RST-S RST-M A '
DB 'CONT DIS RST RST-A RST-B D B '
RedrawAttributeData:
; test area block
BLOCK 32, P_WHITE ; L0
BLOCK 32, P_CYAN ; L1
BLOCK 32, P_WHITE ; L2
BLOCK 32, P_CYAN ; L3
; commands/values block
; 38 = white, 28 = cyan, 78 = bright white (regular key) 70 = bright yellow (shift), 58 = bright magenta (caps shift)
HEX 38 38 70 58 38 78 38 38 38 38 38 38 38 38 38 78 38 38 70 38 78 38 38 70 38 38 38 78 38 38 38 38
HEX 38 38 58 38 38 38 58 38 38 38 38 38 38 78 78 78 78 38 70 38 78 38 38 70 38 38 38 78 38 38 38 38
HEX 58 38 38 38 38 58 38 38 38 38 38 58 38 38 38 38 38 38 38 58 38 38 38 38 38 58 38 78 38 38 38 38
HEX 58 38 38 38 38 58 38 38 38 58 38 38 38 38 38 38 38 58 38 38 38 38 38 58 38 78 38 78 38 38 38 38
ALIGN 2
RedrawAttributeBg:
DB P_BLUE ; base filler for attribute transfers
DB P_YELLOW ; base filler for pixel transfers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; redraw transfer areas (resetting the values in source and destination)
RedrawTransferAreas:
push bc
; clear attributes in both source and destination area
ld a,(s.isPixelTransfer)
add a,low RedrawAttributeBg
ld l,a
ld h,high RedrawAttributeBg
ld a,(hl)
ld d,a
or A_BRIGHT
ld e,a ; DE = attribute values for filler
ld hl,MEM_ZX_ATTRIB_5800+$20*1
call .fillAttributesArea
ld hl,MEM_ZX_ATTRIB_5800+$20*3
call .fillAttributesArea
; clear pixels in both source and destination area
; fill with: in pixel mode char "pixel data" / in attributes using "src/dst DMA" char
ld a,(s.isPixelTransfer)
inc a ; A = %10 for pixel=1, %01 for pixel=0
and (ix + StateData.wr.direction) ; $0A A->B, $0B A<-B
; A = %00 for A->B attr, %01 for B->A attr %10 for pixel=1
rlca ; *=2
push af
add a,low SolidClearData1
ld l,a
ld h,high SolidClearData1
ld e,(hl)
inc l
ld d,(hl)
ld hl,MEM_ZX_SCREEN_4000+$20*1
call .ClearPixelArea
pop af
add a,low SolidClearData2
ld l,a
ld h,high SolidClearData2
ld e,(hl)
inc l
ld d,(hl)
ld hl,MEM_ZX_SCREEN_4000+$20*3
call .ClearPixelArea
; setup source area
ld a,(s.isPixelTransfer)
add a,low SrcDataAdr
ld l,a
ld h,high SrcDataAdr
ld d,(hl)
ld a,(s.wr.direction)
and 1
rrca
rrca
or $21 ; A = $21 for A->B, $61 for A<-B
ld e,a
; DE = address of source data -> fill now, HL = SrcDataAdr + isPixelTransfer
; - pixel: customByte = solid fill, SS = standard pattern
; - attr: customByte = solid fill, SS = standard pattern
call .DrawSourceData
pop bc
ret
.fillAttributesArea:
ld (hl),P_CYAN
inc l
ld b,15
.fillAttributesArea_loop:
ld (hl),e
inc l
ld (hl),d
inc l
djnz .fillAttributesArea_loop
ld (hl),P_CYAN
ret
.ClearPixelArea:
push hl
ld c,8
.fill8Lines:
push hl
ld (hl),0
inc l
ld a,(de)
inc e
ld b,30
.fillOneLine:
ld (hl),a
inc l
djnz .fillOneLine
ld (hl),b
pop hl
inc h
dec c
jr nz,.fill8Lines
pop hl
ret
.DrawSourceData:
ld b,30
ld a,(s.isCByteStandard)
or a
jr z,.fillWithCustomByte
; standard byte for pixels %1000'0010 += 2
; standard byte for attributes %01'100'000 += 1
ld a,(s.isPixelTransfer)
inc a
ld (.fillWithStandardPattern_IncBy),a
inc l
inc l ; HL = SrcDataInitValue+isPixelTransfer (reusing older HL)
ld a,(hl)
.fillWithStandardPattern_Loop:
ld (de),a
inc e
.fillWithStandardPattern_IncBy: EQU $ + 1
add a,0
djnz .fillWithStandardPattern_Loop
ret
.fillWithCustomByte:
ld a,(s.customByte)
.fillWithCustomByte_Loop:
ld (de),a
inc e
djnz .fillWithCustomByte_Loop
ret
ALIGN 16
SolidClearData1:
DW Char_AttrSrcData, Char_AttrDstData, Char_PixelData
SolidClearData2:
DW Char_AttrDstData, Char_AttrSrcData, Char_PixelData
SrcDataAdr:
DB $58, $43
SrcDataInitValue:
DB %01'100'000, %1000'0010
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; swap transfer areas (keeping the values, but flips source/destination area)
SwapTransferAreas:
ld hl,$5821
ld de,$5861
ld c,1
call .swap30bytes
ld hl,$4021
ld de,$4061
ld c,8
.swap30bytes:
push hl
push de
push bc
ld b,30
.swapByte:
ld c,(hl)
ld a,(de)
ld (hl),a
ld a,c
ld (de),a
inc l
inc e
djnz .swapByte
pop bc
pop de
pop hl
inc h
inc d
dec c
jr nz,.swap30bytes
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; redraw variable values, with correct colour-state-encoding
RedrawValues:
push bc
;; redraw the address symbols
; "erase" old PortA positions by using white on white attribute color
ld hl,MEM_ZX_ATTRIB_5800+$20*0
ld de,MEM_ZX_ATTRIB_5800+$20*0+1
ld (hl),P_WHITE|WHITE
call ScrollUpBottomTwoThirdsByRow.unrolled31LDI
ld hl,MEM_ZX_SCREEN_4000+$20*0
; redraw PortA symbols at new positions
ld a,(s.wr.a.adjust)
ld b,a ; B = 0/1/2(3)
cp 1
sbc a,a ; [0, 1, 2, 3] -> [-1, 0, 0, 0]
ld c,a ; C = position adjust for the --/++/+0 char (-1/+0)
ld de,(s.rrAadr)
call TestAdrToXPos
add a,c
ld iyl,a
ld de,(s.wr.a.adr)
call TestAdrToXPos
add a,c
ld iyh,a ; A = IYH = WRpos--++, IYL = RRpos--++, B = adjustment, C=-1/+0 adj.
call DrawAdrPointers
; redraw general PortA label
ld de,MEM_ZX_ATTRIB_5800+$20*0
ld b,'A'
ld c,(ix + StateData.portAtype) ; $00/$08 mem/IO
call DrawPortInfo
; highlight also "edit" address of port A by brightness in attribute
ld hl,MEM_ZX_ATTRIB_5800+$20*0
ld de,(s.edit.a.adr)
call DrawEditAdrPointer
; "erase" old PortB positions by using white on white attribute color
ld hl,MEM_ZX_ATTRIB_5800+$20*2
ld de,MEM_ZX_ATTRIB_5800+$20*2+1
ld (hl),P_WHITE|WHITE
call ScrollUpBottomTwoThirdsByRow.unrolled31LDI
ld hl,MEM_ZX_SCREEN_4000+$20*2
; redraw PortB symbols at new positions
ld a,(s.wr.b.adjust)
ld b,a ; B = 0/1/2(3)
cp 1
sbc a,a ; [0, 1, 2, 3] -> [-1, 0, 0, 0]
ld c,a ; C = position adjust for the --/++/+0 char (-1/+0)
ld de,(s.rrBadr)
call TestAdrToXPos
add a,c
ld iyl,a
ld de,(s.wr.b.adr)
call TestAdrToXPos
add a,c
ld iyh,a ; A = IYH = WRpos--++, IYL = RRpos--++, B = adjustment, C=-1/+0 adj.
call DrawAdrPointers
; redraw general PortB label
ld de,MEM_ZX_ATTRIB_5800+$20*2
ld b,'B'
ld c,(ix + StateData.portBtype) ; $00/$08 mem/IO
call DrawPortInfo
; highlight also "edit" address of port B by brightness in attribute
ld hl,MEM_ZX_ATTRIB_5800+$20*2
ld de,(s.edit.b.adr)
call DrawEditAdrPointer
; redraw custom byte content
ld hl,MEM_ZX_SCREEN_4000+$20*4+0
ld (OutCurrentAdr),hl
xor a
call Clear2Char
ld a,(s.isEditMode)
or a
jr z,.notInEditMode
add a,low (MEM_ZX_ATTRIB_5800+$20*4-1)
ld l,a
ld h,high (MEM_ZX_ATTRIB_5800+$20*4+0)
ld (hl),A_FLASH|A_BRIGHT|P_WHITE|BLACK
.notInEditMode:
ld a,(s.isCByteStandard)
dec a
jr z,.showStandardByte
ld a,(s.customByte)
call OutHexaValue
jr .customByteDrawn
.showStandardByte:
ld a,CUSTOM_CHAR_STD
call OutCharWithCustomGfx
call OutCharWithCustomGfx
.customByteDrawn:
; port data (adjust, timing)
ld hl,MEM_ZX_SCREEN_4000+$20*4+19
ld iy,s.edit.a
call DrawPortData
ld hl,MEM_ZX_SCREEN_4000+$20*5+19
ld iy,s.edit.b
call DrawPortData
; draw transfer direction
ld hl,MEM_ZX_SCREEN_4000+$20*7+26
xor a
call Clear1Char
ld b,(ix + StateData.edit.direction)
xor a
call OutBCharAtA
; draw mode
ld hl,MEM_ZX_SCREEN_4000+$20*4+28
ld (OutCurrentAdr),hl
xor a
ld b,a
call Clear4Char
ld a,(s.edit.mode)
add a,a
add a,a
add a,a
ld c,a
ld hl,ModeStringsPer8B
add hl,bc
call OutString
; draw length, addressA, addressB words
ld hl,MEM_ZX_SCREEN_4000+$20*5+28
ld de,s.edit.length+1
call DrawWordValue
ld hl,MEM_ZX_SCREEN_4000+$20*6+28
ld de,s.edit.a.adr+1
call DrawWordValue
ld hl,MEM_ZX_SCREEN_4000+$20*7+28
ld de,s.edit.b.adr+1
call DrawWordValue
; colorize the values which are not commited
; diff WORD => from 8: mode, dir, length, B.tim, B.adj, B.adr, A.tim, A.adj, A.adr
call RefreshDiffBits
; reset all WR0124 indicators to regular white+black
ld hl,$3838
ld (MEM_ZX_ATTRIB_5800+$20*4+11),hl
ld (MEM_ZX_ATTRIB_5800+$20*4+13),hl
; WR0: %01 in D1D0 ("transfer") - this test does not support/show other options!
; direction D2: 0 = A<-B, 1 = A->B, port A adr: D4D3, length: D6D5
ld hl,MEM_ZX_ATTRIB_5800+$20*4+11
ld bc,(1<<8) | %1'1'000'001 ; WR0: dir, length, A.adr
call MarkUncommitedDifference
; WR1: D3: A-type (not in diff), A-adjust D5D4, A-timing D6+byte
ld l,low (MEM_ZX_ATTRIB_5800+$20*4+12)
ld bc,(1<<8) | %0'0'000'110 ; WR1: A.tim, A.adj
call MarkUncommitedDifference
; WR2: D3: B-type (not in diff), B-adjust D5D4, B-timing D6+byte
ld l,low (MEM_ZX_ATTRIB_5800+$20*4+13)
ld bc,(1<<8) | %0'0'110'000 ; WR2: B.tim, B.adj
call MarkUncommitedDifference
; WR4: mode D6D5, port B adr: D3D2
ld l,low (MEM_ZX_ATTRIB_5800+$20*4+14)
ld a,(s.diff + 1)
rra
ld a,(s.diff)
rla ; shift diff + add mode bit
ld bc,(1<<8) | %0'001'000'1 ; WR4: B.adr (shifted), mode
call MarkUncommitedDifference.customDiffVal
; port A adjustement
ld l,low (MEM_ZX_ATTRIB_5800+$20*4+19)
ld bc,(1<<8) | %0'0'000'010
call MarkUncommitedDifference
; port A timing
ld l,low (MEM_ZX_ATTRIB_5800+$20*4+21)
ld bc,(1<<8) | %0'0'000'100
call MarkUncommitedDifference
ld l,low (MEM_ZX_ATTRIB_5800+$20*4+24)
ld b,2
call MarkUncommitedDifference
; port B adjustement
ld l,low (MEM_ZX_ATTRIB_5800+$20*5+19)
ld bc,(1<<8) | %0'0'010'000
call MarkUncommitedDifference
; port B timing
ld l,low (MEM_ZX_ATTRIB_5800+$20*5+21)
ld bc,(1<<8) | %0'0'100'000
call MarkUncommitedDifference
ld l,low (MEM_ZX_ATTRIB_5800+$20*5+24)
ld b,2
call MarkUncommitedDifference
; transfer mode
ld l,low (MEM_ZX_ATTRIB_5800+$20*5-4)
ld bc,(4<<8) | %0'0'000'001
ld a,(s.diff + 1)
call MarkUncommitedDifference.customDiffVal
; length
ld l,low (MEM_ZX_ATTRIB_5800+$20*6-4)
ld bc,(4<<8) | %0'1'000'000
call MarkUncommitedDifference
; A.adr
ld l,low (MEM_ZX_ATTRIB_5800+$20*7-4)
ld bc,(4<<8) | %0'0'000'001
call MarkUncommitedDifference
; B.adr
ld l,low (MEM_ZX_ATTRIB_5800+$20*8-4)
ld bc,(4<<8) | %0'0'001'000
call MarkUncommitedDifference
; direction
ld l,low (MEM_ZX_ATTRIB_5800+$20*8-6)
ld bc,(1<<8) | %1'0'000'000
call MarkUncommitedDifference
pop bc
ret
ModeStringsPer8B:
DB 'byte',0,0,0,0
DB 'cont',0,0,0,0
DB 'burs',0,0,0,0
DB 'inva',0,0,0,0
TestAdrToXPos: ; DE = memory address (or I/O port, treated as memory address :) )
; returns A 1..30 (column) for addresses within testing range, 128 for other
; Port A attributes: 5821 .. 583E
; Port B attributes: 5861 .. 587E
; Port A pixels: 4321 .. 433E
; Port B pixels: 4361 .. 437E
ld a,$43
cp d
jr z,.HighAddressInTestRange
ld a,$58
cp d
jr z,.HighAddressInTestRange
.addressOutsideOfTestRange:
ld a,128
ret
.HighAddressInTestRange:
ld a,e
cp $21
jr c,.addressOutsideOfTestRange
cp $7E+1
jr nc,.addressOutsideOfTestRange
cp $3E+1
jr c,.LowAddressInTestRange
cp $61
jr c,.addressOutsideOfTestRange
.LowAddressInTestRange:
and $1F
ret
MarkUncommitedDifference: ; HL = target address start, B = length to mark, C = mask
ld a,(s.diff)
.customDiffVal:
and c
ret z
.markLoop:
ld (hl),ATTR_UNCOMMITED
inc l
djnz .markLoop
ret
RefreshDiffBits:
; diff WORD => bits from 8: mode, dir, length, B.tim, B.adj, B.adr, A.tim, A.adj, A.adr
xor a
ld hl,(s.edit.mode)
ld de,(s.wr.mode)
call .testByte
ld (s.diff + 1),a
xor a
ld hl,(s.edit.direction)
ld de,(s.wr.direction)
call .testByte
ld hl,(s.edit.length)
ld de,(s.wr.length)
call .testWord
ld hl,(s.edit.b.timing)
ld de,(s.wr.b.timing)
call .testByte
ld hl,(s.edit.b.adjust)
ld de,(s.wr.b.adjust)
call .testByte
ld hl,(s.edit.b.adr)
ld de,(s.wr.b.adr)
call .testWord
ld hl,(s.edit.a.timing)
ld de,(s.wr.a.timing)
call .testByte
ld hl,(s.edit.a.adjust)
ld de,(s.wr.a.adjust)
call .testByte
ld hl,(s.edit.a.adr)
ld de,(s.wr.a.adr)
call .testWord
ld (s.diff),a
ret
.testByte: ; L vs E
ld d,h ; make D/H irrelevant to the comparison
;