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