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