#pragma warn- // LCD drivers // PORT A is the control port // PORT B is the data port #include // Standard defines #include #include #define begin { #define end } #define Win 0 #define Lose 1 #define Draw 0 #define Undraw 1 #define Song0 0x00 // Song definitions #define Song1 0x10 #define Song2 0x20 #define Song3 0x30 #define Song4 0x40 #define Song5 0x50 #define Song6 0x60 #define Song7 0x70 #define Off 0x80 // LCD control definitions #define LcdReset 0x00 // LCD reset #define DataWrite 0x03 // Data write #define DataSetup 0x07 // Data setup #define CommandWrite 0x43 // Command write #define DataRead 0x45 // Data receive #define LcdNop 0x47 // Do nothing #define CommandSetup 0x47 // Command setup // LCD command definitions #define SystemSet 0x40 // Initialize LCD #define MemoryWrite 0x42 // Write to display memory #define MemoryRead 0x43 // Read display memory #define Scroll 0x44 // Set start address, regions #define SetCursor 0x46 // Set cursor address #define ReadCursor 0x47 // Read cursor address #define CursorRight 0x4C // Cursor right #define CursorLeft 0x4D // Cursor left #define CursorUp 0x4E // Cursor up #define CursorDown 0x4F // Cursor down #define Standby 0x53 // Go to standby #define DisplayOff 0x58 // Disable display #define DisplayOn 0x59 // Enable display #define HorizontalScroll 0x5A // Set horizontal scroll position #define Overlay 0x5B // Set display overlay #define CharAddress 0x5C // Start address of character RAM #define CursorForm 0x5D // Set cursor type // Strings flash unsigned char names[17]={'B','y',' ','D','a','v','i','d',' ','&',' ','C','h','i','r','a','g'}; flash unsigned char player[7]={' ','P','l','a','y','e','r'}; flash unsigned char start[11]={'P','r','e','s','s',' ','S','t','a','r','t'}; flash unsigned char sco[5]={'S','c','o','r','e'}; flash unsigned char lev[5]={'L','e','v','e','l'}; flash unsigned char next[10]={'N','e','x','t',' ','B','l','o','c','k'}; flash unsigned char wait[10]={'W','a','i','t','i','n','g','.','.','.'}; flash unsigned char rbg[17]={'R','u','s','s','i','a','n',' ','B','l','o','c',' ','G','a','m','e'}; flash unsigned char youwin[10]={'Y','O','U',' ','W','I','N','!','!','!'}; flash unsigned char youlose[10]={'Y','O','U',' ','L','O','S','E','.','.'}; flash unsigned char paused[6]={'P','a','u','s','e','d'}; flash unsigned char linescleared[13]={'L','i','n','e','s',' ','C','l','e','a','r','e','d'}; flash unsigned char statstring[5]={'S','t','a','t','s'}; flash unsigned char stat_type[4][8]={{'S','i','n','g','l','e','s',' '},{'D','o','u','b','l','e','s',' '}, {'T','r','i','p','l','e','s',' '},{'C','o','m','m','i','e','s',' '}}; flash unsigned char dropped[14]={'B','l','o','c','k','s',' ','D','r','o','p','p','e','d'}; flash unsigned char ratio[17]={'S','c','o','r','e','-','L','i','n','e','s',' ','R','a','t','i','o'}; flash unsigned char comments[4][7]={{'C','r','a','p','p','y',' '}, {'A','v','e','r','a','g','e'}, {'G','o','o','d',' ',' ',' '}, {'A','m','a','z','i','n','g'}}; flash unsigned char youare[13]={'Y','o','u','r',' ','R','a','t','i','o',' ',':',' '}; flash unsigned char sucks[16]={'y','o','u','r',' ','s','c','o','r','e',' ','S','U','C','K','S'}; flash unsigned char and[4]={'A','n','d',' '}; flash unsigned char but[4]={'B','u','t',' '}; flash unsigned char nice[12]={'N','i','c','e',' ','S','c','o','r','e','!','!'}; flash unsigned char high[13]={'H','i','g','h',' ','S','c','o','r','e',' ','=',' '}; flash unsigned char new_score[16]={'N','e','w',' ','H','i','g','h',' ','S','c','o','r','e','!','!'}; flash unsigned char gameover[10]={'G','a','m','e',' ','O','v','e','r','!'}; flash unsigned char SystemCommand[8]={0x30,0x87,0x07,0x27,0x2F,0xC7,0x28,0x00}; flash unsigned char ScrollCommand[6]={0x00,0x00,0xC8,0xE8,0x03,0xC8}; eeprom unsigned int high_score = 0; // High score value stored in EEPROM unsigned char lcd_buffer[8]; // Buffer for strings flash unsigned char logo[72][5]={{0x00,0x00,0x08,0x00,0x00},{0x00,0x00,0x08,0x00,0x00},{0x00,0x00,0x1c,0x00,0x00}, {0x00,0x00,0x1c,0x00,0x00},{0x00,0x00,0x1c,0x00,0x00},{0x00,0x00,0x3e,0x00,0x00}, {0x00,0x00,0x3e,0x00,0x00},{0x00,0x00,0x3e,0x00,0x00},{0x00,0x00,0x3e,0x00,0x00}, {0x01,0xff,0xff,0xff,0xc0},{0x01,0xff,0xff,0xff,0xc0},{0x00,0xff,0xff,0xff,0x80}, {0x00,0x3f,0xff,0xfe,0x00},{0x00,0x1f,0xff,0xfc,0x00},{0x00,0x0f,0xff,0xf8,0x00}, /* 72X40 game logo */ {0x00,0x03,0xff,0xe0,0x00},{0x00,0x01,0xff,0xc0,0x00},{0x00,0x01,0xff,0xc0,0x00}, {0x00,0x03,0xff,0xe0,0x00},{0x00,0x03,0xff,0xe0,0x00},{0x00,0x03,0xff,0xe0,0x00}, {0x00,0x07,0xe3,0xf0,0x00},{0x00,0x07,0xc1,0xf0,0x00},{0x00,0x07,0x00,0x70,0x00}, {0x00,0x0e,0x00,0x38,0x00},{0x00,0x0c,0x00,0x18,0x00},{0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x1c,0x00,0x00},{0x00,0x00,0x0f,0x00,0x00},{0x00,0x00,0x07,0x80,0x00}, {0x00,0x00,0x03,0xc0,0x00},{0x00,0x00,0x03,0xe0,0x00},{0x00,0x00,0x01,0xf0,0x00}, {0x00,0x00,0x00,0xf8,0x00},{0x00,0x00,0x00,0x3e,0x00},{0x00,0x00,0x00,0x3f,0x00}, {0x00,0x01,0x80,0x1f,0x80},{0x00,0x03,0xfc,0x0f,0xc0},{0x00,0x07,0xfe,0x0f,0xc0}, {0x00,0x0f,0xfe,0x07,0xe0},{0x00,0x1f,0xfe,0x07,0xf0},{0x00,0x3f,0xfc,0x03,0xf0}, {0x00,0x7f,0xfc,0x03,0xf8},{0x00,0xff,0xf0,0x01,0xf8},{0x01,0xff,0xf0,0x01,0xfc}, {0x01,0xff,0xe0,0x01,0xfc},{0x03,0xff,0xf0,0x01,0xfe},{0x03,0xff,0xf0,0x01,0xfe}, {0x03,0xff,0xf8,0x01,0xfe},{0x00,0x7c,0x7f,0x01,0xfe},{0x00,0x30,0x3f,0x81,0xfe}, {0x00,0x00,0x1f,0xc1,0xfe},{0x00,0x00,0x1f,0xc1,0xfe},{0x00,0x00,0x0f,0xf3,0xfe}, {0x00,0x00,0x07,0xff,0xfe},{0x00,0x00,0x03,0xff,0xfe},{0x00,0x00,0x03,0xff,0xfe}, {0x00,0x00,0x01,0xff,0xfc},{0x01,0x0e,0x00,0xff,0xfc},{0x03,0xff,0xff,0xff,0xf8}, {0x03,0xff,0xff,0xff,0xf0},{0x03,0xff,0xff,0xff,0xe0},{0x03,0xff,0xff,0xff,0xe0}, {0x01,0xff,0xff,0xff,0xf0},{0x1f,0xfc,0xff,0xff,0xff},{0x3f,0xbc,0x1f,0xfc,0xff}, {0x7f,0x00,0x03,0xc0,0x7f},{0xfe,0x00,0x00,0x00,0x7f},{0xfe,0x00,0x00,0x00,0x3f}, {0xf8,0x00,0x00,0x00,0x3e},{0x78,0x00,0x00,0x00,0x1c},{0x70,0x00,0x00,0x00,0x00}}; flash unsigned char theme[17]={'R','u','s','s','i','a','n',' ','B','l','o','c',' ','S','o','n','g'}; flash unsigned char bub[9]={'B','u','b',' ','&',' ','B','o','b'}; flash unsigned char commies[15]={'T','h','e',' ','C','o','m','m','i','e',' ','S','o','n','g'}; flash unsigned char link[10]={'L','i','n','k','s',' ','S','o','n','g'}; flash unsigned char underwater[10]={'U','n','d','e','r','w','a','t','e','r'}; flash unsigned char none[9]={'M','u','s','i','c',' ','O','f','f'}; flash unsigned char march[19]={'C','o','r','n','e','l','l',' ','D','e','a','t','h',' ','M','a','r','c','h'}; flash unsigned char jedi[13]={'T','h','e',' ','J','e','d','i',' ','S','o','n','g'}; flash unsigned char indy[4]={'I','n','d','y'}; flash unsigned char clearstring[8]={'C','l','e','a','r','e','d',' '}; flash unsigned char lines[6]={' ','L','i','n','e','s'}; flash unsigned char penaltystring[10]={'P','e','n','a','l','t','y',' ','-',' '}; // Declare LCD functions void WriteCommand(unsigned char Command); // Write command to LCD void WriteData(unsigned char Data); // Write data to LCD void MoveCursor(unsigned int Address); // Move the cursor void InitLCD(void); // Initialize the LCD void ClearLCD(void); // Clear the LCD void DrawIntro(void); // Draw the game introduction void PrintPlayer(void); // Print " Player" on LCD // Highlight a character line (address = 1000 + 320 * Line + Offset) void Highlight(unsigned int InitCursor,unsigned char Write,unsigned char Length); void GameSetup(void); // Set up the game screen void Clear15(void); // Clear 15 characters void PrintPause(unsigned char Action); void PrintSound(unsigned char song); // Print song name on the bottom of the screen void PrintCleared(unsigned char clear); // Print number of lines cleared void PrintPenalty(unsigned char penalize); void PrintBuffer(void); // Print contents in LCD buffer string // LCD functions void WriteCommand(unsigned char Command) // Write command sequence to LCD begin PORTB = Command; PORTA = CommandSetup; PORTA = CommandWrite; PORTA = CommandSetup; end void WriteData(unsigned char Data) // Write data sequence to LCD begin PORTB = Data; PORTA = DataSetup; PORTA = DataWrite; PORTA = DataSetup; end void MoveCursor(unsigned int Address) // Move the cursor begin WriteCommand(SetCursor); WriteData(Address); WriteData(Address>>8); end void InitLCD(void) // Initialization routine (see datasheet, Section 9) begin unsigned char i; DDRA = 0xff; // Set control port to output DDRB = 0xff; // Set data port to output PORTA = LcdNop; delay_ms(5); // Delay 2 ms PORTA = LcdReset; // Assert reset delay_ms(3); PORTA = LcdNop; delay_ms(2); WriteCommand(SystemSet); for(i=0;i<8;i++) begin WriteData(SystemCommand[i]); // System set commands end WriteCommand(Scroll); // Scrolling, addressing for(i=0;i<6;i++) begin WriteData(ScrollCommand[i]); // Scrolling commands end WriteCommand(HorizontalScroll); WriteData(0x00); // No scrolling WriteCommand(Overlay); // Overlay WriteData(0x01); // Set to 2-layer text/graphics, XOR composition WriteCommand(DisplayOff); WriteData(0x14); // No cursor ClearLCD(); // Clear the LCD (blank character and graphic spaces) MoveCursor(0x0000); WriteCommand(CursorForm); // Choose cursor form WriteData(0x04); // Cursor horizontal WriteData(0x86); // Cursor vertical, block vertical WriteCommand(DisplayOn); // Turn on the display end void ClearLCD(void) // LCD clearing function begin unsigned int i; WriteCommand(CursorRight); MoveCursor(0x0000); WriteCommand(MemoryWrite); for(i=0;i<1000;i++) begin WriteData(0x20); // Clear the character space end MoveCursor(0x03E8); WriteCommand(MemoryWrite); for(i=0;i<8000;i++) begin WriteData(0x00); // Clear graphics space end end void DrawIntro(void) begin unsigned char i,j; unsigned int address; WriteCommand(CursorRight); // Cursor direction right address = 0x052E; MoveCursor(address); // 2nd line 2nd character graphics space for(i=0;i<72;i++) begin WriteCommand(MemoryWrite); for(j=0;j<5;j++) begin WriteData(logo[i][j]); // Draw logo end address += 40; MoveCursor(address); end MoveCursor(0x008B); WriteCommand(MemoryWrite); for(i=0;i<17;i++) begin WriteData(rbg[i]); // Game name end MoveCursor(0x00DB); WriteCommand(MemoryWrite); for(i=0;i<17;i++) begin WriteData(names[i]); // Print "By David & Chirag" end MoveCursor(0x0266); WriteCommand(MemoryWrite); for(i=0;i<11;i++) begin WriteData(start[i]); // Print Start string end MoveCursor(0x032F); WriteCommand(MemoryWrite); WriteData('1'); PrintPlayer(); MoveCursor(0x037F); WriteCommand(MemoryWrite); WriteData('2'); PrintPlayer(); // Print player on screen Highlight(0x1CF7,0xFF,8); // Highlight the "1 Player" on the LCD itoa(high_score,lcd_buffer); MoveCursor(0x03CC); WriteCommand(MemoryWrite); for(i=0;i<13;i++) begin WriteData(high[i]); end PrintBuffer(); end void PrintPlayer(void) begin unsigned char i; for(i=0;i<7;i++) begin WriteData(player[i]); end end void Highlight(unsigned int InitCursor,unsigned char Write,unsigned char Length) begin unsigned char i,k; unsigned int cursor; cursor = InitCursor; WriteCommand(CursorRight); for(i=0;i<8;i++) // 8 graphics lines per character line begin MoveCursor(cursor); WriteCommand(MemoryWrite); for(k=0;k