root / hw / sm501_template.h @ 3ced9f7a
History | View | Annotate | Download (2.8 kB)
1 | ffd39257 | blueswir1 | /*
|
---|---|---|---|
2 | ffd39257 | blueswir1 | * Pixel drawing function templates for QEMU SM501 Device
|
3 | ffd39257 | blueswir1 | *
|
4 | ffd39257 | blueswir1 | * Copyright (c) 2008 Shin-ichiro KAWASAKI
|
5 | ffd39257 | blueswir1 | *
|
6 | ffd39257 | blueswir1 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | ffd39257 | blueswir1 | * of this software and associated documentation files (the "Software"), to deal
|
8 | ffd39257 | blueswir1 | * in the Software without restriction, including without limitation the rights
|
9 | ffd39257 | blueswir1 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | ffd39257 | blueswir1 | * copies of the Software, and to permit persons to whom the Software is
|
11 | ffd39257 | blueswir1 | * furnished to do so, subject to the following conditions:
|
12 | ffd39257 | blueswir1 | *
|
13 | ffd39257 | blueswir1 | * The above copyright notice and this permission notice shall be included in
|
14 | ffd39257 | blueswir1 | * all copies or substantial portions of the Software.
|
15 | ffd39257 | blueswir1 | *
|
16 | ffd39257 | blueswir1 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | ffd39257 | blueswir1 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | ffd39257 | blueswir1 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | ffd39257 | blueswir1 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | ffd39257 | blueswir1 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | ffd39257 | blueswir1 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | ffd39257 | blueswir1 | * THE SOFTWARE.
|
23 | ffd39257 | blueswir1 | */
|
24 | ffd39257 | blueswir1 | |
25 | ffd39257 | blueswir1 | #if DEPTH == 8 |
26 | ffd39257 | blueswir1 | #define BPP 1 |
27 | ffd39257 | blueswir1 | #define PIXEL_TYPE uint8_t
|
28 | ffd39257 | blueswir1 | #elif DEPTH == 15 || DEPTH == 16 |
29 | ffd39257 | blueswir1 | #define BPP 2 |
30 | ffd39257 | blueswir1 | #define PIXEL_TYPE uint16_t
|
31 | ffd39257 | blueswir1 | #elif DEPTH == 32 |
32 | ffd39257 | blueswir1 | #define BPP 4 |
33 | ffd39257 | blueswir1 | #define PIXEL_TYPE uint32_t
|
34 | ffd39257 | blueswir1 | #else
|
35 | ffd39257 | blueswir1 | #error unsupport depth
|
36 | ffd39257 | blueswir1 | #endif
|
37 | ffd39257 | blueswir1 | |
38 | ffd39257 | blueswir1 | #ifdef BGR_FORMAT
|
39 | ffd39257 | blueswir1 | #define PIXEL_NAME glue(DEPTH, bgr)
|
40 | ffd39257 | blueswir1 | #else
|
41 | ffd39257 | blueswir1 | #define PIXEL_NAME DEPTH
|
42 | ffd39257 | blueswir1 | #endif /* BGR_FORMAT */ |
43 | ffd39257 | blueswir1 | |
44 | ffd39257 | blueswir1 | |
45 | ffd39257 | blueswir1 | static void glue(draw_line8_, PIXEL_NAME)( |
46 | ffd39257 | blueswir1 | uint8_t *d, const uint8_t *s, int width, const uint32_t *pal) |
47 | ffd39257 | blueswir1 | { |
48 | ffd39257 | blueswir1 | uint8_t v, r, g, b; |
49 | ffd39257 | blueswir1 | do {
|
50 | ffd39257 | blueswir1 | v = ldub_raw(s); |
51 | ffd39257 | blueswir1 | r = (pal[v] >> 16) & 0xff; |
52 | ffd39257 | blueswir1 | g = (pal[v] >> 8) & 0xff; |
53 | ffd39257 | blueswir1 | b = (pal[v] >> 0) & 0xff; |
54 | ffd39257 | blueswir1 | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, PIXEL_NAME)(r, g, b);
|
55 | ffd39257 | blueswir1 | s ++; |
56 | ffd39257 | blueswir1 | d += BPP; |
57 | ffd39257 | blueswir1 | } while (-- width != 0); |
58 | ffd39257 | blueswir1 | } |
59 | ffd39257 | blueswir1 | |
60 | ffd39257 | blueswir1 | static void glue(draw_line16_, PIXEL_NAME)( |
61 | ffd39257 | blueswir1 | uint8_t *d, const uint8_t *s, int width, const uint32_t *pal) |
62 | ffd39257 | blueswir1 | { |
63 | ffd39257 | blueswir1 | uint16_t rgb565; |
64 | ffd39257 | blueswir1 | uint8_t r, g, b; |
65 | ffd39257 | blueswir1 | |
66 | ffd39257 | blueswir1 | do {
|
67 | ffd39257 | blueswir1 | rgb565 = lduw_raw(s); |
68 | ffd39257 | blueswir1 | r = ((rgb565 >> 11) & 0x1f) << 3; |
69 | ffd39257 | blueswir1 | g = ((rgb565 >> 5) & 0x3f) << 2; |
70 | ffd39257 | blueswir1 | b = ((rgb565 >> 0) & 0x1f) << 3; |
71 | ffd39257 | blueswir1 | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, PIXEL_NAME)(r, g, b);
|
72 | ffd39257 | blueswir1 | s += 2;
|
73 | ffd39257 | blueswir1 | d += BPP; |
74 | ffd39257 | blueswir1 | } while (-- width != 0); |
75 | ffd39257 | blueswir1 | } |
76 | ffd39257 | blueswir1 | |
77 | ffd39257 | blueswir1 | static void glue(draw_line32_, PIXEL_NAME)( |
78 | ffd39257 | blueswir1 | uint8_t *d, const uint8_t *s, int width, const uint32_t *pal) |
79 | ffd39257 | blueswir1 | { |
80 | ffd39257 | blueswir1 | uint8_t r, g, b; |
81 | ffd39257 | blueswir1 | |
82 | ffd39257 | blueswir1 | do {
|
83 | ffd39257 | blueswir1 | ldub_raw(s); |
84 | ffd39257 | blueswir1 | #if defined(TARGET_WORDS_BIGENDIAN)
|
85 | ffd39257 | blueswir1 | r = s[1];
|
86 | ffd39257 | blueswir1 | g = s[2];
|
87 | ffd39257 | blueswir1 | b = s[3];
|
88 | ffd39257 | blueswir1 | #else
|
89 | ffd39257 | blueswir1 | b = s[0];
|
90 | ffd39257 | blueswir1 | g = s[1];
|
91 | ffd39257 | blueswir1 | r = s[2];
|
92 | ffd39257 | blueswir1 | #endif
|
93 | ffd39257 | blueswir1 | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, PIXEL_NAME)(r, g, b);
|
94 | ffd39257 | blueswir1 | s += 4;
|
95 | ffd39257 | blueswir1 | d += BPP; |
96 | ffd39257 | blueswir1 | } while (-- width != 0); |
97 | ffd39257 | blueswir1 | } |
98 | ffd39257 | blueswir1 | |
99 | ffd39257 | blueswir1 | #undef DEPTH
|
100 | ffd39257 | blueswir1 | #undef BPP
|
101 | ffd39257 | blueswir1 | #undef PIXEL_TYPE
|
102 | ffd39257 | blueswir1 | #undef PIXEL_NAME
|
103 | ffd39257 | blueswir1 | #undef BGR_FORMAT |