Skip to content

Commit 90fc5bc

Browse files
committed
save 1 more byte in util_ceil_byte_size_to_block_size
1 parent 27953b9 commit 90fc5bc

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/fatdrvce/fatdrvce.asm

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,16 +2519,13 @@ util_ceil_byte_size_to_block_size:
25192519
; - A:UHL
25202520
; output:
25212521
; - A:UHL = ceil(A:UHL / 512)
2522-
; - A = BCU = B = 0
2522+
; - A = 0
25232523
; destroys:
2524-
; - BC, flags
2524+
; - C, flags
25252525

2526-
; add 511 to A:UHL and shift the 33-bit result right by 9
2527-
ld bc,511
2528-
add hl,bc
2529-
dec b
2530-
adc a,b
2531-
rra
2526+
; UHL = A:UHL >> 9
2527+
ld c,l
2528+
srl a
25322529
push af
25332530
inc sp
25342531
push hl
@@ -2537,6 +2534,11 @@ util_ceil_byte_size_to_block_size:
25372534
inc sp
25382535
rr h
25392536
rr l
2537+
; round up if any shifted-out bits were non-zero
2538+
sbc a,a
2539+
or a,c
2540+
ret z
2541+
inc hl
25402542
xor a,a
25412543
ret
25422544

0 commit comments

Comments
 (0)