[TI ASM] storing data

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

Post by chickendude »

What do you mean? Store the result into one of the system string variables? It's very similar to storing into an AppVar, I believe. Why do you need to store into a string?

Also, what exactly are you trying to get your program to do? Is it, say, an extension to the system variables (like A-Z and theta) or is it a way to store a bunch of data, like a tilemap or something?
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

well im trying to give all those basic programmers who want to store data in hard-to-edit datafiles for games etc (its allways possible to edit them anyway, but some basic programmers dislike custom lists because they are real easy to edit) and i would like a read/write char routine (easy to store, same as integers, the read should output the char that had been stored as its ascii value)
oh and the size thing hasnt been fixed, i thought so but i tested it a bit more, the size still changes (it gets bigger, huge, and when you delete the appvar with 2nd mem your ram clears)
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

Post by chickendude »

Hmm... so each AppVar would hold only one byte? That's a lot of space taken up to only hold one data value (and it would have to be less than 256, unless you extended it to 2 bytes). And if they have a fairly large list, that's a lot of AppVars they'd have to make.

And to be honest, I haven't even tested out the program yet, so I'll need to do it sometime so I know what you're talking about. Hopefully either tonight or tomorrow morning I'll get the chance to. I think you're probably writing your data to the wrong place or you didn't allocate enough memory when you created the AppVar, so weird things are happening.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

well.. ChkFindSym has de pointing to the data, right?
and this is intended to store 1 byte per byte (so including the symbol table entry its 17bytes+the size of the appvar, that then could store up to [size] bytes) usually storing you dont really have to store 9byte FP numbers, so you can have 83% compression (i think).
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

Post by chickendude »

Well if you do it that way, each number that they store can't be larger than 255, as that is the limit of one byte. Storing them two bytes at a time would increase that to somewhere around 65,000.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

ofcourse, but that would cut on the compression, and you can get creative and store a 256+ number as 2 bytes yourself (save #/256 and #-(#/256) or something along those lines) so it doesnt really matter, one could (with some trouble) even store a FP as 9 bytes, but you hardly ever need to store FP's, ans when you do there's a big chance you wont need a couple of 100's of them, so 1 byte integer storing al the way!
since everything can be done with them, if you know a little math that is
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

Post by chickendude »

True, and you could even have a routine to return two bytes into Ans, thereby saving the user some work.

But I've got some time tonight to work on it, hopefully I can figure something out :)
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

are there two "size bytes" at the beginning of the data? (weird but looks like it)
when i inc de 2 times (at the offset) it seems to work just fine, could be wrong though, not tested a lot yet
Liazon
Calc Guru
Posts: 962
Joined: Thu 27 Oct, 2005 8:28 pm

Post by Liazon »

at the beginning of a data variable, I believe so.
Image Image Image
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

Post by chickendude »

Hmm, I tried the program and so far everything seems to work just fine. I can't remember if I changed anything, but everything works so long as you have the right amount of parameters passed through. I was able to enter data in and read it, as well as create and delete AppVars without any problems. So what exactly are you having trouble with? Certainly, you might want more error checking because a RAM clear in a BASIC program is devestating. Not so much so with an assembly one. I'll go upstairs and post what I've got, but it's really not much different than yours.

brb.

Code: Select all

.nolist 
#include "ti83plus.inc" 
#define    ProgStart    $9D95 
.list 
.org    ProgStart - 2 
    .db    t2ByteTok, tAsmCmp 
   bcall(_ClrLCDFull) 
   bcall(_RclAns)      ;ans gets lost somewhere.. 
   ld hl, 3      ;3rd list element (offset/size) 
   bcall(_GetLtoOp1)   ;put it in op1 
   bcall(_ConvOp1)      ;store the hex value in de 
   push de         ;push de because it gets destructed 
   bcall(_RclAns) 
   ld hl,2 
   bcall(_GetLtoOp1) 
   bcall(_homeup)
   call name_loop 
        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         ;  jumps:    
   JP Z,del_var      ; 
   dec a         ;0->create_var 
   JP Z,put_int      ;1->del_var 
   dec a         ;2->put_int 
   JP Z,read_int      ;3->read_int 
   dec a         ;4->put_char 
   JP Z,put_char      ;5->read_char 
   dec a         ;6->shrink_var   (starts at [offset],deletes [value] bytes) 
   JP Z,read_char      ;7->grow_var   (starts at [offset],inserts [value] bytes) 
   dec a         ; 
   JP Z,shrink_var      ; 
   dec a         ; 
   JP Z,grow_var      ;{function,name,[offset/size],[value] 
   ret    

create_var:   ;------------------------------------------------------------------------- 
   ld hl,msg_create 
   bcall(_PutS) 
   ld hl, var_name      ;load the name 
   bcall(_Mov9toop1)   ;moves the name to OP1 
   bcall(_ChkFindSym)   ;see if it needs to be deleted 
   JP NC,err_code_1   ;jump if exists 
   pop hl         ;pop size (was de) in hl, name is still in OP1 
   bcall(_CreateAppVar)   ;duhh.. 
   ret 
del_var:   ;-------------------------------------------------------------------------- 
   ld hl,msg_del 
   bcall(_PutS) 
   ld hl, var_name      ;load the name 
   bcall(_Mov9ToOP1)   ;name in op1 
   bcall(_ChkFindSym)   ;check if it exists, cant delete non-existant things 
   JP C, err_code_1   ;if not found, dont delete 
   bcall(_DelVar)      ;else delete 
   xor a         ;0 in a 
   bcall(_SetxxOP1)   ;0 in op1 
   bcall(_StoX)      ;op1 in x (tell user that the appvar has (probebly) been deleted 
   ret 
put_int:   ;-------------------------------------------------------------------------- 
   ld hl,msg_writeint 
   bcall(_PutS) 
   ld hl, var_name      ;load the name 
   bcall(_Mov9toop1)   ;moves the name to OP1 
   bcall(_ChkFindSym)   ;see if it exists (cant write to no-place can you?) 
   push de 
   JP C, err_code_1   ;jump if it doesnt exist 
   ld a, b         ;load rom page in a 
   or a         ;compare a = 0 
   bcallnz(_Arc_Unarc)   ;if a is not 0 unarc, else do nothing 
   
   bcall(_RclAns) 
   ld hl, 4      ;recall the 4th element  (value) 
   bcall(_GetLtoOp1) 
   bcall(_ConvOp1)      ;put the LSB in a 

   pop de 
   pop hl         ;data offset in hl 
   add hl, de      ;de is pointer to begin of appvar, de is offset 
   ld (hl),a
   ret          
read_int:   ;---------------------------------------------------------------------------- 
   ld hl,msg_readint 
   bcall(_PutS) 
   ld hl, var_name      ;load the name 
   bcall(_Mov9toop1)   ;moves the name to OP1 
   bcall(_ChkFindSym)   ;see if it needs to be deleted 
   push de 
   JR C, err_code_1   ;jump if it doesnt exist 
   ld a, b         ;load rom page in a 
   or a         ;compare a = 0 
   bcallnz(_Arc_Unarc)   ;rom page =! 0 so change Archived state 
   pop de 
   pop hl         ;pop offset from stack 
   add hl, de      ;add begin to offset 
   ld de, var_int      ;load pointer to var_int 
   ldi         ;move the data 
   dec de         ;ldi inc's de so we dec it 
   ld a,(de)      ;de points to var_int again 
   bcall(_SetxxOp1)   ;put a in op1 
   bcall(_StoAns)      ;store the byte in ans 
   ret 
put_char:   ;----------------------------------------------------------------------------- 
   ret 
read_char:   ;----------------------------------------------------------------------------- 
   ret 
shrink_var:   ;----------------------------------------------------------------------------- 
   ret 
grow_var:   ;----------------------------------------------------------------------------- 
   ret 


name_loop:   ;----------nameloop by Chickendude, thanx for your help mate :)--------------- 
   ld ix,OP1+2   ;this is the start of the integer series 
   ld hl,var_name+4 
   ld a,(OP1+1)    ;this grabs the length of the integer series (+$7F) 
   sub $7F      ;stores the length to a 
   ld b,a      ;store a into b to use as a counter variable 
loop: 
   ld a,(ix)       ;grab the first byte 
   and $F0          ;$F0 = %11110000.  This loads the first integer into a. 
         ;say the first two digits you entered were 3 and 8. 
         ;OP1+2 would hold the hex value: $38, or %0011 1000. 
         ;%0011 = 3, so if we and %11110000, then the value in a will 
         ;hold %00110000.  We now need to slide a over four bits. 
   srl a      ;a=%00011000 
   srl a      ;a=%00001100 
   srl a      ;a=%00000110 
   srl a      ;a=%00000011, or 3 
   add a,$30   ;get the ascii code and load it into the variable, var_name 
   ld (hl),a 
   inc hl      ;go to the next byte in the variable 
   dec b      ;we've worked one digit, so subtract one from b 
   jr z,exit       ;if b=0, we've worked all the digits and exit 
   ld a,(ix)       ;load the first byte into a again (%00111000) 
   and $0F      ;and %00001111 to a.  a should now hold %00001000, or 8 
   add a,$30   ;get the ascii value... 
   ld (hl),a       ;and load into (hl) 
   inc ix      ;get the next byte in the OP register 
   inc hl      ;go to the next byte in the var_name variable 
   djnz loop   ;subtract one from b.  if b doesn't equal zero, repeat the process 
exit: 
   ret 
err_code_1:   ;------------------------------------------------------------------------------- 
   ld a, 1         ;1 to a 
   bcall(_SetxxOp1)   ;a to op1 
   bcall(_StoX)      ;op1 to x (1 to x) 
   ret 
var_name:   ;------------------------------------------------------------------------------- 
   .db AppVarObj, "Var", $20, $20, $20, $20, $20, 0 
var_int: 
   .db $00 
msg_create: 
   .db "Create var",0 
msg_del: 
   .db "DelVar",0 
msg_writeint: 
   .db "WriteInt",0 
msg_readint: 
   .db "ReadInt",0 
.end 
END
http://www.mysharefile.com/v/3505129/Program.8xp.html
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

well, i see you still have that version,
at this adres you can find the newest version.
With that older version you should try storing something at an offset of zero
the newer version inc's de 2 times before i push it, works better
oh and do you know why the calc messes up completely when a variable is named "?" ?
no other variables will be showed in the mem menu and if you try to delete it you'll first see "ERR:INVALID" and then you get ram cleared (i exedentally named something ? with chasm and then thought it would be funny to do it again)
anyway, it should not work without the 2 inc's (well it seems to, at a first glance, because it returns the value right, but along the way it overwrites the size bytes)
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

Post by chickendude »

Hmm.. alright I'll look over that code :)
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

uhm... so... have you looked it over?
also, i just bought Guild Wars so again no update, sorry, i'll have more time when school starts again (who makes his homework these days? not me.. certainly not in my last year)
CompWiz
Calc King
Posts: 1950
Joined: Thu 13 Oct, 2005 1:54 pm
Location: UB

Post by CompWiz »

yeah, I know what you mean. The only reason I'm actually learning assembly is because I finished the main campaign. When I was in the middle of it, I either did my homework on the way into school, before the class started, or not at all. Although, I didn't do much homework before I got the game either.
Hopefully you have at least a little more self control than me, and manage to do some programming while you have the game. :)
In Memory of the Maxcoderz Trophy Image
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

yea i'll try to, and i'll sure make simple on-calc things around midnight, but they're not worth posting (memchk stuff, selfdeleting program, etc..)
Post Reply