root / hw / jazz_led.c @ a245f2e7
History | View | Annotate | Download (9.4 kB)
1 | 31211df1 | ths | /*
|
---|---|---|---|
2 | 31211df1 | ths | * QEMU JAZZ LED emulator.
|
3 | 5fafdf24 | ths | *
|
4 | 31211df1 | ths | * Copyright (c) 2007 Herv? Poussineau
|
5 | 5fafdf24 | ths | *
|
6 | 31211df1 | ths | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 31211df1 | ths | * of this software and associated documentation files (the "Software"), to deal
|
8 | 31211df1 | ths | * in the Software without restriction, including without limitation the rights
|
9 | 31211df1 | ths | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 31211df1 | ths | * copies of the Software, and to permit persons to whom the Software is
|
11 | 31211df1 | ths | * furnished to do so, subject to the following conditions:
|
12 | 31211df1 | ths | *
|
13 | 31211df1 | ths | * The above copyright notice and this permission notice shall be included in
|
14 | 31211df1 | ths | * all copies or substantial portions of the Software.
|
15 | 31211df1 | ths | *
|
16 | 31211df1 | ths | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 31211df1 | ths | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 31211df1 | ths | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 31211df1 | ths | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 31211df1 | ths | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 31211df1 | ths | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 31211df1 | ths | * THE SOFTWARE.
|
23 | 31211df1 | ths | */
|
24 | 31211df1 | ths | |
25 | 87ecb68b | pbrook | #include "hw.h" |
26 | 87ecb68b | pbrook | #include "mips.h" |
27 | 87ecb68b | pbrook | #include "console.h" |
28 | 31211df1 | ths | #include "pixel_ops.h" |
29 | 31211df1 | ths | |
30 | 31211df1 | ths | //#define DEBUG_LED
|
31 | 31211df1 | ths | |
32 | 31211df1 | ths | typedef enum { |
33 | 31211df1 | ths | REDRAW_NONE = 0, REDRAW_SEGMENTS = 1, REDRAW_BACKGROUND = 2, |
34 | 31211df1 | ths | } screen_state_t; |
35 | 31211df1 | ths | |
36 | 31211df1 | ths | typedef struct LedState { |
37 | 31211df1 | ths | target_phys_addr_t base; |
38 | 31211df1 | ths | uint8_t segments; |
39 | 31211df1 | ths | DisplayState *ds; |
40 | c60e08d9 | pbrook | QEMUConsole *console; |
41 | 31211df1 | ths | screen_state_t state; |
42 | 31211df1 | ths | } LedState; |
43 | 31211df1 | ths | |
44 | 31211df1 | ths | static uint32_t led_readb(void *opaque, target_phys_addr_t addr) |
45 | 31211df1 | ths | { |
46 | 31211df1 | ths | LedState *s = opaque; |
47 | 31211df1 | ths | int relative_addr = addr - s->base;
|
48 | 31211df1 | ths | uint32_t val; |
49 | 31211df1 | ths | |
50 | 31211df1 | ths | switch (relative_addr) {
|
51 | 31211df1 | ths | case 0: |
52 | 31211df1 | ths | val = s->segments; |
53 | 31211df1 | ths | break;
|
54 | 31211df1 | ths | default:
|
55 | 31211df1 | ths | #ifdef DEBUG_LED
|
56 | 31211df1 | ths | printf("jazz led: invalid read [0x%x]\n", relative_addr);
|
57 | 31211df1 | ths | #endif
|
58 | 31211df1 | ths | val = 0;
|
59 | 31211df1 | ths | } |
60 | 31211df1 | ths | |
61 | 31211df1 | ths | return val;
|
62 | 31211df1 | ths | } |
63 | 31211df1 | ths | |
64 | 31211df1 | ths | static uint32_t led_readw(void *opaque, target_phys_addr_t addr) |
65 | 31211df1 | ths | { |
66 | 31211df1 | ths | uint32_t v; |
67 | 31211df1 | ths | #ifdef TARGET_WORDS_BIGENDIAN
|
68 | 31211df1 | ths | v = led_readb(opaque, addr) << 8;
|
69 | 31211df1 | ths | v |= led_readb(opaque, addr + 1);
|
70 | 31211df1 | ths | #else
|
71 | 31211df1 | ths | v = led_readb(opaque, addr); |
72 | 31211df1 | ths | v |= led_readb(opaque, addr + 1) << 8; |
73 | 31211df1 | ths | #endif
|
74 | 31211df1 | ths | return v;
|
75 | 31211df1 | ths | } |
76 | 31211df1 | ths | |
77 | 31211df1 | ths | static uint32_t led_readl(void *opaque, target_phys_addr_t addr) |
78 | 31211df1 | ths | { |
79 | 31211df1 | ths | uint32_t v; |
80 | 31211df1 | ths | #ifdef TARGET_WORDS_BIGENDIAN
|
81 | 31211df1 | ths | v = led_readb(opaque, addr) << 24;
|
82 | 31211df1 | ths | v |= led_readb(opaque, addr + 1) << 16; |
83 | 31211df1 | ths | v |= led_readb(opaque, addr + 2) << 8; |
84 | 31211df1 | ths | v |= led_readb(opaque, addr + 3);
|
85 | 31211df1 | ths | #else
|
86 | 31211df1 | ths | v = led_readb(opaque, addr); |
87 | 31211df1 | ths | v |= led_readb(opaque, addr + 1) << 8; |
88 | 31211df1 | ths | v |= led_readb(opaque, addr + 2) << 16; |
89 | 31211df1 | ths | v |= led_readb(opaque, addr + 3) << 24; |
90 | 31211df1 | ths | #endif
|
91 | 31211df1 | ths | return v;
|
92 | 31211df1 | ths | } |
93 | 31211df1 | ths | |
94 | 31211df1 | ths | static void led_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
95 | 31211df1 | ths | { |
96 | 31211df1 | ths | LedState *s = opaque; |
97 | 31211df1 | ths | int relative_addr = addr - s->base;
|
98 | 31211df1 | ths | |
99 | 31211df1 | ths | switch (relative_addr) {
|
100 | 31211df1 | ths | case 0: |
101 | 31211df1 | ths | s->segments = val; |
102 | 31211df1 | ths | s->state |= REDRAW_SEGMENTS; |
103 | 31211df1 | ths | break;
|
104 | 31211df1 | ths | default:
|
105 | 31211df1 | ths | #ifdef DEBUG_LED
|
106 | 31211df1 | ths | printf("jazz led: invalid write of 0x%02x at [0x%x]\n", val, relative_addr);
|
107 | 31211df1 | ths | #endif
|
108 | 31211df1 | ths | break;
|
109 | 31211df1 | ths | } |
110 | 31211df1 | ths | } |
111 | 31211df1 | ths | |
112 | 31211df1 | ths | static void led_writew(void *opaque, target_phys_addr_t addr, uint32_t val) |
113 | 31211df1 | ths | { |
114 | 31211df1 | ths | #ifdef TARGET_WORDS_BIGENDIAN
|
115 | 31211df1 | ths | led_writeb(opaque, addr, (val >> 8) & 0xff); |
116 | 31211df1 | ths | led_writeb(opaque, addr + 1, val & 0xff); |
117 | 31211df1 | ths | #else
|
118 | 31211df1 | ths | led_writeb(opaque, addr, val & 0xff);
|
119 | 31211df1 | ths | led_writeb(opaque, addr + 1, (val >> 8) & 0xff); |
120 | 31211df1 | ths | #endif
|
121 | 31211df1 | ths | } |
122 | 31211df1 | ths | |
123 | 31211df1 | ths | static void led_writel(void *opaque, target_phys_addr_t addr, uint32_t val) |
124 | 31211df1 | ths | { |
125 | 31211df1 | ths | #ifdef TARGET_WORDS_BIGENDIAN
|
126 | 31211df1 | ths | led_writeb(opaque, addr, (val >> 24) & 0xff); |
127 | 31211df1 | ths | led_writeb(opaque, addr + 1, (val >> 16) & 0xff); |
128 | 31211df1 | ths | led_writeb(opaque, addr + 2, (val >> 8) & 0xff); |
129 | 31211df1 | ths | led_writeb(opaque, addr + 3, val & 0xff); |
130 | 31211df1 | ths | #else
|
131 | 31211df1 | ths | led_writeb(opaque, addr, val & 0xff);
|
132 | 31211df1 | ths | led_writeb(opaque, addr + 1, (val >> 8) & 0xff); |
133 | 31211df1 | ths | led_writeb(opaque, addr + 2, (val >> 16) & 0xff); |
134 | 31211df1 | ths | led_writeb(opaque, addr + 3, (val >> 24) & 0xff); |
135 | 31211df1 | ths | #endif
|
136 | 31211df1 | ths | } |
137 | 31211df1 | ths | |
138 | 31211df1 | ths | static CPUReadMemoryFunc *led_read[3] = { |
139 | 31211df1 | ths | led_readb, |
140 | 31211df1 | ths | led_readw, |
141 | 31211df1 | ths | led_readl, |
142 | 31211df1 | ths | }; |
143 | 31211df1 | ths | |
144 | 31211df1 | ths | static CPUWriteMemoryFunc *led_write[3] = { |
145 | 31211df1 | ths | led_writeb, |
146 | 31211df1 | ths | led_writew, |
147 | 31211df1 | ths | led_writel, |
148 | 31211df1 | ths | }; |
149 | 31211df1 | ths | |
150 | 31211df1 | ths | /***********************************************************/
|
151 | 31211df1 | ths | /* jazz_led display */
|
152 | 31211df1 | ths | |
153 | 31211df1 | ths | static void draw_horizontal_line(DisplayState *ds, int posy, int posx1, int posx2, uint32_t color) |
154 | 31211df1 | ths | { |
155 | 31211df1 | ths | uint8_t *d; |
156 | 31211df1 | ths | int x, bpp;
|
157 | 31211df1 | ths | |
158 | 31211df1 | ths | bpp = (ds->depth + 7) >> 3; |
159 | 31211df1 | ths | d = ds->data + ds->linesize * posy + bpp * posx1; |
160 | 31211df1 | ths | switch(bpp) {
|
161 | 31211df1 | ths | case 1: |
162 | 31211df1 | ths | for (x = posx1; x <= posx2; x++) {
|
163 | 31211df1 | ths | *((uint8_t *)d) = color; |
164 | 31211df1 | ths | d++; |
165 | 31211df1 | ths | } |
166 | 31211df1 | ths | break;
|
167 | 31211df1 | ths | case 2: |
168 | 31211df1 | ths | for (x = posx1; x <= posx2; x++) {
|
169 | 31211df1 | ths | *((uint16_t *)d) = color; |
170 | 31211df1 | ths | d += 2;
|
171 | 31211df1 | ths | } |
172 | 31211df1 | ths | break;
|
173 | 31211df1 | ths | case 4: |
174 | 31211df1 | ths | for (x = posx1; x <= posx2; x++) {
|
175 | 31211df1 | ths | *((uint32_t *)d) = color; |
176 | 31211df1 | ths | d += 4;
|
177 | 31211df1 | ths | } |
178 | 31211df1 | ths | break;
|
179 | 31211df1 | ths | } |
180 | 31211df1 | ths | } |
181 | 31211df1 | ths | |
182 | 31211df1 | ths | static void draw_vertical_line(DisplayState *ds, int posx, int posy1, int posy2, uint32_t color) |
183 | 31211df1 | ths | { |
184 | 31211df1 | ths | uint8_t *d; |
185 | 31211df1 | ths | int y, bpp;
|
186 | 31211df1 | ths | |
187 | 31211df1 | ths | bpp = (ds->depth + 7) >> 3; |
188 | 31211df1 | ths | d = ds->data + ds->linesize * posy1 + bpp * posx; |
189 | 31211df1 | ths | switch(bpp) {
|
190 | 31211df1 | ths | case 1: |
191 | 31211df1 | ths | for (y = posy1; y <= posy2; y++) {
|
192 | 31211df1 | ths | *((uint8_t *)d) = color; |
193 | 31211df1 | ths | d += ds->linesize; |
194 | 31211df1 | ths | } |
195 | 31211df1 | ths | break;
|
196 | 31211df1 | ths | case 2: |
197 | 31211df1 | ths | for (y = posy1; y <= posy2; y++) {
|
198 | 31211df1 | ths | *((uint16_t *)d) = color; |
199 | 31211df1 | ths | d += ds->linesize; |
200 | 31211df1 | ths | } |
201 | 31211df1 | ths | break;
|
202 | 31211df1 | ths | case 4: |
203 | 31211df1 | ths | for (y = posy1; y <= posy2; y++) {
|
204 | 31211df1 | ths | *((uint32_t *)d) = color; |
205 | 31211df1 | ths | d += ds->linesize; |
206 | 31211df1 | ths | } |
207 | 31211df1 | ths | break;
|
208 | 31211df1 | ths | } |
209 | 31211df1 | ths | } |
210 | 31211df1 | ths | |
211 | 31211df1 | ths | static void jazz_led_update_display(void *opaque) |
212 | 31211df1 | ths | { |
213 | 31211df1 | ths | LedState *s = opaque; |
214 | 31211df1 | ths | DisplayState *ds = s->ds; |
215 | 31211df1 | ths | uint8_t *d1; |
216 | 31211df1 | ths | uint32_t color_segment, color_led; |
217 | 31211df1 | ths | int y, bpp;
|
218 | 31211df1 | ths | |
219 | 31211df1 | ths | if (s->state & REDRAW_BACKGROUND) {
|
220 | 31211df1 | ths | /* clear screen */
|
221 | 31211df1 | ths | bpp = (ds->depth + 7) >> 3; |
222 | 31211df1 | ths | d1 = ds->data; |
223 | 31211df1 | ths | for (y = 0; y < ds->height; y++) { |
224 | 31211df1 | ths | memset(d1, 0x00, ds->width * bpp);
|
225 | 31211df1 | ths | d1 += ds->linesize; |
226 | 31211df1 | ths | } |
227 | 31211df1 | ths | } |
228 | 31211df1 | ths | |
229 | 31211df1 | ths | if (s->state & REDRAW_SEGMENTS) {
|
230 | 31211df1 | ths | /* set colors according to bpp */
|
231 | 31211df1 | ths | switch (ds->depth) {
|
232 | 31211df1 | ths | case 8: |
233 | 31211df1 | ths | color_segment = rgb_to_pixel8(0xaa, 0xaa, 0xaa); |
234 | 31211df1 | ths | color_led = rgb_to_pixel8(0x00, 0xff, 0x00); |
235 | 31211df1 | ths | break;
|
236 | 31211df1 | ths | case 15: |
237 | 31211df1 | ths | color_segment = rgb_to_pixel15(0xaa, 0xaa, 0xaa); |
238 | 31211df1 | ths | color_led = rgb_to_pixel15(0x00, 0xff, 0x00); |
239 | 31211df1 | ths | break;
|
240 | 31211df1 | ths | case 16: |
241 | 31211df1 | ths | color_segment = rgb_to_pixel16(0xaa, 0xaa, 0xaa); |
242 | 31211df1 | ths | color_led = rgb_to_pixel16(0x00, 0xff, 0x00); |
243 | 31211df1 | ths | case 24: |
244 | 31211df1 | ths | color_segment = rgb_to_pixel24(0xaa, 0xaa, 0xaa); |
245 | 31211df1 | ths | color_led = rgb_to_pixel24(0x00, 0xff, 0x00); |
246 | 31211df1 | ths | break;
|
247 | 31211df1 | ths | case 32: |
248 | 31211df1 | ths | color_segment = rgb_to_pixel32(0xaa, 0xaa, 0xaa); |
249 | 31211df1 | ths | color_led = rgb_to_pixel32(0x00, 0xff, 0x00); |
250 | 31211df1 | ths | break;
|
251 | 31211df1 | ths | default:
|
252 | 31211df1 | ths | return;
|
253 | 31211df1 | ths | } |
254 | 31211df1 | ths | |
255 | 31211df1 | ths | /* display segments */
|
256 | 31211df1 | ths | draw_horizontal_line(ds, 40, 10, 40, (s->segments & 0x02) ? color_segment : 0); |
257 | 31211df1 | ths | draw_vertical_line(ds, 10, 10, 40, (s->segments & 0x04) ? color_segment : 0); |
258 | 31211df1 | ths | draw_vertical_line(ds, 10, 40, 70, (s->segments & 0x08) ? color_segment : 0); |
259 | 31211df1 | ths | draw_horizontal_line(ds, 70, 10, 40, (s->segments & 0x10) ? color_segment : 0); |
260 | 31211df1 | ths | draw_vertical_line(ds, 40, 40, 70, (s->segments & 0x20) ? color_segment : 0); |
261 | 31211df1 | ths | draw_vertical_line(ds, 40, 10, 40, (s->segments & 0x40) ? color_segment : 0); |
262 | 31211df1 | ths | draw_horizontal_line(ds, 10, 10, 40, (s->segments & 0x80) ? color_segment : 0); |
263 | 31211df1 | ths | |
264 | 31211df1 | ths | /* display led */
|
265 | 31211df1 | ths | if (!(s->segments & 0x01)) |
266 | 31211df1 | ths | color_led = 0; /* black */ |
267 | 31211df1 | ths | draw_horizontal_line(ds, 68, 50, 50, color_led); |
268 | 31211df1 | ths | draw_horizontal_line(ds, 69, 49, 51, color_led); |
269 | 31211df1 | ths | draw_horizontal_line(ds, 70, 48, 52, color_led); |
270 | 31211df1 | ths | draw_horizontal_line(ds, 71, 49, 51, color_led); |
271 | 31211df1 | ths | draw_horizontal_line(ds, 72, 50, 50, color_led); |
272 | 31211df1 | ths | } |
273 | 31211df1 | ths | |
274 | 31211df1 | ths | s->state = REDRAW_NONE; |
275 | 31211df1 | ths | dpy_update(ds, 0, 0, ds->width, ds->height); |
276 | 31211df1 | ths | } |
277 | 31211df1 | ths | |
278 | 31211df1 | ths | static void jazz_led_invalidate_display(void *opaque) |
279 | 31211df1 | ths | { |
280 | 31211df1 | ths | LedState *s = opaque; |
281 | 31211df1 | ths | s->state |= REDRAW_SEGMENTS | REDRAW_BACKGROUND; |
282 | 31211df1 | ths | } |
283 | 31211df1 | ths | |
284 | 31211df1 | ths | static void jazz_led_screen_dump(void *opaque, const char *filename) |
285 | 31211df1 | ths | { |
286 | 31211df1 | ths | printf("jazz_led_screen_dump() not implemented\n");
|
287 | 31211df1 | ths | } |
288 | 31211df1 | ths | |
289 | 4d3b6f6e | balrog | static void jazz_led_text_update(void *opaque, console_ch_t *chardata) |
290 | 4d3b6f6e | balrog | { |
291 | 4d3b6f6e | balrog | LedState *s = opaque; |
292 | 4d3b6f6e | balrog | char buf[2]; |
293 | 4d3b6f6e | balrog | |
294 | 4d3b6f6e | balrog | dpy_cursor(s->ds, -1, -1); |
295 | c60e08d9 | pbrook | qemu_console_resize(s->console, 2, 1); |
296 | 4d3b6f6e | balrog | |
297 | 4d3b6f6e | balrog | /* TODO: draw the segments */
|
298 | 4d3b6f6e | balrog | snprintf(buf, 2, "%02hhx\n", s->segments); |
299 | 4d3b6f6e | balrog | console_write_ch(chardata++, 0x00200100 | buf[0]); |
300 | 4d3b6f6e | balrog | console_write_ch(chardata++, 0x00200100 | buf[1]); |
301 | 4d3b6f6e | balrog | |
302 | 4d3b6f6e | balrog | dpy_update(s->ds, 0, 0, 2, 1); |
303 | 4d3b6f6e | balrog | } |
304 | 4d3b6f6e | balrog | |
305 | 31211df1 | ths | void jazz_led_init(DisplayState *ds, target_phys_addr_t base)
|
306 | 31211df1 | ths | { |
307 | 31211df1 | ths | LedState *s; |
308 | 31211df1 | ths | int io;
|
309 | 31211df1 | ths | |
310 | 31211df1 | ths | s = qemu_mallocz(sizeof(LedState));
|
311 | 31211df1 | ths | if (!s)
|
312 | 31211df1 | ths | return;
|
313 | 31211df1 | ths | |
314 | 31211df1 | ths | s->base = base; |
315 | 31211df1 | ths | s->ds = ds; |
316 | 31211df1 | ths | s->state = REDRAW_SEGMENTS | REDRAW_BACKGROUND; |
317 | 31211df1 | ths | |
318 | 31211df1 | ths | io = cpu_register_io_memory(0, led_read, led_write, s);
|
319 | 31211df1 | ths | cpu_register_physical_memory(s->base, 1, io);
|
320 | 31211df1 | ths | |
321 | c60e08d9 | pbrook | s->console = graphic_console_init(ds, jazz_led_update_display, |
322 | c60e08d9 | pbrook | jazz_led_invalidate_display, |
323 | c60e08d9 | pbrook | jazz_led_screen_dump, |
324 | c60e08d9 | pbrook | jazz_led_text_update, s); |
325 | c60e08d9 | pbrook | qemu_console_resize(s->console, 60, 80); |
326 | 31211df1 | ths | } |