Skip to content

Commit

Permalink
[FAT32] Avoid indexed access with base in IO range on 65C816
Browse files Browse the repository at this point in the history
  • Loading branch information
mooinglemur committed Aug 27, 2024
1 parent 17c25a1 commit defac78
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions fat32/fat32.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.include "lib.inc"
.include "sdcard.inc"
.include "text_input.inc"
.include "65c816.inc"

.import sector_buffer, sector_buffer_end, sector_lba, sdcard_set_fast_mode

Expand Down Expand Up @@ -3189,16 +3190,55 @@ x16_banked_copy:
inx
lda #$9f
sta fat32_ptr+1
set_carry_if_65c816
bcs @816_9f_page
@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
@816_9f_page:
; early exit
cpy tmp_done
beq @end_banked_read
; 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
lda fat32_ptr+1
pha
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
pla
sta fat32_ptr+1
bra @end_banked_read

x16_stream_copy:
; move Y (bytecnt) into X for countdown
Expand Down Expand Up @@ -3478,16 +3518,55 @@ fat32_write:
inx
lda #$9f
sta fat32_ptr+1
set_carry_if_65c816
bcs @816_9f_page
@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 @4c
@816_9f_page:
; early exit
cpy tmp_done
beq @end_banked_read
; 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 a cycle shorter
; in the loop construct, not counting the setup

; save old ptr
lda fat32_ptr+1
pha
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
pla
sta fat32_ptr+1
bra @end_banked_read


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

0 comments on commit defac78

Please sign in to comment.