Skip to content

Commit

Permalink
simplify loop construct
Browse files Browse the repository at this point in the history
  • Loading branch information
mooinglemur committed Aug 27, 2024
1 parent 7c09111 commit b2cb19a
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions fat32/fat32.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
.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 @@ -3186,12 +3185,7 @@ 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
set_carry_if_65c816
bcs @816_9f_page
beq @wrapped
@nowrap:
cpy tmp_done
bne @loop
Expand All @@ -3203,8 +3197,9 @@ x16_banked_copy:
pla
sta krn_ptr1
jmp fat32_read_cont1
@816_9f_page:
; early exit
@wrapped:
inx ; wrap bank
; ended on wrap boundary
cpy tmp_done
beq @end_banked_read
; in order to avoid an indexed write into I/O space
Expand All @@ -3213,9 +3208,7 @@ x16_banked_copy:
; 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
; save old ptr low byte
lda fat32_ptr
pha

Expand All @@ -3236,7 +3229,7 @@ x16_banked_copy:
bne @wrapped_loop
pla
sta fat32_ptr
pla
lda #$9f
sta fat32_ptr+1
bra @end_banked_read

Expand Down Expand Up @@ -3514,12 +3507,7 @@ 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
set_carry_if_65c816
bcs @816_9f_page
beq @wrapped
@nowrap:
cpy tmp_done
bne @loop
Expand All @@ -3531,8 +3519,9 @@ fat32_write:
pla
sta krn_ptr1
jmp @4c
@816_9f_page:
; early exit
@wrapped:
inx ; wrap bank
; ended on wrap boundary?
cpy tmp_done
beq @end_banked_write
; in order to avoid an indexed read from I/O space
Expand All @@ -3541,9 +3530,7 @@ fat32_write:
; 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
; save old ptr low byte
lda fat32_ptr
pha

Expand All @@ -3564,7 +3551,7 @@ fat32_write:
bne @wrapped_loop
pla
sta fat32_ptr
pla
lda #$9f
sta fat32_ptr+1
bra @end_banked_write

Expand Down

0 comments on commit b2cb19a

Please sign in to comment.