Statistics
| Branch: | Revision:

root / hw / sm501_template.h @ 8ca209ad

History | View | Annotate | Download (3.9 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 0a4e7cd2 Shin-ichiro KAWASAKI
/**
100 0a4e7cd2 Shin-ichiro KAWASAKI
 * Draw hardware cursor image on the given line.
101 0a4e7cd2 Shin-ichiro KAWASAKI
 */
102 0a4e7cd2 Shin-ichiro KAWASAKI
static void glue(draw_hwc_line_, PIXEL_NAME)(SM501State * s, int crt,
103 0a4e7cd2 Shin-ichiro KAWASAKI
                         uint8_t * palette, int c_y, uint8_t *d, int width)
104 0a4e7cd2 Shin-ichiro KAWASAKI
{
105 0a4e7cd2 Shin-ichiro KAWASAKI
    int x, i;
106 0a4e7cd2 Shin-ichiro KAWASAKI
    uint8_t bitset = 0;
107 0a4e7cd2 Shin-ichiro KAWASAKI
108 0a4e7cd2 Shin-ichiro KAWASAKI
    /* get hardware cursor pattern */
109 0a4e7cd2 Shin-ichiro KAWASAKI
    uint32_t cursor_addr = get_hwc_address(s, crt);
110 0a4e7cd2 Shin-ichiro KAWASAKI
    assert(0 <= c_y && c_y < SM501_HWC_HEIGHT);
111 0a4e7cd2 Shin-ichiro KAWASAKI
    cursor_addr += 64 * c_y / 4;  /* 4 pixels per byte */
112 0a4e7cd2 Shin-ichiro KAWASAKI
    cursor_addr += s->base;
113 0a4e7cd2 Shin-ichiro KAWASAKI
114 0a4e7cd2 Shin-ichiro KAWASAKI
    /* get cursor position */
115 0a4e7cd2 Shin-ichiro KAWASAKI
    x = get_hwc_x(s, crt);
116 0a4e7cd2 Shin-ichiro KAWASAKI
    d += x * BPP;
117 0a4e7cd2 Shin-ichiro KAWASAKI
118 0a4e7cd2 Shin-ichiro KAWASAKI
    for (i = 0; i < SM501_HWC_WIDTH && x + i < width; i++) {
119 0a4e7cd2 Shin-ichiro KAWASAKI
        uint8_t v;
120 0a4e7cd2 Shin-ichiro KAWASAKI
121 0a4e7cd2 Shin-ichiro KAWASAKI
        /* get pixel value */
122 0a4e7cd2 Shin-ichiro KAWASAKI
        if (i % 4 == 0) {
123 0a4e7cd2 Shin-ichiro KAWASAKI
            cpu_physical_memory_rw(cursor_addr, &bitset, 1, 0);
124 0a4e7cd2 Shin-ichiro KAWASAKI
            cursor_addr++;
125 0a4e7cd2 Shin-ichiro KAWASAKI
        }
126 0a4e7cd2 Shin-ichiro KAWASAKI
        v = bitset & 3;
127 0a4e7cd2 Shin-ichiro KAWASAKI
        bitset >>= 2;
128 0a4e7cd2 Shin-ichiro KAWASAKI
129 0a4e7cd2 Shin-ichiro KAWASAKI
        /* write pixel */
130 0a4e7cd2 Shin-ichiro KAWASAKI
        if (v) {
131 0a4e7cd2 Shin-ichiro KAWASAKI
            v--;
132 0a4e7cd2 Shin-ichiro KAWASAKI
            uint8_t r = palette[v * 3 + 0];
133 0a4e7cd2 Shin-ichiro KAWASAKI
            uint8_t g = palette[v * 3 + 1];
134 0a4e7cd2 Shin-ichiro KAWASAKI
            uint8_t b = palette[v * 3 + 2];
135 0a4e7cd2 Shin-ichiro KAWASAKI
            ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, PIXEL_NAME)(r, g, b);
136 0a4e7cd2 Shin-ichiro KAWASAKI
        }
137 0a4e7cd2 Shin-ichiro KAWASAKI
        d += BPP;
138 0a4e7cd2 Shin-ichiro KAWASAKI
    }
139 0a4e7cd2 Shin-ichiro KAWASAKI
}
140 0a4e7cd2 Shin-ichiro KAWASAKI
141 ffd39257 blueswir1
#undef DEPTH
142 ffd39257 blueswir1
#undef BPP
143 ffd39257 blueswir1
#undef PIXEL_TYPE
144 ffd39257 blueswir1
#undef PIXEL_NAME
145 ffd39257 blueswir1
#undef BGR_FORMAT