mockingboard: update detection code

This commit is contained in:
Vince Weaver 2018-02-05 13:48:37 -05:00
parent 2901c748d7
commit 0faa94473b
1 changed files with 49 additions and 15 deletions

View File

@ -158,45 +158,79 @@ clear_ay_right_loop:
; Attempts to time an instruction sequence with a 6522 ; Attempts to time an instruction sequence with a 6522
; ;
; If found, puts in bMB ; If found, puts in bMB
; OUT2: has address of Mockingboard ; MB_ADDRL:MB_ADDRH has address of Mockingboard
; returns X=0 if not found, X=1 if found
bMB EQU $03
OUT2 EQU $22 ; +$21
bGood EQU $FE ; 0 : ok / 1 : bad
Temp EQU $FF ;
mockingboard_detect: mockingboard_detect:
lda #0 lda #0
sta OUT2 sta MB_ADDRL
mb_detect_loop: ; self-modifying mb_detect_loop: ; self-modifying
lda #$07 ; we start in slot 7 ($C7) and go down to 0 ($C0) lda #$07 ; we start in slot 7 ($C7) and go down to 0 ($C0)
ora #$C0 ; make it start with C ora #$C0 ; make it start with C
sta OUT2+1 sta MB_ADDRH
ldy #04 ; $CX04 ldy #04 ; $CX04
ldx #02 ; 2 tries? ldx #02 ; 2 tries?
mb_check_cycle_loop: mb_check_cycle_loop:
lda (OUT2),Y ; timer 6522 (Low Order Counter) lda (MB_ADDRL),Y ; timer 6522 (Low Order Counter)
; count down ; count down
sta Temp ; 3 cycles sta TEMP ; 3 cycles
lda (OUT2),Y ; + 5 cycles = 8 cycles lda (MB_ADDRL),Y ; + 5 cycles = 8 cycles
; between the two accesses to the timer ; between the two accesses to the timer
sec sec
sbc Temp ; subtract to see if we had 8 cycles sbc TEMP ; subtract to see if we had 8 cycles
cmp #$f8 ; -8 cmp #$f8 ; -8
bne mb_not_in_this_slot bne mb_not_in_this_slot
dex ; decrement, try one more time dex ; decrement, try one more time
bne mb_check_cycle_loop ; loop detection bne mb_check_cycle_loop ; loop detection
inx ; Mockingboard found (X=1) inx ; Mockingboard found (X=1)
done_mb_detect: done_mb_detect:
stx bMB ; store result to bMB ;stx bMB ; store result to bMB
rts ; return rts ; return
mb_not_in_this_slot: mb_not_in_this_slot:
dec mb_detect_loop+1 ; decrement the "slot" (self_modify) dec mb_detect_loop+1 ; decrement the "slot" (self_modify)
bne mb_detect_loop ; loop down to one bne mb_detect_loop ; loop down to one
inc bGood ; didn't find?
ldx #00 ldx #00
beq done_mb_detect beq done_mb_detect
;=======================================
; Detect a Mockingboard card in Slot4
;=======================================
; Based on code from the French Touch "Pure Noise" Demo
; Attempts to time an instruction sequence with a 6522
;
; MB_ADDRL:MB_ADDRH has address of Mockingboard
; returns X=0 if not found, X=1 if found
mockingboard_detect_slot4:
lda #0
sta MB_ADDRL
mb4_detect_loop: ; self-modifying
lda #$04 ; we're only looking in Slot 4
ora #$C0 ; make it start with C
sta MB_ADDRH
ldy #04 ; $CX04
ldx #02 ; 2 tries?
mb4_check_cycle_loop:
lda (MB_ADDRL),Y ; timer 6522 (Low Order Counter)
; count down
sta TEMP ; 3 cycles
lda (MB_ADDRL),Y ; + 5 cycles = 8 cycles
; between the two accesses to the timer
sec
sbc TEMP ; subtract to see if we had 8 cycles
cmp #$f8 ; -8
bne mb4_not_in_this_slot
dex ; decrement, try one more time
bne mb4_check_cycle_loop ; loop detection
inx ; Mockingboard found (X=1)
done_mb4_detect:
rts ; return
mb4_not_in_this_slot:
ldx #00
beq done_mb4_detect