Difference between revisions of "XLIBC for Beginners"

From Learn @ Cemetech
Jump to navigationJump to search
 
Line 213: Line 213:
  
 
= How to make a spritesheet =
 
= How to make a spritesheet =
 +
----
  
 
= How to make a tilemap =
 
= How to make a tilemap =
 +
----
  
 
= Example program =
 
= Example program =
 +
----
 +
 
In this section, we want to make a program together with you.
 
In this section, we want to make a program together with you.
 
  :CODE GOES
 
  :CODE GOES

Latest revision as of 06:57, 26 February 2016

This is a tutorial for people who definitely want to use Hybrid Basic, but don't know how to start, and what you can do with it.

What is Hybrid Basic?

Hybrid Basic is an addition to normal Basic, the standard programming language on (TI) calculators. Better said, with Hybrid Basic, you can use the standard Basic, and even some new features. Hybrid Basic is designed for very fast graphics, so if you want a nice game, with some graphics, we encourage you to use Hybrid Basic!

Getting Ready to Program

Make sure you have DoorsCSE installed on your calculator. You also will want to install TokenIDE on your computer. Doors CSE adds the xLIBC library, as well as many helpful features for your calculator. TokenIDE features an image editor and building tools for the xLIBC library.


Windows:

Unpack the downloaded zip and double click TokenIDE.exe in the folder. DO NOT remove TokenIDE from the folder, as it will not work when removed from its dependencies. You can create a shortcut to the destop if navigating to a folder annoys you.


Linux:

Using TokenIDE on linux is a little roundabout, but it can be done. You just have to install Mono (A wine-like program that includes .net) and then cd to the directory of the program and run Run TokenIDE

Install Mono

sudo apt-get install mono-complete

Run TokenIDE

mono TokenIDE.exe

If you get an error like shown below, go into the TokenIDE.ini and change all of the forward-slashes to back-slashes

Unable to load default file, Tokens/DCSE.xml quitting

Commands

real(0 - xLIBCSetup


The basic of the the xLIBC functions is the half-resolution. This works as follows: the screen as you normally see will being splitted in two halves. One half would be stretched, the other half you don't see, that would being our buffer. That would look like this:

File:Half-res.gif

As you can see, there is no second half.

Very important! All the xLIBC functions expected to be in half-res mode!

These are the functions of real(0 :

GetXLIBCVersion

:real(0,0) -> returns the version of xLIBC in Ans, for me it returns 2.

SetupGraphics

:real(0,1,1) -> this enables the half-res mode, as you can see in the previous image.
:real(0,1,0,0) -> this returns to the normal mode, WITHOUT redrawing the status bar! This might being useful for some games, which are not in the half-res mode, but do not want to see the status bar. 
:real(0,1,0,1) -> this returns to the normal mode, and redraws the statusbar.  

Very important! Don't forget to switch the half-res mode off, or the TIOS will stuck in this mode!

Half-res-program-ended.gif


SetSpeed

:real(0,2,0) -> Disable fast (15MHz) mode, switching to 6MHz mode 
:real(0,2,1) -> Enable fast (15MHz) mode

Note: the default CPU speed is 15MHz. Try it, and see the difference.

SetupColorMode

:real(0,3,0) -> enables all the possible colors in xLIBC 
:real(0,3,1) -> enables 8COLOUR - I have no idea what changes with this. 
:real(0,3,2) -> inverts the screen, like black->white and white->black. It gets each color value per pixel, and then 255-(color_value) would be the new color value. To restore it back, invert it again, or -> 
:real(0,3,3) -> restores the colors back to normal, useful for moments if you do not know whether the colors are inverted or not. 
:real(0,3,4,(color_value),(update_LCD)) -> fills the active half of the screen with one color from the color palette, useful for backgroud. I will explain the update_LCD later. 
:real(0,3,5,(color_value)) -> I cannot get this working, but the wiki says that it will change the color value per pixel with shapes and sprites 

File:Invertscreen.gif

real(1 - UserVariables


xLIBC has the facility to utilize 'internal user variables' for data storage and calculations as opposed to using TI-OS variables. They work exactly the same, but the main difference is, is that they are faster, and temporary, which means that you cannot 'save' them for other programs. Some xLIBC functions expected (only) UserVars, so it is always handy to learn and use these.

These are the functions of real(1:

GetUservar

real(1,0,(uservar_num))

This returns the value of the UserVar in Ans

SetUservar

real(1,1,(uservar_num),(value))

This function writes (value) to UserVar

AddToUservar

real(1,2,(uservar_num),(value))

This function add (value) to UserVar

SubFromUservar

real(1,3,(uservar_num),(value))

This function subtracts (value) to UserVar

Example

:real(1,1,1,5 // Sets uservar 1 to 5
:Disp real(1,0,1 // Displays Uservar 1
:real(1,2,1,3 // Adds 3 to uservar 1
:Disp real(1,0,1
:real(1,3,1,7 // Subtracts 7 from uservar 1
:Disp real(1,0,1
:Pause //Pauses program

Try the above code out on your calculator!

real(2 - GetKey


These routines have been significantly overhauled from the TI-BASIC getKey function and are even more comprehensive.

These are the functions of real(2:

GetKey

real(2,0,0)

Key code stored in Ans Very important! These values are NOT the same as the values of getKey, but it returns the values of _GetCSC:

File:Keycodes xLIBC.png

GetKeyCheckList

real(2,0,1,(getkey_checknum),(getkey_keyvalue),(getKey_uservar),(getkey_value),... )

This updates (getkey_uservar) by (getkey_value) if you pressed (getkey_keyvalue). (getkey_checknum) is the amount of UserVars to update. Useful for counters or sprites.

GetKeyArrows

real(2,1,(uservar_x),(uservar_y),(value_x),(value_y))

This updates (uservar_x) and (uservar_y) with respective (value_x) and (value_y) if you pressed any arrow.

  • If up is pressed then USERVAR_Y = USERVAR_Y - VALUE_Y
  • If down is pressed then USERVAR_Y = USERVAR_Y + VALUE_Y
  • If left is pressed then USERVAR_X = USERVAR_X - VALUE_X
  • If right is pressed then USERVAR_X = USERVAR_X + VALUE_X

GetKeyArrowsDiagonals

real(2,2,(uservar_x),(uservar_y),(value_x),(value_y))

This works the same as GetKeyArrows, with the exception that a combination of the arrows also will update the UserVars.

  • If up is pressed then USERVAR_Y = USERVAR_Y - VALUE_Y
  • If down is pressed then USERVAR_Y = USERVAR_Y + VALUE_Y
  • If left is pressed then USERVAR_X = USERVAR_X - VALUE_X
  • If right is pressed then USERVAR_X = USERVAR_X + VALUE_X
  • If up+left is pressed then USERVAR_Y = USERVAR_Y - VALUE_Y, USERVAR_X = USERVAR_X - VALUE_X
  • If up+right is pressed then USERVAR_Y = USERVAR_Y - VALUE_Y, USERVAR_X = USERVAR_X + VALUE_X
  • If down+left is pressed then USERVAR_Y = USERVAR_Y + VALUE_Y, USERVAR_X = USERVAR_X - VALUE_X
  • If down+right is pressed then USERVAR_Y = USERVAR_Y + VALUE_Y, USERVAR_X = USERVAR_X + VALUE_X

GetKeyArrowsCheckTile

real(2,3,(uservar_x),(uservar_y),(value_x),(value_y),(uservar_mapwidth),(collisiontile),(mapstring),(x_left),(y_up),(x_right),(y_bottom))

This routine will only update the UserVars with their values if the move is to a walkable tile (see real(3) - DrawMap). You must specify an UserVar with the width of the map (that is often 20, 160/Cool. It checks for a box from (X_left, Y_top) to (X_right, Y_bottom). For a single sprite of 8x8 pixels, that would be (X_sprite+0, Y_sprite+0, X_sprite+7, Y_sprite+7).

GetKeyArrowsDiagonalsCheckTile

real(2,4,(uservar_x),(uservar_y),(value_x),(value_y),(uservar_mapwidth),(collisiontile),(mapstring),(x_left),(y_up),(x_right),(y_bottom)) -> same as above, now with diagonals.


GetKeyArrowsCheckTileList

real(2,5,(uservar_x),(uservar_y),(value_x),(value_y),(uservar_mapwidth),(collisiontile),(mapstring),(x_left),(y_up),(x_right),(y_bottom))

It works the same as real(2,3....), but now it will return information regarding any keypress and any collided tiles in a 'real list' contained in a user-defined list named "XL". XL have the following format: {key_press , num_collided_tiles , collided_tiles_list} key_press returns ~1 for noarrow, 0 for up, 1 for down, 2 for left and 3 for right. num_collided_tiles is the number of tiles collided against collided_tiles_list is a list of collided tiles against.

GetKeyArrowsDiagonalsCheckTileList

real(2,6,(uservar_x),(uservar_y),(value_x),(value_y),(uservar_mapwidth),(collisiontile),(mapstring),(x_left),(y_up),(x_right),(y_bottom))

Same as above, now with diagonals.

All of these routines are pretty useful, for smarter and better movement.

real(3 - DrawMap


Explanation

real(4 - DrawSprite


Explanation

real(5 - ManagePic


Explanation

real(6 - DrawString


Explanation

real(7 - DrawShape


Explanation

real(8 - xLIBCUtility


Explanation

real(9 - UpdateLCD


Explanation

How to make a spritesheet


How to make a tilemap


Example program


In this section, we want to make a program together with you.

:CODE GOES
:ONE SPACE IN FROM THE MARGIN
:SO MEDIAWIKI CAN PUT IT IN A BOX

You can also add emphasis and use other tools to mark up text.

This Tutorial is in Development


Go the development thread for information and current progress.