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
30 #define XOFF (MAXX-XSZ)
31 #define YOFF (MAXY-YSZ)
33 typedef struct TCXState {
41 void vga_update_display()
43 dpy_update(ts->ds, 0, 0, XSZ, YSZ);
46 void vga_invalidate_display() {}
48 static uint32_t tcx_mem_readb(void *opaque, target_phys_addr_t addr)
54 saddr = addr - s->addr - YOFF*MAXX - XOFF;
57 if (x < XSZ && y < YSZ) {
58 return s->vram[y * XSZ + x];
63 static uint32_t tcx_mem_readw(void *opaque, target_phys_addr_t addr)
66 #ifdef TARGET_WORDS_BIGENDIAN
67 v = tcx_mem_readb(opaque, addr) << 8;
68 v |= tcx_mem_readb(opaque, addr + 1);
70 v = tcx_mem_readb(opaque, addr);
71 v |= tcx_mem_readb(opaque, addr + 1) << 8;
76 static uint32_t tcx_mem_readl(void *opaque, target_phys_addr_t addr)
79 #ifdef TARGET_WORDS_BIGENDIAN
80 v = tcx_mem_readb(opaque, addr) << 24;
81 v |= tcx_mem_readb(opaque, addr + 1) << 16;
82 v |= tcx_mem_readb(opaque, addr + 2) << 8;
83 v |= tcx_mem_readb(opaque, addr + 3);
85 v = tcx_mem_readb(opaque, addr);
86 v |= tcx_mem_readb(opaque, addr + 1) << 8;
87 v |= tcx_mem_readb(opaque, addr + 2) << 16;
88 v |= tcx_mem_readb(opaque, addr + 3) << 24;
93 static void tcx_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
100 saddr = addr - s->addr - YOFF*MAXX - XOFF;
102 x = saddr - y * MAXX;
103 if (x < XSZ && y < YSZ) {
106 if (s->ds->depth == 24 || s->ds->depth == 32) {
107 /* XXX need to do CLUT translation */
108 sptr[y * s->ds->linesize + x*4] = val & 0xff;
109 sptr[y * s->ds->linesize + x*4+1] = val & 0xff;
110 sptr[y * s->ds->linesize + x*4+2] = val & 0xff;
112 else if (s->ds->depth == 8) {
113 sptr[y * s->ds->linesize + x] = val & 0xff;
116 cpu_physical_memory_set_dirty(addr);
117 s->vram[y * XSZ + x] = val & 0xff;
121 static void tcx_mem_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
123 #ifdef TARGET_WORDS_BIGENDIAN
124 tcx_mem_writeb(opaque, addr, (val >> 8) & 0xff);
125 tcx_mem_writeb(opaque, addr + 1, val & 0xff);
127 tcx_mem_writeb(opaque, addr, val & 0xff);
128 tcx_mem_writeb(opaque, addr + 1, (val >> 8) & 0xff);
132 static void tcx_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
134 #ifdef TARGET_WORDS_BIGENDIAN
135 tcx_mem_writeb(opaque, addr, (val >> 24) & 0xff);
136 tcx_mem_writeb(opaque, addr + 1, (val >> 16) & 0xff);
137 tcx_mem_writeb(opaque, addr + 2, (val >> 8) & 0xff);
138 tcx_mem_writeb(opaque, addr + 3, val & 0xff);
140 tcx_mem_writeb(opaque, addr, val & 0xff);
141 tcx_mem_writeb(opaque, addr + 1, (val >> 8) & 0xff);
142 tcx_mem_writeb(opaque, addr + 2, (val >> 16) & 0xff);
143 tcx_mem_writeb(opaque, addr + 3, (val >> 24) & 0xff);
147 static CPUReadMemoryFunc *tcx_mem_read[3] = {
153 static CPUWriteMemoryFunc *tcx_mem_write[3] = {
159 void tcx_init(DisplayState *ds, uint32_t addr)
164 s = qemu_mallocz(sizeof(TCXState));
170 tcx_io_memory = cpu_register_io_memory(0, tcx_mem_read, tcx_mem_write, s);
171 cpu_register_physical_memory(addr, 0x100000,
173 s->vram = qemu_mallocz(XSZ*YSZ);
174 dpy_resize(s->ds, XSZ, YSZ);
177 void vga_screen_dump(const char *filename)
185 f = fopen(filename, "wb");
188 fprintf(f, "P6\n%d %d\n%d\n",
191 for(y = 0; y < YSZ; y++) {
193 for(x = 0; x < XSZ; x++) {
195 fputc((v) & 0xff, f);
196 fputc((v) & 0xff, f);
197 fputc((v) & 0xff, f);