Skip to content

Commit

Permalink
[FAT32] Avoid indexed access with base in IO range on 65C816 (X16Comm…
Browse files Browse the repository at this point in the history
…unity#355)

* [FAT32] Avoid indexed access with base in IO range on 65C816

* better label names

* simplify loop construct

* minor comment update

* correctly handle boundary case
  • Loading branch information
mooinglemur authored Aug 28, 2024
1 parent 17c25a1 commit 3ee434c
Showing 1 changed file with 76 additions and 8 deletions.
84 changes: 76 additions & 8 deletions fat32/fat32.s
Original file line number Diff line number Diff line change
Expand Up @@ -3185,20 +3185,54 @@ x16_banked_copy:
bne @nowrap
lda fat32_ptr+1
cmp #$bf ; only wrap when leaving page $BF
bne @nowrap
inx
lda #$9f
sta fat32_ptr+1
beq @wrapped
@nowrap:
cpy tmp_done
bne @loop
@end_banked_read:
; restore temporary zero page
stx bank_save
pla
sta krn_ptr1+1
pla
sta krn_ptr1
jmp fat32_read_cont1
@wrapped:
inx ; wrap bank
; ended on wrap boundary?
cpy tmp_done
beq @end_wrapped
; in order to avoid an indexed write into I/O space
; on the 65C816, which could have side effects, we
; resort to an alternate method here which avoids
; this condition, and is at least two cycles shorter
; in the loop construct, not counting the setup

; save old ptr low byte
lda fat32_ptr
pha

stz fat32_ptr
lda #$a0
sta fat32_ptr+1
@wrapped_loop:
lda (fat32_bufptr),y
stx ram_bank
sta (fat32_ptr)
stz ram_bank
iny
; we will always have less than 256 bytes to copy
; before loop end here, so we only ever need to increment
; the low byte of the destination ptr
inc fat32_ptr
cpy tmp_done
bne @wrapped_loop
pla
sta fat32_ptr
@end_wrapped:
lda #$9f
sta fat32_ptr+1
bra @end_banked_read

x16_stream_copy:
; move Y (bytecnt) into X for countdown
Expand Down Expand Up @@ -3474,20 +3508,54 @@ fat32_write:
bne @nowrap
lda fat32_ptr+1
cmp #$bf ; only wrap when leaving page $BF
bne @nowrap
inx
lda #$9f
sta fat32_ptr+1
beq @wrapped
@nowrap:
cpy tmp_done
bne @loop
@end_banked_write:
; restore temporary zero page
stx bank_save
pla
sta krn_ptr1+1
pla
sta krn_ptr1
jmp @4c
@wrapped:
inx ; wrap bank
; ended on wrap boundary?
cpy tmp_done
beq @end_wrapped
; in order to avoid an indexed read from I/O space
; on the 65C816, which could have side effects, we
; resort to an alternate method here which avoids
; this condition, and is at least two cycles shorter
; in the loop construct, not counting the setup

; save old ptr low byte
lda fat32_ptr
pha

stz fat32_ptr
lda #$a0
sta fat32_ptr+1
@wrapped_loop:
stx ram_bank
lda (fat32_ptr)
stz ram_bank
sta (fat32_bufptr),y
iny
; we will always have less than 256 bytes to copy
; before loop end here, so we only ever need to increment
; the low byte of the source ptr
inc fat32_ptr
cpy tmp_done
bne @wrapped_loop
pla
sta fat32_ptr
@end_wrapped:
lda #$9f
sta fat32_ptr+1
bra @end_banked_write


;-----------------------------------------------------------------------------
Expand Down

0 comments on commit 3ee434c

Please sign in to comment.