Skip to content

Commit 8c111d3

Browse files
read as many chunks as possible
1 parent 4c0a2c5 commit 8c111d3

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/fileioc/fileioc.asm

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -566,34 +566,34 @@ ti_Read:
566566
ld c, (iy + 12)
567567
call util_is_slot_open
568568
jr z, .ret0
569-
ld bc, (iy + 6)
570-
ld hl, (iy + 9)
571-
call __smulu
572-
add hl, de
573-
xor a, a
574-
sbc hl, de
575-
jr z, .ret0
576-
push hl ; hl = total size to read
577569
call util_get_slot_size
578570
push bc
579571
call util_get_offset
580572
pop hl
581573
or a, a
582574
sbc hl, bc ; size - offset = bytes left to read
583-
pop de ; if no bytes left, return
584575
jr z, .ret0
585576
jr c, .ret0
577+
ld bc, (iy + 6)
578+
call __sdivu ; (size - offset) / chunk_size
579+
ld de, (iy + 9) ; number of chunks to read, hl = number of chunks left
586580
or a, a
587581
sbc hl, de
588-
add hl, de ; check if left size <= read size
582+
add hl, de ; check if left <= read
589583
jr nc, .copy
590-
jr .ret0 ; otherwise just return if not enough read space
584+
ex de, hl
591585
.copy:
592-
push de
593-
call util_get_data_offset
586+
ex de, hl
587+
ld bc, (iy + 6)
588+
push hl
589+
call __smulu
590+
add hl, de
591+
or a, a
592+
sbc hl, de
593+
jr z, .ret0.pop
594+
push hl
594595
ld de, (iy + 3)
595596
pop bc
596-
push bc
597597
ldir
598598
call util_get_offset
599599
pop hl
@@ -603,8 +603,9 @@ ti_Read:
603603
call util_get_offset_ptr
604604
ld (hl), de
605605
pop hl
606-
ld bc, (iy + 6)
607-
jp __sdivu ; return actual chunks read
606+
ret ; return actual chunks read
607+
.ret0.pop:
608+
pop hl
608609
.ret0:
609610
xor a, a
610611
sbc hl, hl

0 commit comments

Comments
 (0)