diff --git a/fat32/fat32.s b/fat32/fat32.s index 4f8aec12..9a62ebbb 100644 --- a/fat32/fat32.s +++ b/fat32/fat32.s @@ -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 @@ -3189,9 +3190,12 @@ 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 @@ -3199,6 +3203,42 @@ x16_banked_copy: 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 @@ -3478,9 +3518,12 @@ 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 @@ -3488,6 +3531,42 @@ fat32_write: 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 ;-----------------------------------------------------------------------------