Hello all,
I have been playing with pal signal generation, and decided to make pong as an example.
I based my video code on work by Benoît ROUSSEAU, found at
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1176757335.
But it didn't work for me, so I rewrote it using information found in.
http://www.amazon.com/Black-Video-Game-Console-Design/dp/0672328208
This code works for both of my (Australian) pal tvs.
All the source on one page
Title screen
during play
schematic
//Arduino Tv framebuffer
//Alastair Parker
//2007
// Video out voltage levels
#define _SYNC 0x00
#define _BLACK 0x01
#define _GRAY 0x02
#define _WHITE 0x03
// dimensions of the screen
#define WIDTH 38
#define HEIGHT 14
//number of lines to display
#define DISPLAY_LINES 240
// update speed for the main loop of the game
#define UPDATE_INTERVAL 1
// positions of the player paddles
#define PLAYER_RIGHT_X 35
#define PLAYER_LEFT_X 2
// maximum velocity of the ball
#define MAX_VEL 10
// locations of the top and bottom virtual bars
#define SCORE_BAR 3
#define BASE_BAR 13
// time to wait while paused
#define DONE_WAITING 30
#define SCORE_WAITING 30
// max player life
#define MAX_LIFE 6
//positions of player life bars
#define PLAYER_LEFT_LIFE 2
#define PLAYER_RIGHT_LIFE 23
// input pins for the player pots
#define PLAYER_LEFT_PIN 2
// currently the same pin
#define PLAYER_RIGHT_PIN 2
//video pins
#define DATA_PIN 9
#define SYNC_PIN 8
// the video frameBuffer
byte frameBuffer[WIDTH][HEIGHT];
// loop indices
byte index, index2;
// pal video line loop
byte line;
// current drawing line in framebuffer
byte newLine;
// flag used in wait loop to indicate that player just scored
boolean justScored=false;
// positions for the left paddle
byte playerLeft;
byte playerLeftOld=-1;
// life for the left player
byte playerLeftLife = MAX_LIFE;
// positions of the right paddle
byte playerRight;
byte playerRightOld=-1;
// life for the right player
byte playerRightLife = MAX_LIFE;
// positions and velocity of the ball
int ballXVel = -1;
int ballYVel = -5;
byte ballXPos = 14;
byte ballYPos = 7;
// loop counters to control the velocity of the ball
byte ballXLoop =MAX_VEL;
byte ballYLoop =MAX_VEL;
// loop counter to for the main loop delay
int waitingCount = 0;
// start postion of the loading bar
byte loadingBar = 2;
// if the left player should be updated or the right
boolean playerLeftTurn=true;
// if we should be waiting for something to happen
boolean waiting=true;
// if displaying the title
boolean showingTitle = true;
// value of the counter controlling the freq of updates
byte updateCounter=0;
// init the variables
void initGame()
{
playerLeftOld=-1;
playerLeftLife = MAX_LIFE;
playerRightOld=-1;
playerRightLife = MAX_LIFE;
ballXVel = -1;
ballYVel = -5;
ballXPos = 14;
ballYPos = 7;
ballXLoop =MAX_VEL;
ballYLoop =MAX_VEL;
waitingCount = 0;
loadingBar = 2;
playerLeftTurn=true;
waiting=true;
showingTitle = true;
justScored=false;
updateCounter=0;
}
// draw a pixel to the buffer
void setPixel(byte x,byte y)
{
frameBuffer[x][y]= _WHITE;
}
void grayPixel(byte x, byte y)
{
frameBuffer[x][y]= _GRAY;
}
// draw a black pixel to the buffer
void clearPixel(byte x,byte y)
{
frameBuffer[x][y]= _BLACK;
}
// draw a paddle
void drawPaddle(byte x,byte y,byte col)
{
frameBuffer[x][y]= col;
frameBuffer[x][y+1]= col;
}
//draw the title message
void drawArduinoPong()
{
//arduino
setPixel(7,3);
setPixel(8,3);
setPixel(15,3);
setPixel(21,3);
setPixel(6,4);
setPixel(8,4);
setPixel(14,4);
setPixel(15,4);
setPixel(28,4);
setPixel(6,5);
setPixel(7,5);
setPixel(8,5);
setPixel(10,5);
setPixel(11,5);
setPixel(13,5);
setPixel(15,5);
setPixel(17,5);
setPixel(19,5);
setPixel(21,5);
setPixel(23,5);
setPixel(24,5);
setPixel(27,5);
setPixel(29,5);
setPixel(6,6);
setPixel(8,6);
setPixel(10,6);
setPixel(14,6);
setPixel(15,6);
setPixel(18,6);
setPixel(19,6);
setPixel(21,6);
setPixel(23,6);
setPixel(25,6);
setPixel(28,6);
//pong
setPixel(10,8);
setPixel(11,8);
setPixel(15,8);
setPixel(16,8);
setPixel(19,8);
setPixel(22,8);
setPixel(24,8);
setPixel(25,8);
setPixel(26,8);
setPixel(10,9);
setPixel(12,9);
setPixel(14,9);
setPixel(17,9);
setPixel(19,9);
setPixel(20,9);
setPixel(22,9);
setPixel(24,9);
setPixel(10,10);
setPixel(11,10);
setPixel(14,10);
setPixel(17,10);
setPixel(19,10);
setPixel(21,10);
setPixel(22,10);
setPixel(24,10);
setPixel(26,10);
setPixel(10,11);
setPixel(15,11);
setPixel(16,11);
setPixel(19,11);
setPixel(22,11);
setPixel(24,11);
setPixel(25,11);
setPixel(26,11);
}