Entry Stack
Written by Andy Hochhaus on April 21, 2000
Have you ever wondered how to access items that were typed in on the home screen and are now in the TI-86's history? This tutorial is meant to show you how to access entries or add new ones into the TIOS's entry stack.
Here are all the special equates that you will need to work with the
last entry stack. The RAM equates (the first four) are found in the
standard include files of
Assembly Studio 86 ver 3.1. However the
ROM call _GETLASTENTRY
is not in the include files so
you must add its equate to your source:
_LASTENTRYPTR =$ce2a
_LASTENTRYSTK =$ce2c
_numlastentries =$ceac
_currlastentry =$cead
_GETLASTENTRY =$4627
Here is a description of what each does:
_LASTENTRYPTR
#
This is a word size variable that is a pointer to the end of the last entry
(_numlastentries
) in the entry stack _LASTENTRYSTK
.
_LASTENTRYSTK
#
This is the entry stack where all of the calculators' entries from 1
to _numlastentries
are stored. They are stored in compiled
(tokenized) form with the first word being a size word, just like a
standard TIOS variable.
For example, 1+1
in ascii would be stored as
07 00 44 31 00 60 44 31 00
in the stack. The first
two bytes are the entry size; next x bytes are compiled data.
NOTE: Entry 0 is not stored here it is the hidden system #
variable. (I think)
NOTE: _LASTENTRYSTK
is 128 bytes long.
_numlastentries
#
This is a one-byte variable that is a counter of the total number of entries that
the calculator is currently storing.
_currlastentry
#
This is a one byte variable that points to the entry number we wish to recall in
the _LASTENTRYSTK
.
_currlastentry
is incremented everytime you press [2nd] [Entry] on the homescreen.
_GETLASTENTRY
*#
This gets a pointer to a Homescreen History entry (used to recall entries from stack)
_GETLASTENTRY=$4627#
Description | Returns a pointer to the requested Homescreen History entry. |
Input | _currlastentry - the entry number you want (can be a
number anywhere between 0 and (_numlastentries) .
|
Output | bde - points to entry size (two bytes) at the start
of the requested entry_curlastentry either incremented or reset
|
Destroys | a is zeroedhl
|
* Based off a description written by Josh Seagoe on A86.
This tutorial assumes that you are familiar with absolute addressing and its ROM calls. Please refer here if you need equates or you want a good tutorial on absolute addressing.
Now on to the actual code it self. I will start with a basic example of recalling an entry from the stack.
First we must store whatever entry number we wish to recall to _curlastentry
. Next we
must call _GETLASTENTRY
which will convert our entry number into an absolute pointer
to our entry in the _LASTENTRYSTK
. Now we must copy the data out into a temporary
variable that we have created.
ld a,1 ;I want to retrieve entry #1
ld (_curlastentry),a ;set up _curlastentry for _GETLASTENTRY
call _GETLASTENTRY ;points bde to our data
call _ex_ahl_bde ;ahl=bde
push af ;ahl pushed onto stack for later use
push hl ;ahl=start of last entry in _LASTENTRYSTK
call _get_word_ahl ;get size word of entry and store to de
push de ;store size word for _mm_num_bytes
push de ;store size word for size of tempvar1
ld hl,equvarname-1
rst 20h ;_mov10toop1 puts equvarname in op1
pop hl ;gets size word that program should be
call _createequ ;creates new equ var
call _ex_ahl_bde ;ahl points to size word of tempvar1
call _set_abs_dest_addr;sets dest addr, tempvar1, for copy
ld a,0
pop hl ;ahl=number of bytes to copy - 2
call _ahl_plus_2_pg3 ;ahl=number to bytes to copy
call _set_mm_num_bytes ;set number of bytes to be copied
pop hl ;ahl=start of entry in _LASTENTRYSTK
pop af ;
call _set_abs_src_addr ;sets source as ahl
call _mm_ldir ;copy from _LASTENTRYSTK to tempvar1
. . .
. . .
. . .
equvarname:
.db 8,"tempvar1" ;temp variable name
Now we have copied an entry from the _LASTENTRYSTK
into a temporary variable being used
by our program. Note that this variable is still in compiled (tokenized) form and must be detokenized
before you display it.
So far, I have gone over how to retrieve an entry already in the stack. But what if you wanted to add a new item onto the stack? This is slightly harder but can be achieved by using this algorithm*.
* The basis for this routine has been supplied by Josh Seagoe on A86.
First, get the last entry's location. (using _GETLASTENTRY
) Then add the amount of
space taken by the new entry. Update _LASTENTRYPTR
to point to the new end of the
last entry. Now move all the entries in _LASTENTRYSTK
up by the size of the new
entry. This provides space for our new entry to be added into the entry stack. Next copy the new
entry, including size word, to _LASTENTRYSTK
. Then add one to _numlastentries
.
Finally set _currlastentry
to zero. This is for compatibility with TIOS.
ld hl,tempprogname-1
rst 20h
rst 10h
call _ex_ahl_bde
call _get_word_ahl ;gets size word and stores it in (de)
inc de
inc de ;lenght of data to be added plus size word
ld hl,127 ;length of _LASTENTRYSTK
call _cphlde ;is entry too big for _LASTENTRYSTK
ret c ;if entry to big don't store to stack
push de ;store length of new data + 2 (size word)
checkforlastentryprt:
ld hl,_LASTENTRYPTR
ld c,(hl)
inc hl
ld b,(hl) ;bc=end of last entry (i.e. _LASTENTRYPTR)
push bc
ex de,hl
add hl,bc ;hl=end of last entry after new data is added
ex de,hl
ld hl,_numlastentries-1
call _cphlde
jp c,calcnewlastentryptr
ld hl,_LASTENTRYPTR
ld (hl),e
inc hl
ld (hl),d ;de=destination of data move
pop hl
push hl
ld bc,_LASTENTRYSTK-1
xor a
sbc hl,bc ;hl=# of bytes to be moved
push hl
pop bc
pop hl ;hl=source of move
lddr
ld hl,tempprogname-1
call _mov10toop1
call _findsym
ld a,b
ex de,hl
call _set_abs_src_addr
ld a,0
pop hl
call _set_mm_num_bytes
ld a,0
ld hl,_LASTENTRYSTK
call _set_abs_dest_addr
call _mm_ldir
ld a,(_numlastentries)
inc a
ld (_numlastentries),a
ld a,0
ld (_currlastentry),a
. . .
. . .
. . .
equvarname:
.db 8,"tempvar1" ;temp variable name
This code adds a entry to the _LASTENTRYSTK
and has error checking. It checks to see
if the entry is too long, longer than _LASTENTRYSTK
, and doesn't add the entry if it
is. This code also checks to see if any old entries will no longer fit into _LASTENTRYSTK
and if they won't it deletes them. The only problem with this code is that the variable you are
adding needs to be compiled.
I hope that this tutorial gave you a better understanding of how the calculator deals with
entries. Hopefully you now understand how to access and add entries into the _LASTENTRYSTK
.
If you find any problems or have any comments or questions please send me,
Andy Hochhaus, an email.
Special thanks to:
- Josh Seagoe (rabidcow) Web page Without his posts to A86 I would have never learned about the entry stack! Thanks for all your help Josh. This tutorial wouldn't be around without him!
- James Malcolm Web Page For creating a great TI-86 ASM resource and for letting me post my tutorial to it.
- Clem Vasseur for making some great updated Include files. From which I got new equates from.
- Tim Costa for helping me to revise this tutorial.
More from z80 » Advanced
All The Ports // APD // Assembler Directives // Entry Stack // User Fonts // IM 1 // IM 2 // Index, Shadow, and Other Registers // User Interrupt // Morphic Code // On-Off // Reading Keypresses from Port // Shift and Rotate // Simulating Key Presses // Sound // Square-Root Programs // System Flags of TI-OS