@@ -858,17 +858,15 @@ fat_SetFileBlockOffset:
858858 add hl , de
859859 jq nc , .invalid
860860 ld de , (yfatFile.block_index)
861- or a , a
861+ xor a , a
862862 sbc hl , de
863863 ret z ; if at the same block position, done (return 0)
864864 add hl , de ; hl = new block_index, de = current block_index
865865
866866 ; check if block is within current cluster
867867 ; we can optimize by just changing the block position
868868 ld (yfatFile.block_index) , hl
869- ld a , (yfatFile.blocks_per_cluster)
870- dec a
871- cpl
869+ sub a , (yfatFile.blocks_per_cluster)
872870 ld c , a ; mask for number of blocks
873871 and a , l
874872 ld l , a
@@ -2298,16 +2296,14 @@ util_fat_read_write:
22982296 compare_hl_zero ; no more blocks left, exit
22992297 jq z , .return
23002298
2301- ld d , (xfatFile.blocks_per_cluster)
2302- ld a , d
2303- dec a
2304- and a , (xfatFile.block_index) ; mask off the number of blocks remaining in this cluster
2305- ld e , a
2306- ld a , d
2307- sub a , e
2308- ld de , 0
2309- ld e , a
2310- ex de , hl ; de = total remaining, hl = remaining in cluster
2299+ ex de , hl ; de = total remaining
2300+ xor a , a
2301+ sub a , (xfatFile.blocks_per_cluster) ; mask for number of blocks
2302+ or a , (xfatFile.block_index) ; mask the negative number of blocks remaining in this cluster
2303+ cpl
2304+ inc a
2305+ sbc hl , hl
2306+ ld l , a ; hl = remaining in cluster
23112307 compare_hl_de
23122308 jr nc , .singleclusterread
23132309.multicluster:
@@ -2343,11 +2339,9 @@ util_fat_read_write:
23432339 ld hl , (xfatFile.block_index)
23442340 add hl , de
23452341 ld (xfatFile.block_index) , hl
2346- ld h , (xfatFile.blocks_per_cluster)
2347- ld a , h
2342+ ld a , (xfatFile.blocks_per_cluster)
23482343 dec a
2349- and a , l
2350- or a , a ; if at end of cluster, get the next one
2344+ and a , l ; if at end of cluster, get the next one
23512345 call z , .getnextcluster
23522346.return:
23532347 ld hl , (xfatFile.block_index)
0 commit comments