Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 52 additions & 51 deletions src/fileioc/fileioc.asm
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ ti_OpenVar:
; sp + 9 : variable Type
; return:
; slot index if no error
ld iy, 0
add iy, sp
ld a, (iy + 9)
ld hl, 9
add hl, sp
ld a, (hl) ; (sp + 9)
; jr ti_Open.start ; emulated by dummifying next instruction
db $fe ; ld a,ti.AppVarObj -> cp a,$3e \ dec d
assert ti.AppVarObj = $15
Expand Down Expand Up @@ -343,7 +343,7 @@ ti_Open:
cp a,'a'
jr z,.mode
cp a,'w'
jp nz,util_ret_null_pop_ix
jr nz, .ret_null_pop_ix
.mode:
inc hl
ld a,(hl)
Expand All @@ -362,9 +362,16 @@ ti_Open:
ld d, (hl)
ex de, hl
call ti.EnoughMem
jp c, util_ret_null_pop_ix
jr c, .ret_null_pop_ix
call util_unarchive
jr .unarchive_var

.ret_null_pop_ix:
pop ix
xor a, a
sbc hl, hl
ret

.no_append:
call ti.ChkFindSym
jr c, .not_found
Expand All @@ -375,14 +382,14 @@ ti_Open:
ld a, (hl)
cp a, 'r'
pop hl
jp nz, util_ret_null_pop_ix
jr nz, .ret_null_pop_ix
call util_skip_archive_header
jr .save_ptrs
.not_found:
ld hl, (ix + 9)
ld a, (hl)
cp a, 'r'
jp z, util_ret_null_pop_ix
jr z, .ret_null_pop_ix
or a, a
sbc hl, hl
ld a, 0
Expand Down Expand Up @@ -525,6 +532,7 @@ ti_Write:
ld hl, (iy + 9)
ret
.ret0:
util_ret_null:
xor a, a
sbc hl, hl
ret
Expand Down Expand Up @@ -574,10 +582,9 @@ ti_Read:
or a, a
sbc hl, de
add hl, de ; check if left <= read
jr nc, .copy
ex de, hl
.copy:
jr c, .no_copy
ex de, hl
.no_copy:
ld bc, (iy + 6)
push hl
call ti._smulu
Expand Down Expand Up @@ -748,7 +755,16 @@ ti_Seek:
push de
pop bc
jr c, .ret_neg_one
jp util_set_offset
; jp util_set_offset
.util_set_offset:
; input:
; BC = offset
; output:
; HL = offset_ptr
call util_get_offset_ptr
ld (hl), bc
ret

.seek_curr:
push de
call util_get_offset
Expand All @@ -758,6 +774,8 @@ ti_Seek:
sbc hl, hl
ret

util_set_offset := ti_Seek.util_set_offset

;-------------------------------------------------------------------------------
ti_DeleteVar:
; deletes an arbitrary variable
Expand Down Expand Up @@ -799,6 +817,7 @@ ti_Delete:
jp c, util_ret_null
ld iy, ti.flags
call ti.DelVarArc
util_ret_neg_one:
scf
sbc hl, hl
ret
Expand Down Expand Up @@ -908,9 +927,9 @@ ti_DetectVar:
; sp + 9 : type of variable to search for
; return:
; hl -> name of variable
ld hl,9
add hl,sp
ld a,(hl)
ld hl, 9
add hl, sp
ld a, (hl) ; (sp + 9)
; jr ti_Detect.start ; emulated by dummifying next instruction:
db $fe ; ld a,ti.AppVarObj -> cp a,$3E \ dec d
assert ti.AppVarObj = $15
Expand Down Expand Up @@ -958,14 +977,6 @@ ti_Detect:
jr c, .finish
jr z, .finish
add hl, de
jr .fcontinue

.finish:
xor a, a
sbc hl, hl
pop ix
ret

.fcontinue:
push hl
ld a, 0
Expand All @@ -976,6 +987,13 @@ ti_Detect:
ld de, (ix + 12)
ld (de), a
jr .fgoodtype

.finish:
xor a, a
sbc hl, hl
pop ix
ret

.fdetectnormal:
cp a, ti.AppVarObj
.smc_type := $-1
Expand Down Expand Up @@ -1190,9 +1208,9 @@ ti_RenameVar:
; a = 1 if new file already exists
; a = 2 if old file does not exist
; a = 3 if other error
ld iy, 0
add iy, sp
ld a, (iy + 9)
ld hl, 9
add hl, sp
ld a, (hl) ; (sp + 9)
ld iy, ti.flags ; probably not needed
; jr ti_Rename.start ; emulated by dummifying next instruction
db $fe ; ld a,appVarObj -> cp a,$3E \ dec d
Expand Down Expand Up @@ -1345,7 +1363,7 @@ ti_StoVar:
jr nz, .notcr
.iscr:
call ti.FindSym
jp c, .notcr ; fill it with zeros
jr c, .notcr ; fill it with zeros
and a, $3f
ex de, hl
call ti.Mov9OP1OP2
Expand All @@ -1371,10 +1389,13 @@ ti_RclVar:
; sp + 9 : pointer to data structure pointer
; return:
; a = type of variable
ld iy, 0
add iy, sp
ld hl, (iy + 6) ; pointer to data
ld a, (iy + 3) ; var type
ld hl, 3
add hl, sp
ld a, (hl) ; (sp + 3) var type
inc hl
inc hl
inc hl
ld hl, (hl) ; (sp + 6) pointer to data
ld iy,ti.flags
call util_set_var_str
call ti.FindSym
Expand Down Expand Up @@ -1585,17 +1606,6 @@ util_ret_neg_one_byte:
ld a, 255
ret

util_ret_null_pop_ix:
pop ix
util_ret_null:
xor a, a
sbc hl, hl
ret
util_ret_neg_one:
scf
sbc hl, hl
ret

util_is_slot_open:
; in:
; c = slot
Expand Down Expand Up @@ -1685,7 +1695,7 @@ util_get_slot_size:
; A
call util_get_data_ptr
ld hl, (hl)
ld bc, 0
inc.s bc ; clear UBC
ld c, (hl)
inc hl
ld b, (hl)
Expand All @@ -1699,15 +1709,6 @@ util_get_offset:
ld bc, (hl)
ret

util_set_offset:
; input:
; BC = offset
; output:
; HL = offset_ptr
call util_get_offset_ptr
ld (hl), bc
ret

util_archive: ; properly handle garbage collects
ld iy, ti.flags
call ti.ChkFindSym
Expand Down
Loading