summaryrefslogtreecommitdiff
path: root/firmware/drivers/lcd-player.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/lcd-player.c')
-rw-r--r--firmware/drivers/lcd-player.c212
1 files changed, 114 insertions, 98 deletions
diff --git a/firmware/drivers/lcd-player.c b/firmware/drivers/lcd-player.c
index bac18d28c8..738816c4dc 100644
--- a/firmware/drivers/lcd-player.c
+++ b/firmware/drivers/lcd-player.c
@@ -74,13 +74,13 @@ struct scrollinfo {
74 74
75#define MAX_CURSOR_CHARS 8 75#define MAX_CURSOR_CHARS 8
76struct cursorinfo { 76struct cursorinfo {
77 int len; 77 int len;
78 char text[MAX_CURSOR_CHARS]; 78 char text[MAX_CURSOR_CHARS];
79 int textpos; 79 int textpos;
80 int y_pos; 80 int y_pos;
81 int x_pos; 81 int x_pos;
82 int divider; 82 int divider;
83 int downcount; 83 int downcount;
84} cursor; 84} cursor;
85 85
86static void scroll_thread(void); 86static void scroll_thread(void);
@@ -124,25 +124,25 @@ static void lcd_free_pat(int map_ch)
124 pat=extended_chars_mapped[map_ch]; 124 pat=extended_chars_mapped[map_ch];
125 if (pat!=NO_CHAR) { 125 if (pat!=NO_CHAR) {
126 126
127 substitute_char=lcd_player_extended_lcd_to_rocklatin1[map_ch]; 127 substitute_char=lcd_player_extended_lcd_to_rocklatin1[map_ch];
128 128
129 for (x=0; x<11; x++) { 129 for (x=0; x<11; x++) {
130 for (y=0; y<2; y++) { 130 for (y=0; y<2; y++) {
131 if (map_ch==lcd_ascii[buffer_xlcd[x][y]]-512) { 131 if (map_ch==lcd_ascii[buffer_xlcd[x][y]]-512) {
132 buffer_xlcd[x][y]=substitute_char; 132 buffer_xlcd[x][y]=substitute_char;
133 buffer_lcd_mirror[x][y]=substitute_char; 133 buffer_lcd_mirror[x][y]=substitute_char;
134#ifdef SIMULATOR 134#ifdef SIMULATOR
135 hardware_buffer_lcd[x][y]=substitute_char; 135 hardware_buffer_lcd[x][y]=substitute_char;
136#else 136#else
137 lcd_write(true, LCD_CURSOR(x, y)); 137 lcd_write(true, LCD_CURSOR(x, y));
138 lcd_write(false, substitute_char); 138 lcd_write(false, substitute_char);
139#endif 139#endif
140 } 140 }
141 }
141 } 142 }
142 } 143 extended_chars_mapped[map_ch]=NO_CHAR;
143 extended_chars_mapped[map_ch]=NO_CHAR; 144 extended_pattern_content[pat]=NO_CHAR;
144 extended_pattern_content[pat]=NO_CHAR; 145 extended_pattern_usage[pat]=0;
145 extended_pattern_usage[pat]=0;
146 } 146 }
147#ifdef SIMULATOR 147#ifdef SIMULATOR
148 lcd_update(); 148 lcd_update();
@@ -197,18 +197,22 @@ void xlcd_update(void)
197 int map_ch=lcd_ascii[ch]; 197 int map_ch=lcd_ascii[ch];
198 if (map_ch<512) { 198 if (map_ch<512) {
199 hw_ch=map_ch; 199 hw_ch=map_ch;
200 } else { 200 }
201 else {
201 map_ch=map_ch-512; 202 map_ch=map_ch-512;
202 if (extended_chars_mapped[map_ch]!=NO_CHAR) { 203 if (extended_chars_mapped[map_ch]!=NO_CHAR) {
203 hw_ch=extended_chars_mapped[map_ch]; 204 hw_ch=extended_chars_mapped[map_ch];
204 extended_pattern_usage[hw_ch]++; 205 extended_pattern_usage[hw_ch]++;
205 } else { 206 }
207 else {
206 int pat; 208 int pat;
207 pat=lcd_get_free_pat(map_ch); 209 pat=lcd_get_free_pat(map_ch);
208 if (pat<0) { 210 if (pat<0) {
209 DEBUGF("Substitute for %02x (map 0x%02x) is used.\n", ch, map_ch); 211 DEBUGF("Substitute for %02x (map 0x%02x)"
212 " is used.\n", ch, map_ch);
210 /* Find substitute char */ 213 /* Find substitute char */
211 map_ch=lcd_player_extended_lcd_to_rocklatin1[map_ch]; 214 map_ch=
215 lcd_player_extended_lcd_to_rocklatin1[map_ch];
212 hw_ch=lcd_ascii[map_ch]; 216 hw_ch=lcd_ascii[map_ch];
213 } else { 217 } else {
214#ifdef DEBUG 218#ifdef DEBUG
@@ -220,7 +224,8 @@ void xlcd_update(void)
220 extended_pattern_content[pat]=map_ch; 224 extended_pattern_content[pat]=map_ch;
221 extended_pattern_usage[pat]=1; 225 extended_pattern_usage[pat]=1;
222 lcd_define_hw_pattern(pat*8, 226 lcd_define_hw_pattern(pat*8,
223 extended_font_player[map_ch], 8); 227 extended_font_player[map_ch],
228 8);
224 hw_ch=pat; 229 hw_ch=pat;
225 } 230 }
226 } 231 }
@@ -239,35 +244,35 @@ void xlcd_update(void)
239 244
240bool lcdx_putc(int x, int y, unsigned short ch) 245bool lcdx_putc(int x, int y, unsigned short ch)
241{ 246{
242 int lcd_char; 247 int lcd_char;
243 if (buffer_xlcd[x][y]==ch) 248 if (buffer_xlcd[x][y]==ch)
244 return false; /* Same char, ignore any update */ 249 return false; /* Same char, ignore any update */
245 lcd_char=lcd_ascii[buffer_xlcd[x][y]]; 250 lcd_char=lcd_ascii[buffer_xlcd[x][y]];
246 if (lcd_char>=512) { 251 if (lcd_char>=512) {
247 /* The removed char is a defined pattern, count down the reference. */ 252 /* The removed char is a defined pattern, count down the reference. */
248 extended_pattern_usage[(int)extended_chars_mapped[lcd_char-512]]--; 253 extended_pattern_usage[(int)extended_chars_mapped[lcd_char-512]]--;
249#ifdef DEBUG 254#ifdef DEBUG
250 if (extended_pattern_usage[(int)extended_chars_mapped[lcd_char]]<0) { 255 if (extended_pattern_usage[(int)extended_chars_mapped[lcd_char]]<0) {
251 DEBUGF("**** Mapped char %02x is less than 0!\n", lcd_char); 256 DEBUGF("**** Mapped char %02x is less than 0!\n", lcd_char);
252 } 257 }
253#endif 258#endif
254 } 259 }
255 260
256 buffer_xlcd[x][y]=ch; 261 buffer_xlcd[x][y]=ch;
257 262
258 lcd_char=lcd_ascii[ch]; 263 lcd_char=lcd_ascii[ch];
259 if (lcd_char>=256) 264 if (lcd_char>=256)
260 return true; /* Caller shall call xlcd_update() when done */ 265 return true; /* Caller shall call xlcd_update() when done */
261 266
262 buffer_lcd_mirror[x][y]=lcd_char; 267 buffer_lcd_mirror[x][y]=lcd_char;
263#ifdef SIMULATOR 268#ifdef SIMULATOR
264 hardware_buffer_lcd[x][y]=lcd_char; 269 hardware_buffer_lcd[x][y]=lcd_char;
265 lcd_update(); 270 lcd_update();
266#else 271#else
267 lcd_write(true, LCD_CURSOR(x, y)); 272 lcd_write(true, LCD_CURSOR(x, y));
268 lcd_write(false, lcd_char); 273 lcd_write(false, lcd_char);
269#endif 274#endif
270 return false; 275 return false;
271} 276}
272 277
273void lcd_clear_display(void) 278void lcd_clear_display(void)
@@ -278,9 +283,9 @@ void lcd_clear_display(void)
278 lcd_stop_scroll(); 283 lcd_stop_scroll();
279 cursor.len=0; /* Stop cursor */ 284 cursor.len=0; /* Stop cursor */
280 for (i=0;i<22;i++) 285 for (i=0;i<22;i++)
281 update|=lcdx_putc(i%11, i/11, ' '); 286 update|=lcdx_putc(i%11, i/11, ' ');
282 if (update) 287 if (update)
283 xlcd_update(); 288 xlcd_update();
284} 289}
285 290
286static void lcd_puts_cont_scroll(int x, int y, unsigned char *string) 291static void lcd_puts_cont_scroll(int x, int y, unsigned char *string)
@@ -289,22 +294,26 @@ static void lcd_puts_cont_scroll(int x, int y, unsigned char *string)
289 DEBUGF("lcd_puts_cont_scroll(%d, %d, \"", x, y); 294 DEBUGF("lcd_puts_cont_scroll(%d, %d, \"", x, y);
290 295
291 for (; *string && x<11; x++) 296 for (; *string && x<11; x++)
292 { 297 {
293#ifdef DEBUGF 298#ifdef DEBUGF
294 if (*string>=32 && *string<128) 299 if (*string>=32 && *string<128)
295 {DEBUGF("%c", *string);} 300 {
301 DEBUGF("%c", *string);
302 }
296 else 303 else
297 {DEBUGF("(0x%02x)", *string);} 304 {
305 DEBUGF("(0x%02x)", *string);
306 }
298#endif 307#endif
299 /* We should check if char is over 256 */ 308 /* We should check if char is over 256 */
300 update|=lcdx_putc(x, y, *(unsigned char*)string++); 309 update|=lcdx_putc(x, y, *(unsigned char*)string++);
301 } 310 }
302 DEBUGF("\")\n"); 311 DEBUGF("\")\n");
303 312
304 for (; x<11; x++) 313 for (; x<11; x++)
305 update|=lcdx_putc(x, y, ' '); 314 update|=lcdx_putc(x, y, ' ');
306 if (update) 315 if (update)
307 xlcd_update(); 316 xlcd_update();
308} 317}
309void lcd_puts(int x, int y, unsigned char *string) 318void lcd_puts(int x, int y, unsigned char *string)
310{ 319{
@@ -315,25 +324,28 @@ void lcd_puts(int x, int y, unsigned char *string)
315 324
316void lcd_put_cursor(int x, int y, char cursor_char) 325void lcd_put_cursor(int x, int y, char cursor_char)
317{ 326{
318 if (cursor.len==0) { 327 if (cursor.len == 0) {
319 cursor.text[0]=buffer_xlcd[x][y]; 328 cursor.text[0]=buffer_xlcd[x][y];
320 cursor.text[1]=cursor_char; 329 cursor.text[1]=cursor_char;
321 cursor.len=2; 330 cursor.len=2;
322 cursor.textpos=0; 331 cursor.textpos=0;
323 cursor.y_pos=y; 332 cursor.y_pos=y;
324 cursor.x_pos=x; 333 cursor.x_pos=x;
325 cursor.downcount=0; 334 cursor.downcount=0;
326 cursor.divider=4; 335 cursor.divider=4;
327 } 336 }
328} 337}
329 338
330void lcd_remove_cursor(void) 339void lcd_remove_cursor(void)
331{ 340{
332 if (cursor.len!=0) { 341 if (cursor.len!=0) {
333 cursor.len=0; 342 bool up;
334 if (lcdx_putc(cursor.x_pos, cursor.y_pos, cursor.text[0])) 343 cursor.len=0;
335 lcd_update(); 344 up = lcdx_putc(cursor.x_pos, cursor.y_pos, cursor.text[0]);
336 } 345#ifdef SIMULATOR
346 lcd_update();
347#endif
348 }
337} 349}
338 350
339void lcd_putc(int x, int y, unsigned short ch) 351void lcd_putc(int x, int y, unsigned short ch)
@@ -341,42 +353,42 @@ void lcd_putc(int x, int y, unsigned short ch)
341 bool update; 353 bool update;
342 DEBUGF("lcd_putc(%d, %d, %d '0x%02x')\n", x, y, ch, ch); 354 DEBUGF("lcd_putc(%d, %d, %d '0x%02x')\n", x, y, ch, ch);
343 if (x<0 || y<0) { 355 if (x<0 || y<0) {
344 return; 356 return;
345 } 357 }
346 update=lcdx_putc(x, y, ch); 358 update=lcdx_putc(x, y, ch);
347 359
348 if (update) 360 if (update)
349 xlcd_update(); 361 xlcd_update();
350} 362}
351 363
352unsigned char lcd_get_locked_pattern(void) 364unsigned char lcd_get_locked_pattern(void)
353{ 365{
354 unsigned char pat=1; 366 unsigned char pat=1;
355 while (pat<LAST_RESERVED_CHAR) { 367 while (pat<LAST_RESERVED_CHAR) {
356 if (lcd_ascii[pat]==RESERVED_CHAR) { 368 if (lcd_ascii[pat]==RESERVED_CHAR) {
357 lcd_ascii[pat]=0x200+pat; 369 lcd_ascii[pat]=0x200+pat;
358 return pat; 370 return pat;
359 } 371 }
360 pat++; 372 pat++;
361 } 373 }
362 return 0; 374 return 0;
363} 375}
364 376
365void lcd_unlock_pattern(unsigned char pat) 377void lcd_unlock_pattern(unsigned char pat)
366{ 378{
367 lcd_ascii[pat]=RESERVED_CHAR; 379 lcd_ascii[pat]=RESERVED_CHAR;
368 lcd_free_pat(pat); 380 lcd_free_pat(pat);
369} 381}
370 382
371void lcd_define_pattern(int pat, char *pattern) 383void lcd_define_pattern(int pat, char *pattern)
372{ 384{
373 int i; 385 int i;
374 for (i=0; i<7; i++) { 386 for (i=0; i<7; i++) {
375 extended_font_player[pat][i]=pattern[i]; 387 extended_font_player[pat][i]=pattern[i];
376 } 388 }
377 if (extended_chars_mapped[pat]!=NO_CHAR) { 389 if (extended_chars_mapped[pat]!=NO_CHAR) {
378 lcd_define_hw_pattern(extended_chars_mapped[pat]*8, pattern, 7); 390 lcd_define_hw_pattern(extended_chars_mapped[pat]*8, pattern, 7);
379 } 391 }
380} 392}
381 393
382#ifndef SIMULATOR 394#ifndef SIMULATOR
@@ -471,7 +483,8 @@ void lcd_init (void)
471 lcd_pram = NEW_LCD_PRAM; 483 lcd_pram = NEW_LCD_PRAM;
472 lcd_iram = NEW_LCD_IRAM; 484 lcd_iram = NEW_LCD_IRAM;
473 pattern_size=7; /* Last pattern, 3 for old LCD, 7 for new LCD */ 485 pattern_size=7; /* Last pattern, 3 for old LCD, 7 for new LCD */
474 } else { 486 }
487 else {
475 lcd_ascii = old_lcd_rocklatin1_to_xlcd; 488 lcd_ascii = old_lcd_rocklatin1_to_xlcd;
476 lcd_contrast_set = OLD_LCD_CONTRAST_SET; 489 lcd_contrast_set = OLD_LCD_CONTRAST_SET;
477 lcd_cram = OLD_LCD_CRAM; 490 lcd_cram = OLD_LCD_CRAM;
@@ -512,15 +525,18 @@ void lcd_puts_scroll(int x, int y, unsigned char* string )
512 s->turn_offset=-1; 525 s->turn_offset=-1;
513 if (bidir_limit && (s->textlen < ((11-x)*(100+bidir_limit))/100)) { 526 if (bidir_limit && (s->textlen < ((11-x)*(100+bidir_limit))/100)) {
514 s->turn_offset=s->textlen+x-11; 527 s->turn_offset=s->textlen+x-11;
515 } else { 528 }
516 for (i=0; i<scroll_spacing && s->textlen<(int)sizeof(s->text); i++) { 529 else {
530 for (i=0; i<scroll_spacing &&
531 s->textlen<(int)sizeof(s->text); i++) {
517 s->text[s->textlen++]=' '; 532 s->text[s->textlen++]=' ';
518 } 533 }
519 } 534 }
520 if (s->textlen<(int)sizeof(s->text)) 535 if (s->textlen<(int)sizeof(s->text))
521 s->text[s->textlen]=' '; 536 s->text[s->textlen]=' ';
522 s->text[sizeof s->text - 1] = 0; 537 s->text[sizeof s->text - 1] = 0;
523 } else 538 }
539 else
524 s->mode = SCROLL_MODE_OFF; 540 s->mode = SCROLL_MODE_OFF;
525} 541}
526 542
@@ -590,7 +606,7 @@ static void scroll_thread(void)
590 } 606 }
591 } 607 }
592 else { 608 else {
593 s->offset = 0; 609 s->offset = 0;
594 } 610 }
595 611
596 i=0; 612 i=0;
@@ -609,14 +625,14 @@ static void scroll_thread(void)
609 } 625 }
610 } 626 }
611 if (cursor.len>0) { 627 if (cursor.len>0) {
612 if (cursor.downcount--<0) { 628 if (cursor.downcount--<0) {
613 cursor.downcount=cursor.divider; 629 cursor.downcount=cursor.divider;
614 cursor.textpos++; 630 cursor.textpos++;
615 if (cursor.textpos>=cursor.len) 631 if (cursor.textpos>=cursor.len)
616 cursor.textpos=0; 632 cursor.textpos=0;
617 update|=lcdx_putc(cursor.x_pos, cursor.y_pos, 633 update|=lcdx_putc(cursor.x_pos, cursor.y_pos,
618 cursor.text[cursor.textpos]); 634 cursor.text[cursor.textpos]);
619 } 635 }
620 } 636 }
621 if (update) { 637 if (update) {
622 lcd_update(); 638 lcd_update();