Author Topic: Subroutines, arrays, and screen manipulation - oh my!  (Read 3455 times)

0 Members and 1 Guest are viewing this topic.

Offline alberthrocks

  • Moderator
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 876
  • Rating: +103/-10
    • View Profile
Subroutines, arrays, and screen manipulation - oh my!
« 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
Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/


Proud member of ClrHome!

Miss my old signature? Here it is!
Spoiler For Signature:
Alternate "New" IRC post notification bot (Newy) down? Go here to reset it! http://withg.org/albert/cpuhero/

Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/

Activity remains limited due to busyness from school et al. Sorry! :( Feel free to PM, email, or if you know me well enough, FB me if you have a question/concern. :)

Don't expect me to be online 24/7 until summer. Contact me via FB if you feel it's urgent.


Proud member of ClrHome!

Spoiler For "My Projects! :D":
Projects:

Computer/Web/IRC Projects:
C______c: 0% done (Doing planning and trying to not forget it :P)
A_____m: 40% done (Need to develop a sophisticated process queue, and a pretty web GUI)
AtomBot v3.0: 0% done (Planning stage, may do a litmus test of developer wants in the future)
IdeaFrenzy: 0% done (Planning and trying to not forget it :P)
wxWabbitemu: 40% done (NEED MOAR FEATURES :P)

Calculator Projects:
M__ C_____ (an A____ _____ clone): 0% done (Need to figure out physics and Axe)
C2I: 0% done (planning, checking the demand for it, and dreaming :P)

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Subroutines, arrays, and screen manipulation - oh my!
« Reply #1 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 ;)

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
« Last Edit: July 22, 2011, 05:34:23 pm by Deep Thought »




Offline shmibs

  • しらす丼
  • Administrator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2132
  • Rating: +281/-3
  • try to be ok, ok?
    • View Profile
    • shmibbles.me
Re: Subroutines, arrays, and screen manipulation - oh my!
« Reply #2 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.
« Last Edit: February 27, 2011, 01:02:59 am by shmibs »

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Subroutines, arrays, and screen manipulation - oh my!
« Reply #3 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

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Subroutines, arrays, and screen manipulation - oh my!
« Reply #4 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.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Subroutines, arrays, and screen manipulation - oh my!
« Reply #5 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.