actually this is written for a hackvision atm but changing it to work for the video game shield would be easy (i have both). The only thing is this requires the latest TVout as it uses TVouts version of millis() and the new bitmap function which is a very recent addition. All the other changes would be simple to get working on the version of TVout that nootropic has posted for the hackvision.
The simple tetris clone is a great bit of code it takes care of all the computation you are just left to code the input and output.
Short video of me loosing: [media]http://www.youtube.com/watch?v=Bawl3-wNE7Q[/media]
It uses a modified version of simple tetris clone The only modifications are some quick datatype changes (ints to chars ect) to fit with the memory constraints. This could also be easily used with a Tellymate shield if one desires with no extra effort.
I will release post the sketch when I fix a small bug that kills the input randomly.
The 168 does not have enough memory for the default resolution. It will return an error while calling TV.begin()/TV.start_render() (error code 4). The horizontal resolution/8*vertical resolution must be lower than the amount of sram that the device has. I don't know how much memory pong requires so a change in resolution will be required but to what I don't know. The lowest horizontal resolution is 104(must be a multiple of and there is no limit to how small the vertical resolution is.
Thats great PlayMoney I was going to mention my library in this thread, then you had created a full pong game on top of it, if I had a pot that did not require a screw driver to operate I would have to try it.
As far as color goes thats beyond the scope of the library, gray scale is possible with some slight modifications to the library but it would require twice as much memory.
PAL is super easy just change _NTSC to _PAL when you call begin.
Given a device with enough memory TVout can already go up to 256x216 for NTSC and 256x260 for PAL. I have also considered creating a new render mode that would use the second USART on some devices in SPI transmit mode with no start stop or parity bits to create a faster method of output(360 pixels/line @16mhz).
I also already plan on implementing 2bit gray-scale version when I get it to a feature complete point, which would just involve changing the core and leaving the public interface alone. If I ever have time I also would like to create a VGA version this library that would have 4bit color(16 colors) however the highest possible resolution for VGA @16mhz would be 128x96, or 16x120 @20mhz (if I remember correctly).
Im very intrigued as to how this artifact color is actually generated, the pictures are very impressive.
There is a serial terminal demo sketch in the most recent version of the library(not released in a zip file, get it from the source section of the google code page). If you want to use it please be aware of the fact the video pin changed to digital pin 7 for higher output resolution support; the sync pin stays the same and cannot be changed.
//---------------------------------------------------------------------------------- // Communication Functions //----------------------------------------------------------------------------------
//send a byte to the lcd void send_byte ( unsigned char command ) { A1_0; setLCDBUS(command); CS_0; WR0_0; WR0_1; CS_1; }// end send_byte
//close the byte stream of commands void close_byte() { A1_1; setLCDBUS(0x01); CS_0; WR0_0; WR0_1; CS_1; }// end close_byte
//send a full command package void send_package(unsigned char *package) { unsigned char i; for (i = *package; i ; i--) send_byte( *(++package)); close_byte(); #if us_delay delayMicroseconds(package_delay*us_scale); #else delay(package_delay); #endif }// end send_package
//---------------------------------------------------------------------------------- // Color Set Functions //----------------------------------------------------------------------------------
//set the forground color of shapes (the color of the shape void set_color_fg(unsigned int color) { unsigned char Buffer[4];
Buffer[0]=3; Buffer[1]=0x20; Buffer[2]=color; Buffer[3]=color>>8; send_package(Buffer); }// end SetFgColor
// set the font forground color (the color of the text) // setting the regular fg will also set the fg for the font. void set_color_fg_font(unsigned int color) { unsigned char Buffer[4];
Buffer[0]=3; Buffer[1]=0x14; Buffer[2]=color; Buffer[3]=color>>8; send_package(Buffer); }// end SetFontFgColor
// set the font background color (the color backdrop behind the text) void set_color_bg(unsigned int color) { unsigned char Buffer[4];
Buffer[0]=3; Buffer[1]=0x15; Buffer[2]=color; Buffer[3]=color>>8; send_package(Buffer); }// end SetFontBgColor
//------------------------------------------- // Prints a 16-bit bitmap //------------------------------------------- void show_bmp( unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int * bmp) { unsigned char Buffer[5]; unsigned int i,j,k; unsigned long p = 0; unsigned long addr = y*640 + 2*x;
//--------------------------------------- // initialize a full screen direct draw 1 frame. //--------------------------------------- void fdd_init(unsigned int line) { // the following 2 lines are the equivalent of addr = line * 640 // however that overflows due to the size of the variable line? unsigned long addr = line*5; addr = addr << 7;
//-------------------------------------- // send a direct draw package consisting of 16 pixels //-------------------------------------- void fdd_sendpackage( unsigned int *pkg ) {
send_byte(0x84); send_byte(32);
for (int i = 0; i < 16; i++) { send_byte(pkg[i]); send_byte(pkg[i]>>8); } close_byte(); delayMicroseconds(110); }
// setup the port directions DDRD |= 0xFC; // set pins 2-7 on port D to be output DDRB |= 0x07; // set pins 0 and 1 on port B to be output //DDRD = 0xFF; DDRC = B00110111;
//Initialize the ports //set command to 0xFF setLCDBUS(0xFF); CS_1; RES_0; A1_0; RD_1; WR0_1;
// data bus is defined as // high 6 bits are on PORTD.2 through PORTD.7 // low 2 bits are on PORTB.0 and PORTB.1
// color definitions #define RED 0xf800 #define GREEN 0x07e0 #define BLUE 0x001f #define YELLOW 0xffe0 #define CYAN 0x07ff #define MAGENTA 0xf81f #define BLACK 0x0000 #define WHITE 0xffff #define GRAY 0xdefb
//----------------------------------------------------------------------------- // Communication Functions //-----------------------------------------------------------------------------
// put the 8 bit word onto the bus void setLCDBUS(unsigned char command);
//send a byte to the lcd void send_byte ( unsigned char command );
//close the byte stream of commands void close_byte();
//send a full command package void send_package(unsigned char *package);
//------------------------------------------------------------------------------ // Color Set Functions //------------------------------------------------------------------------------
//set the foreground color of shapes (the color of the shape void set_color_fg(unsigned int color);
// set the font foreground color (the color of the text) // setting the regular fg will also set the fg for the font. void set_color_fg_font(unsigned int color);
// set the font background color (the color backdrop behind the text) void set_color_bg(unsigned int color);
//set a pixel void set_pixel(unsigned int X, unsigned int Y);
//Draw a line void draw_line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2);
//Draw an empty rectangle void draw_rect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2);
//draw an empty circle void draw_circle(unsigned int X, unsigned int Y, unsigned char R);
// fill a rectangle void fill_rect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2);
//draw a filled circle void fill_circle(unsigned int X, unsigned int Y, unsigned char R);
//----------------------------------- // String Routine // max 64 byte in string // size s = 8x8 font // m = 16x16 GB2312-80 (External ROM) // b = 16x16 BIG5 (External ROM) //----------------------------------- void print_string(unsigned int X, unsigned int Y, unsigned char *pstr, unsigned char size);
// print a character at X,Y void printchar(unsigned int X, unsigned int Y, unsigned char character);
//----------------------------------- // Prints a 16-bit bitmap // x,y = coordinates of the top left corner of the bmp // w = the width in pixels of the bmp // h = the height in pixels of the bmp //----------------------------------- void show_bmp( unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int * bmp);
//----------------------------------- // Initilizes required values for a full screen direct draw // This is used when a full frame is to be written directy to the // the LCD. It is faster then primative shape drawing. //----------------------------------- void fdd_init(unsigned int line);
//---------------------------------- // draw 16 pixels to the screen as a package // pkg = the 16 pixels to be drawn, anything beyond the 16 will be ignored. // // fdd_init() MUST be called first //---------------------------------- void fdd_sendpackage(unsigned int *pkg);
//----------------------------------------------------------------------------- // initialization function //----------------------------------------------------------------------------- void init_lcd();
I got most of the hardware functions working; I never did try to get the sprites working. The library I created is in the next two posts.
Anyway here is my implementation of the game of life on a 320x240 color lcd. [media]http://www.youtube.com/watch?v=g5kAbDZXEb8[/media] there are 40x30 cells as the only way I could get a reasonable amount of speed out of the LCD was to feed it the data as special characters that are either a blank character of solid block character.
Anyway here is the life sketch:
Code:
#include <TCB8000C.h> #include <stdlib.h>
#define ALIVE 1 #define DEAD 0
#define bheight 30 #define bwidth 40 // must be devisable by 8
char isAlive(int x, int y) { int xindex = x >> 3; // shift operation is is the same as (x-1)/8 int bit = x & B00000111; // same as char mask = B10000000 >> bit;
return board[cdisplay][y][xindex] & mask; }
void update() { char count; for (int y = 0; y < bheight; y++) { for (int x = 0; x < bwidth; x++) { count = neighbors(x,y);
char neighbors( int x, int y ) { char count = 0; if ( x > 0 && x < bwidth-1 && y > 0 && y < bheight-1 ) { // 3 above if ( isAlive(x-1,y-1) ) count++; if ( isAlive(x,y-1) ) count++; if ( isAlive(x+1,y-1) ) count++;
// 2 to each side if ( isAlive(x-1,y) ) count++; if ( isAlive(x+1,y) ) count++;
// 3 below if ( isAlive(x-1,y+1) ) count++; if ( isAlive(x,y+1) ) count++; if ( isAlive(x+1,y+1) ) count++; } else if ( x == 0 && y == 0 ) { if ( isAlive(x+1,y) ) count++; if ( isAlive(x,y+1) ) count++; if ( isAlive(x+1,y+1) ) count++; } else if ( x == bwidth-1 && y == bheight-1 ) { if ( isAlive(x-1,y-1) ) count++; if ( isAlive(x,y-1) ) count++; if ( isAlive(x-1,y) ) count++; } else if ( x == 0 ) { if ( isAlive(x,y-1) ) count++; if ( isAlive(x+1,y-1) ) count++; if ( isAlive(x+1,y) ) count++; if ( isAlive(x,y+1) ) count++; if ( isAlive(x+1,y+1) ) count++; } else if ( x == bwidth-1 ) { if ( isAlive(x-1,y-1) ) count++; if ( isAlive(x,y-1) ) count++; if ( isAlive(x-1,y) ) count++; if ( isAlive(x-1,y+1) ) count++; if ( isAlive(x,y+1) ) count++; } else if ( y == 0 ) { if ( isAlive(x-1,y) ) count++; if ( isAlive(x+1,y) ) count++; if ( isAlive(x-1,y+1) ) count++; if ( isAlive(x,y+1) ) count++; if ( isAlive(x+1,y+1) ) count++; } else { if ( isAlive(x-1,y-1) ) count++; if ( isAlive(x,y-1) ) count++; if ( isAlive(x+1,y-1) ) count++; if ( isAlive(x-1,y) ) count++; if ( isAlive(x+1,y) ) count++; } return count; }
void setCell(int x, int y, int b, char status) { int xindex = x >> 3; // shift operation is is the same as (x-1)/8 int bit = x & B00000111; // same as char mask = B10000000 >> bit;
yeah I agree that font I have is crap, If anyone knows of a good way to convert fonts to bitmaps that would be very helpful. Ive looked and looked for something that will do what I need to no avail. Ive found a few but they dont give me info on the how the byte is arranged.... an 8x8 font would be ideal as it could be placed into memory very fast and should be large enough to look decent(currently its 5x7).
Yes use my library Depends on what you are doing though making a tellemate would be better for text where as TVout is more suited to general graphics.
If you do use TVout I would suggest using the version found in the source section and not one of the ones in a zip file as the pinout has changed and I have a working Serial library.