2 * QEMU Sun4m System Emulator
4 * Copyright (c) 2003-2004 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
29 * Proll uses only small part of display, we need to switch to full
30 * display when we get linux framebuffer console or X11 running. For
31 * now it's just slower and awkward.
36 #define XOFF (MAXX-XSZ)
37 #define YOFF (MAXY-YSZ)
45 typedef struct TCXState {
49 unsigned long vram_offset;
50 uint8_t r[256], g[256], b[256];
53 static void tcx_draw_line32(TCXState *s1, uint8_t *d,
54 const uint8_t *s, int width)
59 for(x = 0; x < width; x++) {
68 static void tcx_draw_line24(TCXState *s1, uint8_t *d,
69 const uint8_t *s, int width)
74 for(x = 0; x < width; x++) {
82 static void tcx_draw_line8(TCXState *s1, uint8_t *d,
83 const uint8_t *s, int width)
88 for(x = 0; x < width; x++) {
90 /* XXX translate between palettes? */
95 /* Fixed line length 1024 allows us to do nice tricks not possible on
97 void tcx_update_display(void *opaque)
99 TCXState *ts = opaque;
101 int y, page_min, page_max, y_start, dd, ds;
103 void (*f)(TCXState *s1, uint8_t *d, const uint8_t *s, int width);
105 if (ts->ds->depth == 0)
108 page = ts->vram_offset + YOFF*MAXX;
110 page = ts->addr + YOFF*MAXX;
113 page_min = 0x7fffffff;
116 s = ts->vram + YOFF*MAXX + XOFF;
117 dd = ts->ds->linesize;
120 switch (ts->ds->depth) {
135 for(y = 0; y < YSZ; y += 4, page += TARGET_PAGE_SIZE) {
136 if (cpu_physical_memory_is_dirty(page)) {
157 /* flush to display */
158 dpy_update(ts->ds, 0, y_start,
167 /* flush to display */
168 dpy_update(ts->ds, 0, y_start,
171 /* reset modified pages */
172 if (page_max != -1) {
173 cpu_physical_memory_reset_dirty(page_min, page_max + TARGET_PAGE_SIZE);
177 void tcx_invalidate_display(void *opaque)
179 TCXState *s = opaque;
182 for (i = 0; i < MAXX*MAXY; i += TARGET_PAGE_SIZE) {
184 cpu_physical_memory_set_dirty(s->vram_offset + i);
186 cpu_physical_memory_set_dirty(s->addr + i);
191 static void tcx_save(QEMUFile *f, void *opaque)
193 TCXState *s = opaque;
195 qemu_put_be32s(f, (uint32_t *)&s->addr);
196 qemu_put_be32s(f, (uint32_t *)&s->vram);
197 qemu_put_buffer(f, s->r, 256);
198 qemu_put_buffer(f, s->g, 256);
199 qemu_put_buffer(f, s->b, 256);
202 static int tcx_load(QEMUFile *f, void *opaque, int version_id)
204 TCXState *s = opaque;
209 qemu_get_be32s(f, (uint32_t *)&s->addr);
210 qemu_get_be32s(f, (uint32_t *)&s->vram);
211 qemu_get_buffer(f, s->r, 256);
212 qemu_get_buffer(f, s->g, 256);
213 qemu_get_buffer(f, s->b, 256);
217 static void tcx_reset(void *opaque)
219 TCXState *s = opaque;
221 /* Initialize palette */
222 memset(s->r, 0, 256);
223 memset(s->g, 0, 256);
224 memset(s->b, 0, 256);
225 s->r[255] = s->g[255] = s->b[255] = 255;
226 memset(s->vram, 0, MAXX*MAXY);
228 cpu_physical_memory_reset_dirty(s->vram_offset, s->vram_offset + MAXX*MAXY - 1);
232 void *tcx_init(DisplayState *ds, uint32_t addr, uint8_t *vram_base,
233 unsigned long vram_offset, int vram_size)
237 s = qemu_mallocz(sizeof(TCXState));
243 s->vram_offset = vram_offset;
245 cpu_register_physical_memory(addr, vram_size, vram_offset);
247 register_savevm("tcx", addr, 1, tcx_save, tcx_load, s);
248 qemu_register_reset(tcx_reset, s);
250 dpy_resize(s->ds, XSZ, YSZ);
254 void tcx_screen_dump(void *opaque, const char *filename)
256 TCXState *s = opaque;
261 f = fopen(filename, "wb");
264 fprintf(f, "P6\n%d %d\n%d\n", XSZ, YSZ, 255);
265 d1 = s->vram + YOFF*MAXX + XOFF;
266 for(y = 0; y < YSZ; y++) {
268 for(x = 0; x < XSZ; x++) {