summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/main_menu.c2
-rw-r--r--apps/plugin.c29
-rw-r--r--apps/plugin.h56
-rw-r--r--apps/plugins/logo.c8
-rw-r--r--apps/plugins/snow.c14
-rw-r--r--firmware/drivers/lcd-h100-remote.c632
-rw-r--r--firmware/drivers/lcd-h100.c18
-rw-r--r--firmware/drivers/lcd-recorder.c16
-rw-r--r--firmware/export/lcd-remote.h33
-rw-r--r--firmware/export/lcd.h10
10 files changed, 469 insertions, 349 deletions
diff --git a/apps/main_menu.c b/apps/main_menu.c
index 9654b806e3..46a3e6f4a5 100644
--- a/apps/main_menu.c
+++ b/apps/main_menu.c
@@ -80,7 +80,7 @@ int show_logo( void )
80 80
81#ifdef HAVE_REMOTE_LCD 81#ifdef HAVE_REMOTE_LCD
82 lcd_remote_clear_display(); 82 lcd_remote_clear_display();
83 lcd_remote_bitmap(rockbox112x37,10,14,112,37, false); 83 lcd_remote_bitmap(rockbox112x37,10,14,112,37);
84#endif 84#endif
85 85
86 snprintf(version, sizeof(version), "Ver. %s", appsversion); 86 snprintf(version, sizeof(version), "Ver. %s", appsversion);
diff --git a/apps/plugin.c b/apps/plugin.c
index 2a8d2c0841..bd8ea2f9a6 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -133,32 +133,33 @@ static const struct plugin_api rockbox_api = {
133 splash, 133 splash,
134#ifdef HAVE_REMOTE_LCD 134#ifdef HAVE_REMOTE_LCD
135 /* remote lcd */ 135 /* remote lcd */
136 lcd_remote_set_contrast,
136 lcd_remote_clear_display, 137 lcd_remote_clear_display,
137 lcd_remote_puts, 138 lcd_remote_puts,
138 lcd_remote_puts_scroll, 139 lcd_remote_puts_scroll,
139 lcd_remote_stop_scroll, 140 lcd_remote_stop_scroll,
140 lcd_remote_set_contrast, 141 lcd_remote_roll,
142 lcd_remote_set_drawmode,
143 lcd_remote_get_drawmode,
144 lcd_remote_setfont,
145 lcd_remote_getstringsize,
146 lcd_remote_drawpixel,
147 lcd_remote_drawline,
148 lcd_remote_hline,
149 lcd_remote_vline,
150 lcd_remote_drawrect,
151 lcd_remote_fillrect,
152 lcd_remote_bitmap_part,
153 lcd_remote_bitmap,
141 lcd_remote_putsxy, 154 lcd_remote_putsxy,
142 lcd_remote_puts_style, 155 lcd_remote_puts_style,
143 lcd_remote_puts_scroll_style, 156 lcd_remote_puts_scroll_style,
144 lcd_remote_bitmap, 157 &lcd_remote_framebuffer[0][0],
145 lcd_remote_drawline,
146 lcd_remote_clearline,
147 lcd_remote_drawpixel,
148 lcd_remote_clearpixel,
149 lcd_remote_setfont,
150 font_get,
151 lcd_remote_clearrect,
152 lcd_remote_fillrect,
153 lcd_remote_drawrect,
154 lcd_remote_invertrect,
155 lcd_remote_getstringsize,
156 lcd_remote_update, 158 lcd_remote_update,
157 lcd_remote_update_rect, 159 lcd_remote_update_rect,
158 160
159 lcd_remote_backlight_on, 161 lcd_remote_backlight_on,
160 lcd_remote_backlight_off, 162 lcd_remote_backlight_off,
161 &lcd_remote_framebuffer[0][0],
162#endif 163#endif
163 /* button */ 164 /* button */
164 button_get, 165 button_get,
diff --git a/apps/plugin.h b/apps/plugin.h
index 78bffe08ed..b2e798d0e8 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -189,35 +189,39 @@ struct plugin_api {
189 189
190#ifdef HAVE_REMOTE_LCD 190#ifdef HAVE_REMOTE_LCD
191 /* remote lcd */ 191 /* remote lcd */
192 void (*remote_clear_display)(void); 192 void (*lcd_remote_set_contrast)(int x);
193 void (*remote_puts)(int x, int y, const unsigned char *string); 193 void (*lcd_remote_clear_display)(void);
194 void (*remote_lcd_puts_scroll)(int x, int y, const unsigned char* string); 194 void (*lcd_remote_puts)(int x, int y, const unsigned char *string);
195 void (*remote_lcd_stop_scroll)(void); 195 void (*lcd_remote_lcd_puts_scroll)(int x, int y, const unsigned char* string);
196 void (*remote_set_contrast)(int x); 196 void (*lcd_remote_lcd_stop_scroll)(void);
197 197
198 void (*remote_putsxy)(int x, int y, const unsigned char *string); 198 void (*lcd_remote_roll)(int pixels);
199 void (*remote_puts_style)(int x, int y, const unsigned char *str, int style); 199
200 void (*remote_puts_scroll_style)(int x, int y, const unsigned char* string, 200 void (*lcd_remote_set_drawmode)(int mode);
201 int style); 201 int (*lcd_remote_get_drawmode)(void);
202 void (*remote_bitmap)(const unsigned char *src, int x, int y, 202 void (*lcd_remote_setfont)(int font);
203 int nx, int ny, bool clear); 203 int (*lcd_remote_getstringsize)(const unsigned char *str, int *w, int *h);
204 void (*remote_drawline)(int x1, int y1, int x2, int y2); 204 void (*lcd_remote_drawpixel)(int x, int y);
205 void (*remote_clearline)(int x1, int y1, int x2, int y2); 205 void (*lcd_remote_drawline)(int x1, int y1, int x2, int y2);
206 void (*remote_drawpixel)(int x, int y); 206 void (*lcd_remote_hline)(int x1, int x2, int y);
207 void (*remote_clearpixel)(int x, int y); 207 void (*lcd_remote_vline)(int x, int y1, int y2);
208 void (*remote_setfont)(int font); 208 void (*lcd_remote_drawrect)(int x, int y, int nx, int ny);
209 struct font* (*remote_font_get)(int font); 209 void (*lcd_remote_fillrect)(int x, int y, int nx, int ny);
210 void (*remote_clearrect)(int x, int y, int nx, int ny); 210 void (*lcd_remote_bitmap_part)(const unsigned char *src, int src_x,
211 void (*remote_fillrect)(int x, int y, int nx, int ny); 211 int src_y, int stride, int x, int y,
212 void (*remote_drawrect)(int x, int y, int nx, int ny); 212 int width, int height);
213 void (*remote_invertrect)(int x, int y, int nx, int ny); 213 void (*lcd_remote_bitmap)(const unsigned char *src, int x, int y, int nx,
214 int (*remote_getstringsize)(const unsigned char *str, int *w, int *h); 214 int ny);
215 void (*remote_update)(void); 215 void (*lcd_remote_putsxy)(int x, int y, const unsigned char *string);
216 void (*remote_update_rect)(int x, int y, int width, int height); 216 void (*lcd_remote_puts_style)(int x, int y, const unsigned char *str, int style);
217 void (*lcd_remote_puts_scroll_style)(int x, int y, const unsigned char* string,
218 int style);
219 unsigned char* lcd_remote_framebuffer;
220 void (*lcd_remote_update)(void);
221 void (*lcd_remote_update_rect)(int x, int y, int width, int height);
217 222
218 void (*remote_backlight_on)(void); 223 void (*remote_backlight_on)(void);
219 void (*remote_backlight_off)(void); 224 void (*remote_backlight_off)(void);
220 unsigned char* lcd_remote_framebuffer;
221#endif 225#endif
222 226
223 /* button */ 227 /* button */
diff --git a/apps/plugins/logo.c b/apps/plugins/logo.c
index 7807982ebc..abe4e0bc3b 100644
--- a/apps/plugins/logo.c
+++ b/apps/plugins/logo.c
@@ -231,11 +231,11 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) {
231 rb->lcd_clear_display(); 231 rb->lcd_clear_display();
232 rb->lcd_bitmap(LOGO, x, y, LOGO_WIDTH, LOGO_HEIGHT); 232 rb->lcd_bitmap(LOGO, x, y, LOGO_WIDTH, LOGO_HEIGHT);
233#ifdef REMOTE_LOGO 233#ifdef REMOTE_LOGO
234 rb->remote_clear_display(); 234 rb->lcd_remote_clear_display();
235 rb->remote_bitmap(REMOTE_LOGO, 235 rb->lcd_remote_bitmap(REMOTE_LOGO,
236 (x * (REMOTE_WIDTH - REMOTE_LOGO_WIDTH)) / (DISPLAY_WIDTH - LOGO_WIDTH), 236 (x * (REMOTE_WIDTH - REMOTE_LOGO_WIDTH)) / (DISPLAY_WIDTH - LOGO_WIDTH),
237 (y * (REMOTE_HEIGHT - REMOTE_LOGO_HEIGHT)) / (DISPLAY_HEIGHT - LOGO_HEIGHT), 237 (y * (REMOTE_HEIGHT - REMOTE_LOGO_HEIGHT)) / (DISPLAY_HEIGHT - LOGO_HEIGHT),
238 REMOTE_LOGO_WIDTH, REMOTE_LOGO_HEIGHT, false); 238 REMOTE_LOGO_WIDTH, REMOTE_LOGO_HEIGHT);
239#endif 239#endif
240#else 240#else
241 pgfx_clear_display(); 241 pgfx_clear_display();
@@ -266,7 +266,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) {
266#ifdef HAVE_LCD_BITMAP 266#ifdef HAVE_LCD_BITMAP
267 rb->lcd_update(); 267 rb->lcd_update();
268#ifdef REMOTE_LOGO 268#ifdef REMOTE_LOGO
269 rb->remote_update(); 269 rb->lcd_remote_update();
270#endif 270#endif
271#else 271#else
272 if (cpos != old_cpos) { 272 if (cpos != old_cpos) {
diff --git a/apps/plugins/snow.c b/apps/plugins/snow.c
index 36181e6eae..b3d3b14c46 100644
--- a/apps/plugins/snow.c
+++ b/apps/plugins/snow.c
@@ -92,8 +92,10 @@ static void snow_move(void)
92#ifdef HAVE_REMOTE_LCD 92#ifdef HAVE_REMOTE_LCD
93 if (particles[i][0] <= LCD_REMOTE_WIDTH 93 if (particles[i][0] <= LCD_REMOTE_WIDTH
94 && particles[i][1] <= LCD_REMOTE_HEIGHT) { 94 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
95 rb->remote_clearrect(particles[i][0],particles[i][1], 95 rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
96 FLAKE_WIDTH,FLAKE_WIDTH); 96 rb->lcd_remote_fillrect(particles[i][0],particles[i][1],
97 FLAKE_WIDTH,FLAKE_WIDTH);
98 rb->lcd_remote_set_drawmode(DRMODE_SOLID);
97 } 99 }
98#endif 100#endif
99 switch ((rb->rand()%7)) { 101 switch ((rb->rand()%7)) {
@@ -122,8 +124,8 @@ static void snow_move(void)
122#ifdef HAVE_REMOTE_LCD 124#ifdef HAVE_REMOTE_LCD
123 if (particles[i][0] <= LCD_REMOTE_WIDTH 125 if (particles[i][0] <= LCD_REMOTE_WIDTH
124 && particles[i][1] <= LCD_REMOTE_HEIGHT) { 126 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
125 rb->remote_bitmap(flake,particles[i][0],particles[i][1], 127 rb->lcd_remote_bitmap(flake,particles[i][0],particles[i][1],
126 FLAKE_WIDTH,FLAKE_WIDTH,true); 128 FLAKE_WIDTH,FLAKE_WIDTH);
127 } 129 }
128#endif 130#endif
129 } 131 }
@@ -148,7 +150,7 @@ static void snow_init(void)
148 pgfx_clear_display(); 150 pgfx_clear_display();
149#endif 151#endif
150#ifdef HAVE_REMOTE_LCD 152#ifdef HAVE_REMOTE_LCD
151 rb->remote_clear_display(); 153 rb->lcd_remote_clear_display();
152#endif 154#endif
153} 155}
154 156
@@ -175,7 +177,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
175 pgfx_update(); 177 pgfx_update();
176#endif 178#endif
177#ifdef HAVE_REMOTE_LCD 179#ifdef HAVE_REMOTE_LCD
178 rb->remote_update(); 180 rb->lcd_remote_update();
179#endif 181#endif
180 rb->sleep(HZ/20); 182 rb->sleep(HZ/20);
181 183
diff --git a/firmware/drivers/lcd-h100-remote.c b/firmware/drivers/lcd-h100-remote.c
index 90bb12e7c3..fe1c82dd3d 100644
--- a/firmware/drivers/lcd-h100-remote.c
+++ b/firmware/drivers/lcd-h100-remote.c
@@ -72,9 +72,10 @@ unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH]
72#endif 72#endif
73 ; 73 ;
74 74
75static int curfont = FONT_SYSFIXED; 75static int drawmode = DRMODE_SOLID;
76static int xmargin = 0; 76static int xmargin = 0;
77static int ymargin = 0; 77static int ymargin = 0;
78static int curfont = FONT_SYSFIXED;
78#ifndef SIMULATOR 79#ifndef SIMULATOR
79static int xoffset; /* needed for flip */ 80static int xoffset; /* needed for flip */
80 81
@@ -90,12 +91,6 @@ static int cached_contrast = 32;
90static int cached_roll = 0; 91static int cached_roll = 0;
91#endif 92#endif
92 93
93/* All zeros and ones bitmaps for area filling */
94static const unsigned char zeros[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
95static const unsigned char ones[8] = {
96 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
97};
98
99/* scrolling */ 94/* scrolling */
100static volatile int scrolling_lines=0; /* Bitpattern of which lines are scrolling */ 95static volatile int scrolling_lines=0; /* Bitpattern of which lines are scrolling */
101#ifndef SIMULATOR 96#ifndef SIMULATOR
@@ -397,10 +392,10 @@ void lcd_remote_update(void)
397 return; 392 return;
398 393
399 /* Copy display bitmap to hardware */ 394 /* Copy display bitmap to hardware */
400 for (y = 0; y < LCD_REMOTE_HEIGHT / 8; y++) 395 for (y = 0; y < LCD_REMOTE_HEIGHT/8; y++)
401 { 396 {
402 lcd_remote_write_command(LCD_REMOTE_CNTL_SET_PAGE_ADDRESS | y); 397 lcd_remote_write_command(LCD_REMOTE_CNTL_SET_PAGE_ADDRESS | y);
403 lcd_remote_write_command(LCD_REMOTE_CNTL_HIGHCOL | ((xoffset>>4) & 0xf)); 398 lcd_remote_write_command(LCD_REMOTE_CNTL_HIGHCOL | ((xoffset >> 4) & 0xf));
404 lcd_remote_write_command(LCD_REMOTE_CNTL_LOWCOL | (xoffset & 0xf)); 399 lcd_remote_write_command(LCD_REMOTE_CNTL_LOWCOL | (xoffset & 0xf));
405 lcd_remote_write_data(lcd_remote_framebuffer[y], LCD_REMOTE_WIDTH); 400 lcd_remote_write_data(lcd_remote_framebuffer[y], LCD_REMOTE_WIDTH);
406 } 401 }
@@ -408,39 +403,49 @@ void lcd_remote_update(void)
408 403
409/* Update a fraction of the display. */ 404/* Update a fraction of the display. */
410void lcd_remote_update_rect(int, int, int, int) __attribute__ ((section (".icode"))); 405void lcd_remote_update_rect(int, int, int, int) __attribute__ ((section (".icode")));
411void lcd_remote_update_rect(int x_start, int y, int width, int height) 406void lcd_remote_update_rect(int x, int y, int width, int height)
412{ 407{
413 int ymax; 408 int ymax;
414 409
415 if (!remote_initialized) 410 if (!remote_initialized)
416 return; 411 return;
417 412
418 /* The Y coordinates have to work on even 8 pixel rows */ 413 /* The Y coordinates have to work on even 8 pixel rows */
419 ymax = (y + height-1)/8; 414 ymax = (y + height-1) >> 3;
420 y /= 8; 415 y >>= 3;
421 416
422 if(x_start + width > LCD_REMOTE_WIDTH) 417 if(x + width > LCD_REMOTE_WIDTH)
423 width = LCD_REMOTE_WIDTH - x_start; 418 width = LCD_REMOTE_WIDTH - x;
424 if (width <= 0) 419 if (width <= 0)
425 return; /* nothing left to do, 0 is harmful to lcd_write_data() */ 420 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
426 if(ymax >= LCD_REMOTE_HEIGHT/8) 421 if(ymax >= LCD_REMOTE_HEIGHT/8)
427 ymax = LCD_REMOTE_HEIGHT/8-1; 422 ymax = LCD_REMOTE_HEIGHT/8-1;
423
424 x += xoffset;
428 425
429 /* Copy specified rectange bitmap to hardware */ 426 /* Copy specified rectange bitmap to hardware */
430 for (; y <= ymax; y++) 427 for (; y <= ymax; y++)
431 { 428 {
432 lcd_remote_write_command(LCD_REMOTE_CNTL_SET_PAGE_ADDRESS | y); 429 lcd_remote_write_command(LCD_REMOTE_CNTL_SET_PAGE_ADDRESS | y);
433 lcd_remote_write_command(LCD_REMOTE_CNTL_HIGHCOL 430 lcd_remote_write_command(LCD_REMOTE_CNTL_HIGHCOL | ((x >> 4) & 0xf));
434 | (((x_start+xoffset)>>4) & 0xf)); 431 lcd_remote_write_command(LCD_REMOTE_CNTL_LOWCOL | (x & 0xf));
435 lcd_remote_write_command(LCD_REMOTE_CNTL_LOWCOL 432 lcd_remote_write_data(&lcd_remote_framebuffer[y][x], width);
436 | ((x_start+xoffset) & 0xf));
437 lcd_remote_write_data(&lcd_remote_framebuffer[y][x_start], width);
438 } 433 }
439} 434}
440#endif /* !SIMULATOR */ 435#endif /* !SIMULATOR */
441 436
442/*** parameter handling ***/ 437/*** parameter handling ***/
443 438
439void lcd_remote_set_drawmode(int mode)
440{
441 drawmode = mode & (DRMODE_SOLID|DRMODE_INVERSEVID);
442}
443
444int lcd_remote_get_drawmode(void)
445{
446 return drawmode;
447}
448
444void lcd_remote_setmargins(int x, int y) 449void lcd_remote_setmargins(int x, int y)
445{ 450{
446 xmargin = x; 451 xmargin = x;
@@ -468,102 +473,99 @@ int lcd_remote_getstringsize(const unsigned char *str, int *w, int *h)
468 return font_getstringsize(str, w, h, curfont); 473 return font_getstringsize(str, w, h, curfont);
469} 474}
470 475
471/*** drawing functions ***/ 476/*** low-level drawing functions ***/
472 477
473void lcd_remote_clear_display(void) 478static void setpixel(int x, int y)
474{ 479{
475 memset(lcd_remote_framebuffer, 0, sizeof lcd_remote_framebuffer); 480 REMOTE_DRAW_PIXEL(x, y);
476} 481}
477 482
478/* Set a single pixel */ 483static void clearpixel(int x, int y)
479void lcd_remote_drawpixel(int x, int y)
480{ 484{
481 REMOTE_DRAW_PIXEL(x,y); 485 REMOTE_CLEAR_PIXEL(x, y);
482} 486}
483 487
484/* Clear a single pixel */ 488static void flippixel(int x, int y)
485void lcd_remote_clearpixel(int x, int y)
486{ 489{
487 REMOTE_CLEAR_PIXEL(x,y); 490 REMOTE_INVERT_PIXEL(x, y);
488} 491}
489 492
490/* Invert a single pixel */ 493static void nopixel(int x, int y)
491void lcd_remote_invertpixel(int x, int y)
492{ 494{
493 REMOTE_INVERT_PIXEL(x,y); 495 (void)x;
496 (void)y;
494} 497}
495 498
496void lcd_remote_drawline(int x1, int y1, int x2, int y2) 499lcd_pixelfunc_type* lcd_remote_pixelfuncs[8] = {
500 flippixel, nopixel, setpixel, setpixel,
501 nopixel, clearpixel, nopixel, clearpixel
502};
503
504static void flipblock(unsigned char *address, unsigned mask, unsigned bits)
497{ 505{
498 int numpixels; 506 *address ^= (bits & mask);
499 int i; 507}
500 int deltax, deltay;
501 int d, dinc1, dinc2;
502 int x, xinc1, xinc2;
503 int y, yinc1, yinc2;
504 508
505 deltax = abs(x2 - x1); 509static void bgblock(unsigned char *address, unsigned mask, unsigned bits)
506 deltay = abs(y2 - y1); 510{
511 *address &= (bits | ~mask);
512}
507 513
508 if(deltax >= deltay) 514static void fgblock(unsigned char *address, unsigned mask, unsigned bits)
509 { 515{
510 numpixels = deltax; 516 *address |= (bits & mask);
511 d = 2 * deltay - deltax; 517}
512 dinc1 = deltay * 2;
513 dinc2 = (deltay - deltax) * 2;
514 xinc1 = 1;
515 xinc2 = 1;
516 yinc1 = 0;
517 yinc2 = 1;
518 }
519 else
520 {
521 numpixels = deltay;
522 d = 2 * deltax - deltay;
523 dinc1 = deltax * 2;
524 dinc2 = (deltax - deltay) * 2;
525 xinc1 = 0;
526 xinc2 = 1;
527 yinc1 = 1;
528 yinc2 = 1;
529 }
530 numpixels++; /* include endpoints */
531 518
532 if(x1 > x2) 519static void solidblock(unsigned char *address, unsigned mask, unsigned bits)
533 { 520{
534 xinc1 = -xinc1; 521 *address = (*address & ~mask) | (bits & mask);
535 xinc2 = -xinc2; 522}
536 }
537 523
538 if(y1 > y2) 524static void flipinvblock(unsigned char *address, unsigned mask, unsigned bits)
539 { 525{
540 yinc1 = -yinc1; 526 *address ^= (~bits & mask);
541 yinc2 = -yinc2; 527}
542 }
543 528
544 x = x1; 529static void bginvblock(unsigned char *address, unsigned mask, unsigned bits)
545 y = y1; 530{
531 *address &= ~(bits & mask);
532}
546 533
547 for(i=0; i<numpixels; i++) 534static void fginvblock(unsigned char *address, unsigned mask, unsigned bits)
548 { 535{
549 REMOTE_DRAW_PIXEL(x,y); 536 *address |= (~bits & mask);
537}
550 538
551 if(d < 0) 539static void solidinvblock(unsigned char *address, unsigned mask, unsigned bits)
552 { 540{
553 d += dinc1; 541 *address = (*address & ~mask) | (~bits & mask);
554 x += xinc1;
555 y += yinc1;
556 }
557 else
558 {
559 d += dinc2;
560 x += xinc2;
561 y += yinc2;
562 }
563 }
564} 542}
565 543
566void lcd_remote_clearline(int x1, int y1, int x2, int y2) 544lcd_blockfunc_type* lcd_remote_blockfuncs[8] = {
545 flipblock, bgblock, fgblock, solidblock,
546 flipinvblock, bginvblock, fginvblock, solidinvblock
547};
548
549/*** drawing functions ***/
550
551/* Clear the whole display */
552void lcd_remote_clear_display(void)
553{
554 unsigned bits = (drawmode & DRMODE_INVERSEVID) ? 0xFFu : 0;
555
556 memset(lcd_remote_framebuffer, bits, sizeof lcd_remote_framebuffer);
557 scrolling_lines = 0;
558}
559
560/* Set a single pixel */
561void lcd_remote_drawpixel(int x, int y)
562{
563 if (((unsigned)x < LCD_REMOTE_WIDTH) || ((unsigned)y < LCD_REMOTE_HEIGHT))
564 lcd_remote_pixelfuncs[drawmode](x, y);
565}
566
567/* Draw a line */
568void lcd_remote_drawline(int x1, int y1, int x2, int y2)
567{ 569{
568 int numpixels; 570 int numpixels;
569 int i; 571 int i;
@@ -571,20 +573,21 @@ void lcd_remote_clearline(int x1, int y1, int x2, int y2)
571 int d, dinc1, dinc2; 573 int d, dinc1, dinc2;
572 int x, xinc1, xinc2; 574 int x, xinc1, xinc2;
573 int y, yinc1, yinc2; 575 int y, yinc1, yinc2;
576 lcd_pixelfunc_type *pfunc = lcd_remote_pixelfuncs[drawmode];
574 577
575 deltax = abs(x2 - x1); 578 deltax = abs(x2 - x1);
576 deltay = abs(y2 - y1); 579 deltay = abs(y2 - y1);
580 xinc2 = 1;
581 yinc2 = 1;
577 582
578 if(deltax >= deltay) 583 if (deltax >= deltay)
579 { 584 {
580 numpixels = deltax; 585 numpixels = deltax;
581 d = 2 * deltay - deltax; 586 d = 2 * deltay - deltax;
582 dinc1 = deltay * 2; 587 dinc1 = deltay * 2;
583 dinc2 = (deltay - deltax) * 2; 588 dinc2 = (deltay - deltax) * 2;
584 xinc1 = 1; 589 xinc1 = 1;
585 xinc2 = 1;
586 yinc1 = 0; 590 yinc1 = 0;
587 yinc2 = 1;
588 } 591 }
589 else 592 else
590 { 593 {
@@ -593,19 +596,17 @@ void lcd_remote_clearline(int x1, int y1, int x2, int y2)
593 dinc1 = deltax * 2; 596 dinc1 = deltax * 2;
594 dinc2 = (deltax - deltay) * 2; 597 dinc2 = (deltax - deltay) * 2;
595 xinc1 = 0; 598 xinc1 = 0;
596 xinc2 = 1;
597 yinc1 = 1; 599 yinc1 = 1;
598 yinc2 = 1;
599 } 600 }
600 numpixels++; /* include endpoints */ 601 numpixels++; /* include endpoints */
601 602
602 if(x1 > x2) 603 if (x1 > x2)
603 { 604 {
604 xinc1 = -xinc1; 605 xinc1 = -xinc1;
605 xinc2 = -xinc2; 606 xinc2 = -xinc2;
606 } 607 }
607 608
608 if(y1 > y2) 609 if (y1 > y2)
609 { 610 {
610 yinc1 = -yinc1; 611 yinc1 = -yinc1;
611 yinc2 = -yinc2; 612 yinc2 = -yinc2;
@@ -614,11 +615,12 @@ void lcd_remote_clearline(int x1, int y1, int x2, int y2)
614 x = x1; 615 x = x1;
615 y = y1; 616 y = y1;
616 617
617 for(i=0; i<numpixels; i++) 618 for (i = 0; i < numpixels; i++)
618 { 619 {
619 REMOTE_CLEAR_PIXEL(x,y); 620 if (((unsigned)x < LCD_REMOTE_WIDTH) && ((unsigned)y < LCD_REMOTE_HEIGHT))
621 pfunc(x, y);
620 622
621 if(d < 0) 623 if (d < 0)
622 { 624 {
623 d += dinc1; 625 d += dinc1;
624 x += xinc1; 626 x += xinc1;
@@ -633,185 +635,292 @@ void lcd_remote_clearline(int x1, int y1, int x2, int y2)
633 } 635 }
634} 636}
635 637
636void lcd_remote_drawrect(int x, int y, int nx, int ny) 638/* Draw a horizontal line (optimised) */
639void lcd_remote_hline(int x1, int x2, int y)
637{ 640{
638 int i; 641 int x;
642 unsigned char *dst;
643 unsigned mask;
644 lcd_blockfunc_type *bfunc;
639 645
640 if (x > LCD_REMOTE_WIDTH) 646 /* direction flip */
647 if (x2 < x1)
641 { 648 {
642 return; 649 x = x1;
650 x1 = x2;
651 x2 = x;
643 } 652 }
644 653
645 if (y > LCD_REMOTE_HEIGHT) 654 /* nothing to draw? */
646 { 655 if (((unsigned)y >= LCD_REMOTE_HEIGHT) || (x1 >= LCD_REMOTE_WIDTH)
647 return; 656 || (x2 < 0))
648 } 657 return;
649
650 if (x + nx > LCD_REMOTE_WIDTH)
651 {
652 nx = LCD_REMOTE_WIDTH - x;
653 }
654 658
655 if (y + ny > LCD_REMOTE_HEIGHT) 659 /* clipping */
656 { 660 if (x1 < 0)
657 ny = LCD_REMOTE_HEIGHT - y; 661 x1 = 0;
658 } 662 if (x2 >= LCD_REMOTE_WIDTH)
663 x2 = LCD_REMOTE_WIDTH-1;
664
665 bfunc = lcd_remote_blockfuncs[drawmode];
666 dst = &lcd_remote_framebuffer[y>>3][x1];
667 mask = 1 << (y & 7);
659 668
660 /* vertical lines */ 669 for (x = x1; x <= x2; x++)
661 for (i = 0; i < ny; i++) 670 bfunc(dst++, mask, 0xFFu);
671}
672
673/* Draw a vertical line (optimised) */
674void lcd_remote_vline(int x, int y1, int y2)
675{
676 int ny;
677 unsigned char *dst;
678 unsigned mask, mask_bottom;
679 lcd_blockfunc_type *bfunc;
680
681 /* direction flip */
682 if (y2 < y1)
662 { 683 {
663 REMOTE_DRAW_PIXEL(x, (y + i)); 684 ny = y1;
664 REMOTE_DRAW_PIXEL((x + nx - 1), (y + i)); 685 y1 = y2;
686 y2 = ny;
665 } 687 }
666 688
667 /* horizontal lines */ 689 /* nothing to draw? */
668 for (i = 0; i < nx; i++) 690 if (((unsigned)x >= LCD_REMOTE_WIDTH) || (y1 >= LCD_REMOTE_HEIGHT)
691 || (y2 < 0))
692 return;
693
694 /* clipping */
695 if (y1 < 0)
696 y1 = 0;
697 if (y2 >= LCD_REMOTE_HEIGHT)
698 y2 = LCD_REMOTE_HEIGHT-1;
699
700 bfunc = lcd_remote_blockfuncs[drawmode];
701 dst = &lcd_remote_framebuffer[y1>>3][x];
702 ny = y2 - (y1 & ~7);
703 mask = 0xFFu << (y1 & 7);
704 mask_bottom = 0xFFu >> (7 - (ny & 7));
705
706 for (; ny >= 8; ny -= 8)
669 { 707 {
670 REMOTE_DRAW_PIXEL((x + i),y); 708 bfunc(dst, mask, 0xFFu);
671 REMOTE_DRAW_PIXEL((x + i),(y + ny - 1)); 709 dst += LCD_REMOTE_WIDTH;
710 mask = 0xFFu;
672 } 711 }
712 mask_bottom &= mask;
713 bfunc(dst, mask_bottom, 0xFFu);
673} 714}
674 715
675/* Clear a rectangular area at (x, y), size (nx, ny) */ 716/* Draw a rectangular box */
676void lcd_remote_clearrect(int x, int y, int nx, int ny) 717void lcd_remote_drawrect(int x, int y, int width, int height)
677{ 718{
678 int i; 719 if ((width <= 0) || (height <= 0))
679 for (i = 0; i < nx; i++) 720 return;
680 lcd_remote_bitmap(zeros, x+i, y, 1, ny, true);
681}
682 721
683/* Fill a rectangular area at (x, y), size (nx, ny) */ 722 int x2 = x + width - 1;
684void lcd_remote_fillrect(int x, int y, int nx, int ny) 723 int y2 = y + height - 1;
685{ 724
686 int i; 725 lcd_remote_vline(x, y, y2);
687 for (i = 0; i < nx; i++) 726 lcd_remote_vline(x2, y, y2);
688 lcd_remote_bitmap(ones, x+i, y, 1, ny, true); 727 lcd_remote_hline(x, x2, y);
728 lcd_remote_hline(x, x2, y2);
689} 729}
690 730
691/* Invert a rectangular area at (x, y), size (nx, ny) */ 731/* Fill a rectangular area */
692void lcd_remote_invertrect(int x, int y, int nx, int ny) 732void lcd_remote_fillrect(int x, int y, int width, int height)
693{ 733{
694 int i, j; 734 int ny, i;
695 735 unsigned char *dst;
696 if (x > LCD_REMOTE_WIDTH) 736 unsigned mask, mask_bottom;
697 return; 737 unsigned bits = 0xFFu;
698 if (y > LCD_REMOTE_HEIGHT) 738 lcd_blockfunc_type *bfunc;
739 bool fillopt;
740
741 /* nothing to draw? */
742 if ((width <= 0) || (height <= 0) || (x >= LCD_REMOTE_WIDTH)
743 || (y >= LCD_REMOTE_HEIGHT) || (x + width <= 0) || (y + height <= 0))
699 return; 744 return;
700 745
701 if (x + nx > LCD_REMOTE_WIDTH) 746 /* clipping */
702 nx = LCD_REMOTE_WIDTH - x; 747 if (x < 0)
703 if (y + ny > LCD_REMOTE_HEIGHT) 748 {
704 ny = LCD_REMOTE_HEIGHT - y; 749 width += x;
750 x = 0;
751 }
752 if (y < 0)
753 {
754 height += y;
755 y = 0;
756 }
757 if (x + width > LCD_REMOTE_WIDTH)
758 width = LCD_REMOTE_WIDTH - x;
759 if (y + height > LCD_REMOTE_HEIGHT)
760 height = LCD_REMOTE_HEIGHT - y;
761
762 fillopt = (drawmode & DRMODE_INVERSEVID) ?
763 (drawmode & DRMODE_BG) : (drawmode & DRMODE_FG);
764 if (fillopt &&(drawmode & DRMODE_INVERSEVID))
765 bits = 0;
766 bfunc = lcd_remote_blockfuncs[drawmode];
767 dst = &lcd_remote_framebuffer[y>>3][x];
768 ny = height - 1 + (y & 7);
769 mask = 0xFFu << (y & 7);
770 mask_bottom = 0xFFu >> (7 - (ny & 7));
771
772 for (; ny >= 8; ny -= 8)
773 {
774 if (fillopt && (mask == 0xFFu))
775 memset(dst, bits, width);
776 else
777 {
778 unsigned char *dst_row = dst;
705 779
706 for (i = 0; i < nx; i++) 780 for (i = width; i > 0; i--)
707 for (j = 0; j < ny; j++) 781 bfunc(dst_row++, mask, 0xFFu);
708 REMOTE_INVERT_PIXEL((x + i), (y + j)); 782 }
709}
710 783
711void lcd_remote_bitmap(const unsigned char *src, int x, int y, int nx, int ny, 784 dst += LCD_REMOTE_WIDTH;
712 bool clear) __attribute__ ((section (".icode"))); 785 mask = 0xFFu;
713void lcd_remote_bitmap(const unsigned char *src, int x, int y, int nx, int ny, 786 }
714 bool clear) 787 mask_bottom &= mask;
715{ 788
716 const unsigned char *src_col; 789 if (fillopt && (mask_bottom == 0xFFu))
717 unsigned char *dst, *dst_col; 790 memset(dst, bits, width);
718 unsigned int data, mask1, mask2, mask3, mask4; 791 else
719 int stride, shift;
720
721 if (((unsigned) x >= LCD_REMOTE_WIDTH) || ((unsigned) y >= LCD_REMOTE_HEIGHT))
722 { 792 {
723 return; 793 for (i = width; i > 0; i--)
794 bfunc(dst++, mask_bottom, 0xFFu);
724 } 795 }
725 796}
726 stride = nx; /* otherwise right-clipping will destroy the image */
727 797
728 if (((unsigned) (x + nx)) >= LCD_REMOTE_WIDTH) 798/* About Rockbox' internal bitmap format:
799 *
800 * A bitmap contains one bit for every pixel that defines if that pixel is
801 * black (1) or white (0). Bits within a byte are arranged vertically, LSB
802 * at top.
803 * The bytes are stored in row-major order, with byte 0 being top left,
804 * byte 1 2nd from left etc. The first row of bytes defines pixel rows
805 * 0..7, the second row defines pixel row 8..15 etc.
806 *
807 * This is the same as the internal lcd hw format. */
808
809/* Draw a partial bitmap */
810void lcd_remote_bitmap_part(const unsigned char *src, int src_x, int src_y,
811 int stride, int x, int y, int width, int height)
812 __attribute__ ((section(".icode")));
813void lcd_remote_bitmap_part(const unsigned char *src, int src_x, int src_y,
814 int stride, int x, int y, int width, int height)
815{
816 int shift, ny, i;
817 unsigned char *dst;
818 unsigned mask, mask_bottom;
819 lcd_blockfunc_type *bfunc;
820
821 /* nothing to draw? */
822 if ((width <= 0) || (height <= 0) || (x >= LCD_REMOTE_WIDTH)
823 || (y >= LCD_REMOTE_HEIGHT) || (x + width <= 0) || (y + height <= 0))
824 return;
825
826 /* clipping */
827 if (x < 0)
729 { 828 {
730 nx = LCD_REMOTE_WIDTH - x; 829 width += x;
830 src_x -= x;
831 x = 0;
731 } 832 }
732 833 if (y < 0)
733 if (((unsigned) (y + ny)) >= LCD_REMOTE_HEIGHT)
734 { 834 {
735 ny = LCD_REMOTE_HEIGHT - y; 835 height += y;
836 src_y -= y;
837 y = 0;
736 } 838 }
737 839 if (x + width > LCD_REMOTE_WIDTH)
738 dst = &lcd_remote_framebuffer[y >> 3][x]; 840 width = LCD_REMOTE_WIDTH - x;
739 shift = y & 7; 841 if (y + height > LCD_REMOTE_HEIGHT)
842 height = LCD_REMOTE_HEIGHT - y;
843
844 src += stride * (src_y >> 3) + src_x; /* move starting point */
845 src_y &= 7;
846 y -= src_y;
847 dst = &lcd_remote_framebuffer[y>>3][x];
848 shift = y & 7;
849 ny = height - 1 + shift + src_y;
850
851 bfunc = lcd_remote_blockfuncs[drawmode];
852 mask = 0xFFu << (shift + src_y);
853 mask_bottom = 0xFFu >> (7 - (ny & 7));
740 854
741 if (!shift && clear) /* shortcut for byte aligned match with clear */ 855 if (shift == 0)
742 { 856 {
743 while (ny >= 8) /* all full rows */ 857 bool copyopt = (drawmode == DRMODE_SOLID);
858
859 for (; ny >= 8; ny -= 8)
744 { 860 {
745 memcpy(dst, src, nx); 861 if (copyopt && (mask == 0xFFu))
862 memcpy(dst, src, width);
863 else
864 {
865 const unsigned char *src_row = src;
866 unsigned char *dst_row = dst;
867
868 for (i = width; i > 0; i--)
869 bfunc(dst_row++, mask, *src_row++);
870 }
871
746 src += stride; 872 src += stride;
747 dst += LCD_REMOTE_WIDTH; 873 dst += LCD_REMOTE_WIDTH;
748 ny -= 8; 874 mask = 0xFFu;
749 }
750 if (ny == 0) /* nothing left to do? */
751 {
752 return;
753 } 875 }
754 /* last partial row to do by default routine */ 876 mask_bottom &= mask;
755 }
756
757 ny += shift;
758 877
759 /* Calculate bit masks */ 878 if (copyopt && (mask_bottom == 0xFFu))
760 mask4 = ~(0xfe << ((ny-1) & 7)); /* data mask for last partial row */ 879 memcpy(dst, src, width);
761 880 else
762 if (clear)
763 {
764 mask1 = ~(0xff << shift); /* clearing of first partial row */
765 mask2 = 0; /* clearing of intermediate (full) rows */
766 mask3 = ~mask4; /* clearing of last partial row */
767 if (ny <= 8)
768 { 881 {
769 mask3 |= mask1; 882 for (i = width; i > 0; i--)
883 bfunc(dst++, mask_bottom, *src++);
770 } 884 }
771 } 885 }
772 else 886 else
773 { 887 {
774 mask1 = mask2 = mask3 = 0xff; 888 for (x = 0; x < width; x++)
775 }
776
777 /* Loop for each column */
778 for (x = 0; x < nx; x++)
779 {
780 src_col = src++;
781 dst_col = dst++;
782 data = 0;
783 y = 0;
784
785 if (ny > 8)
786 { 889 {
787 /* First partial row */ 890 const unsigned char *src_col = src++;
788 data = *src_col << shift; 891 unsigned char *dst_col = dst++;
789 *dst_col = (*dst_col & mask1) | data; 892 unsigned mask_col = mask;
790 src_col += stride; 893 unsigned data = 0;
791 dst_col += LCD_REMOTE_WIDTH; 894
792 data >>= 8; 895 for (y = ny; y >= 8; y -= 8)
793
794 /* Intermediate rows */
795 for (y = 8; y < ny-8; y += 8)
796 { 896 {
797 data |= *src_col << shift; 897 data |= *src_col << shift;
798 *dst_col = (*dst_col & mask2) | data; 898
899 if (mask_col & 0xFFu)
900 {
901 bfunc(dst_col, mask_col, data);
902 mask_col = 0xFFu;
903 }
904 else
905 mask_col >>= 8;
906
799 src_col += stride; 907 src_col += stride;
800 dst_col += LCD_REMOTE_WIDTH; 908 dst_col += LCD_REMOTE_WIDTH;
801 data >>= 8; 909 data >>= 8;
802 } 910 }
803 }
804
805 /* Last partial row */
806 if (y + shift < ny)
807 {
808 data |= *src_col << shift; 911 data |= *src_col << shift;
912 bfunc(dst_col, mask_col & mask_bottom, data);
809 } 913 }
810
811 *dst_col = (*dst_col & mask3) | (data & mask4);
812 } 914 }
813} 915}
814 916
917/* Draw a full bitmap */
918void lcd_remote_bitmap(const unsigned char *src, int x, int y, int width,
919 int height)
920{
921 lcd_remote_bitmap_part(src, 0, 0, width, x, y, width, height);
922}
923
815/* put a string at a given pixel position, skipping first ofs pixel columns */ 924/* put a string at a given pixel position, skipping first ofs pixel columns */
816static void lcd_remote_putsxyofs(int x, int y, int ofs, const unsigned char *str) 925static void lcd_remote_putsxyofs(int x, int y, int ofs, const unsigned char *str)
817{ 926{
@@ -820,7 +929,8 @@ static void lcd_remote_putsxyofs(int x, int y, int ofs, const unsigned char *str
820 929
821 while ((ch = *str++) != '\0' && x < LCD_REMOTE_WIDTH) 930 while ((ch = *str++) != '\0' && x < LCD_REMOTE_WIDTH)
822 { 931 {
823 int gwidth, width; 932 int width;
933 const unsigned char *bits;
824 934
825 /* check input range */ 935 /* check input range */
826 if (ch < pf->firstchar || ch >= pf->firstchar+pf->size) 936 if (ch < pf->firstchar || ch >= pf->firstchar+pf->size)
@@ -828,40 +938,21 @@ static void lcd_remote_putsxyofs(int x, int y, int ofs, const unsigned char *str
828 ch -= pf->firstchar; 938 ch -= pf->firstchar;
829 939
830 /* get proportional width and glyph bits */ 940 /* get proportional width and glyph bits */
831 gwidth = pf->width ? pf->width[ch] : pf->maxwidth; 941 width = pf->width ? pf->width[ch] : pf->maxwidth;
832 width = MIN (gwidth, LCD_REMOTE_WIDTH - x);
833 942
834 if (ofs != 0) 943 if (ofs > width)
835 { 944 {
836 if (ofs > width) 945 ofs -= width;
837 { 946 continue;
838 ofs -= width;
839 continue;
840 }
841 width -= ofs;
842 } 947 }
843 948
844 if (width > 0) 949 bits = pf->bits + (pf->offset ?
845 { 950 pf->offset[ch] : ((pf->height + 7) / 8 * pf->maxwidth * ch));
846 unsigned int i;
847 const unsigned char* bits = pf->bits +
848 (pf->offset ? pf->offset[ch]
849 : ((pf->height + 7) / 8 * pf->maxwidth * ch));
850 951
851 if (ofs != 0) 952 lcd_remote_bitmap_part(bits, ofs, 0, width, x, y, width - ofs,
852 { 953 pf->height);
853 for (i = 0; i < pf->height; i += 8) 954
854 { 955 x += width - ofs;
855 lcd_remote_bitmap (bits + ofs, x, y + i, width,
856 MIN(8, pf->height - i), true);
857 bits += gwidth;
858 }
859 }
860 else
861 lcd_remote_bitmap ((unsigned char*) bits, x, y, gwidth,
862 pf->height, true);
863 x += width;
864 }
865 ofs = 0; 956 ofs = 0;
866 } 957 }
867} 958}
@@ -883,9 +974,10 @@ void lcd_remote_puts(int x, int y, const unsigned char *str)
883void lcd_remote_puts_style(int x, int y, const unsigned char *str, int style) 974void lcd_remote_puts_style(int x, int y, const unsigned char *str, int style)
884{ 975{
885 int xpos,ypos,w,h; 976 int xpos,ypos,w,h;
977 int lastmode = lcd_remote_get_drawmode();
886 978
887 /* make sure scrolling is turned off on the line we are updating */ 979 /* make sure scrolling is turned off on the line we are updating */
888 //scrolling_lines &= ~(1 << y); 980 scrolling_lines &= ~(1 << y);
889 981
890 if(!str || !str[0]) 982 if(!str || !str[0])
891 return; 983 return;
@@ -894,10 +986,14 @@ void lcd_remote_puts_style(int x, int y, const unsigned char *str, int style)
894 xpos = xmargin + x*w / strlen(str); 986 xpos = xmargin + x*w / strlen(str);
895 ypos = ymargin + y*h; 987 ypos = ymargin + y*h;
896 lcd_remote_putsxy(xpos, ypos, str); 988 lcd_remote_putsxy(xpos, ypos, str);
897 lcd_remote_clearrect(xpos + w, ypos, LCD_REMOTE_WIDTH - (xpos + w), h); 989 lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
990 lcd_remote_fillrect(xpos + w, ypos, LCD_REMOTE_WIDTH - (xpos + w), h);
898 if (style & STYLE_INVERT) 991 if (style & STYLE_INVERT)
899 lcd_remote_invertrect(xpos, ypos, LCD_REMOTE_WIDTH - xpos, h); 992 {
900 993 lcd_remote_set_drawmode(DRMODE_COMPLEMENT);
994 lcd_remote_fillrect(xpos, ypos, LCD_REMOTE_WIDTH - xpos, h);
995 }
996 lcd_remote_set_drawmode(lastmode);
901} 997}
902 998
903/*** scrolling ***/ 999/*** scrolling ***/
@@ -1008,6 +1104,7 @@ static void scroll_thread(void)
1008 struct scrollinfo* s; 1104 struct scrollinfo* s;
1009 int index; 1105 int index;
1010 int xpos, ypos; 1106 int xpos, ypos;
1107 int lastmode;
1011 1108
1012 /* initialize scroll struct array */ 1109 /* initialize scroll struct array */
1013 scrolling_lines = 0; 1110 scrolling_lines = 0;
@@ -1061,10 +1158,17 @@ static void scroll_thread(void)
1061 s->offset %= s->width; 1158 s->offset %= s->width;
1062 } 1159 }
1063 1160
1064 lcd_remote_clearrect(xpos, ypos, LCD_REMOTE_WIDTH - xpos, pf->height); 1161 lastmode = lcd_remote_get_drawmode();
1162 lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1163 lcd_remote_fillrect(xpos, ypos, LCD_REMOTE_WIDTH - xpos, pf->height);
1164 lcd_remote_set_drawmode(DRMODE_SOLID);
1065 lcd_remote_putsxyofs(xpos, ypos, s->offset, s->line); 1165 lcd_remote_putsxyofs(xpos, ypos, s->offset, s->line);
1066 if (s->invert) 1166 if (s->invert)
1067 lcd_remote_invertrect(xpos, ypos, LCD_REMOTE_WIDTH - xpos, pf->height); 1167 {
1168 lcd_remote_set_drawmode(DRMODE_COMPLEMENT);
1169 lcd_remote_fillrect(xpos, ypos, LCD_REMOTE_WIDTH - xpos, pf->height);
1170 }
1171 lcd_remote_set_drawmode(lastmode);
1068 lcd_remote_update_rect(xpos, ypos, LCD_REMOTE_WIDTH - xpos, pf->height); 1172 lcd_remote_update_rect(xpos, ypos, LCD_REMOTE_WIDTH - xpos, pf->height);
1069 } 1173 }
1070 1174
diff --git a/firmware/drivers/lcd-h100.c b/firmware/drivers/lcd-h100.c
index 616a8521b0..93988f6c74 100644
--- a/firmware/drivers/lcd-h100.c
+++ b/firmware/drivers/lcd-h100.c
@@ -333,7 +333,7 @@ static void nopixel(int x, int y)
333 (void)y; 333 (void)y;
334} 334}
335 335
336lcd_pixelfunc_type* pixelfunc[8] = { 336lcd_pixelfunc_type* lcd_pixelfuncs[8] = {
337 flippixel, nopixel, setpixel, setpixel, 337 flippixel, nopixel, setpixel, setpixel,
338 nopixel, clearpixel, nopixel, clearpixel 338 nopixel, clearpixel, nopixel, clearpixel
339}; 339};
@@ -378,7 +378,7 @@ static void solidinvblock(unsigned char *address, unsigned mask, unsigned bits)
378 *address = (*address & ~mask) | (~bits & mask); 378 *address = (*address & ~mask) | (~bits & mask);
379} 379}
380 380
381lcd_blockfunc_type* blockfunc[8] = { 381lcd_blockfunc_type* lcd_blockfuncs[8] = {
382 flipblock, bgblock, fgblock, solidblock, 382 flipblock, bgblock, fgblock, solidblock,
383 flipinvblock, bginvblock, fginvblock, solidinvblock 383 flipinvblock, bginvblock, fginvblock, solidinvblock
384}; 384};
@@ -398,7 +398,7 @@ void lcd_clear_display(void)
398void lcd_drawpixel(int x, int y) 398void lcd_drawpixel(int x, int y)
399{ 399{
400 if (((unsigned)x < LCD_WIDTH) || ((unsigned)y < LCD_HEIGHT)) 400 if (((unsigned)x < LCD_WIDTH) || ((unsigned)y < LCD_HEIGHT))
401 pixelfunc[drawmode](x, y); 401 lcd_pixelfuncs[drawmode](x, y);
402} 402}
403 403
404/* Draw a line */ 404/* Draw a line */
@@ -410,7 +410,7 @@ void lcd_drawline(int x1, int y1, int x2, int y2)
410 int d, dinc1, dinc2; 410 int d, dinc1, dinc2;
411 int x, xinc1, xinc2; 411 int x, xinc1, xinc2;
412 int y, yinc1, yinc2; 412 int y, yinc1, yinc2;
413 lcd_pixelfunc_type *pfunc = pixelfunc[drawmode]; 413 lcd_pixelfunc_type *pfunc = lcd_pixelfuncs[drawmode];
414 414
415 deltax = abs(x2 - x1); 415 deltax = abs(x2 - x1);
416 deltay = abs(y2 - y1); 416 deltay = abs(y2 - y1);
@@ -498,7 +498,7 @@ void lcd_hline(int x1, int x2, int y)
498 if (x2 >= LCD_WIDTH) 498 if (x2 >= LCD_WIDTH)
499 x2 = LCD_WIDTH-1; 499 x2 = LCD_WIDTH-1;
500 500
501 bfunc = blockfunc[drawmode]; 501 bfunc = lcd_blockfuncs[drawmode];
502 dst = &lcd_framebuffer[y>>3][x1]; 502 dst = &lcd_framebuffer[y>>3][x1];
503 mask = 1 << (y & 7); 503 mask = 1 << (y & 7);
504 504
@@ -532,7 +532,7 @@ void lcd_vline(int x, int y1, int y2)
532 if (y2 >= LCD_HEIGHT) 532 if (y2 >= LCD_HEIGHT)
533 y2 = LCD_HEIGHT-1; 533 y2 = LCD_HEIGHT-1;
534 534
535 bfunc = blockfunc[drawmode]; 535 bfunc = lcd_blockfuncs[drawmode];
536 dst = &lcd_framebuffer[y1>>3][x]; 536 dst = &lcd_framebuffer[y1>>3][x];
537 ny = y2 - (y1 & ~7); 537 ny = y2 - (y1 & ~7);
538 mask = 0xFFu << (y1 & 7); 538 mask = 0xFFu << (y1 & 7);
@@ -598,7 +598,7 @@ void lcd_fillrect(int x, int y, int width, int height)
598 (drawmode & DRMODE_BG) : (drawmode & DRMODE_FG); 598 (drawmode & DRMODE_BG) : (drawmode & DRMODE_FG);
599 if (fillopt &&(drawmode & DRMODE_INVERSEVID)) 599 if (fillopt &&(drawmode & DRMODE_INVERSEVID))
600 bits = 0; 600 bits = 0;
601 bfunc = blockfunc[drawmode]; 601 bfunc = lcd_blockfuncs[drawmode];
602 dst = &lcd_framebuffer[y>>3][x]; 602 dst = &lcd_framebuffer[y>>3][x];
603 ny = height - 1 + (y & 7); 603 ny = height - 1 + (y & 7);
604 mask = 0xFFu << (y & 7); 604 mask = 0xFFu << (y & 7);
@@ -683,7 +683,7 @@ void lcd_bitmap_part(const unsigned char *src, int src_x, int src_y,
683 shift = y & 7; 683 shift = y & 7;
684 ny = height - 1 + shift + src_y; 684 ny = height - 1 + shift + src_y;
685 685
686 bfunc = blockfunc[drawmode]; 686 bfunc = lcd_blockfuncs[drawmode];
687 mask = 0xFFu << (shift + src_y); 687 mask = 0xFFu << (shift + src_y);
688 mask_bottom = 0xFFu >> (7 - (ny & 7)); 688 mask_bottom = 0xFFu >> (7 - (ny & 7));
689 689
@@ -779,7 +779,7 @@ static void lcd_putsxyofs(int x, int y, int ofs, const unsigned char *str)
779 ofs -= width; 779 ofs -= width;
780 continue; 780 continue;
781 } 781 }
782 782
783 bits = pf->bits + (pf->offset ? 783 bits = pf->bits + (pf->offset ?
784 pf->offset[ch] : ((pf->height + 7) / 8 * pf->maxwidth * ch)); 784 pf->offset[ch] : ((pf->height + 7) / 8 * pf->maxwidth * ch));
785 785
diff --git a/firmware/drivers/lcd-recorder.c b/firmware/drivers/lcd-recorder.c
index 9513c26380..65866ec83f 100644
--- a/firmware/drivers/lcd-recorder.c
+++ b/firmware/drivers/lcd-recorder.c
@@ -392,7 +392,7 @@ static void nopixel(int x, int y)
392 (void)y; 392 (void)y;
393} 393}
394 394
395lcd_pixelfunc_type* pixelfunc[8] = { 395lcd_pixelfunc_type* lcd_pixelfuncs[8] = {
396 flippixel, nopixel, setpixel, setpixel, 396 flippixel, nopixel, setpixel, setpixel,
397 nopixel, clearpixel, nopixel, clearpixel 397 nopixel, clearpixel, nopixel, clearpixel
398}; 398};
@@ -437,7 +437,7 @@ static void solidinvblock(unsigned char *address, unsigned mask, unsigned bits)
437 *address = (*address & ~mask) | (~bits & mask); 437 *address = (*address & ~mask) | (~bits & mask);
438} 438}
439 439
440lcd_blockfunc_type* blockfunc[8] = { 440lcd_blockfunc_type* lcd_blockfuncs[8] = {
441 flipblock, bgblock, fgblock, solidblock, 441 flipblock, bgblock, fgblock, solidblock,
442 flipinvblock, bginvblock, fginvblock, solidinvblock 442 flipinvblock, bginvblock, fginvblock, solidinvblock
443}; 443};
@@ -457,7 +457,7 @@ void lcd_clear_display(void)
457void lcd_drawpixel(int x, int y) 457void lcd_drawpixel(int x, int y)
458{ 458{
459 if (((unsigned)x < LCD_WIDTH) || ((unsigned)y < LCD_HEIGHT)) 459 if (((unsigned)x < LCD_WIDTH) || ((unsigned)y < LCD_HEIGHT))
460 pixelfunc[drawmode](x, y); 460 lcd_pixelfuncs[drawmode](x, y);
461} 461}
462 462
463/* Draw a line */ 463/* Draw a line */
@@ -469,7 +469,7 @@ void lcd_drawline(int x1, int y1, int x2, int y2)
469 int d, dinc1, dinc2; 469 int d, dinc1, dinc2;
470 int x, xinc1, xinc2; 470 int x, xinc1, xinc2;
471 int y, yinc1, yinc2; 471 int y, yinc1, yinc2;
472 lcd_pixelfunc_type *pfunc = pixelfunc[drawmode]; 472 lcd_pixelfunc_type *pfunc = lcd_pixelfuncs[drawmode];
473 473
474 deltax = abs(x2 - x1); 474 deltax = abs(x2 - x1);
475 deltay = abs(y2 - y1); 475 deltay = abs(y2 - y1);
@@ -557,7 +557,7 @@ void lcd_hline(int x1, int x2, int y)
557 if (x2 >= LCD_WIDTH) 557 if (x2 >= LCD_WIDTH)
558 x2 = LCD_WIDTH-1; 558 x2 = LCD_WIDTH-1;
559 559
560 bfunc = blockfunc[drawmode]; 560 bfunc = lcd_blockfuncs[drawmode];
561 dst = &lcd_framebuffer[y>>3][x1]; 561 dst = &lcd_framebuffer[y>>3][x1];
562 mask = 1 << (y & 7); 562 mask = 1 << (y & 7);
563 563
@@ -591,7 +591,7 @@ void lcd_vline(int x, int y1, int y2)
591 if (y2 >= LCD_HEIGHT) 591 if (y2 >= LCD_HEIGHT)
592 y2 = LCD_HEIGHT-1; 592 y2 = LCD_HEIGHT-1;
593 593
594 bfunc = blockfunc[drawmode]; 594 bfunc = lcd_blockfuncs[drawmode];
595 dst = &lcd_framebuffer[y1>>3][x]; 595 dst = &lcd_framebuffer[y1>>3][x];
596 ny = y2 - (y1 & ~7); 596 ny = y2 - (y1 & ~7);
597 mask = 0xFFu << (y1 & 7); 597 mask = 0xFFu << (y1 & 7);
@@ -657,7 +657,7 @@ void lcd_fillrect(int x, int y, int width, int height)
657 (drawmode & DRMODE_BG) : (drawmode & DRMODE_FG); 657 (drawmode & DRMODE_BG) : (drawmode & DRMODE_FG);
658 if (fillopt &&(drawmode & DRMODE_INVERSEVID)) 658 if (fillopt &&(drawmode & DRMODE_INVERSEVID))
659 bits = 0; 659 bits = 0;
660 bfunc = blockfunc[drawmode]; 660 bfunc = lcd_blockfuncs[drawmode];
661 dst = &lcd_framebuffer[y>>3][x]; 661 dst = &lcd_framebuffer[y>>3][x];
662 ny = height - 1 + (y & 7); 662 ny = height - 1 + (y & 7);
663 mask = 0xFFu << (y & 7); 663 mask = 0xFFu << (y & 7);
@@ -742,7 +742,7 @@ void lcd_bitmap_part(const unsigned char *src, int src_x, int src_y,
742 shift = y & 7; 742 shift = y & 7;
743 ny = height - 1 + shift + src_y; 743 ny = height - 1 + shift + src_y;
744 744
745 bfunc = blockfunc[drawmode]; 745 bfunc = lcd_blockfuncs[drawmode];
746 mask = 0xFFu << (shift + src_y); 746 mask = 0xFFu << (shift + src_y);
747 mask_bottom = 0xFFu >> (7 - (ny & 7)); 747 mask_bottom = 0xFFu >> (7 - (ny & 7));
748 748
diff --git a/firmware/export/lcd-remote.h b/firmware/export/lcd-remote.h
index c5793eda93..17025a7421 100644
--- a/firmware/export/lcd-remote.h
+++ b/firmware/export/lcd-remote.h
@@ -26,9 +26,9 @@
26 26
27#ifdef HAVE_REMOTE_LCD 27#ifdef HAVE_REMOTE_LCD
28 28
29#define REMOTE_DRAW_PIXEL(x,y) lcd_remote_framebuffer[(y)/8][(x)] |= (1<<((y)&7)) 29#define REMOTE_DRAW_PIXEL(x,y) lcd_remote_framebuffer[(y)>>3][(x)] |= (1<<((y)&7))
30#define REMOTE_CLEAR_PIXEL(x,y) lcd_remote_framebuffer[(y)/8][(x)] &= ~(1<<((y)&7)) 30#define REMOTE_CLEAR_PIXEL(x,y) lcd_remote_framebuffer[(y)>>3][(x)] &= ~(1<<((y)&7))
31#define REMOTE_INVERT_PIXEL(x,y) lcd_remote_framebuffer[(y)/8][(x)] ^= (1<<((y)&7)) 31#define REMOTE_INVERT_PIXEL(x,y) lcd_remote_framebuffer[(y)>>3][(x)] ^= (1<<((y)&7))
32 32
33#define STYLE_DEFAULT 0 33#define STYLE_DEFAULT 0
34#define STYLE_INVERT 1 34#define STYLE_INVERT 1
@@ -48,11 +48,11 @@ extern void lcd_remote_stop_scroll(void);
48extern void lcd_remote_scroll_speed(int speed); 48extern void lcd_remote_scroll_speed(int speed);
49extern void lcd_remote_scroll_delay(int ms); 49extern void lcd_remote_scroll_delay(int ms);
50extern void lcd_remote_puts_scroll(int x, int y, const unsigned char* string); 50extern void lcd_remote_puts_scroll(int x, int y, const unsigned char* string);
51extern void lcd_remote_puts_scroll_style(int x, int y, const unsigned char* string, 51extern void lcd_remote_puts_scroll_style(int x, int y,
52 int style); 52 const unsigned char* string, int style);
53 53
54extern void lcd_remote_update(void); 54extern void lcd_remote_update(void);
55extern void lcd_remote_update_rect(int x_start, int y, int width, int height); 55extern void lcd_remote_update_rect(int x, int y, int width, int height);
56 56
57/* Memory copy of display bitmap */ 57/* Memory copy of display bitmap */
58extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH]; 58extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH];
@@ -60,23 +60,28 @@ extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDT
60extern void lcd_remote_set_invert_display(bool yesno); 60extern void lcd_remote_set_invert_display(bool yesno);
61extern void lcd_remote_set_flip(bool yesno); 61extern void lcd_remote_set_flip(bool yesno);
62extern void lcd_remote_roll(int pixels); 62extern void lcd_remote_roll(int pixels);
63
64extern void lcd_remote_set_drawmode(int mode);
65extern int lcd_remote_get_drawmode(void);
63extern void lcd_remote_setmargins(int xmargin, int ymargin); 66extern void lcd_remote_setmargins(int xmargin, int ymargin);
64extern int lcd_remote_getxmargin(void); 67extern int lcd_remote_getxmargin(void);
65extern int lcd_remote_getymargin(void); 68extern int lcd_remote_getymargin(void);
66extern void lcd_remote_setfont(int font); 69extern void lcd_remote_setfont(int font);
67extern int lcd_remote_getstringsize(const unsigned char *str, int *w, int *h); 70extern int lcd_remote_getstringsize(const unsigned char *str, int *w, int *h);
71
68extern void lcd_remote_drawpixel(int x, int y); 72extern void lcd_remote_drawpixel(int x, int y);
69extern void lcd_remote_clearpixel(int x, int y);
70extern void lcd_remote_invertpixel(int x, int y);
71extern void lcd_remote_drawline(int x1, int y1, int x2, int y2); 73extern void lcd_remote_drawline(int x1, int y1, int x2, int y2);
72extern void lcd_remote_clearline(int x1, int y1, int x2, int y2); 74extern void lcd_remote_hline(int x1, int x2, int y);
73extern void lcd_remote_drawrect(int x, int y, int nx, int ny); 75extern void lcd_remote_vline(int x, int y1, int y2);
74extern void lcd_remote_clearrect(int x, int y, int nx, int ny); 76extern void lcd_remote_drawrect(int x, int y, int width, int height);
75extern void lcd_remote_fillrect(int x, int y, int nx, int ny); 77extern void lcd_remote_fillrect(int x, int y, int width, int height);
76extern void lcd_remote_invertrect(int x, int y, int nx, int ny); 78extern void lcd_remote_bitmap_part(const unsigned char *src, int src_x,
79 int src_y, int stride, int x, int y,
80 int width, int height);
77extern void lcd_remote_bitmap(const unsigned char *src, int x, int y, 81extern void lcd_remote_bitmap(const unsigned char *src, int x, int y,
78 int nx, int ny, bool clear); 82 int width, int height);
79extern void lcd_remote_putsxy(int x, int y, const unsigned char *string); 83extern void lcd_remote_putsxy(int x, int y, const unsigned char *string);
84
80extern void lcd_remote_invertscroll(int x, int y); 85extern void lcd_remote_invertscroll(int x, int y);
81extern void lcd_remote_bidir_scroll(int threshold); 86extern void lcd_remote_bidir_scroll(int threshold);
82extern void lcd_remote_scroll_step(int pixels); 87extern void lcd_remote_scroll_step(int pixels);
diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h
index 6a6a8e8697..77e79799f8 100644
--- a/firmware/export/lcd.h
+++ b/firmware/export/lcd.h
@@ -122,9 +122,9 @@ extern void lcd_jump_scroll_delay(int ms);
122#define DRMODE_SOLID 3 122#define DRMODE_SOLID 3
123#define DRMODE_INVERSEVID 4 /* used as bit modifier for basic modes */ 123#define DRMODE_INVERSEVID 4 /* used as bit modifier for basic modes */
124 124
125#define DRAW_PIXEL(x,y) lcd_framebuffer[(y)/8][(x)] |= (1<<((y)&7)) 125#define DRAW_PIXEL(x,y) lcd_framebuffer[(y)>>3][(x)] |= (1<<((y)&7))
126#define CLEAR_PIXEL(x,y) lcd_framebuffer[(y)/8][(x)] &= ~(1<<((y)&7)) 126#define CLEAR_PIXEL(x,y) lcd_framebuffer[(y)>>3][(x)] &= ~(1<<((y)&7))
127#define INVERT_PIXEL(x,y) lcd_framebuffer[(y)/8][(x)] ^= (1<<((y)&7)) 127#define INVERT_PIXEL(x,y) lcd_framebuffer[(y)>>3][(x)] ^= (1<<((y)&7))
128 128
129typedef void lcd_pixelfunc_type(int x, int y); /* for b&w */ 129typedef void lcd_pixelfunc_type(int x, int y); /* for b&w */
130typedef void lcd_blockfunc_type(unsigned char *address, unsigned mask, unsigned bits); 130typedef void lcd_blockfunc_type(unsigned char *address, unsigned mask, unsigned bits);
@@ -144,6 +144,10 @@ extern int lcd_getymargin(void);
144extern void lcd_setfont(int font); 144extern void lcd_setfont(int font);
145extern int lcd_getstringsize(const unsigned char *str, int *w, int *h); 145extern int lcd_getstringsize(const unsigned char *str, int *w, int *h);
146 146
147/* low level drawing function pointer arrays */
148extern lcd_pixelfunc_type* lcd_pixelfuncs[8];
149extern lcd_blockfunc_type* lcd_blockfuncs[8];
150
147extern void lcd_drawpixel(int x, int y); 151extern void lcd_drawpixel(int x, int y);
148extern void lcd_drawline(int x1, int y1, int x2, int y2); 152extern void lcd_drawline(int x1, int y1, int x2, int y2);
149extern void lcd_hline(int x1, int x2, int y); 153extern void lcd_hline(int x1, int x2, int y);