-
Notifications
You must be signed in to change notification settings - Fork 1
/
mb-audit.a
2175 lines (1768 loc) · 37.9 KB
/
mb-audit.a
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
;license:MIT
;(c) 2021-2024 by Tom Charlesworth
;
; mb-audit:
; . Verify real h/w is operating correctly, eg. inter-component (addr/data line, IRQ)
; . Verify emulated h/w is operating correctly at a chip level, eg. chip functionality
;
; ACME 0.97
;
!cpu 6502 ; Compatible with all Apple2's
!to "mb-audit", plain
!sl "mb-audit.labels"
*=$2000
;------------------------------------------------------------------------------
!source "AppleDefs.a"
!source "MockingboardDefs.a"
;------------------------------------------------------------------------------
; Mockingboard types supported:
;
; $00 $80
; --------------------------------------------------------------------------
; Sound I 6522-A/AY8910 n/a
; Sound/Speech I 6522-A/SC01 6522-B/AY8910
; Sound II 6522-A/AY8910 6522-B/AY8910
; Speech I 6522-A/SC01
; MB-C
; . MB-C & clones 6522-A/AY8913 6522-B/AY8913 +[1|2x SSI263]
; . MB-C (AppleWin) MB-C +SC01 MB-C +[1|2x SSI263]
; . MB-C (MAME) MB-C +SC01 MB-C
; . MEGA Audio (a2heaven) MB-C MB-C 6522 & AY8913 implemented in FPGA, supports 2x MB-C's
; Phasor
; . MB-C 6522-A/AY8913 6522-B/AY8913 +[1|2x SSI263]
; . Echo+ 6522-B/AY8913 6522-B/AY8913 Same 6522 mapped to both $00 & $80
; . Phasor native 6522-A/AY8913x2 6522-B/AY8913x2 +[1|2x SSI263]
; . Phasor (AppleWin) Phasor +SC01 Phasor +[1|2x SSI263]
; Mockingboard 4c (Ian Kim) 6522-A/AY8913 6522-A/AY8913 Same 6522 mapped to both $00 & $80
; Echo+ 6522-A/AY8913 6522-A/AY8913 + TMS5220 (at DEVICE SELECT) NB. Same 6522 mapped to both $00 & $80
; SD Music (Ian Kim) 6522-A/AY8913 6522-A/AY8913 Same 6522 mapped to both $00 & $80
; SD Music Deluxe (Ian Kim) 6522-A/AY8913 6522-A/AY8913 Same 6522 mapped to both $00 & $80
;------------------------------------------------------------------------------
ZP_BASE = $f0
zpTmpPtr2 = $f2
zpTmpPtr2L = zpTmpPtr2
zpTmpPtr2H = zpTmpPtr2+1
zpTmpSrc = $f4
zpTmpSrcL = zpTmpSrc
zpTmpSrcH = zpTmpSrc+1
MBTimer = $f4
MBTimerL = MBTimer
MBTimerH = MBTimer+1
MBBase2 = $f6 ; alias with SSI263Base
MBBase2L = MBBase2
MBBase2H = MBBase2+1
SSI263Base = $f6
SSI263BaseL = SSI263Base
SSI263BaseH = SSI263Base+1
zpTmp6 = $f8
zpTmp5 = $f9
SpeechData = $f8
SpeechDataL = SpeechData
SpeechDataH = SpeechData+1
zpTmp4 = $fa
zpTmp3 = $fb
zpTmpPtr = $fa
zpTmpPtrL = zpTmpPtr
zpTmpPtrH = zpTmpPtr+1
zpTmp2 = $fc
zpTmp1 = $fd
String = $fc ; alias with zpTmp2 & zpTmp1
StringL = String
StringH = String+1
MBBase = $fe ; Mockingboard base
MBBaseL = MBBase
MBBaseH = MBBase+1
;------------------------------------------------------------------------------
!zone code
entrypoint
; Pre: TODO: disable accelerators or set to 1MHz
;
ldx #0 ; Callee can POKE 8193,%bitfield to configure behaviour
txa
and #1
sta cfgRebootOnExit ; b0: force reboot on exit
txa
lsr
tax
and #1
bne +
lda #NO_SOAK_TEST
bne ++
+ lda #SOAK_TEST
++ sta cfgDoSoakTest ; b1: soak test
;
sei
ldx #($ff-ZP_BASE)
- lda ZP_BASE,x
sta saveZP,x
dex
bpl -
ldx #2
- lda NMI,x
sta saveNMI,x
dex
bpl -
lda IRQL
sta saveIRQL
lda IRQH
sta saveIRQH
lda SOFTEV_L
sta saveRESETL
lda SOFTEV_H
sta saveRESETH
lda PWREDUP
sta savePWREDUP
;
!cpu 65816
sed
lda #$99
clc
adc #$01
cld
bmi @3
lda #1
clc
xce ; 65C02:NOP / 65816:exchange carry and emulation flags
bcc @1
xce
sta is65816
bra @2
@1 sta is65C02
@2 sta is65C02or65816
@3
!cpu 6502
lda VERSION
cmp #VERSION_IIE_OR_HIGHER
bne +
lda #1
sta hasLowerCase
+
jsr isIIc
bne +
; //c only: Enable MB4c (and disable mouse firmware). (mb-audit/GH#8)
lda #$ff
sta $C403 ; SY6522_DDRA
sta $C404 ; SY6522_TIMER1L_COUNTER - just writes to T1_LATCH(low)
+
lda TEXTON
lda MIXEDOFF
lda PAGE2OFF
lda HIRESOFF
jsr HOME ; perhaps better to clear to $00? ie. for floating-bus reads in GetSlotInfo()
jsr GetSlotInfo ; Scan all slots (7->1) for 6522(s) by calling Detect6522()
bne +
lda #<msg_NoMB
ldx #>msg_NoMB
jsr Print
jmp exit
+ lda #<msg_mbaudit
ldx #>msg_mbaudit
jsr Print
jsr Display
lda #<msg_cpu6502Detected
ldx #>msg_cpu6502Detected
ldy is65C02or65816
beq +
lda #<msg_cpu65C02Detected
ldx #>msg_cpu65C02Detected
ldy is65816
beq +
lda #<msg_cpu65816Detected
ldx #>msg_cpu65816Detected
+ jsr Print
jsr CROUT ; Blank line between "65??? detected Phasor mode=???" and test results
lda #0
sta totalTests+0
sta totalTests+1
sta totalTests+2
sta warningCount
sta numMegaAudioCards
lda #7
sta slotUnderTest
@nextSlot
ldx slotUnderTest
lda slotInfo,x
beq +
and #3
sta has6522
jsr DisplaySlotUpdate
ldx slotUnderTest
jsr Check6522 ; Basic 6522 checks - test both 6522s
bcc ++
jsr PrintTestFailedErrBytesBoth6522s
jmp exit
++ jsr DetectSubunits ; AY8913 & speech chips
jsr DisplayCardUpdate
;
jsr Test6522
bcs @error
jsr TestAY8913
bcs @error
jsr TestSSI263
bcs @error
jsr TestSC01
bcc ++
@error jsr PrintTestFailedErrBytes
lda testComponentNum
and #$f0
cmp #COMPONENT_AY8913
bne +++
jsr DumpAYRegs ; if AY8913 failed then dump all AY regs
+++ jmp exit
++ jsr PrintWarning ; if there's a warning then print it. Reset warningCount to 0.
;
+ dec slotUnderTest
bne @nextSlot
; Mult-card Test (MCT)
lda numMockingboards
cmp #2
bcc + ; (branch if A < 2)
jsr GetNumMBsForMCT ; calc numMockingboardsForMCT
lda #<msg_MultiCardSkipped
ldx #>msg_MultiCardSkipped
ldy numMegaAudioCards ; skip MCT if any MegaAudio cards
bne ++
ldy numMockingboardsForMCT
cpy #2
bcc ++ ; (branch if A < 2)
jsr Test6522MultiCard
bcs @error ; NB. slotUnderTest=0
lda #<msg_MultiCardOK
ldx #>msg_MultiCardOK
++ jsr Print
+
jsr TestReset
bcs @error
jsr TestTones
;
lda #<msg_OK
ldx #>msg_OK
jsr Print
ldx totalTests+2
jsr PRNTX
ldy totalTests+1
ldx totalTests+0
jsr PRNTYX
lda #$80+')'
jsr COUT
jsr CROUT
;
exit
lda saveRESETL
sta SOFTEV_L
lda saveRESETH
sta SOFTEV_H
lda savePWREDUP
sta PWREDUP
lda saveIRQL
sta IRQL
lda saveIRQH
sta IRQH
ldx #2
- lda saveNMI,x
sta NMI,x
dex
bpl -
ldx #($ff-ZP_BASE)
- lda saveZP,x
sta ZP_BASE,x
dex
bpl -
lda cfgRebootOnExit
beq +
lda #<msg_PressKeyToReboot
ldx #>msg_PressKeyToReboot
jsr Print
- lda KBD
bpl -
lda KBDSTRB
lda SOFTEV_H
sta PWREDUP ; force a system reboot (as PWREDUP = SOFTEV_H ^ $A5 to prevent reboot)
jmp ($fffc) ; reset vector
+
rts
;------------------------------------------------------------------------------
TestReset
; Post: C=0(OK), C=1(NG)
lda #7
sta slotUnderTest
TRMainLoop
ldx slotUnderTest
lda slotInfo,x
bne +
jmp TRNextSlot
+ and #3
sta has6522
jsr SetMBBase ; pre: X=slot#
jsr RestoreFromSlotInfo ; pre: X=slot#
;
; 1st CTRL+RESET test for this slot/card
;
lda #$f0
sta testNum ; test #f0
; Setup Phasor/SSI263 before 6522, as we don't want any 6522 timer ints active
jsr SetupPhasorWithSSI263ForReset
bcc +
jmp TestResetError ; test component $43
+ jsr Setup6522ForReset
bcc +
jmp TestResetError ; test component $13
+ jsr DisplaySlotUpdate
jsr PrintSlotNum
lda #<msg_PressReset
ldx #>msg_PressReset
jsr Print
tsx
lda #<TestResetLoop1
ldy #>TestResetLoop1
jsr SetupResetVector ; NB. do this after Print, as we save the text screen vars
lda #0
sta hasBeenReset
TestResetLoop1
- lda hasBeenReset
bne @test1
lda KBD
bpl -
bit KBDSTRB
cmp #$80+27
bne -
; ESC pressed - so skip this card
jsr TestResetSkip
jmp TRNextSlot
@test1 ; # of cycles to get here: [Enh//e] 0x1C941 (117,057 = 117ms)
lda #$f1
cmp testNum
beq TestResetStuckError
sta testNum ; test #f1
jsr Test6522AfterReset
bcs TestResetError ; test component $13
; Test Phasor/SSI263 after testing 6522 to ensure that none of the 6522 timer ints are active
jsr TestPhasorWithSSI263AfterReset
bcs TestResetError ; test component $43
jsr PrintWarning ; if there's a warning then print it. Reset warningCount to 0.
;
; 2nd CTRL+RESET test for this slot/card
;
lda isPhasorCard
beq TRNextSlot
lda #$f2
sta testNum ; test #f2
jsr SetupPhasorWithSSI263ForReset2
bcs TestResetError ; test component $43
lda #<msg_ResetMsg2
ldx #>msg_ResetMsg2
jsr Print
lda #<msg_PressReset
ldx #>msg_PressReset
jsr Print
tsx
lda #<TestResetLoop2
ldy #>TestResetLoop2
jsr SetupResetVector ; NB. do this after Print, as we save the text screen vars
lda #0
sta hasBeenReset
TestResetLoop2
- lda hasBeenReset
bne @test2
lda KBD
bpl -
bit KBDSTRB
cmp #$80+27
bne -
; ESC pressed - so skip this card
jsr TestResetSkip
jmp TRNextSlot
@test2 ; # of cycles to get here: [Enh//e] 0x1C941 (117,057 = 117ms)
lda #$f3
cmp testNum
beq TestResetStuckError
sta testNum ; test #f3
jsr TestPhasorWithSSI263AfterReset2
bcs TestResetError ; test component $43
; jsr PrintWarning ; if there's a warning then print it. Reset warningCount to 0.
;
TRNextSlot
dec slotUnderTest
beq +
jmp TRMainLoop
+
lda #<msg_ResetOK
ldx #>msg_ResetOK
jsr Print
@ok clc
rts
;------------------
TestResetStuckError ; Got stuck in an "after-reset" test!
lda #$ff
sta testNum ; test #ff
; fall through...
TestResetError
jsr TestResetSkip
sec
rts
; Restore to sensible state for: 6522 & SSI263 chips
TestResetSkip
jsr Skip6522ForReset
jsr SkipPhasorWithSSI263ForReset
rts
;------------------
ResetVector
lda #1
sta hasBeenReset
ldx #0
- lda saveZPTextVars,x
sta CH,x
inx
cpx #(BAS2H-CH)+1
bne -
ldx userlandSP
txs
ResetVector_smc
jmp TestResetLoop1
;------------------
SetupResetVector
; Pre: X=SP
; Y:A = &TestResetLoop1 or &TestResetLoop2
stx userlandSP
sta ResetVector_smc+1
sty ResetVector_smc+2
ldx #0
- lda CH,x
sta saveZPTextVars,x
inx
cpx #(BAS2H-CH)+1
bne -
lda #<ResetVector
sta SOFTEV_L
lda #>ResetVector
sta SOFTEV_H
eor #$A5
sta PWREDUP
rts
;------------------------------------------------------------------------------
TestTones
lda #<msg_ToneHelp
ldx #>msg_ToneHelp
jsr Print
; FLASH the "USE KEYS" start of this message:
ldy #7
- lda (BASL),y
cmp #$80+' ' ; special case for SPACE
bne +
lda #$80+$60
+ eor #$80 ; for letters: NORMAL -> FLASH
sta (BASL),y
dey
bpl -
jsr CROUT
;
lda CV
sta saveZPTextVars ; Use same line for all cards
lda #7
sta slotUnderTest
@loop ldx slotUnderTest
lda slotInfo,x
beq @nextSlot
!if 0 { ; has6522 not needed by TestAYTones or AYTonesISR
pha
and #HAS_BOTH_6522s
sta has6522
pla
}
jsr RestoreFromSlotInfo ; pre: X=slot#
; "Tone: "
jsr PrintSlotNumInvert
lda #<msg_ToneKeys
ldx #>msg_ToneKeys
jsr Print
; "A:123"
lda hasAY8913
and #1
beq +
lda #<msg_ToneKeysA123
ldx #>msg_ToneKeysA123
jsr Print
lda hasAY8913
and #%00001110 ; any more AYs?
beq @clreol
lda #$80+','
jsr COUT
+
; "B:456"
lda hasAY8913
and #2
beq +
lda #<msg_ToneKeysB456
ldx #>msg_ToneKeysB456
jsr Print
lda hasAY8913
and #%00001100 ; any more AYs?
beq @clreol
+
; ",A2:QWE,B2:RTY"
lda isPhasorCard
beq @clreol
lda #<msg_ToneKeysPhasor
ldx #>msg_ToneKeysPhasor
jsr Print
jmp + ; NB. No CR, since exactly 40 chars
@clreol jsr CLREOL ; clear to EOL
+ ; Use same line for all cards; and reset BASL for TestAYTones()
lda saveZPTextVars
sta CV ; update CV, as VTABZ doesn't
jsr VTABZ
lda #0
sta CH
jsr DisplaySlotUpdate
ldx slotUnderTest
jsr TestAYTones
@nextSlot
dec slotUnderTest
beq @done
jmp @loop
@done
ldy saveZPTextVars
dey
tya
sta CV ; update CV, as VTABZ doesn't
jsr VTABZ
jsr CLREOL ; erase the "USE KEYS: ..." message
jsr CROUT
jmp CLREOL ; erase the "Slot #? :Tone: A:123..." message
;------------------------------------------------------------------------------
DumpAYRegs
; Dump order is: 6522-A AY1 (and AY2), 6522-B AY1 (and AY2)
; For each AY show 2 rows:
; 1) current regs
; 2) writes values {0,1,...,D}, then read back & show
lda #<msg_DumpAYRegs
ldx #>msg_DumpAYRegs
jsr Print
lda isPhasorCard
beq +
lda #PH_PHASOR
jsr SetPhasorMode
+
ldy #SY6522_A_PH_BASE+SY6522_DDRB
lda #$1f ; OK to use this for Mockingboard too
sta (MBBase),y
ldy #SY6522_B_BASE+SY6522_DDRB
lda #$1f ; OK to use this for Mockingboard too
sta (MBBase),y
;
lda #<msg_dollar00
ldx #>msg_dollar00
jsr Print ; "$00:"
lda #SY6522_A_PH_BASE ; 6522 A (OK for Mockingboard too)
jsr @ReadRegsAndOutputForAY12
lda #<msg_dollar80
ldx #>msg_dollar80
jsr Print ; "$80:"
lda #SY6522_B_BASE ; 6522 B
jsr @ReadRegsAndOutputForAY12
;
lda isPhasorCard
beq +
lda #PH_MOCKINGBOARD
jsr SetPhasorMode
+
rts
;
@ReadRegsAndOutputForAY12
; Pre: A = 6522 chip select: SY6522_A_BASE, SY6522_A_PH_BASE, SY6522_B_BASE
; Post: Z = 1
sta zpTmp3
lda isPhasorCard
beq + ; $00: Mockingboard's AY
lda #$40 ; $40: Phasor's AY1
+ sta zpTmp4
- jsr AYReadRegs ; Post: zpTmpPtr2L,H = &ayRegs
jsr @OutputAYRegs
lda #<msg_ayCurr
ldx #>msg_ayCurr
jsr Print ; " (curr)",CR
jsr AYSetAndReadRegs ; Post: zpTmpPtr2L,H = &ayRegs
jsr @OutputAYRegs
lda #<msg_ayIncr
ldx #>msg_ayIncr
jsr Print ; " (incr)",CR
asl zpTmp4
bne - ; $80: branch only to do Phasor's AY2
rts
;
@OutputAYRegs
; Pre: zpTmpPtr2L,H = &ayRegs
lda #4
sta CH ; Start at H pos=4
lda #0
sta zpTmp2
- ldy zpTmp2
lda (zpTmpPtr2),y
tax
jsr PRNTX
inc zpTmp2
lda #AY_PORTA
cmp zpTmp2
bne -
rts
;------------------------------------------------------------------------------
GetSlotInfo
; Scan all slots for 6522s at $Cn00 and $Cn80
; Post: Z=1 (BEQ) if nothing found
lda #0
sta numMockingboards
ldx #7
- lda #0
sta slotInfo,x
jsr Detect6522
lda slotInfo,x
beq +
inc numMockingboards
+ dex
bne -
lda numMockingboards
rts
;------------------------------------------------------------------------------
GetNumMBsForMCT
; Post: Z=1 (BEQ) if nothing found
lda #0
sta numMockingboardsForMCT
ldx #7
- lda slotInfo,x
beq +
and #HAS_BOTH_6522s
cmp #HAS_BOTH_6522s
bne +
inc numMockingboardsForMCT
+ dex
bne -
rts
;------------------------------------------------------------------------------
SetMBBase
; Pre: X=slot#
; Post: X=slot#
txa
ora #$c0
sta MBBaseH
lda #SY6522_A_BASE
sta MBBaseL
rts
;------------------------------------------------------------------------------
DetectSubunits
; Detect Phasor card, AY8913, SSI263 & SC01
; Pre: zpTmp1 = slotInfo[slot]
lda #0
sta isSDMusic
sta isMegaAudioCard
sta isMB4C
sta isEchoPlus
sta isPhasorCard ; assume Mockingboard
sta hasSSI263 ; ... no SSI263's
sta hasSC01 ; ... no SC01
sta hasAY8913 ; ... no AY8913's
lda #PH_MOCKINGBOARD
sta phasorMode
lda zpTmp1
and #HAS_BOTH_6522s
cmp #HAS_BOTH_6522s
bne @doneCardDetection
; Determine if this is a MegaAudio
jsr DetectMegaAudioCard ; Post: Z=1 if no MegaAudio
beq +
inc numMegaAudioCards
bne @doneCardDetection
+
; Determine if this is a MB4C or Echo+ or SD Music card
; NB. if Phasor(Echo+ mode), then don't do the Phasor check - want to preserve the Echo+ mode for user
jsr DetectMB4CorEchoPlusorSDM ; Post: Z=1 if no MB4C/EchoPlus/SD Music
beq +
; Indicate there's only a 6522 at $Cn80, otherwise some 6522 tests will fail
; NB. For Phasor(Echo+ mode), CTRL+RESET will switch back to MB mode, so need to use 6522-B
ldx slotUnderTest
lda #HAS_6522B
sta slotInfo,x
sta has6522
sta zpTmp1
bne @doneCardDetection
+
; Determine if this is a Mockingboard or Phasor card
lda #$55
ldy #SY6522_DDRB
sta (MBBase),y
asl ; A=$AA
iny ; SY6522_DDRA
sta (MBBase),y
lda #PH_PHASOR
jsr SetPhasorMode
; Phasor card in Phasor-native mode has floating-bus at $Cn00-$Cn0F
ldy #SY6522_DDRB
lda #$55
cmp (MBBase),y
bne +
asl ; A=$AA
iny ; SY6522_DDRA
cmp (MBBase),y
bne +
ldy #SY6522_TIMER2L_COUNTER
jsr SF_GetTimerL
beq ++
+ inc isPhasorCard
++ lda #PH_MOCKINGBOARD
jsr SetPhasorMode
@doneCardDetection
;
jsr DetectSSI263 ; pre: zpTmp1
jsr DetectSC01 ; pre: zpTmp1
jsr DetectAY8913 ; pre: zpTmp1
lda hasAY8913
asl
asl
asl
asl
ldx slotUnderTest
ora slotInfo,x
ldy isrNMIcount_A
beq +
ora #NMI_FOR_6522A
+
ldy isrNMIcount_B
beq +
ora #NMI_FOR_6522B
+
sta slotInfo,x ; slotInfo[slot] |= (hasAY8913 << 4)
;
; set slotInfo2
;
ldy #CARDTYPE_SDMUSIC
lda isSDMusic
bne @setSlotInfo2
dey
lda isMegaAudioCard
bne @setSlotInfo2
dey
lda isMB4C
bne @setSlotInfo2
dey
lda isEchoPlus
bne @setSlotInfo2
dey
lda isPhasorCard
bne @setSlotInfo2
dey ; CARDTYPE_UNKNOWN
@setSlotInfo2
tya
sta slotInfo2,x
;
; set slotInfo3 - speech chips
;
lda hasSC01
asl
asl
ora hasSSI263
sta slotInfo3,x
rts
;------------------------------------------------------------------------------
RestoreFromSlotInfo
; pre: X=slot#
; post: hasAY8913; isSDMusic, isMegaAudioCard, isMB4C, isEchoPlus, isPhasorCard, phasorMode=PH_MOCKINGBOARD
lda slotInfo,x
lsr
lsr
lsr
lsr
sta hasAY8913
lda #PH_MOCKINGBOARD
sta phasorMode
;
lda slotInfo3,x
pha
and #SI3_SSI263_MASK
sta hasSSI263
pla
lsr
lsr
and #SI3_SC01_MASK
sta hasSC01
;
lda #0
sta isSDMusic
sta isMegaAudioCard
sta isMB4C
sta isEchoPlus
sta isPhasorCard
lda slotInfo2,x
ldx #1
and #CARDTYPE_MASK
tay
beq @done ; unknown
dey
beq @phasor
dey
beq @echoplus
dey
beq @mb4c
dey
beq @megaaudio
; fall through...
@sdmusic
stx isSDMusic
rts
@megaaudio
stx isMegaAudioCard
rts
@mb4c
stx isMB4C
rts
@echoplus
stx isEchoPlus
rts
@phasor