"Advanced TI-82 Programming Techniques"

by Frank Force

Hey hey hey! Thanks for the big response to my last article. I was being sarcastic, you jerks. I got about three letters, so no thanks to you. Really, I need questions, send them to me at *****@voicent.com, ok? Lets see what I can pull out of my hat for this issue.


Last issue I said this: Pxl-Test() will tell if a given pixel is on or off; 1 for on, 2 for off. Of course this would be incorrect. Pxl-Test() will return 1 for on and 0 for off; the same as any other logic test.


You probably noticed these commands in the program menu under ctl, but don't know what they do. Well that's ok because they're not all that useful and I'll tell you why. First off, what do they do? The format of the commands look like this:

:IS>(variable, value)
:DS<(variable, value)
IS>() increments variable by one and skips commandA if variable is more then value. DS<() decrements variable by one and skips commandA if variable is less then value. This is where commandA is the immediate next line after IS>() or DS<(). Your instincts may tell you to use it in conjunction with a goto like this:
:0 -> X
:Lbl 1
:(looping code here)
:IS>(X, 10)
:Goto 1
That will loop from when X=0 to X=10. But I keep telling you, DON'T USE GOTO! Instead, a more efficient version would be:
:For(X, 0, 10)
:(looping code here)
What happens when you leave the line after IS>() or DS<() blank? It will cause the variable to be incremented or decremented by 1 and that's all. But it's faster to just simply add or subtract one to the variable. I think this function is useless for the most part. It may have worked if it just added one to the variable and didn't bother with the next command. I have never used these functions in one of my programs. That's all I have to say about that.


You can use log to measure the amount of digits in an integer. 1 + int log (value) That's all you need. I should also mention that this will only work for values above and not including 0. When displaying variables to the graph or home screen, you can use this principal to center numbers. The following example will center A on the graph at the pixel (31, 47), which is the center of the screen:

:Text(28, 46 - 2int log A, A)

I subtracted 3 from the Y coordinate (which comes first). This is because all numbers on the graph are 7 pixels high. On the X coordinate I subtracted the formula that I told you before times 2 because numbers on the graph are 4 pixels wide. So I subtracted half, get it, half of something is in the center of it. Also note that the X coord changed to 46. The 1 in the original formula got subtracted from it. Ok, see if you can figure any of that out, and try it for yourself. I will also mention that this should not appear during normal program flow because log is a relatively slow function.


Ok, kids, here's even more reasons to use subprograms. Our friend Brian Hill sent me these reasons why he uses subprograms. Lets take a look at what he said.

1. When you change your entire program into a series of subprograms, you get rid of many Goto's and create the proper loops, since you can't do a Goto to another program.

2. You can rearrange the different parts if you need to. For example, I created an ENDGAME subprogram. I found that where I originally had it was not the best place, and used unnecessary code. So, I just moved the subprogram to a different place. If I had not cut the program up, I probably would have never noticed this.

3. Editing the program as a whole is so much easier. If you want to change one specific part, you don't have to go through the entire program looking for the code you want to change. All you do is edit the appropriate subprogram. This saves lots of time wasted scrolling, and you know that you won't accidentally change other parts of the program.

4. You can optimize the program one part at a time. Start with one subprogram, optimize, and then go to the next. Much easier than trying to keep track of what parts of one big program you have or have not optimized.

5. When you are done, if the subprogram only has one call, then you can easily recall it back to the main program. With Puzzler3, I have about 8 subprograms. The game would work fine if I left it with all the subprograms. However, it would be much easier to run if I put all the subprograms back into the main program, so all I need to run the game is one file.

Basically Brian uses subprograms to make programs easier to edit and optimize. Also the obvious reason is that they're faster. Special thanks to Brian for this.


That's it for volume 5. PLEASE SEND ME E-MAIL!!!! *****@voicent.com!!!! Get it? I need questions and suggestions for next issue. Again I have nothing planned. Send me questions or you will be punished! (well not really but that's what I like to think) Please, I'm begging you. I'm desperate for material. OK, that's it, see you next time.