forked from trykaar/dc-sms-dasm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcsms.asm
15843 lines (14647 loc) · 253 KB
/
dcsms.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
; Dragon Crystal Disassembly
; Disassembled with Emulicious
; Variable Definitions
.include "defines\system_constants.i"
.include "defines\asciitable.i"
.include "defines\ram_map.i"
.include "defines\item_constants.i"
.include "defines\game_variables.i"
.include "defines\monster_constants.i"
.include "defines\game_message_constants.i"
.include "defines\mask_constants.i"
.include "defines\music_constants.i"
; End Definitions
.MEMORYMAP
SLOTSIZE $4001
SLOT 0 $0000
SLOTSIZE $3FFF
SLOT 1 $4001
SLOTSIZE $4000
SLOT 2 $8000
DEFAULTSLOT 2
.ENDME
.ROMBANKMAP
BANKSTOTAL 8
BANKSIZE $4001
BANKS 1
BANKSIZE $3FFF
BANKS 1
BANKSIZE $4000
BANKS 6
.ENDRO
.BANK 0 SLOT 0
.ORG $0000
Origin:
jp Initialize
; Empty space
.ds 5, $FF
.org $0008
Interrupt8:
di
ld a, e
out (VDPControl), a
ld a, $40
or d
out (VDPControl), a
ei
ret
; Empty space
.ds 5, $FF
.org $0018
Interrupt18:
di
ld a, e
out (VDPControl), a
ld a, d
out (VDPControl), a
ei
ret
; Empty space
.ds 7, $FF
.org $0028
Interrupt28:
ld a, $E2
jp FinishVDPControlInterrupt
; Empty space
.ds 3, $FF
.org $0030
Interrupt30:
ld a, $A2
jp FinishVDPControlInterrupt
; Empty space
.ds 3, $FF
; Interrupt $38 is VBLANK
.org $0038
VBlank:
jp VBlankHandler
FinishVDPControlInterrupt:
out (VDPControl), a
ld a, $81
out (VDPControl), a
ret
; Data from 42 to 65 (36 bytes)
Data_42:
.dw $8026 $81A2 $82FF $83FF
.dw $84FF $85FF $86FB $8700
.dw $8800 $8900 $8A00
; Empty space
.ds 14, $FF
; Pause handler- must be at $0066
.org $0066
PauseHandler:
push af
ld a, ($C019) ; If $C019 is 10, do nothing
cp $0A
jr nz, ++
ld a, (Autoplay) ; If autoplay is on, do nothing
or a
jr nz, +
ld a, (PlayerSpeed) ; Get player speed
cpl ; Toggle between fast speed ($FF) and slow speed ($00)
ld (PlayerSpeed), a ; Save player speed
+:
pop af
retn
++:
pop af
retn
Initialize:
di
ld sp, $DFF0
im 1
ld hl, $FFFC ; Initialize mapper
ld (hl), $00
inc hl ; $FFFD
ld (hl), $00
inc hl ; $FFFE
ld (hl), $01
inc hl ; $FFFF
ld (hl), $02
ld hl, $C001 ; Zero out C001-C100
ld de, $C002
ld bc, $00FE
ld (hl), $00
ldir
WaitForLineB0:
in a, ($7E) ; Get scan line currently being drawn
cp $B0 ; Is it $B0?
jr nz, WaitForLineB0 ; If not, go back and wait
xor a ; Zero out a
out (VDPControl), a ; Write $C000 out to the VDP to select CRAM
ld a, $C0
out (VDPControl), a
xor a ; Zero out a again
ld b, $20 ; Load counter with $20
ex (sp), hl ; Wait
ex (sp), hl
-:
out (VDPData), a ; Set the next palette color to black
nop ; Wait
djnz - ; Do this $20 times (32 times) for the whole palette
DoReset: ; If the game is reset, it jumps back to this point
di
ld sp, $DFF0 ; Initialize stack pointer
xor a ; Zero out a
ld ($C005), a ; Set $C005 to zero
ld ($C002), a ; Set $C002 to zero
in a, (VDPControl) ; Clear VDP status flags by reading from port
ld b, $16 ; Read $16 from $0042 and output to VDPControl
ld c, VDPControl
ld hl, Data_42
otir
ld hl, $C100 ; Zero out $C100-D000
ld de, $C101
ld bc, $0EFF
ld (hl), $00
ldir
ld hl, $DD00 ; Zero out $DD00-DFF0
ld de, TempoTimeout
ld bc, $02EF
ld (hl), $00
ldir
rst $30 ; Interrupt30- write $A2, $81 to VDPControl
call InitializePaletteInRAM ; Initializes more memory, sets a flag in PaletteInRAMStatus
call VDPOut_59D ; Some sort of display? Title screen, maybe?
ld a, $FF
ld (PlayerSpeed), a ; Set speed to fast ($FF)
ld a, $00 ; Zero out $C019 and TableIndex1...
ld ($C019), a
ld (TableIndex1), a
ei ; Done with setup?
in a, ($DC) ; Read controller 1 input
cpl ; Invert so 1 means button pressed
and %00111111 ; Ignore bits used for Player 2 controller up and down input- not useful
cp %00000101 ; %00000101 Up and left pressed together? Cheat?
jp nz, _LABEL_111_ ; If not, go here
ld a, $01 ; If pressed, set $C0D6 to $01
ld ($C0D6), a
jp _LABEL_111_
ret ; Unreachable
_LABEL_111_:
call UpdateControllerState
call _LABEL_4BD_
ld hl, _LABEL_111_
push hl
ld hl, TableIndex1
ld a, ($C019)
xor (hl)
and $7F
ld a, (hl)
jr z, _LABEL_12A_
ld ($C019), a
_LABEL_12A_:
ld hl, JumpTable1
CallJumpTable:
ld e, a ; Load index passed in a into lower byte
ld d, $00 ; $00XX where XX is index
add hl, de
add hl, de
ld a, (hl)
inc hl
ld h, (hl)
ld l, a
jp (hl)
_LABEL_137_:
ld a, $01
ld (VBlankAction), a
_LABEL_13C_:
ld a, (VBlankAction)
or a
jr nz, _LABEL_13C_
ret
_LABEL_143_:
ld a, (VBlankAction)
or a
jr nz, _LABEL_143_
ld a, $02
ld (VBlankAction), a
_LABEL_14E_:
ld a, (VBlankAction)
cp $02
jr z, _LABEL_14E_
ret
_LABEL_156_:
ld a, (VBlankAction)
or a
jr nz, _LABEL_156_
ld a, $04
ld (VBlankAction), a
_LABEL_161_:
ld a, (VBlankAction)
cp $04
jr z, _LABEL_161_
ret
_LABEL_169_:
ld a, $06
ld (VBlankAction), a
_LABEL_16E_:
ld a, (VBlankAction)
or a
jr nz, _LABEL_16E_
ret
_LABEL_175_:
ld hl, (TitleScreenCounterLow)
dec hl
ld (TitleScreenCounterLow), hl
ld a, l
or h
ret
; Jump Table from 17F to 1AE (24 entries, indexed by TableIndex1)
JumpTable1:
.dw JumpTable1_BD7 JumpTable1_BD7 JumpTable1_BEA JumpTable1_C6D
.dw SetUpGameAutoplay Origin JumpTable1_F4C JumpTable1_F4C
.dw JumpTable1_1058 JumpTable1_1127 JumpTable1_11A0 DoGameOver
.dw JumpTable1_1424 JumpTable1_1435 JumpTable1_152F JumpTable1_16F4
.dw JumpTable1_192B JumpTable1_1B20 JumpTable1_1CA8 JumpTable1_1CD0
.dw JumpTable1_1D11 JumpTable1_1D4B JumpTable1_153B JumpTable1_1566
VBlankHandler:
push af
in a, (VDPControl)
and $80
jp z, _LABEL_2D1_
ld a, ($FFFF) ; Save current mapper value
push af ; Save registers
push bc
push de
push hl
ex af, af'
exx
push af
push bc
push de
push hl
push ix
push iy
ld a, (VBlankAction)
ld hl, VBlankActionTable
jp CallJumpTable
; Jump Table from 1D1 to 1E6 (11 entries, indexed by VBlankAction)
VBlankActionTable:
.dw VBlankUpdateSound VBlankActionTable_20E VBlankActionTable_22F VBlankActionTable_26B
.dw VBlankActionTable_275 VBlankActionTable_29D VBlankActionTable_2AC VBlankUpdateSound
.dw VBlankUpdateSound VBlankUpdateSound VBlankUpdateSound
; 1st entry of Jump Table from 1D1 (indexed by VBlankAction)
VBlankUpdateSound:
ld hl, EndVBlank
push hl
ld a, $07
ld ($FFFF), a
ld a, ($C002)
or a
jp nz, SilencePSG
jp UpdateAllSound
EndVBlank:
pop iy
pop ix
pop hl
pop de
pop bc
pop af
ex af, af'
exx
pop hl
pop de
pop bc
pop af
ld ($FFFF), a
pop af
ei
ret
; 2nd entry of Jump Table from 1D1 (indexed by VBlankAction)
VBlankActionTable_20E:
call CheckForReset
call _LABEL_2DD_
call VDPOut_2E9
ld b, $00
-:
djnz -
ld a, (PaletteInRAMStatus)
and $01
call nz, WritePalette
xor a
ld (PaletteInRAMStatus), a
ld ($C01F), a
ld (VBlankAction), a
jr VBlankUpdateSound
; 3rd entry of Jump Table from 1D1 (indexed by VBlankAction)
VBlankActionTable_22F:
call CheckForReset
call _LABEL_2DD_
call VDPOut_2E9
call _LABEL_2802_
ld a, (PaletteInRAMStatus)
and $01
call nz, WritePalette
call _LABEL_30CC_
call _LABEL_28B2_
call _LABEL_30DF_
call _LABEL_28FD_
xor a
ld (PaletteInRAMStatus), a
ld ($C01F), a
ld a, (PlayerSpeed) ; Get player speed
or a ; Is player speed slow ($00)?
jr nz, PlayerSpeedIsFast ; If not (speed is fast/$FF), go here
ld hl, VBlankAction
inc (hl)
jp VBlankUpdateSound
PlayerSpeedIsFast:
ld hl, VBlankAction
ld (hl), $00
jp VBlankUpdateSound
; 4th entry of Jump Table from 1D1 (indexed by VBlankAction)
VBlankActionTable_26B:
call CheckForReset
xor a
ld (VBlankAction), a
jp VBlankUpdateSound
; 5th entry of Jump Table from 1D1 (indexed by VBlankAction)
VBlankActionTable_275:
ld a, $00
out (VDPControl), a
ld a, $88
out (VDPControl), a
call _LABEL_2DD_
call VDPOut_2E9
ld b, $00
-:
djnz -
ld a, (PaletteInRAMStatus)
and $01
call nz, WritePalette
xor a
ld (PaletteInRAMStatus), a
ld ($C01F), a
ld hl, VBlankAction
inc (hl)
jp VBlankUpdateSound
; 6th entry of Jump Table from 1D1 (indexed by VBlankAction)
VBlankActionTable_29D:
ld a, $00
out (VDPControl), a
ld a, $88
out (VDPControl), a
xor a
ld (VBlankAction), a
jp VBlankUpdateSound
; 7th entry of Jump Table from 1D1 (indexed by VBlankAction)
VBlankActionTable_2AC:
ld a, ($C0D2)
out (VDPControl), a
ld a, $89
out (VDPControl), a
call VDPOut_2E9
ld b, $00
-:
djnz -
ld a, (PaletteInRAMStatus)
and $01
call nz, WritePalette
xor a
ld (PaletteInRAMStatus), a
ld ($C01F), a
ld (VBlankAction), a
jp VBlankUpdateSound
_LABEL_2D1_:
ld a, ($C0B7)
out (VDPControl), a
ld a, $88
out (VDPControl), a
pop af
ei
ret
_LABEL_2DD_:
ld a, ($C014)
or a
ret z
dec a
jr z, _LABEL_2E7_
rst $28 ; Interrupt28
ret
_LABEL_2E7_:
rst $30 ; Interrupt30
ret
VDPOut_2E9:
ld c, VDPData
ld a, $00
out (VDPControl), a
ld a, $7F
out (VDPControl), a
ld hl, $C500
call OUTI64
ld a, $80
out (VDPControl), a
ld a, $7F
out (VDPControl), a
ld hl, $C540
call OUTI128
ret
CheckForReset:
in a, ($DD) ; Read input from port $DD
cpl ; Invert- now 1 is on
and %00010000 ; Check if RESET is on
jr z, NoReset ; If not, jump down
ld a, (CurrentlyResetting) ; If it is set, check CurrentlyResetting
or a ; Is it zero?
ret nz ; If already set, return
ld a, $FF ; If it is zero, set it to $FF
ld (CurrentlyResetting), a
jp DoReset
NoReset:
xor a ; Zero out a
ld (CurrentlyResetting), a ; Set CurrentlyResetting flag to zero
ret
UpdateControllerState:
ld a, (CurrentControllerState) ; Read previously stored controller state
cpl ; Invert- now 1 is off, as if it was read just from the port
ld d, a ; Save inverted input
in a, ($DC) ; Read from controller port
cpl ; Invert- now 1 is on
and %00111111 ; Mask off bits used for player 2 controller
ld (CurrentControllerState), a ; Store updated value in controller state
and d ; Get button press continued since last state
ld (LastControllerState), a ; Load into LastControllerState
ld a, (Autoplay) ; If autoplay is on, return
or a
ret z
dec a
jr z, _LABEL_33C_
jr _LABEL_384_
_LABEL_33C_:
ld a, (LastControllerState)
and %00110000 ; Check for A or B button press
jr z, _LABEL_35C_ ; If none, start autoplay
xor a ; Otherwise, zero out autoplay variables
ld (Autoplay), a
ld (AutoplayDirection), a
ld (AutoplayCountdownLow), a
ld (AutoplayCountdownHigh), a
ld (AutoplayVar3), a
call _LABEL_42C_
ld a, $02
ld (TableIndex1), a
ret
_LABEL_35C_:
ld hl, (AutoplayCountdownLow)
ld a, l
or h
jr nz, _LABEL_37C_
xor a
ld (Autoplay), a
ld (AutoplayDirection), a
ld (AutoplayCountdownLow), a
ld (AutoplayCountdownHigh), a
ld (AutoplayVar3), a
call _LABEL_42C_
ld a, $00
ld (TableIndex1), a
ret
_LABEL_37C_:
dec hl
ld (AutoplayCountdownLow), hl
ld a, h
cp $02
ret nc
_LABEL_384_:
ld a, (AutoplayVar3)
or a
jr z, _LABEL_3BE_
dec a
ld (AutoplayVar3), a
_LABEL_38E_:
ld a, (AutoplayDirection)
ld hl, Data_3DE
ld b, $04
Loop_396:
rrca
jr c, _LABEL_39F_
inc hl
inc hl
djnz Loop_396
jr _LABEL_3BE_
_LABEL_39F_:
ld e, (hl)
inc hl
ld d, (hl)
ld hl, ($C105)
add hl, de
ld a, (hl)
and $7F
jr z, _LABEL_3BE_
cp $06
jr c, _LABEL_3B3_
cp $0C
jr c, _LABEL_3BE_
_LABEL_3B3_:
ld a, (AutoplayDirection)
ld (CurrentControllerState), a
xor a
ld (LastControllerState), a
ret
_LABEL_3BE_:
ld d, $01
call GetRandomNumber
and $03
_LABEL_3C5_:
or a
jr z, _LABEL_3CD_
dec a
rlc d
jr _LABEL_3C5_
_LABEL_3CD_:
ld a, d
ld (AutoplayDirection), a
call GetRandomNumber
and $1F
add a, $10
ld (AutoplayVar3), a
jp _LABEL_38E_
; Data from 3DE to 3E5 (8 bytes)
Data_3DE:
.dw $FFE0 $0020 $FFFF $0001
_LABEL_3E6_:
ld ix, $C400
ld b, $08
jr ContinueFromSavedFunction
_LABEL_3EE_:
ld ix, $C100
ld b, $18
ContinueFromSavedFunction:
push bc
ld hl, _LABEL_403_
push hl
ld l, (ix+0)
ld h, (ix+1)
ld a, l
or h
ret z
jp (hl)
_LABEL_403_:
ld de, $0020
add ix, de
pop bc
djnz ContinueFromSavedFunction
ret
_LABEL_40C_:
call LoadPaletteToRAMMirror
_LABEL_40F_:
ld a, $01
ld (TableIndex3), a
ld hl, PaletteInRAM
ld de, $C021
ld bc, $001F
ld (hl), $00
ldir
ld hl, PaletteInRAMStatus
set 0, (hl)
ld a, $04
ld ($C0A2), a
ret
_LABEL_42C_:
ld a, $02
ld (TableIndex3), a
ld hl, PaletteInRAM
ld de, PaletteInRAM2
call LDI32
ld a, $04
ld ($C0A2), a
ret
; Data from 440 to 442 (3 bytes)
Data_440:
.db $CD $50 $07
_LABEL_443_:
ld a, $03
ld (TableIndex3), a
ld a, $3F
ld (PaletteInRAM), a
ld hl, PaletteInRAM
ld de, $C021
call LDI32
ld hl, PaletteInRAMStatus
set 0, (hl)
ld a, $04
ld ($C0A2), a
ret
_LABEL_461_:
ld a, $04
ld (TableIndex3), a
ld hl, PaletteInRAM
ld de, PaletteInRAM2
call LDI32
ld a, $04
ld ($C0A2), a
ret
_LABEL_475_:
ld c, (hl)
ld b, $00
ex de, hl
ld hl, PaletteInRAM
add hl, bc
ld ($C0A4), hl
inc de
ld a, (de)
ld ($C0A3), a
dec de
ex de, hl
call LoadPaletteToRAMMirror
ld a, $05
ld (TableIndex3), a
ld a, ($C0A3)
or a
jr z, _LABEL_4DC_
ld b, a
ld hl, ($C0A4)
xor a
-:
ld (hl), a
inc hl
djnz -
ld hl, PaletteInRAMStatus
set 0, (hl)
ld a, $04
ld ($C0A2), a
ret
_LABEL_4A9_:
ld a, $06
ld (TableIndex3), a
ld hl, PaletteInRAM
ld de, PaletteInRAM2
call LDI32
ld a, $04
ld ($C0A2), a
ret
_LABEL_4BD_:
ld hl, $C0A2
dec (hl)
ret nz
ld a, $04
ld ($C0A2), a
ld a, (TableIndex3)
or a
ret z
call CallJumpTable3
ld hl, PaletteInRAMStatus
set 0, (hl)
ld hl, $C0A1
inc (hl)
ld a, (hl)
cp $04
ret nz
_LABEL_4DC_:
xor a
ld ($C0A1), a
ld (TableIndex3), a
ret
CallJumpTable3:
ld a, (TableIndex3) ; Call func in jumptable based on TableIndex3
ld hl, JumpTable3
jp CallJumpTable
; Jump Table from 4ED to 4FA (7 entries, indexed by TableIndex3)
JumpTable3:
.dw Origin JumpTable3_4FB JumpTable3_504 JumpTable3_539
.dw JumpTable3_542 JumpTable3_580 JumpTable3_589
; 2nd entry of Jump Table from 4ED (indexed by TableIndex3)
JumpTable3_4FB:
ld a, ($C0A1)
ld d, a
ld a, $03
sub d
jr _LABEL_507_
; 3rd entry of Jump Table from 4ED (indexed by TableIndex3)
JumpTable3_504:
ld a, ($C0A1)
_LABEL_507_:
ld c, a
ld de, PaletteInRAM2
ld hl, PaletteInRAM
ld b, $20
_LABEL_510_:
push bc
ld a, (de)
and $03
sub c
jr nc, _LABEL_518_
xor a
_LABEL_518_:
ld (hl), a
rlc c
rlc c
ld a, (de)
and $0C
sub c
jr nc, _LABEL_524_
xor a
_LABEL_524_:
or (hl)
ld (hl), a
rlc c
rlc c
ld a, (de)
and $30
sub c
jr nc, _LABEL_531_
xor a
_LABEL_531_:
or (hl)
ld (hl), a
inc hl
inc de
pop bc
djnz _LABEL_510_
ret
; 4th entry of Jump Table from 4ED (indexed by TableIndex3)
; Title screen?
JumpTable3_539:
ld a, ($C0A1)
ld d, a
ld a, $03
sub d
jr _LABEL_545_
; 5th entry of Jump Table from 4ED (indexed by TableIndex3)
JumpTable3_542:
ld a, ($C0A1)
_LABEL_545_:
ld c, a
ld de, PaletteInRAM2
ld hl, PaletteInRAM
ld b, $20
Loop_54E:
push bc
ld a, (de)
and $03
add a, c
cp $04
jr c, _LABEL_559_
ld a, $03
_LABEL_559_:
ld (hl), a
rlc c
rlc c
ld a, (de)
and $0C
add a, c
cp $10
jr c, _LABEL_568_
ld a, $0C
_LABEL_568_:
or (hl)
ld (hl), a
rlc c
rlc c
ld a, (de)
and $30
add a, c
cp $40
jr c, _LABEL_578_
ld a, $30
_LABEL_578_:
or (hl)
ld (hl), a
inc hl
inc de
pop bc
djnz Loop_54E
ret
; 6th entry of Jump Table from 4ED (indexed by TableIndex3)
JumpTable3_580:
ld a, ($C0A1)
ld d, a
ld a, $03
sub d
jr _LABEL_58C_
; 7th entry of Jump Table from 4ED (indexed by TableIndex3)
JumpTable3_589:
ld a, ($C0A1)
_LABEL_58C_:
ld c, a
ld de, ($C0A4)
ld hl, $0040
add hl, de
ex de, hl
ld a, ($C0A3)
ld b, a
jp _LABEL_510_
VDPOut_59D:
ld de, $0000
ld hl, $0000
ld bc, $0010
call VDPOut_Loop_632
ld de, $2000
ld hl, $0000
ld bc, $0010
call VDPOut_Loop_632
ld de, $3800
ld hl, $0000
ld bc, $0380
call VDPOut_Loop_632
ld de, $3F00
ld a, $D0
ld bc, $0001
call VDPOut_618
ld hl, $C500
ld (hl), $D0
inc hl
ld de, $C502
ld (hl), $00
call LDI129
call LDI64
ret
_LABEL_5DE_:
ld hl, $C100
ld de, $C101
ld bc, $02FF
ld (hl), $00
ldir
ld de, $3F00
ld a, $D0
ld bc, $0001
call VDPOut_618
ld hl, $C500
ld (hl), $D0
inc hl
ld de, $C502
ld (hl), $00
call LDI129
call LDI64
ret
_LABEL_608_:
rst $08 ; Interrupt8
inc b
Loop_60A:
ld a, b
ld b, c
ld c, VDPData
_LABEL_60E_:
outi
jr nz, _LABEL_60E_
ld b, a
ld c, $00
djnz Loop_60A
ret
VDPOut_618:
ex af, af'
rst $08 ; Interrupt8
ex af, af'
inc b
push bc
ld b, c
jr _LABEL_623_
Loop_620:
push bc
ld b, $00
_LABEL_623_:
out (VDPData), a
nop
djnz -4
pop bc
djnz Loop_620
ret
; Unused?
_LABEL_62C_:
out ($BE), a
nop
djnz -5
ret
VDPOut_Loop_632:
rst $08 ; Interrupt8
inc b
ld d, c
ld c, VDPData
push bc ; Nested counters- rows and columns, maybe?
ld b, d
jr Inner_Loop_63E
Outer_Loop_63B:
push bc
ld b, $00
Inner_Loop_63E:
ld a, l
out (c), a
ld a, h