]>
Commit | Line | Data |
---|---|---|
420557e8 | 1 | /* |
6f7e9aec | 2 | * QEMU TCX Frame buffer |
5fafdf24 | 3 | * |
6f7e9aec | 4 | * Copyright (c) 2003-2005 Fabrice Bellard |
5fafdf24 | 5 | * |
420557e8 FB |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
23 | */ | |
f40070c3 | 24 | |
077805fa | 25 | #include "qemu-common.h" |
28ecbaee PB |
26 | #include "ui/console.h" |
27 | #include "ui/pixel_ops.h" | |
da87dd7b | 28 | #include "hw/loader.h" |
83c9f4ca | 29 | #include "hw/sysbus.h" |
d49b6836 | 30 | #include "qemu/error-report.h" |
420557e8 | 31 | |
da87dd7b MCA |
32 | #define TCX_ROM_FILE "QEMU,tcx.bin" |
33 | #define FCODE_MAX_ROM_SIZE 0x10000 | |
34 | ||
420557e8 FB |
35 | #define MAXX 1024 |
36 | #define MAXY 768 | |
55d7bfe2 MCA |
37 | #define TCX_DAC_NREGS 16 |
38 | #define TCX_THC_NREGS 0x1000 | |
39 | #define TCX_DHC_NREGS 0x4000 | |
8508b89e | 40 | #define TCX_TEC_NREGS 0x1000 |
55d7bfe2 MCA |
41 | #define TCX_ALT_NREGS 0x8000 |
42 | #define TCX_STIP_NREGS 0x800000 | |
43 | #define TCX_BLIT_NREGS 0x800000 | |
44 | #define TCX_RSTIP_NREGS 0x800000 | |
45 | #define TCX_RBLIT_NREGS 0x800000 | |
46 | ||
47 | #define TCX_THC_MISC 0x818 | |
48 | #define TCX_THC_CURSXY 0x8fc | |
49 | #define TCX_THC_CURSMASK 0x900 | |
50 | #define TCX_THC_CURSBITS 0x980 | |
420557e8 | 51 | |
01774ddb AF |
52 | #define TYPE_TCX "SUNW,tcx" |
53 | #define TCX(obj) OBJECT_CHECK(TCXState, (obj), TYPE_TCX) | |
54 | ||
420557e8 | 55 | typedef struct TCXState { |
01774ddb AF |
56 | SysBusDevice parent_obj; |
57 | ||
c78f7137 | 58 | QemuConsole *con; |
55d7bfe2 | 59 | qemu_irq irq; |
8d5f07fa | 60 | uint8_t *vram; |
eee0b836 | 61 | uint32_t *vram24, *cplane; |
da87dd7b MCA |
62 | hwaddr prom_addr; |
63 | MemoryRegion rom; | |
d08151bf AK |
64 | MemoryRegion vram_mem; |
65 | MemoryRegion vram_8bit; | |
66 | MemoryRegion vram_24bit; | |
55d7bfe2 MCA |
67 | MemoryRegion stip; |
68 | MemoryRegion blit; | |
d08151bf | 69 | MemoryRegion vram_cplane; |
55d7bfe2 MCA |
70 | MemoryRegion rstip; |
71 | MemoryRegion rblit; | |
d08151bf | 72 | MemoryRegion tec; |
55d7bfe2 MCA |
73 | MemoryRegion dac; |
74 | MemoryRegion thc; | |
75 | MemoryRegion dhc; | |
76 | MemoryRegion alt; | |
d08151bf | 77 | MemoryRegion thc24; |
55d7bfe2 | 78 | |
d08151bf | 79 | ram_addr_t vram24_offset, cplane_offset; |
55d7bfe2 | 80 | uint32_t tmpblit; |
ee6847d1 | 81 | uint32_t vram_size; |
55d7bfe2 MCA |
82 | uint32_t palette[260]; |
83 | uint8_t r[260], g[260], b[260]; | |
427a66c3 | 84 | uint16_t width, height, depth; |
6f7e9aec | 85 | uint8_t dac_index, dac_state; |
55d7bfe2 MCA |
86 | uint32_t thcmisc; |
87 | uint32_t cursmask[32]; | |
88 | uint32_t cursbits[32]; | |
89 | uint16_t cursx; | |
90 | uint16_t cursy; | |
420557e8 FB |
91 | } TCXState; |
92 | ||
d3ffcafe BS |
93 | static void tcx_set_dirty(TCXState *s) |
94 | { | |
fd4aa979 | 95 | memory_region_set_dirty(&s->vram_mem, 0, MAXX * MAXY); |
d3ffcafe BS |
96 | } |
97 | ||
55d7bfe2 MCA |
98 | static inline int tcx24_check_dirty(TCXState *s, ram_addr_t page, |
99 | ram_addr_t page24, ram_addr_t cpage) | |
d3ffcafe | 100 | { |
55d7bfe2 MCA |
101 | int ret; |
102 | ||
103 | ret = memory_region_get_dirty(&s->vram_mem, page, TARGET_PAGE_SIZE, | |
104 | DIRTY_MEMORY_VGA); | |
105 | ret |= memory_region_get_dirty(&s->vram_mem, page24, TARGET_PAGE_SIZE * 4, | |
106 | DIRTY_MEMORY_VGA); | |
107 | ret |= memory_region_get_dirty(&s->vram_mem, cpage, TARGET_PAGE_SIZE * 4, | |
108 | DIRTY_MEMORY_VGA); | |
109 | return ret; | |
110 | } | |
111 | ||
112 | static inline void tcx24_reset_dirty(TCXState *ts, ram_addr_t page_min, | |
113 | ram_addr_t page_max, ram_addr_t page24, | |
114 | ram_addr_t cpage) | |
115 | { | |
116 | memory_region_reset_dirty(&ts->vram_mem, | |
117 | page_min, | |
118 | (page_max - page_min) + TARGET_PAGE_SIZE, | |
119 | DIRTY_MEMORY_VGA); | |
120 | memory_region_reset_dirty(&ts->vram_mem, | |
121 | page24 + page_min * 4, | |
122 | (page_max - page_min) * 4 + TARGET_PAGE_SIZE, | |
123 | DIRTY_MEMORY_VGA); | |
124 | memory_region_reset_dirty(&ts->vram_mem, | |
125 | cpage + page_min * 4, | |
126 | (page_max - page_min) * 4 + TARGET_PAGE_SIZE, | |
127 | DIRTY_MEMORY_VGA); | |
d3ffcafe | 128 | } |
95219897 | 129 | |
21206a10 FB |
130 | static void update_palette_entries(TCXState *s, int start, int end) |
131 | { | |
c78f7137 | 132 | DisplaySurface *surface = qemu_console_surface(s->con); |
21206a10 | 133 | int i; |
c78f7137 GH |
134 | |
135 | for (i = start; i < end; i++) { | |
136 | switch (surface_bits_per_pixel(surface)) { | |
21206a10 FB |
137 | default: |
138 | case 8: | |
139 | s->palette[i] = rgb_to_pixel8(s->r[i], s->g[i], s->b[i]); | |
140 | break; | |
141 | case 15: | |
8927bcfd | 142 | s->palette[i] = rgb_to_pixel15(s->r[i], s->g[i], s->b[i]); |
21206a10 FB |
143 | break; |
144 | case 16: | |
8927bcfd | 145 | s->palette[i] = rgb_to_pixel16(s->r[i], s->g[i], s->b[i]); |
21206a10 FB |
146 | break; |
147 | case 32: | |
c78f7137 | 148 | if (is_surface_bgr(surface)) { |
7b5d76da | 149 | s->palette[i] = rgb_to_pixel32bgr(s->r[i], s->g[i], s->b[i]); |
c78f7137 | 150 | } else { |
7b5d76da | 151 | s->palette[i] = rgb_to_pixel32(s->r[i], s->g[i], s->b[i]); |
c78f7137 | 152 | } |
21206a10 FB |
153 | break; |
154 | } | |
155 | } | |
55d7bfe2 | 156 | tcx_set_dirty(s); |
21206a10 FB |
157 | } |
158 | ||
5fafdf24 | 159 | static void tcx_draw_line32(TCXState *s1, uint8_t *d, |
f930d07e | 160 | const uint8_t *s, int width) |
420557e8 | 161 | { |
e80cfcfc FB |
162 | int x; |
163 | uint8_t val; | |
8bdc2159 | 164 | uint32_t *p = (uint32_t *)d; |
e80cfcfc | 165 | |
55d7bfe2 | 166 | for (x = 0; x < width; x++) { |
f930d07e | 167 | val = *s++; |
8bdc2159 | 168 | *p++ = s1->palette[val]; |
e80cfcfc | 169 | } |
420557e8 FB |
170 | } |
171 | ||
5fafdf24 | 172 | static void tcx_draw_line16(TCXState *s1, uint8_t *d, |
f930d07e | 173 | const uint8_t *s, int width) |
e80cfcfc FB |
174 | { |
175 | int x; | |
176 | uint8_t val; | |
8bdc2159 | 177 | uint16_t *p = (uint16_t *)d; |
8d5f07fa | 178 | |
55d7bfe2 | 179 | for (x = 0; x < width; x++) { |
f930d07e | 180 | val = *s++; |
8bdc2159 | 181 | *p++ = s1->palette[val]; |
e80cfcfc FB |
182 | } |
183 | } | |
184 | ||
5fafdf24 | 185 | static void tcx_draw_line8(TCXState *s1, uint8_t *d, |
f930d07e | 186 | const uint8_t *s, int width) |
420557e8 | 187 | { |
e80cfcfc FB |
188 | int x; |
189 | uint8_t val; | |
190 | ||
191 | for(x = 0; x < width; x++) { | |
f930d07e | 192 | val = *s++; |
21206a10 | 193 | *d++ = s1->palette[val]; |
420557e8 | 194 | } |
420557e8 FB |
195 | } |
196 | ||
55d7bfe2 MCA |
197 | static void tcx_draw_cursor32(TCXState *s1, uint8_t *d, |
198 | int y, int width) | |
199 | { | |
200 | int x, len; | |
201 | uint32_t mask, bits; | |
202 | uint32_t *p = (uint32_t *)d; | |
203 | ||
204 | y = y - s1->cursy; | |
205 | mask = s1->cursmask[y]; | |
206 | bits = s1->cursbits[y]; | |
207 | len = MIN(width - s1->cursx, 32); | |
208 | p = &p[s1->cursx]; | |
209 | for (x = 0; x < len; x++) { | |
210 | if (mask & 0x80000000) { | |
211 | if (bits & 0x80000000) { | |
212 | *p = s1->palette[259]; | |
213 | } else { | |
214 | *p = s1->palette[258]; | |
215 | } | |
216 | } | |
217 | p++; | |
218 | mask <<= 1; | |
219 | bits <<= 1; | |
220 | } | |
221 | } | |
222 | ||
223 | static void tcx_draw_cursor16(TCXState *s1, uint8_t *d, | |
224 | int y, int width) | |
225 | { | |
226 | int x, len; | |
227 | uint32_t mask, bits; | |
228 | uint16_t *p = (uint16_t *)d; | |
229 | ||
230 | y = y - s1->cursy; | |
231 | mask = s1->cursmask[y]; | |
232 | bits = s1->cursbits[y]; | |
233 | len = MIN(width - s1->cursx, 32); | |
234 | p = &p[s1->cursx]; | |
235 | for (x = 0; x < len; x++) { | |
236 | if (mask & 0x80000000) { | |
237 | if (bits & 0x80000000) { | |
238 | *p = s1->palette[259]; | |
239 | } else { | |
240 | *p = s1->palette[258]; | |
241 | } | |
242 | } | |
243 | p++; | |
244 | mask <<= 1; | |
245 | bits <<= 1; | |
246 | } | |
247 | } | |
248 | ||
249 | static void tcx_draw_cursor8(TCXState *s1, uint8_t *d, | |
250 | int y, int width) | |
251 | { | |
252 | int x, len; | |
253 | uint32_t mask, bits; | |
254 | ||
255 | y = y - s1->cursy; | |
256 | mask = s1->cursmask[y]; | |
257 | bits = s1->cursbits[y]; | |
258 | len = MIN(width - s1->cursx, 32); | |
259 | d = &d[s1->cursx]; | |
260 | for (x = 0; x < len; x++) { | |
261 | if (mask & 0x80000000) { | |
262 | if (bits & 0x80000000) { | |
263 | *d = s1->palette[259]; | |
264 | } else { | |
265 | *d = s1->palette[258]; | |
266 | } | |
267 | } | |
268 | d++; | |
269 | mask <<= 1; | |
270 | bits <<= 1; | |
271 | } | |
272 | } | |
273 | ||
688ea2eb BS |
274 | /* |
275 | XXX Could be much more optimal: | |
276 | * detect if line/page/whole screen is in 24 bit mode | |
277 | * if destination is also BGR, use memcpy | |
278 | */ | |
eee0b836 BS |
279 | static inline void tcx24_draw_line32(TCXState *s1, uint8_t *d, |
280 | const uint8_t *s, int width, | |
281 | const uint32_t *cplane, | |
282 | const uint32_t *s24) | |
283 | { | |
c78f7137 | 284 | DisplaySurface *surface = qemu_console_surface(s1->con); |
7b5d76da | 285 | int x, bgr, r, g, b; |
688ea2eb | 286 | uint8_t val, *p8; |
eee0b836 BS |
287 | uint32_t *p = (uint32_t *)d; |
288 | uint32_t dval; | |
c78f7137 | 289 | bgr = is_surface_bgr(surface); |
eee0b836 | 290 | for(x = 0; x < width; x++, s++, s24++) { |
55d7bfe2 MCA |
291 | if (be32_to_cpu(*cplane) & 0x03000000) { |
292 | /* 24-bit direct, BGR order */ | |
688ea2eb BS |
293 | p8 = (uint8_t *)s24; |
294 | p8++; | |
295 | b = *p8++; | |
296 | g = *p8++; | |
f7e683b8 | 297 | r = *p8; |
7b5d76da AL |
298 | if (bgr) |
299 | dval = rgb_to_pixel32bgr(r, g, b); | |
300 | else | |
301 | dval = rgb_to_pixel32(r, g, b); | |
eee0b836 | 302 | } else { |
55d7bfe2 | 303 | /* 8-bit pseudocolor */ |
eee0b836 BS |
304 | val = *s; |
305 | dval = s1->palette[val]; | |
306 | } | |
307 | *p++ = dval; | |
55d7bfe2 | 308 | cplane++; |
eee0b836 BS |
309 | } |
310 | } | |
311 | ||
e80cfcfc FB |
312 | /* Fixed line length 1024 allows us to do nice tricks not possible on |
313 | VGA... */ | |
55d7bfe2 | 314 | |
95219897 | 315 | static void tcx_update_display(void *opaque) |
420557e8 | 316 | { |
e80cfcfc | 317 | TCXState *ts = opaque; |
c78f7137 | 318 | DisplaySurface *surface = qemu_console_surface(ts->con); |
c227f099 | 319 | ram_addr_t page, page_min, page_max; |
550be127 | 320 | int y, y_start, dd, ds; |
e80cfcfc | 321 | uint8_t *d, *s; |
b3ceef24 | 322 | void (*f)(TCXState *s1, uint8_t *dst, const uint8_t *src, int width); |
55d7bfe2 | 323 | void (*fc)(TCXState *s1, uint8_t *dst, int y, int width); |
e80cfcfc | 324 | |
c78f7137 | 325 | if (surface_bits_per_pixel(surface) == 0) { |
f930d07e | 326 | return; |
c78f7137 GH |
327 | } |
328 | ||
d08151bf | 329 | page = 0; |
e80cfcfc | 330 | y_start = -1; |
c0c440f3 | 331 | page_min = -1; |
550be127 | 332 | page_max = 0; |
c78f7137 | 333 | d = surface_data(surface); |
6f7e9aec | 334 | s = ts->vram; |
c78f7137 | 335 | dd = surface_stride(surface); |
e80cfcfc FB |
336 | ds = 1024; |
337 | ||
c78f7137 | 338 | switch (surface_bits_per_pixel(surface)) { |
e80cfcfc | 339 | case 32: |
f930d07e | 340 | f = tcx_draw_line32; |
55d7bfe2 | 341 | fc = tcx_draw_cursor32; |
f930d07e | 342 | break; |
21206a10 FB |
343 | case 15: |
344 | case 16: | |
f930d07e | 345 | f = tcx_draw_line16; |
55d7bfe2 | 346 | fc = tcx_draw_cursor16; |
f930d07e | 347 | break; |
e80cfcfc FB |
348 | default: |
349 | case 8: | |
f930d07e | 350 | f = tcx_draw_line8; |
55d7bfe2 | 351 | fc = tcx_draw_cursor8; |
f930d07e | 352 | break; |
e80cfcfc | 353 | case 0: |
f930d07e | 354 | return; |
e80cfcfc | 355 | } |
3b46e624 | 356 | |
5299c0f2 | 357 | memory_region_sync_dirty_bitmap(&ts->vram_mem); |
55d7bfe2 | 358 | for (y = 0; y < ts->height; page += TARGET_PAGE_SIZE) { |
cd7a45c9 BS |
359 | if (memory_region_get_dirty(&ts->vram_mem, page, TARGET_PAGE_SIZE, |
360 | DIRTY_MEMORY_VGA)) { | |
f930d07e | 361 | if (y_start < 0) |
e80cfcfc FB |
362 | y_start = y; |
363 | if (page < page_min) | |
364 | page_min = page; | |
365 | if (page > page_max) | |
366 | page_max = page; | |
55d7bfe2 | 367 | |
f930d07e | 368 | f(ts, d, s, ts->width); |
55d7bfe2 MCA |
369 | if (y >= ts->cursy && y < ts->cursy + 32 && ts->cursx < ts->width) { |
370 | fc(ts, d, y, ts->width); | |
371 | } | |
f930d07e BS |
372 | d += dd; |
373 | s += ds; | |
55d7bfe2 MCA |
374 | y++; |
375 | ||
f930d07e | 376 | f(ts, d, s, ts->width); |
55d7bfe2 MCA |
377 | if (y >= ts->cursy && y < ts->cursy + 32 && ts->cursx < ts->width) { |
378 | fc(ts, d, y, ts->width); | |
379 | } | |
f930d07e BS |
380 | d += dd; |
381 | s += ds; | |
55d7bfe2 MCA |
382 | y++; |
383 | ||
f930d07e | 384 | f(ts, d, s, ts->width); |
55d7bfe2 MCA |
385 | if (y >= ts->cursy && y < ts->cursy + 32 && ts->cursx < ts->width) { |
386 | fc(ts, d, y, ts->width); | |
387 | } | |
f930d07e BS |
388 | d += dd; |
389 | s += ds; | |
55d7bfe2 MCA |
390 | y++; |
391 | ||
f930d07e | 392 | f(ts, d, s, ts->width); |
55d7bfe2 MCA |
393 | if (y >= ts->cursy && y < ts->cursy + 32 && ts->cursx < ts->width) { |
394 | fc(ts, d, y, ts->width); | |
395 | } | |
f930d07e BS |
396 | d += dd; |
397 | s += ds; | |
55d7bfe2 | 398 | y++; |
f930d07e | 399 | } else { |
e80cfcfc FB |
400 | if (y_start >= 0) { |
401 | /* flush to display */ | |
c78f7137 | 402 | dpy_gfx_update(ts->con, 0, y_start, |
a93a4a22 | 403 | ts->width, y - y_start); |
e80cfcfc FB |
404 | y_start = -1; |
405 | } | |
f930d07e BS |
406 | d += dd * 4; |
407 | s += ds * 4; | |
55d7bfe2 | 408 | y += 4; |
f930d07e | 409 | } |
e80cfcfc FB |
410 | } |
411 | if (y_start >= 0) { | |
f930d07e | 412 | /* flush to display */ |
c78f7137 | 413 | dpy_gfx_update(ts->con, 0, y_start, |
a93a4a22 | 414 | ts->width, y - y_start); |
e80cfcfc FB |
415 | } |
416 | /* reset modified pages */ | |
c0c440f3 | 417 | if (page_max >= page_min) { |
d08151bf | 418 | memory_region_reset_dirty(&ts->vram_mem, |
f10acc8b MCA |
419 | page_min, |
420 | (page_max - page_min) + TARGET_PAGE_SIZE, | |
d08151bf | 421 | DIRTY_MEMORY_VGA); |
e80cfcfc | 422 | } |
420557e8 FB |
423 | } |
424 | ||
eee0b836 BS |
425 | static void tcx24_update_display(void *opaque) |
426 | { | |
427 | TCXState *ts = opaque; | |
c78f7137 | 428 | DisplaySurface *surface = qemu_console_surface(ts->con); |
c227f099 | 429 | ram_addr_t page, page_min, page_max, cpage, page24; |
eee0b836 BS |
430 | int y, y_start, dd, ds; |
431 | uint8_t *d, *s; | |
432 | uint32_t *cptr, *s24; | |
433 | ||
c78f7137 | 434 | if (surface_bits_per_pixel(surface) != 32) { |
eee0b836 | 435 | return; |
c78f7137 GH |
436 | } |
437 | ||
d08151bf | 438 | page = 0; |
eee0b836 BS |
439 | page24 = ts->vram24_offset; |
440 | cpage = ts->cplane_offset; | |
441 | y_start = -1; | |
c0c440f3 | 442 | page_min = -1; |
eee0b836 | 443 | page_max = 0; |
c78f7137 | 444 | d = surface_data(surface); |
eee0b836 BS |
445 | s = ts->vram; |
446 | s24 = ts->vram24; | |
447 | cptr = ts->cplane; | |
c78f7137 | 448 | dd = surface_stride(surface); |
eee0b836 BS |
449 | ds = 1024; |
450 | ||
5299c0f2 | 451 | memory_region_sync_dirty_bitmap(&ts->vram_mem); |
55d7bfe2 | 452 | for (y = 0; y < ts->height; page += TARGET_PAGE_SIZE, |
eee0b836 | 453 | page24 += TARGET_PAGE_SIZE, cpage += TARGET_PAGE_SIZE) { |
55d7bfe2 | 454 | if (tcx24_check_dirty(ts, page, page24, cpage)) { |
eee0b836 BS |
455 | if (y_start < 0) |
456 | y_start = y; | |
457 | if (page < page_min) | |
458 | page_min = page; | |
459 | if (page > page_max) | |
460 | page_max = page; | |
461 | tcx24_draw_line32(ts, d, s, ts->width, cptr, s24); | |
55d7bfe2 MCA |
462 | if (y >= ts->cursy && y < ts->cursy+32 && ts->cursx < ts->width) { |
463 | tcx_draw_cursor32(ts, d, y, ts->width); | |
464 | } | |
eee0b836 BS |
465 | d += dd; |
466 | s += ds; | |
467 | cptr += ds; | |
468 | s24 += ds; | |
55d7bfe2 | 469 | y++; |
eee0b836 | 470 | tcx24_draw_line32(ts, d, s, ts->width, cptr, s24); |
55d7bfe2 MCA |
471 | if (y >= ts->cursy && y < ts->cursy+32 && ts->cursx < ts->width) { |
472 | tcx_draw_cursor32(ts, d, y, ts->width); | |
473 | } | |
eee0b836 BS |
474 | d += dd; |
475 | s += ds; | |
476 | cptr += ds; | |
477 | s24 += ds; | |
55d7bfe2 | 478 | y++; |
eee0b836 | 479 | tcx24_draw_line32(ts, d, s, ts->width, cptr, s24); |
55d7bfe2 MCA |
480 | if (y >= ts->cursy && y < ts->cursy+32 && ts->cursx < ts->width) { |
481 | tcx_draw_cursor32(ts, d, y, ts->width); | |
482 | } | |
eee0b836 BS |
483 | d += dd; |
484 | s += ds; | |
485 | cptr += ds; | |
486 | s24 += ds; | |
55d7bfe2 | 487 | y++; |
eee0b836 | 488 | tcx24_draw_line32(ts, d, s, ts->width, cptr, s24); |
55d7bfe2 MCA |
489 | if (y >= ts->cursy && y < ts->cursy+32 && ts->cursx < ts->width) { |
490 | tcx_draw_cursor32(ts, d, y, ts->width); | |
491 | } | |
eee0b836 BS |
492 | d += dd; |
493 | s += ds; | |
494 | cptr += ds; | |
495 | s24 += ds; | |
55d7bfe2 | 496 | y++; |
eee0b836 BS |
497 | } else { |
498 | if (y_start >= 0) { | |
499 | /* flush to display */ | |
c78f7137 | 500 | dpy_gfx_update(ts->con, 0, y_start, |
a93a4a22 | 501 | ts->width, y - y_start); |
eee0b836 BS |
502 | y_start = -1; |
503 | } | |
504 | d += dd * 4; | |
505 | s += ds * 4; | |
506 | cptr += ds * 4; | |
507 | s24 += ds * 4; | |
55d7bfe2 | 508 | y += 4; |
eee0b836 BS |
509 | } |
510 | } | |
511 | if (y_start >= 0) { | |
512 | /* flush to display */ | |
c78f7137 | 513 | dpy_gfx_update(ts->con, 0, y_start, |
a93a4a22 | 514 | ts->width, y - y_start); |
eee0b836 BS |
515 | } |
516 | /* reset modified pages */ | |
c0c440f3 | 517 | if (page_max >= page_min) { |
55d7bfe2 | 518 | tcx24_reset_dirty(ts, page_min, page_max, page24, cpage); |
eee0b836 BS |
519 | } |
520 | } | |
521 | ||
95219897 | 522 | static void tcx_invalidate_display(void *opaque) |
420557e8 | 523 | { |
e80cfcfc | 524 | TCXState *s = opaque; |
e80cfcfc | 525 | |
d3ffcafe | 526 | tcx_set_dirty(s); |
c78f7137 | 527 | qemu_console_resize(s->con, s->width, s->height); |
420557e8 FB |
528 | } |
529 | ||
eee0b836 BS |
530 | static void tcx24_invalidate_display(void *opaque) |
531 | { | |
532 | TCXState *s = opaque; | |
eee0b836 | 533 | |
d3ffcafe | 534 | tcx_set_dirty(s); |
c78f7137 | 535 | qemu_console_resize(s->con, s->width, s->height); |
eee0b836 BS |
536 | } |
537 | ||
e59fb374 | 538 | static int vmstate_tcx_post_load(void *opaque, int version_id) |
420557e8 FB |
539 | { |
540 | TCXState *s = opaque; | |
3b46e624 | 541 | |
21206a10 | 542 | update_palette_entries(s, 0, 256); |
55d7bfe2 | 543 | tcx_set_dirty(s); |
e80cfcfc | 544 | return 0; |
420557e8 FB |
545 | } |
546 | ||
c0c41a4b BS |
547 | static const VMStateDescription vmstate_tcx = { |
548 | .name ="tcx", | |
549 | .version_id = 4, | |
550 | .minimum_version_id = 4, | |
752ff2fa | 551 | .post_load = vmstate_tcx_post_load, |
35d08458 | 552 | .fields = (VMStateField[]) { |
c0c41a4b BS |
553 | VMSTATE_UINT16(height, TCXState), |
554 | VMSTATE_UINT16(width, TCXState), | |
555 | VMSTATE_UINT16(depth, TCXState), | |
556 | VMSTATE_BUFFER(r, TCXState), | |
557 | VMSTATE_BUFFER(g, TCXState), | |
558 | VMSTATE_BUFFER(b, TCXState), | |
559 | VMSTATE_UINT8(dac_index, TCXState), | |
560 | VMSTATE_UINT8(dac_state, TCXState), | |
561 | VMSTATE_END_OF_LIST() | |
562 | } | |
563 | }; | |
564 | ||
7f23f812 | 565 | static void tcx_reset(DeviceState *d) |
420557e8 | 566 | { |
01774ddb | 567 | TCXState *s = TCX(d); |
e80cfcfc FB |
568 | |
569 | /* Initialize palette */ | |
55d7bfe2 MCA |
570 | memset(s->r, 0, 260); |
571 | memset(s->g, 0, 260); | |
572 | memset(s->b, 0, 260); | |
e80cfcfc | 573 | s->r[255] = s->g[255] = s->b[255] = 255; |
55d7bfe2 MCA |
574 | s->r[256] = s->g[256] = s->b[256] = 255; |
575 | s->r[258] = s->g[258] = s->b[258] = 255; | |
576 | update_palette_entries(s, 0, 260); | |
e80cfcfc | 577 | memset(s->vram, 0, MAXX*MAXY); |
d08151bf AK |
578 | memory_region_reset_dirty(&s->vram_mem, 0, MAXX * MAXY * (1 + 4 + 4), |
579 | DIRTY_MEMORY_VGA); | |
6f7e9aec FB |
580 | s->dac_index = 0; |
581 | s->dac_state = 0; | |
55d7bfe2 MCA |
582 | s->cursx = 0xf000; /* Put cursor off screen */ |
583 | s->cursy = 0xf000; | |
6f7e9aec FB |
584 | } |
585 | ||
a8170e5e | 586 | static uint64_t tcx_dac_readl(void *opaque, hwaddr addr, |
d08151bf | 587 | unsigned size) |
6f7e9aec | 588 | { |
55d7bfe2 MCA |
589 | TCXState *s = opaque; |
590 | uint32_t val = 0; | |
591 | ||
592 | switch (s->dac_state) { | |
593 | case 0: | |
594 | val = s->r[s->dac_index] << 24; | |
595 | s->dac_state++; | |
596 | break; | |
597 | case 1: | |
598 | val = s->g[s->dac_index] << 24; | |
599 | s->dac_state++; | |
600 | break; | |
601 | case 2: | |
602 | val = s->b[s->dac_index] << 24; | |
603 | s->dac_index = (s->dac_index + 1) & 0xff; /* Index autoincrement */ | |
604 | default: | |
605 | s->dac_state = 0; | |
606 | break; | |
607 | } | |
608 | ||
609 | return val; | |
6f7e9aec FB |
610 | } |
611 | ||
a8170e5e | 612 | static void tcx_dac_writel(void *opaque, hwaddr addr, uint64_t val, |
d08151bf | 613 | unsigned size) |
6f7e9aec FB |
614 | { |
615 | TCXState *s = opaque; | |
55d7bfe2 | 616 | unsigned index; |
6f7e9aec | 617 | |
e64d7d59 | 618 | switch (addr) { |
55d7bfe2 | 619 | case 0: /* Address */ |
f930d07e BS |
620 | s->dac_index = val >> 24; |
621 | s->dac_state = 0; | |
622 | break; | |
55d7bfe2 MCA |
623 | case 4: /* Pixel colours */ |
624 | case 12: /* Overlay (cursor) colours */ | |
625 | if (addr & 8) { | |
626 | index = (s->dac_index & 3) + 256; | |
627 | } else { | |
628 | index = s->dac_index; | |
629 | } | |
f930d07e BS |
630 | switch (s->dac_state) { |
631 | case 0: | |
55d7bfe2 MCA |
632 | s->r[index] = val >> 24; |
633 | update_palette_entries(s, index, index + 1); | |
f930d07e BS |
634 | s->dac_state++; |
635 | break; | |
636 | case 1: | |
55d7bfe2 MCA |
637 | s->g[index] = val >> 24; |
638 | update_palette_entries(s, index, index + 1); | |
f930d07e BS |
639 | s->dac_state++; |
640 | break; | |
641 | case 2: | |
55d7bfe2 MCA |
642 | s->b[index] = val >> 24; |
643 | update_palette_entries(s, index, index + 1); | |
644 | s->dac_index = (s->dac_index + 1) & 0xff; /* Index autoincrement */ | |
f930d07e BS |
645 | default: |
646 | s->dac_state = 0; | |
647 | break; | |
648 | } | |
649 | break; | |
55d7bfe2 | 650 | default: /* Control registers */ |
f930d07e | 651 | break; |
6f7e9aec | 652 | } |
420557e8 FB |
653 | } |
654 | ||
d08151bf AK |
655 | static const MemoryRegionOps tcx_dac_ops = { |
656 | .read = tcx_dac_readl, | |
657 | .write = tcx_dac_writel, | |
658 | .endianness = DEVICE_NATIVE_ENDIAN, | |
659 | .valid = { | |
660 | .min_access_size = 4, | |
661 | .max_access_size = 4, | |
662 | }, | |
6f7e9aec FB |
663 | }; |
664 | ||
55d7bfe2 MCA |
665 | static uint64_t tcx_stip_readl(void *opaque, hwaddr addr, |
666 | unsigned size) | |
667 | { | |
668 | return 0; | |
669 | } | |
670 | ||
671 | static void tcx_stip_writel(void *opaque, hwaddr addr, | |
672 | uint64_t val, unsigned size) | |
673 | { | |
674 | TCXState *s = opaque; | |
675 | int i; | |
676 | uint32_t col; | |
677 | ||
678 | if (!(addr & 4)) { | |
679 | s->tmpblit = val; | |
680 | } else { | |
681 | addr = (addr >> 3) & 0xfffff; | |
682 | col = cpu_to_be32(s->tmpblit); | |
683 | if (s->depth == 24) { | |
684 | for (i = 0; i < 32; i++) { | |
685 | if (val & 0x80000000) { | |
686 | s->vram[addr + i] = s->tmpblit; | |
687 | s->vram24[addr + i] = col; | |
688 | } | |
689 | val <<= 1; | |
690 | } | |
691 | } else { | |
692 | for (i = 0; i < 32; i++) { | |
693 | if (val & 0x80000000) { | |
694 | s->vram[addr + i] = s->tmpblit; | |
695 | } | |
696 | val <<= 1; | |
697 | } | |
698 | } | |
699 | memory_region_set_dirty(&s->vram_mem, addr, 32); | |
700 | } | |
701 | } | |
702 | ||
703 | static void tcx_rstip_writel(void *opaque, hwaddr addr, | |
704 | uint64_t val, unsigned size) | |
705 | { | |
706 | TCXState *s = opaque; | |
707 | int i; | |
708 | uint32_t col; | |
709 | ||
710 | if (!(addr & 4)) { | |
711 | s->tmpblit = val; | |
712 | } else { | |
713 | addr = (addr >> 3) & 0xfffff; | |
714 | col = cpu_to_be32(s->tmpblit); | |
715 | if (s->depth == 24) { | |
716 | for (i = 0; i < 32; i++) { | |
717 | if (val & 0x80000000) { | |
718 | s->vram[addr + i] = s->tmpblit; | |
719 | s->vram24[addr + i] = col; | |
720 | s->cplane[addr + i] = col; | |
721 | } | |
722 | val <<= 1; | |
723 | } | |
724 | } else { | |
725 | for (i = 0; i < 32; i++) { | |
726 | if (val & 0x80000000) { | |
727 | s->vram[addr + i] = s->tmpblit; | |
728 | } | |
729 | val <<= 1; | |
730 | } | |
731 | } | |
732 | memory_region_set_dirty(&s->vram_mem, addr, 32); | |
733 | } | |
734 | } | |
735 | ||
736 | static const MemoryRegionOps tcx_stip_ops = { | |
737 | .read = tcx_stip_readl, | |
738 | .write = tcx_stip_writel, | |
739 | .endianness = DEVICE_NATIVE_ENDIAN, | |
740 | .valid = { | |
741 | .min_access_size = 4, | |
742 | .max_access_size = 4, | |
743 | }, | |
744 | }; | |
745 | ||
746 | static const MemoryRegionOps tcx_rstip_ops = { | |
747 | .read = tcx_stip_readl, | |
748 | .write = tcx_rstip_writel, | |
749 | .endianness = DEVICE_NATIVE_ENDIAN, | |
750 | .valid = { | |
751 | .min_access_size = 4, | |
752 | .max_access_size = 4, | |
753 | }, | |
754 | }; | |
755 | ||
756 | static uint64_t tcx_blit_readl(void *opaque, hwaddr addr, | |
757 | unsigned size) | |
758 | { | |
759 | return 0; | |
760 | } | |
761 | ||
762 | static void tcx_blit_writel(void *opaque, hwaddr addr, | |
763 | uint64_t val, unsigned size) | |
764 | { | |
765 | TCXState *s = opaque; | |
766 | uint32_t adsr, len; | |
767 | int i; | |
768 | ||
769 | if (!(addr & 4)) { | |
770 | s->tmpblit = val; | |
771 | } else { | |
772 | addr = (addr >> 3) & 0xfffff; | |
773 | adsr = val & 0xffffff; | |
774 | len = ((val >> 24) & 0x1f) + 1; | |
775 | if (adsr == 0xffffff) { | |
776 | memset(&s->vram[addr], s->tmpblit, len); | |
777 | if (s->depth == 24) { | |
778 | val = s->tmpblit & 0xffffff; | |
779 | val = cpu_to_be32(val); | |
780 | for (i = 0; i < len; i++) { | |
781 | s->vram24[addr + i] = val; | |
782 | } | |
783 | } | |
784 | } else { | |
785 | memcpy(&s->vram[addr], &s->vram[adsr], len); | |
786 | if (s->depth == 24) { | |
787 | memcpy(&s->vram24[addr], &s->vram24[adsr], len * 4); | |
788 | } | |
789 | } | |
790 | memory_region_set_dirty(&s->vram_mem, addr, len); | |
791 | } | |
792 | } | |
793 | ||
794 | static void tcx_rblit_writel(void *opaque, hwaddr addr, | |
795 | uint64_t val, unsigned size) | |
796 | { | |
797 | TCXState *s = opaque; | |
798 | uint32_t adsr, len; | |
799 | int i; | |
800 | ||
801 | if (!(addr & 4)) { | |
802 | s->tmpblit = val; | |
803 | } else { | |
804 | addr = (addr >> 3) & 0xfffff; | |
805 | adsr = val & 0xffffff; | |
806 | len = ((val >> 24) & 0x1f) + 1; | |
807 | if (adsr == 0xffffff) { | |
808 | memset(&s->vram[addr], s->tmpblit, len); | |
809 | if (s->depth == 24) { | |
810 | val = s->tmpblit & 0xffffff; | |
811 | val = cpu_to_be32(val); | |
812 | for (i = 0; i < len; i++) { | |
813 | s->vram24[addr + i] = val; | |
814 | s->cplane[addr + i] = val; | |
815 | } | |
816 | } | |
817 | } else { | |
818 | memcpy(&s->vram[addr], &s->vram[adsr], len); | |
819 | if (s->depth == 24) { | |
820 | memcpy(&s->vram24[addr], &s->vram24[adsr], len * 4); | |
821 | memcpy(&s->cplane[addr], &s->cplane[adsr], len * 4); | |
822 | } | |
823 | } | |
824 | memory_region_set_dirty(&s->vram_mem, addr, len); | |
825 | } | |
826 | } | |
827 | ||
828 | static const MemoryRegionOps tcx_blit_ops = { | |
829 | .read = tcx_blit_readl, | |
830 | .write = tcx_blit_writel, | |
831 | .endianness = DEVICE_NATIVE_ENDIAN, | |
832 | .valid = { | |
833 | .min_access_size = 4, | |
834 | .max_access_size = 4, | |
835 | }, | |
836 | }; | |
837 | ||
838 | static const MemoryRegionOps tcx_rblit_ops = { | |
839 | .read = tcx_blit_readl, | |
840 | .write = tcx_rblit_writel, | |
841 | .endianness = DEVICE_NATIVE_ENDIAN, | |
842 | .valid = { | |
843 | .min_access_size = 4, | |
844 | .max_access_size = 4, | |
845 | }, | |
846 | }; | |
847 | ||
848 | static void tcx_invalidate_cursor_position(TCXState *s) | |
849 | { | |
850 | int ymin, ymax, start, end; | |
851 | ||
852 | /* invalidate only near the cursor */ | |
853 | ymin = s->cursy; | |
854 | if (ymin >= s->height) { | |
855 | return; | |
856 | } | |
857 | ymax = MIN(s->height, ymin + 32); | |
858 | start = ymin * 1024; | |
859 | end = ymax * 1024; | |
860 | ||
861 | memory_region_set_dirty(&s->vram_mem, start, end-start); | |
862 | } | |
863 | ||
864 | static uint64_t tcx_thc_readl(void *opaque, hwaddr addr, | |
865 | unsigned size) | |
866 | { | |
867 | TCXState *s = opaque; | |
868 | uint64_t val; | |
869 | ||
870 | if (addr == TCX_THC_MISC) { | |
871 | val = s->thcmisc | 0x02000000; | |
872 | } else { | |
873 | val = 0; | |
874 | } | |
875 | return val; | |
876 | } | |
877 | ||
878 | static void tcx_thc_writel(void *opaque, hwaddr addr, | |
879 | uint64_t val, unsigned size) | |
880 | { | |
881 | TCXState *s = opaque; | |
882 | ||
883 | if (addr == TCX_THC_CURSXY) { | |
884 | tcx_invalidate_cursor_position(s); | |
885 | s->cursx = val >> 16; | |
886 | s->cursy = val; | |
887 | tcx_invalidate_cursor_position(s); | |
888 | } else if (addr >= TCX_THC_CURSMASK && addr < TCX_THC_CURSMASK + 128) { | |
889 | s->cursmask[(addr - TCX_THC_CURSMASK) >> 2] = val; | |
890 | tcx_invalidate_cursor_position(s); | |
891 | } else if (addr >= TCX_THC_CURSBITS && addr < TCX_THC_CURSBITS + 128) { | |
892 | s->cursbits[(addr - TCX_THC_CURSBITS) >> 2] = val; | |
893 | tcx_invalidate_cursor_position(s); | |
894 | } else if (addr == TCX_THC_MISC) { | |
895 | s->thcmisc = val; | |
896 | } | |
897 | ||
898 | } | |
899 | ||
900 | static const MemoryRegionOps tcx_thc_ops = { | |
901 | .read = tcx_thc_readl, | |
902 | .write = tcx_thc_writel, | |
903 | .endianness = DEVICE_NATIVE_ENDIAN, | |
904 | .valid = { | |
905 | .min_access_size = 4, | |
906 | .max_access_size = 4, | |
907 | }, | |
908 | }; | |
909 | ||
910 | static uint64_t tcx_dummy_readl(void *opaque, hwaddr addr, | |
d08151bf | 911 | unsigned size) |
8508b89e BS |
912 | { |
913 | return 0; | |
914 | } | |
915 | ||
55d7bfe2 | 916 | static void tcx_dummy_writel(void *opaque, hwaddr addr, |
d08151bf | 917 | uint64_t val, unsigned size) |
8508b89e | 918 | { |
55d7bfe2 | 919 | return; |
8508b89e BS |
920 | } |
921 | ||
55d7bfe2 MCA |
922 | static const MemoryRegionOps tcx_dummy_ops = { |
923 | .read = tcx_dummy_readl, | |
924 | .write = tcx_dummy_writel, | |
d08151bf AK |
925 | .endianness = DEVICE_NATIVE_ENDIAN, |
926 | .valid = { | |
927 | .min_access_size = 4, | |
928 | .max_access_size = 4, | |
929 | }, | |
8508b89e BS |
930 | }; |
931 | ||
380cd056 GH |
932 | static const GraphicHwOps tcx_ops = { |
933 | .invalidate = tcx_invalidate_display, | |
934 | .gfx_update = tcx_update_display, | |
935 | }; | |
936 | ||
937 | static const GraphicHwOps tcx24_ops = { | |
938 | .invalidate = tcx24_invalidate_display, | |
939 | .gfx_update = tcx24_update_display, | |
940 | }; | |
941 | ||
01b91ac2 MCA |
942 | static void tcx_initfn(Object *obj) |
943 | { | |
944 | SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | |
945 | TCXState *s = TCX(obj); | |
946 | ||
b21de199 | 947 | memory_region_init_ram(&s->rom, obj, "tcx.prom", FCODE_MAX_ROM_SIZE, |
f8ed85ac | 948 | &error_fatal); |
01b91ac2 MCA |
949 | memory_region_set_readonly(&s->rom, true); |
950 | sysbus_init_mmio(sbd, &s->rom); | |
951 | ||
55d7bfe2 | 952 | /* 2/STIP : Stippler */ |
b21de199 | 953 | memory_region_init_io(&s->stip, obj, &tcx_stip_ops, s, "tcx.stip", |
55d7bfe2 MCA |
954 | TCX_STIP_NREGS); |
955 | sysbus_init_mmio(sbd, &s->stip); | |
956 | ||
957 | /* 3/BLIT : Blitter */ | |
b21de199 | 958 | memory_region_init_io(&s->blit, obj, &tcx_blit_ops, s, "tcx.blit", |
55d7bfe2 MCA |
959 | TCX_BLIT_NREGS); |
960 | sysbus_init_mmio(sbd, &s->blit); | |
961 | ||
962 | /* 5/RSTIP : Raw Stippler */ | |
b21de199 | 963 | memory_region_init_io(&s->rstip, obj, &tcx_rstip_ops, s, "tcx.rstip", |
55d7bfe2 MCA |
964 | TCX_RSTIP_NREGS); |
965 | sysbus_init_mmio(sbd, &s->rstip); | |
966 | ||
967 | /* 6/RBLIT : Raw Blitter */ | |
b21de199 | 968 | memory_region_init_io(&s->rblit, obj, &tcx_rblit_ops, s, "tcx.rblit", |
55d7bfe2 MCA |
969 | TCX_RBLIT_NREGS); |
970 | sysbus_init_mmio(sbd, &s->rblit); | |
971 | ||
972 | /* 7/TEC : ??? */ | |
b21de199 TH |
973 | memory_region_init_io(&s->tec, obj, &tcx_dummy_ops, s, "tcx.tec", |
974 | TCX_TEC_NREGS); | |
55d7bfe2 MCA |
975 | sysbus_init_mmio(sbd, &s->tec); |
976 | ||
977 | /* 8/CMAP : DAC */ | |
b21de199 TH |
978 | memory_region_init_io(&s->dac, obj, &tcx_dac_ops, s, "tcx.dac", |
979 | TCX_DAC_NREGS); | |
01b91ac2 MCA |
980 | sysbus_init_mmio(sbd, &s->dac); |
981 | ||
55d7bfe2 | 982 | /* 9/THC : Cursor */ |
b21de199 | 983 | memory_region_init_io(&s->thc, obj, &tcx_thc_ops, s, "tcx.thc", |
55d7bfe2 MCA |
984 | TCX_THC_NREGS); |
985 | sysbus_init_mmio(sbd, &s->thc); | |
01b91ac2 | 986 | |
55d7bfe2 | 987 | /* 11/DHC : ??? */ |
b21de199 | 988 | memory_region_init_io(&s->dhc, obj, &tcx_dummy_ops, s, "tcx.dhc", |
55d7bfe2 MCA |
989 | TCX_DHC_NREGS); |
990 | sysbus_init_mmio(sbd, &s->dhc); | |
991 | ||
992 | /* 12/ALT : ??? */ | |
b21de199 | 993 | memory_region_init_io(&s->alt, obj, &tcx_dummy_ops, s, "tcx.alt", |
55d7bfe2 MCA |
994 | TCX_ALT_NREGS); |
995 | sysbus_init_mmio(sbd, &s->alt); | |
01b91ac2 MCA |
996 | } |
997 | ||
d4ad9dec | 998 | static void tcx_realizefn(DeviceState *dev, Error **errp) |
f40070c3 | 999 | { |
d4ad9dec | 1000 | SysBusDevice *sbd = SYS_BUS_DEVICE(dev); |
01774ddb | 1001 | TCXState *s = TCX(dev); |
d08151bf | 1002 | ram_addr_t vram_offset = 0; |
da87dd7b | 1003 | int size, ret; |
dc828ca1 | 1004 | uint8_t *vram_base; |
da87dd7b | 1005 | char *fcode_filename; |
dc828ca1 | 1006 | |
3eadad55 | 1007 | memory_region_init_ram(&s->vram_mem, OBJECT(s), "tcx.vram", |
f8ed85ac | 1008 | s->vram_size * (1 + 4 + 4), &error_fatal); |
c5705a77 | 1009 | vmstate_register_ram_global(&s->vram_mem); |
74259ae5 | 1010 | memory_region_set_log(&s->vram_mem, true, DIRTY_MEMORY_VGA); |
d08151bf | 1011 | vram_base = memory_region_get_ram_ptr(&s->vram_mem); |
eee0b836 | 1012 | |
55d7bfe2 | 1013 | /* 10/ROM : FCode ROM */ |
da87dd7b | 1014 | vmstate_register_ram_global(&s->rom); |
da87dd7b MCA |
1015 | fcode_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, TCX_ROM_FILE); |
1016 | if (fcode_filename) { | |
1017 | ret = load_image_targphys(fcode_filename, s->prom_addr, | |
1018 | FCODE_MAX_ROM_SIZE); | |
8684e85c | 1019 | g_free(fcode_filename); |
da87dd7b | 1020 | if (ret < 0 || ret > FCODE_MAX_ROM_SIZE) { |
d4ad9dec | 1021 | error_report("tcx: could not load prom '%s'", TCX_ROM_FILE); |
da87dd7b MCA |
1022 | } |
1023 | } | |
1024 | ||
55d7bfe2 | 1025 | /* 0/DFB8 : 8-bit plane */ |
eee0b836 | 1026 | s->vram = vram_base; |
ee6847d1 | 1027 | size = s->vram_size; |
3eadad55 | 1028 | memory_region_init_alias(&s->vram_8bit, OBJECT(s), "tcx.vram.8bit", |
d08151bf | 1029 | &s->vram_mem, vram_offset, size); |
d4ad9dec | 1030 | sysbus_init_mmio(sbd, &s->vram_8bit); |
eee0b836 BS |
1031 | vram_offset += size; |
1032 | vram_base += size; | |
e80cfcfc | 1033 | |
55d7bfe2 MCA |
1034 | /* 1/DFB24 : 24bit plane */ |
1035 | size = s->vram_size * 4; | |
1036 | s->vram24 = (uint32_t *)vram_base; | |
1037 | s->vram24_offset = vram_offset; | |
1038 | memory_region_init_alias(&s->vram_24bit, OBJECT(s), "tcx.vram.24bit", | |
1039 | &s->vram_mem, vram_offset, size); | |
1040 | sysbus_init_mmio(sbd, &s->vram_24bit); | |
1041 | vram_offset += size; | |
1042 | vram_base += size; | |
1043 | ||
1044 | /* 4/RDFB32 : Raw Framebuffer */ | |
1045 | size = s->vram_size * 4; | |
1046 | s->cplane = (uint32_t *)vram_base; | |
1047 | s->cplane_offset = vram_offset; | |
1048 | memory_region_init_alias(&s->vram_cplane, OBJECT(s), "tcx.vram.cplane", | |
1049 | &s->vram_mem, vram_offset, size); | |
1050 | sysbus_init_mmio(sbd, &s->vram_cplane); | |
f40070c3 | 1051 | |
55d7bfe2 MCA |
1052 | /* 9/THC24bits : NetBSD writes here even with 8-bit display: dummy */ |
1053 | if (s->depth == 8) { | |
1054 | memory_region_init_io(&s->thc24, OBJECT(s), &tcx_dummy_ops, s, | |
1055 | "tcx.thc24", TCX_THC_NREGS); | |
1056 | sysbus_init_mmio(sbd, &s->thc24); | |
1057 | } | |
1058 | ||
1059 | sysbus_init_irq(sbd, &s->irq); | |
f40070c3 | 1060 | |
55d7bfe2 | 1061 | if (s->depth == 8) { |
5643706a | 1062 | s->con = graphic_console_init(DEVICE(dev), 0, &tcx_ops, s); |
55d7bfe2 MCA |
1063 | } else { |
1064 | s->con = graphic_console_init(DEVICE(dev), 0, &tcx24_ops, s); | |
eee0b836 | 1065 | } |
55d7bfe2 | 1066 | s->thcmisc = 0; |
e80cfcfc | 1067 | |
c78f7137 | 1068 | qemu_console_resize(s->con, s->width, s->height); |
420557e8 FB |
1069 | } |
1070 | ||
999e12bb | 1071 | static Property tcx_properties[] = { |
c7bcc85d | 1072 | DEFINE_PROP_UINT32("vram_size", TCXState, vram_size, -1), |
999e12bb AL |
1073 | DEFINE_PROP_UINT16("width", TCXState, width, -1), |
1074 | DEFINE_PROP_UINT16("height", TCXState, height, -1), | |
1075 | DEFINE_PROP_UINT16("depth", TCXState, depth, -1), | |
c7bcc85d | 1076 | DEFINE_PROP_UINT64("prom_addr", TCXState, prom_addr, -1), |
999e12bb AL |
1077 | DEFINE_PROP_END_OF_LIST(), |
1078 | }; | |
1079 | ||
1080 | static void tcx_class_init(ObjectClass *klass, void *data) | |
1081 | { | |
39bffca2 | 1082 | DeviceClass *dc = DEVICE_CLASS(klass); |
999e12bb | 1083 | |
d4ad9dec | 1084 | dc->realize = tcx_realizefn; |
39bffca2 AL |
1085 | dc->reset = tcx_reset; |
1086 | dc->vmsd = &vmstate_tcx; | |
1087 | dc->props = tcx_properties; | |
999e12bb AL |
1088 | } |
1089 | ||
8c43a6f0 | 1090 | static const TypeInfo tcx_info = { |
01774ddb | 1091 | .name = TYPE_TCX, |
39bffca2 AL |
1092 | .parent = TYPE_SYS_BUS_DEVICE, |
1093 | .instance_size = sizeof(TCXState), | |
01b91ac2 | 1094 | .instance_init = tcx_initfn, |
39bffca2 | 1095 | .class_init = tcx_class_init, |
ee6847d1 GH |
1096 | }; |
1097 | ||
83f7d43a | 1098 | static void tcx_register_types(void) |
f40070c3 | 1099 | { |
39bffca2 | 1100 | type_register_static(&tcx_info); |
f40070c3 BS |
1101 | } |
1102 | ||
83f7d43a | 1103 | type_init(tcx_register_types) |