This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
mg_notes:apple_iic:iic_bugs [2017/11/10 03:37] M.G. |
mg_notes:apple_iic:iic_bugs [2017/11/10 03:46] (current) M.G. |
||
---|---|---|---|
Line 78: | Line 78: | ||
sta data,x ; restore data | sta data,x ; restore data | ||
pla ; restore counter (net save 4 bytes) | pla ; restore counter (net save 4 bytes) | ||
- | beq tsnoram ; no RAM somehow! (if we fixed to find lonely bank 0, returned size would be wrong) | + | beq tsnoram ; no RAM somehow! |
bcs tsloop ; loop until we find a bank | bcs tsloop ; loop until we find a bank | ||
adc #1 ; C = 0 from compare | adc #1 ; C = 0 from compare | ||
+ | tsnoram sta numbanks,y | ||
+ | lsr a | ||
+ | sta sizetemp ; sizetemp = upper byte of block count | ||
+ | rts | ||
+ | </code> | ||
+ | |||
+ | We could use a couple of those bytes to fix the bank 0 issue: | ||
+ | |||
+ | <code> | ||
+ | testsize equ * | ||
+ | lda #0 ; zero address reg l/m | ||
+ | sta addrl,x | ||
+ | sta addrm,x | ||
+ | lda #$10 ; start at 1 meg and go down | ||
+ | sec | ||
+ | tsloop sbc #1 ; move down a bank | ||
+ | sta addrh,x | ||
+ | pha ; save counter, +1 byte code added | ||
+ | lda data,x ; save existing data | ||
+ | pha | ||
+ | dec addrl,x ; fix address (undo auto-increment) | ||
+ | lda #$a5 ; common apple check byte | ||
+ | sta data,x ; store it | ||
+ | dec addrl,x ; fix... | ||
+ | eor data,x ; 0 if the data is there | ||
+ | dec addrl,x ; fix... | ||
+ | cmp #1 ; C = 0 if data okay | ||
+ | pla | ||
+ | sta data,x ; restore data | ||
+ | pla ; restore counter (net save 4 bytes) | ||
+ | bcc tsgotram ; RAM found, extra branch net cost 2 bytes | ||
+ | beq tsnoram ; still won't find lonely bank 0 | ||
+ | bne tsloop ; loop until we find a bank | ||
+ | tsgotram adc #1 ; C = 0 from compare | ||
tsnoram sta numbanks,y | tsnoram sta numbanks,y | ||
lsr a | lsr a | ||
Line 108: | Line 142: | ||
sta data,x ; restore data | sta data,x ; restore data | ||
pla ; get counter back, sets N and Z, net save 4 bytes over existing code | pla ; get counter back, sets N and Z, net save 4 bytes over existing code | ||
+ | bcc tsgotram ; RAM found, extra branch net cost 2 bytes | ||
beq tsnoram ; still won't find lonely bank 0 | beq tsnoram ; still won't find lonely bank 0 | ||
- | bcs tsloop ; loop until we find a bank | + | bra tsloop ; loop until we find a bank |
- | adc #1 ; C = 0 from compare, could also use inc a | + | tsgotram: adc #1 ; C = 0 from compare, could also use inc a |
tsnoram: sta numbanks,y | tsnoram: sta numbanks,y | ||
lsr a | lsr a |