blob: d720ea66662c2d18a60e8f8bd9e19a8054362135 [file] [log] [blame]
bellard420557e2004-09-30 22:13:50 +00001/*
bellard6f7e9ae2005-03-13 09:43:36 +00002 * QEMU TCX Frame buffer
ths5fafdf22007-09-16 21:08:06 +00003 *
bellard6f7e9ae2005-03-13 09:43:36 +00004 * Copyright (c) 2003-2005 Fabrice Bellard
ths5fafdf22007-09-16 21:08:06 +00005 *
bellard420557e2004-09-30 22:13:50 +00006 * 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 */
Blue Swirlf40070c2009-07-12 19:21:36 +000024
Paolo Bonzini077805f2012-09-25 10:04:17 +020025#include "qemu-common.h"
Paolo Bonzini28ecbae2012-11-28 12:06:30 +010026#include "ui/console.h"
27#include "ui/pixel_ops.h"
Mark Cave-Aylandda87dd72013-11-02 16:03:50 +000028#include "hw/loader.h"
Paolo Bonzini83c9f4c2013-02-04 15:40:22 +010029#include "hw/sysbus.h"
Markus Armbrusterd49b6832015-03-17 18:29:20 +010030#include "qemu/error-report.h"
bellard420557e2004-09-30 22:13:50 +000031
Mark Cave-Aylandda87dd72013-11-02 16:03:50 +000032#define TCX_ROM_FILE "QEMU,tcx.bin"
33#define FCODE_MAX_ROM_SIZE 0x10000
34
bellard420557e2004-09-30 22:13:50 +000035#define MAXX 1024
36#define MAXY 768
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +010037#define TCX_DAC_NREGS 16
38#define TCX_THC_NREGS 0x1000
39#define TCX_DHC_NREGS 0x4000
blueswir18508b892007-05-06 17:39:55 +000040#define TCX_TEC_NREGS 0x1000
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +010041#define TCX_ALT_NREGS 0x8000
42#define TCX_STIP_NREGS 0x800000
43#define TCX_BLIT_NREGS 0x800000
44#define TCX_RSTIP_NREGS 0x800000
45#define TCX_RBLIT_NREGS 0x800000
46
47#define TCX_THC_MISC 0x818
48#define TCX_THC_CURSXY 0x8fc
49#define TCX_THC_CURSMASK 0x900
50#define TCX_THC_CURSBITS 0x980
bellard420557e2004-09-30 22:13:50 +000051
Andreas Färber01774dd2013-07-25 01:13:54 +020052#define TYPE_TCX "SUNW,tcx"
53#define TCX(obj) OBJECT_CHECK(TCXState, (obj), TYPE_TCX)
54
bellard420557e2004-09-30 22:13:50 +000055typedef struct TCXState {
Andreas Färber01774dd2013-07-25 01:13:54 +020056 SysBusDevice parent_obj;
57
Gerd Hoffmannc78f7132013-03-05 15:24:14 +010058 QemuConsole *con;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +010059 qemu_irq irq;
bellard8d5f07f2004-10-04 21:23:09 +000060 uint8_t *vram;
blueswir1eee0b832007-04-21 19:45:49 +000061 uint32_t *vram24, *cplane;
Mark Cave-Aylandda87dd72013-11-02 16:03:50 +000062 hwaddr prom_addr;
63 MemoryRegion rom;
Avi Kivityd08151b2011-10-05 18:26:24 +020064 MemoryRegion vram_mem;
65 MemoryRegion vram_8bit;
66 MemoryRegion vram_24bit;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +010067 MemoryRegion stip;
68 MemoryRegion blit;
Avi Kivityd08151b2011-10-05 18:26:24 +020069 MemoryRegion vram_cplane;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +010070 MemoryRegion rstip;
71 MemoryRegion rblit;
Avi Kivityd08151b2011-10-05 18:26:24 +020072 MemoryRegion tec;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +010073 MemoryRegion dac;
74 MemoryRegion thc;
75 MemoryRegion dhc;
76 MemoryRegion alt;
Avi Kivityd08151b2011-10-05 18:26:24 +020077 MemoryRegion thc24;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +010078
Avi Kivityd08151b2011-10-05 18:26:24 +020079 ram_addr_t vram24_offset, cplane_offset;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +010080 uint32_t tmpblit;
Gerd Hoffmannee6847d2009-07-15 13:43:31 +020081 uint32_t vram_size;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +010082 uint32_t palette[260];
83 uint8_t r[260], g[260], b[260];
Blue Swirl427a66c2011-08-07 19:13:24 +000084 uint16_t width, height, depth;
bellard6f7e9ae2005-03-13 09:43:36 +000085 uint8_t dac_index, dac_state;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +010086 uint32_t thcmisc;
87 uint32_t cursmask[32];
88 uint32_t cursbits[32];
89 uint16_t cursx;
90 uint16_t cursy;
bellard420557e2004-09-30 22:13:50 +000091} TCXState;
92
Blue Swirld3ffcaf2009-07-16 13:45:57 +000093static void tcx_set_dirty(TCXState *s)
94{
Blue Swirlfd4aa972011-10-16 16:04:59 +000095 memory_region_set_dirty(&s->vram_mem, 0, MAXX * MAXY);
Blue Swirld3ffcaf2009-07-16 13:45:57 +000096}
97
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +010098static inline int tcx24_check_dirty(TCXState *s, ram_addr_t page,
99 ram_addr_t page24, ram_addr_t cpage)
Blue Swirld3ffcaf2009-07-16 13:45:57 +0000100{
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100101 int ret;
102
103 ret = memory_region_get_dirty(&s->vram_mem, page, TARGET_PAGE_SIZE,
104 DIRTY_MEMORY_VGA);
105 ret |= memory_region_get_dirty(&s->vram_mem, page24, TARGET_PAGE_SIZE * 4,
106 DIRTY_MEMORY_VGA);
107 ret |= memory_region_get_dirty(&s->vram_mem, cpage, TARGET_PAGE_SIZE * 4,
108 DIRTY_MEMORY_VGA);
109 return ret;
110}
111
112static inline void tcx24_reset_dirty(TCXState *ts, ram_addr_t page_min,
113 ram_addr_t page_max, ram_addr_t page24,
114 ram_addr_t cpage)
115{
116 memory_region_reset_dirty(&ts->vram_mem,
117 page_min,
118 (page_max - page_min) + TARGET_PAGE_SIZE,
119 DIRTY_MEMORY_VGA);
120 memory_region_reset_dirty(&ts->vram_mem,
121 page24 + page_min * 4,
122 (page_max - page_min) * 4 + TARGET_PAGE_SIZE,
123 DIRTY_MEMORY_VGA);
124 memory_region_reset_dirty(&ts->vram_mem,
125 cpage + page_min * 4,
126 (page_max - page_min) * 4 + TARGET_PAGE_SIZE,
127 DIRTY_MEMORY_VGA);
Blue Swirld3ffcaf2009-07-16 13:45:57 +0000128}
pbrook95219892006-04-09 01:06:34 +0000129
bellard21206a12006-09-09 11:31:34 +0000130static void update_palette_entries(TCXState *s, int start, int end)
131{
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100132 DisplaySurface *surface = qemu_console_surface(s->con);
bellard21206a12006-09-09 11:31:34 +0000133 int i;
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100134
135 for (i = start; i < end; i++) {
136 switch (surface_bits_per_pixel(surface)) {
bellard21206a12006-09-09 11:31:34 +0000137 default:
138 case 8:
139 s->palette[i] = rgb_to_pixel8(s->r[i], s->g[i], s->b[i]);
140 break;
141 case 15:
aliguori8927bcf2009-01-15 22:07:16 +0000142 s->palette[i] = rgb_to_pixel15(s->r[i], s->g[i], s->b[i]);
bellard21206a12006-09-09 11:31:34 +0000143 break;
144 case 16:
aliguori8927bcf2009-01-15 22:07:16 +0000145 s->palette[i] = rgb_to_pixel16(s->r[i], s->g[i], s->b[i]);
bellard21206a12006-09-09 11:31:34 +0000146 break;
147 case 32:
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100148 if (is_surface_bgr(surface)) {
aliguori7b5d76d2009-03-13 15:02:13 +0000149 s->palette[i] = rgb_to_pixel32bgr(s->r[i], s->g[i], s->b[i]);
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100150 } else {
aliguori7b5d76d2009-03-13 15:02:13 +0000151 s->palette[i] = rgb_to_pixel32(s->r[i], s->g[i], s->b[i]);
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100152 }
bellard21206a12006-09-09 11:31:34 +0000153 break;
154 }
155 }
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100156 tcx_set_dirty(s);
bellard21206a12006-09-09 11:31:34 +0000157}
158
ths5fafdf22007-09-16 21:08:06 +0000159static void tcx_draw_line32(TCXState *s1, uint8_t *d,
blueswir1f930d072007-10-06 11:28:21 +0000160 const uint8_t *s, int width)
bellard420557e2004-09-30 22:13:50 +0000161{
bellarde80cfcf2004-12-19 23:18:01 +0000162 int x;
163 uint8_t val;
ths8bdc2152006-12-21 17:24:45 +0000164 uint32_t *p = (uint32_t *)d;
bellarde80cfcf2004-12-19 23:18:01 +0000165
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100166 for (x = 0; x < width; x++) {
blueswir1f930d072007-10-06 11:28:21 +0000167 val = *s++;
ths8bdc2152006-12-21 17:24:45 +0000168 *p++ = s1->palette[val];
bellarde80cfcf2004-12-19 23:18:01 +0000169 }
bellard420557e2004-09-30 22:13:50 +0000170}
171
ths5fafdf22007-09-16 21:08:06 +0000172static void tcx_draw_line16(TCXState *s1, uint8_t *d,
blueswir1f930d072007-10-06 11:28:21 +0000173 const uint8_t *s, int width)
bellarde80cfcf2004-12-19 23:18:01 +0000174{
175 int x;
176 uint8_t val;
ths8bdc2152006-12-21 17:24:45 +0000177 uint16_t *p = (uint16_t *)d;
bellard8d5f07f2004-10-04 21:23:09 +0000178
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100179 for (x = 0; x < width; x++) {
blueswir1f930d072007-10-06 11:28:21 +0000180 val = *s++;
ths8bdc2152006-12-21 17:24:45 +0000181 *p++ = s1->palette[val];
bellarde80cfcf2004-12-19 23:18:01 +0000182 }
183}
184
ths5fafdf22007-09-16 21:08:06 +0000185static void tcx_draw_line8(TCXState *s1, uint8_t *d,
blueswir1f930d072007-10-06 11:28:21 +0000186 const uint8_t *s, int width)
bellarde80cfcf2004-12-19 23:18:01 +0000187{
188 int x;
189 uint8_t val;
190
191 for(x = 0; x < width; x++) {
blueswir1f930d072007-10-06 11:28:21 +0000192 val = *s++;
bellard21206a12006-09-09 11:31:34 +0000193 *d++ = s1->palette[val];
bellarde80cfcf2004-12-19 23:18:01 +0000194 }
195}
196
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100197static void tcx_draw_cursor32(TCXState *s1, uint8_t *d,
198 int y, int width)
199{
200 int x, len;
201 uint32_t mask, bits;
202 uint32_t *p = (uint32_t *)d;
203
204 y = y - s1->cursy;
205 mask = s1->cursmask[y];
206 bits = s1->cursbits[y];
207 len = MIN(width - s1->cursx, 32);
208 p = &p[s1->cursx];
209 for (x = 0; x < len; x++) {
210 if (mask & 0x80000000) {
211 if (bits & 0x80000000) {
212 *p = s1->palette[259];
213 } else {
214 *p = s1->palette[258];
215 }
216 }
217 p++;
218 mask <<= 1;
219 bits <<= 1;
220 }
221}
222
223static void tcx_draw_cursor16(TCXState *s1, uint8_t *d,
224 int y, int width)
225{
226 int x, len;
227 uint32_t mask, bits;
228 uint16_t *p = (uint16_t *)d;
229
230 y = y - s1->cursy;
231 mask = s1->cursmask[y];
232 bits = s1->cursbits[y];
233 len = MIN(width - s1->cursx, 32);
234 p = &p[s1->cursx];
235 for (x = 0; x < len; x++) {
236 if (mask & 0x80000000) {
237 if (bits & 0x80000000) {
238 *p = s1->palette[259];
239 } else {
240 *p = s1->palette[258];
241 }
242 }
243 p++;
244 mask <<= 1;
245 bits <<= 1;
246 }
247}
248
249static void tcx_draw_cursor8(TCXState *s1, uint8_t *d,
250 int y, int width)
251{
252 int x, len;
253 uint32_t mask, bits;
254
255 y = y - s1->cursy;
256 mask = s1->cursmask[y];
257 bits = s1->cursbits[y];
258 len = MIN(width - s1->cursx, 32);
259 d = &d[s1->cursx];
260 for (x = 0; x < len; x++) {
261 if (mask & 0x80000000) {
262 if (bits & 0x80000000) {
263 *d = s1->palette[259];
264 } else {
265 *d = s1->palette[258];
266 }
267 }
268 d++;
269 mask <<= 1;
270 bits <<= 1;
271 }
272}
273
blueswir1688ea2e2008-07-24 11:26:38 +0000274/*
275 XXX Could be much more optimal:
276 * detect if line/page/whole screen is in 24 bit mode
277 * if destination is also BGR, use memcpy
278 */
blueswir1eee0b832007-04-21 19:45:49 +0000279static inline void tcx24_draw_line32(TCXState *s1, uint8_t *d,
280 const uint8_t *s, int width,
281 const uint32_t *cplane,
282 const uint32_t *s24)
283{
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100284 DisplaySurface *surface = qemu_console_surface(s1->con);
aliguori7b5d76d2009-03-13 15:02:13 +0000285 int x, bgr, r, g, b;
blueswir1688ea2e2008-07-24 11:26:38 +0000286 uint8_t val, *p8;
blueswir1eee0b832007-04-21 19:45:49 +0000287 uint32_t *p = (uint32_t *)d;
288 uint32_t dval;
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100289 bgr = is_surface_bgr(surface);
blueswir1eee0b832007-04-21 19:45:49 +0000290 for(x = 0; x < width; x++, s++, s24++) {
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100291 if (be32_to_cpu(*cplane) & 0x03000000) {
292 /* 24-bit direct, BGR order */
blueswir1688ea2e2008-07-24 11:26:38 +0000293 p8 = (uint8_t *)s24;
294 p8++;
295 b = *p8++;
296 g = *p8++;
Blue Swirlf7e683b2010-01-13 18:58:51 +0000297 r = *p8;
aliguori7b5d76d2009-03-13 15:02:13 +0000298 if (bgr)
299 dval = rgb_to_pixel32bgr(r, g, b);
300 else
301 dval = rgb_to_pixel32(r, g, b);
blueswir1eee0b832007-04-21 19:45:49 +0000302 } else {
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100303 /* 8-bit pseudocolor */
blueswir1eee0b832007-04-21 19:45:49 +0000304 val = *s;
305 dval = s1->palette[val];
306 }
307 *p++ = dval;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100308 cplane++;
blueswir1eee0b832007-04-21 19:45:49 +0000309 }
310}
311
bellarde80cfcf2004-12-19 23:18:01 +0000312/* Fixed line length 1024 allows us to do nice tricks not possible on
313 VGA... */
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100314
pbrook95219892006-04-09 01:06:34 +0000315static void tcx_update_display(void *opaque)
bellarde80cfcf2004-12-19 23:18:01 +0000316{
317 TCXState *ts = opaque;
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100318 DisplaySurface *surface = qemu_console_surface(ts->con);
Anthony Liguoric227f092009-10-01 16:12:16 -0500319 ram_addr_t page, page_min, page_max;
bellard550be122006-08-02 22:19:33 +0000320 int y, y_start, dd, ds;
bellarde80cfcf2004-12-19 23:18:01 +0000321 uint8_t *d, *s;
blueswir1b3ceef22007-06-25 19:56:13 +0000322 void (*f)(TCXState *s1, uint8_t *dst, const uint8_t *src, int width);
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100323 void (*fc)(TCXState *s1, uint8_t *dst, int y, int width);
bellarde80cfcf2004-12-19 23:18:01 +0000324
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100325 if (surface_bits_per_pixel(surface) == 0) {
blueswir1f930d072007-10-06 11:28:21 +0000326 return;
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100327 }
328
Avi Kivityd08151b2011-10-05 18:26:24 +0200329 page = 0;
bellarde80cfcf2004-12-19 23:18:01 +0000330 y_start = -1;
Blue Swirlc0c440f2009-04-27 18:10:37 +0000331 page_min = -1;
bellard550be122006-08-02 22:19:33 +0000332 page_max = 0;
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100333 d = surface_data(surface);
bellard6f7e9ae2005-03-13 09:43:36 +0000334 s = ts->vram;
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100335 dd = surface_stride(surface);
bellarde80cfcf2004-12-19 23:18:01 +0000336 ds = 1024;
337
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100338 switch (surface_bits_per_pixel(surface)) {
bellarde80cfcf2004-12-19 23:18:01 +0000339 case 32:
blueswir1f930d072007-10-06 11:28:21 +0000340 f = tcx_draw_line32;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100341 fc = tcx_draw_cursor32;
blueswir1f930d072007-10-06 11:28:21 +0000342 break;
bellard21206a12006-09-09 11:31:34 +0000343 case 15:
344 case 16:
blueswir1f930d072007-10-06 11:28:21 +0000345 f = tcx_draw_line16;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100346 fc = tcx_draw_cursor16;
blueswir1f930d072007-10-06 11:28:21 +0000347 break;
bellarde80cfcf2004-12-19 23:18:01 +0000348 default:
349 case 8:
blueswir1f930d072007-10-06 11:28:21 +0000350 f = tcx_draw_line8;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100351 fc = tcx_draw_cursor8;
blueswir1f930d072007-10-06 11:28:21 +0000352 break;
bellarde80cfcf2004-12-19 23:18:01 +0000353 case 0:
blueswir1f930d072007-10-06 11:28:21 +0000354 return;
bellarde80cfcf2004-12-19 23:18:01 +0000355 }
ths3b46e622007-09-17 08:09:54 +0000356
Paolo Bonzini5299c0f2015-04-22 13:12:40 +0200357 memory_region_sync_dirty_bitmap(&ts->vram_mem);
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100358 for (y = 0; y < ts->height; page += TARGET_PAGE_SIZE) {
Blue Swirlcd7a45c2012-01-22 16:38:21 +0000359 if (memory_region_get_dirty(&ts->vram_mem, page, TARGET_PAGE_SIZE,
360 DIRTY_MEMORY_VGA)) {
blueswir1f930d072007-10-06 11:28:21 +0000361 if (y_start < 0)
bellarde80cfcf2004-12-19 23:18:01 +0000362 y_start = y;
363 if (page < page_min)
364 page_min = page;
365 if (page > page_max)
366 page_max = page;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100367
blueswir1f930d072007-10-06 11:28:21 +0000368 f(ts, d, s, ts->width);
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100369 if (y >= ts->cursy && y < ts->cursy + 32 && ts->cursx < ts->width) {
370 fc(ts, d, y, ts->width);
371 }
blueswir1f930d072007-10-06 11:28:21 +0000372 d += dd;
373 s += ds;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100374 y++;
375
blueswir1f930d072007-10-06 11:28:21 +0000376 f(ts, d, s, ts->width);
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100377 if (y >= ts->cursy && y < ts->cursy + 32 && ts->cursx < ts->width) {
378 fc(ts, d, y, ts->width);
379 }
blueswir1f930d072007-10-06 11:28:21 +0000380 d += dd;
381 s += ds;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100382 y++;
383
blueswir1f930d072007-10-06 11:28:21 +0000384 f(ts, d, s, ts->width);
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100385 if (y >= ts->cursy && y < ts->cursy + 32 && ts->cursx < ts->width) {
386 fc(ts, d, y, ts->width);
387 }
blueswir1f930d072007-10-06 11:28:21 +0000388 d += dd;
389 s += ds;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100390 y++;
391
blueswir1f930d072007-10-06 11:28:21 +0000392 f(ts, d, s, ts->width);
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100393 if (y >= ts->cursy && y < ts->cursy + 32 && ts->cursx < ts->width) {
394 fc(ts, d, y, ts->width);
395 }
blueswir1f930d072007-10-06 11:28:21 +0000396 d += dd;
397 s += ds;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100398 y++;
blueswir1f930d072007-10-06 11:28:21 +0000399 } else {
bellarde80cfcf2004-12-19 23:18:01 +0000400 if (y_start >= 0) {
401 /* flush to display */
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100402 dpy_gfx_update(ts->con, 0, y_start,
Gerd Hoffmanna93a4a22012-09-28 15:02:08 +0200403 ts->width, y - y_start);
bellarde80cfcf2004-12-19 23:18:01 +0000404 y_start = -1;
405 }
blueswir1f930d072007-10-06 11:28:21 +0000406 d += dd * 4;
407 s += ds * 4;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100408 y += 4;
blueswir1f930d072007-10-06 11:28:21 +0000409 }
bellarde80cfcf2004-12-19 23:18:01 +0000410 }
411 if (y_start >= 0) {
blueswir1f930d072007-10-06 11:28:21 +0000412 /* flush to display */
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100413 dpy_gfx_update(ts->con, 0, y_start,
Gerd Hoffmanna93a4a22012-09-28 15:02:08 +0200414 ts->width, y - y_start);
bellarde80cfcf2004-12-19 23:18:01 +0000415 }
416 /* reset modified pages */
Blue Swirlc0c440f2009-04-27 18:10:37 +0000417 if (page_max >= page_min) {
Avi Kivityd08151b2011-10-05 18:26:24 +0200418 memory_region_reset_dirty(&ts->vram_mem,
Mark Cave-Aylandf10acc82013-06-02 17:23:00 +0100419 page_min,
420 (page_max - page_min) + TARGET_PAGE_SIZE,
Avi Kivityd08151b2011-10-05 18:26:24 +0200421 DIRTY_MEMORY_VGA);
bellarde80cfcf2004-12-19 23:18:01 +0000422 }
423}
424
blueswir1eee0b832007-04-21 19:45:49 +0000425static void tcx24_update_display(void *opaque)
426{
427 TCXState *ts = opaque;
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100428 DisplaySurface *surface = qemu_console_surface(ts->con);
Anthony Liguoric227f092009-10-01 16:12:16 -0500429 ram_addr_t page, page_min, page_max, cpage, page24;
blueswir1eee0b832007-04-21 19:45:49 +0000430 int y, y_start, dd, ds;
431 uint8_t *d, *s;
432 uint32_t *cptr, *s24;
433
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100434 if (surface_bits_per_pixel(surface) != 32) {
blueswir1eee0b832007-04-21 19:45:49 +0000435 return;
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100436 }
437
Avi Kivityd08151b2011-10-05 18:26:24 +0200438 page = 0;
blueswir1eee0b832007-04-21 19:45:49 +0000439 page24 = ts->vram24_offset;
440 cpage = ts->cplane_offset;
441 y_start = -1;
Blue Swirlc0c440f2009-04-27 18:10:37 +0000442 page_min = -1;
blueswir1eee0b832007-04-21 19:45:49 +0000443 page_max = 0;
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100444 d = surface_data(surface);
blueswir1eee0b832007-04-21 19:45:49 +0000445 s = ts->vram;
446 s24 = ts->vram24;
447 cptr = ts->cplane;
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100448 dd = surface_stride(surface);
blueswir1eee0b832007-04-21 19:45:49 +0000449 ds = 1024;
450
Paolo Bonzini5299c0f2015-04-22 13:12:40 +0200451 memory_region_sync_dirty_bitmap(&ts->vram_mem);
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100452 for (y = 0; y < ts->height; page += TARGET_PAGE_SIZE,
blueswir1eee0b832007-04-21 19:45:49 +0000453 page24 += TARGET_PAGE_SIZE, cpage += TARGET_PAGE_SIZE) {
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100454 if (tcx24_check_dirty(ts, page, page24, cpage)) {
blueswir1eee0b832007-04-21 19:45:49 +0000455 if (y_start < 0)
456 y_start = y;
457 if (page < page_min)
458 page_min = page;
459 if (page > page_max)
460 page_max = page;
461 tcx24_draw_line32(ts, d, s, ts->width, cptr, s24);
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100462 if (y >= ts->cursy && y < ts->cursy+32 && ts->cursx < ts->width) {
463 tcx_draw_cursor32(ts, d, y, ts->width);
464 }
blueswir1eee0b832007-04-21 19:45:49 +0000465 d += dd;
466 s += ds;
467 cptr += ds;
468 s24 += ds;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100469 y++;
blueswir1eee0b832007-04-21 19:45:49 +0000470 tcx24_draw_line32(ts, d, s, ts->width, cptr, s24);
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100471 if (y >= ts->cursy && y < ts->cursy+32 && ts->cursx < ts->width) {
472 tcx_draw_cursor32(ts, d, y, ts->width);
473 }
blueswir1eee0b832007-04-21 19:45:49 +0000474 d += dd;
475 s += ds;
476 cptr += ds;
477 s24 += ds;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100478 y++;
blueswir1eee0b832007-04-21 19:45:49 +0000479 tcx24_draw_line32(ts, d, s, ts->width, cptr, s24);
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100480 if (y >= ts->cursy && y < ts->cursy+32 && ts->cursx < ts->width) {
481 tcx_draw_cursor32(ts, d, y, ts->width);
482 }
blueswir1eee0b832007-04-21 19:45:49 +0000483 d += dd;
484 s += ds;
485 cptr += ds;
486 s24 += ds;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100487 y++;
blueswir1eee0b832007-04-21 19:45:49 +0000488 tcx24_draw_line32(ts, d, s, ts->width, cptr, s24);
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100489 if (y >= ts->cursy && y < ts->cursy+32 && ts->cursx < ts->width) {
490 tcx_draw_cursor32(ts, d, y, ts->width);
491 }
blueswir1eee0b832007-04-21 19:45:49 +0000492 d += dd;
493 s += ds;
494 cptr += ds;
495 s24 += ds;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100496 y++;
blueswir1eee0b832007-04-21 19:45:49 +0000497 } else {
498 if (y_start >= 0) {
499 /* flush to display */
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100500 dpy_gfx_update(ts->con, 0, y_start,
Gerd Hoffmanna93a4a22012-09-28 15:02:08 +0200501 ts->width, y - y_start);
blueswir1eee0b832007-04-21 19:45:49 +0000502 y_start = -1;
503 }
504 d += dd * 4;
505 s += ds * 4;
506 cptr += ds * 4;
507 s24 += ds * 4;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100508 y += 4;
blueswir1eee0b832007-04-21 19:45:49 +0000509 }
510 }
511 if (y_start >= 0) {
512 /* flush to display */
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100513 dpy_gfx_update(ts->con, 0, y_start,
Gerd Hoffmanna93a4a22012-09-28 15:02:08 +0200514 ts->width, y - y_start);
blueswir1eee0b832007-04-21 19:45:49 +0000515 }
516 /* reset modified pages */
Blue Swirlc0c440f2009-04-27 18:10:37 +0000517 if (page_max >= page_min) {
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100518 tcx24_reset_dirty(ts, page_min, page_max, page24, cpage);
blueswir1eee0b832007-04-21 19:45:49 +0000519 }
520}
521
pbrook95219892006-04-09 01:06:34 +0000522static void tcx_invalidate_display(void *opaque)
bellard420557e2004-09-30 22:13:50 +0000523{
524 TCXState *s = opaque;
bellard420557e2004-09-30 22:13:50 +0000525
Blue Swirld3ffcaf2009-07-16 13:45:57 +0000526 tcx_set_dirty(s);
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100527 qemu_console_resize(s->con, s->width, s->height);
bellarde80cfcf2004-12-19 23:18:01 +0000528}
529
blueswir1eee0b832007-04-21 19:45:49 +0000530static void tcx24_invalidate_display(void *opaque)
531{
532 TCXState *s = opaque;
blueswir1eee0b832007-04-21 19:45:49 +0000533
Blue Swirld3ffcaf2009-07-16 13:45:57 +0000534 tcx_set_dirty(s);
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100535 qemu_console_resize(s->con, s->width, s->height);
blueswir1eee0b832007-04-21 19:45:49 +0000536}
537
Juan Quintelae59fb372009-09-29 22:48:21 +0200538static int vmstate_tcx_post_load(void *opaque, int version_id)
bellarde80cfcf2004-12-19 23:18:01 +0000539{
540 TCXState *s = opaque;
ths3b46e622007-09-17 08:09:54 +0000541
bellard21206a12006-09-09 11:31:34 +0000542 update_palette_entries(s, 0, 256);
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100543 tcx_set_dirty(s);
bellard420557e2004-09-30 22:13:50 +0000544 return 0;
545}
546
Blue Swirlc0c41a42009-08-28 20:43:01 +0000547static const VMStateDescription vmstate_tcx = {
548 .name ="tcx",
549 .version_id = 4,
550 .minimum_version_id = 4,
Juan Quintela752ff2f2009-09-10 03:04:30 +0200551 .post_load = vmstate_tcx_post_load,
Juan Quintela35d08452014-04-16 16:01:33 +0200552 .fields = (VMStateField[]) {
Blue Swirlc0c41a42009-08-28 20:43:01 +0000553 VMSTATE_UINT16(height, TCXState),
554 VMSTATE_UINT16(width, TCXState),
555 VMSTATE_UINT16(depth, TCXState),
556 VMSTATE_BUFFER(r, TCXState),
557 VMSTATE_BUFFER(g, TCXState),
558 VMSTATE_BUFFER(b, TCXState),
559 VMSTATE_UINT8(dac_index, TCXState),
560 VMSTATE_UINT8(dac_state, TCXState),
561 VMSTATE_END_OF_LIST()
562 }
563};
564
Michael S. Tsirkin7f23f812009-09-16 13:40:27 +0300565static void tcx_reset(DeviceState *d)
bellard420557e2004-09-30 22:13:50 +0000566{
Andreas Färber01774dd2013-07-25 01:13:54 +0200567 TCXState *s = TCX(d);
bellard420557e2004-09-30 22:13:50 +0000568
bellarde80cfcf2004-12-19 23:18:01 +0000569 /* Initialize palette */
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100570 memset(s->r, 0, 260);
571 memset(s->g, 0, 260);
572 memset(s->b, 0, 260);
bellarde80cfcf2004-12-19 23:18:01 +0000573 s->r[255] = s->g[255] = s->b[255] = 255;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100574 s->r[256] = s->g[256] = s->b[256] = 255;
575 s->r[258] = s->g[258] = s->b[258] = 255;
576 update_palette_entries(s, 0, 260);
bellarde80cfcf2004-12-19 23:18:01 +0000577 memset(s->vram, 0, MAXX*MAXY);
Avi Kivityd08151b2011-10-05 18:26:24 +0200578 memory_region_reset_dirty(&s->vram_mem, 0, MAXX * MAXY * (1 + 4 + 4),
579 DIRTY_MEMORY_VGA);
bellard6f7e9ae2005-03-13 09:43:36 +0000580 s->dac_index = 0;
581 s->dac_state = 0;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100582 s->cursx = 0xf000; /* Put cursor off screen */
583 s->cursy = 0xf000;
bellard420557e2004-09-30 22:13:50 +0000584}
585
Avi Kivitya8170e52012-10-23 12:30:10 +0200586static uint64_t tcx_dac_readl(void *opaque, hwaddr addr,
Avi Kivityd08151b2011-10-05 18:26:24 +0200587 unsigned size)
bellard6f7e9ae2005-03-13 09:43:36 +0000588{
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100589 TCXState *s = opaque;
590 uint32_t val = 0;
591
592 switch (s->dac_state) {
593 case 0:
594 val = s->r[s->dac_index] << 24;
595 s->dac_state++;
596 break;
597 case 1:
598 val = s->g[s->dac_index] << 24;
599 s->dac_state++;
600 break;
601 case 2:
602 val = s->b[s->dac_index] << 24;
603 s->dac_index = (s->dac_index + 1) & 0xff; /* Index autoincrement */
604 default:
605 s->dac_state = 0;
606 break;
607 }
608
609 return val;
bellard6f7e9ae2005-03-13 09:43:36 +0000610}
611
Avi Kivitya8170e52012-10-23 12:30:10 +0200612static void tcx_dac_writel(void *opaque, hwaddr addr, uint64_t val,
Avi Kivityd08151b2011-10-05 18:26:24 +0200613 unsigned size)
bellard6f7e9ae2005-03-13 09:43:36 +0000614{
615 TCXState *s = opaque;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100616 unsigned index;
bellard6f7e9ae2005-03-13 09:43:36 +0000617
blueswir1e64d7d52008-12-02 17:47:02 +0000618 switch (addr) {
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100619 case 0: /* Address */
blueswir1f930d072007-10-06 11:28:21 +0000620 s->dac_index = val >> 24;
621 s->dac_state = 0;
622 break;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100623 case 4: /* Pixel colours */
624 case 12: /* Overlay (cursor) colours */
625 if (addr & 8) {
626 index = (s->dac_index & 3) + 256;
627 } else {
628 index = s->dac_index;
629 }
blueswir1f930d072007-10-06 11:28:21 +0000630 switch (s->dac_state) {
631 case 0:
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100632 s->r[index] = val >> 24;
633 update_palette_entries(s, index, index + 1);
blueswir1f930d072007-10-06 11:28:21 +0000634 s->dac_state++;
635 break;
636 case 1:
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100637 s->g[index] = val >> 24;
638 update_palette_entries(s, index, index + 1);
blueswir1f930d072007-10-06 11:28:21 +0000639 s->dac_state++;
640 break;
641 case 2:
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100642 s->b[index] = val >> 24;
643 update_palette_entries(s, index, index + 1);
644 s->dac_index = (s->dac_index + 1) & 0xff; /* Index autoincrement */
blueswir1f930d072007-10-06 11:28:21 +0000645 default:
646 s->dac_state = 0;
647 break;
648 }
649 break;
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100650 default: /* Control registers */
blueswir1f930d072007-10-06 11:28:21 +0000651 break;
bellard6f7e9ae2005-03-13 09:43:36 +0000652 }
bellard6f7e9ae2005-03-13 09:43:36 +0000653}
654
Avi Kivityd08151b2011-10-05 18:26:24 +0200655static const MemoryRegionOps tcx_dac_ops = {
656 .read = tcx_dac_readl,
657 .write = tcx_dac_writel,
658 .endianness = DEVICE_NATIVE_ENDIAN,
659 .valid = {
660 .min_access_size = 4,
661 .max_access_size = 4,
662 },
bellard6f7e9ae2005-03-13 09:43:36 +0000663};
664
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100665static uint64_t tcx_stip_readl(void *opaque, hwaddr addr,
666 unsigned size)
667{
668 return 0;
669}
670
671static void tcx_stip_writel(void *opaque, hwaddr addr,
672 uint64_t val, unsigned size)
673{
674 TCXState *s = opaque;
675 int i;
676 uint32_t col;
677
678 if (!(addr & 4)) {
679 s->tmpblit = val;
680 } else {
681 addr = (addr >> 3) & 0xfffff;
682 col = cpu_to_be32(s->tmpblit);
683 if (s->depth == 24) {
684 for (i = 0; i < 32; i++) {
685 if (val & 0x80000000) {
686 s->vram[addr + i] = s->tmpblit;
687 s->vram24[addr + i] = col;
688 }
689 val <<= 1;
690 }
691 } else {
692 for (i = 0; i < 32; i++) {
693 if (val & 0x80000000) {
694 s->vram[addr + i] = s->tmpblit;
695 }
696 val <<= 1;
697 }
698 }
699 memory_region_set_dirty(&s->vram_mem, addr, 32);
700 }
701}
702
703static void tcx_rstip_writel(void *opaque, hwaddr addr,
704 uint64_t val, unsigned size)
705{
706 TCXState *s = opaque;
707 int i;
708 uint32_t col;
709
710 if (!(addr & 4)) {
711 s->tmpblit = val;
712 } else {
713 addr = (addr >> 3) & 0xfffff;
714 col = cpu_to_be32(s->tmpblit);
715 if (s->depth == 24) {
716 for (i = 0; i < 32; i++) {
717 if (val & 0x80000000) {
718 s->vram[addr + i] = s->tmpblit;
719 s->vram24[addr + i] = col;
720 s->cplane[addr + i] = col;
721 }
722 val <<= 1;
723 }
724 } else {
725 for (i = 0; i < 32; i++) {
726 if (val & 0x80000000) {
727 s->vram[addr + i] = s->tmpblit;
728 }
729 val <<= 1;
730 }
731 }
732 memory_region_set_dirty(&s->vram_mem, addr, 32);
733 }
734}
735
736static const MemoryRegionOps tcx_stip_ops = {
737 .read = tcx_stip_readl,
738 .write = tcx_stip_writel,
739 .endianness = DEVICE_NATIVE_ENDIAN,
740 .valid = {
741 .min_access_size = 4,
742 .max_access_size = 4,
743 },
744};
745
746static const MemoryRegionOps tcx_rstip_ops = {
747 .read = tcx_stip_readl,
748 .write = tcx_rstip_writel,
749 .endianness = DEVICE_NATIVE_ENDIAN,
750 .valid = {
751 .min_access_size = 4,
752 .max_access_size = 4,
753 },
754};
755
756static uint64_t tcx_blit_readl(void *opaque, hwaddr addr,
757 unsigned size)
758{
759 return 0;
760}
761
762static void tcx_blit_writel(void *opaque, hwaddr addr,
763 uint64_t val, unsigned size)
764{
765 TCXState *s = opaque;
766 uint32_t adsr, len;
767 int i;
768
769 if (!(addr & 4)) {
770 s->tmpblit = val;
771 } else {
772 addr = (addr >> 3) & 0xfffff;
773 adsr = val & 0xffffff;
774 len = ((val >> 24) & 0x1f) + 1;
775 if (adsr == 0xffffff) {
776 memset(&s->vram[addr], s->tmpblit, len);
777 if (s->depth == 24) {
778 val = s->tmpblit & 0xffffff;
779 val = cpu_to_be32(val);
780 for (i = 0; i < len; i++) {
781 s->vram24[addr + i] = val;
782 }
783 }
784 } else {
785 memcpy(&s->vram[addr], &s->vram[adsr], len);
786 if (s->depth == 24) {
787 memcpy(&s->vram24[addr], &s->vram24[adsr], len * 4);
788 }
789 }
790 memory_region_set_dirty(&s->vram_mem, addr, len);
791 }
792}
793
794static void tcx_rblit_writel(void *opaque, hwaddr addr,
795 uint64_t val, unsigned size)
796{
797 TCXState *s = opaque;
798 uint32_t adsr, len;
799 int i;
800
801 if (!(addr & 4)) {
802 s->tmpblit = val;
803 } else {
804 addr = (addr >> 3) & 0xfffff;
805 adsr = val & 0xffffff;
806 len = ((val >> 24) & 0x1f) + 1;
807 if (adsr == 0xffffff) {
808 memset(&s->vram[addr], s->tmpblit, len);
809 if (s->depth == 24) {
810 val = s->tmpblit & 0xffffff;
811 val = cpu_to_be32(val);
812 for (i = 0; i < len; i++) {
813 s->vram24[addr + i] = val;
814 s->cplane[addr + i] = val;
815 }
816 }
817 } else {
818 memcpy(&s->vram[addr], &s->vram[adsr], len);
819 if (s->depth == 24) {
820 memcpy(&s->vram24[addr], &s->vram24[adsr], len * 4);
821 memcpy(&s->cplane[addr], &s->cplane[adsr], len * 4);
822 }
823 }
824 memory_region_set_dirty(&s->vram_mem, addr, len);
825 }
826}
827
828static const MemoryRegionOps tcx_blit_ops = {
829 .read = tcx_blit_readl,
830 .write = tcx_blit_writel,
831 .endianness = DEVICE_NATIVE_ENDIAN,
832 .valid = {
833 .min_access_size = 4,
834 .max_access_size = 4,
835 },
836};
837
838static const MemoryRegionOps tcx_rblit_ops = {
839 .read = tcx_blit_readl,
840 .write = tcx_rblit_writel,
841 .endianness = DEVICE_NATIVE_ENDIAN,
842 .valid = {
843 .min_access_size = 4,
844 .max_access_size = 4,
845 },
846};
847
848static void tcx_invalidate_cursor_position(TCXState *s)
849{
850 int ymin, ymax, start, end;
851
852 /* invalidate only near the cursor */
853 ymin = s->cursy;
854 if (ymin >= s->height) {
855 return;
856 }
857 ymax = MIN(s->height, ymin + 32);
858 start = ymin * 1024;
859 end = ymax * 1024;
860
861 memory_region_set_dirty(&s->vram_mem, start, end-start);
862}
863
864static uint64_t tcx_thc_readl(void *opaque, hwaddr addr,
865 unsigned size)
866{
867 TCXState *s = opaque;
868 uint64_t val;
869
870 if (addr == TCX_THC_MISC) {
871 val = s->thcmisc | 0x02000000;
872 } else {
873 val = 0;
874 }
875 return val;
876}
877
878static void tcx_thc_writel(void *opaque, hwaddr addr,
879 uint64_t val, unsigned size)
880{
881 TCXState *s = opaque;
882
883 if (addr == TCX_THC_CURSXY) {
884 tcx_invalidate_cursor_position(s);
885 s->cursx = val >> 16;
886 s->cursy = val;
887 tcx_invalidate_cursor_position(s);
888 } else if (addr >= TCX_THC_CURSMASK && addr < TCX_THC_CURSMASK + 128) {
889 s->cursmask[(addr - TCX_THC_CURSMASK) >> 2] = val;
890 tcx_invalidate_cursor_position(s);
891 } else if (addr >= TCX_THC_CURSBITS && addr < TCX_THC_CURSBITS + 128) {
892 s->cursbits[(addr - TCX_THC_CURSBITS) >> 2] = val;
893 tcx_invalidate_cursor_position(s);
894 } else if (addr == TCX_THC_MISC) {
895 s->thcmisc = val;
896 }
897
898}
899
900static const MemoryRegionOps tcx_thc_ops = {
901 .read = tcx_thc_readl,
902 .write = tcx_thc_writel,
903 .endianness = DEVICE_NATIVE_ENDIAN,
904 .valid = {
905 .min_access_size = 4,
906 .max_access_size = 4,
907 },
908};
909
910static uint64_t tcx_dummy_readl(void *opaque, hwaddr addr,
Avi Kivityd08151b2011-10-05 18:26:24 +0200911 unsigned size)
blueswir18508b892007-05-06 17:39:55 +0000912{
913 return 0;
914}
915
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100916static void tcx_dummy_writel(void *opaque, hwaddr addr,
Avi Kivityd08151b2011-10-05 18:26:24 +0200917 uint64_t val, unsigned size)
blueswir18508b892007-05-06 17:39:55 +0000918{
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100919 return;
blueswir18508b892007-05-06 17:39:55 +0000920}
921
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100922static const MemoryRegionOps tcx_dummy_ops = {
923 .read = tcx_dummy_readl,
924 .write = tcx_dummy_writel,
Avi Kivityd08151b2011-10-05 18:26:24 +0200925 .endianness = DEVICE_NATIVE_ENDIAN,
926 .valid = {
927 .min_access_size = 4,
928 .max_access_size = 4,
929 },
blueswir18508b892007-05-06 17:39:55 +0000930};
931
Gerd Hoffmann380cd052013-03-13 14:04:18 +0100932static const GraphicHwOps tcx_ops = {
933 .invalidate = tcx_invalidate_display,
934 .gfx_update = tcx_update_display,
935};
936
937static const GraphicHwOps tcx24_ops = {
938 .invalidate = tcx24_invalidate_display,
939 .gfx_update = tcx24_update_display,
940};
941
Mark Cave-Ayland01b91ac2014-05-24 12:44:53 +0100942static void tcx_initfn(Object *obj)
943{
944 SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
945 TCXState *s = TCX(obj);
946
Thomas Huthb21de192015-10-15 10:54:15 +0200947 memory_region_init_ram(&s->rom, obj, "tcx.prom", FCODE_MAX_ROM_SIZE,
Markus Armbrusterf8ed85a2015-09-11 16:51:43 +0200948 &error_fatal);
Mark Cave-Ayland01b91ac2014-05-24 12:44:53 +0100949 memory_region_set_readonly(&s->rom, true);
950 sysbus_init_mmio(sbd, &s->rom);
951
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100952 /* 2/STIP : Stippler */
Thomas Huthb21de192015-10-15 10:54:15 +0200953 memory_region_init_io(&s->stip, obj, &tcx_stip_ops, s, "tcx.stip",
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100954 TCX_STIP_NREGS);
955 sysbus_init_mmio(sbd, &s->stip);
956
957 /* 3/BLIT : Blitter */
Thomas Huthb21de192015-10-15 10:54:15 +0200958 memory_region_init_io(&s->blit, obj, &tcx_blit_ops, s, "tcx.blit",
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100959 TCX_BLIT_NREGS);
960 sysbus_init_mmio(sbd, &s->blit);
961
962 /* 5/RSTIP : Raw Stippler */
Thomas Huthb21de192015-10-15 10:54:15 +0200963 memory_region_init_io(&s->rstip, obj, &tcx_rstip_ops, s, "tcx.rstip",
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100964 TCX_RSTIP_NREGS);
965 sysbus_init_mmio(sbd, &s->rstip);
966
967 /* 6/RBLIT : Raw Blitter */
Thomas Huthb21de192015-10-15 10:54:15 +0200968 memory_region_init_io(&s->rblit, obj, &tcx_rblit_ops, s, "tcx.rblit",
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100969 TCX_RBLIT_NREGS);
970 sysbus_init_mmio(sbd, &s->rblit);
971
972 /* 7/TEC : ??? */
Thomas Huthb21de192015-10-15 10:54:15 +0200973 memory_region_init_io(&s->tec, obj, &tcx_dummy_ops, s, "tcx.tec",
974 TCX_TEC_NREGS);
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100975 sysbus_init_mmio(sbd, &s->tec);
976
977 /* 8/CMAP : DAC */
Thomas Huthb21de192015-10-15 10:54:15 +0200978 memory_region_init_io(&s->dac, obj, &tcx_dac_ops, s, "tcx.dac",
979 TCX_DAC_NREGS);
Mark Cave-Ayland01b91ac2014-05-24 12:44:53 +0100980 sysbus_init_mmio(sbd, &s->dac);
981
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100982 /* 9/THC : Cursor */
Thomas Huthb21de192015-10-15 10:54:15 +0200983 memory_region_init_io(&s->thc, obj, &tcx_thc_ops, s, "tcx.thc",
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100984 TCX_THC_NREGS);
985 sysbus_init_mmio(sbd, &s->thc);
Mark Cave-Ayland01b91ac2014-05-24 12:44:53 +0100986
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100987 /* 11/DHC : ??? */
Thomas Huthb21de192015-10-15 10:54:15 +0200988 memory_region_init_io(&s->dhc, obj, &tcx_dummy_ops, s, "tcx.dhc",
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100989 TCX_DHC_NREGS);
990 sysbus_init_mmio(sbd, &s->dhc);
991
992 /* 12/ALT : ??? */
Thomas Huthb21de192015-10-15 10:54:15 +0200993 memory_region_init_io(&s->alt, obj, &tcx_dummy_ops, s, "tcx.alt",
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +0100994 TCX_ALT_NREGS);
995 sysbus_init_mmio(sbd, &s->alt);
Mark Cave-Ayland01b91ac2014-05-24 12:44:53 +0100996}
997
Mark Cave-Aylandd4ad9de2014-05-24 12:19:44 +0100998static void tcx_realizefn(DeviceState *dev, Error **errp)
Blue Swirlf40070c2009-07-12 19:21:36 +0000999{
Mark Cave-Aylandd4ad9de2014-05-24 12:19:44 +01001000 SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
Andreas Färber01774dd2013-07-25 01:13:54 +02001001 TCXState *s = TCX(dev);
Avi Kivityd08151b2011-10-05 18:26:24 +02001002 ram_addr_t vram_offset = 0;
Mark Cave-Aylandda87dd72013-11-02 16:03:50 +00001003 int size, ret;
pbrookdc828ca2009-04-09 22:21:07 +00001004 uint8_t *vram_base;
Mark Cave-Aylandda87dd72013-11-02 16:03:50 +00001005 char *fcode_filename;
pbrookdc828ca2009-04-09 22:21:07 +00001006
Paolo Bonzini3eadad52013-06-06 21:25:08 -04001007 memory_region_init_ram(&s->vram_mem, OBJECT(s), "tcx.vram",
Markus Armbrusterf8ed85a2015-09-11 16:51:43 +02001008 s->vram_size * (1 + 4 + 4), &error_fatal);
Avi Kivityc5705a72011-12-20 15:59:12 +02001009 vmstate_register_ram_global(&s->vram_mem);
Paolo Bonzini74259ae2015-03-23 10:47:45 +01001010 memory_region_set_log(&s->vram_mem, true, DIRTY_MEMORY_VGA);
Avi Kivityd08151b2011-10-05 18:26:24 +02001011 vram_base = memory_region_get_ram_ptr(&s->vram_mem);
bellarde80cfcf2004-12-19 23:18:01 +00001012
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +01001013 /* 10/ROM : FCode ROM */
Mark Cave-Aylandda87dd72013-11-02 16:03:50 +00001014 vmstate_register_ram_global(&s->rom);
Mark Cave-Aylandda87dd72013-11-02 16:03:50 +00001015 fcode_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, TCX_ROM_FILE);
1016 if (fcode_filename) {
1017 ret = load_image_targphys(fcode_filename, s->prom_addr,
1018 FCODE_MAX_ROM_SIZE);
Shannon Zhao8684e852015-05-28 19:13:45 +08001019 g_free(fcode_filename);
Mark Cave-Aylandda87dd72013-11-02 16:03:50 +00001020 if (ret < 0 || ret > FCODE_MAX_ROM_SIZE) {
Mark Cave-Aylandd4ad9de2014-05-24 12:19:44 +01001021 error_report("tcx: could not load prom '%s'", TCX_ROM_FILE);
Mark Cave-Aylandda87dd72013-11-02 16:03:50 +00001022 }
1023 }
1024
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +01001025 /* 0/DFB8 : 8-bit plane */
blueswir1eee0b832007-04-21 19:45:49 +00001026 s->vram = vram_base;
Gerd Hoffmannee6847d2009-07-15 13:43:31 +02001027 size = s->vram_size;
Paolo Bonzini3eadad52013-06-06 21:25:08 -04001028 memory_region_init_alias(&s->vram_8bit, OBJECT(s), "tcx.vram.8bit",
Avi Kivityd08151b2011-10-05 18:26:24 +02001029 &s->vram_mem, vram_offset, size);
Mark Cave-Aylandd4ad9de2014-05-24 12:19:44 +01001030 sysbus_init_mmio(sbd, &s->vram_8bit);
blueswir1eee0b832007-04-21 19:45:49 +00001031 vram_offset += size;
1032 vram_base += size;
1033
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +01001034 /* 1/DFB24 : 24bit plane */
1035 size = s->vram_size * 4;
1036 s->vram24 = (uint32_t *)vram_base;
1037 s->vram24_offset = vram_offset;
1038 memory_region_init_alias(&s->vram_24bit, OBJECT(s), "tcx.vram.24bit",
1039 &s->vram_mem, vram_offset, size);
1040 sysbus_init_mmio(sbd, &s->vram_24bit);
1041 vram_offset += size;
1042 vram_base += size;
blueswir1eee0b832007-04-21 19:45:49 +00001043
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +01001044 /* 4/RDFB32 : Raw Framebuffer */
1045 size = s->vram_size * 4;
1046 s->cplane = (uint32_t *)vram_base;
1047 s->cplane_offset = vram_offset;
1048 memory_region_init_alias(&s->vram_cplane, OBJECT(s), "tcx.vram.cplane",
1049 &s->vram_mem, vram_offset, size);
1050 sysbus_init_mmio(sbd, &s->vram_cplane);
Blue Swirlf40070c2009-07-12 19:21:36 +00001051
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +01001052 /* 9/THC24bits : NetBSD writes here even with 8-bit display: dummy */
1053 if (s->depth == 8) {
1054 memory_region_init_io(&s->thc24, OBJECT(s), &tcx_dummy_ops, s,
1055 "tcx.thc24", TCX_THC_NREGS);
1056 sysbus_init_mmio(sbd, &s->thc24);
blueswir1eee0b832007-04-21 19:45:49 +00001057 }
1058
Mark Cave-Ayland55d7bfe2014-09-13 10:44:07 +01001059 sysbus_init_irq(sbd, &s->irq);
1060
1061 if (s->depth == 8) {
1062 s->con = graphic_console_init(DEVICE(dev), 0, &tcx_ops, s);
1063 } else {
1064 s->con = graphic_console_init(DEVICE(dev), 0, &tcx24_ops, s);
1065 }
1066 s->thcmisc = 0;
1067
Gerd Hoffmannc78f7132013-03-05 15:24:14 +01001068 qemu_console_resize(s->con, s->width, s->height);
bellard420557e2004-09-30 22:13:50 +00001069}
1070
Anthony Liguori999e12b2012-01-24 13:12:29 -06001071static Property tcx_properties[] = {
Paolo Bonzinic7bcc852014-02-08 11:01:53 +01001072 DEFINE_PROP_UINT32("vram_size", TCXState, vram_size, -1),
Anthony Liguori999e12b2012-01-24 13:12:29 -06001073 DEFINE_PROP_UINT16("width", TCXState, width, -1),
1074 DEFINE_PROP_UINT16("height", TCXState, height, -1),
1075 DEFINE_PROP_UINT16("depth", TCXState, depth, -1),
Paolo Bonzinic7bcc852014-02-08 11:01:53 +01001076 DEFINE_PROP_UINT64("prom_addr", TCXState, prom_addr, -1),
Anthony Liguori999e12b2012-01-24 13:12:29 -06001077 DEFINE_PROP_END_OF_LIST(),
1078};
1079
1080static void tcx_class_init(ObjectClass *klass, void *data)
1081{
Anthony Liguori39bffca2011-12-07 21:34:16 -06001082 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguori999e12b2012-01-24 13:12:29 -06001083
Mark Cave-Aylandd4ad9de2014-05-24 12:19:44 +01001084 dc->realize = tcx_realizefn;
Anthony Liguori39bffca2011-12-07 21:34:16 -06001085 dc->reset = tcx_reset;
1086 dc->vmsd = &vmstate_tcx;
1087 dc->props = tcx_properties;
Anthony Liguori999e12b2012-01-24 13:12:29 -06001088}
1089
Andreas Färber8c43a6f2013-01-10 16:19:07 +01001090static const TypeInfo tcx_info = {
Andreas Färber01774dd2013-07-25 01:13:54 +02001091 .name = TYPE_TCX,
Anthony Liguori39bffca2011-12-07 21:34:16 -06001092 .parent = TYPE_SYS_BUS_DEVICE,
1093 .instance_size = sizeof(TCXState),
Mark Cave-Ayland01b91ac2014-05-24 12:44:53 +01001094 .instance_init = tcx_initfn,
Anthony Liguori39bffca2011-12-07 21:34:16 -06001095 .class_init = tcx_class_init,
Gerd Hoffmannee6847d2009-07-15 13:43:31 +02001096};
1097
Andreas Färber83f7d432012-02-09 15:20:55 +01001098static void tcx_register_types(void)
Blue Swirlf40070c2009-07-12 19:21:36 +00001099{
Anthony Liguori39bffca2011-12-07 21:34:16 -06001100 type_register_static(&tcx_info);
Blue Swirlf40070c2009-07-12 19:21:36 +00001101}
1102
Andreas Färber83f7d432012-02-09 15:20:55 +01001103type_init(tcx_register_types)