Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: XVicarious on June 26, 2011, 03:49:46 pm

Title: Using AppVars, more help!
Post by: XVicarious on June 26, 2011, 03:49:46 pm
Okay, I read FinaleTI's external vars tutorial, but I still have a couple of questions.

1) So from what I understand, accessing the data in my appvars, I need to know EXACTLY where everything is, knowing exactly what byte it is at. Correct?
2) How would I go about storing PICs and tilemaps in AppVars and then accessing that data?

If you need more info, ask. I will probly add more questions to this as I go along programming this game.

edit:
3) How do I get my Pic out of the appv and store it to Pic1? I have tried a variety of methods but none seem to work.
Title: Re: Using AppVars, more help!
Post by: leafy on June 26, 2011, 03:53:11 pm
1) Yes indeedly
2) You need to know how many bytes each PIC and tilemap takes up. For example, if I had a 108 byte tilemap (For Tag! ^^) then I would do something like

Accessing:
3->L //Store offset into a var
getCalc("appvTEST")->V //Load appvar into a pointer
Copy(L*108+V,L1,108) //Copy the 4th tilemap (3+1, starts at 0), which is 108 bytes, into L1 space of free ram.

Do the same with PICS. Note that with appvars it's a bit more difficult because you need to know explicitly how large each item is.
Title: Re: Using AppVars, more help!
Post by: XVicarious on June 26, 2011, 03:56:01 pm
So, how big is say an 8x8 sprite in hex? Just so I know.

This might make it a little hard to make the engine easy to use with a custom APPVAR system... There would have to be extremely strict specifications on how to build the appvars.
Title: Re: Using AppVars, more help!
Post by: shmibs on June 26, 2011, 03:59:06 pm
an 8*8 is 8 bytes, which means a 16 character alpha-numeric code per sprite

EDIT: oh, and instead of having an exact size for each object you could always just use a specific pattern of values to act as a header, indicating that one is ending and another is beginning, and then just number your objects to find the offset to it in your data. or, as another option, you could have a list that's a set size at the beginning of your appvar which holds, in a set number of bytes (say 2-4) indicates the size of your object and the offset to where it begins. that would mean that, in order to find the 3rd tileset (or whatever it is you happen to be storing) you could just skip to the 3rd entry in the table, find it's position and size, and work from there.
Title: Re: Using AppVars, more help!
Post by: XVicarious on June 26, 2011, 04:00:03 pm
Thanks!
Title: Re: Using AppVars, more help!
Post by: XVicarious on June 27, 2011, 01:31:31 am
First post updated. I'm not sure what exactly doub post rule is... but meh. my last post was one worded lol.
Title: Re: Using AppVars, more help!
Post by: XVicarious on June 29, 2011, 05:33:17 pm
Bumping since it has been a couple of days, and I need help on one more thing, the menu. The loading is strange and I know the !Str1 etc is not proper syntax I was playing around trying to iron bugs out and I misinterpreted what someone said
Bugs:
Calculator crashes almost instantly
Chapters that are not existing on the calculator are appearing
Chapters are overlapping and pushing up to the top of the screen, instead of proper space

Code: [Select]
..MENU

2→C

If GetCalc("appvBLUTCH1")
"Chap 1"→Str1
C+1→C
End
If GetCalc("appvBLUTCH2")
"Chap 2"→Str2
C+1→C
End
If GetCalc("appvBLUTCH3")
"Chap 3"→Str3
C+1→C
End

C→[theta]

Repeat getKey(15)
 ClrDraw
 Fix 1:Fix 5
 Text(1,,"blut")
 Text(8,C*10,"Quit")
 Text(8,(C-1)*10,"Help")
 C-1→C
 If Str₃ and !Str₂ and !Str₃
  Text(8,(C-1)*10,Str3)
  C-1→C
 End
 If Str₂ and !Str₁ and !Str₃
  Text(8,(C-1)*10,Str2)
  C-1→C
 End
 If Str₁ and !Str₁ and !Str₂
  Text(8,(C-1)*10,Str1)
  C-1→C
 End
 DispGraph
 End
 
 .FULL MENU, STILL NEED KEYPRESSES ETC LOL
Title: Re: Using AppVars, more help!
Post by: Quigibo on June 29, 2011, 06:59:33 pm
Strings are static pointers meaning that they are always constant and always defined.  Putting them in If statements doesn't do anything, it will behave as if you had put them in the beginning of your file (which you should always do by the way).  Also you might want to consider copying the file names in L1 so you can easily edit the ending number.  For instance:

Code: [Select]
:.Input: Arg1 = File number to look up
:Lbl GET
:Copy("appvBLUTCH1",L1,9) .Copy the name to L1
:r1+'0'->{L1+7} .Overwrite the last character
:Return GetCalc(L1) .Find the appvar

Then all you have to do to look up files is sub(GET,N) to get the pointer to the Nth file.
Title: Re: Using AppVars, more help!
Post by: XVicarious on June 29, 2011, 07:20:35 pm
Okay, so then I'd check for drawing almost the same way correct? Or just using that instead?

like
Code: [Select]
If sub(GET,1)
.draw this option
end
if sub(GET,2)
.draw this option
end
.etc
correct?

or for a more complete version:
Code: [Select]
..MENU

2→C

If sub(GET,1)
 C+1→C
End
If sub(GET,2)
 C+1→C
End
If sub(GET,3)
 C+1→C
End

C→[theta]

Repeat getKey(15)
 ClrDraw
 Fix 1:Fix 5
 Text(1,,"blut")
 Text(8,C*10,"Quit")
 Text(8,(C-1)*10,"Help")
 C-1→C
 If sub(GET,3)
  Text(8,(C-1)*10,"Chap 3")
  C-1→C
 End
 If sub(GET,2)
  Text(8,(C-1)*10,"Chap 2")
  C-1→C
 End
 If sub(GET,1)
  Text(8,(C-1)*10,"Chap 1")
  C-1→C
 End
 DispGraph
 End
 
.Input: Arg1 = File number to look up
Lbl GET
Copy("appvBLUTCH1",L1,9) .Copy the name to L1
r1+'0'->{L1+7} .Overwrite the last character
Return GetCalc(L1) .Find the appvar
 
 .FULL MENU, STILL NEED KEYPRESSES ETC LOL

And I'm not sure if its my calc or not, this ram clears the thing.
Title: Re: Using AppVars, more help!
Post by: Darl181 on June 29, 2011, 08:29:26 pm
You can use L# tokens as var names?
(you can type a theta with alt+233 Θ btw ;) )

Anyway idk but that might be causing the RAM clear

You can modify a string just like you're modifying L1.  I got that to work in Tio anyway..

EDIT: what might be causing the crash is that strings are zero-terminated (there has to be [00] at the end) and without that, whatever random junk is after the intended stuff at L1 is counted as part of the string until it reaches [00]--it probably tried to make a var with a >8-byte name...I'd just use a string, much safer :)

EDIT2: ok so the 0 is in there...idk :P

EDIT3: it's not in there unless r1=0.  you might want to put it in there after that ;)

EDIT4: the "" make a string, which should do the stuff on its own. oops :P
Title: Re: Using AppVars, more help!
Post by: XVicarious on June 29, 2011, 10:48:02 pm
Quote
EDIT3: it's not in there unless r1=0.  you might want to put it in there after that Wink

what do you mean by this exactly?
Title: Re: Using AppVars, more help!
Post by: Darl181 on June 29, 2011, 10:49:40 pm
Nvm that, it was cleared up in IRC that the quotes denote a string.

I was talking about r1+'0'->{L1+7} anyway

edited.
Title: Re: Using AppVars, more help!
Post by: XVicarious on June 29, 2011, 10:50:54 pm
Yeah. I'm having trouble figuring out why my calculator crashes from this code... The menu isn't too important as of now, but it will have to be soon.
Title: Re: Using AppVars, more help!
Post by: Darl181 on June 29, 2011, 10:52:37 pm
Have you tried simply using a string (as in storing to Str#)?  That might have to do with it...and as said before you can edit strings.

EDIT
Copy looks for a pointer.
Copy("appvBLUTCH1",L1,9)
"appvBLUTCH1" isn't exactly a pointer, it's data methinks

Try "appvBLUTCH1"→L1 ?
Title: Re: Using AppVars, more help!
Post by: XVicarious on June 29, 2011, 11:03:16 pm
If you look up, the code I am using (and I think you are referring to) is the code Quigibo gave me. And "appvBLUTCH1" is an appv, which copy uses I believe.
Title: Re: Using AppVars, more help!
Post by: Darl181 on June 29, 2011, 11:07:02 pm
wth..I'm so mixed up atm :P

What are you trying to do with this?
Title: Re: Using AppVars, more help!
Post by: XVicarious on June 29, 2011, 11:11:41 pm
I'm trying to display each chapter (appv) that exists on the calculator. appvBLUTCH1, etc.  If it exists, draw a menu item for it. My problems are: the code just crashes, the menu items are drawn near the top of the screen, chapters that do exist are drawn on top of one another.
Title: Re: Using AppVars, more help!
Post by: Darl181 on June 29, 2011, 11:13:43 pm
Hmm, maybe that can be done with a for loop, how many levels are planned?

0→C
10→Y .or whatever y-coordinate you want the top menu item to be at
"appvBLUTCH0"→Str1
For(A,1,3) .counting from 1 to 3 b/c there's 3 chapters
A+48→{Str1+8} .or 7, whichever the number is
.+48 because token value of 0 is 48, other numbers follow (1 is 49, etc), string is made of tokens
If Getcalc(Str1) .I think that'll work
Text(256*8,Y) .ask if you need but this defines coordinates, Y being Y and 8 for X...more optimized to pre-compute 8*256 btw this is just for simplicity
Text "Chapter ",A►Dec
.above 2 lines are the same as Text(Y,8,"Chapter ",A►Dec)
Y+8→Y .or whatever the gap from one option to another is
C++
End
End


This is assuming the fix and such is set.  After this C is the # of chapters, and you can do the other stuff accordingly.
Title: Re: Using AppVars, more help!
Post by: XVicarious on June 29, 2011, 11:19:04 pm
Well I'm planning on supporting only three chapters, and maybe after I finish the game add support for more, but that really isn't an issue right now. I could write a loop for any amount of chapters I wanted. The issues that really need to be addressed right here though is the crashing is the biggest issue, and then after that the overlapping of menu items.

edit:
in the case people didn't see I edited the first post.
3) How do I get my Pic out of the appv and store it to Pic1? I have tried a variety of methods but none seem to work.
Title: Re: Using AppVars, more help!
Post by: Darl181 on June 29, 2011, 11:34:55 pm
You mean the TIOS Pic1?  I think there's a command for that...
EDIT: i guess not..there's the option to absorb but not to store :P
Title: Re: Using AppVars, more help!
Post by: XVicarious on June 29, 2011, 11:42:17 pm
I have tried methods, I can store the contents of an appv to like {A} as described in FinaleTI's tutorial and used his method, but I get two little dots.
Title: Re: Using AppVars, more help!
Post by: Runer112 on June 29, 2011, 11:56:08 pm
This should be working menu code. The code on the left should make sense. The code on the right should do the same thing as the code on the left while being about two-thirds of the compiled size, but probably won't make sense. They both rely on the appvars being in RAM, but you could probably modify this to successfully detect them if they are in archive as well.

I've also attached 8xp files for both of these so you don't have to retype all this code. The code blocks are just so you can see what the code looks like.


Code: (Sane Axe code) [Select]
..MENU

ClrDraw
Fix 1:Fix 5
Text(1,0→Y,"blut")
If sub(GET,1)
 Text(8,Y+10→Y,"Chap 1")
End
If sub(GET,2)
 Text(8,Y+10→Y,"Chap 2")
End
If sub(GET,3)
 Text(8,Y+10→Y,"Chap 3")
End
Text(8,Y+10→Y,"Help")
Text(8,Y+10→Y,"Quit")
Fix 0:Fix 4
DispGraph

FnOn
Repeat getKey(15)
 Stop  .Conserve batteries!
End
FnOff

.Input: Arg1 = File number to look up
Lbl GET
 Copy("appvBLUTCH1",L₁,9)  .Copy the name to L₁
 r₁+'0'→{L₁+7}  .Overwrite the last character
Return GetCalc(L₁)  .Find the appvar
   
   
Code: (Insane (optimized) Axe code) [Select]
..MENU

ClrDraw
Fix 1:Fix 5
Text(0*256+1)
Text "blut"
10*256+8sub(SMP)
⁻3
While 1
 +1→I
 If +3sub(GET)
  Copy("Chap "[],L₁+2,5)
  L₁+2sub(PMI)
 End
End!If I
"Help"sub(PMI)
"Quit"sub(PMI)
Fix 0:Fix 4
DispGraph

FnOn
While 1
 Stop  .Conserve batteries!
EndIf getKey(15)
FnOff

.Input: File number to look up
Lbl GET
 +'0'→{L₁+7}ʳ  .Write the number and terminator
 Copy("appvBLUTCH"[],L₁,7)  .Copy the name to L₁
Return GetCalc(L₁)  .Find the appvar

.Print Menu Item
Lbl PMI
 Text
 P+2560
.Set Menu Position
Lbl SMP
 Text(→P)
Return
   
Title: Re: Using AppVars, more help!
Post by: XVicarious on June 30, 2011, 12:14:09 am
Thank you SOOO much Runer112. That Helped sooooo sooo much!
About my other question? Look either a couple posts up or the edit on the first post please.

edit:
Code: [Select]
.ROTT
GetCalc("appvROTTDATA")->A
ClrDraw
Pt-On(8,8,A)
DispGraph
Repeat getKey(15)
End
Title: Re: Using AppVars, more help!
Post by: Quigibo on June 30, 2011, 04:31:30 am
If you want to copy the contents of an appvar to the TI-OS Pic1, you could do it with this one line of code.  However, I would do the checks that I'm ignoring to make sure the appvar exists and that there was enough ram to create the picture if it didn't already exist.

Code: [Select]
Copy(GetCalc("appvMYAPPV"),GetCalc("Pic1",768),768)
If you mean to copy it to the buffer for drawing over, then you would do this:

Code: [Select]
Copy(GetCalc("appvMYAPPV"),L6,768)
Since appvars could be located anywhere in RAM you cannot refer to them with static pointers such as Pic1, you would have to use variables instead.