[TI ASM] storing data

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

[TI ASM] storing data

Post by King Harold »

i want to store data to the $20's (which are spaces without zero terminating the string)
var:
.db AppVarObj, "Var", $20, $20, $20, $20, $20, 0

how exactly do you do that?
i have some ideas about using
ld hl, (var)

i didnt get it to work though..

EDIT: Link to source
I'll try to keep this up to date as much as possible
Last edited by King Harold on Sat 12 Aug, 2006 5:45 pm, edited 1 time in total.
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

Post by chickendude »

Try this:
ld hl,var+4
ld a,#
ld (hl),a
inc hl
ld a,#
ld (hl),a
etc
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

thanx, but since im a complete idiot i got a name "Var 0: " thats right var+_space+0+: and i think it has something to do with the input not being hex (it cant be since its a list), its a bit odd.. but ok, code looks like this oh and the bug is mostly in trying to input 10 because it just shifts to the next ascii char instead of adding to the next number... it looks messy, but it works anyway (you can actually store more this way right?)
lower then 10 works (ofcourse) just fine
.nolist
#include "ti83plus.inc"
#define ProgStart $9D95
.list
.org ProgStart - 2
.db t2ByteTok, tAsmCmp
bcall(_RclAns) ; recall Ans
ld hl,1 ; 1st element in Real List
bcall(_GetLtoOp1) ; get element
bcall(_ConvOp1) ; returns a as LSByte (and de as the total 16bit value)
or a
JP Z,create_var
dec a
JP Z,del_var
dec a
JP Z,put_int
ret

create_var:
bcall(_RclAns) ;rcl ans because its lost
ld hl, 2 ;2nd list element (size)
bcall(_GetLtoOp1) ;put it in op1
bcall(_ConvOp1) ;make it a number and put it in de
push de ;push de because it gets destructed
bcall(_RclAns) ;ans gets lost somewhere..
ld hl, 3 ;3rd list element (name)
bcall(_GetLtoOp1) ;put it in op1
bcall(_ConvOp1) ;op1 -> de
ld hl, var_name+5
ld a, $30
add a, d
ld d, a
ld a, $30
add a, e
ld e, a
ld (hl), d
inc hl
ld (hl), e

ld hl, var_name
bcall(_mov9toop1)
bcall(_ChkFindSym) ;see if it needs to be deleted
JR C, create_var_2 ;jump if it doesnt exist
bcall(_DelVarArc) ;delete if so
create_var_2:
pop hl ;pop size (was de) in hl, name is still in OP1
bcall(_CreateAppVar) ;duhh..
ret
del_var:
bcall(_RclAns)
ld hl, 2 ;for deleting the name should be in the 2nd element
bcall(_GetLtoOp1) ;2nd element to op1
bcall(_ConvOp1) ;store the number in de




;name generation based on de.. (same as in "create_var")
ld hl, var_name
bcall(_Mov9ToOP1) ;name in op1
bcall(_ChkFindSym) ;check if it exists, cant delete non-existant things
JR C, not_found ;if not found, dont delete
bcall(_DelVar) ;else delete
ld a, 1 ;1 in a
bcall(_SetxxOP1) ;1 in op1
bcall(_StoX) ;op1 in x (tell user that the appvar has (probebly) been deleted
ret
put_int:
ret ;not made yet
var_name:
.db AppVarObj, "Var", $20, $20, $20, $20, $20, 0
not_found:
xor a ;if the appvar has not been found, 0 to a
bcall(_SetxxOp1) ;a to op1
bcall(_StoX) ;op1 to x (0 to x)
ret
char_string:
.db 10,"0123456789"

.end
END
i hope i didnt do something insanely stupid :(
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

after some thinking i decided that 2 ascii's isnt that bad and i'll keep them. (5 digits or 2 ascii's, well, with digits you know which one to delete, but since my program can do that.. what does it matter..)
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

Post by chickendude »

Well, the reason for the space in the variable name is because you ld hl with var_name+5, it should be var_name+4 (it starts at 0, varnmae+0 corresponds to the first byte).

And that whole section could be optimized as such:
ld hl, var_name+4
ld a, $30
add a, d
ld (hl), a
inc hl
ld a, $30
add a, d
ld (hl), a

but I don't think that's your problem. You probably need to load the numbers from OP directly, rather than using the bcall. The bcall concatenates all the numbers. I'm not sure if you can do this or not, but you should try
ld a,(OP1+2)
push af
and $F0
srl a
srl a
srl a
srl a
add a,$30
ld (hl),a
inc hl
pop af
and $0F
add a,$30
ld (hl),a

then do that for every digit you need (that right there SHOULD load the first two digits into your variable, but I'm not sure if it will work).

You could go into a loop:

Code: Select all

 ld ix,OP1+2
 ld hl,var_name+4
 ld b,3
loop:
 ld a,(ix)
 push af
 and $F0
 srl a
 srl a
 srl a
 srl a
 add a,$30
 ld (hl),a
 inc hl
 pop af
 and $0F
 add a,$30
 ld (hl),a
 inc x
 inc hl
 djnz loop
 dec hl
 xor a
 ld (hl),a
Again, I don't know that that will work, but if you finetune it, something meaningful should come out of it.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

thanx loads, it works!
although it starts at the beginning and "appends" zero's
is there a way to turn it around and start at the end?
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

Post by chickendude »

Sure. Start at OP1+5 and var_name+9 then dec ix and dec hl.

Hmm. It would be a lot larger though because, since you're only using a five digit number and not six (odd vs even), the rightmost nibble would have to be skipped the first time through. Actually, you could just ld a,b \ cp 3 \ jr someLabelAfter the second nibble is taken care of.

Well, actually there are a couple other complications as well. You'd have to work the lower nibble first.

Give me a few minutes and I'll edit it so that it should work the other way. But why do you need it to work backwards?

Code: Select all

 ld ix,OP1+5
 ld hl,var_name+9
 ld b,3
loop:
 ld a,b
 cp 3
 jr z,skip
 ld a,(ix)
 and $0F
 add a,$30
 ld (hl),a
skip:
 dec hl
 ld a,(ix)
 and $F0
 srl a
 srl a
 srl a
 srl a
 add a,$30
 ld (hl),a
 dec ix
 dec hl
 djnz loop
See if that works.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

i need to work backwards because otherwise 3, 30, 300, 3000 and 30000 will all result in the name "Var30000"
because it starts with the 3 and cant put anything else then zero's in the rest....
i think looping over the number backwards should solve the problem, im not sure though..

this code gives me all-zero names.. :(
it looks very much like something that should work though
Last edited by King Harold on Tue 08 Aug, 2006 3:43 pm, edited 1 time in total.
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

Post by chickendude »

Nope. That would still store the zeros. Make the user use 00003 and 00030 etc. I mean, you could read in the number, check if it's a zero, and then skip to the next number (making a zero an illegal number).

Otherwise, I could make a routine that starts at var_name+9 and deletes all zeros (well, either converts them to spaces or to a null value) until it reaches a non-zero. That would be incredibly simple to do.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

i mean, i get all-zero names when the inputs are like 100 or 200, kinda odd
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

Post by chickendude »

What do you mean? Like Var00000?
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

Post by chickendude »

Code: Select all

 ld ix,OP1+2
 ld hl,var_name+4
 ld a,(OP1+1)
 sub a,$7F
 ld b,a
loop:
 ld a,(ix) 
 push af 
 and $F0 
 srl a 
 srl a 
 srl a 
 srl a 
 add a,$30 
 ld (hl),a 
 inc hl
 dec b
 jr z,exit
 pop af 
 and $0F 
 add a,$30 
 ld (hl),a 
 inc x
 inc hl
 djnz,loop
exit:
Hopefully that will work. Test it out, it should leave out the extra 0s.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

well.. inc x is illegal (tasm is odd sometimes), inc ix is ok, and for some reason it complains about either sub a,$7F or ld a,(OP1+1)
i had to count 127 lines for that, and somewhere i lost 1, so it could be either one
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

Post by chickendude »

It should be inc ix, sorry! Typo.

And switch this:
Code:
ld ix,OP1+2
ld hl,var_name+4
ld a,(OP1+1)
sub a,$7F
ld b,a

to this:
Code:
ld ix,OP1+2
ld hl,OP1+1
ld a,(hl)
ld hl,var_name+4
sub a,$7F
ld b,a


that should fix it.

Also, tasm should output a .lst file. Open that with notepad or something and on the left it should list the line numbers, then the hex values, then what you typed in your program. I don't know if it deletes it if there's an error, but it might not. It'll prevent you from having to count though :)
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

yes it deletes it.. but after a look in the bat file i saw it isnt tasm who does that..

c:\asm\source\appvar.z80 line 0128: Label not found: (a)
c:\asm\source\appvar.z80 line 0128: Unknown token: (,)
c:\asm\source\appvar.z80 line 0128: Unknown token.

i still get this
Post Reply