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)
107 page = ts->vram_offset + YOFF*MAXX;
109 page_min = 0x7fffffff;
112 s = ts->vram + YOFF*MAXX + XOFF;
113 dd = ts->ds->linesize;
116 switch (ts->ds->depth) {
131 for(y = 0; y < YSZ; y += 4, page += TARGET_PAGE_SIZE) {
132 if (cpu_physical_memory_get_dirty(page, VGA_DIRTY_FLAG)) {
153 /* flush to display */
154 dpy_update(ts->ds, 0, y_start,
163 /* flush to display */
164 dpy_update(ts->ds, 0, y_start,
167 /* reset modified pages */
168 if (page_max != -1) {
169 cpu_physical_memory_reset_dirty(page_min, page_max + TARGET_PAGE_SIZE,
174 void tcx_invalidate_display(void *opaque)
176 TCXState *s = opaque;
179 for (i = 0; i < MAXX*MAXY; i += TARGET_PAGE_SIZE) {
180 cpu_physical_memory_set_dirty(s->vram_offset + i);
184 static void tcx_save(QEMUFile *f, void *opaque)
186 TCXState *s = opaque;
188 qemu_put_be32s(f, (uint32_t *)&s->addr);
189 qemu_put_be32s(f, (uint32_t *)&s->vram);
190 qemu_put_buffer(f, s->r, 256);
191 qemu_put_buffer(f, s->g, 256);
192 qemu_put_buffer(f, s->b, 256);
195 static int tcx_load(QEMUFile *f, void *opaque, int version_id)
197 TCXState *s = opaque;
202 qemu_get_be32s(f, (uint32_t *)&s->addr);
203 qemu_get_be32s(f, (uint32_t *)&s->vram);
204 qemu_get_buffer(f, s->r, 256);
205 qemu_get_buffer(f, s->g, 256);
206 qemu_get_buffer(f, s->b, 256);
210 static void tcx_reset(void *opaque)
212 TCXState *s = opaque;
214 /* Initialize palette */
215 memset(s->r, 0, 256);
216 memset(s->g, 0, 256);
217 memset(s->b, 0, 256);
218 s->r[255] = s->g[255] = s->b[255] = 255;
219 memset(s->vram, 0, MAXX*MAXY);
220 cpu_physical_memory_reset_dirty(s->vram_offset, s->vram_offset + MAXX*MAXY,
224 void *tcx_init(DisplayState *ds, uint32_t addr, uint8_t *vram_base,
225 unsigned long vram_offset, int vram_size)
229 s = qemu_mallocz(sizeof(TCXState));
235 s->vram_offset = vram_offset;
237 cpu_register_physical_memory(addr, vram_size, vram_offset);
239 register_savevm("tcx", addr, 1, tcx_save, tcx_load, s);
240 qemu_register_reset(tcx_reset, s);
242 dpy_resize(s->ds, XSZ, YSZ);
246 void tcx_screen_dump(void *opaque, const char *filename)
248 TCXState *s = opaque;
253 f = fopen(filename, "wb");
256 fprintf(f, "P6\n%d %d\n%d\n", XSZ, YSZ, 255);
257 d1 = s->vram + YOFF*MAXX + XOFF;
258 for(y = 0; y < YSZ; y++) {
260 for(x = 0; x < XSZ; x++) {