Hi all,

I'm wondering how to access the calculator variables (A, B, C, L1, L2, Str1, etc.) in ASM. I tried going through the 28 days tutorial but it doesn't quite make sense to me.

Thanks
toraora wrote:
Hi all,

I'm wondering how to access the calculator variables (A, B, C, L1, L2, Str1, etc.) in ASM. I tried going through the 28 days tutorial but it doesn't quite make sense to me.

Thanks
Edit: When in doubt, read this document:

http://education.ti.com/downloads/guidebooks/sdk/83p/83psysroutines.pdf

Older post: Allow me to present this probably quite poor code from Doors CS 4:


Code:
;+---------------------------------------------+
;|      Set BASIC Variables Routines       |
;+---------------------------------------------+
;|  Thanks to Tutorial 25 of ASMGuru for this! |
;+---------------------------------------------+
SETVAR_X:
   call SETVAR_INIT
   ld hl,'X'
   ld (OP1+1),hl
   jp _STOOTHER
SETVAR_Y:
   call SETVAR_INIT
   ld hl,'Y'
   ld (OP1+1),hl
   jp _STOOTHER
SETVAR_A:
   call SETVAR_INIT
   ld hl,'A'
   ld (OP1+1),hl
   jp _STOOTHER
SETVAR_N:
   call SETVAR_INIT
   ld hl,'N'
   ld (OP1+1),hl
   jp _STOOTHER
SETVAR_N_hl:
   call _SetXXXXOp2
   call _Op2ToOp1
   call _PUSHREALO1
   call _ZEROOP1
   ld hl,'N'
   ld (OP1+1),hl
   jp _STOOTHER
SETVAR_INIT:
   ld (op1),a
   call _Setxxop1
   call _PUSHREALO1
   call _ZEROOP1
   ret
;+---------------------------------------------+
;|      Get BASIC Variables Routines       |
;+---------------------------------------------+
;|  Thanks to Tutorial 25 of ASMGuru for this! |
;+---------------------------------------------+
GET_A:
   call _zerooop1
   ld hl,op1+1
   ld (hl),'A'          ;or any other var
   jp GETVAR
GET_X:
   call _zerooop1
   ld hl,op1+1
   ld (hl),'X'          ;or any other var
   jp GETVAR
GET_Y:
   call _zerooop1
   ld hl,op1+1
   ld (hl),'Y'          ;or any other var
   jp GETVAR
GET_N:
   call _zerooop1
   ld hl,op1+1
   ld (hl),'N'          ;or any other var
GETVAR:
   call _rclvarsym          ;op1 / op2 -> value
   call _convop1
   ld a,e            ;previously ld a,hl
   ret
Note that this is TI-83 ASM. For TI-83+ ASM, all the call _routines need to be bcall(_routine)s.
Quick tutorial for RAM vars (they're easier):

Just like anything else in memory, you access calculator variables with a pointer, which means you'd need to know where it is first. The TI-OS includes two b_calls that find variables for you: FindSym and ChkFindSym. The first one is faster but can only find variables that aren't programs, appvars, or groups. If you want to find a variable that's one of those, you'll have to use ChkFindSym.

Either way, you first have to load the name of the program into the nine-byte area called OP1 (so the routine knows what to look for). The easiest way is to store the name as data in the program:


Code:

ProgName:
    .db ProgObj, "NAME", 0


Then when you actually call the routine, load the label into HL, call Mov9ToOp1 (with rst 20h), and call the appropriate finding routine:


Code:

    LD HL, ProgName
    RST 20h
    b_call(ChkFindSym)


If it finds the variable, the carry is reset:


Code:

    JR c, ProgNotFound


If it's in RAM, B will be 0:


Code:

    LD A, B
    OR A
    JR nz, ProgInArc


DE now points to the two size bytes of the variable, which come before the data. If you want to make DE point to the start of the actual data, add two:


Code:

    INC DE
    INC DE


This will also work with any other variable type.

Hope that clears some stuff up.
So, if I wanted to find a list LIST, I would have the following code:


Code:

ListName:
 .db ListObj, "LIST", 0
 
 LD HL, ListName
 RST 20h
 b_call(_FindSym)


and if I wanted to read from list LIST, then i would start from DE + 2 in RAM.

Correct?
List are found with ChkFindSym, not FindSym. Also, you don't inline .dbs, unless you weren't. Convention is to put data like that at the end of your program. Otherwise, correct.
What Kerm said. Always put your data at the end of the program (after the RET). Otherwise it'll get run as a sequence of commands, since they're the same thing.
So I am trying to code a calculator lock that utilizes list LIST, which contains the key values. Here is the code I have (doesn't work):

Code:


.NOLIST
#include "ti83plus.inc"
.LIST

   .ORG   9d93h
   .DB   t2ByteTok, tAsmCmp

FindList:
   LD   HL, ListName
   RST   20h
   b_call(_ChkFindSym)
   LD   H, D
   LD   L, E
   LD   (ListLoc), HL
   LD   B, (HL)
   LD   L, B
   LD   (ListLeng), HL   

   LD   C, 0
Start:
   INC   C
   LD   A, C
   LD   HL, (ListLeng)
   CP   L
   JR   Z, End
   PUSH   BC

GetKeyCode:
   b_call(_GetCSC)
   CP   0
   JR   Z, GetKeyCode

   POP   BC
   PUSH   AF
   LD   HL, (ListLoc)+2
   LD   B, C

Loop:
   INC   HL
   DJNZ   Loop

   LD   B, (HL)
   POP    AF
   CP   B
   JR   Z, Start
   LD   C, 0
   JR   Start

End:
   RET

.end
.end

ListName:
        .DB   ListObj, "LIST", 0
ListLoc:
   .DW   0
ListLeng:
   .DB   0


This indirection is making me dizzy...
Deep Thought wrote:
Otherwise it'll get run as a sequence of commands, since they're the same thing.

Uh, no. It will only get run if the programmer forgets to jump around the data. IMO, randomly scattering data around your program isn't good, but it won't crash your calc if you are careful. Smile
Numbers in lists are stored as 9-byte floating points (tutorial here).
Oh yeah. I forgot >.<
Still, when I run the debugger, ListLoc points at apparently nowhere in particular.

EDIT: after hours of debugging, i finished the program.
toraora wrote:
Oh yeah. I forgot >.<
Still, when I run the debugger, ListLoc points at apparently nowhere in particular.

EDIT: after hours of debugging, i finished the program.
That's great to hear, congrats! Perhaps you'll consider uploading it to the Cemetech archives, once you decide it's complete?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement