This Apple DA: Don't use stack during RamWorks detection to preserve page 1

This commit is contained in:
Joshua Bell 2018-04-30 20:55:06 -07:00
parent f2f3e8467d
commit 558753bdc8

View File

@ -1098,10 +1098,8 @@ notpas:
ldx #0 ; bank we are checking ldx #0 ; bank we are checking
ldy #0 ; populated bank count ldy #0 ; populated bank count
loop: stx RWBANK ; select bank loop: stx RWBANK ; select bank
lda sigb0 ; save existing data copy sigb0, stash0 ; save existing data
pha ; on stack copy sigb1, stash1
lda sigb1
pha
txa ; bank number as first check byte txa ; bank number as first check byte
sta sigb0 sta sigb0
cmp sigb0 cmp sigb0
@ -1111,10 +1109,8 @@ loop: stx RWBANK ; select bank
cmp sigb1 cmp sigb1
bne :+ bne :+
iny ; found a bank, count it iny ; found a bank, count it
: pla ; restore saved data copy stash1, sigb1
sta sigb1 copy stash0, sigb0
pla
sta sigb0
inx ; next bank inx ; next bank
bne loop ; if we hit 256 banks, make sure we exit bne loop ; if we hit 256 banks, make sure we exit
@ -1133,17 +1129,13 @@ loop: stx RWBANK ; select bank
;; and testing that they work. We know that bank 1 is ;; and testing that they work. We know that bank 1 is
;; not an unpopulated RW bank. ;; not an unpopulated RW bank.
lda sigb0 ; Write signature to bank 0 copy sigb0, stash0 ; Write signature to bank 0
pha copy #0, sigb0
lda #0
sta sigb0
lda #1 ; Write signature to bank 1 lda #1 ; Write signature to bank 1
sta RWBANK sta RWBANK
lda sigb0 copy sigb0, stash1
pha copy #1, sigb0
lda #1
sta sigb0
lda #0 ; Check signature in bank 0 lda #0 ; Check signature in bank 0
sta RWBANK sta RWBANK
@ -1153,19 +1145,20 @@ loop: stx RWBANK ; select bank
: lda #1 ; Restore bank 1 : lda #1 ; Restore bank 1
sta RWBANK sta RWBANK
pla copy stash1, sigb0
sta sigb0
lda #0 ; Restore bank 0 lda #0 ; Restore bank 0
sta RWBANK sta RWBANK
pla copy stash0, sigb0
sta sigb0
;; Back to executing from aux memory ;; Back to executing from aux memory
done: sta RAMRDON done: sta RAMRDON
sta RAMWRTON sta RAMWRTON
plp ; restore interrupt state plp ; restore interrupt state
rts rts
stash0: .byte 0
stash1: .byte 0
.endproc .endproc
;;; ============================================================ ;;; ============================================================