4cade/src/hw.mockingboard.a

190 lines
4.5 KiB
Plaintext
Raw Normal View History

;license:MIT
2020-05-13 17:24:35 +00:00
;(c) 2019-2020 by Andrew Roughan, qkumba, 4am, Tom Charlesworth
;
; Mockingboard support functions
;
;------------------------------------------------------------------------------
2020-02-28 23:33:10 +00:00
; GetMockingboardStuff
; detect Mockingboard card by searching for 6522 timers across all slots 7->1
; access 6522 timers with deterministic cycle counts
;
; based on prior art in Mockingboard Developers Toolkit
; with optimisation from deater/french touch
; also takes into account FastChip //e clock difference
;
2020-03-05 17:38:53 +00:00
; in: A/Y contains address of callback to call if card was found
; (this will be called before the speech detection routine, and
; (zp$81 will contain the slot in form $Cx)
; /!\ ALL ACCELERATORS MUST BE OFF OR SET TO 1 MHZ
; out: if card was found, X = #$?n where n is the slot number of the card, otherwise #$00
2020-02-28 23:33:10 +00:00
; and bit 6 = 0 if Mockingboard Sound I found
; or bit 6 = 1 if Mockingboard Sound II or "A" found
; and bit 7 = 1 if Mockingboard Sound/Speech I or "C" found
; flags clobbered
; zp $80-$82 clobbered
; A/Y clobbered
;------------------------------------------------------------------------------
2020-02-28 23:33:10 +00:00
GetMockingboardStuff
2020-03-24 20:30:14 +00:00
+ST16 @callback+1
lda #$00
sta $80
2020-02-28 23:33:10 +00:00
sta $82 ; type
ldx #$C1
@slotLoop
stx $81
ldy #$04 ; 6522 #1 $Cx04
2020-02-28 23:33:10 +00:00
jsr @timercheck
beq @foundI
@nextSlot
inx
cpx #$C8
bne @slotLoop
ldx #$00 ; not found
rts
2020-02-28 23:33:10 +00:00
@foundI ; sound I or better
2020-03-05 17:38:53 +00:00
jsr @callback
2020-02-28 23:33:10 +00:00
ldy #$84 ; 6522 #2 $Cx84
jsr @timercheck
beq @foundII
ldy #$0c
2020-05-13 17:24:35 +00:00
sty @mb_smc1 + 1
2020-02-28 23:33:10 +00:00
iny
2020-05-18 15:21:16 +00:00
sty @mb_smc10 + 1
2020-02-28 23:33:10 +00:00
iny
2020-05-13 17:24:35 +00:00
sty @mb_smc5 + 1
2020-05-18 15:21:16 +00:00
sty @mb_smc14 + 1
2020-02-28 23:33:10 +00:00
+HIDE_NEXT_2_BYTES
@foundII ;stereo
ror $82
lda $81
sta @mb_smc1 + 2
sta @mb_smc2 + 2
sta @mb_smc3 + 2
sta @mb_smc4 + 2
sta @mb_smc5 + 2
sta @mb_smc6 + 2
sta @mb_smc7 + 2
sta @mb_smc8 + 2
sta @mb_smc9 + 2
sta @mb_smc10 + 2
sta @mb_smc11 + 2
sta @mb_smc12 + 2
2020-05-18 15:21:16 +00:00
sta @mb_smc13 + 2
sta @mb_smc14 + 2
2020-02-28 23:33:10 +00:00
; detect speech chip
sei
lda #<@mb_irq
sta $3fe
sta $fffe
lda #>@mb_irq
sta $3ff
sta $ffff
lda #$0c
2020-05-13 17:24:35 +00:00
@mb_smc1
2020-02-28 23:33:10 +00:00
sta $c48c
lda #$80
2020-05-13 17:24:35 +00:00
@mb_smc2
2020-02-28 23:33:10 +00:00
sta $c443
lda #$c0
2020-05-13 17:24:35 +00:00
@mb_smc3
2020-02-28 23:33:10 +00:00
sta $c440
lda #$70
2020-05-13 17:24:35 +00:00
@mb_smc4
2020-02-28 23:33:10 +00:00
sta $c443
lda #$82
2020-05-13 17:24:35 +00:00
@mb_smc5
2020-02-28 23:33:10 +00:00
sta $c48e
ldx #0
ldy #0
sec
cli
@wait_irq
lda $80
bne @got_irq
iny
bne @wait_irq
inx
bne @wait_irq
clc
@got_irq
sei
ror $82
@onlyI
2020-05-13 17:24:35 +00:00
ldy #$ff
@mb_smc6
sty $c403
lda #7
@mb_smc7
sta $c402
2020-05-18 15:21:16 +00:00
@mb_smc8
sty $c483
@mb_smc9
sta $c482
2020-05-13 17:24:35 +00:00
2020-05-18 15:21:16 +00:00
and $81
2020-02-28 23:33:10 +00:00
ora $82
tax
lda #<Ignore
sta $fffe
lda #>Ignore
sta $ffff
2020-05-11 16:58:22 +00:00
2020-05-13 17:24:35 +00:00
iny
2020-05-18 15:21:16 +00:00
sty $80
2020-05-11 16:58:22 +00:00
tya
sta ($80),y
lda #4
sta ($80),y
tya
ldy #$80
sta ($80),y
lda #4
sta ($80),y
2020-02-28 23:33:10 +00:00
rts ; found
@timercheck
sec
2020-02-28 23:33:10 +00:00
lda ($80),y ; read 6522 timer low byte
sbc ($80),y ; second time
cmp #5 ; looking for (-)8 cycles between reads
beq +
2020-02-28 23:33:10 +00:00
cmp #6 ; FastChip //e clock is different
+ rts
2020-02-28 23:33:10 +00:00
@mb_irq
lda #2
2020-05-18 15:21:16 +00:00
@mb_smc10
2020-02-28 23:33:10 +00:00
sta $c48d
2020-05-13 17:24:35 +00:00
lda #$80
2020-05-18 15:21:16 +00:00
@mb_smc11
2020-05-13 17:24:35 +00:00
sta $c443
lda #0
2020-05-18 15:21:16 +00:00
@mb_smc12
2020-02-28 23:33:10 +00:00
sta $c440
lda #$70
2020-05-18 15:21:16 +00:00
@mb_smc13
2020-02-28 23:33:10 +00:00
sta $c443
sta $80
lda #2
2020-05-18 15:21:16 +00:00
@mb_smc14
2020-05-13 17:24:35 +00:00
sta $c48e
2020-02-28 23:33:10 +00:00
lda $45
rti
2020-03-05 17:38:53 +00:00
@callback
jmp $FDFD ; SMC