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
47 FBFN(data
) LCDFN(framebuffer
)[LCDM(FBHEIGHT
)][LCDM(FBWIDTH
)] IBSS_ATTR
;
49 static const FBFN(data
) patterns
[4] = {0xFFFF, 0xFF00, 0x00FF, 0x0000};
51 static FBFN(data
) *backdrop
= NULL
;
52 static long backdrop_offset IDATA_ATTR
= 0;
54 static struct viewport default_vp
=
59 .height
= LCDM(HEIGHT
),
60 .font
= FONT_SYSFIXED
,
61 .drawmode
= DRMODE_SOLID
,
64 .fg_pattern
= LCDM(DEFAULT_FG
),
65 .bg_pattern
= LCDM(DEFAULT_BG
)
68 static struct viewport IDATA_ATTR
*current_vp
= &default_vp
;
70 static unsigned fg_pattern IBSS_ATTR
;
71 static unsigned bg_pattern IBSS_ATTR
;
75 void LCDFN(set_viewport
)(struct viewport
* vp
)
78 current_vp
= &default_vp
;
82 fg_pattern
= patterns
[current_vp
->fg_pattern
& 3];
83 bg_pattern
= patterns
[current_vp
->bg_pattern
& 3];
86 void LCDFN(update_viewport
)(void)
88 LCDFN(update_rect
)(current_vp
->x
, current_vp
->y
,
89 current_vp
->width
, current_vp
->height
);
92 void LCDFN(update_viewport_rect
)(int x
, int y
, int width
, int height
)
94 LCDFN(update_rect
)(current_vp
->x
+ x
, current_vp
->y
+ y
, width
, height
);
98 void LCDFN(init
)(void)
100 LCDFN(clear_display
)();
102 LCDFN(init_device
)();
109 /*** parameter handling ***/
111 #if !defined(MAIN_LCD) && defined(HAVE_LCD_COLOR)
112 /* When compiling for remote LCD and the main LCD is colour. */
113 unsigned lcd_remote_color_to_native(unsigned color
)
115 unsigned r
= (color
& 0xf800) >> 10;
116 unsigned g
= (color
& 0x07e0) >> 5;
117 unsigned b
= (color
& 0x001f) << 2;
120 * |Y'| = |0.299000 0.587000 0.114000| |G|
123 return (5*r
+ 9*g
+ b
) >> 8;
127 void LCDFN(set_drawmode
)(int mode
)
129 current_vp
->drawmode
= mode
& (DRMODE_SOLID
|DRMODE_INVERSEVID
);
132 int LCDFN(get_drawmode
)(void)
134 return current_vp
->drawmode
;
137 void LCDFN(set_foreground
)(unsigned brightness
)
139 current_vp
->fg_pattern
= brightness
;
140 fg_pattern
= patterns
[brightness
& 3];
143 unsigned LCDFN(get_foreground
)(void)
145 return current_vp
->fg_pattern
;
148 void LCDFN(set_background
)(unsigned brightness
)
150 current_vp
->bg_pattern
= brightness
;
151 bg_pattern
= patterns
[brightness
& 3];
154 unsigned LCDFN(get_background
)(void)
156 return current_vp
->bg_pattern
;
159 void LCDFN(set_drawinfo
)(int mode
, unsigned fg_brightness
,
160 unsigned bg_brightness
)
162 LCDFN(set_drawmode
)(mode
);
163 LCDFN(set_foreground
)(fg_brightness
);
164 LCDFN(set_background
)(bg_brightness
);
167 int LCDFN(getwidth
)(void)
169 return current_vp
->width
;
172 int LCDFN(getheight
)(void)
174 return current_vp
->height
;
177 void LCDFN(setmargins
)(int x
, int y
)
179 current_vp
->xmargin
= x
;
180 current_vp
->ymargin
= y
;
183 int LCDFN(getxmargin
)(void)
185 return current_vp
->xmargin
;
188 int LCDFN(getymargin
)(void)
190 return current_vp
->ymargin
;
193 void LCDFN(setfont
)(int newfont
)
195 current_vp
->font
= newfont
;
198 int LCDFN(getfont
)(void)
200 return current_vp
->font
;
203 int LCDFN(getstringsize
)(const unsigned char *str
, int *w
, int *h
)
205 return font_getstringsize(str
, w
, h
, current_vp
->font
);
208 /*** low-level drawing functions ***/
210 static void setpixel(int x
, int y
)
212 unsigned mask
= 0x0101 << (y
& 7);
213 FBFN(data
) *address
= &LCDFN(framebuffer
)[y
>>3][x
];
214 unsigned data
= *address
;
216 *address
= data
^ ((data
^ fg_pattern
) & mask
);
219 static void clearpixel(int x
, int y
)
221 unsigned mask
= 0x0101 << (y
& 7);
222 FBFN(data
) *address
= &LCDFN(framebuffer
)[y
>>3][x
];
223 unsigned data
= *address
;
225 *address
= data
^ ((data
^ bg_pattern
) & mask
);
228 static void clearimgpixel(int x
, int y
)
230 unsigned mask
= 0x0101 << (y
& 7);
231 FBFN(data
) *address
= &LCDFN(framebuffer
)[y
>>3][x
];
232 unsigned data
= *address
;
234 *address
= data
^ ((data
^ *(FBFN(data
) *)((long)address
235 + backdrop_offset
)) & mask
);
238 static void flippixel(int x
, int y
)
240 unsigned mask
= 0x0101 << (y
& 7);
241 FBFN(data
) *address
= &LCDFN(framebuffer
)[y
>>3][x
];
246 static void nopixel(int x
, int y
)
252 LCDFN(pixelfunc_type
)* const LCDFN(pixelfuncs_bgcolor
)[8] = {
253 flippixel
, nopixel
, setpixel
, setpixel
,
254 nopixel
, clearpixel
, nopixel
, clearpixel
257 LCDFN(pixelfunc_type
)* const LCDFN(pixelfuncs_backdrop
)[8] = {
258 flippixel
, nopixel
, setpixel
, setpixel
,
259 nopixel
, clearimgpixel
, nopixel
, clearimgpixel
262 LCDFN(pixelfunc_type
)* const *LCDFN(pixelfuncs
) = LCDFN(pixelfuncs_bgcolor
);
264 /* 'mask' and 'bits' contain 2 bits per pixel */
265 static void ICODE_ATTR
flipblock(FBFN(data
) *address
, unsigned mask
,
268 *address
^= bits
& mask
;
271 static void ICODE_ATTR
bgblock(FBFN(data
) *address
, unsigned mask
,
274 unsigned data
= *address
;
276 *address
= data
^ ((data
^ bg_pattern
) & mask
& ~bits
);
279 static void ICODE_ATTR
bgimgblock(FBFN(data
) *address
, unsigned mask
,
282 unsigned data
= *address
;
284 *address
= data
^ ((data
^ *(FBFN(data
) *)((long)address
285 + backdrop_offset
)) & mask
& ~bits
);
288 static void ICODE_ATTR
fgblock(FBFN(data
) *address
, unsigned mask
,
291 unsigned data
= *address
;
293 *address
= data
^ ((data
^ fg_pattern
) & mask
& bits
);
296 static void ICODE_ATTR
solidblock(FBFN(data
) *address
, unsigned mask
,
299 unsigned data
= *address
;
300 unsigned bgp
= bg_pattern
;
302 bits
= bgp
^ ((bgp
^ fg_pattern
) & bits
);
303 *address
= data
^ ((data
^ bits
) & mask
);
306 static void ICODE_ATTR
solidimgblock(FBFN(data
) *address
, unsigned mask
,
309 unsigned data
= *address
;
310 unsigned bgp
= *(FBFN(data
) *)((long)address
+ backdrop_offset
);
312 bits
= bgp
^ ((bgp
^ fg_pattern
) & bits
);
313 *address
= data
^ ((data
^ bits
) & mask
);
316 static void ICODE_ATTR
flipinvblock(FBFN(data
) *address
, unsigned mask
,
319 *address
^= ~bits
& mask
;
322 static void ICODE_ATTR
bginvblock(FBFN(data
) *address
, unsigned mask
,
325 unsigned data
= *address
;
327 *address
= data
^ ((data
^ bg_pattern
) & mask
& bits
);
330 static void ICODE_ATTR
bgimginvblock(FBFN(data
) *address
, unsigned mask
,
333 unsigned data
= *address
;
335 *address
= data
^ ((data
^ *(FBFN(data
) *)((long)address
336 + backdrop_offset
)) & mask
& bits
);
339 static void ICODE_ATTR
fginvblock(FBFN(data
) *address
, unsigned mask
,
342 unsigned data
= *address
;
344 *address
= data
^ ((data
^ fg_pattern
) & mask
& ~bits
);
347 static void ICODE_ATTR
solidinvblock(FBFN(data
) *address
, unsigned mask
,
350 unsigned data
= *address
;
351 unsigned fgp
= fg_pattern
;
353 bits
= fgp
^ ((fgp
^ bg_pattern
) & bits
);
354 *address
= data
^ ((data
^ bits
) & mask
);
357 static void ICODE_ATTR
solidimginvblock(FBFN(data
) *address
, unsigned mask
,
360 unsigned data
= *address
;
361 unsigned fgp
= fg_pattern
;
363 bits
= fgp
^ ((fgp
^ *(FBFN(data
) *)((long)address
364 + backdrop_offset
)) & bits
);
365 *address
= data
^ ((data
^ bits
) & mask
);
368 LCDFN(blockfunc_type
)* const LCDFN(blockfuncs_bgcolor
)[8] = {
369 flipblock
, bgblock
, fgblock
, solidblock
,
370 flipinvblock
, bginvblock
, fginvblock
, solidinvblock
373 LCDFN(blockfunc_type
)* const LCDFN(blockfuncs_backdrop
)[8] = {
374 flipblock
, bgimgblock
, fgblock
, solidimgblock
,
375 flipinvblock
, bgimginvblock
, fginvblock
, solidimginvblock
378 LCDFN(blockfunc_type
)* const *LCDFN(blockfuncs
) = LCDFN(blockfuncs_bgcolor
);
381 void LCDFN(set_backdrop
)(FBFN(data
) *bd
)
386 backdrop_offset
= (long)bd
- (long)LCDFN(framebuffer
);
387 LCDFN(pixelfuncs
) = LCDFN(pixelfuncs_backdrop
);
388 LCDFN(blockfuncs
) = LCDFN(blockfuncs_backdrop
);
393 LCDFN(pixelfuncs
) = LCDFN(pixelfuncs_bgcolor
);
394 LCDFN(blockfuncs
) = LCDFN(blockfuncs_bgcolor
);
398 FBFN(data
)* LCDFN(get_backdrop
)(void)
403 static inline void setblock(FBFN(data
) *address
, unsigned mask
, unsigned bits
)
405 unsigned data
= *address
;
408 *address
= data
^ (bits
& mask
);
411 /*** drawing functions ***/
413 /* Clear the whole display */
414 void LCDFN(clear_display
)(void)
416 if (default_vp
.drawmode
& DRMODE_INVERSEVID
)
418 memset(LCDFN(framebuffer
), patterns
[default_vp
.fg_pattern
& 3],
419 sizeof LCDFN(framebuffer
));
424 memcpy(LCDFN(framebuffer
), backdrop
, sizeof LCDFN(framebuffer
));
426 memset(LCDFN(framebuffer
), patterns
[default_vp
.bg_pattern
& 3],
427 sizeof LCDFN(framebuffer
));
430 LCDFN(scroll_info
).lines
= 0;
433 /* Clear the current viewport */
434 void LCDFN(clear_viewport
)(void)
438 if (current_vp
== &default_vp
)
440 LCDFN(clear_display
)();
444 lastmode
= current_vp
->drawmode
;
446 /* Invert the INVERSEVID bit and set basic mode to SOLID */
447 current_vp
->drawmode
= (~lastmode
& DRMODE_INVERSEVID
) |
450 LCDFN(fillrect
)(0, 0, current_vp
->width
, current_vp
->height
);
452 current_vp
->drawmode
= lastmode
;
454 LCDFN(scroll_stop
)(current_vp
);
458 /* Set a single pixel */
459 void LCDFN(drawpixel
)(int x
, int y
)
461 if (((unsigned)x
< (unsigned)current_vp
->width
) &&
462 ((unsigned)y
< (unsigned)current_vp
->height
))
463 LCDFN(pixelfuncs
)[current_vp
->drawmode
](current_vp
->x
+x
, current_vp
->y
+y
);
467 void LCDFN(drawline
)(int x1
, int y1
, int x2
, int y2
)
475 LCDFN(pixelfunc_type
) *pfunc
= LCDFN(pixelfuncs
)[current_vp
->drawmode
];
477 deltax
= abs(x2
- x1
);
478 deltay
= abs(y2
- y1
);
482 if (deltax
>= deltay
)
485 d
= 2 * deltay
- deltax
;
487 dinc2
= (deltay
- deltax
) * 2;
494 d
= 2 * deltax
- deltay
;
496 dinc2
= (deltax
- deltay
) * 2;
500 numpixels
++; /* include endpoints */
517 for (i
= 0; i
< numpixels
; i
++)
519 if (((unsigned)x
< (unsigned)current_vp
->width
) &&
520 ((unsigned)y
< (unsigned)current_vp
->height
))
521 pfunc(current_vp
->x
+ x
, current_vp
->y
+ y
);
538 /* Draw a horizontal line (optimised) */
539 void LCDFN(hline
)(int x1
, int x2
, int y
)
543 FBFN(data
) *dst
, *dst_end
;
545 LCDFN(blockfunc_type
) *bfunc
;
555 /* nothing to draw? */
556 if (((unsigned)y
>= (unsigned)current_vp
->height
) || (x1
>= current_vp
->width
)
563 if (x2
>= current_vp
->width
)
564 x2
= current_vp
->width
-1;
568 /* adjust x1 and y to viewport */
572 bfunc
= LCDFN(blockfuncs
)[current_vp
->drawmode
];
573 dst
= &LCDFN(framebuffer
)[y
>>3][x1
];
574 mask
= 0x0101 << (y
& 7);
576 dst_end
= dst
+ width
;
578 bfunc(dst
++, mask
, 0xFFFFu
);
579 while (dst
< dst_end
);
582 /* Draw a vertical line (optimised) */
583 void LCDFN(vline
)(int x
, int y1
, int y2
)
587 unsigned mask
, mask_bottom
;
588 LCDFN(blockfunc_type
) *bfunc
;
598 /* nothing to draw? */
599 if (((unsigned)x
>= (unsigned)current_vp
->width
) || (y1
>= current_vp
->height
)
606 if (y2
>= current_vp
->height
)
607 y2
= current_vp
->height
-1;
609 /* adjust for viewport */
614 bfunc
= LCDFN(blockfuncs
)[current_vp
->drawmode
];
615 dst
= &LCDFN(framebuffer
)[y1
>>3][x
];
617 mask
= (0xFFu
<< (y1
& 7)) & 0xFFu
;
619 mask_bottom
= 0xFFu
>> (~ny
& 7);
620 mask_bottom
|= mask_bottom
<< 8;
622 for (; ny
>= 8; ny
-= 8)
624 bfunc(dst
, mask
, 0xFFFFu
);
629 bfunc(dst
, mask
, 0xFFFFu
);
632 /* Draw a rectangular box */
633 void LCDFN(drawrect
)(int x
, int y
, int width
, int height
)
635 if ((width
<= 0) || (height
<= 0))
638 int x2
= x
+ width
- 1;
639 int y2
= y
+ height
- 1;
641 LCDFN(vline
)(x
, y
, y2
);
642 LCDFN(vline
)(x2
, y
, y2
);
643 LCDFN(hline
)(x
, x2
, y
);
644 LCDFN(hline
)(x
, x2
, y2
);
647 /* Fill a rectangular area */
648 void LCDFN(fillrect
)(int x
, int y
, int width
, int height
)
651 FBFN(data
) *dst
, *dst_end
;
652 unsigned mask
, mask_bottom
;
654 LCDFN(blockfunc_type
) *bfunc
;
655 bool fillopt
= false;
657 /* nothing to draw? */
658 if ((width
<= 0) || (height
<= 0) || (x
>= current_vp
->width
)
659 || (y
>= current_vp
->height
) || (x
+ width
<= 0) || (y
+ height
<= 0))
673 if (x
+ width
> current_vp
->width
)
674 width
= current_vp
->width
- x
;
675 if (y
+ height
> current_vp
->height
)
676 height
= current_vp
->height
- y
;
678 /* adjust for viewport */
682 if (current_vp
->drawmode
& DRMODE_INVERSEVID
)
684 if ((current_vp
->drawmode
& DRMODE_BG
) && !backdrop
)
692 if (current_vp
->drawmode
& DRMODE_FG
)
698 bfunc
= LCDFN(blockfuncs
)[current_vp
->drawmode
];
699 dst
= &LCDFN(framebuffer
)[y
>>3][x
];
700 ny
= height
- 1 + (y
& 7);
701 mask
= (0xFFu
<< (y
& 7)) & 0xFFu
;
703 mask_bottom
= 0xFFu
>> (~ny
& 7);
704 mask_bottom
|= mask_bottom
<< 8;
706 for (; ny
>= 8; ny
-= 8)
708 if (fillopt
&& (mask
== 0xFFFFu
))
709 memset16(dst
, bits
, width
);
712 FBFN(data
) *dst_row
= dst
;
714 dst_end
= dst_row
+ width
;
716 bfunc(dst_row
++, mask
, 0xFFFFu
);
717 while (dst_row
< dst_end
);
725 if (fillopt
&& (mask
== 0xFFFFu
))
726 memset16(dst
, bits
, width
);
729 dst_end
= dst
+ width
;
731 bfunc(dst
++, mask
, 0xFFFFu
);
732 while (dst
< dst_end
);
736 /* About Rockbox' internal monochrome bitmap format:
738 * A bitmap contains one bit for every pixel that defines if that pixel is
739 * black (1) or white (0). Bits within a byte are arranged vertically, LSB
741 * The bytes are stored in row-major order, with byte 0 being top left,
742 * byte 1 2nd from left etc. The first row of bytes defines pixel rows
743 * 0..7, the second row defines pixel row 8..15 etc.
745 * This is similar to the internal lcd hw format. */
747 /* Draw a partial monochrome bitmap */
748 void ICODE_ATTR
LCDFN(mono_bitmap_part
)(const unsigned char *src
, int src_x
,
749 int src_y
, int stride
, int x
, int y
,
750 int width
, int height
)
753 FBFN(data
) *dst
, *dst_end
;
754 unsigned data
, mask
, mask_bottom
;
755 LCDFN(blockfunc_type
) *bfunc
;
757 /* nothing to draw? */
758 if ((width
<= 0) || (height
<= 0) || (x
>= current_vp
->width
) ||
759 (y
>= current_vp
->height
) || (x
+ width
<= 0) || (y
+ height
<= 0))
775 if (x
+ width
> current_vp
->width
)
776 width
= current_vp
->width
- x
;
777 if (y
+ height
> current_vp
->height
)
778 height
= current_vp
->height
- y
;
780 /* adjust for viewport */
784 src
+= stride
* (src_y
>> 3) + src_x
; /* move starting point */
787 dst
= &LCDFN(framebuffer
)[y
>>3][x
];
789 ny
= height
- 1 + shift
+ src_y
;
791 bfunc
= LCDFN(blockfuncs
)[current_vp
->drawmode
];
792 mask
= 0xFFu
<< (shift
+ src_y
);
793 /* not byte-doubled here because shift+src_y can be > 7 */
794 mask_bottom
= 0xFFu
>> (~ny
& 7);
795 mask_bottom
|= mask_bottom
<< 8;
802 for (; ny
>= 8; ny
-= 8)
804 const unsigned char *src_row
= src
;
805 FBFN(data
) *dst_row
= dst
;
807 dst_end
= dst_row
+ width
;
811 bfunc(dst_row
++, mask
, data
| (data
<< 8));
813 while (dst_row
< dst_end
);
821 dst_end
= dst
+ width
;
825 bfunc(dst
++, mask
, data
| (data
<< 8));
827 while (dst
< dst_end
);
833 dst_end
= dst
+ width
;
836 const unsigned char *src_col
= src
++;
837 FBFN(data
) *dst_col
= dst
++;
838 unsigned mask_col
= mask
& 0xFFu
;
840 mask_col
|= mask_col
<< 8;
843 for (y
= ny
; y
>= 8; y
-= 8)
845 data
|= *src_col
<< shift
;
849 ddata
= data
& 0xFFu
;
850 bfunc(dst_col
, mask_col
, ddata
| (ddata
<< 8));
855 mask_col
= (mask
>> 8) & 0xFFu
;
856 mask_col
|= mask_col
<< 8;
860 dst_col
+= LCDM(WIDTH
);
863 data
|= *src_col
<< shift
;
864 mask_col
&= mask_bottom
;
865 ddata
= data
& 0xFFu
;
866 bfunc(dst_col
, mask_col
, ddata
| (ddata
<< 8));
868 while (dst
< dst_end
);
872 /* Draw a full monochrome bitmap */
873 void LCDFN(mono_bitmap
)(const unsigned char *src
, int x
, int y
, int width
,
876 LCDFN(mono_bitmap_part
)(src
, 0, 0, width
, x
, y
, width
, height
);
879 /* About Rockbox' internal native bitmap format:
881 * A bitmap contains one bit in each byte of a pair of bytes for every pixel.
882 * 00 = white, 01 = light grey, 10 = dark grey, 11 = black. Bits within a byte
883 * are arranged vertically, LSB at top.
884 * The pairs of bytes are stored as shorts, in row-major order, with word 0
885 * being top left, word 1 2nd from left etc. The first row of words defines
886 * pixel rows 0..7, the second row defines pixel row 8..15 etc.
888 * This is the same as the internal lcd hw format. */
890 /* Draw a partial native bitmap */
891 void ICODE_ATTR
LCDFN(bitmap_part
)(const FBFN(data
) *src
, int src_x
,
892 int src_y
, int stride
, int x
, int y
,
893 int width
, int height
)
896 FBFN(data
) *dst
, *dst_end
;
897 unsigned mask
, mask_bottom
;
899 /* nothing to draw? */
900 if ((width
<= 0) || (height
<= 0) || (x
>= current_vp
->width
)
901 || (y
>= current_vp
->height
) || (x
+ width
<= 0) || (y
+ height
<= 0))
917 if (x
+ width
> current_vp
->width
)
918 width
= current_vp
->width
- x
;
919 if (y
+ height
> current_vp
->height
)
920 height
= current_vp
->height
- y
;
922 /* adjust for viewport */
926 src
+= stride
* (src_y
>> 3) + src_x
; /* move starting point */
929 dst
= &LCDFN(framebuffer
)[y
>>3][x
];
931 ny
= height
- 1 + shift
+ src_y
;
933 mask
= 0xFFu
<< (shift
+ src_y
);
934 /* not byte-doubled here because shift+src_y can be > 7 */
935 mask_bottom
= 0xFFu
>> (~ny
& 7);
936 mask_bottom
|= mask_bottom
<< 8;
943 for (; ny
>= 8; ny
-= 8)
946 memcpy(dst
, src
, width
* sizeof(FBFN(data
)));
949 const FBFN(data
) *src_row
= src
;
950 FBFN(data
) *dst_row
= dst
;
952 dst_end
= dst_row
+ width
;
954 setblock(dst_row
++, mask
, *src_row
++);
955 while (dst_row
< dst_end
);
964 memcpy(dst
, src
, width
* sizeof(FBFN(data
)));
967 dst_end
= dst
+ width
;
969 setblock(dst
++, mask
, *src
++);
970 while (dst
< dst_end
);
975 unsigned datamask
= (0xFFu
<< shift
) & 0xFFu
;
977 datamask
|= datamask
<< 8;
979 dst_end
= dst
+ width
;
982 const FBFN(data
) *src_col
= src
++;
983 FBFN(data
) *dst_col
= dst
++;
984 unsigned mask_col
= mask
& 0xFFu
;
985 unsigned data
, olddata
= 0;
987 mask_col
|= mask_col
<< 8;
989 for (y
= ny
; y
>= 8; y
-= 8)
991 data
= *src_col
<< shift
;
995 setblock(dst_col
, mask_col
,
996 olddata
^((olddata
^ data
) & datamask
));
1001 mask_col
= (mask
<< 8) & 0xFFu
;
1002 mask_col
|= mask_col
<< 8;
1005 dst_col
+= LCDM(WIDTH
);
1006 olddata
= data
>> 8;
1008 data
= *src_col
<< shift
;
1009 setblock(dst_col
, mask_col
& mask_bottom
,
1010 olddata
^((olddata
^ data
) & datamask
));
1012 while (dst
< dst_end
);
1016 /* Draw a full native bitmap */
1017 void LCDFN(bitmap
)(const FBFN(data
) *src
, int x
, int y
, int width
, int height
)
1019 LCDFN(bitmap_part
)(src
, 0, 0, width
, x
, y
, width
, height
);
1022 /* put a string at a given pixel position, skipping first ofs pixel columns */
1023 static void LCDFN(putsxyofs
)(int x
, int y
, int ofs
, const unsigned char *str
)
1026 unsigned short *ucs
;
1027 struct font
* pf
= font_get(current_vp
->font
);
1029 ucs
= bidi_l2v(str
, 1);
1031 while ((ch
= *ucs
++) != 0 && x
< current_vp
->width
)
1034 const unsigned char *bits
;
1036 /* get proportional width and glyph bits */
1037 width
= font_get_width(pf
, ch
);
1045 bits
= font_get_bits(pf
, ch
);
1047 LCDFN(mono_bitmap_part
)(bits
, ofs
, 0, width
, x
, y
, width
- ofs
,
1055 /* put a string at a given pixel position */
1056 void LCDFN(putsxy
)(int x
, int y
, const unsigned char *str
)
1058 LCDFN(putsxyofs
)(x
, y
, 0, str
);
1061 /*** line oriented text output ***/
1063 /* put a string at a given char position */
1064 void LCDFN(puts
)(int x
, int y
, const unsigned char *str
)
1066 LCDFN(puts_style_offset
)(x
, y
, str
, STYLE_DEFAULT
, 0);
1069 void LCDFN(puts_style
)(int x
, int y
, const unsigned char *str
, int style
)
1071 LCDFN(puts_style_offset
)(x
, y
, str
, style
, 0);
1074 void LCDFN(puts_offset
)(int x
, int y
, const unsigned char *str
, int offset
)
1076 LCDFN(puts_style_offset
)(x
, y
, str
, STYLE_DEFAULT
, offset
);
1079 /* put a string at a given char position, style, and pixel position,
1080 * skipping first offset pixel columns */
1081 void LCDFN(puts_style_offset
)(int x
, int y
, const unsigned char *str
,
1082 int style
, int offset
)
1084 int xpos
,ypos
,w
,h
,xrect
;
1085 int lastmode
= current_vp
->drawmode
;
1087 /* make sure scrolling is turned off on the line we are updating */
1088 LCDFN(scroll_stop_line
)(current_vp
, y
);
1093 LCDFN(getstringsize
)(str
, &w
, &h
);
1094 xpos
= current_vp
->xmargin
+ x
*w
/ utf8length((char *)str
);
1095 ypos
= current_vp
->ymargin
+ y
*h
;
1096 current_vp
->drawmode
= (style
& STYLE_INVERT
) ?
1097 (DRMODE_SOLID
|DRMODE_INVERSEVID
) : DRMODE_SOLID
;
1098 LCDFN(putsxyofs
)(xpos
, ypos
, offset
, str
);
1099 current_vp
->drawmode
^= DRMODE_INVERSEVID
;
1100 xrect
= xpos
+ MAX(w
- offset
, 0);
1101 LCDFN(fillrect
)(xrect
, ypos
, current_vp
->width
- xrect
, h
);
1102 current_vp
->drawmode
= lastmode
;
1106 void LCDFN(puts_scroll
)(int x
, int y
, const unsigned char *string
)
1108 LCDFN(puts_scroll_style
)(x
, y
, string
, STYLE_DEFAULT
);
1111 void LCDFN(puts_scroll_style
)(int x
, int y
, const unsigned char *string
, int style
)
1113 LCDFN(puts_scroll_style_offset
)(x
, y
, string
, style
, 0);
1116 void LCDFN(puts_scroll_offset
)(int x
, int y
, const unsigned char *string
, int offset
)
1118 LCDFN(puts_scroll_style_offset
)(x
, y
, string
, STYLE_DEFAULT
, offset
);
1121 void LCDFN(puts_scroll_style_offset
)(int x
, int y
, const unsigned char *string
,
1122 int style
, int offset
)
1124 struct scrollinfo
* s
;
1127 if ((unsigned)y
>= (unsigned)current_vp
->height
)
1130 /* remove any previously scrolling line at the same location */
1131 LCDFN(scroll_stop_line
)(current_vp
, y
);
1133 if (LCDFN(scroll_info
).lines
>= LCDM(SCROLLABLE_LINES
)) return;
1135 s
= &LCDFN(scroll_info
).scroll
[LCDFN(scroll_info
).lines
];
1137 s
->start_tick
= current_tick
+ LCDFN(scroll_info
).delay
;
1139 if (style
& STYLE_INVERT
) {
1140 LCDFN(puts_style_offset
)(x
,y
,string
,STYLE_INVERT
,offset
);
1143 LCDFN(puts_offset
)(x
,y
,string
,offset
);
1145 LCDFN(getstringsize
)(string
, &w
, &h
);
1147 if (current_vp
->width
- x
* 8 - current_vp
->xmargin
< w
) {
1148 /* prepare scroll line */
1151 memset(s
->line
, 0, sizeof s
->line
);
1152 strcpy(s
->line
, string
);
1155 s
->width
= LCDFN(getstringsize
)(s
->line
, &w
, &h
);
1157 /* scroll bidirectional or forward only depending on the string
1159 if ( LCDFN(scroll_info
).bidir_limit
) {
1160 s
->bidir
= s
->width
< (current_vp
->width
- current_vp
->xmargin
) *
1161 (100 + LCDFN(scroll_info
).bidir_limit
) / 100;
1166 if (!s
->bidir
) { /* add spaces if scrolling in the round */
1167 strcat(s
->line
, " ");
1168 /* get new width incl. spaces */
1169 s
->width
= LCDFN(getstringsize
)(s
->line
, &w
, &h
);
1172 end
= strchr(s
->line
, '\0');
1173 strncpy(end
, (char *)string
, current_vp
->width
/2);
1177 s
->len
= utf8length((char *)string
);
1179 s
->startx
= current_vp
->xmargin
+ x
* s
->width
/ s
->len
;
1180 s
->backward
= false;
1182 LCDFN(scroll_info
).lines
++;
1186 void LCDFN(scroll_fn
)(void)
1189 struct scrollinfo
* s
;
1193 struct viewport
* old_vp
= current_vp
;
1195 for ( index
= 0; index
< LCDFN(scroll_info
).lines
; index
++ ) {
1196 s
= &LCDFN(scroll_info
).scroll
[index
];
1199 if (TIME_BEFORE(current_tick
, s
->start_tick
))
1202 LCDFN(set_viewport
)(s
->vp
);
1205 s
->offset
-= LCDFN(scroll_info
).step
;
1207 s
->offset
+= LCDFN(scroll_info
).step
;
1209 pf
= font_get(current_vp
->font
);
1211 ypos
= current_vp
->ymargin
+ s
->y
* pf
->height
;
1213 if (s
->bidir
) { /* scroll bidirectional */
1214 if (s
->offset
<= 0) {
1215 /* at beginning of line */
1217 s
->backward
= false;
1218 s
->start_tick
= current_tick
+ LCDFN(scroll_info
).delay
* 2;
1220 if (s
->offset
>= s
->width
- (current_vp
->width
- xpos
)) {
1221 /* at end of line */
1222 s
->offset
= s
->width
- (current_vp
->width
- xpos
);
1224 s
->start_tick
= current_tick
+ LCDFN(scroll_info
).delay
* 2;
1228 /* scroll forward the whole time */
1229 if (s
->offset
>= s
->width
)
1230 s
->offset
%= s
->width
;
1233 lastmode
= current_vp
->drawmode
;
1234 current_vp
->drawmode
= (s
->style
&STYLE_INVERT
) ?
1235 (DRMODE_SOLID
|DRMODE_INVERSEVID
) : DRMODE_SOLID
;
1236 LCDFN(putsxyofs
)(xpos
, ypos
, s
->offset
, s
->line
);
1237 current_vp
->drawmode
= lastmode
;
1238 LCDFN(update_viewport_rect
)(xpos
, ypos
,
1239 current_vp
->width
- xpos
, pf
->height
);
1242 LCDFN(set_viewport
)(old_vp
);