Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: yunhua98 on June 04, 2010, 06:13:26 pm

Title: How do you read and possibly write to an external program?
Post by: yunhua98 on June 04, 2010, 06:13:26 pm
The topic says it all.
I want to make a level editor for my bomberman program I'm making for the Axe Competition.
I want it so that a user writes a program named BOMBLVL(#/Letter) and the program can automatically detect which programs are there and read from them.  of course I'll probably add a random level generator and some included levels.

If it's not possible to detect many levels, at least one? ???
And then you could name it whatever you want, and you can still make many levels, just Rcl them into a program called BOMBRLVL or whatever I choose.
Title: Re: How do you read and possibly write to an external program?
Post by: calcdude84se on June 04, 2010, 07:30:52 pm
as of now, you can only read programs, not create them. (Okay, not completely true, but the exception is you can overwrite an existing program with another one of the same name)
And for detection of levels, there is no nice way to scan the VAT yet, so you'll have to use GetCalc for each level name to see if it exists. (For this, you can just change the last letter of the name string, so you don't need lots of strings. Code below)
Code: [Select]
.Check for level, with X containing the final character, as stored by 'L'->X
"prgmBOMBLVL?"->Str1
.You can use whatever string, of course, and that question mark is just a dummy placeholder
X->{Str1+8
.The eight is because its the eight character in the string as indexed from zero, the "v" being the zeroth
GetCalc(Str1)->P
If
.Level Found!
Else
.Not found...
End
Something like this would probably be placed in a loop, with X being what is looped, and possibly with the X->{Str1+8 becoming {Str0+X}->{Str1+8 if X is an index to the list of searched characters.
Edit: replaced incorrect "v" with correct "prgm"
Title: Re: How do you read and possibly write to an external program?
Post by: yunhua98 on June 04, 2010, 07:39:59 pm
Hold up..  Have I missed something?!
Are you saying that "vSTRING->Str1:GetCalc(Str1->P also looks for Programs named "String"?, I thought it was just for AppVars?
Title: Re: How do you read and possibly write to an external program?
Post by: calcdude84se on June 04, 2010, 07:49:54 pm
It does, though that should be "prgm", not "v", since "v" returns appvars in preference to programs, while "prgm" does the opposite. Let me correct that typo...
Title: Re: How do you read and possibly write to an external program?
Post by: yunhua98 on June 05, 2010, 07:45:05 pm
OK...
I still don't understand how you would read FROM it though.  As in finding out whats written in it...
Title: Re: How do you read and possibly write to an external program?
Post by: FinaleTI on June 05, 2010, 08:02:31 pm
You could just read bytes from the pointer like, if your pointer is A, then you would just do {A}->{L1} which would store the value of the byte at A to the starting point of the L1 ram area for later reference.
Title: Re: How do you read and possibly write to an external program?
Post by: yunhua98 on June 05, 2010, 08:17:29 pm
I don't get it...
maybe I'm not stating my question clearly, I'm asking how to read from a user created program assuming you already know what that program is called.

@FinaleTI: But how would you know what byte the program is stored in?  Assuming you've understood my question properly.


EDIT:  Oh!  I just figured it out!
Just for confirmation though... Using Calcdude's method I would get the first byte which the program resides.  Then I could read from it with FInaleTI's.
But... How would I tell what was what?  Say I wrote prgmBOMBLVL# as :0123456789 and used the above method, would {L1} end up as 0 and {L1+1} end up as 1 and so on?
Title: Re: How do you read and possibly write to an external program?
Post by: calcdude84se on June 05, 2010, 08:37:35 pm
No, they'd end up as 48, 49, and so on (the hex, $30, $31, and so on looks much nicer, but anyway), because you're reading characters, not what they represent. Basically, what you see in the BASIC program editor is completely different than what the bytes are. (If you want to know the correspondences, here are token tables (http://tibasicdev.wikidot.com/tokens)) Basically, if you want to use the BASIC editor as an editor, you'll have to implement a mini-parser, otherwise just ignore it.
Title: Re: How do you read and possibly write to an external program?
Post by: jnesselr on June 07, 2010, 03:43:55 pm
If It's just numbers, you could just read what character it is, and subtract 48.
Title: Re: How do you read and possibly write to an external program?
Post by: calcdude84se on June 08, 2010, 11:01:45 am
True, but be aware that you'd be using one byte to store one base-10 digit. (only approx. 41.5% of a byte's capacity) Again, the level file format depends on how you plan to edit those files (Your own level editor vs. the TI-BASIC editor)