summaryrefslogtreecommitdiff
path: root/firmware/drivers/lcd-remote-2bit-vi.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/lcd-remote-2bit-vi.c')
-rwxr-xr-xfirmware/drivers/lcd-remote-2bit-vi.c1085
1 files changed, 1085 insertions, 0 deletions
diff --git a/firmware/drivers/lcd-remote-2bit-vi.c b/firmware/drivers/lcd-remote-2bit-vi.c
new file mode 100755
index 0000000000..cf486b5d0d
--- /dev/null
+++ b/firmware/drivers/lcd-remote-2bit-vi.c
@@ -0,0 +1,1085 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Jens Arnold
11 *
12 * Rockbox driver for 2bit vertically interleaved remote LCDs
13 *
14 * All files in this archive are subject to the GNU General Public License.
15 * See the file COPYING in the source tree root for full license agreement.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "config.h"
22#include "cpu.h"
23#include "lcd.h"
24#include "lcd-remote.h"
25#include "kernel.h"
26#include "thread.h"
27#include <string.h>
28#include <stdlib.h>
29#include "memory.h"
30#include "file.h"
31#include "debug.h"
32#include "system.h"
33#include "font.h"
34#include "rbunicode.h"
35#include "bidi.h"
36
37#define SCROLLABLE_LINES (((LCD_REMOTE_HEIGHT+4)/5 < 32) ? (LCD_REMOTE_HEIGHT+4)/5 : 32)
38
39/*** globals ***/
40
41fb_remote_data lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_FBWIDTH]
42 IBSS_ATTR;
43
44static const fb_data patterns[4] = {0xFFFF, 0xFF00, 0x00FF, 0x0000};
45
46static unsigned fg_pattern IDATA_ATTR = 0xFFFF; /* initially black */
47static unsigned bg_pattern IDATA_ATTR = 0x0000; /* initially white */
48static int drawmode = DRMODE_SOLID;
49static int xmargin = 0;
50static int ymargin = 0;
51static int curfont = FONT_SYSFIXED;
52
53/* scrolling */
54static volatile int scrolling_lines=0; /* Bitpattern of which lines are scrolling */
55static void scroll_thread(void);
56static long scroll_stack[DEFAULT_STACK_SIZE/sizeof(long)];
57static const char scroll_name[] = "remote_scroll";
58static int scroll_ticks = 12; /* # of ticks between updates*/
59static int scroll_delay = HZ/2; /* ticks delay before start */
60static int scroll_step = 6; /* pixels per scroll step */
61static int bidir_limit = 50; /* percent */
62static struct scrollinfo scroll[SCROLLABLE_LINES];
63
64static const char scroll_tick_table[16] = {
65 /* Hz values:
66 1, 1.25, 1.55, 2, 2.5, 3.12, 4, 5, 6.25, 8.33, 10, 12.5, 16.7, 20, 25, 33 */
67 100, 80, 64, 50, 40, 32, 25, 20, 16, 12, 10, 8, 6, 5, 4, 3
68};
69
70
71/* LCD init */
72void lcd_remote_init(void)
73{
74 lcd_remote_clear_display();
75#if 0 /* FIXME */
76 /* Call device specific init */
77 remote_init();
78#endif
79 create_thread(scroll_thread, scroll_stack,
80 sizeof(scroll_stack), scroll_name);
81}
82
83/*** parameter handling ***/
84
85void lcd_remote_set_drawmode(int mode)
86{
87 drawmode = mode & (DRMODE_SOLID|DRMODE_INVERSEVID);
88}
89
90int lcd_remote_get_drawmode(void)
91{
92 return drawmode;
93}
94
95void lcd_remote_set_foreground(unsigned brightness)
96{
97 fg_pattern = patterns[brightness & 3];
98}
99
100unsigned lcd_remote_get_foreground(void)
101{
102 return (~fg_pattern >> 7) & 3;
103}
104
105void lcd_remote_set_background(unsigned brightness)
106{
107 bg_pattern = patterns[brightness & 3];
108}
109
110unsigned lcd_remote_get_background(void)
111{
112 return (~bg_pattern >> 7) & 3;
113}
114
115void lcd_remote_set_drawinfo(int mode, unsigned fg_brightness,
116 unsigned bg_brightness)
117{
118 lcd_remote_set_drawmode(mode);
119 lcd_remote_set_foreground(fg_brightness);
120 lcd_remote_set_background(bg_brightness);
121}
122
123void lcd_remote_setmargins(int x, int y)
124{
125 xmargin = x;
126 ymargin = y;
127}
128
129int lcd_remote_getxmargin(void)
130{
131 return xmargin;
132}
133
134int lcd_remote_getymargin(void)
135{
136 return ymargin;
137}
138
139void lcd_remote_setfont(int newfont)
140{
141 curfont = newfont;
142}
143
144int lcd_remote_getstringsize(const unsigned char *str, int *w, int *h)
145{
146 return font_getstringsize(str, w, h, curfont);
147}
148
149/*** low-level drawing functions ***/
150
151static void setpixel(int x, int y)
152{
153 unsigned mask = 0x0101 << (y & 7);
154 fb_remote_data *address = &lcd_remote_framebuffer[y>>3][x];
155 unsigned data = *address;
156
157 *address = data ^ ((data ^ fg_pattern) & mask);
158}
159
160static void clearpixel(int x, int y)
161{
162 unsigned mask = 0x0101 << (y & 7);
163 fb_remote_data *address = &lcd_remote_framebuffer[y>>3][x];
164 unsigned data = *address;
165
166 *address = data ^ ((data ^ bg_pattern) & mask);
167}
168
169static void flippixel(int x, int y)
170{
171 unsigned mask = 0x0101 << (y & 7);
172 fb_remote_data *address = &lcd_remote_framebuffer[y>>3][x];
173
174 *address ^= mask;
175}
176
177static void nopixel(int x, int y)
178{
179 (void)x;
180 (void)y;
181}
182
183lcd_remote_pixelfunc_type* const lcd_remote_pixelfuncs[8] = {
184 flippixel, nopixel, setpixel, setpixel,
185 nopixel, clearpixel, nopixel, clearpixel
186};
187
188/* 'mask' and 'bits' contain 2 bits per pixel */
189static void flipblock(fb_remote_data *address, unsigned mask, unsigned bits)
190 ICODE_ATTR;
191static void flipblock(fb_remote_data *address, unsigned mask, unsigned bits)
192{
193 *address ^= bits & mask;
194}
195
196static void bgblock(fb_remote_data *address, unsigned mask, unsigned bits)
197 ICODE_ATTR;
198static void bgblock(fb_remote_data *address, unsigned mask, unsigned bits)
199{
200 unsigned data = *address;
201
202 *address = data ^ ((data ^ bg_pattern) & mask & ~bits);
203}
204
205static void fgblock(fb_remote_data *address, unsigned mask, unsigned bits)
206 ICODE_ATTR;
207static void fgblock(fb_remote_data *address, unsigned mask, unsigned bits)
208{
209 unsigned data = *address;
210
211 *address = data ^ ((data ^ fg_pattern) & mask & bits);
212}
213
214static void solidblock(fb_remote_data *address, unsigned mask, unsigned bits)
215 ICODE_ATTR;
216static void solidblock(fb_remote_data *address, unsigned mask, unsigned bits)
217{
218 unsigned data = *address;
219 unsigned bgp = bg_pattern;
220
221 bits = bgp ^ ((bgp ^ fg_pattern) & bits);
222 *address = data ^ ((data ^ bits) & mask);
223}
224
225static void flipinvblock(fb_remote_data *address, unsigned mask, unsigned bits)
226 ICODE_ATTR;
227static void flipinvblock(fb_remote_data *address, unsigned mask, unsigned bits)
228{
229 *address ^= ~bits & mask;
230}
231
232static void bginvblock(fb_remote_data *address, unsigned mask, unsigned bits)
233 ICODE_ATTR;
234static void bginvblock(fb_remote_data *address, unsigned mask, unsigned bits)
235{
236 unsigned data = *address;
237
238 *address = data ^ ((data ^ bg_pattern) & mask & bits);
239}
240
241static void fginvblock(fb_remote_data *address, unsigned mask, unsigned bits)
242 ICODE_ATTR;
243static void fginvblock(fb_remote_data *address, unsigned mask, unsigned bits)
244{
245 unsigned data = *address;
246
247 *address = data ^ ((data ^ fg_pattern) & mask & ~bits);
248}
249
250static void solidinvblock(fb_remote_data *address, unsigned mask, unsigned bits)
251 ICODE_ATTR;
252static void solidinvblock(fb_remote_data *address, unsigned mask, unsigned bits)
253{
254 unsigned data = *address;
255 unsigned fgp = fg_pattern;
256
257 bits = fgp ^ ((fgp ^ bg_pattern) & bits);
258 *address = data ^ ((data ^ bits) & mask);
259}
260
261lcd_remote_blockfunc_type* const lcd_remote_blockfuncs[8] = {
262 flipblock, bgblock, fgblock, solidblock,
263 flipinvblock, bginvblock, fginvblock, solidinvblock
264};
265
266static inline void setblock(fb_remote_data *address, unsigned mask, unsigned bits)
267{
268 unsigned data = *address;
269
270 bits ^= data;
271 *address = data ^ (bits & mask);
272}
273
274/*** drawing functions ***/
275
276/* Clear the whole display */
277void lcd_remote_clear_display(void)
278{
279 unsigned bits = (drawmode & DRMODE_INVERSEVID) ? fg_pattern : bg_pattern;
280
281 memset16(lcd_remote_framebuffer, bits, sizeof lcd_remote_framebuffer / 2);
282 scrolling_lines = 0;
283}
284
285/* Set a single pixel */
286void lcd_remote_drawpixel(int x, int y)
287{
288 if (((unsigned)x < LCD_REMOTE_WIDTH) && ((unsigned)y < LCD_REMOTE_HEIGHT))
289 lcd_remote_pixelfuncs[drawmode](x, y);
290}
291
292/* Draw a line */
293void lcd_remote_drawline(int x1, int y1, int x2, int y2)
294{
295 int numpixels;
296 int i;
297 int deltax, deltay;
298 int d, dinc1, dinc2;
299 int x, xinc1, xinc2;
300 int y, yinc1, yinc2;
301 lcd_remote_pixelfunc_type *pfunc = lcd_remote_pixelfuncs[drawmode];
302
303 deltax = abs(x2 - x1);
304 deltay = abs(y2 - y1);
305 xinc2 = 1;
306 yinc2 = 1;
307
308 if (deltax >= deltay)
309 {
310 numpixels = deltax;
311 d = 2 * deltay - deltax;
312 dinc1 = deltay * 2;
313 dinc2 = (deltay - deltax) * 2;
314 xinc1 = 1;
315 yinc1 = 0;
316 }
317 else
318 {
319 numpixels = deltay;
320 d = 2 * deltax - deltay;
321 dinc1 = deltax * 2;
322 dinc2 = (deltax - deltay) * 2;
323 xinc1 = 0;
324 yinc1 = 1;
325 }
326 numpixels++; /* include endpoints */
327
328 if (x1 > x2)
329 {
330 xinc1 = -xinc1;
331 xinc2 = -xinc2;
332 }
333
334 if (y1 > y2)
335 {
336 yinc1 = -yinc1;
337 yinc2 = -yinc2;
338 }
339
340 x = x1;
341 y = y1;
342
343 for (i = 0; i < numpixels; i++)
344 {
345 if (((unsigned)x < LCD_REMOTE_WIDTH) && ((unsigned)y < LCD_REMOTE_HEIGHT))
346 pfunc(x, y);
347
348 if (d < 0)
349 {
350 d += dinc1;
351 x += xinc1;
352 y += yinc1;
353 }
354 else
355 {
356 d += dinc2;
357 x += xinc2;
358 y += yinc2;
359 }
360 }
361}
362
363/* Draw a horizontal line (optimised) */
364void lcd_remote_hline(int x1, int x2, int y)
365{
366 int x;
367 fb_remote_data *dst, *dst_end;
368 unsigned mask;
369 lcd_remote_blockfunc_type *bfunc;
370
371 /* direction flip */
372 if (x2 < x1)
373 {
374 x = x1;
375 x1 = x2;
376 x2 = x;
377 }
378
379 /* nothing to draw? */
380 if (((unsigned)y >= LCD_REMOTE_HEIGHT) || (x1 >= LCD_REMOTE_WIDTH)
381 || (x2 < 0))
382 return;
383
384 /* clipping */
385 if (x1 < 0)
386 x1 = 0;
387 if (x2 >= LCD_REMOTE_WIDTH)
388 x2 = LCD_REMOTE_WIDTH-1;
389
390 bfunc = lcd_remote_blockfuncs[drawmode];
391 dst = &lcd_remote_framebuffer[y>>3][x1];
392 mask = 0x0101 << (y & 7);
393
394 dst_end = dst + x2 - x1;
395 do
396 bfunc(dst++, mask, 0xFFFFu);
397 while (dst <= dst_end);
398}
399
400/* Draw a vertical line (optimised) */
401void lcd_remote_vline(int x, int y1, int y2)
402{
403 int ny;
404 fb_remote_data *dst;
405 unsigned mask, mask_bottom;
406 lcd_remote_blockfunc_type *bfunc;
407
408 /* direction flip */
409 if (y2 < y1)
410 {
411 ny = y1;
412 y1 = y2;
413 y2 = ny;
414 }
415
416 /* nothing to draw? */
417 if (((unsigned)x >= LCD_REMOTE_WIDTH) || (y1 >= LCD_REMOTE_HEIGHT)
418 || (y2 < 0))
419 return;
420
421 /* clipping */
422 if (y1 < 0)
423 y1 = 0;
424 if (y2 >= LCD_REMOTE_HEIGHT)
425 y2 = LCD_REMOTE_HEIGHT-1;
426
427 bfunc = lcd_remote_blockfuncs[drawmode];
428 dst = &lcd_remote_framebuffer[y1>>3][x];
429 ny = y2 - (y1 & ~7);
430 mask = (0xFFu << (y1 & 7)) & 0xFFu;
431 mask |= mask << 8;
432 mask_bottom = 0xFFu >> (~ny & 7);
433 mask_bottom |= mask_bottom << 8;
434
435 for (; ny >= 8; ny -= 8)
436 {
437 bfunc(dst, mask, 0xFFFFu);
438 dst += LCD_REMOTE_WIDTH;
439 mask = 0xFFFFu;
440 }
441 mask &= mask_bottom;
442 bfunc(dst, mask, 0xFFFFu);
443}
444
445/* Draw a rectangular box */
446void lcd_remote_drawrect(int x, int y, int width, int height)
447{
448 if ((width <= 0) || (height <= 0))
449 return;
450
451 int x2 = x + width - 1;
452 int y2 = y + height - 1;
453
454 lcd_remote_vline(x, y, y2);
455 lcd_remote_vline(x2, y, y2);
456 lcd_remote_hline(x, x2, y);
457 lcd_remote_hline(x, x2, y2);
458}
459
460/* Fill a rectangular area */
461void lcd_remote_fillrect(int x, int y, int width, int height)
462{
463 int ny;
464 fb_remote_data *dst, *dst_end;
465 unsigned mask, mask_bottom;
466 unsigned bits = 0;
467 lcd_remote_blockfunc_type *bfunc;
468 bool fillopt = false;
469
470 /* nothing to draw? */
471 if ((width <= 0) || (height <= 0) || (x >= LCD_REMOTE_WIDTH)
472 || (y >= LCD_REMOTE_HEIGHT) || (x + width <= 0) || (y + height <= 0))
473 return;
474
475 /* clipping */
476 if (x < 0)
477 {
478 width += x;
479 x = 0;
480 }
481 if (y < 0)
482 {
483 height += y;
484 y = 0;
485 }
486 if (x + width > LCD_REMOTE_WIDTH)
487 width = LCD_REMOTE_WIDTH - x;
488 if (y + height > LCD_REMOTE_HEIGHT)
489 height = LCD_REMOTE_HEIGHT - y;
490
491 if (drawmode & DRMODE_INVERSEVID)
492 {
493 if (drawmode & DRMODE_BG)
494 {
495 fillopt = true;
496 bits = bg_pattern;
497 }
498 }
499 else
500 {
501 if (drawmode & DRMODE_FG)
502 {
503 fillopt = true;
504 bits = fg_pattern;
505 }
506 }
507 bfunc = lcd_remote_blockfuncs[drawmode];
508 dst = &lcd_remote_framebuffer[y>>3][x];
509 ny = height - 1 + (y & 7);
510 mask = (0xFFu << (y & 7)) & 0xFFu;
511 mask |= mask << 8;
512 mask_bottom = 0xFFu >> (~ny & 7);
513 mask_bottom |= mask_bottom << 8;
514
515 for (; ny >= 8; ny -= 8)
516 {
517 if (fillopt && (mask == 0xFFFFu))
518 memset16(dst, bits, width);
519 else
520 {
521 fb_remote_data *dst_row = dst;
522
523 dst_end = dst_row + width;
524 do
525 bfunc(dst_row++, mask, 0xFFFFu);
526 while (dst_row < dst_end);
527 }
528
529 dst += LCD_REMOTE_WIDTH;
530 mask = 0xFFFFu;
531 }
532 mask &= mask_bottom;
533
534 if (fillopt && (mask == 0xFFFFu))
535 memset16(dst, bits, width);
536 else
537 {
538 dst_end = dst + width;
539 do
540 bfunc(dst++, mask, 0xFFFFu);
541 while (dst < dst_end);
542 }
543}
544
545/* About Rockbox' internal monochrome bitmap format:
546 *
547 * A bitmap contains one bit for every pixel that defines if that pixel is
548 * black (1) or white (0). Bits within a byte are arranged vertically, LSB
549 * at top.
550 * The bytes are stored in row-major order, with byte 0 being top left,
551 * byte 1 2nd from left etc. The first row of bytes defines pixel rows
552 * 0..7, the second row defines pixel row 8..15 etc.
553 *
554 * This is similar to the internal lcd hw format. */
555
556/* Draw a partial monochrome bitmap */
557void lcd_remote_mono_bitmap_part(const unsigned char *src, int src_x, int src_y,
558 int stride, int x, int y, int width, int height)
559 ICODE_ATTR;
560void lcd_remote_mono_bitmap_part(const unsigned char *src, int src_x, int src_y,
561 int stride, int x, int y, int width, int height)
562{
563 int shift, ny;
564 fb_remote_data *dst, *dst_end;
565 unsigned data, mask, mask_bottom;
566 lcd_remote_blockfunc_type *bfunc;
567
568 /* nothing to draw? */
569 if ((width <= 0) || (height <= 0) || (x >= LCD_REMOTE_WIDTH)
570 || (y >= LCD_REMOTE_HEIGHT) || (x + width <= 0) || (y + height <= 0))
571 return;
572
573 /* clipping */
574 if (x < 0)
575 {
576 width += x;
577 src_x -= x;
578 x = 0;
579 }
580 if (y < 0)
581 {
582 height += y;
583 src_y -= y;
584 y = 0;
585 }
586 if (x + width > LCD_REMOTE_WIDTH)
587 width = LCD_REMOTE_WIDTH - x;
588 if (y + height > LCD_REMOTE_HEIGHT)
589 height = LCD_REMOTE_HEIGHT - y;
590
591 src += stride * (src_y >> 3) + src_x; /* move starting point */
592 src_y &= 7;
593 y -= src_y;
594 dst = &lcd_remote_framebuffer[y>>3][x];
595 shift = y & 7;
596 ny = height - 1 + shift + src_y;
597
598 bfunc = lcd_remote_blockfuncs[drawmode];
599 mask = 0xFFu << (shift + src_y);
600 /* not byte-doubled here because shift+src_y can be > 7 */
601 mask_bottom = 0xFFu >> (~ny & 7);
602 mask_bottom |= mask_bottom << 8;
603
604 if (shift == 0)
605 {
606 mask &= 0xFFu;
607 mask |= mask << 8;
608
609 for (; ny >= 8; ny -= 8)
610 {
611 const unsigned char *src_row = src;
612 fb_remote_data *dst_row = dst;
613
614 dst_end = dst_row + width;
615 do
616 {
617 data = *src_row++;
618 bfunc(dst_row++, mask, data | (data << 8));
619 }
620 while (dst_row < dst_end);
621
622 src += stride;
623 dst += LCD_REMOTE_WIDTH;
624 mask = 0xFFFFu;
625 }
626 mask &= mask_bottom;
627
628 dst_end = dst + width;
629 do
630 {
631 data = *src++;
632 bfunc(dst++, mask, data | (data << 8));
633 }
634 while (dst < dst_end);
635 }
636 else
637 {
638 unsigned ddata;
639
640 dst_end = dst + width;
641 do
642 {
643 const unsigned char *src_col = src++;
644 fb_remote_data *dst_col = dst++;
645 unsigned mask_col = mask & 0xFFu;
646
647 mask_col |= mask_col << 8;
648 data = 0;
649
650 for (y = ny; y >= 8; y -= 8)
651 {
652 data |= *src_col << shift;
653
654 if (mask_col)
655 {
656 ddata = data & 0xFFu;
657 bfunc(dst_col, mask_col, ddata | (ddata << 8));
658 mask_col = 0xFFFFu;
659 }
660 else
661 {
662 mask_col = (mask >> 8) & 0xFFu;
663 mask_col |= mask_col << 8;
664 }
665
666 src_col += stride;
667 dst_col += LCD_REMOTE_WIDTH;
668 data >>= 8;
669 }
670 data |= *src_col << shift;
671 mask_col &= mask_bottom;
672 ddata = data & 0xFFu;
673 bfunc(dst_col, mask_col, ddata | (ddata << 8));
674 }
675 while (dst < dst_end);
676 }
677}
678
679/* Draw a full monochrome bitmap */
680void lcd_remote_mono_bitmap(const unsigned char *src, int x, int y, int width,
681 int height)
682{
683 lcd_remote_mono_bitmap_part(src, 0, 0, width, x, y, width, height);
684}
685
686/* About Rockbox' internal native bitmap format:
687 *
688 * A bitmap contains one bit in each byte of a pair of bytes for every pixel.
689 * 00 = white, 01 = light grey, 10 = dark grey, 11 = black. Bits within a byte
690 * are arranged vertically, LSB at top.
691 * The pairs of bytes are stored as shorts, in row-major order, with word 0
692 * being top left, word 1 2nd from left etc. The first row of words defines
693 * pixel rows 0..7, the second row defines pixel row 8..15 etc.
694 *
695 * This is the same as the internal lcd hw format. */
696
697/* Draw a partial native bitmap */
698void lcd_remote_bitmap_part(const fb_remote_data *src, int src_x, int src_y,
699 int stride, int x, int y, int width, int height)
700 ICODE_ATTR;
701void lcd_remote_bitmap_part(const fb_remote_data *src, int src_x, int src_y,
702 int stride, int x, int y, int width, int height)
703{
704 int shift, ny;
705 fb_remote_data *dst, *dst_end;
706 unsigned mask, mask_bottom;
707
708 /* nothing to draw? */
709 if ((width <= 0) || (height <= 0) || (x >= LCD_REMOTE_WIDTH)
710 || (y >= LCD_REMOTE_HEIGHT) || (x + width <= 0) || (y + height <= 0))
711 return;
712
713 /* clipping */
714 if (x < 0)
715 {
716 width += x;
717 src_x -= x;
718 x = 0;
719 }
720 if (y < 0)
721 {
722 height += y;
723 src_y -= y;
724 y = 0;
725 }
726 if (x + width > LCD_REMOTE_WIDTH)
727 width = LCD_REMOTE_WIDTH - x;
728 if (y + height > LCD_REMOTE_HEIGHT)
729 height = LCD_REMOTE_HEIGHT - y;
730
731 src += stride * (src_y >> 3) + src_x; /* move starting point */
732 src_y &= 7;
733 y -= src_y;
734 dst = &lcd_remote_framebuffer[y>>3][x];
735 shift = y & 7;
736 ny = height - 1 + shift + src_y;
737
738 mask = 0xFFu << (shift + src_y);
739 /* not byte-doubled here because shift+src_y can be > 7 */
740 mask_bottom = 0xFFu >> (~ny & 7);
741 mask_bottom |= mask_bottom << 8;
742
743 if (shift == 0)
744 {
745 mask &= 0xFFu;
746 mask |= mask << 8;
747
748 for (; ny >= 8; ny -= 8)
749 {
750 if (mask == 0xFFFFu)
751 memcpy(dst, src, width * sizeof(fb_remote_data));
752 else
753 {
754 const fb_remote_data *src_row = src;
755 fb_remote_data *dst_row = dst;
756
757 dst_end = dst_row + width;
758 do
759 setblock(dst_row++, mask, *src_row++);
760 while (dst_row < dst_end);
761 }
762 src += stride;
763 dst += LCD_REMOTE_WIDTH;
764 mask = 0xFFFFu;
765 }
766 mask &= mask_bottom;
767
768 if (mask == 0xFFFFu)
769 memcpy(dst, src, width * sizeof(fb_remote_data));
770 else
771 {
772 dst_end = dst + width;
773 do
774 setblock(dst++, mask, *src++);
775 while (dst < dst_end);
776 }
777 }
778 else
779 {
780 unsigned datamask = (0xFFu << shift) & 0xFFu;
781
782 datamask |= datamask << 8;
783
784 dst_end = dst + width;
785 do
786 {
787 const fb_remote_data *src_col = src++;
788 fb_remote_data *dst_col = dst++;
789 unsigned mask_col = mask & 0xFFu;
790 unsigned data, olddata = 0;
791
792 mask_col |= mask_col << 8;
793
794 for (y = ny; y >= 8; y -= 8)
795 {
796 data = *src_col << shift;
797
798 if (mask_col)
799 {
800 setblock(dst_col, mask_col,
801 olddata ^((olddata ^ data) & datamask));
802 mask_col = 0xFFFFu;
803 }
804 else
805 {
806 mask_col = (mask << 8) & 0xFFu;
807 mask_col |= mask_col << 8;
808 }
809 src_col += stride;
810 dst_col += LCD_REMOTE_WIDTH;
811 olddata = data >> 8;
812 }
813 data = *src_col << shift;
814 setblock(dst_col, mask_col & mask_bottom,
815 olddata ^((olddata ^ data) & datamask));
816 }
817 while (dst < dst_end);
818 }
819}
820
821/* Draw a full native bitmap */
822void lcd_remote_bitmap(const fb_remote_data *src, int x, int y, int width,
823 int height)
824{
825 lcd_remote_bitmap_part(src, 0, 0, width, x, y, width, height);
826}
827
828/* put a string at a given pixel position, skipping first ofs pixel columns */
829static void lcd_remote_putsxyofs(int x, int y, int ofs, const unsigned char *str)
830{
831 unsigned short ch;
832 unsigned short *ucs;
833 struct font* pf = font_get(curfont);
834
835 ucs = bidi_l2v(str, 1);
836
837 while ((ch = *ucs++) != 0 && x < LCD_REMOTE_WIDTH)
838 {
839 int width;
840 const unsigned char *bits;
841
842 /* get proportional width and glyph bits */
843 width = font_get_width(pf, ch);
844
845 if (ofs > width)
846 {
847 ofs -= width;
848 continue;
849 }
850
851 bits = font_get_bits(pf, ch);
852
853 lcd_remote_mono_bitmap_part(bits, ofs, 0, width, x, y, width - ofs,
854 pf->height);
855
856 x += width - ofs;
857 ofs = 0;
858 }
859}
860
861/* put a string at a given pixel position */
862void lcd_remote_putsxy(int x, int y, const unsigned char *str)
863{
864 lcd_remote_putsxyofs(x, y, 0, str);
865}
866
867/*** line oriented text output ***/
868
869/* put a string at a given char position */
870void lcd_remote_puts(int x, int y, const unsigned char *str)
871{
872 lcd_remote_puts_style_offset(x, y, str, STYLE_DEFAULT, 0);
873}
874
875void lcd_remote_puts_style(int x, int y, const unsigned char *str, int style)
876{
877 lcd_remote_puts_style_offset(x, y, str, style, 0);
878}
879
880void lcd_remote_puts_offset(int x, int y, const unsigned char *str, int offset)
881{
882 lcd_remote_puts_style_offset(x, y, str, STYLE_DEFAULT, offset);
883}
884
885/* put a string at a given char position, style, and pixel position,
886 * skipping first offset pixel columns */
887void lcd_remote_puts_style_offset(int x, int y, const unsigned char *str,
888 int style, int offset)
889{
890 int xpos,ypos,w,h,xrect;
891 int lastmode = drawmode;
892
893 /* make sure scrolling is turned off on the line we are updating */
894 scrolling_lines &= ~(1 << y);
895
896 if(!str || !str[0])
897 return;
898
899 lcd_remote_getstringsize(str, &w, &h);
900 xpos = xmargin + x*w / utf8length((char *)str);
901 ypos = ymargin + y*h;
902 drawmode = (style & STYLE_INVERT) ?
903 (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID;
904 lcd_remote_putsxyofs(xpos, ypos, offset, str);
905 drawmode ^= DRMODE_INVERSEVID;
906 xrect = xpos + MAX(w - offset, 0);
907 lcd_remote_fillrect(xrect, ypos, LCD_REMOTE_WIDTH - xrect, h);
908 drawmode = lastmode;
909}
910
911/*** scrolling ***/
912
913/* Reverse the invert setting of the scrolling line (if any) at given char
914 position. Setting will go into affect next time line scrolls. */
915void lcd_remote_invertscroll(int x, int y)
916{
917 struct scrollinfo* s;
918
919 (void)x;
920
921 s = &scroll[y];
922 s->invert = !s->invert;
923}
924
925void lcd_remote_stop_scroll(void)
926{
927 scrolling_lines=0;
928}
929
930void lcd_remote_scroll_speed(int speed)
931{
932 scroll_ticks = scroll_tick_table[speed];
933}
934
935void lcd_remote_scroll_step(int step)
936{
937 scroll_step = step;
938}
939
940void lcd_remote_scroll_delay(int ms)
941{
942 scroll_delay = ms / (HZ / 10);
943}
944
945void lcd_remote_bidir_scroll(int percent)
946{
947 bidir_limit = percent;
948}
949
950void lcd_remote_puts_scroll(int x, int y, const unsigned char *string)
951{
952 lcd_remote_puts_scroll_style(x, y, string, STYLE_DEFAULT);
953}
954
955void lcd_remote_puts_scroll_style(int x, int y, const unsigned char *string, int style)
956{
957 lcd_remote_puts_scroll_style_offset(x, y, string, style, 0);
958}
959
960void lcd_remote_puts_scroll_offset(int x, int y, const unsigned char *string, int offset)
961{
962 lcd_remote_puts_scroll_style_offset(x, y, string, STYLE_DEFAULT, offset);
963}
964
965void lcd_remote_puts_scroll_style_offset(int x, int y, const unsigned char *string,
966 int style, int offset)
967{
968 struct scrollinfo* s;
969 int w, h;
970
971 s = &scroll[y];
972
973 s->start_tick = current_tick + scroll_delay;
974 s->invert = false;
975 if (style & STYLE_INVERT) {
976 s->invert = true;
977 lcd_remote_puts_style_offset(x,y,string,STYLE_INVERT,offset);
978 }
979 else
980 lcd_remote_puts_offset(x,y,string,offset);
981
982 lcd_remote_getstringsize(string, &w, &h);
983
984 if (LCD_REMOTE_WIDTH - x * 8 - xmargin < w) {
985 /* prepare scroll line */
986 char *end;
987
988 memset(s->line, 0, sizeof s->line);
989 strcpy(s->line, (char *)string);
990
991 /* get width */
992 s->width = lcd_remote_getstringsize((unsigned char *)s->line, &w, &h);
993
994 /* scroll bidirectional or forward only depending on the string
995 width */
996 if ( bidir_limit ) {
997 s->bidir = s->width < (LCD_REMOTE_WIDTH - xmargin) *
998 (100 + bidir_limit) / 100;
999 }
1000 else
1001 s->bidir = false;
1002
1003 if (!s->bidir) { /* add spaces if scrolling in the round */
1004 strcat(s->line, " ");
1005 /* get new width incl. spaces */
1006 s->width = lcd_remote_getstringsize((unsigned char *)s->line, &w, &h);
1007 }
1008
1009 end = strchr(s->line, '\0');
1010 strncpy(end, (char *)string, LCD_REMOTE_WIDTH/2);
1011
1012 s->len = utf8length((char *)string);
1013 s->offset = offset;
1014 s->startx = x;
1015 s->backward = false;
1016 scrolling_lines |= (1<<y);
1017 }
1018 else
1019 /* force a bit switch-off since it doesn't scroll */
1020 scrolling_lines &= ~(1<<y);
1021}
1022
1023static void scroll_thread(void)
1024{
1025 struct font* pf;
1026 struct scrollinfo* s;
1027 int index;
1028 int xpos, ypos;
1029 int lastmode;
1030
1031 /* initialize scroll struct array */
1032 scrolling_lines = 0;
1033
1034 while ( 1 ) {
1035 for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
1036 /* really scroll? */
1037 if ( !(scrolling_lines&(1<<index)) )
1038 continue;
1039
1040 s = &scroll[index];
1041
1042 /* check pause */
1043 if (TIME_BEFORE(current_tick, s->start_tick))
1044 continue;
1045
1046 if (s->backward)
1047 s->offset -= scroll_step;
1048 else
1049 s->offset += scroll_step;
1050
1051 pf = font_get(curfont);
1052 xpos = xmargin + s->startx * s->width / s->len;
1053 ypos = ymargin + index * pf->height;
1054
1055 if (s->bidir) { /* scroll bidirectional */
1056 if (s->offset <= 0) {
1057 /* at beginning of line */
1058 s->offset = 0;
1059 s->backward = false;
1060 s->start_tick = current_tick + scroll_delay * 2;
1061 }
1062 if (s->offset >= s->width - (LCD_REMOTE_WIDTH - xpos)) {
1063 /* at end of line */
1064 s->offset = s->width - (LCD_REMOTE_WIDTH - xpos);
1065 s->backward = true;
1066 s->start_tick = current_tick + scroll_delay * 2;
1067 }
1068 }
1069 else {
1070 /* scroll forward the whole time */
1071 if (s->offset >= s->width)
1072 s->offset %= s->width;
1073 }
1074
1075 lastmode = drawmode;
1076 drawmode = s->invert ?
1077 (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID;
1078 lcd_remote_putsxyofs(xpos, ypos, s->offset, s->line);
1079 drawmode = lastmode;
1080 lcd_remote_update_rect(xpos, ypos, LCD_REMOTE_WIDTH - xpos, pf->height);
1081 }
1082
1083 sleep(scroll_ticks);
1084 }
1085}