ICE:Tips and Tricks

From Learn @ Cemetech
Jump to navigationJump to search

Double buffering

Double buffering is used avoid flickering, when you want to redraw sprites at other coordinates, and need to erase the old ones. In 8bpp, the vRAM area is large enough to hold 2 screen buffers, and you can set the LCD which area to display, the first half or the second half. To avoid flickering, you must draw to the buffer, which isn't visible yet, and when everything is drawn, swap the LCD pointer, and draw again to the buffer. You can do that with this piece of code:

SetDraw(1)
While/Repeat <condition>
<clear buffer>
<display sprites>
<code>
SwapDraw
End

Notice the "SwapDraw" at the very end, this swaps the LCD pointers, and displays the buffer.

randInt(

ICE only supports rand, but that unfortunately returns a number between 0 and 16777215. If you want to get a number in between A and B where 0<=A<=B<=16777215, you can use remainder( to get the remainder of rand and an expression. Examples:


randInt(1,6:

1+remainder(rand,6

This gets the remainder of rand and 6, which is a number in between 0 and 5, and increments it with 1, to get a random number in between 1 and 6.


randInt(A,B:

A+remainder(rand,B-A+1

This gets the remainder of rand and B-A+1, which returns a number in between 0 and B-A. Thus, when adding A, it gets a random number A<=X<=B.


As of ICE V2.0, you can now use randInt:

randInt(A,B

Will return a random number A<=X<=B.

randInt(1,10

Will return a random number 1<=X<=10.

Listing Variables

Sometimes you want to list all the available files on calc, and often that are programs, for example when you create a shell or IDE. This is pretty easy with ICE, but you need to know it, so let's see what the possibilities are. We already have DetectVar( and Detect(, so let's use them. The documentation says the first argument is °POS where it should be 0 if the want to find the first variable. Let's use this to create a small code snippet to find all the available programs, and open them!

0->POS
While DetectVar(°POS,0,5)->PROG
OpenVar(PROG,"r",5)->SLOT
...
End