2 * Pixel drawing function templates for QEMU SM501 Device
4 * Copyright (c) 2008 Shin-ichiro KAWASAKI
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 #define PIXEL_TYPE uint8_t
28 #elif DEPTH == 15 || DEPTH == 16
30 #define PIXEL_TYPE uint16_t
33 #define PIXEL_TYPE uint32_t
35 #error unsupport depth
39 #define PIXEL_NAME glue(DEPTH, bgr)
41 #define PIXEL_NAME DEPTH
42 #endif /* BGR_FORMAT */
45 static void glue(draw_line8_
, PIXEL_NAME
)(
46 uint8_t *d
, const uint8_t *s
, int width
, const uint32_t *pal
)
51 r
= (pal
[v
] >> 16) & 0xff;
52 g
= (pal
[v
] >> 8) & 0xff;
53 b
= (pal
[v
] >> 0) & 0xff;
54 *(PIXEL_TYPE
*)d
= glue(rgb_to_pixel
, PIXEL_NAME
)(r
, g
, b
);
57 } while (--width
!= 0);
60 static void glue(draw_line16_
, PIXEL_NAME
)(
61 uint8_t *d
, const uint8_t *s
, int width
, const uint32_t *pal
)
67 rgb565
= lduw_le_p(s
);
68 r
= (rgb565
>> 8) & 0xf8;
69 g
= (rgb565
>> 3) & 0xfc;
70 b
= (rgb565
<< 3) & 0xf8;
71 *(PIXEL_TYPE
*)d
= glue(rgb_to_pixel
, PIXEL_NAME
)(r
, g
, b
);
74 } while (--width
!= 0);
77 static void glue(draw_line32_
, PIXEL_NAME
)(
78 uint8_t *d
, const uint8_t *s
, int width
, const uint32_t *pal
)
86 *(PIXEL_TYPE
*)d
= glue(rgb_to_pixel
, PIXEL_NAME
)(r
, g
, b
);
89 } while (--width
!= 0);
93 * Draw hardware cursor image on the given line.
95 static void glue(draw_hwc_line_
, PIXEL_NAME
)(uint8_t *d
, const uint8_t *s
,
96 int width
, const uint8_t *palette
, int c_x
, int c_y
)
99 uint8_t r
, g
, b
, v
, bitset
= 0;
101 /* get cursor position */
102 assert(0 <= c_y
&& c_y
< SM501_HWC_HEIGHT
);
103 s
+= SM501_HWC_WIDTH
* c_y
/ 4; /* 4 pixels per byte */
106 for (i
= 0; i
< SM501_HWC_WIDTH
&& c_x
+ i
< width
; i
++) {
107 /* get pixel value */
118 r
= palette
[v
* 3 + 0];
119 g
= palette
[v
* 3 + 1];
120 b
= palette
[v
* 3 + 2];
121 *(PIXEL_TYPE
*)d
= glue(rgb_to_pixel
, PIXEL_NAME
)(r
, g
, b
);