]>
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 | */ | |
87ecb68b PB |
24 | #include "hw.h" |
25 | #include "sun4m.h" | |
26 | #include "console.h" | |
94470844 | 27 | #include "pixel_ops.h" |
420557e8 | 28 | |
420557e8 FB |
29 | #define MAXX 1024 |
30 | #define MAXY 768 | |
6f7e9aec | 31 | #define TCX_DAC_NREGS 16 |
8508b89e BS |
32 | #define TCX_THC_NREGS_8 0x081c |
33 | #define TCX_THC_NREGS_24 0x1000 | |
34 | #define TCX_TEC_NREGS 0x1000 | |
420557e8 | 35 | |
420557e8 | 36 | typedef struct TCXState { |
5dcb6b91 | 37 | target_phys_addr_t addr; |
420557e8 | 38 | DisplayState *ds; |
c60e08d9 | 39 | QEMUConsole *console; |
8d5f07fa | 40 | uint8_t *vram; |
eee0b836 BS |
41 | uint32_t *vram24, *cplane; |
42 | ram_addr_t vram_offset, vram24_offset, cplane_offset; | |
43 | uint16_t width, height, depth; | |
e80cfcfc | 44 | uint8_t r[256], g[256], b[256]; |
21206a10 | 45 | uint32_t palette[256]; |
6f7e9aec | 46 | uint8_t dac_index, dac_state; |
420557e8 FB |
47 | } TCXState; |
48 | ||
95219897 | 49 | static void tcx_screen_dump(void *opaque, const char *filename); |
eee0b836 | 50 | static void tcx24_screen_dump(void *opaque, const char *filename); |
97e7df27 BS |
51 | static void tcx_invalidate_display(void *opaque); |
52 | static void tcx24_invalidate_display(void *opaque); | |
95219897 | 53 | |
21206a10 FB |
54 | static void update_palette_entries(TCXState *s, int start, int end) |
55 | { | |
56 | int i; | |
57 | for(i = start; i < end; i++) { | |
58 | switch(s->ds->depth) { | |
59 | default: | |
60 | case 8: | |
61 | s->palette[i] = rgb_to_pixel8(s->r[i], s->g[i], s->b[i]); | |
62 | break; | |
63 | case 15: | |
b29169d2 BS |
64 | if (s->ds->bgr) |
65 | s->palette[i] = rgb_to_pixel15bgr(s->r[i], s->g[i], s->b[i]); | |
66 | else | |
67 | s->palette[i] = rgb_to_pixel15(s->r[i], s->g[i], s->b[i]); | |
21206a10 FB |
68 | break; |
69 | case 16: | |
b29169d2 BS |
70 | if (s->ds->bgr) |
71 | s->palette[i] = rgb_to_pixel16bgr(s->r[i], s->g[i], s->b[i]); | |
72 | else | |
73 | s->palette[i] = rgb_to_pixel16(s->r[i], s->g[i], s->b[i]); | |
21206a10 FB |
74 | break; |
75 | case 32: | |
b29169d2 BS |
76 | if (s->ds->bgr) |
77 | s->palette[i] = rgb_to_pixel32bgr(s->r[i], s->g[i], s->b[i]); | |
78 | else | |
79 | s->palette[i] = rgb_to_pixel32(s->r[i], s->g[i], s->b[i]); | |
21206a10 FB |
80 | break; |
81 | } | |
82 | } | |
97e7df27 BS |
83 | if (s->depth == 24) |
84 | tcx24_invalidate_display(s); | |
85 | else | |
86 | tcx_invalidate_display(s); | |
21206a10 FB |
87 | } |
88 | ||
5fafdf24 | 89 | static void tcx_draw_line32(TCXState *s1, uint8_t *d, |
f930d07e | 90 | const uint8_t *s, int width) |
420557e8 | 91 | { |
e80cfcfc FB |
92 | int x; |
93 | uint8_t val; | |
8bdc2159 | 94 | uint32_t *p = (uint32_t *)d; |
e80cfcfc FB |
95 | |
96 | for(x = 0; x < width; x++) { | |
f930d07e | 97 | val = *s++; |
8bdc2159 | 98 | *p++ = s1->palette[val]; |
e80cfcfc | 99 | } |
420557e8 FB |
100 | } |
101 | ||
5fafdf24 | 102 | static void tcx_draw_line16(TCXState *s1, uint8_t *d, |
f930d07e | 103 | const uint8_t *s, int width) |
e80cfcfc FB |
104 | { |
105 | int x; | |
106 | uint8_t val; | |
8bdc2159 | 107 | uint16_t *p = (uint16_t *)d; |
8d5f07fa | 108 | |
e80cfcfc | 109 | for(x = 0; x < width; x++) { |
f930d07e | 110 | val = *s++; |
8bdc2159 | 111 | *p++ = s1->palette[val]; |
e80cfcfc FB |
112 | } |
113 | } | |
114 | ||
5fafdf24 | 115 | static void tcx_draw_line8(TCXState *s1, uint8_t *d, |
f930d07e | 116 | const uint8_t *s, int width) |
420557e8 | 117 | { |
e80cfcfc FB |
118 | int x; |
119 | uint8_t val; | |
120 | ||
121 | for(x = 0; x < width; x++) { | |
f930d07e | 122 | val = *s++; |
21206a10 | 123 | *d++ = s1->palette[val]; |
420557e8 | 124 | } |
420557e8 FB |
125 | } |
126 | ||
eee0b836 BS |
127 | static inline void tcx24_draw_line32(TCXState *s1, uint8_t *d, |
128 | const uint8_t *s, int width, | |
129 | const uint32_t *cplane, | |
130 | const uint32_t *s24) | |
131 | { | |
132 | int x; | |
133 | uint8_t val; | |
134 | uint32_t *p = (uint32_t *)d; | |
135 | uint32_t dval; | |
136 | ||
137 | for(x = 0; x < width; x++, s++, s24++) { | |
138 | if ((bswap32(*cplane++) & 0xff000000) == 0x03000000) { // 24-bit direct | |
139 | dval = bswap32(*s24) & 0x00ffffff; | |
140 | } else { | |
141 | val = *s; | |
142 | dval = s1->palette[val]; | |
143 | } | |
144 | *p++ = dval; | |
145 | } | |
146 | } | |
147 | ||
22548760 | 148 | static inline int check_dirty(ram_addr_t page, ram_addr_t page24, |
eee0b836 BS |
149 | ram_addr_t cpage) |
150 | { | |
151 | int ret; | |
152 | unsigned int off; | |
153 | ||
154 | ret = cpu_physical_memory_get_dirty(page, VGA_DIRTY_FLAG); | |
155 | for (off = 0; off < TARGET_PAGE_SIZE * 4; off += TARGET_PAGE_SIZE) { | |
156 | ret |= cpu_physical_memory_get_dirty(page24 + off, VGA_DIRTY_FLAG); | |
157 | ret |= cpu_physical_memory_get_dirty(cpage + off, VGA_DIRTY_FLAG); | |
158 | } | |
159 | return ret; | |
160 | } | |
161 | ||
162 | static inline void reset_dirty(TCXState *ts, ram_addr_t page_min, | |
163 | ram_addr_t page_max, ram_addr_t page24, | |
164 | ram_addr_t cpage) | |
165 | { | |
166 | cpu_physical_memory_reset_dirty(page_min, page_max + TARGET_PAGE_SIZE, | |
167 | VGA_DIRTY_FLAG); | |
168 | page_min -= ts->vram_offset; | |
169 | page_max -= ts->vram_offset; | |
170 | cpu_physical_memory_reset_dirty(page24 + page_min * 4, | |
171 | page24 + page_max * 4 + TARGET_PAGE_SIZE, | |
172 | VGA_DIRTY_FLAG); | |
173 | cpu_physical_memory_reset_dirty(cpage + page_min * 4, | |
174 | cpage + page_max * 4 + TARGET_PAGE_SIZE, | |
175 | VGA_DIRTY_FLAG); | |
176 | } | |
177 | ||
e80cfcfc FB |
178 | /* Fixed line length 1024 allows us to do nice tricks not possible on |
179 | VGA... */ | |
95219897 | 180 | static void tcx_update_display(void *opaque) |
420557e8 | 181 | { |
e80cfcfc | 182 | TCXState *ts = opaque; |
550be127 FB |
183 | ram_addr_t page, page_min, page_max; |
184 | int y, y_start, dd, ds; | |
e80cfcfc | 185 | uint8_t *d, *s; |
b3ceef24 | 186 | void (*f)(TCXState *s1, uint8_t *dst, const uint8_t *src, int width); |
e80cfcfc FB |
187 | |
188 | if (ts->ds->depth == 0) | |
f930d07e | 189 | return; |
6f7e9aec | 190 | page = ts->vram_offset; |
e80cfcfc | 191 | y_start = -1; |
550be127 FB |
192 | page_min = 0xffffffff; |
193 | page_max = 0; | |
e80cfcfc | 194 | d = ts->ds->data; |
6f7e9aec | 195 | s = ts->vram; |
e80cfcfc FB |
196 | dd = ts->ds->linesize; |
197 | ds = 1024; | |
198 | ||
199 | switch (ts->ds->depth) { | |
200 | case 32: | |
f930d07e BS |
201 | f = tcx_draw_line32; |
202 | break; | |
21206a10 FB |
203 | case 15: |
204 | case 16: | |
f930d07e BS |
205 | f = tcx_draw_line16; |
206 | break; | |
e80cfcfc FB |
207 | default: |
208 | case 8: | |
f930d07e BS |
209 | f = tcx_draw_line8; |
210 | break; | |
e80cfcfc | 211 | case 0: |
f930d07e | 212 | return; |
e80cfcfc | 213 | } |
3b46e624 | 214 | |
6f7e9aec | 215 | for(y = 0; y < ts->height; y += 4, page += TARGET_PAGE_SIZE) { |
f930d07e BS |
216 | if (cpu_physical_memory_get_dirty(page, VGA_DIRTY_FLAG)) { |
217 | if (y_start < 0) | |
e80cfcfc FB |
218 | y_start = y; |
219 | if (page < page_min) | |
220 | page_min = page; | |
221 | if (page > page_max) | |
222 | page_max = page; | |
f930d07e BS |
223 | f(ts, d, s, ts->width); |
224 | d += dd; | |
225 | s += ds; | |
226 | f(ts, d, s, ts->width); | |
227 | d += dd; | |
228 | s += ds; | |
229 | f(ts, d, s, ts->width); | |
230 | d += dd; | |
231 | s += ds; | |
232 | f(ts, d, s, ts->width); | |
233 | d += dd; | |
234 | s += ds; | |
235 | } else { | |
e80cfcfc FB |
236 | if (y_start >= 0) { |
237 | /* flush to display */ | |
5fafdf24 | 238 | dpy_update(ts->ds, 0, y_start, |
6f7e9aec | 239 | ts->width, y - y_start); |
e80cfcfc FB |
240 | y_start = -1; |
241 | } | |
f930d07e BS |
242 | d += dd * 4; |
243 | s += ds * 4; | |
244 | } | |
e80cfcfc FB |
245 | } |
246 | if (y_start >= 0) { | |
f930d07e BS |
247 | /* flush to display */ |
248 | dpy_update(ts->ds, 0, y_start, | |
249 | ts->width, y - y_start); | |
e80cfcfc FB |
250 | } |
251 | /* reset modified pages */ | |
550be127 | 252 | if (page_min <= page_max) { |
0a962c02 FB |
253 | cpu_physical_memory_reset_dirty(page_min, page_max + TARGET_PAGE_SIZE, |
254 | VGA_DIRTY_FLAG); | |
e80cfcfc | 255 | } |
420557e8 FB |
256 | } |
257 | ||
eee0b836 BS |
258 | static void tcx24_update_display(void *opaque) |
259 | { | |
260 | TCXState *ts = opaque; | |
261 | ram_addr_t page, page_min, page_max, cpage, page24; | |
262 | int y, y_start, dd, ds; | |
263 | uint8_t *d, *s; | |
264 | uint32_t *cptr, *s24; | |
265 | ||
266 | if (ts->ds->depth != 32) | |
267 | return; | |
268 | page = ts->vram_offset; | |
269 | page24 = ts->vram24_offset; | |
270 | cpage = ts->cplane_offset; | |
271 | y_start = -1; | |
272 | page_min = 0xffffffff; | |
273 | page_max = 0; | |
274 | d = ts->ds->data; | |
275 | s = ts->vram; | |
276 | s24 = ts->vram24; | |
277 | cptr = ts->cplane; | |
278 | dd = ts->ds->linesize; | |
279 | ds = 1024; | |
280 | ||
281 | for(y = 0; y < ts->height; y += 4, page += TARGET_PAGE_SIZE, | |
282 | page24 += TARGET_PAGE_SIZE, cpage += TARGET_PAGE_SIZE) { | |
22548760 | 283 | if (check_dirty(page, page24, cpage)) { |
eee0b836 BS |
284 | if (y_start < 0) |
285 | y_start = y; | |
286 | if (page < page_min) | |
287 | page_min = page; | |
288 | if (page > page_max) | |
289 | page_max = page; | |
290 | tcx24_draw_line32(ts, d, s, ts->width, cptr, s24); | |
291 | d += dd; | |
292 | s += ds; | |
293 | cptr += ds; | |
294 | s24 += ds; | |
295 | tcx24_draw_line32(ts, d, s, ts->width, cptr, s24); | |
296 | d += dd; | |
297 | s += ds; | |
298 | cptr += ds; | |
299 | s24 += ds; | |
300 | tcx24_draw_line32(ts, d, s, ts->width, cptr, s24); | |
301 | d += dd; | |
302 | s += ds; | |
303 | cptr += ds; | |
304 | s24 += ds; | |
305 | tcx24_draw_line32(ts, d, s, ts->width, cptr, s24); | |
306 | d += dd; | |
307 | s += ds; | |
308 | cptr += ds; | |
309 | s24 += ds; | |
310 | } else { | |
311 | if (y_start >= 0) { | |
312 | /* flush to display */ | |
313 | dpy_update(ts->ds, 0, y_start, | |
314 | ts->width, y - y_start); | |
315 | y_start = -1; | |
316 | } | |
317 | d += dd * 4; | |
318 | s += ds * 4; | |
319 | cptr += ds * 4; | |
320 | s24 += ds * 4; | |
321 | } | |
322 | } | |
323 | if (y_start >= 0) { | |
324 | /* flush to display */ | |
325 | dpy_update(ts->ds, 0, y_start, | |
326 | ts->width, y - y_start); | |
327 | } | |
328 | /* reset modified pages */ | |
329 | if (page_min <= page_max) { | |
330 | reset_dirty(ts, page_min, page_max, page24, cpage); | |
331 | } | |
332 | } | |
333 | ||
95219897 | 334 | static void tcx_invalidate_display(void *opaque) |
420557e8 | 335 | { |
e80cfcfc FB |
336 | TCXState *s = opaque; |
337 | int i; | |
338 | ||
339 | for (i = 0; i < MAXX*MAXY; i += TARGET_PAGE_SIZE) { | |
f930d07e | 340 | cpu_physical_memory_set_dirty(s->vram_offset + i); |
e80cfcfc | 341 | } |
420557e8 FB |
342 | } |
343 | ||
eee0b836 BS |
344 | static void tcx24_invalidate_display(void *opaque) |
345 | { | |
346 | TCXState *s = opaque; | |
347 | int i; | |
348 | ||
349 | tcx_invalidate_display(s); | |
350 | for (i = 0; i < MAXX*MAXY * 4; i += TARGET_PAGE_SIZE) { | |
351 | cpu_physical_memory_set_dirty(s->vram24_offset + i); | |
352 | cpu_physical_memory_set_dirty(s->cplane_offset + i); | |
353 | } | |
354 | } | |
355 | ||
e80cfcfc | 356 | static void tcx_save(QEMUFile *f, void *opaque) |
420557e8 FB |
357 | { |
358 | TCXState *s = opaque; | |
3b46e624 | 359 | |
6f7e9aec FB |
360 | qemu_put_be16s(f, (uint16_t *)&s->height); |
361 | qemu_put_be16s(f, (uint16_t *)&s->width); | |
eee0b836 | 362 | qemu_put_be16s(f, (uint16_t *)&s->depth); |
e80cfcfc FB |
363 | qemu_put_buffer(f, s->r, 256); |
364 | qemu_put_buffer(f, s->g, 256); | |
365 | qemu_put_buffer(f, s->b, 256); | |
6f7e9aec FB |
366 | qemu_put_8s(f, &s->dac_index); |
367 | qemu_put_8s(f, &s->dac_state); | |
420557e8 FB |
368 | } |
369 | ||
e80cfcfc | 370 | static int tcx_load(QEMUFile *f, void *opaque, int version_id) |
420557e8 | 371 | { |
e80cfcfc | 372 | TCXState *s = opaque; |
fda77c2d BS |
373 | uint32_t dummy; |
374 | ||
375 | if (version_id != 3 && version_id != 4) | |
e80cfcfc FB |
376 | return -EINVAL; |
377 | ||
fda77c2d BS |
378 | if (version_id == 3) { |
379 | qemu_get_be32s(f, (uint32_t *)&dummy); | |
380 | qemu_get_be32s(f, (uint32_t *)&dummy); | |
381 | qemu_get_be32s(f, (uint32_t *)&dummy); | |
382 | } | |
6f7e9aec FB |
383 | qemu_get_be16s(f, (uint16_t *)&s->height); |
384 | qemu_get_be16s(f, (uint16_t *)&s->width); | |
eee0b836 | 385 | qemu_get_be16s(f, (uint16_t *)&s->depth); |
e80cfcfc FB |
386 | qemu_get_buffer(f, s->r, 256); |
387 | qemu_get_buffer(f, s->g, 256); | |
388 | qemu_get_buffer(f, s->b, 256); | |
6f7e9aec FB |
389 | qemu_get_8s(f, &s->dac_index); |
390 | qemu_get_8s(f, &s->dac_state); | |
21206a10 | 391 | update_palette_entries(s, 0, 256); |
97e7df27 BS |
392 | if (s->depth == 24) |
393 | tcx24_invalidate_display(s); | |
394 | else | |
395 | tcx_invalidate_display(s); | |
5425a216 | 396 | |
e80cfcfc | 397 | return 0; |
420557e8 FB |
398 | } |
399 | ||
e80cfcfc | 400 | static void tcx_reset(void *opaque) |
420557e8 | 401 | { |
e80cfcfc FB |
402 | TCXState *s = opaque; |
403 | ||
404 | /* Initialize palette */ | |
405 | memset(s->r, 0, 256); | |
406 | memset(s->g, 0, 256); | |
407 | memset(s->b, 0, 256); | |
408 | s->r[255] = s->g[255] = s->b[255] = 255; | |
21206a10 | 409 | update_palette_entries(s, 0, 256); |
e80cfcfc | 410 | memset(s->vram, 0, MAXX*MAXY); |
eee0b836 BS |
411 | cpu_physical_memory_reset_dirty(s->vram_offset, s->vram_offset + |
412 | MAXX * MAXY * (1 + 4 + 4), VGA_DIRTY_FLAG); | |
6f7e9aec FB |
413 | s->dac_index = 0; |
414 | s->dac_state = 0; | |
415 | } | |
416 | ||
417 | static uint32_t tcx_dac_readl(void *opaque, target_phys_addr_t addr) | |
418 | { | |
419 | return 0; | |
420 | } | |
421 | ||
422 | static void tcx_dac_writel(void *opaque, target_phys_addr_t addr, uint32_t val) | |
423 | { | |
424 | TCXState *s = opaque; | |
425 | uint32_t saddr; | |
426 | ||
427 | saddr = (addr & (TCX_DAC_NREGS - 1)) >> 2; | |
428 | switch (saddr) { | |
429 | case 0: | |
f930d07e BS |
430 | s->dac_index = val >> 24; |
431 | s->dac_state = 0; | |
432 | break; | |
6f7e9aec | 433 | case 1: |
f930d07e BS |
434 | switch (s->dac_state) { |
435 | case 0: | |
436 | s->r[s->dac_index] = val >> 24; | |
21206a10 | 437 | update_palette_entries(s, s->dac_index, s->dac_index + 1); |
f930d07e BS |
438 | s->dac_state++; |
439 | break; | |
440 | case 1: | |
441 | s->g[s->dac_index] = val >> 24; | |
21206a10 | 442 | update_palette_entries(s, s->dac_index, s->dac_index + 1); |
f930d07e BS |
443 | s->dac_state++; |
444 | break; | |
445 | case 2: | |
446 | s->b[s->dac_index] = val >> 24; | |
21206a10 | 447 | update_palette_entries(s, s->dac_index, s->dac_index + 1); |
5c8cdbf8 | 448 | s->dac_index = (s->dac_index + 1) & 255; // Index autoincrement |
f930d07e BS |
449 | default: |
450 | s->dac_state = 0; | |
451 | break; | |
452 | } | |
453 | break; | |
6f7e9aec | 454 | default: |
f930d07e | 455 | break; |
6f7e9aec FB |
456 | } |
457 | return; | |
420557e8 FB |
458 | } |
459 | ||
6f7e9aec | 460 | static CPUReadMemoryFunc *tcx_dac_read[3] = { |
7c560456 BS |
461 | NULL, |
462 | NULL, | |
6f7e9aec FB |
463 | tcx_dac_readl, |
464 | }; | |
465 | ||
466 | static CPUWriteMemoryFunc *tcx_dac_write[3] = { | |
7c560456 BS |
467 | NULL, |
468 | NULL, | |
6f7e9aec FB |
469 | tcx_dac_writel, |
470 | }; | |
471 | ||
8508b89e BS |
472 | static uint32_t tcx_dummy_readl(void *opaque, target_phys_addr_t addr) |
473 | { | |
474 | return 0; | |
475 | } | |
476 | ||
477 | static void tcx_dummy_writel(void *opaque, target_phys_addr_t addr, | |
478 | uint32_t val) | |
479 | { | |
480 | } | |
481 | ||
482 | static CPUReadMemoryFunc *tcx_dummy_read[3] = { | |
7c560456 BS |
483 | NULL, |
484 | NULL, | |
8508b89e BS |
485 | tcx_dummy_readl, |
486 | }; | |
487 | ||
488 | static CPUWriteMemoryFunc *tcx_dummy_write[3] = { | |
7c560456 BS |
489 | NULL, |
490 | NULL, | |
8508b89e BS |
491 | tcx_dummy_writel, |
492 | }; | |
493 | ||
5dcb6b91 | 494 | void tcx_init(DisplayState *ds, target_phys_addr_t addr, uint8_t *vram_base, |
eee0b836 BS |
495 | unsigned long vram_offset, int vram_size, int width, int height, |
496 | int depth) | |
420557e8 FB |
497 | { |
498 | TCXState *s; | |
8508b89e | 499 | int io_memory, dummy_memory; |
eee0b836 | 500 | int size; |
420557e8 FB |
501 | |
502 | s = qemu_mallocz(sizeof(TCXState)); | |
503 | if (!s) | |
95219897 | 504 | return; |
420557e8 | 505 | s->ds = ds; |
8d5f07fa | 506 | s->addr = addr; |
e80cfcfc | 507 | s->vram_offset = vram_offset; |
6f7e9aec FB |
508 | s->width = width; |
509 | s->height = height; | |
eee0b836 BS |
510 | s->depth = depth; |
511 | ||
512 | // 8-bit plane | |
513 | s->vram = vram_base; | |
514 | size = vram_size; | |
5dcb6b91 | 515 | cpu_register_physical_memory(addr + 0x00800000ULL, size, vram_offset); |
eee0b836 BS |
516 | vram_offset += size; |
517 | vram_base += size; | |
e80cfcfc | 518 | |
6f7e9aec | 519 | io_memory = cpu_register_io_memory(0, tcx_dac_read, tcx_dac_write, s); |
77f193da BS |
520 | cpu_register_physical_memory(addr + 0x00200000ULL, TCX_DAC_NREGS, |
521 | io_memory); | |
eee0b836 | 522 | |
8508b89e BS |
523 | dummy_memory = cpu_register_io_memory(0, tcx_dummy_read, tcx_dummy_write, |
524 | s); | |
5dcb6b91 | 525 | cpu_register_physical_memory(addr + 0x00700000ULL, TCX_TEC_NREGS, |
8508b89e | 526 | dummy_memory); |
eee0b836 BS |
527 | if (depth == 24) { |
528 | // 24-bit plane | |
529 | size = vram_size * 4; | |
530 | s->vram24 = (uint32_t *)vram_base; | |
531 | s->vram24_offset = vram_offset; | |
5dcb6b91 | 532 | cpu_register_physical_memory(addr + 0x02000000ULL, size, vram_offset); |
eee0b836 BS |
533 | vram_offset += size; |
534 | vram_base += size; | |
535 | ||
536 | // Control plane | |
537 | size = vram_size * 4; | |
538 | s->cplane = (uint32_t *)vram_base; | |
539 | s->cplane_offset = vram_offset; | |
5dcb6b91 | 540 | cpu_register_physical_memory(addr + 0x0a000000ULL, size, vram_offset); |
c60e08d9 PB |
541 | s->console = graphic_console_init(s->ds, tcx24_update_display, |
542 | tcx24_invalidate_display, | |
543 | tcx24_screen_dump, NULL, s); | |
eee0b836 | 544 | } else { |
5dcb6b91 | 545 | cpu_register_physical_memory(addr + 0x00300000ULL, TCX_THC_NREGS_8, |
8508b89e | 546 | dummy_memory); |
c60e08d9 PB |
547 | s->console = graphic_console_init(s->ds, tcx_update_display, |
548 | tcx_invalidate_display, | |
549 | tcx_screen_dump, NULL, s); | |
eee0b836 | 550 | } |
f96f4c9d | 551 | // NetBSD writes here even with 8-bit display |
5dcb6b91 | 552 | cpu_register_physical_memory(addr + 0x00301000ULL, TCX_THC_NREGS_24, |
f96f4c9d | 553 | dummy_memory); |
e80cfcfc | 554 | |
fda77c2d | 555 | register_savevm("tcx", addr, 4, tcx_save, tcx_load, s); |
e80cfcfc FB |
556 | qemu_register_reset(tcx_reset, s); |
557 | tcx_reset(s); | |
c60e08d9 | 558 | qemu_console_resize(s->console, width, height); |
420557e8 FB |
559 | } |
560 | ||
95219897 | 561 | static void tcx_screen_dump(void *opaque, const char *filename) |
8d5f07fa | 562 | { |
e80cfcfc | 563 | TCXState *s = opaque; |
8d5f07fa | 564 | FILE *f; |
e80cfcfc | 565 | uint8_t *d, *d1, v; |
8d5f07fa FB |
566 | int y, x; |
567 | ||
568 | f = fopen(filename, "wb"); | |
569 | if (!f) | |
e80cfcfc | 570 | return; |
6f7e9aec FB |
571 | fprintf(f, "P6\n%d %d\n%d\n", s->width, s->height, 255); |
572 | d1 = s->vram; | |
573 | for(y = 0; y < s->height; y++) { | |
8d5f07fa | 574 | d = d1; |
6f7e9aec | 575 | for(x = 0; x < s->width; x++) { |
8d5f07fa | 576 | v = *d; |
e80cfcfc FB |
577 | fputc(s->r[v], f); |
578 | fputc(s->g[v], f); | |
579 | fputc(s->b[v], f); | |
8d5f07fa FB |
580 | d++; |
581 | } | |
e80cfcfc | 582 | d1 += MAXX; |
8d5f07fa FB |
583 | } |
584 | fclose(f); | |
585 | return; | |
586 | } | |
587 | ||
eee0b836 BS |
588 | static void tcx24_screen_dump(void *opaque, const char *filename) |
589 | { | |
590 | TCXState *s = opaque; | |
591 | FILE *f; | |
592 | uint8_t *d, *d1, v; | |
593 | uint32_t *s24, *cptr, dval; | |
594 | int y, x; | |
8d5f07fa | 595 | |
eee0b836 BS |
596 | f = fopen(filename, "wb"); |
597 | if (!f) | |
598 | return; | |
599 | fprintf(f, "P6\n%d %d\n%d\n", s->width, s->height, 255); | |
600 | d1 = s->vram; | |
601 | s24 = s->vram24; | |
602 | cptr = s->cplane; | |
603 | for(y = 0; y < s->height; y++) { | |
604 | d = d1; | |
605 | for(x = 0; x < s->width; x++, d++, s24++) { | |
606 | if ((*cptr++ & 0xff000000) == 0x03000000) { // 24-bit direct | |
607 | dval = *s24 & 0x00ffffff; | |
608 | fputc((dval >> 16) & 0xff, f); | |
609 | fputc((dval >> 8) & 0xff, f); | |
610 | fputc(dval & 0xff, f); | |
611 | } else { | |
612 | v = *d; | |
613 | fputc(s->r[v], f); | |
614 | fputc(s->g[v], f); | |
615 | fputc(s->b[v], f); | |
616 | } | |
617 | } | |
618 | d1 += MAXX; | |
619 | } | |
620 | fclose(f); | |
621 | return; | |
622 | } |