@@ -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
289289assert 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)
@@ -354,17 +354,23 @@ ti_Open:
354354 jr c , .not_found
355355 call ti.ChkInRam
356356 jr z , .save_ptrs
357- or a , a
358- sbc hl , hl
359357 ex de , hl
358+ inc .s de ; clear UDE
360359 ld e , (hl)
361360 inc hl
362361 ld d , (hl)
363362 ex de , hl
364363 call ti.EnoughMem
365- jp c , util_ret_null_pop_ix
364+ jr c , .ret_null_pop_ix
366365 call util_unarchive
367366 jr .unarchive_var
367+
368+ .ret_null_pop_ix:
369+ pop ix
370+ xor a , a
371+ sbc hl , hl
372+ ret
373+
368374.no_append:
369375 call ti.ChkFindSym
370376 jr c , .not_found
@@ -375,14 +381,14 @@ ti_Open:
375381 ld a , (hl)
376382 cp a , 'r'
377383 pop hl
378- jp nz , util_ret_null_pop_ix
384+ jr nz , .ret_null_pop_ix
379385 call util_skip_archive_header
380386 jr .save_ptrs
381387.not_found:
382388 ld hl , (ix + 9 )
383389 ld a , (hl)
384390 cp a , 'r'
385- jp z , util_ret_null_pop_ix
391+ jr z , .ret_null_pop_ix
386392 or a , a
387393 sbc hl , hl
388394 ld a , 0
@@ -525,6 +531,7 @@ ti_Write:
525531 ld hl , (iy + 9 )
526532 ret
527533.ret0:
534+ util_ret_null:
528535 xor a , a
529536 sbc hl , hl
530537 ret
@@ -564,20 +571,19 @@ ti_Read:
564571 push bc
565572 call util_get_offset
566573 pop hl
567- or a , a
574+ xor a , a
568575 sbc hl , bc ; size - offset = bytes left to read
569- jr z , .ret0
576+ ret z ; jr z, .ret0
570577 jr c , .ret0
571578 ld bc , (iy + 6 )
572579 call ti._sdivu ; (size - offset) / chunk_size
573580 ld de , (iy + 9 ) ; number of chunks to read, hl = number of chunks left
574581 or a , a
575582 sbc hl , de
576583 add hl , de ; check if left <= read
577- jr nc , .copy
578- ex de , hl
579- .copy:
584+ jr c , .no_copy
580585 ex de , hl
586+ .no_copy:
581587 ld bc , (iy + 6 )
582588 push hl
583589 call ti._smulu
@@ -748,7 +754,16 @@ ti_Seek:
748754 push de
749755 pop bc
750756 jr c , .ret_neg_one
751- jp util_set_offset
757+ ; jp util_set_offset
758+ .util_set_offset:
759+ ; input:
760+ ; BC = offset
761+ ; output:
762+ ; HL = offset_ptr
763+ call util_get_offset_ptr
764+ ld (hl) , bc
765+ ret
766+
752767.seek_curr:
753768 push de
754769 call util_get_offset
@@ -758,6 +773,8 @@ ti_Seek:
758773 sbc hl , hl
759774 ret
760775
776+ util_set_offset := ti_Seek.util_set_offset
777+
761778;-------------------------------------------------------------------------------
762779ti_DeleteVar:
763780; deletes an arbitrary variable
@@ -799,6 +816,7 @@ ti_Delete:
799816 jp c , util_ret_null
800817 ld iy , ti. flags
801818 call ti.DelVarArc
819+ util_ret_neg_one:
802820 scf
803821 sbc hl , hl
804822 ret
@@ -908,9 +926,9 @@ ti_DetectVar:
908926; sp + 9 : type of variable to search for
909927; return:
910928; hl -> name of variable
911- ld hl , 9
912- add hl , sp
913- ld a , (hl)
929+ ld hl , 9
930+ add hl , sp
931+ ld a , (hl) ; (sp + 9 )
914932; jr ti_Detect.start ; emulated by dummifying next instruction:
915933 db $ fe ; ld a,ti.AppVarObj -> cp a,$3E \ dec d
916934assert ti.AppVarObj = $ 15
@@ -958,14 +976,6 @@ ti_Detect:
958976 jr c , .finish
959977 jr z , .finish
960978 add hl , de
961- jr .fcontinue
962-
963- .finish:
964- xor a , a
965- sbc hl , hl
966- pop ix
967- ret
968-
969979.fcontinue:
970980 push hl
971981 ld a , 0
@@ -976,6 +986,13 @@ ti_Detect:
976986 ld de , (ix + 12 )
977987 ld (de) , a
978988 jr .fgoodtype
989+
990+ .finish:
991+ xor a , a
992+ sbc hl , hl
993+ pop ix
994+ ret
995+
979996.fdetectnormal:
980997 cp a , ti.AppVarObj
981998.smc_type := $ - 1
@@ -1190,9 +1207,9 @@ ti_RenameVar:
11901207; a = 1 if new file already exists
11911208; a = 2 if old file does not exist
11921209; a = 3 if other error
1193- ld iy , 0
1194- add iy , sp
1195- ld a , (iy + 9 )
1210+ ld hl , 9
1211+ add hl , sp
1212+ ld a , (hl) ; (sp + 9)
11961213 ld iy , ti. flags ; probably not needed
11971214; jr ti_Rename.start ; emulated by dummifying next instruction
11981215 db $ fe ; ld a,appVarObj -> cp a,$3E \ dec d
@@ -1345,7 +1362,7 @@ ti_StoVar:
13451362 jr nz , .notcr
13461363.iscr:
13471364 call ti.FindSym
1348- jp c , .notcr ; fill it with zeros
1365+ jr c , .notcr ; fill it with zeros
13491366 and a , $ 3f
13501367 ex de , hl
13511368 call ti.Mov9OP1OP2
@@ -1371,10 +1388,13 @@ ti_RclVar:
13711388; sp + 9 : pointer to data structure pointer
13721389; return:
13731390; 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
1391+ ld hl , 3
1392+ add hl , sp
1393+ ld a , (hl) ; (sp + 3) var type
1394+ inc hl
1395+ inc hl
1396+ inc hl
1397+ ld hl , (hl) ; (sp + 6) pointer to data
13781398 ld iy , ti. flags
13791399 call util_set_var_str
13801400 call ti.FindSym
@@ -1544,7 +1564,7 @@ util_insert_mem:
15441564 pop hl
15451565 ld hl , (hl)
15461566 push hl
1547- ld de , 0
1567+ inc .s de ; clear UDE
15481568 ld e , (hl)
15491569 inc hl
15501570 ld d , (hl)
@@ -1567,7 +1587,7 @@ util_delete_mem:
15671587 pop hl
15681588 ld hl , (hl)
15691589 push hl
1570- ld de , 0
1590+ inc .s de ; clear UDE
15711591 ld e , (hl)
15721592 inc hl
15731593 ld d , (hl)
@@ -1585,17 +1605,6 @@ util_ret_neg_one_byte:
15851605 ld a , 255
15861606 ret
15871607
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-
15991608util_is_slot_open:
16001609; in:
16011610; c = slot
@@ -1685,7 +1694,7 @@ util_get_slot_size:
16851694; A
16861695 call util_get_data_ptr
16871696 ld hl , (hl)
1688- ld bc , 0
1697+ inc .s bc ; clear UBC
16891698 ld c , (hl)
16901699 inc hl
16911700 ld b , (hl)
@@ -1699,15 +1708,6 @@ util_get_offset:
16991708 ld bc , (hl)
17001709 ret
17011710
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-
17111711util_archive: ; properly handle garbage collects
17121712 ld iy , ti. flags
17131713 call ti.ChkFindSym
0 commit comments