Skip to content

Commit 27caed9

Browse files
committed
optimized fileioc
1 parent 0d032c5 commit 27caed9

File tree

1 file changed

+52
-51
lines changed

1 file changed

+52
-51
lines changed

src/fileioc/fileioc.asm

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ ti_OpenVar:
281281
; sp + 9 : variable Type
282282
; return:
283283
; slot index if no error
284-
ld iy, 0
285-
add iy, sp
286-
ld a, (iy + 9)
284+
ld hl, 9
285+
add hl, sp
286+
ld a, (hl) ; (sp + 9)
287287
; jr ti_Open.start ; emulated by dummifying next instruction
288288
db $fe ; ld a,ti.AppVarObj -> cp a,$3e \ dec d
289289
assert ti.AppVarObj = $15
@@ -343,7 +343,7 @@ ti_Open:
343343
cp a,'a'
344344
jr z,.mode
345345
cp a,'w'
346-
jp nz,util_ret_null_pop_ix
346+
jr nz, .ret_null_pop_ix
347347
.mode:
348348
inc hl
349349
ld a,(hl)
@@ -362,9 +362,16 @@ ti_Open:
362362
ld d, (hl)
363363
ex de, hl
364364
call ti.EnoughMem
365-
jp c, util_ret_null_pop_ix
365+
jr c, .ret_null_pop_ix
366366
call util_unarchive
367367
jr .unarchive_var
368+
369+
.ret_null_pop_ix:
370+
pop ix
371+
xor a, a
372+
sbc hl, hl
373+
ret
374+
368375
.no_append:
369376
call ti.ChkFindSym
370377
jr c, .not_found
@@ -375,14 +382,14 @@ ti_Open:
375382
ld a, (hl)
376383
cp a, 'r'
377384
pop hl
378-
jp nz, util_ret_null_pop_ix
385+
jr nz, .ret_null_pop_ix
379386
call util_skip_archive_header
380387
jr .save_ptrs
381388
.not_found:
382389
ld hl, (ix + 9)
383390
ld a, (hl)
384391
cp a, 'r'
385-
jp z, util_ret_null_pop_ix
392+
jr z, .ret_null_pop_ix
386393
or a, a
387394
sbc hl, hl
388395
ld a, 0
@@ -525,6 +532,7 @@ ti_Write:
525532
ld hl, (iy + 9)
526533
ret
527534
.ret0:
535+
util_ret_null:
528536
xor a, a
529537
sbc hl, hl
530538
ret
@@ -574,10 +582,9 @@ ti_Read:
574582
or a, a
575583
sbc hl, de
576584
add hl, de ; check if left <= read
577-
jr nc, .copy
578-
ex de, hl
579-
.copy:
585+
jr c, .no_copy
580586
ex de, hl
587+
.no_copy:
581588
ld bc, (iy + 6)
582589
push hl
583590
call ti._smulu
@@ -748,7 +755,16 @@ ti_Seek:
748755
push de
749756
pop bc
750757
jr c, .ret_neg_one
751-
jp util_set_offset
758+
; jp util_set_offset
759+
.util_set_offset:
760+
; input:
761+
; BC = offset
762+
; output:
763+
; HL = offset_ptr
764+
call util_get_offset_ptr
765+
ld (hl), bc
766+
ret
767+
752768
.seek_curr:
753769
push de
754770
call util_get_offset
@@ -758,6 +774,8 @@ ti_Seek:
758774
sbc hl, hl
759775
ret
760776

777+
util_set_offset := ti_Seek.util_set_offset
778+
761779
;-------------------------------------------------------------------------------
762780
ti_DeleteVar:
763781
; deletes an arbitrary variable
@@ -799,6 +817,7 @@ ti_Delete:
799817
jp c, util_ret_null
800818
ld iy, ti.flags
801819
call ti.DelVarArc
820+
util_ret_neg_one:
802821
scf
803822
sbc hl, hl
804823
ret
@@ -908,9 +927,9 @@ ti_DetectVar:
908927
; sp + 9 : type of variable to search for
909928
; return:
910929
; hl -> name of variable
911-
ld hl,9
912-
add hl,sp
913-
ld a,(hl)
930+
ld hl, 9
931+
add hl, sp
932+
ld a, (hl) ; (sp + 9)
914933
; jr ti_Detect.start ; emulated by dummifying next instruction:
915934
db $fe ; ld a,ti.AppVarObj -> cp a,$3E \ dec d
916935
assert ti.AppVarObj = $15
@@ -958,14 +977,6 @@ ti_Detect:
958977
jr c, .finish
959978
jr z, .finish
960979
add hl, de
961-
jr .fcontinue
962-
963-
.finish:
964-
xor a, a
965-
sbc hl, hl
966-
pop ix
967-
ret
968-
969980
.fcontinue:
970981
push hl
971982
ld a, 0
@@ -976,6 +987,13 @@ ti_Detect:
976987
ld de, (ix + 12)
977988
ld (de), a
978989
jr .fgoodtype
990+
991+
.finish:
992+
xor a, a
993+
sbc hl, hl
994+
pop ix
995+
ret
996+
979997
.fdetectnormal:
980998
cp a, ti.AppVarObj
981999
.smc_type := $-1
@@ -1190,9 +1208,9 @@ ti_RenameVar:
11901208
; a = 1 if new file already exists
11911209
; a = 2 if old file does not exist
11921210
; a = 3 if other error
1193-
ld iy, 0
1194-
add iy, sp
1195-
ld a, (iy + 9)
1211+
ld hl, 9
1212+
add hl, sp
1213+
ld a, (hl) ; (sp + 9)
11961214
ld iy, ti.flags ; probably not needed
11971215
; jr ti_Rename.start ; emulated by dummifying next instruction
11981216
db $fe ; ld a,appVarObj -> cp a,$3E \ dec d
@@ -1345,7 +1363,7 @@ ti_StoVar:
13451363
jr nz, .notcr
13461364
.iscr:
13471365
call ti.FindSym
1348-
jp c, .notcr ; fill it with zeros
1366+
jr c, .notcr ; fill it with zeros
13491367
and a, $3f
13501368
ex de, hl
13511369
call ti.Mov9OP1OP2
@@ -1371,10 +1389,13 @@ ti_RclVar:
13711389
; sp + 9 : pointer to data structure pointer
13721390
; return:
13731391
; a = type of variable
1374-
ld iy, 0
1375-
add iy, sp
1376-
ld hl, (iy + 6) ; pointer to data
1377-
ld a, (iy + 3) ; var type
1392+
ld hl, 3
1393+
add hl, sp
1394+
ld a, (hl) ; (sp + 3) var type
1395+
inc hl
1396+
inc hl
1397+
inc hl
1398+
ld hl, (hl) ; (sp + 6) pointer to data
13781399
ld iy,ti.flags
13791400
call util_set_var_str
13801401
call ti.FindSym
@@ -1585,17 +1606,6 @@ util_ret_neg_one_byte:
15851606
ld a, 255
15861607
ret
15871608

1588-
util_ret_null_pop_ix:
1589-
pop ix
1590-
util_ret_null:
1591-
xor a, a
1592-
sbc hl, hl
1593-
ret
1594-
util_ret_neg_one:
1595-
scf
1596-
sbc hl, hl
1597-
ret
1598-
15991609
util_is_slot_open:
16001610
; in:
16011611
; c = slot
@@ -1685,7 +1695,7 @@ util_get_slot_size:
16851695
; A
16861696
call util_get_data_ptr
16871697
ld hl, (hl)
1688-
ld bc, 0
1698+
inc.s bc ; clear UBC
16891699
ld c, (hl)
16901700
inc hl
16911701
ld b, (hl)
@@ -1699,15 +1709,6 @@ util_get_offset:
16991709
ld bc, (hl)
17001710
ret
17011711

1702-
util_set_offset:
1703-
; input:
1704-
; BC = offset
1705-
; output:
1706-
; HL = offset_ptr
1707-
call util_get_offset_ptr
1708-
ld (hl), bc
1709-
ret
1710-
17111712
util_archive: ; properly handle garbage collects
17121713
ld iy, ti.flags
17131714
call ti.ChkFindSym

0 commit comments

Comments
 (0)