1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 Jens Arnold
12 * Rockbox driver for 2bit vertically interleaved LCDs
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
34 #include "rbunicode.h"
36 #include "scroll_engine.h"
38 #ifndef LCDFN /* Not compiling for remote - define macros for main LCD. */
39 #define LCDFN(fn) lcd_ ## fn
40 #define FBFN(fn) fb_ ## fn
41 #define LCDM(ma) LCD_ ## ma
42 #define LCDNAME "lcd_"
48 FBFN(data
) LCDFN(framebuffer
)[LCDM(FBHEIGHT
)][LCDM(FBWIDTH
)] IBSS_ATTR
;
50 static const FBFN(data
) patterns
[4] = {0xFFFF, 0xFF00, 0x00FF, 0x0000};
52 static FBFN(data
) *backdrop
= NULL
;
53 static long backdrop_offset IDATA_ATTR
= 0;
55 static struct viewport default_vp
=
60 .height
= LCDM(HEIGHT
),
61 .font
= FONT_SYSFIXED
,
62 .drawmode
= DRMODE_SOLID
,
65 .fg_pattern
= LCDM(DEFAULT_FG
),
66 .bg_pattern
= LCDM(DEFAULT_BG
)
69 static struct viewport
*current_vp IBSS_ATTR
;
71 static unsigned fg_pattern IBSS_ATTR
;
72 static unsigned bg_pattern IBSS_ATTR
;
76 void LCDFN(set_viewport
)(struct viewport
* vp
)
79 current_vp
= &default_vp
;
83 fg_pattern
= patterns
[current_vp
->fg_pattern
& 3];
84 bg_pattern
= patterns
[current_vp
->bg_pattern
& 3];
87 void LCDFN(update_viewport
)(void)
89 LCDFN(update_rect
)(current_vp
->x
, current_vp
->y
,
90 current_vp
->width
, current_vp
->height
);
93 void LCDFN(update_viewport_rect
)(int x
, int y
, int width
, int height
)
95 LCDFN(update_rect
)(current_vp
->x
+ x
, current_vp
->y
+ y
, width
, height
);
99 void LCDFN(init
)(void)
101 LCDFN(set_viewport
)(NULL
);
102 LCDFN(clear_display
)();
104 LCDFN(init_device
)();
111 /*** parameter handling ***/
113 #if !defined(MAIN_LCD) && defined(HAVE_LCD_COLOR)
114 /* When compiling for remote LCD and the main LCD is colour. */
115 unsigned lcd_remote_color_to_native(unsigned color
)
117 unsigned r
= (color
& 0xf800) >> 10;
118 unsigned g
= (color
& 0x07e0) >> 5;
119 unsigned b
= (color
& 0x001f) << 2;
122 * |Y'| = |0.299000 0.587000 0.114000| |G|
125 return (5*r
+ 9*g
+ b
) >> 8;
129 void LCDFN(set_drawmode
)(int mode
)
131 current_vp
->drawmode
= mode
& (DRMODE_SOLID
|DRMODE_INVERSEVID
);
134 int LCDFN(get_drawmode
)(void)
136 return current_vp
->drawmode
;
139 void LCDFN(set_foreground
)(unsigned brightness
)
141 current_vp
->fg_pattern
= brightness
;
142 fg_pattern
= patterns
[brightness
& 3];
145 unsigned LCDFN(get_foreground
)(void)
147 return current_vp
->fg_pattern
;
150 void LCDFN(set_background
)(unsigned brightness
)
152 current_vp
->bg_pattern
= brightness
;
153 bg_pattern
= patterns
[brightness
& 3];
156 unsigned LCDFN(get_background
)(void)
158 return current_vp
->bg_pattern
;
161 void LCDFN(set_drawinfo
)(int mode
, unsigned fg_brightness
,
162 unsigned bg_brightness
)
164 LCDFN(set_drawmode
)(mode
);
165 LCDFN(set_foreground
)(fg_brightness
);
166 LCDFN(set_background
)(bg_brightness
);
169 int LCDFN(getwidth
)(void)
171 return current_vp
->width
;
174 int LCDFN(getheight
)(void)
176 return current_vp
->height
;
179 void LCDFN(setmargins
)(int x
, int y
)
181 current_vp
->xmargin
= x
;
182 current_vp
->ymargin
= y
;
185 int LCDFN(getxmargin
)(void)
187 return current_vp
->xmargin
;
190 int LCDFN(getymargin
)(void)
192 return current_vp
->ymargin
;
195 void LCDFN(setfont
)(int newfont
)
197 current_vp
->font
= newfont
;
200 int LCDFN(getfont
)(void)
202 return current_vp
->font
;
205 int LCDFN(getstringsize
)(const unsigned char *str
, int *w
, int *h
)
207 return font_getstringsize(str
, w
, h
, current_vp
->font
);
210 /*** low-level drawing functions ***/
212 static void setpixel(int x
, int y
)
214 unsigned mask
= 0x0101 << (y
& 7);
215 FBFN(data
) *address
= &LCDFN(framebuffer
)[y
>>3][x
];
216 unsigned data
= *address
;
218 *address
= data
^ ((data
^ fg_pattern
) & mask
);
221 static void clearpixel(int x
, int y
)
223 unsigned mask
= 0x0101 << (y
& 7);
224 FBFN(data
) *address
= &LCDFN(framebuffer
)[y
>>3][x
];
225 unsigned data
= *address
;
227 *address
= data
^ ((data
^ bg_pattern
) & mask
);
230 static void clearimgpixel(int x
, int y
)
232 unsigned mask
= 0x0101 << (y
& 7);
233 FBFN(data
) *address
= &LCDFN(framebuffer
)[y
>>3][x
];
234 unsigned data
= *address
;
236 *address
= data
^ ((data
^ *(FBFN(data
) *)((long)address
237 + backdrop_offset
)) & mask
);
240 static void flippixel(int x
, int y
)
242 unsigned mask
= 0x0101 << (y
& 7);
243 FBFN(data
) *address
= &LCDFN(framebuffer
)[y
>>3][x
];
248 static void nopixel(int x
, int y
)
254 LCDFN(pixelfunc_type
)* const LCDFN(pixelfuncs_bgcolor
)[8] = {
255 flippixel
, nopixel
, setpixel
, setpixel
,
256 nopixel
, clearpixel
, nopixel
, clearpixel
259 LCDFN(pixelfunc_type
)* const LCDFN(pixelfuncs_backdrop
)[8] = {
260 flippixel
, nopixel
, setpixel
, setpixel
,
261 nopixel
, clearimgpixel
, nopixel
, clearimgpixel
264 LCDFN(pixelfunc_type
)* const *LCDFN(pixelfuncs
) = LCDFN(pixelfuncs_bgcolor
);
266 /* 'mask' and 'bits' contain 2 bits per pixel */
267 static void ICODE_ATTR
flipblock(FBFN(data
) *address
, unsigned mask
,
270 *address
^= bits
& mask
;
273 static void ICODE_ATTR
bgblock(FBFN(data
) *address
, unsigned mask
,
276 unsigned data
= *address
;
278 *address
= data
^ ((data
^ bg_pattern
) & mask
& ~bits
);
281 static void ICODE_ATTR
bgimgblock(FBFN(data
) *address
, unsigned mask
,
284 unsigned data
= *address
;
286 *address
= data
^ ((data
^ *(FBFN(data
) *)((long)address
287 + backdrop_offset
)) & mask
& ~bits
);
290 static void ICODE_ATTR
fgblock(FBFN(data
) *address
, unsigned mask
,
293 unsigned data
= *address
;
295 *address
= data
^ ((data
^ fg_pattern
) & mask
& bits
);
298 static void ICODE_ATTR
solidblock(FBFN(data
) *address
, unsigned mask
,
301 unsigned data
= *address
;
302 unsigned bgp
= bg_pattern
;
304 bits
= bgp
^ ((bgp
^ fg_pattern
) & bits
);
305 *address
= data
^ ((data
^ bits
) & mask
);
308 static void ICODE_ATTR
solidimgblock(FBFN(data
) *address
, unsigned mask
,
311 unsigned data
= *address
;
312 unsigned bgp
= *(FBFN(data
) *)((long)address
+ backdrop_offset
);
314 bits
= bgp
^ ((bgp
^ fg_pattern
) & bits
);
315 *address
= data
^ ((data
^ bits
) & mask
);
318 static void ICODE_ATTR
flipinvblock(FBFN(data
) *address
, unsigned mask
,
321 *address
^= ~bits
& mask
;
324 static void ICODE_ATTR
bginvblock(FBFN(data
) *address
, unsigned mask
,
327 unsigned data
= *address
;
329 *address
= data
^ ((data
^ bg_pattern
) & mask
& bits
);
332 static void ICODE_ATTR
bgimginvblock(FBFN(data
) *address
, unsigned mask
,
335 unsigned data
= *address
;
337 *address
= data
^ ((data
^ *(FBFN(data
) *)((long)address
338 + backdrop_offset
)) & mask
& bits
);
341 static void ICODE_ATTR
fginvblock(FBFN(data
) *address
, unsigned mask
,
344 unsigned data
= *address
;
346 *address
= data
^ ((data
^ fg_pattern
) & mask
& ~bits
);
349 static void ICODE_ATTR
solidinvblock(FBFN(data
) *address
, unsigned mask
,
352 unsigned data
= *address
;
353 unsigned fgp
= fg_pattern
;
355 bits
= fgp
^ ((fgp
^ bg_pattern
) & bits
);
356 *address
= data
^ ((data
^ bits
) & mask
);
359 static void ICODE_ATTR
solidimginvblock(FBFN(data
) *address
, unsigned mask
,
362 unsigned data
= *address
;
363 unsigned fgp
= fg_pattern
;
365 bits
= fgp
^ ((fgp
^ *(FBFN(data
) *)((long)address
366 + backdrop_offset
)) & bits
);
367 *address
= data
^ ((data
^ bits
) & mask
);
370 LCDFN(blockfunc_type
)* const LCDFN(blockfuncs_bgcolor
)[8] = {
371 flipblock
, bgblock
, fgblock
, solidblock
,
372 flipinvblock
, bginvblock
, fginvblock
, solidinvblock
375 LCDFN(blockfunc_type
)* const LCDFN(blockfuncs_backdrop
)[8] = {
376 flipblock
, bgimgblock
, fgblock
, solidimgblock
,
377 flipinvblock
, bgimginvblock
, fginvblock
, solidimginvblock
380 LCDFN(blockfunc_type
)* const *LCDFN(blockfuncs
) = LCDFN(blockfuncs_bgcolor
);
383 void LCDFN(set_backdrop
)(FBFN(data
) *bd
)
388 backdrop_offset
= (long)bd
- (long)LCDFN(framebuffer
);
389 LCDFN(pixelfuncs
) = LCDFN(pixelfuncs_backdrop
);
390 LCDFN(blockfuncs
) = LCDFN(blockfuncs_backdrop
);
395 LCDFN(pixelfuncs
) = LCDFN(pixelfuncs_bgcolor
);
396 LCDFN(blockfuncs
) = LCDFN(blockfuncs_bgcolor
);
400 FBFN(data
)* LCDFN(get_backdrop
)(void)
405 static inline void setblock(FBFN(data
) *address
, unsigned mask
, unsigned bits
)
407 unsigned data
= *address
;
410 *address
= data
^ (bits
& mask
);
413 /*** drawing functions ***/
415 /* Clear the whole display */
416 void LCDFN(clear_display
)(void)
418 if (default_vp
.drawmode
& DRMODE_INVERSEVID
)
420 memset(LCDFN(framebuffer
), patterns
[default_vp
.fg_pattern
& 3],
421 sizeof LCDFN(framebuffer
));
426 memcpy(LCDFN(framebuffer
), backdrop
, sizeof LCDFN(framebuffer
));
428 memset(LCDFN(framebuffer
), patterns
[default_vp
.bg_pattern
& 3],
429 sizeof LCDFN(framebuffer
));
432 LCDFN(scroll_info
).lines
= 0;
435 /* Clear the current viewport */
436 void LCDFN(clear_viewport
)(void)
440 if (current_vp
== &default_vp
)
442 LCDFN(clear_display
)();
446 lastmode
= current_vp
->drawmode
;
448 /* Invert the INVERSEVID bit and set basic mode to SOLID */
449 current_vp
->drawmode
= (~lastmode
& DRMODE_INVERSEVID
) |
452 LCDFN(fillrect
)(0, 0, current_vp
->width
, current_vp
->height
);
454 current_vp
->drawmode
= lastmode
;
456 LCDFN(scroll_stop
)(current_vp
);
460 /* Set a single pixel */
461 void LCDFN(drawpixel
)(int x
, int y
)
463 if (((unsigned)x
< (unsigned)current_vp
->width
) &&
464 ((unsigned)y
< (unsigned)current_vp
->height
))
465 LCDFN(pixelfuncs
)[current_vp
->drawmode
](current_vp
->x
+x
, current_vp
->y
+y
);
469 void LCDFN(drawline
)(int x1
, int y1
, int x2
, int y2
)
477 LCDFN(pixelfunc_type
) *pfunc
= LCDFN(pixelfuncs
)[current_vp
->drawmode
];
479 deltax
= abs(x2
- x1
);
482 DEBUGF(LCDNAME
"drawline() called for vertical line - optimisation.\n");
483 LCDFN(vline
)(x1
, y1
, y2
);
486 deltay
= abs(y2
- y1
);
489 DEBUGF(LCDNAME
"drawline() called for horizontal line - optimisation.\n");
490 LCDFN(hline
)(x1
, x2
, y1
);
496 if (deltax
>= deltay
)
499 d
= 2 * deltay
- deltax
;
501 dinc2
= (deltay
- deltax
) * 2;
508 d
= 2 * deltax
- deltay
;
510 dinc2
= (deltax
- deltay
) * 2;
514 numpixels
++; /* include endpoints */
531 for (i
= 0; i
< numpixels
; i
++)
533 if (((unsigned)x
< (unsigned)current_vp
->width
) &&
534 ((unsigned)y
< (unsigned)current_vp
->height
))
535 pfunc(current_vp
->x
+ x
, current_vp
->y
+ y
);
552 /* Draw a horizontal line (optimised) */
553 void LCDFN(hline
)(int x1
, int x2
, int y
)
557 FBFN(data
) *dst
, *dst_end
;
559 LCDFN(blockfunc_type
) *bfunc
;
569 /* nothing to draw? */
570 if (((unsigned)y
>= (unsigned)current_vp
->height
) || (x1
>= current_vp
->width
)
577 if (x2
>= current_vp
->width
)
578 x2
= current_vp
->width
-1;
582 /* adjust x1 and y to viewport */
586 bfunc
= LCDFN(blockfuncs
)[current_vp
->drawmode
];
587 dst
= &LCDFN(framebuffer
)[y
>>3][x1
];
588 mask
= 0x0101 << (y
& 7);
590 dst_end
= dst
+ width
;
592 bfunc(dst
++, mask
, 0xFFFFu
);
593 while (dst
< dst_end
);
596 /* Draw a vertical line (optimised) */
597 void LCDFN(vline
)(int x
, int y1
, int y2
)
601 unsigned mask
, mask_bottom
;
602 LCDFN(blockfunc_type
) *bfunc
;
612 /* nothing to draw? */
613 if (((unsigned)x
>= (unsigned)current_vp
->width
) || (y1
>= current_vp
->height
)
620 if (y2
>= current_vp
->height
)
621 y2
= current_vp
->height
-1;
623 /* adjust for viewport */
628 bfunc
= LCDFN(blockfuncs
)[current_vp
->drawmode
];
629 dst
= &LCDFN(framebuffer
)[y1
>>3][x
];
631 mask
= (0xFFu
<< (y1
& 7)) & 0xFFu
;
633 mask_bottom
= 0xFFu
>> (~ny
& 7);
634 mask_bottom
|= mask_bottom
<< 8;
636 for (; ny
>= 8; ny
-= 8)
638 bfunc(dst
, mask
, 0xFFFFu
);
643 bfunc(dst
, mask
, 0xFFFFu
);
646 /* Draw a rectangular box */
647 void LCDFN(drawrect
)(int x
, int y
, int width
, int height
)
649 if ((width
<= 0) || (height
<= 0))
652 int x2
= x
+ width
- 1;
653 int y2
= y
+ height
- 1;
655 LCDFN(vline
)(x
, y
, y2
);
656 LCDFN(vline
)(x2
, y
, y2
);
657 LCDFN(hline
)(x
, x2
, y
);
658 LCDFN(hline
)(x
, x2
, y2
);
661 /* Fill a rectangular area */
662 void LCDFN(fillrect
)(int x
, int y
, int width
, int height
)
665 FBFN(data
) *dst
, *dst_end
;
666 unsigned mask
, mask_bottom
;
668 LCDFN(blockfunc_type
) *bfunc
;
669 bool fillopt
= false;
671 /* nothing to draw? */
672 if ((width
<= 0) || (height
<= 0) || (x
>= current_vp
->width
)
673 || (y
>= current_vp
->height
) || (x
+ width
<= 0) || (y
+ height
<= 0))
687 if (x
+ width
> current_vp
->width
)
688 width
= current_vp
->width
- x
;
689 if (y
+ height
> current_vp
->height
)
690 height
= current_vp
->height
- y
;
692 /* adjust for viewport */
696 if (current_vp
->drawmode
& DRMODE_INVERSEVID
)
698 if ((current_vp
->drawmode
& DRMODE_BG
) && !backdrop
)
706 if (current_vp
->drawmode
& DRMODE_FG
)
712 bfunc
= LCDFN(blockfuncs
)[current_vp
->drawmode
];
713 dst
= &LCDFN(framebuffer
)[y
>>3][x
];
714 ny
= height
- 1 + (y
& 7);
715 mask
= (0xFFu
<< (y
& 7)) & 0xFFu
;
717 mask_bottom
= 0xFFu
>> (~ny
& 7);
718 mask_bottom
|= mask_bottom
<< 8;
720 for (; ny
>= 8; ny
-= 8)
722 if (fillopt
&& (mask
== 0xFFFFu
))
723 memset16(dst
, bits
, width
);
726 FBFN(data
) *dst_row
= dst
;
728 dst_end
= dst_row
+ width
;
730 bfunc(dst_row
++, mask
, 0xFFFFu
);
731 while (dst_row
< dst_end
);
739 if (fillopt
&& (mask
== 0xFFFFu
))
740 memset16(dst
, bits
, width
);
743 dst_end
= dst
+ width
;
745 bfunc(dst
++, mask
, 0xFFFFu
);
746 while (dst
< dst_end
);
750 /* About Rockbox' internal monochrome bitmap format:
752 * A bitmap contains one bit for every pixel that defines if that pixel is
753 * black (1) or white (0). Bits within a byte are arranged vertically, LSB
755 * The bytes are stored in row-major order, with byte 0 being top left,
756 * byte 1 2nd from left etc. The first row of bytes defines pixel rows
757 * 0..7, the second row defines pixel row 8..15 etc.
759 * This is similar to the internal lcd hw format. */
761 /* Draw a partial monochrome bitmap */
762 void ICODE_ATTR
LCDFN(mono_bitmap_part
)(const unsigned char *src
, int src_x
,
763 int src_y
, int stride
, int x
, int y
,
764 int width
, int height
)
767 FBFN(data
) *dst
, *dst_end
;
768 unsigned data
, mask
, mask_bottom
;
769 LCDFN(blockfunc_type
) *bfunc
;
771 /* nothing to draw? */
772 if ((width
<= 0) || (height
<= 0) || (x
>= current_vp
->width
) ||
773 (y
>= current_vp
->height
) || (x
+ width
<= 0) || (y
+ height
<= 0))
789 if (x
+ width
> current_vp
->width
)
790 width
= current_vp
->width
- x
;
791 if (y
+ height
> current_vp
->height
)
792 height
= current_vp
->height
- y
;
794 /* adjust for viewport */
798 src
+= stride
* (src_y
>> 3) + src_x
; /* move starting point */
801 dst
= &LCDFN(framebuffer
)[y
>>3][x
];
803 ny
= height
- 1 + shift
+ src_y
;
805 bfunc
= LCDFN(blockfuncs
)[current_vp
->drawmode
];
806 mask
= 0xFFu
<< (shift
+ src_y
);
807 /* not byte-doubled here because shift+src_y can be > 7 */
808 mask_bottom
= 0xFFu
>> (~ny
& 7);
809 mask_bottom
|= mask_bottom
<< 8;
816 for (; ny
>= 8; ny
-= 8)
818 const unsigned char *src_row
= src
;
819 FBFN(data
) *dst_row
= dst
;
821 dst_end
= dst_row
+ width
;
825 bfunc(dst_row
++, mask
, data
| (data
<< 8));
827 while (dst_row
< dst_end
);
835 dst_end
= dst
+ width
;
839 bfunc(dst
++, mask
, data
| (data
<< 8));
841 while (dst
< dst_end
);
847 dst_end
= dst
+ width
;
850 const unsigned char *src_col
= src
++;
851 FBFN(data
) *dst_col
= dst
++;
852 unsigned mask_col
= mask
& 0xFFu
;
854 mask_col
|= mask_col
<< 8;
857 for (y
= ny
; y
>= 8; y
-= 8)
859 data
|= *src_col
<< shift
;
863 ddata
= data
& 0xFFu
;
864 bfunc(dst_col
, mask_col
, ddata
| (ddata
<< 8));
869 mask_col
= (mask
>> 8) & 0xFFu
;
870 mask_col
|= mask_col
<< 8;
874 dst_col
+= LCDM(WIDTH
);
877 data
|= *src_col
<< shift
;
878 mask_col
&= mask_bottom
;
879 ddata
= data
& 0xFFu
;
880 bfunc(dst_col
, mask_col
, ddata
| (ddata
<< 8));
882 while (dst
< dst_end
);
886 /* Draw a full monochrome bitmap */
887 void LCDFN(mono_bitmap
)(const unsigned char *src
, int x
, int y
, int width
,
890 LCDFN(mono_bitmap_part
)(src
, 0, 0, width
, x
, y
, width
, height
);
893 /* About Rockbox' internal native bitmap format:
895 * A bitmap contains one bit in each byte of a pair of bytes for every pixel.
896 * 00 = white, 01 = light grey, 10 = dark grey, 11 = black. Bits within a byte
897 * are arranged vertically, LSB at top.
898 * The pairs of bytes are stored as shorts, in row-major order, with word 0
899 * being top left, word 1 2nd from left etc. The first row of words defines
900 * pixel rows 0..7, the second row defines pixel row 8..15 etc.
902 * This is the same as the internal lcd hw format. */
904 /* Draw a partial native bitmap */
905 void ICODE_ATTR
LCDFN(bitmap_part
)(const FBFN(data
) *src
, int src_x
,
906 int src_y
, int stride
, int x
, int y
,
907 int width
, int height
)
910 FBFN(data
) *dst
, *dst_end
;
911 unsigned mask
, mask_bottom
;
913 /* nothing to draw? */
914 if ((width
<= 0) || (height
<= 0) || (x
>= current_vp
->width
)
915 || (y
>= current_vp
->height
) || (x
+ width
<= 0) || (y
+ height
<= 0))
931 if (x
+ width
> current_vp
->width
)
932 width
= current_vp
->width
- x
;
933 if (y
+ height
> current_vp
->height
)
934 height
= current_vp
->height
- y
;
936 /* adjust for viewport */
940 src
+= stride
* (src_y
>> 3) + src_x
; /* move starting point */
943 dst
= &LCDFN(framebuffer
)[y
>>3][x
];
945 ny
= height
- 1 + shift
+ src_y
;
947 mask
= 0xFFu
<< (shift
+ src_y
);
948 /* not byte-doubled here because shift+src_y can be > 7 */
949 mask_bottom
= 0xFFu
>> (~ny
& 7);
950 mask_bottom
|= mask_bottom
<< 8;
957 for (; ny
>= 8; ny
-= 8)
960 memcpy(dst
, src
, width
* sizeof(FBFN(data
)));
963 const FBFN(data
) *src_row
= src
;
964 FBFN(data
) *dst_row
= dst
;
966 dst_end
= dst_row
+ width
;
968 setblock(dst_row
++, mask
, *src_row
++);
969 while (dst_row
< dst_end
);
978 memcpy(dst
, src
, width
* sizeof(FBFN(data
)));
981 dst_end
= dst
+ width
;
983 setblock(dst
++, mask
, *src
++);
984 while (dst
< dst_end
);
989 unsigned datamask
= (0xFFu
<< shift
) & 0xFFu
;
991 datamask
|= datamask
<< 8;
993 dst_end
= dst
+ width
;
996 const FBFN(data
) *src_col
= src
++;
997 FBFN(data
) *dst_col
= dst
++;
998 unsigned mask_col
= mask
& 0xFFu
;
999 unsigned data
, olddata
= 0;
1001 mask_col
|= mask_col
<< 8;
1003 for (y
= ny
; y
>= 8; y
-= 8)
1005 data
= *src_col
<< shift
;
1009 setblock(dst_col
, mask_col
,
1010 olddata
^((olddata
^ data
) & datamask
));
1015 mask_col
= (mask
>> 8) & 0xFFu
;
1016 mask_col
|= mask_col
<< 8;
1019 dst_col
+= LCDM(WIDTH
);
1020 olddata
= data
>> 8;
1022 data
= *src_col
<< shift
;
1023 setblock(dst_col
, mask_col
& mask_bottom
,
1024 olddata
^((olddata
^ data
) & datamask
));
1026 while (dst
< dst_end
);
1030 /* Draw a full native bitmap */
1031 void LCDFN(bitmap
)(const FBFN(data
) *src
, int x
, int y
, int width
, int height
)
1033 LCDFN(bitmap_part
)(src
, 0, 0, width
, x
, y
, width
, height
);
1036 /* put a string at a given pixel position, skipping first ofs pixel columns */
1037 static void LCDFN(putsxyofs
)(int x
, int y
, int ofs
, const unsigned char *str
)
1040 unsigned short *ucs
;
1041 struct font
* pf
= font_get(current_vp
->font
);
1043 ucs
= bidi_l2v(str
, 1);
1045 while ((ch
= *ucs
++) != 0 && x
< current_vp
->width
)
1048 const unsigned char *bits
;
1050 /* get proportional width and glyph bits */
1051 width
= font_get_width(pf
, ch
);
1059 bits
= font_get_bits(pf
, ch
);
1061 LCDFN(mono_bitmap_part
)(bits
, ofs
, 0, width
, x
, y
, width
- ofs
,
1069 /* put a string at a given pixel position */
1070 void LCDFN(putsxy
)(int x
, int y
, const unsigned char *str
)
1072 LCDFN(putsxyofs
)(x
, y
, 0, str
);
1075 /*** line oriented text output ***/
1077 /* put a string at a given char position */
1078 void LCDFN(puts
)(int x
, int y
, const unsigned char *str
)
1080 LCDFN(puts_style_offset
)(x
, y
, str
, STYLE_DEFAULT
, 0);
1083 void LCDFN(puts_style
)(int x
, int y
, const unsigned char *str
, int style
)
1085 LCDFN(puts_style_offset
)(x
, y
, str
, style
, 0);
1088 void LCDFN(puts_offset
)(int x
, int y
, const unsigned char *str
, int offset
)
1090 LCDFN(puts_style_offset
)(x
, y
, str
, STYLE_DEFAULT
, offset
);
1093 /* put a string at a given char position, style, and pixel position,
1094 * skipping first offset pixel columns */
1095 void LCDFN(puts_style_offset
)(int x
, int y
, const unsigned char *str
,
1096 int style
, int offset
)
1098 int xpos
,ypos
,w
,h
,xrect
;
1099 int lastmode
= current_vp
->drawmode
;
1101 /* make sure scrolling is turned off on the line we are updating */
1102 LCDFN(scroll_stop_line
)(current_vp
, y
);
1107 LCDFN(getstringsize
)(str
, &w
, &h
);
1108 xpos
= current_vp
->xmargin
+ x
*w
/ utf8length((char *)str
);
1109 ypos
= current_vp
->ymargin
+ y
*h
;
1110 current_vp
->drawmode
= (style
& STYLE_INVERT
) ?
1111 (DRMODE_SOLID
|DRMODE_INVERSEVID
) : DRMODE_SOLID
;
1112 LCDFN(putsxyofs
)(xpos
, ypos
, offset
, str
);
1113 current_vp
->drawmode
^= DRMODE_INVERSEVID
;
1114 xrect
= xpos
+ MAX(w
- offset
, 0);
1115 LCDFN(fillrect
)(xrect
, ypos
, current_vp
->width
- xrect
, h
);
1116 current_vp
->drawmode
= lastmode
;
1120 void LCDFN(puts_scroll
)(int x
, int y
, const unsigned char *string
)
1122 LCDFN(puts_scroll_style
)(x
, y
, string
, STYLE_DEFAULT
);
1125 void LCDFN(puts_scroll_style
)(int x
, int y
, const unsigned char *string
, int style
)
1127 LCDFN(puts_scroll_style_offset
)(x
, y
, string
, style
, 0);
1130 void LCDFN(puts_scroll_offset
)(int x
, int y
, const unsigned char *string
, int offset
)
1132 LCDFN(puts_scroll_style_offset
)(x
, y
, string
, STYLE_DEFAULT
, offset
);
1135 void LCDFN(puts_scroll_style_offset
)(int x
, int y
, const unsigned char *string
,
1136 int style
, int offset
)
1138 struct scrollinfo
* s
;
1141 if ((unsigned)y
>= (unsigned)current_vp
->height
)
1144 /* remove any previously scrolling line at the same location */
1145 LCDFN(scroll_stop_line
)(current_vp
, y
);
1147 if (LCDFN(scroll_info
).lines
>= LCDM(SCROLLABLE_LINES
)) return;
1149 s
= &LCDFN(scroll_info
).scroll
[LCDFN(scroll_info
).lines
];
1151 s
->start_tick
= current_tick
+ LCDFN(scroll_info
).delay
;
1153 if (style
& STYLE_INVERT
) {
1154 LCDFN(puts_style_offset
)(x
,y
,string
,STYLE_INVERT
,offset
);
1157 LCDFN(puts_offset
)(x
,y
,string
,offset
);
1159 LCDFN(getstringsize
)(string
, &w
, &h
);
1161 if (current_vp
->width
- x
* 8 - current_vp
->xmargin
< w
) {
1162 /* prepare scroll line */
1165 memset(s
->line
, 0, sizeof s
->line
);
1166 strcpy(s
->line
, string
);
1169 s
->width
= LCDFN(getstringsize
)(s
->line
, &w
, &h
);
1171 /* scroll bidirectional or forward only depending on the string
1173 if ( LCDFN(scroll_info
).bidir_limit
) {
1174 s
->bidir
= s
->width
< (current_vp
->width
- current_vp
->xmargin
) *
1175 (100 + LCDFN(scroll_info
).bidir_limit
) / 100;
1180 if (!s
->bidir
) { /* add spaces if scrolling in the round */
1181 strcat(s
->line
, " ");
1182 /* get new width incl. spaces */
1183 s
->width
= LCDFN(getstringsize
)(s
->line
, &w
, &h
);
1186 end
= strchr(s
->line
, '\0');
1187 strncpy(end
, (char *)string
, current_vp
->width
/2);
1191 s
->len
= utf8length((char *)string
);
1193 s
->startx
= current_vp
->xmargin
+ x
* s
->width
/ s
->len
;
1194 s
->backward
= false;
1196 LCDFN(scroll_info
).lines
++;
1200 void LCDFN(scroll_fn
)(void)
1203 struct scrollinfo
* s
;
1207 struct viewport
* old_vp
= current_vp
;
1209 for ( index
= 0; index
< LCDFN(scroll_info
).lines
; index
++ ) {
1210 s
= &LCDFN(scroll_info
).scroll
[index
];
1213 if (TIME_BEFORE(current_tick
, s
->start_tick
))
1216 LCDFN(set_viewport
)(s
->vp
);
1219 s
->offset
-= LCDFN(scroll_info
).step
;
1221 s
->offset
+= LCDFN(scroll_info
).step
;
1223 pf
= font_get(current_vp
->font
);
1225 ypos
= current_vp
->ymargin
+ s
->y
* pf
->height
;
1227 if (s
->bidir
) { /* scroll bidirectional */
1228 if (s
->offset
<= 0) {
1229 /* at beginning of line */
1231 s
->backward
= false;
1232 s
->start_tick
= current_tick
+ LCDFN(scroll_info
).delay
* 2;
1234 if (s
->offset
>= s
->width
- (current_vp
->width
- xpos
)) {
1235 /* at end of line */
1236 s
->offset
= s
->width
- (current_vp
->width
- xpos
);
1238 s
->start_tick
= current_tick
+ LCDFN(scroll_info
).delay
* 2;
1242 /* scroll forward the whole time */
1243 if (s
->offset
>= s
->width
)
1244 s
->offset
%= s
->width
;
1247 lastmode
= current_vp
->drawmode
;
1248 current_vp
->drawmode
= (s
->style
&STYLE_INVERT
) ?
1249 (DRMODE_SOLID
|DRMODE_INVERSEVID
) : DRMODE_SOLID
;
1250 LCDFN(putsxyofs
)(xpos
, ypos
, s
->offset
, s
->line
);
1251 current_vp
->drawmode
= lastmode
;
1252 LCDFN(update_viewport_rect
)(xpos
, ypos
,
1253 current_vp
->width
- xpos
, pf
->height
);
1256 LCDFN(set_viewport
)(old_vp
);