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