Mats Lidell | 36e935f | 2002-10-11 11:10:52 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2002 by Alan Korr |
| 11 | * |
| 12 | * All files in this archive are subject to the GNU General Public License. |
| 13 | * See the file COPYING in the source tree root for full license agreement. |
| 14 | * |
| 15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 16 | * KIND, either express or implied. |
| 17 | * |
| 18 | ****************************************************************************/ |
| 19 | #include "config.h" |
Mats Lidell | 786d2c3 | 2002-10-18 09:20:48 +0000 | [diff] [blame] | 20 | #include "hwcompat.h" |
Mats Lidell | 36e935f | 2002-10-11 11:10:52 +0000 | [diff] [blame] | 21 | |
Mats Lidell | 36e935f | 2002-10-11 11:10:52 +0000 | [diff] [blame] | 22 | #include "lcd.h" |
| 23 | #include "kernel.h" |
| 24 | #include "thread.h" |
| 25 | #include <string.h> |
| 26 | #include <stdlib.h> |
| 27 | #include "file.h" |
| 28 | #include "debug.h" |
| 29 | #include "system.h" |
Kjell Ericson | ccfa848 | 2002-10-21 20:20:09 +0000 | [diff] [blame] | 30 | |
| 31 | #include "font-player.h" |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 32 | #include "lcd-playersim.h" |
Mats Lidell | 36e935f | 2002-10-11 11:10:52 +0000 | [diff] [blame] | 33 | |
| 34 | /*** definitions ***/ |
| 35 | |
Mats Lidell | 786d2c3 | 2002-10-18 09:20:48 +0000 | [diff] [blame] | 36 | #define CHAR_WIDTH 6 |
| 37 | #define CHAR_HEIGHT 8 |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 38 | #define ICON_HEIGHT 24 |
| 39 | #define CHAR_PIXEL 4 |
Kjell Ericson | 54d5e2c | 2002-11-01 13:38:21 +0000 | [diff] [blame] | 40 | #define BORDER_MARGIN 5 |
Mats Lidell | 36e935f | 2002-10-11 11:10:52 +0000 | [diff] [blame] | 41 | |
Mats Lidell | 786d2c3 | 2002-10-18 09:20:48 +0000 | [diff] [blame] | 42 | static int double_height=1; |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 43 | extern bool lcd_display_redraw; |
Kjell Ericson | ea3d4d5 | 2003-01-10 10:02:27 +0000 | [diff] [blame] | 44 | extern const unsigned short *lcd_ascii; |
| 45 | extern unsigned char hardware_buffer_lcd[11][2]; |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 46 | |
Mats Lidell | 36e935f | 2002-10-11 11:10:52 +0000 | [diff] [blame] | 47 | |
Kjell Ericson | ccfa848 | 2002-10-21 20:20:09 +0000 | [diff] [blame] | 48 | void lcd_print_icon(int x, int icon_line, bool enable, char **icon) |
| 49 | { |
| 50 | int xpos = x; |
Mats Lidell | 097bd10 | 2002-10-31 17:33:41 +0000 | [diff] [blame] | 51 | int ypos = icon_line*(ICON_HEIGHT+CHAR_HEIGHT*2*4); |
Kjell Ericson | ccfa848 | 2002-10-21 20:20:09 +0000 | [diff] [blame] | 52 | int row=0, col; |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 53 | |
| 54 | int p=0, cp=0; |
| 55 | struct coordinate points[LCD_WIDTH * LCD_HEIGHT]; |
| 56 | struct coordinate clearpoints[LCD_WIDTH * LCD_HEIGHT]; |
Kjell Ericson | ccfa848 | 2002-10-21 20:20:09 +0000 | [diff] [blame] | 57 | |
| 58 | while (icon[row]) { |
| 59 | col=0; |
| 60 | while (icon[row][col]) { |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 61 | switch(icon[row][col]) { |
| 62 | case '*': |
| 63 | if (enable) { |
| 64 | /* set a dot */ |
| 65 | points[p].x = xpos + col +BORDER_MARGIN; |
| 66 | points[p].y = ypos+row +BORDER_MARGIN; |
| 67 | p++; /* increase the point counter */ |
| 68 | } else { |
| 69 | /* clear a dot */ |
| 70 | clearpoints[cp].x = xpos + col +BORDER_MARGIN; |
| 71 | clearpoints[cp].y = ypos+row +BORDER_MARGIN; |
| 72 | cp++; /* increase the point counter */ |
| 73 | } |
| 74 | break; |
| 75 | case ' ': /* Clear bit */ |
| 76 | /* clear a dot */ |
| 77 | clearpoints[cp].x = xpos + col+BORDER_MARGIN; |
| 78 | clearpoints[cp].y = ypos+row+BORDER_MARGIN; |
| 79 | cp++; /* increase the point counter */ |
| 80 | break; |
Kjell Ericson | ccfa848 | 2002-10-21 20:20:09 +0000 | [diff] [blame] | 81 | } |
| 82 | col++; |
| 83 | } |
| 84 | row++; |
| 85 | } |
Kjell Ericson | ffefc5d | 2003-06-05 08:29:21 +0000 | [diff] [blame] | 86 | /* DEBUGF("icon draw %d/%d\n", p, cp);*/ |
| 87 | if (cp) |
| 88 | drawdots(0, &clearpoints[0], cp); |
| 89 | if (p) |
| 90 | drawdots(1, &points[0], p); |
Kjell Ericson | ccfa848 | 2002-10-21 20:20:09 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 93 | void lcd_print_char(int x, int y) |
Kjell Ericson | ccfa848 | 2002-10-21 20:20:09 +0000 | [diff] [blame] | 94 | { |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 95 | int xpos = x * CHAR_WIDTH * CHAR_PIXEL; |
| 96 | int ypos = y * CHAR_HEIGHT * CHAR_PIXEL + ICON_HEIGHT; |
Kjell Ericson | ccfa848 | 2002-10-21 20:20:09 +0000 | [diff] [blame] | 97 | int col, row; |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 98 | int p=0, cp=0; |
| 99 | struct rectangle points[CHAR_HEIGHT*CHAR_WIDTH]; |
| 100 | struct rectangle clearpoints[CHAR_HEIGHT*CHAR_WIDTH]; |
Kjell Ericson | ea3d4d5 | 2003-01-10 10:02:27 +0000 | [diff] [blame] | 101 | unsigned char ch=hardware_buffer_lcd[x][y]; |
Kjell Ericson | ffefc5d | 2003-06-05 08:29:21 +0000 | [diff] [blame] | 102 | static char bitmap_content[11*8][2*8]; |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 103 | |
Kjell Ericson | ccfa848 | 2002-10-21 20:20:09 +0000 | [diff] [blame] | 104 | if (double_height == 2 && y == 1) |
| 105 | return; /* Second row can't be printed in double height. ??*/ |
| 106 | |
Kjell Ericson | ccfa848 | 2002-10-21 20:20:09 +0000 | [diff] [blame] | 107 | for (col=0; col<5; col++) { |
Kjell Ericson | ffefc5d | 2003-06-05 08:29:21 +0000 | [diff] [blame] | 108 | unsigned char fontbitmap=(*font_player)[ch][col]; |
Kjell Ericson | ccfa848 | 2002-10-21 20:20:09 +0000 | [diff] [blame] | 109 | for (row=0; row<7; row++) { |
Kjell Ericson | ffefc5d | 2003-06-05 08:29:21 +0000 | [diff] [blame] | 110 | char fontbit=fontbitmap&(1<<row); |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 111 | int height=CHAR_PIXEL*double_height; |
Kjell Ericson | ffefc5d | 2003-06-05 08:29:21 +0000 | [diff] [blame] | 112 | int ypixel; |
| 113 | if (bitmap_content[x*8+col][y*8+row*double_height]!=fontbit || |
| 114 | bitmap_content[x*8+col][y*8+row*double_height+double_height-1]!= |
| 115 | fontbit) { |
| 116 | bitmap_content[x*8+col][y*8+row*double_height]=fontbit; |
| 117 | bitmap_content[x*8+col][y*8+row*double_height+double_height-1]=fontbit; |
Kjell Ericson | ccfa848 | 2002-10-21 20:20:09 +0000 | [diff] [blame] | 118 | |
Kjell Ericson | ffefc5d | 2003-06-05 08:29:21 +0000 | [diff] [blame] | 119 | ypixel=CHAR_PIXEL*(double_height*row)+ypos; |
| 120 | if (double_height==2) { |
| 121 | if (row == 3) /* Adjust for blank row in the middle */ |
| 122 | height=CHAR_PIXEL; |
| 123 | } |
Kjell Ericson | ccfa848 | 2002-10-21 20:20:09 +0000 | [diff] [blame] | 124 | |
Kjell Ericson | ffefc5d | 2003-06-05 08:29:21 +0000 | [diff] [blame] | 125 | if (fontbit) { |
| 126 | /* set a dot */ |
| 127 | points[p].x = xpos + col*CHAR_PIXEL +BORDER_MARGIN; |
| 128 | points[p].y = ypixel +BORDER_MARGIN; |
| 129 | points[p].width=CHAR_PIXEL; |
| 130 | points[p].height=height; |
| 131 | p++; /* increase the point counter */ |
| 132 | } else { |
| 133 | clearpoints[cp].x = xpos + col*CHAR_PIXEL +BORDER_MARGIN; |
| 134 | clearpoints[cp].y = ypixel +BORDER_MARGIN; |
| 135 | clearpoints[cp].width=CHAR_PIXEL; |
| 136 | clearpoints[cp].height=height; |
| 137 | cp++; |
| 138 | } |
Kjell Ericson | ccfa848 | 2002-10-21 20:20:09 +0000 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | } |
Kjell Ericson | ffefc5d | 2003-06-05 08:29:21 +0000 | [diff] [blame] | 142 | /* DEBUGF("print_char %d/%d\n", p, cp);*/ |
| 143 | if (cp) |
| 144 | drawrectangles(0, &clearpoints[0], cp); |
| 145 | if (p) |
| 146 | drawrectangles(1, &points[0], p); |
Kjell Ericson | ccfa848 | 2002-10-21 20:20:09 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Mats Lidell | 36e935f | 2002-10-11 11:10:52 +0000 | [diff] [blame] | 149 | |
| 150 | /* |
Mats Lidell | 36e935f | 2002-10-11 11:10:52 +0000 | [diff] [blame] | 151 | * Draw a rectangle with upper left corner at (x, y) |
| 152 | * and size (nx, ny) |
| 153 | */ |
| 154 | void lcd_drawrect (int x, int y, int nx, int ny) |
| 155 | { |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 156 | (void)x; |
| 157 | (void)y; |
| 158 | (void)nx; |
| 159 | (void)ny; |
Mats Lidell | 36e935f | 2002-10-11 11:10:52 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Mats Lidell | 36e935f | 2002-10-11 11:10:52 +0000 | [diff] [blame] | 162 | /* Invert a rectangular area at (x, y), size (nx, ny) */ |
| 163 | void lcd_invertrect (int x, int y, int nx, int ny) |
| 164 | { |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 165 | (void)x; |
| 166 | (void)y; |
| 167 | (void)nx; |
| 168 | (void)ny; |
Mats Lidell | 36e935f | 2002-10-11 11:10:52 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | void lcd_drawline( int x1, int y1, int x2, int y2 ) |
| 172 | { |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 173 | (void)x1; |
| 174 | (void)x2; |
| 175 | (void)y1; |
| 176 | (void)y2; |
Mats Lidell | 36e935f | 2002-10-11 11:10:52 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | void lcd_clearline( int x1, int y1, int x2, int y2 ) |
| 180 | { |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 181 | (void)x1; |
| 182 | (void)x2; |
| 183 | (void)y1; |
| 184 | (void)y2; |
Mats Lidell | 36e935f | 2002-10-11 11:10:52 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /* |
| 188 | * Set a single pixel |
| 189 | */ |
| 190 | void lcd_drawpixel(int x, int y) |
| 191 | { |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 192 | (void)x; |
| 193 | (void)y; |
Mats Lidell | 36e935f | 2002-10-11 11:10:52 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /* |
| 197 | * Clear a single pixel |
| 198 | */ |
| 199 | void lcd_clearpixel(int x, int y) |
| 200 | { |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 201 | (void)x; |
| 202 | (void)y; |
Mats Lidell | 36e935f | 2002-10-11 11:10:52 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /* |
| 206 | * Invert a single pixel |
| 207 | */ |
| 208 | void lcd_invertpixel(int x, int y) |
| 209 | { |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 210 | (void)x; |
| 211 | (void)y; |
Mats Lidell | 36e935f | 2002-10-11 11:10:52 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Mats Lidell | 36e935f | 2002-10-11 11:10:52 +0000 | [diff] [blame] | 214 | |
Mats Lidell | 786d2c3 | 2002-10-18 09:20:48 +0000 | [diff] [blame] | 215 | |
| 216 | void lcd_double_height(bool on) |
| 217 | { |
| 218 | double_height = 1; |
| 219 | if (on) |
| 220 | double_height = 2; |
Kjell Ericson | dae8dea | 2002-10-29 10:43:30 +0000 | [diff] [blame] | 221 | lcd_display_redraw=true; |
| 222 | lcd_update(); |
Mats Lidell | 786d2c3 | 2002-10-18 09:20:48 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Kjell Ericson | ea3d4d5 | 2003-01-10 10:02:27 +0000 | [diff] [blame] | 225 | void lcd_define_hw_pattern(int which, char *pattern, int length) |
Mats Lidell | 786d2c3 | 2002-10-18 09:20:48 +0000 | [diff] [blame] | 226 | { |
| 227 | int i, j; |
| 228 | int pat = which / 8; |
Kjell Ericson | ea3d4d5 | 2003-01-10 10:02:27 +0000 | [diff] [blame] | 229 | unsigned char icon[8]; |
Mats Lidell | 786d2c3 | 2002-10-18 09:20:48 +0000 | [diff] [blame] | 230 | memset(icon, 0, sizeof icon); |
Kjell Ericson | ccfa848 | 2002-10-21 20:20:09 +0000 | [diff] [blame] | 231 | |
Kjell Ericson | dae8dea | 2002-10-29 10:43:30 +0000 | [diff] [blame] | 232 | DEBUGF("Defining pattern %d:", pat); |
Mats Lidell | 786d2c3 | 2002-10-18 09:20:48 +0000 | [diff] [blame] | 233 | for (j = 0; j <= 5; j++) { |
| 234 | for (i = 0; i < length; i++) { |
| 235 | if ((pattern[i])&(1<<(j))) |
| 236 | icon[5-j] |= (1<<(i)); |
| 237 | } |
| 238 | } |
Kjell Ericson | ccfa848 | 2002-10-21 20:20:09 +0000 | [diff] [blame] | 239 | for (i = 1; i <= 5; i++) |
Mats Lidell | 786d2c3 | 2002-10-18 09:20:48 +0000 | [diff] [blame] | 240 | { |
Kjell Ericson | dae8dea | 2002-10-29 10:43:30 +0000 | [diff] [blame] | 241 | DEBUGF(" 0x%02x", icon[i]); |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 242 | (*font_player)[pat][i-1] = icon[i]; |
Mats Lidell | 786d2c3 | 2002-10-18 09:20:48 +0000 | [diff] [blame] | 243 | } |
Kjell Ericson | dae8dea | 2002-10-29 10:43:30 +0000 | [diff] [blame] | 244 | DEBUGF("\n"); |
Kjell Ericson | 3262207 | 2002-10-28 20:00:19 +0000 | [diff] [blame] | 245 | lcd_display_redraw=true; |
| 246 | lcd_update(); |
Mats Lidell | 786d2c3 | 2002-10-18 09:20:48 +0000 | [diff] [blame] | 247 | } |
| 248 | |