root / hw / display / jazz_led.c @ 2c9b15ca
History | View | Annotate | Download (9.1 kB)
1 | 31211df1 | ths | /*
|
---|---|---|---|
2 | 31211df1 | ths | * QEMU JAZZ LED emulator.
|
3 | 5fafdf24 | ths | *
|
4 | b39506e4 | Hervé Poussineau | * Copyright (c) 2007-2012 Herve 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 | 077805fa | Paolo Bonzini | #include "qemu-common.h" |
26 | 28ecbaee | Paolo Bonzini | #include "ui/console.h" |
27 | 28ecbaee | Paolo Bonzini | #include "ui/pixel_ops.h" |
28 | 63b9932d | Hervé Poussineau | #include "trace.h" |
29 | 83c9f4ca | Paolo Bonzini | #include "hw/sysbus.h" |
30 | 14414da4 | Hervé Poussineau | |
31 | 31211df1 | ths | typedef enum { |
32 | 31211df1 | ths | REDRAW_NONE = 0, REDRAW_SEGMENTS = 1, REDRAW_BACKGROUND = 2, |
33 | c227f099 | Anthony Liguori | } screen_state_t; |
34 | 31211df1 | ths | |
35 | 31211df1 | ths | typedef struct LedState { |
36 | b39506e4 | Hervé Poussineau | SysBusDevice busdev; |
37 | c6017850 | Avi Kivity | MemoryRegion iomem; |
38 | 31211df1 | ths | uint8_t segments; |
39 | c78f7137 | Gerd Hoffmann | QemuConsole *con; |
40 | c227f099 | Anthony Liguori | screen_state_t state; |
41 | 31211df1 | ths | } LedState; |
42 | 31211df1 | ths | |
43 | a8170e5e | Avi Kivity | static uint64_t jazz_led_read(void *opaque, hwaddr addr, |
44 | b39506e4 | Hervé Poussineau | unsigned int size) |
45 | 31211df1 | ths | { |
46 | 31211df1 | ths | LedState *s = opaque; |
47 | 63b9932d | Hervé Poussineau | uint8_t val; |
48 | 31211df1 | ths | |
49 | b39506e4 | Hervé Poussineau | val = s->segments; |
50 | 63b9932d | Hervé Poussineau | trace_jazz_led_read(addr, val); |
51 | 14414da4 | Hervé Poussineau | |
52 | 31211df1 | ths | return val;
|
53 | 31211df1 | ths | } |
54 | 31211df1 | ths | |
55 | a8170e5e | Avi Kivity | static void jazz_led_write(void *opaque, hwaddr addr, |
56 | b39506e4 | Hervé Poussineau | uint64_t val, unsigned int size) |
57 | 31211df1 | ths | { |
58 | 31211df1 | ths | LedState *s = opaque; |
59 | 63b9932d | Hervé Poussineau | uint8_t new_val = val & 0xff;
|
60 | 31211df1 | ths | |
61 | 63b9932d | Hervé Poussineau | trace_jazz_led_write(addr, new_val); |
62 | 14414da4 | Hervé Poussineau | |
63 | b39506e4 | Hervé Poussineau | s->segments = new_val; |
64 | b39506e4 | Hervé Poussineau | s->state |= REDRAW_SEGMENTS; |
65 | 31211df1 | ths | } |
66 | 31211df1 | ths | |
67 | c6017850 | Avi Kivity | static const MemoryRegionOps led_ops = { |
68 | b39506e4 | Hervé Poussineau | .read = jazz_led_read, |
69 | b39506e4 | Hervé Poussineau | .write = jazz_led_write, |
70 | c6017850 | Avi Kivity | .endianness = DEVICE_NATIVE_ENDIAN, |
71 | b39506e4 | Hervé Poussineau | .impl.min_access_size = 1,
|
72 | b39506e4 | Hervé Poussineau | .impl.max_access_size = 1,
|
73 | 31211df1 | ths | }; |
74 | 31211df1 | ths | |
75 | 31211df1 | ths | /***********************************************************/
|
76 | 31211df1 | ths | /* jazz_led display */
|
77 | 31211df1 | ths | |
78 | c78f7137 | Gerd Hoffmann | static void draw_horizontal_line(DisplaySurface *ds, |
79 | c78f7137 | Gerd Hoffmann | int posy, int posx1, int posx2, |
80 | c78f7137 | Gerd Hoffmann | uint32_t color) |
81 | 31211df1 | ths | { |
82 | 31211df1 | ths | uint8_t *d; |
83 | 31211df1 | ths | int x, bpp;
|
84 | 31211df1 | ths | |
85 | c78f7137 | Gerd Hoffmann | bpp = (surface_bits_per_pixel(ds) + 7) >> 3; |
86 | c78f7137 | Gerd Hoffmann | d = surface_data(ds) + surface_stride(ds) * posy + bpp * posx1; |
87 | 31211df1 | ths | switch(bpp) {
|
88 | 31211df1 | ths | case 1: |
89 | 31211df1 | ths | for (x = posx1; x <= posx2; x++) {
|
90 | 31211df1 | ths | *((uint8_t *)d) = color; |
91 | 31211df1 | ths | d++; |
92 | 31211df1 | ths | } |
93 | 31211df1 | ths | break;
|
94 | 31211df1 | ths | case 2: |
95 | 31211df1 | ths | for (x = posx1; x <= posx2; x++) {
|
96 | 31211df1 | ths | *((uint16_t *)d) = color; |
97 | 31211df1 | ths | d += 2;
|
98 | 31211df1 | ths | } |
99 | 31211df1 | ths | break;
|
100 | 31211df1 | ths | case 4: |
101 | 31211df1 | ths | for (x = posx1; x <= posx2; x++) {
|
102 | 31211df1 | ths | *((uint32_t *)d) = color; |
103 | 31211df1 | ths | d += 4;
|
104 | 31211df1 | ths | } |
105 | 31211df1 | ths | break;
|
106 | 31211df1 | ths | } |
107 | 31211df1 | ths | } |
108 | 31211df1 | ths | |
109 | c78f7137 | Gerd Hoffmann | static void draw_vertical_line(DisplaySurface *ds, |
110 | c78f7137 | Gerd Hoffmann | int posx, int posy1, int posy2, |
111 | c78f7137 | Gerd Hoffmann | uint32_t color) |
112 | 31211df1 | ths | { |
113 | 31211df1 | ths | uint8_t *d; |
114 | 31211df1 | ths | int y, bpp;
|
115 | 31211df1 | ths | |
116 | c78f7137 | Gerd Hoffmann | bpp = (surface_bits_per_pixel(ds) + 7) >> 3; |
117 | c78f7137 | Gerd Hoffmann | d = surface_data(ds) + surface_stride(ds) * posy1 + bpp * posx; |
118 | 31211df1 | ths | switch(bpp) {
|
119 | 31211df1 | ths | case 1: |
120 | 31211df1 | ths | for (y = posy1; y <= posy2; y++) {
|
121 | 31211df1 | ths | *((uint8_t *)d) = color; |
122 | c78f7137 | Gerd Hoffmann | d += surface_stride(ds); |
123 | 31211df1 | ths | } |
124 | 31211df1 | ths | break;
|
125 | 31211df1 | ths | case 2: |
126 | 31211df1 | ths | for (y = posy1; y <= posy2; y++) {
|
127 | 31211df1 | ths | *((uint16_t *)d) = color; |
128 | c78f7137 | Gerd Hoffmann | d += surface_stride(ds); |
129 | 31211df1 | ths | } |
130 | 31211df1 | ths | break;
|
131 | 31211df1 | ths | case 4: |
132 | 31211df1 | ths | for (y = posy1; y <= posy2; y++) {
|
133 | 31211df1 | ths | *((uint32_t *)d) = color; |
134 | c78f7137 | Gerd Hoffmann | d += surface_stride(ds); |
135 | 31211df1 | ths | } |
136 | 31211df1 | ths | break;
|
137 | 31211df1 | ths | } |
138 | 31211df1 | ths | } |
139 | 31211df1 | ths | |
140 | 31211df1 | ths | static void jazz_led_update_display(void *opaque) |
141 | 31211df1 | ths | { |
142 | 31211df1 | ths | LedState *s = opaque; |
143 | c78f7137 | Gerd Hoffmann | DisplaySurface *surface = qemu_console_surface(s->con); |
144 | 31211df1 | ths | uint8_t *d1; |
145 | 31211df1 | ths | uint32_t color_segment, color_led; |
146 | 31211df1 | ths | int y, bpp;
|
147 | 31211df1 | ths | |
148 | 31211df1 | ths | if (s->state & REDRAW_BACKGROUND) {
|
149 | 31211df1 | ths | /* clear screen */
|
150 | c78f7137 | Gerd Hoffmann | bpp = (surface_bits_per_pixel(surface) + 7) >> 3; |
151 | c78f7137 | Gerd Hoffmann | d1 = surface_data(surface); |
152 | c78f7137 | Gerd Hoffmann | for (y = 0; y < surface_height(surface); y++) { |
153 | c78f7137 | Gerd Hoffmann | memset(d1, 0x00, surface_width(surface) * bpp);
|
154 | c78f7137 | Gerd Hoffmann | d1 += surface_stride(surface); |
155 | 31211df1 | ths | } |
156 | 31211df1 | ths | } |
157 | 31211df1 | ths | |
158 | 31211df1 | ths | if (s->state & REDRAW_SEGMENTS) {
|
159 | 31211df1 | ths | /* set colors according to bpp */
|
160 | c78f7137 | Gerd Hoffmann | switch (surface_bits_per_pixel(surface)) {
|
161 | 31211df1 | ths | case 8: |
162 | 31211df1 | ths | color_segment = rgb_to_pixel8(0xaa, 0xaa, 0xaa); |
163 | 31211df1 | ths | color_led = rgb_to_pixel8(0x00, 0xff, 0x00); |
164 | 31211df1 | ths | break;
|
165 | 31211df1 | ths | case 15: |
166 | 31211df1 | ths | color_segment = rgb_to_pixel15(0xaa, 0xaa, 0xaa); |
167 | 31211df1 | ths | color_led = rgb_to_pixel15(0x00, 0xff, 0x00); |
168 | 31211df1 | ths | break;
|
169 | 31211df1 | ths | case 16: |
170 | 31211df1 | ths | color_segment = rgb_to_pixel16(0xaa, 0xaa, 0xaa); |
171 | 31211df1 | ths | color_led = rgb_to_pixel16(0x00, 0xff, 0x00); |
172 | 31211df1 | ths | case 24: |
173 | 31211df1 | ths | color_segment = rgb_to_pixel24(0xaa, 0xaa, 0xaa); |
174 | 31211df1 | ths | color_led = rgb_to_pixel24(0x00, 0xff, 0x00); |
175 | 31211df1 | ths | break;
|
176 | 31211df1 | ths | case 32: |
177 | 31211df1 | ths | color_segment = rgb_to_pixel32(0xaa, 0xaa, 0xaa); |
178 | 31211df1 | ths | color_led = rgb_to_pixel32(0x00, 0xff, 0x00); |
179 | 31211df1 | ths | break;
|
180 | 31211df1 | ths | default:
|
181 | 31211df1 | ths | return;
|
182 | 31211df1 | ths | } |
183 | 31211df1 | ths | |
184 | 31211df1 | ths | /* display segments */
|
185 | c78f7137 | Gerd Hoffmann | draw_horizontal_line(surface, 40, 10, 40, |
186 | c78f7137 | Gerd Hoffmann | (s->segments & 0x02) ? color_segment : 0); |
187 | c78f7137 | Gerd Hoffmann | draw_vertical_line(surface, 10, 10, 40, |
188 | c78f7137 | Gerd Hoffmann | (s->segments & 0x04) ? color_segment : 0); |
189 | c78f7137 | Gerd Hoffmann | draw_vertical_line(surface, 10, 40, 70, |
190 | c78f7137 | Gerd Hoffmann | (s->segments & 0x08) ? color_segment : 0); |
191 | c78f7137 | Gerd Hoffmann | draw_horizontal_line(surface, 70, 10, 40, |
192 | c78f7137 | Gerd Hoffmann | (s->segments & 0x10) ? color_segment : 0); |
193 | c78f7137 | Gerd Hoffmann | draw_vertical_line(surface, 40, 40, 70, |
194 | c78f7137 | Gerd Hoffmann | (s->segments & 0x20) ? color_segment : 0); |
195 | c78f7137 | Gerd Hoffmann | draw_vertical_line(surface, 40, 10, 40, |
196 | c78f7137 | Gerd Hoffmann | (s->segments & 0x40) ? color_segment : 0); |
197 | c78f7137 | Gerd Hoffmann | draw_horizontal_line(surface, 10, 10, 40, |
198 | c78f7137 | Gerd Hoffmann | (s->segments & 0x80) ? color_segment : 0); |
199 | 31211df1 | ths | |
200 | 31211df1 | ths | /* display led */
|
201 | 31211df1 | ths | if (!(s->segments & 0x01)) |
202 | 31211df1 | ths | color_led = 0; /* black */ |
203 | c78f7137 | Gerd Hoffmann | draw_horizontal_line(surface, 68, 50, 50, color_led); |
204 | c78f7137 | Gerd Hoffmann | draw_horizontal_line(surface, 69, 49, 51, color_led); |
205 | c78f7137 | Gerd Hoffmann | draw_horizontal_line(surface, 70, 48, 52, color_led); |
206 | c78f7137 | Gerd Hoffmann | draw_horizontal_line(surface, 71, 49, 51, color_led); |
207 | c78f7137 | Gerd Hoffmann | draw_horizontal_line(surface, 72, 50, 50, color_led); |
208 | 31211df1 | ths | } |
209 | 31211df1 | ths | |
210 | 31211df1 | ths | s->state = REDRAW_NONE; |
211 | c78f7137 | Gerd Hoffmann | dpy_gfx_update(s->con, 0, 0, |
212 | c78f7137 | Gerd Hoffmann | surface_width(surface), surface_height(surface)); |
213 | 31211df1 | ths | } |
214 | 31211df1 | ths | |
215 | 31211df1 | ths | static void jazz_led_invalidate_display(void *opaque) |
216 | 31211df1 | ths | { |
217 | 31211df1 | ths | LedState *s = opaque; |
218 | 31211df1 | ths | s->state |= REDRAW_SEGMENTS | REDRAW_BACKGROUND; |
219 | 31211df1 | ths | } |
220 | 31211df1 | ths | |
221 | c227f099 | Anthony Liguori | static void jazz_led_text_update(void *opaque, console_ch_t *chardata) |
222 | 4d3b6f6e | balrog | { |
223 | 4d3b6f6e | balrog | LedState *s = opaque; |
224 | 4d3b6f6e | balrog | char buf[2]; |
225 | 4d3b6f6e | balrog | |
226 | c78f7137 | Gerd Hoffmann | dpy_text_cursor(s->con, -1, -1); |
227 | c78f7137 | Gerd Hoffmann | qemu_console_resize(s->con, 2, 1); |
228 | 4d3b6f6e | balrog | |
229 | 4d3b6f6e | balrog | /* TODO: draw the segments */
|
230 | 4d3b6f6e | balrog | snprintf(buf, 2, "%02hhx\n", s->segments); |
231 | 4d3b6f6e | balrog | console_write_ch(chardata++, 0x00200100 | buf[0]); |
232 | 4d3b6f6e | balrog | console_write_ch(chardata++, 0x00200100 | buf[1]); |
233 | 4d3b6f6e | balrog | |
234 | c78f7137 | Gerd Hoffmann | dpy_text_update(s->con, 0, 0, 2, 1); |
235 | 4d3b6f6e | balrog | } |
236 | 4d3b6f6e | balrog | |
237 | b39506e4 | Hervé Poussineau | static int jazz_led_post_load(void *opaque, int version_id) |
238 | 31211df1 | ths | { |
239 | b39506e4 | Hervé Poussineau | /* force refresh */
|
240 | b39506e4 | Hervé Poussineau | jazz_led_invalidate_display(opaque); |
241 | 31211df1 | ths | |
242 | b39506e4 | Hervé Poussineau | return 0; |
243 | b39506e4 | Hervé Poussineau | } |
244 | 31211df1 | ths | |
245 | b39506e4 | Hervé Poussineau | static const VMStateDescription vmstate_jazz_led = { |
246 | b39506e4 | Hervé Poussineau | .name = "jazz-led",
|
247 | b39506e4 | Hervé Poussineau | .version_id = 0,
|
248 | b39506e4 | Hervé Poussineau | .minimum_version_id = 0,
|
249 | b39506e4 | Hervé Poussineau | .minimum_version_id_old = 0,
|
250 | b39506e4 | Hervé Poussineau | .post_load = jazz_led_post_load, |
251 | b39506e4 | Hervé Poussineau | .fields = (VMStateField[]) { |
252 | b39506e4 | Hervé Poussineau | VMSTATE_UINT8(segments, LedState), |
253 | b39506e4 | Hervé Poussineau | VMSTATE_END_OF_LIST() |
254 | b39506e4 | Hervé Poussineau | } |
255 | b39506e4 | Hervé Poussineau | }; |
256 | b39506e4 | Hervé Poussineau | |
257 | 380cd056 | Gerd Hoffmann | static const GraphicHwOps jazz_led_ops = { |
258 | 380cd056 | Gerd Hoffmann | .invalidate = jazz_led_invalidate_display, |
259 | 380cd056 | Gerd Hoffmann | .gfx_update = jazz_led_update_display, |
260 | 380cd056 | Gerd Hoffmann | .text_update = jazz_led_text_update, |
261 | 380cd056 | Gerd Hoffmann | }; |
262 | 380cd056 | Gerd Hoffmann | |
263 | b39506e4 | Hervé Poussineau | static int jazz_led_init(SysBusDevice *dev) |
264 | b39506e4 | Hervé Poussineau | { |
265 | b39506e4 | Hervé Poussineau | LedState *s = FROM_SYSBUS(LedState, dev); |
266 | 31211df1 | ths | |
267 | 2c9b15ca | Paolo Bonzini | memory_region_init_io(&s->iomem, NULL, &led_ops, s, "led", 1); |
268 | b39506e4 | Hervé Poussineau | sysbus_init_mmio(dev, &s->iomem); |
269 | 31211df1 | ths | |
270 | aa2beaa1 | Gerd Hoffmann | s->con = graphic_console_init(DEVICE(dev), &jazz_led_ops, s); |
271 | b39506e4 | Hervé Poussineau | |
272 | b39506e4 | Hervé Poussineau | return 0; |
273 | b39506e4 | Hervé Poussineau | } |
274 | b39506e4 | Hervé Poussineau | |
275 | b39506e4 | Hervé Poussineau | static void jazz_led_reset(DeviceState *d) |
276 | b39506e4 | Hervé Poussineau | { |
277 | b39506e4 | Hervé Poussineau | LedState *s = DO_UPCAST(LedState, busdev.qdev, d); |
278 | b39506e4 | Hervé Poussineau | |
279 | b39506e4 | Hervé Poussineau | s->segments = 0;
|
280 | b39506e4 | Hervé Poussineau | s->state = REDRAW_SEGMENTS | REDRAW_BACKGROUND; |
281 | c78f7137 | Gerd Hoffmann | qemu_console_resize(s->con, 60, 80); |
282 | 31211df1 | ths | } |
283 | b39506e4 | Hervé Poussineau | |
284 | b39506e4 | Hervé Poussineau | static void jazz_led_class_init(ObjectClass *klass, void *data) |
285 | b39506e4 | Hervé Poussineau | { |
286 | b39506e4 | Hervé Poussineau | DeviceClass *dc = DEVICE_CLASS(klass); |
287 | b39506e4 | Hervé Poussineau | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
288 | b39506e4 | Hervé Poussineau | |
289 | b39506e4 | Hervé Poussineau | k->init = jazz_led_init; |
290 | b39506e4 | Hervé Poussineau | dc->desc = "Jazz LED display",
|
291 | b39506e4 | Hervé Poussineau | dc->vmsd = &vmstate_jazz_led; |
292 | b39506e4 | Hervé Poussineau | dc->reset = jazz_led_reset; |
293 | b39506e4 | Hervé Poussineau | } |
294 | b39506e4 | Hervé Poussineau | |
295 | 8c43a6f0 | Andreas Färber | static const TypeInfo jazz_led_info = { |
296 | b39506e4 | Hervé Poussineau | .name = "jazz-led",
|
297 | b39506e4 | Hervé Poussineau | .parent = TYPE_SYS_BUS_DEVICE, |
298 | b39506e4 | Hervé Poussineau | .instance_size = sizeof(LedState),
|
299 | b39506e4 | Hervé Poussineau | .class_init = jazz_led_class_init, |
300 | b39506e4 | Hervé Poussineau | }; |
301 | b39506e4 | Hervé Poussineau | |
302 | b39506e4 | Hervé Poussineau | static void jazz_led_register(void) |
303 | b39506e4 | Hervé Poussineau | { |
304 | b39506e4 | Hervé Poussineau | type_register_static(&jazz_led_info); |
305 | b39506e4 | Hervé Poussineau | } |
306 | b39506e4 | Hervé Poussineau | |
307 | b39506e4 | Hervé Poussineau | type_init(jazz_led_register); |