Skip to content

Commit

Permalink
fix #461
Browse files Browse the repository at this point in the history
  • Loading branch information
mateoconlechuga committed Nov 20, 2023
1 parent 269cd97 commit fa9a271
Showing 1 changed file with 61 additions and 24 deletions.
85 changes: 61 additions & 24 deletions src/fileioc/fileioc.asm
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ ti_IsArchived:
push bc
push de
call util_is_slot_open
jp nz, util_ret_null
jr z, util_is_in_ram
xor a, a
ret
util_is_in_ram:
call util_get_vat_ptr
ld hl, (hl)
Expand Down Expand Up @@ -621,14 +623,14 @@ ti_GetC:
push bc
push de
call util_is_slot_open
jp nz, util_ret_neg_one
jr nz, .ret_neg_one
call util_get_slot_size
push bc
call util_get_offset
pop hl
scf
sbc hl, bc ; size-offset
jp c, util_ret_neg_one
jr c, .ret_neg_one
push bc
call util_get_data_ptr
ld hl, (hl)
Expand All @@ -643,6 +645,11 @@ ti_GetC:
sbc hl, hl
ld l, a
ret
.ret_neg_one:
scf
sbc hl, hl
ld a, l
ret

;-------------------------------------------------------------------------------
ti_PutC:
Expand All @@ -661,31 +668,30 @@ ti_PutC:
ld a, e
ld (char_in), a
call util_is_slot_open
jp nz, util_ret_neg_one
jr nz, .ret_neg_one
call util_is_in_ram
jp c, util_ret_neg_one
_PutChar:
jr c, .ret_neg_one
call util_get_slot_size
push bc
call util_get_offset
pop hl
or a, a
sbc hl, bc
jp c, util_ret_neg_one
jr c, .ret_neg_one
jr nz, .no_increment
.increment:
push bc
inc hl
ld (resize_amount), hl
call ti.EnoughMem
pop bc
jp c, util_ret_neg_one
jr c, .ret_neg_one
push bc
ex de, hl
call util_insert_mem
pop bc
or a, a
jp z, util_ret_neg_one
jr z, .ret_neg_one
.no_increment:
call util_get_data_ptr
ld hl, (hl)
Expand All @@ -703,6 +709,11 @@ char_in := $-1
sbc hl, hl
ld l, a
ret
.ret_neg_one:
scf
sbc hl, hl
ld a, l
ret

;-------------------------------------------------------------------------------
ti_Seek:
Expand All @@ -718,14 +729,14 @@ ti_Seek:
ld de, (iy + 3)
ld c, (iy + 9)
call util_is_slot_open
jp nz, util_ret_neg_one
jr nz, .ret_neg_one
ld a, (iy + 6) ; origin location
or a, a
jr z, .seek_set
dec a
jr z, .seek_curr
dec a
jp nz, util_ret_neg_one
jr nz, .ret_neg_one
.seek_end:
push de
call util_get_slot_size
Expand All @@ -741,12 +752,16 @@ ti_Seek:
sbc hl, de
push de
pop bc
jp c, util_ret_neg_one
jr c, .ret_neg_one
jp util_set_offset
.seek_curr:
push de
call util_get_offset
jr .seek_set_asm
.ret_neg_one:
scf
sbc hl, hl
ret

;-------------------------------------------------------------------------------
ti_DeleteVar:
Expand Down Expand Up @@ -805,13 +820,17 @@ ti_Rewind:
push bc
push hl
call util_is_slot_open
jp nz, util_ret_neg_one
jr nz, .ret_neg_one
.rewind:
ld bc, 0
call util_set_offset
or a, a
sbc hl, hl
ret
scf
.ret_neg_one:
sbc hl, hl
ret

;-------------------------------------------------------------------------------
ti_Tell:
Expand All @@ -825,11 +844,14 @@ ti_Tell:
push bc
push hl
call util_is_slot_open
jp nz, util_ret_neg_one
jr nz, .ret_neg_one
call util_get_offset
push bc
pop hl
ret
.ret_neg_one:
sbc hl, hl
ret

;-------------------------------------------------------------------------------
ti_GetSize:
Expand All @@ -843,11 +865,14 @@ ti_GetSize:
push bc
push hl
call util_is_slot_open
jp nz, util_ret_neg_one
jr nz, .ret_neg_one
call util_get_slot_size
push bc
pop hl
ret
.ret_neg_one:
sbc hl, hl
ret

;-------------------------------------------------------------------------------
ti_Close:
Expand Down Expand Up @@ -1088,14 +1113,18 @@ ti_GetDataPtr:
push bc
push de
call util_is_slot_open
jp nz, util_ret_null
jr nz, .ret_null
call util_get_slot_size
inc hl
push hl
call util_get_offset
pop hl
add hl, bc
ret
.ret_null:
xor a, a
sbc hl, hl
ret

;-------------------------------------------------------------------------------
ti_GetVATPtr:
Expand All @@ -1109,10 +1138,14 @@ ti_GetVATPtr:
push bc
push de
call util_is_slot_open
jp nz, util_ret_null
jr nz, .ret_null
call util_get_vat_ptr
ld hl, (hl)
ret
.ret_null:
xor a, a
sbc hl, hl
ret

;-------------------------------------------------------------------------------
ti_GetName:
Expand Down Expand Up @@ -1345,20 +1378,23 @@ ti_RclVar:
ld iy,ti.flags
call util_set_var_str
call ti.FindSym
jp c, util_ret_neg_one_byte
jr c, .ret_neg_one
push af
call ti.ChkInRam
pop bc
ld a, b
jp nz, util_ret_neg_one_byte
jr nz, .ret_neg_one
ld iy, 0
add iy, sp
and a, $3f
sub a, (iy + 3) ; var type
jp nz, util_ret_neg_one_byte
jr nz, .ret_neg_one
ld hl, (iy + 9)
ld (hl), de
ret
.ret_neg_one:
ld a,-1
ret

;-------------------------------------------------------------------------------
ti_ArchiveHasRoom:
Expand Down Expand Up @@ -1499,7 +1535,11 @@ util_insert_mem:
call ti.EnoughMem
pop de
pop hl
jr c, util_ret_null_byte
jr nc, .enough_mem
pop hl
xor a, a
ret
.enough_mem:
call ti.InsertMem
pop hl
ld hl, (hl)
Expand Down Expand Up @@ -1544,9 +1584,6 @@ util_save_size:
util_ret_neg_one_byte:
ld a, 255
ret
util_ret_null_byte:
xor a, a
ret

util_ret_null_pop_ix:
pop ix
Expand Down

0 comments on commit fa9a271

Please sign in to comment.