Xlib Tutorial Beginner
by Luby

What is xLIB?

In a nutshell, xLIB allows you to have better graphics in your Basic programs.

In a squirrel's nest (just bigger then a nutshell), xLIB is an Application made by Peter Pandergast that installs a parser hook (don't worry if you don't know what that is) which gives Basic Programs a glimps into ASM type commands that mainly pertain to graphics.

Installing xLIB:
First, download xLIB from TICalc.org.
Then, send it to your calculator with any linking software you like.
Press your Apps button and scroll down to xLIB. Run and press 1 to install.
Done.
Bonus instruction: Print out the readme.

Using xLIB:

Now, you may be asking yourself, "Self.... How do I use this wonderful application?" Well, here's the answer.

xLIB intercepts anytime you use the real( command and converts it into a command.

My first command:

The first thing that xLIB allows you to do that Basic can't is to shut off those five annoying pixels in the upper right hand corner of the screen, better known as the run indicator. The command to do this is real(7,0 Now let's analyze this.

real( = tells the calculator "THIS IS AN xLIB COMMAND"

7 = tells xLIB that this has to do with command 7, which happens to be run indicator. If you have the readme handy, you will see that there are commands from 0-14

0 = parameter 1. The first (and only) parameter that real(7 takes has to do whether you want it on or off

Now, we are going to look at a few other commands that are pretty straight forward.

Clearing screen:
This is pretty simple. real(0,1 will clear the screen. That 1 on the end tells whether we want to update the screen or not. This can be useful if you want to draw the next screen or frame with out the user knowing. But, our optimizers have found a useful feature of xLIB. If you don't specify a parameter, it defaults it to 1. So, if you did real(0 it would clear the screen and update the screen. 2 bytes saved!

Update Screen:
real(6. That's it

KeyPresses:
real(8. It will return (in ANS) what was pressed. The cool thing about this is that it can sense if 2 arrows are being pressed. And it is faster then getkey. See readme for Key Codes.

Graphics:
Here's the reason that xLIB deserves 16kb of memory on my calc. It can draw sprites like none other. A sprite is a block of pixels arranged into an image. How xlib makes these sprites is it copies them off a picture(defined by you) and pastes them onto the screen (where you want). This is a sample sprite sheet. All the sprites are 8*8. Now, brace yourself for the syntax of real(1 {Sprite drawing}

real(1,A,B,C,D,E,F,G,H,I,J
A= The upper right hand corner of where you want the sprite drawn (x coordinate)
B= The upper right hand corner of where you want the sprite drawn (y coordinate)
C= Width of the sprite in bytes.  a byte is 8 pixels, so an 8*8 sprite would have a width of 1 (byte)
D= The height of the sprite in pixels.
E= The picture you are copying the sprite off of.
F= Column (or slot) in which your sprite is.  If we look back at the picture,the 9-volt battery looking thing would be in slot 0, the floppy disk in slot 1, etc. This can be a number from 0 to 11.
G= This is the y coordinate of which you want your sprite. In the example, the first row is 0, the second row 8...
H= How do you want your sprite to be put on the screen? 0 = put it on there exactly as it is 1= AND it on 2= OR it on and 3 is XOR it on.  
I= Do you want it flipped horizontally? 1=yes, 0=no
J= Update LCD? 1=yes, 0=no

Whew. Take a break, go get a glass of water, use the restroom if you need to before I resume.

Ready?

Okay, so here's an example. To display the tank like thing I would use the following code (the picture is Pic0)

real(1,32,45,1,8,0,10,8,0,0,1

And, that yields:

Try some yourself. If you are looking for good sprite editors, there's artistic by Harrierfalcon and PyroEdit by Demon