-
Notifications
You must be signed in to change notification settings - Fork 1
/
games_express_commented.asm
4609 lines (4593 loc) · 201 KB
/
games_express_commented.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
.code
.bank $000
.org $e000
gx_unknown_e000: ; bank: $000 logical: $e000
jmp gx_irq_reset ; $e000
jmp gx_proc_reset ; $e003
jmp gx_unknown_ea19 ; $e006
jmp gx_proc.wait_multiple ; $e009
jmp gx_proc_set_exec ; $e00c
jmp gx_unknown_e95b ; $e00f
jmp gx_proc_load ; $e012
jmp gx_unknown_e9cc ; $e015
jmp gx_unknown_e9d7 ; $e018
jmp gx_proc.wait_single ; $e01b
jmp gx_read_joypad ; $e01e
jmp gx_unpack ; $e021
jmp gx_vdc_load_vram ; $e024
jmp gx_unknown_ed03 ; $e027
jmp gx_unknown_ed07 ; $e02a
jmp gx_unknown_ed0b ; $e02d
jmp gx_unknown_ef12 ; $e030
jmp gx_unknown_ef02 ; $e033
jmp gx_cd_reset ; $e036
jmp gx_unknown_e17f ; $e039
jmp gx_cd_dinfo ; $e03c
jmp gx_unknown_fe3c ; $e03f
jmp gx_unknown_ff75 ; $e042
jmp gx_cd_fade ; $e045
jmp gx_scsi_cmd ; $e048
jmp gx_unknown_e33a ; $e04b
jmp gx_unknown_e6ea ; $e04e
jmp gx_unknown_e738 ; $e051
jmp gx_adpcm_reset ; $e054
jmp gx_unknown_e7a8 ; $e057
jmp gx_unknown_e7e7 ; $e05a
jmp gx_unknown_e817 ; $e05d
jmp gx_cd_play ; $e060
jmp gx_scsi_cmd ; $e063
jmp gx_irq_reset ; $e066
jmp gx_irq_reset ; $e069
jmp gx_irq_reset ; $e06c
jmp gx_irq_reset ; $e06f
jmp gx_irq_reset ; $e072
jmp gx_irq_reset ; $e075
jmp gx_irq_reset ; $e078
jmp gx_irq_reset ; $e07b
jmp gx_irq_reset ; $e07e
jmp gx_irq_reset ; $e081
jmp gx_irq_reset ; $e084
jmp gx_irq_reset ; $e087
jmp gx_unknown_fe11 ; $e08a
jmp gx_unknown_ff2f ; $e08d
jmp gx_vdc_clear_satb ; $e090
jmp lf9e5_00 ; $e093
jmp lf9ed_00 ; $e096
jmp gx_update_satb ; $e099
jmp gx_vdc_clear_satb_2 ; $e09c
jmp gx_display_init ; $e09f
jmp gx_vdc_enable_display ; $e0a2
jmp gx_vdc_disable_display ; $e0a5
jmp gx_clear_bat ; $e0a8
jmp gx_vdc_set_ctrl_hi ; $e0ab
jmp gx_unknown_f194 ; $e0ae
jmp lf22d_00 ; $e0b1
jmp gx_unknown_f1db ; $e0b4
jmp lf4a4_00 ; $e0b7
jmp lf4ce_00 ; $e0ba
jmp lf4fa_00 ; $e0bd
jmp lf518_00 ; $e0c0
jmp lf49f_00 ; $e0c3
jmp lf1b1_00 ; $e0c6
jmp gx_vdc_enable_interrupts ; $e0c9
jmp gx_vdc_set_control_reg ; $e0cc
jmp gx_vdc_set_yres ; $e0cf
jmp gx_vdc_set_bat_size ; $e0d2
jmp gx_unknown_f0c3 ; $e0d5
jmp gx_unknown_f596 ; $e0d8
jmp gx_unknown_f59e ; $e0db
jmp gx_unknown_f5aa ; $e0de
jmp lf5b7_00 ; $e0e1
jmp lf5c0_00 ; $e0e4
jmp gx_tile_addr ; $e0e7
jmp lf622_00 ; $e0ea
jmp lf6ad_00 ; $e0ed
jmp lf683_00 ; $e0f0
jmp lf7c7_00 ; $e0f3
jmp lfb5c_00 ; $e0f6
jmp lfb66_00 ; $e0f9
jmp lfbc3_00 ; $e0fc
jmp lfbf5_00 ; $e0ff
jmp gx_irq_reset ; $e102
jmp gx_irq_reset ; $e105
jmp gx_irq_reset ; $e108
jmp gx_irq_reset ; $e10b
jmp gx_irq_reset ; $e10e
jmp gx_irq_reset ; $e111
gx_info_string: ; bank: $000 logical: $e114
db "SYSTEM KERNEL REV 2reserv_tbl_0 1993/04/18",$0d,$0a
db "Created by Hack Technical Group",$0d,$0a
db "Special thanks to Ryo",$0d,$0a,$00
gx_write_cd_fade_timer: ; bank: $000 logical: $e179
and #$0f
sta cd_fade_timer
rts
; ----------------------------------------------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------------------------------------------
gx_unknown_e17f: ; bank: $000 logical: $e17f
stz <$20
lda #$35 ; output buffer lsb
sta <$21
lda #$22 ; output buffer msb
sta <$22
jsr gx_cd_dinfo ; get dir info de 00
tax
bne le19f_00
lda #$01
sta <$20
lda #$37 ; output buffer lsb
sta <$21
lda #$22 ; output buffer lsb
sta <$22
jsr gx_cd_dinfo ; get dir info de 01
tax
le19f_00: ; bank: $000 logical: $e19f
rts
; ----------------------------------------------------------------------------------------------------------------------
; Get DIR Info
; ----------------------------------------------------------------------------------------------------------------------
gx_cd_dinfo: ; bank: $000 logical: $e1a0
tii $2020, $2207, $0008
@loop: ; bank: $000 logical: $e1a7
jsr gx_scsi_clear_buffer
lda #$de
sta $2210
lda <$20
sta $2211
lda <$23
sta $2212
jsr gx_scsi_cmd
cmp #$c8
bne @end
lda #$04
sta <$23
stz <$24
jsr gx_unknown_e1e7
jsr gx_unknown_e4cd
tii $2207, $2020, $0008
cmp #$00
beq @end
jsr gx_unknown_e532
bcs @end
tii $2207, $2020, $0008
jmp @loop
@end: ; bank: $000 logical: $e1e6
rts
; ----------------------------------------------------------------------------------------------------------------------
; Read data?
; Warning this routine doesn't not remap the destination pointer.
; $2021, $2022 : address of the destination buffer
; $2023, $2024 : number of bytes to read
; ----------------------------------------------------------------------------------------------------------------------
gx_unknown_e1e7: ; bank: $000 logical: $e1e7
lda cd_port
and #$f8
sta $222f
cmp #$d8
beq @resp
cmp #$c8
beq @read
jmp gx_unknown_e1e7
@read: ; bank: $000 logical: $e1fa
cly
lda cd_command
sta [$21], Y
jsr gx_scsi_handshake
inc <$21
bne @l0
inc <$22
@l0: ; bank: $000 logical: $e209
sec
lda <$23
sbc #$01
sta <$23
lda <$24
sbc #$00
sta <$24
ora <$23
bne gx_unknown_e1e7
@resp: ; bank: $000 logical: $e21a
lda cd_port
and #$f8
sta $222f
and #$b8
cmp #$88
jsr gx_scsi_resp
rts
; ----------------------------------------------------------------------------------------------------------------------
; Reset CDROM
; ----------------------------------------------------------------------------------------------------------------------
gx_cd_reset: ; bank: $000 logical: $e22a
lda cd_reset ; setting bit 2 will reset CDROM hardware
ora #$02
sta cd_reset
lda #$01
jsr gx_cd_wait
lda cd_reset ; reset bit 2
and #$fd
sta cd_reset
ldx #$80 ; wait a little longer
@loop: ; bank: $000 logical: $e241
dex
bne @loop
rts
; ----------------------------------------------------------------------------------------------------------------------
; Test Unit Ready
; ----------------------------------------------------------------------------------------------------------------------
gx_cd_test_ready: ; bank: $000 logical: $e245
jsr gx_scsi_clear_buffer
stz $2210
jsr gx_scsi_cmd
jsr gx_unknown_e4cd ; get SCSI status code
cmp #$00
beq @ready
jsr gx_unknown_e532 ; process subcode error
sec ; and try to resend command if possible
rts
@ready: ; bank: $000 logical: $e25a
clc
rts
; ----------------------------------------------------------------------------------------------------------------------
; Clear scsi command buffer.
; ----------------------------------------------------------------------------------------------------------------------
gx_scsi_clear_buffer: ; bank: $000 logical: $e25c
stz $2211
tii $2211, $2212, $0008
rts
; ----------------------------------------------------------------------------------------------------------------------
; Wait 7962 cycles.
; This should be enough for CDROM to be ready.
; ----------------------------------------------------------------------------------------------------------------------
gx_cd_wait: ; bank: $000 logical: $e267
phx ; it will wait for A*(loop cycles)
phy
@l0: ; bank: $000 logical: $e269
ldx #$28 ; 2
@l1: ; bank: $000 logical: $e26b
ldy #$21 ; 2
@l2: ; bank: $000 logical: $e26d
dey ; 2
bne @l2 ; 4 (2 if the branch is not taken)
dex ; 2
bne @l1 ; 4 (2 if the branch is not taken)
dec A ; = 7962 cycles
bne @l0
ply
plx
rts
; ----------------------------------------------------------------------------------------------------------------------
; SCSI handshake
; ----------------------------------------------------------------------------------------------------------------------
gx_scsi_handshake: ; bank: $000 logical: $e279
lda #$80
tsb cd_control ; initiator (PCE) set /ACK signal to 1
@l0: ; bank: $000 logical: $e27e
lda cd_port ; wait for target (CD) to set /REQ signal to 0
and #$40
bne @l0
lda #$80 ; initiator (PCE) set /ACK signal to 0
trb cd_control
rts
; ----------------------------------------------------------------------------------------------------------------------
; Process SCSI command buffer
; ----------------------------------------------------------------------------------------------------------------------
gx_scsi_cmd: ; bank: $000 logical: $e28b
stz $220f
@retry: ; bank: $000 logical: $e28e
lda #$81 ; try to send command prefix $81, $ff
sta cd_command
tst #$80, cd_port
beq @go
lda #$60 ; flush command buffer
trb cd_control
sta cd_port
lda #$19
jsr gx_cd_wait
lda #$ff
sta cd_command
tst #$40, cd_port
beq @retry
; wait while the CD is busy
@l0: ; bank: $000 logical: $e2b1
jsr gx_scsi_handshake
@l1: ; bank: $000 logical: $e2b4
tst #$40, cd_port
bne @l0
tst #$80, cd_port
bne @l1
bra @retry
@go: ; bank: $000 logical: $e2c2
sta cd_port
clx
@busy: ; bank: $000 logical: $e2c6
lda cd_port
and #$40
bne @next
lda #$5a
@wait: ; bank: $000 logical: $e2cf
dec A
bne @wait
nop
dex
bne @busy
bra @retry
@next: ; bank: $000 logical: $e2d8
stz $222f
clx
@l2: ; bank: $000 logical: $e2dc
lda cd_port ; get cd status
and #$f8
sta $222f
cmp #$d0
beq @send
and #$b8
cmp #$98
beq le308_00
cmp #$88
beq le308_00
cmp #$80
beq le308_00
bra @l2
@send: ; bank: $000 logical: $e2f8
lda $2210, X ; send command buffer
inx
sta cd_command
nop
nop
nop
nop
jsr gx_scsi_handshake
bra @l2
le308_00: ; bank: $000 logical: $e308
lda $2206
bne le339_00
lda $2210
cmp #$d9
bne le31b_00
lda $2211
cmp #$01
beq le339_00
le31b_00: ; bank: $000 logical: $e31b
ldx <$33
le31d_00: ; bank: $000 logical: $e31d
lda cd_port
and #$f8
sta $222f
bit #$40
bne le339_00
txa
sec
sbc <$33
eor #$ff
inc A
cmp #$fe
bcc le31d_00
lda #$01
sta $220f
le339_00: ; bank: $000 logical: $e339
rts
gx_unknown_e33a: ; bank: $000 logical: $e33a
tii $2020, $2207, $0008
jsr gx_scsi_clear_buffer ; clears the 9 bytes starting at $2211
lda #$08
sta $2210
lda <$27
sta $2211
lda <$26
sta $2212
lda <$25
sta $2213
lda <$23
sta $2214
lda <$20
cmp #$ff
beq @vdc.copy
tma #$06 ; backup MPR 6
pha
jsr gx_scsi_cmd
cmp #$c8
bne @end
@loop: ; bank: $000 logical: $e36d
lda <$21 ; map CDROM RAM
tam #$06
lda #$00 ; dest: $c000
sta <$15
lda #$c0
sta <$16
lda #$00 ; len: 8 KBytes
sta <$17
lda #$20
sta <$18
jsr gx_cd_read
cmp #$88 ; check if the CD read is successful
bne @end
inc <$21 ; next 8KB RAM
lda <$23 ; we just read 8KB (4 sectors)
sec
sbc #$04
beq @end ; repeat until we read all sectors
bpl @loop
@end: ; bank: $000 logical: $e393
pla ; restore MPR 6
tam #$06
jsr gx_unknown_e4cd
cmp #$00
beq @quit
jsr gx_unknown_e532
bcs @quit
tii $2207, $2020, $0008
jmp gx_unknown_e33a
@quit: ; bank: $000 logical: $e3ac
stz $2246
rts
@vdc.copy: ; bank: $000 logical: $e3b0
jsr gx_scsi_cmd
cmp #$c8
bne @le3ed
cla
jsr gx_vdc_set_ctrl_hi ; copy data to VRAM
lda #$01
sta $2246
lda #$00
sta vdc_reg
sta video_reg_l
lda <$21
sta video_data_l
lda <$22
sta video_data_h
lda #$02
sta vdc_reg
sta video_reg_l
@le3da: ; bank: $000 logical: $e3da
lda #$00
sta <$17
lda #$08
sta <$18
jsr gx_cd_read_to_vdc
cmp #$88
bne @le3ed
dec <$23
bne @le3da
@le3ed: ; bank: $000 logical: $e3ed
jsr gx_unknown_e4cd
cmp #$00
beq @quit
jsr gx_unknown_e532
bcs @quit
tii $2207, $2020, $0008
jmp gx_unknown_e33a
gx_negate: ; bank: $000 logical: $e403
cla
sec
sbc <$17
sta <$17
cla
sbc <$18
sta <$18
rts
; ----------------------------------------------------------------------------------------------------------------------
; Read data from CD and store it to RAM.
; Parameters:
; $2017-18 : the number of bytes to read.
; $2015-16 : the memory address where the read data will be stored
;
; Return:
; A : CD status
; X : Remaining number of 256 bytes blocs in the current sector
; ----------------------------------------------------------------------------------------------------------------------
gx_cd_read: ; bank: $000 logical: $e40f
jsr gx_negate ; negates the number of bytes to read
@start: ; bank: $000 logical: $e412
lda cd_port ; wait until cdrom is ready
and #$f8
sta $222f
cmp #$c8
beq @ok ; data can be read
cmp #$d8
beq @end ; cd is unavailable
jmp @start
@ok: ; bank: $000 logical: $e425
lda <$15
ora <$16 ; is this some write overflow test?
beq @end
ldx #$02
@wait: ; bank: $000 logical: $e42d
nop ; wait ...
dex
bne @wait
cly
ldx #$08 ; you can't read more than 8*256 bytes (a whole sector)
@loop: ; bank: $000 logical: $e434
lda cd_data
sta [$15], Y
inc <$17 ; check if we read all the requested number of bytes
bne @next
inc <$18
beq @end
@next: ; bank: $000 logical: $e441
iny
bne @loop
inc <$16 ; we wrote 256 bytes, so we increase the MSB of the output pointer
dex ; check if we read a whole sector
bne @loop
bra @start
@end: ; bank: $000 logical: $e44b
lda cd_port
and #$f8
sta $222f
rts
; ----------------------------------------------------------------------------------------------------------------------
; Same as gx_cd_read_to_ram but the read bytes are transfered to the VDC.
; Note that the VDC write register must have been set beforehand.
; ----------------------------------------------------------------------------------------------------------------------
gx_cd_read_to_vdc: ; bank: $000 logical: $e454
jsr gx_negate
@start: ; bank: $000 logical: $e457
lda cd_port
and #$f8
sta $222f
cmp #$c8
beq @ok
cmp #$d8
beq @end
jmp @start
@ok: ; bank: $000 logical: $e46a
ldx #$02
@wait: ; bank: $000 logical: $e46c
nop
dex
bne @wait
cly
@loop: ; bank: $000 logical: $e471
lda cd_data
sta video_data_l, Y
say
inc A
and #$01
say
inc <$17
bne @loop
inc <$18
beq @end
bra @loop
@end: ; bank: $000 logical: $e486
lda cd_port
and #$f8
sta $222f
rts
le48f_00: ; bank: $000 logical: $e48f
cla
sec
sbc <$17
sta <$17
cla
sbc <$18
sta <$18
le49a_00: ; bank: $000 logical: $e49a
lda cd_port
and #$f8
sta $222f
cmp #$c8
beq le4ad_00
cmp #$d8
beq le4c4_00
jmp le49a_00
le4ad_00: ; bank: $000 logical: $e4ad
cly
lda cd_command
sta [$15], Y
jsr gx_scsi_handshake
inc <$15
bne le4bc_00
inc <$16
le4bc_00: ; bank: $000 logical: $e4bc
inc <$17
bne le49a_00
inc <$18
bne le49a_00
le4c4_00: ; bank: $000 logical: $e4c4
lda cd_port
and #$b8
sta $222f
rts
gx_unknown_e4cd: ; bank: $000 logical: $e4cd
lda $220f
beq le4db_00
stz $220f
jsr gx_cd_reset
lda #$06
rts
le4db_00: ; bank: $000 logical: $e4db
jsr gx_scsi_resp
jsr gx_unknown_e513
lda $2232
bne le4e9_00
stz $2233
le4e9_00: ; bank: $000 logical: $e4e9
rts
; ----------------------------------------------------------------------------------------------------------------------
; Process SCSI response
; ----------------------------------------------------------------------------------------------------------------------
gx_scsi_resp: ; bank: $000 logical: $e4ea
stz $2232
le4ed_00: ; bank: $000 logical: $e4ed
lda cd_port
and #$f8
sta $222f
cmp #$d8
beq le4ff_00
cmp #$f8
beq le50a_00
bra le4ed_00
le4ff_00: ; bank: $000 logical: $e4ff
lda cd_command
sta $2232
jsr gx_scsi_handshake
bra le4ed_00
le50a_00: ; bank: $000 logical: $e50a
lda cd_port
and #$b8
sta $222f
rts
; ----------------------------------------------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------------------------------------------
gx_unknown_e513: ; bank: $000 logical: $e513
php
sei
le515_00: ; bank: $000 logical: $e515
lda cd_port
and #$f8
cmp #$f8
beq le520_00
bra le515_00
le520_00: ; bank: $000 logical: $e520
lda cd_command
sta $222f
jsr gx_scsi_handshake
plp
le52a_00: ; bank: $000 logical: $e52a
lda cd_port
and #$80
bmi le52a_00
rts
; ----------------------------------------------------------------------------------------------------------------------
; Check if the error is recoverable or not.
; Parameters:
; A - SCSI sense keys.
;
; Return:
; C - the error is considered recoverable if the carry flag is set.
; ----------------------------------------------------------------------------------------------------------------------
gx_unknown_e532: ; bank: $000 logical: $e532
cmp #$06 ; unit attention
beq @err
cmp #$02 ; not ready
beq @err
tii $2210, $221b, $000a
jsr gx_unknown_e586
lda $2233
beq @err
cmp #$04 ; not ready
beq @no_ready
cmp #$11 ; data field incorrect
beq @err
cmp #$15 ; seek eerror
beq @err
cmp #$16 ; header read error
beq @err
cmp #$0b ; no disc
beq @ok
cmp #$0d ; cover open
beq @ok
cmp #$1c ; not a digital audio track
beq @ok
cmp #$1d ; not a cdrom data track
beq @ok
cmp #$20 ; invalid command
bcc @err
cmp #$23 ; ???
bcc @ok
cmp #$25 ; end of volume
beq @ok
cmp #$2a ; invalid parameter
beq @ok
cmp #$2c ; audio not playing
beq @ok
bra @err
@no_ready: ; bank: $000 logical: $e57f
sta $2231
@err: ; bank: $000 logical: $e582
clc
rts
@ok: ; bank: $000 logical: $e584
sec
rts
; ----------------------------------------------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------------------------------------------
gx_unknown_e586: ; bank: $000 logical: $e586
stz $2225
tii $2225, $2226, $0009
jsr gx_scsi_clear_buffer
lda #$00
sta $2210
lda #$0a
sta $2214
jsr gx_scsi_cmd
cmp #$c8
bne le5b7_00
lda #$25
sta <$15
lda #$22
sta <$16
lda #$0a
sta <$17
lda #$00
sta <$18
jsr le48f_00
le5b7_00: ; bank: $000 logical: $e5b7
jsr gx_unknown_e4cd
pha
cmp #$00
bne le5cb_00
lda $2227
sta $2230
lda $222e
sta $2233
le5cb_00: ; bank: $000 logical: $e5cb
pla
rts
; ----------------------------------------------------------------------------------------------------------------------
; CD Audio playback; Parameters:
; Parameters:
; $2020 - Play mode.
; $2025 - Start track number.
; $2026 - End track number.
;
; Return:
; A - 00 ok else sub error code.
; ----------------------------------------------------------------------------------------------------------------------
gx_cd_play: ; bank: $000 logical: $e5cd
tii $2020, $2207, $0008
le5d4_00: ; bank: $000 logical: $e5d4
jsr gx_scsi_clear_buffer
lda #$80
sta $2219
lda #$d8
sta $2210
lda <$25
sta $2212
jsr gx_scsi_cmd
jsr gx_unknown_e4cd
cmp #$00
beq le600_00
jsr gx_unknown_e532
bcc le5f6_00
rts
le5f6_00: ; bank: $000 logical: $e5f6
tii $2207, $2020, $0008
jmp le5d4_00
le600_00: ; bank: $000 logical: $e600
jsr gx_scsi_clear_buffer
lda #$d9
sta $2210
lda <$20
and #$07
sta $2211
lda #$80
sta $2219
lda <$26
sta $2212
jsr gx_scsi_cmd
cmp #$98
beq le63f_00
lda $2211
cmp #$04
bne le62a_00
lda $223b
le62a_00: ; bank: $000 logical: $e62a
sta $223b
cmp #$01
beq le660_00
cmp #$02
bne le63f_00
stz $2206
lda #$20
tsb cd_control
bra le660_00
le63f_00: ; bank: $000 logical: $e63f
lda $2211
cmp #$04
bne le649_00
sta $223b
le649_00: ; bank: $000 logical: $e649
jsr gx_unknown_e4cd
cmp #$00
beq le65f_00
jsr gx_unknown_e532
bcs le65f_00
tii $2207, $2020, $0008
jmp le600_00
le65f_00: ; bank: $000 logical: $e65f
rts
le660_00: ; bank: $000 logical: $e660
lda #$00
rts
le663_00: ; bank: $000 logical: $e663
lda #$3c
sta <$21
lda #$22
sta <$22
jsr le68e_00
lda $223c
beq le676_00
lda #$00
rts
le676_00: ; bank: $000 logical: $e676
jsr gx_scsi_clear_buffer
lda #$da ; pause
sta $2210
jsr gx_scsi_cmd
jsr gx_unknown_e4cd
cmp #$00
beq le68d_00
jsr gx_unknown_e532
bcc le663_00
le68d_00: ; bank: $000 logical: $e68d
rts
le68e_00: ; bank: $000 logical: $e68e
tii $2020, $2207, $0008
le695_00: ; bank: $000 logical: $e695
jsr gx_scsi_clear_buffer
lda #$dd ; read subchannel Q
sta $2210
lda #$0a
sta $2211
jsr gx_scsi_cmd
cmp #$c8
bne le6b4_00
lda #$0a
sta <$23
lda #$00
sta <$24
jsr gx_unknown_e1e7
le6b4_00: ; bank: $000 logical: $e6b4
jsr gx_unknown_e4cd
tax
beq le6c9_00
jsr gx_unknown_e532
bcs le6c9_00
tii $2207, $2020, $0008
jmp le695_00
le6c9_00: ; bank: $000 logical: $e6c9
rts
le6ca_00: ; bank: $000 logical: $e6ca
lda #$03
tsb adpcm_addr_ctrl
lda #$01
trb adpcm_addr_ctrl
lda #$02
trb adpcm_addr_ctrl
rts
gx_unknown_e6da: ; bank: $000 logical: $e6da
lda #$0c
tsb adpcm_addr_ctrl
lda #$04
trb adpcm_addr_ctrl
lda #$08
trb adpcm_addr_ctrl
rts
gx_unknown_e6ea: ; bank: $000 logical: $e6ea
lda adpcm_status
and #$01
bne le6f6_00
lda bram_lock
and #$04
le6f6_00: ; bank: $000 logical: $e6f6
tax
lda adpcm_addr_ctrl
and #$20
bne le703_00
lda adpcm_status
and #$08
le703_00: ; bank: $000 logical: $e703
rts
le704_00: ; bank: $000 logical: $e704
lda #$10
tsb adpcm_addr_ctrl
lda #$10
trb adpcm_addr_ctrl
rts
le70f_00: ; bank: $000 logical: $e70f
lda cd_port
and #$f8
sta $222f
cmp #$c8
beq le721_00
cmp #$d8
beq le72f_00
bra le70f_00
le721_00: ; bank: $000 logical: $e721
lda cd_data
sta adpcm_ram_offset
le727_00: ; bank: $000 logical: $e727
tst #$04, adpcm_status
bne le727_00
bra le70f_00
le72f_00: ; bank: $000 logical: $e72f
lda cd_port
and #$b8
sta $222f
rts
gx_unknown_e738: ; bank: $000 logical: $e738
tst #$03, adpcm_dma_ctrl ; ad_read ?
beq le742_00
lda #$ff
bra le793_00
le742_00: ; bank: $000 logical: $e742
tii $2020, $2207, $0008
le749_00: ; bank: $000 logical: $e749
tii $2021, cd_data, $0002
jsr le6ca_00
jsr gx_scsi_clear_buffer
lda #$08 ; read
sta $2210
lda <$27
sta $2211
lda <$26
sta $2212
lda <$25
sta $2213
lda <$23
sta $2214
jsr gx_scsi_cmd
cmp #$c8
bne le779_00
jsr le70f_00
le779_00: ; bank: $000 logical: $e779
jsr gx_unknown_e4cd
cmp #$00
beq le793_00
jsr gx_unknown_e532
bcs le793_00
tii $2207, $2020, $0008
lda $2233
cmp #$10
bcc le749_00
le793_00: ; bank: $000 logical: $e793
rts
gx_adpcm_reset: ; bank: $000 logical: $e794
lda #$80
sta adpcm_addr_ctrl
stz adpcm_addr_ctrl
stz adpcm_dma_ctrl
lda #$6f
trb cd_control ; clear all bits except bits 4 and 7
stz adpcm_playback_rate
rts
gx_unknown_e7a8: ; bank: $000 logical: $e7a8
jsr gx_adpcm_reset
le7ab_00: ; bank: $000 logical: $e7ab
jsr gx_unknown_e6ea
bne le7ab_00
tii $201a, cd_data, $0002
jsr gx_unknown_e6da
tii $201e, cd_data, $0002
jsr le704_00
lda adpcm_ram_offset
le7c7_00: ; bank: $000 logical: $e7c7
tst #$80, adpcm_status
bne le7c7_00
lda adpcm_ram_offset
sta [$1c]
inc <$1c
bne le7d8_00
inc <$1d
le7d8_00: ; bank: $000 logical: $e7d8
lda <$1e
bne le7de_00
dec <$1f
le7de_00: ; bank: $000 logical: $e7de
dec <$1e
lda <$1e
ora <$1f
bne le7c7_00
rts
gx_unknown_e7e7: ; bank: $000 logical: $e7e7
tst #$03, adpcm_dma_ctrl
bne le816_00
tii $201a, cd_data, $0002
jsr le6ca_00