Notes on Graphics_Demo.spin

Custom PCB Boards Getting Started Tips Timing Pulse Generation Object Exchange FAQ Programming Examples

bullet

First, note that the screen is divided up into 16x16 pixel "tiles".  Each tile can have 4 different colors.

bullet

There are 3 arrays used to define the screen:  Bitmap, Display, and Screen

bullet

Screen is the only formally declared array.  It is an array of words, one for every 16x16 pixel tile.  Each member in the array is a pointer to the actual pixel data as well as a pointer to 1 of the 64 sets of colors. 

bullet
It is a bit complex how each word member of Screen can be a pointer (which is a word size, 16 bits) as well as hold the color info (6 bits).  But, this has to do with alignment...  The Display array that Screen points to is aligned so that the last 6 bits of each address are always 0.  So, these 6 bits are used to also hold the color info.
bullet

The bitmap and display arrays are not declared, but just reserved memory.  The base addresses are declared by these lines:

bitmap_base = $2000
display_base = $5000
bullet
Note that the "display_base" address should end in "00" for reasons of alignment, discussed above.
bullet
These arrays take up most of the 32kB of hub RAM.  The bitmap array extends from $2000 up to  $4FFF and the display array extends from $5000 up to $7FFF (the end of memory).   
bullet
Because there is so little room left for actual code, this compiler directive:
_stack = ($3000 + $3000 + 100) >> 2 'accomodate display memory and stack
bullet
Is used to reserve the space for these arrays, about 12kB each.
bullet

The Display array holds the actual pixel data for the graphics that is displayed on the screen.  The Screen array is filled with pointers to the Display array.

bullet

The Bitmap array is just like the Display array, but it is the working buffer to draw on.  After all the drawing is done for the next frame, the entire Bitmap array is copied to the Display array.  Then, the Bitmap array is cleared and work begins on drawing the next frame into it.  This gives a flicker-free display.

bullet

Each tile takes 16 longs (64 bytes or 512 bits) to represent it as each tile is 16x16 pixels by 2 bits of color (4 possible color values). 

bullet

The screen is made up of 16x12 tiles.  So, the total memory requirement is 16x12x16 = 3,072 longs = 12,288 Bytes.  Note that 12,288 is $3000 in hex, which explains the size of Bitmap and Display arrays.

bullet

Each 16x16 pixel tile has a pre-defined set of 4 colors. 

bullet

There are 64 sets of 4 colors each stored in the Colors array that is passed to the Graphics driver.  Each color is defined by 1 byte, so each set of 4 colors is a long, which is why the Colors array is an array of 64 longs.

bullet

Find more info about the TV colors here.

bullet

6 bits in every word of the Screen array hold the selection of color set for each tile.

bullet

In this demo all tiles have 3 of the 4 colors the same (black, white, and blue).  

bullet

The 4th color varies from tile to tile.  Each row is given the same 4th color.  So, the 4th color is graded from top to bottom.  At the top it is green and at the bottom it is purple.

bullet

Note that only 12 of the 64 sets of colors are actually used by the demo since there are only 12 rows of tiles.