Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: alberthrocks on February 27, 2011, 12:08:15 am

Title: Subroutines, arrays, and screen manipulation - oh my!
Post by: alberthrocks on February 27, 2011, 12:08:15 am
...as the title says, I have questions about subroutines, arrays, and screen manipulation. ;)
This is in prep for a very secret but awesome project! :D

Let's get started!

Subroutines
1) In a subroutine, are the letter variables (like A-Z, theta, etc.) isolated from the "main" program?
2) In a subroutine, if I'm not using rn (n is a number) for arguments, can I use them and not worry about crashing?
3) Can I call a subroutine from a subroutine? If so, will I lose my rn variables from the origin called subroutine?
4) Can I get more arguments than just r0-r6, or am I stuck with them?

Arrays
1) How do I make string or number arrays in Axe? Please include as many ways as possible to manipulate the array, and obviously read it! :)
2) Is it possible to do an array of an array? If so, how?

Screen Manipulation
1) How can I capture the whole or part of the screen? (And restore it?)
2) With that capture, can I use Pt-On( to move it? If not, how would I do so?

BONUS QUESTION - Axioms ;)
1) If I'm right.... if I want to use more than one Axiom, I could flip flop the "includes" (#Axiom) and use the functions interchangably? (Not at the same time tho)
2) Does compiled Axe code need the Axiom appvar or is the appvar's code included inside the compiled prgm?

I might have more questions in the future, so beware! ;)

Thanks in advance! :D
Title: Re: Subroutines, arrays, and screen manipulation - oh my!
Post by: Deep Toaster on February 27, 2011, 12:18:13 am
1) In a subroutine, are the letter variables (like A-Z, theta, etc.) isolated from the "main" program?

Nope, it's all global. The only local vars are r1-r6 when you save them (by calling the subroutine with sub(LBL,ARG,...)r

2) In a subroutine, if I'm not using rn (n is a number) for arguments, can I use them and not worry about crashing?

Sure, if you don't replace them, they're whatever they were before you called that subroutine.

3) Can I call a subroutine from a subroutine? If so, will I lose my rn variables from the origin called subroutine?

That's what the sub(LBL,ARG,...)r syntax is for. It saves your r-vars.

4) Can I get more arguments than just r0-r6, or am I stuck with them?

You can always use global vars, as well as X1T-Y3T.

1) How do I make string or number arrays in Axe? Please include as many ways as possible to manipulate the array, and obviously read it! :)

See my array tutorial ;) (http://clrhome.co.cc/tutorials/arrays/)

2) Is it possible to do an array of an array? If so, how?

I guess you could put references (pointers) to each array as elements of the array, but it would get pretty complex. Certainly possible, though.

1) How can I capture the whole or part of the screen? (And restore it?)

L6 is known as the "graph buffer" because it's used as an in-RAM representation of what's on the screen. You draw whatever you want to the buffer, then use DispGraph to copy it to the display, and you can play with L6 however you want. It's just RAM, after all.

StoreGDB copies whatever's on the LCD to the graph buffer.

2) With that capture, can I use Pt-On( to move it? If not, how would I do so?

All drawing commands except Text(, Text, and Bitmap( draw only to the buffer.

1) If I'm right.... if I want to use more than one Axiom, I could flip flop the "includes" (#Axiom) and use the functions interchangably? (Not at the same time tho)

Nope, #Axiom( is a precompiler instruction. You can use multiple Axioms in one program, but they need to be different tokens.

2) Does compiled Axe code need the Axiom appvar or is the appvar's code included inside the compiled prgm?

Not at all.

EDIT: Holy crap, I didn't even get ninja'd O.O
Title: Re: Subroutines, arrays, and screen manipulation - oh my!
Post by: shmibs on February 27, 2011, 01:01:40 am
if you want to capture and move a portion of the buffer around the screen then you are going to need to set up an array in free RAM. find the position of the portion you want(it has to be byte alligned, unless you want to use pixel test) in L6 (the position will be the horizontal, byte-alligned position [0-11] and the vertical, pixel alligned position [0-63]) and do something like this:
Code: [Select]
[offset to selection in L6]->A
for(N,0,[selection height in bytes-1]
for(M,0,7
for(L,0,[selection width in bytes-1]
{N*8+M*[selection width in bytes-1]+L+A+L6}->{N*[selection width in bytes-1](L*8)+M+L1}
End
End
End

the data for your selection(as long as it's small enough to fit in the free RAM without overflowing. if you need more space than is available in L1, your best bet is to either relocate the vars to a different spot in free RAM, or to create a 768 byte appvar and store it there.) should now be stored in L1. to draw it on the screen using Pt-on simply do something like this:
Code: [Select]
[X draw offset]->A
[Y draw offset]->B
for(M,0,[selection height in bytes-1]
for(L,0,[selection width in bytes-1]
Pt-On(L*8,M*8,{M*[selection width in bytes-1]*8+(L*8)+L1
End
End

disclaimer:there are probably horrific errors in this code that i am somehow missing, as that tends to be the case. also, these routines can be optimised considerably. they are in their current form for readibility.
Title: Re: Subroutines, arrays, and screen manipulation - oh my!
Post by: squidgetx on February 27, 2011, 10:40:55 am
Yeah, the r variables are really just the same as A-theta. You can even store to them with the store arrow, which I use a lot for optimization hacks or if I need a temp variable in a pinch.

Also, to save your arguments, the syntax is sub(LBLr,...) not sub(LBL,..)r
Title: Re: Subroutines, arrays, and screen manipulation - oh my!
Post by: Quigibo on February 27, 2011, 01:54:44 pm
Flip-flopping axioms won't work because the axioms are looked at in the order they are imported, and the limit is 5 axioms per program.  If you need to use 2 sets of Axioms, just make sure they use different token combinations and you won't have any conflicts.  If they do use the same token combinations, you can probably change the source and recompile the Axiom to use a different token since I assume most axioms will be open source.

You do not need the Axiom appvar to execute the program, just to compile.  Axioms work a lot like the Asm() command, but smarter and with readable syntax.
Title: Re: Subroutines, arrays, and screen manipulation - oh my!
Post by: Deep Toaster on March 13, 2011, 12:39:07 pm
Also, to save your arguments, the syntax is sub(LBLr,...) not sub(LBL,..)r

Whoops, I keep getting that confused. I rarely use the r for sub( because I don't need it, and it takes more mem.