/******** display.c specific functions for displaying character data Copyright 2007 Christian Montoya & James Luk This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ********/ void gen_color(void); void draw_sprite_8x8(unsigned char car[8][8], unsigned char x, unsigned char y); void erase_8x8(unsigned char x, unsigned char y); void draw_font_12x12(unsigned char letter, unsigned char x, unsigned char y); void fill_screen(unsigned char color); void draw_bg(void); void LCD_say(unsigned char *str, unsigned char x, unsigned char y); void LCD_unsay_r(unsigned char *str, unsigned char x, unsigned char y); unsigned char triangle[8][8] = { trans,trans,white,trans,trans,trans,trans,trans, trans,trans,white,white,trans,trans,trans,trans, trans,trans,white,white,white,trans,trans,trans, trans,trans,white,white,white,white,trans,trans, trans,trans,white,white,white,white,trans,trans, trans,trans,white,white,white,trans,trans,trans, trans,trans,white,white,trans,trans,trans,trans, trans,trans,white,trans,trans,trans,trans,trans}; void gen_color(void) { r_color = rand()%254; if(r_color==251 || r_color==247 || r_color==223 || r_color==191 || r_color==0b11011011 || r_color==0b11011110 || r_color==0b11011010) r_color--; } /******** draw a sprite using 8x8 matrix of colors does not draw the color "trans" (1) used by menu and dodgeball ********/ void draw_sprite_8x8(unsigned char sprite[8][8], unsigned char x, unsigned char y) { unsigned char i, j; for(i=0; i<8; i++) { for(j=0; j<8; j++) { if(sprite[i][j]!=trans) { LCD_put_pixel(sprite[i][j], y+i, x+j); } } } } /******** undraw sprite r(andom) draws r_color wherever a sprite has colors used by menu ********/ void undraw_sprite_r_8x8(unsigned char sprite[8][8], unsigned char x, unsigned char y) { unsigned char i, j; for(i=0; i<8; i++) { for(j=0; j<8; j++) { if(sprite[i][j]!=trans) { LCD_put_pixel(r_color, y+i, x+j); } } } } /******** erase 8x8 draws dodge_bg in an 8x8 area used to erase 8x8 sprites by dodgeball ********/ void erase_8x8(unsigned char x, unsigned char y) { unsigned char i, j, i0, j0, x0, y0, ex, ey; x0 = x>>1; // divide by 2 to get location in 65x65 bg y0 = y>>1; ex = x%2; // get one-offset for odd locations ey = y%2; for(i=0; i<8; i=i+2) { for(j=0; j<8; j=j+2) { i0 = i>>1; j0 = j>>1; if(currBG==1) { LCD_put_pixel(dodge_bg[y0+j0][x0+i0], y+j, x+i); sendData(dodge_bg[y0+j0][x0+i0+ex]); LCD_put_pixel(dodge_bg[y0+j0+ey][x0+i0], y+j+1, x+i); sendData(dodge_bg[y0+j0+ey][x0+i0+ex]); } } } } /******** erase 12x12 r(andom) draws random color in 12x12 area used by LCD_unsay for menu ********/ void erase_12x12_r(unsigned char x, unsigned char y) { unsigned char i, j; for(i=0; i<12; i=i+1) { LCD_put_pixel(r_color, y+i, x); for(j=1; j<12; j=j+1) { sendData(r_color); } } } /******** erase 15x16 draws dodge_bg in an 15x16 area used to erase 15x16 sprites by dodgeball ********/ void erase_15x16(unsigned char x, unsigned char y) { unsigned char i, j, i0, j0, x0, y0, ex, ey; x0 = x>>1; // divide by 2 to get location in 65x65 bg y0 = y>>1; ex = x%2; // get one-offset for odd locations ey = y%2; for(i=0; i<15; i=i+2) { for(j=0; j<16; j=j+2) { i0 = i>>1; j0 = j>>1; if(currBG==1) { LCD_put_pixel(dodge_bg[y0+j0][x0+i0], y+j, x+i); sendData(dodge_bg[y0+j0][x0+i0+ex]); LCD_put_pixel(dodge_bg[y0+j0+ey][x0+i0], y+j+1, x+i); sendData(dodge_bg[y0+j0+ey][x0+i0+ex]); } } } } /******** draw_font_12x12 uses 6x6 font and doubles it ********/ void draw_font_12x12(unsigned char letter, unsigned char x, unsigned char y) { unsigned int i, j, row, i2, j2; row = letter * 6; for(i=0; i<6; i++) { for(j=0; j<6; j++) { i2 = i<<1; j2 = j<<1; if(font6x6[i+row][j]!=trans) { LCD_put_pixel(font6x6[i+row][j], y+i2, x+j2); sendData(font6x6[i+row][j]); LCD_put_pixel(font6x6[i+row][j], y+i2+1, x+j2); sendData(font6x6[i+row][j]); } } } } /******** fill screen start at 0,0 and fill one color straight through simple and very fast ********/ void fill_screen(unsigned char color) { unsigned int i; LCD_put_pixel(color,0,0); for (i = 0; i < 17160; i++) { sendData(color); } } /******** Draw BG used by dodgeball and tunnel ********/ void draw_bg(void) { unsigned int i, j, i0, j0; //put background for(i = 0; i < 130; i=i+2) { for (j = 0; j < 130; j=j+2) { i0 = i>>1; j0 = j>>1; if(currBG==1) { LCD_put_pixel(dodge_bg[j0][i0],j,i); sendData(dodge_bg[j0][i0]); LCD_put_pixel(dodge_bg[j0][i0],j+1,i); sendData(dodge_bg[j0][i0]); } else if(currBG==2) { LCD_put_pixel(tunnel_bg[j0][i0],j,i); sendData(tunnel_bg[j0][i0]); LCD_put_pixel(tunnel_bg[j0][i0],j+1,i); sendData(tunnel_bg[j0][i0]); } } } } /******** LCD_say writes a string to the lcd at x, y adapted from video code by Prof. Bruce Land ********/ void LCD_say(unsigned char *str, unsigned char x, unsigned char y) { unsigned char i; for (i=0; str[i]!=0; i++) { if (str[i]>=0x30 && str[i]<=0x3a) // this is a number draw_font_12x12(str[i]-0x30,x,y); else if(str[i]==' ') // this is a space draw_font_12x12(str[i]-0x20+10,x,y); else draw_font_12x12(str[i]-0x40+10,x,y); // this is a letter x = x+12; } } /******** LCD_unsay remove a string from the lcd at x, y using current random color ********/ void LCD_unsay_r(unsigned char *str, unsigned char x, unsigned char y) { unsigned char i; for(i=0; str[i]!=0; i++) { erase_12x12_r(x,y); x = x+12; } }