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