Calculator Community > ASM

ASM Delvar - Clean and free up from BASIC variables

(1/6) > >>

Galandros:
Coded this morning. Not that useful but just some practise and wanted to do.
This is an assembly version of DelVar ADelVar B(...)DelVar /theta/.

Features for now:
- custom builds
- small, fast and stable
- TI-83+ and some TI-83 compatibility

Suggested uses:
 - include in your custom asm library to TI-BASIC, this is a faster and smaller way to clean up variables after use
 - can be also used in APPS that allocate memory, through bcall(_InsertMem), and in the case it has not enough memory (prompting the user or not is up to you),
try to free enough memory to execute.

Source Code:

Make sure you have a complete ti83plus.inc and ti83.inc. especially the ti83.inc. Check the src folder in the zip file attached.

- Deletes variables real and complex variables from A to Z and Theta

--- Code: ---#ifdef TI83
#undefine DELARCVARS ; bcall(_DelVarArc) not documented in TI83
#undefine ZEROANS
#endif

;Delete Real and Complex Vars from A to Z and Theta
deleteAtoZaTheta:
#ifdef ZEROANS
bcall(_OP1Set0) ; This will set OP1 to FP 0 ( .db 0,$80,0,0,0,0,0,0,0)
bcall(_StoAns) ; Ans will be equal 0 (Ans can be a huge list or string and take huge space)
#else
bcall(_ZeroOP1) ; OP1 needs to be zeroed or it will not work for some reason
#endif
call deleteAZ ; (OP1) = RealObj = $00 because OP1 is zeroed
deleteAZcplx:
ld a,CplxObj
ld (OP1+0),a
deleteAZ:
ld a,tA
deleteAZloop:
push af
ld (OP1+1),a
bcall(_FindSym) ; look up
jr c,sdelarcAZ
#ifndef DELARCVARS
#ifndef TI83 ; TI-83 does not have flash
inc b ;\
dec b ; | if b!=0 (it is in flash), then skip
jr nz,sdelarcAZ ;/
#endif
bcall(_DelVar) ; delete variable only if in RAM
#else
bcall(_DelVarArc)
#endif
sdelarcAZ:
pop af
inc a
cp tTheta+1
jr nz,deleteAZloop
ret

;OPTIMIZE TRY: use ld hl,OP1, push and pop hl in deleAZloop
;and other changes but is exactly the same size

deleteAtoZaThetaEnd:

 .echo "code size: ",deleteAtoZaThetaEnd-deleteAtoZaTheta

--- End code ---

- Deletes many variables: A-Z and Theta, L1-L6, [A]-[Z], Y1-Y6, X1T-X6T, Y1T-Y6T, r1-r6 and u-w.
- DOES NOT WORK WITH TI-83 besides has some #if's for TI-83 in my attempt to work

--- Code: ---;Clean Up Basic Variables
;all numbers A-Z and /theta/, lists L1 to L6, matrices [A]-[J], Ans, graphics functions
;detects real and complex numbers or lists
CleanUpBASICvars:
#ifndef TI83
bcall(_CleanAll) ; delete all temp variables
#endif
#ifdef ZEROANS
bcall(_OP1Set0) ; This will set OP1 to FP 0 ( .db 0,$80,0,0,0,0,0,0,0)
bcall(_StoAns) ; Ans will be equal 0 (Ans can be a huge list or string and take huge space)
#else
bcall(_ZeroOP1) ; OP1 needs to be zeroed or it will not work for some reason
#endif
ld ix,OP1 ; the pointer
ld d,0 ; a flag for activate equ create with 0 bytes (needed to not crash TI-OS)
; it is preserved in deletevars2
ld c,d ; c = RealObj = $00
ld a,tA ; (OP1+0) = $00 = RealObj, already
ld b,tTheta+1
call deletevars2
ld c,CplxObj
ld a,tA
; ld b,tTheta+1 ; it was preserved!
call deletevars2

;these vars have 3 bytes, so a smart solution is coded
inc ix
ld e,d ; e = RealObj = $00
ld c,tVarLst
ld a,tL1
ld b,tL6+1
call deletevars3
ld e,CListObj
; ld c,tVarLst ; it was preserved!
ld a,tL1
; ld b,tL6+1 ; it was preserved!
call deletevars3
ld e,MatObj
ld c,tVarMat
ld a,tMatA
ld b,tMatJ+1
call deletevars3

inc d ; activate bcall(_Create0Equ)
ld e,EquObj
ld c,tVarEqu
ld a,tY1
ld b,tY0+1
call deletevars3
; ld e,EquObj
; ld c,tVarEqu ; it was preserved!
ld a,tX1T ;\tX1T to tX6T
ld b,tY6T+1 ;/tY1T to tY6T
call deletevars2
; ld e,EquObj
; ld c,tVarEqu ; it was preserved!
ld a,tR1
ld b,tR6+1
call deletevars2
; ld e,EquObj
; ld c,tVarEqu ; it was preserved!
ld a,tun
ld b,twn+1
;fall back

deletevars3:
ld (ix-1),e
deletevars2:
ld (ix+0),c
deletevarloop:
push af
push bc
push de ; all preserved
ld (ix+1),a
bcall(_FindSym) ; look up
jr c,sdelarc ; if doesn't exist, then skip
#ifndef DELARCVARS
#ifndef TI83 ; TI-83 does not have flash
inc b ;\
dec b ; | if b!=0 (it is in flash), then skip
jr nz,sdelarc ;/
#endif
bcall(_DelVar) ; delete variable only if in RAM
#else
bcall(_DelVarArc) ; delete variable archived or not
#endif
sdelarc:
pop de
inc d ;\
dec d ; | if d=0, then we don't need to recreate the equation var
jr z,notequvar ;/
bcall(_Create0Equ) ; OP1 destroyed, OP4 has variable name
bcall(_OP4toOP1) ; restore OP1 ^^
notequvar:
pop bc
pop af
inc a
cp b ; b holds the end value
jr nz,deletevarloop ; if we arrived b, then return
ret

; ld hl,OPFomarts
; rst 20h ; rMov9ToOP1 ; OP1 is variable
;OPFomarts:
; .db RealObj,tA,0,0,0,0,0,0,0
; .db CplxObj,tTheta,0,0
; .db RealObj,tVarLst,tL1,0
; .db CListObj,tVarLst,tL6,0
; .db MatObj, tVarMat, tMatA, 0
; .db MatObj, tVarMat, tMatJ, 0
; .db EquObj, tVarEqu, tY1, 0
; tY1 to tY9 and tY0, tX1T to tX6T, tY1T to tY6T, tR1 to tR6, tun, tvn, twn
; if graph equations do not exist, TI-OS will crash
;delete with bcall(_DelVar) and bcall(_Create0Equ)
; NewEquObj, what it does???

;ToDo:
;ClearEntries
;clear GDBs, Pics, Strs
;LRESID
;http://wikiti.brandonw.net/?title=83Plus:BCALLs:5041

cleanupBASICvarsend:

 .echo "code size: ",cleanupBASICvarsend-cleanupBASICvars

--- End code ---

EDIT: rewritten post with recent code

DJ Omnimaga:
interesting, I wonder how fast will it be compared to using several dozens of delvar commands, since it is actually larger than those delvar commands? (81 bytes total for all 27 vars). Does it also delete archived vars?

jsj795:
I think since this is assembly, it will be faster? And I'm also curious about if it deletes archived vars.

DJ Omnimaga:
Well it would be faster code-wise, but just the action of doing Asm(prgmNAME is slow. It needs to copy the program in a RAM area to run it and other stuff and when you're running low in RAM or have several sub-programs, the Asm( command takes almost a second to execute at all (altough the program ASM code will be executed at lightning speed. See The Reign Of Legends 3 map loading speed for an example of how slow it can be

jsj795:
ahh okay. Yeah, it's something about searching through the whole program list to find the asm program, right? So if you have a lot of programs, than it takes long time to load the program... Got it^^

Navigation

[0] Message Index

[#] Next page

Go to full version