tcx.c 17.8 KB
Newer Older
1
/*
B
bellard 已提交
2
 * QEMU TCX Frame buffer
3
 *
B
bellard 已提交
4
 * Copyright (c) 2003-2005 Fabrice Bellard
5
 *
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
P
pbrook 已提交
24 25 26
#include "hw.h"
#include "sun4m.h"
#include "console.h"
B
blueswir1 已提交
27
#include "pixel_ops.h"
28 29 30

#define MAXX 1024
#define MAXY 768
B
bellard 已提交
31
#define TCX_DAC_NREGS 16
32 33 34
#define TCX_THC_NREGS_8  0x081c
#define TCX_THC_NREGS_24 0x1000
#define TCX_TEC_NREGS    0x1000
35 36

typedef struct TCXState {
37
    target_phys_addr_t addr;
38
    DisplayState *ds;
39
    QEMUConsole *console;
B
bellard 已提交
40
    uint8_t *vram;
B
blueswir1 已提交
41 42 43
    uint32_t *vram24, *cplane;
    ram_addr_t vram_offset, vram24_offset, cplane_offset;
    uint16_t width, height, depth;
B
bellard 已提交
44
    uint8_t r[256], g[256], b[256];
B
bellard 已提交
45
    uint32_t palette[256];
B
bellard 已提交
46
    uint8_t dac_index, dac_state;
47 48
} TCXState;

P
pbrook 已提交
49
static void tcx_screen_dump(void *opaque, const char *filename);
B
blueswir1 已提交
50
static void tcx24_screen_dump(void *opaque, const char *filename);
51 52
static void tcx_invalidate_display(void *opaque);
static void tcx24_invalidate_display(void *opaque);
P
pbrook 已提交
53

B
bellard 已提交
54 55 56 57
static void update_palette_entries(TCXState *s, int start, int end)
{
    int i;
    for(i = start; i < end; i++) {
58
        switch(ds_get_bits_per_pixel(s->ds)) {
B
bellard 已提交
59 60 61 62 63
        default:
        case 8:
            s->palette[i] = rgb_to_pixel8(s->r[i], s->g[i], s->b[i]);
            break;
        case 15:
64 65 66 67
            if (s->ds->bgr)
                s->palette[i] = rgb_to_pixel15bgr(s->r[i], s->g[i], s->b[i]);
            else
                s->palette[i] = rgb_to_pixel15(s->r[i], s->g[i], s->b[i]);
B
bellard 已提交
68 69
            break;
        case 16:
70 71 72 73
            if (s->ds->bgr)
                s->palette[i] = rgb_to_pixel16bgr(s->r[i], s->g[i], s->b[i]);
            else
                s->palette[i] = rgb_to_pixel16(s->r[i], s->g[i], s->b[i]);
B
bellard 已提交
74 75
            break;
        case 32:
76 77 78 79
            if (s->ds->bgr)
                s->palette[i] = rgb_to_pixel32bgr(s->r[i], s->g[i], s->b[i]);
            else
                s->palette[i] = rgb_to_pixel32(s->r[i], s->g[i], s->b[i]);
B
bellard 已提交
80 81 82
            break;
        }
    }
83 84 85 86
    if (s->depth == 24)
        tcx24_invalidate_display(s);
    else
        tcx_invalidate_display(s);
B
bellard 已提交
87 88
}

89
static void tcx_draw_line32(TCXState *s1, uint8_t *d,
B
blueswir1 已提交
90
                            const uint8_t *s, int width)
91
{
B
bellard 已提交
92 93
    int x;
    uint8_t val;
T
ths 已提交
94
    uint32_t *p = (uint32_t *)d;
B
bellard 已提交
95 96

    for(x = 0; x < width; x++) {
B
blueswir1 已提交
97
        val = *s++;
T
ths 已提交
98
        *p++ = s1->palette[val];
B
bellard 已提交
99
    }
100 101
}

102
static void tcx_draw_line16(TCXState *s1, uint8_t *d,
B
blueswir1 已提交
103
                            const uint8_t *s, int width)
B
bellard 已提交
104 105 106
{
    int x;
    uint8_t val;
T
ths 已提交
107
    uint16_t *p = (uint16_t *)d;
B
bellard 已提交
108

B
bellard 已提交
109
    for(x = 0; x < width; x++) {
B
blueswir1 已提交
110
        val = *s++;
T
ths 已提交
111
        *p++ = s1->palette[val];
B
bellard 已提交
112 113 114
    }
}

115
static void tcx_draw_line8(TCXState *s1, uint8_t *d,
B
blueswir1 已提交
116
                           const uint8_t *s, int width)
117
{
B
bellard 已提交
118 119 120 121
    int x;
    uint8_t val;

    for(x = 0; x < width; x++) {
B
blueswir1 已提交
122
        val = *s++;
B
bellard 已提交
123
        *d++ = s1->palette[val];
124 125 126
    }
}

B
blueswir1 已提交
127 128 129 130 131
/*
  XXX Could be much more optimal:
  * detect if line/page/whole screen is in 24 bit mode
  * if destination is also BGR, use memcpy
  */
B
blueswir1 已提交
132 133 134 135 136
static inline void tcx24_draw_line32(TCXState *s1, uint8_t *d,
                                     const uint8_t *s, int width,
                                     const uint32_t *cplane,
                                     const uint32_t *s24)
{
B
blueswir1 已提交
137 138
    int x, bgr, r, g, b;
    uint8_t val, *p8;
B
blueswir1 已提交
139 140 141
    uint32_t *p = (uint32_t *)d;
    uint32_t dval;

B
blueswir1 已提交
142
    bgr = s1->ds->bgr;
B
blueswir1 已提交
143
    for(x = 0; x < width; x++, s++, s24++) {
B
blueswir1 已提交
144 145 146 147 148 149 150 151 152 153 154
        if ((be32_to_cpu(*cplane++) & 0xff000000) == 0x03000000) {
            // 24-bit direct, BGR order
            p8 = (uint8_t *)s24;
            p8++;
            b = *p8++;
            g = *p8++;
            r = *p8++;
            if (bgr)
                dval = rgb_to_pixel32bgr(r, g, b);
            else
                dval = rgb_to_pixel32(r, g, b);
B
blueswir1 已提交
155 156 157 158 159 160 161 162
        } else {
            val = *s;
            dval = s1->palette[val];
        }
        *p++ = dval;
    }
}

B
blueswir1 已提交
163
static inline int check_dirty(ram_addr_t page, ram_addr_t page24,
B
blueswir1 已提交
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
                              ram_addr_t cpage)
{
    int ret;
    unsigned int off;

    ret = cpu_physical_memory_get_dirty(page, VGA_DIRTY_FLAG);
    for (off = 0; off < TARGET_PAGE_SIZE * 4; off += TARGET_PAGE_SIZE) {
        ret |= cpu_physical_memory_get_dirty(page24 + off, VGA_DIRTY_FLAG);
        ret |= cpu_physical_memory_get_dirty(cpage + off, VGA_DIRTY_FLAG);
    }
    return ret;
}

static inline void reset_dirty(TCXState *ts, ram_addr_t page_min,
                               ram_addr_t page_max, ram_addr_t page24,
                              ram_addr_t cpage)
{
    cpu_physical_memory_reset_dirty(page_min, page_max + TARGET_PAGE_SIZE,
                                    VGA_DIRTY_FLAG);
    page_min -= ts->vram_offset;
    page_max -= ts->vram_offset;
    cpu_physical_memory_reset_dirty(page24 + page_min * 4,
                                    page24 + page_max * 4 + TARGET_PAGE_SIZE,
                                    VGA_DIRTY_FLAG);
    cpu_physical_memory_reset_dirty(cpage + page_min * 4,
                                    cpage + page_max * 4 + TARGET_PAGE_SIZE,
                                    VGA_DIRTY_FLAG);
}

B
bellard 已提交
193 194
/* Fixed line length 1024 allows us to do nice tricks not possible on
   VGA... */
P
pbrook 已提交
195
static void tcx_update_display(void *opaque)
196
{
B
bellard 已提交
197
    TCXState *ts = opaque;
198 199
    ram_addr_t page, page_min, page_max;
    int y, y_start, dd, ds;
B
bellard 已提交
200
    uint8_t *d, *s;
201
    void (*f)(TCXState *s1, uint8_t *dst, const uint8_t *src, int width);
B
bellard 已提交
202

203
    if (ds_get_bits_per_pixel(ts->ds) == 0)
B
blueswir1 已提交
204
        return;
B
bellard 已提交
205
    page = ts->vram_offset;
B
bellard 已提交
206
    y_start = -1;
207 208
    page_min = 0xffffffff;
    page_max = 0;
209
    d = ds_get_data(ts->ds);
B
bellard 已提交
210
    s = ts->vram;
211
    dd = ds_get_linesize(ts->ds);
B
bellard 已提交
212 213
    ds = 1024;

214
    switch (ds_get_bits_per_pixel(ts->ds)) {
B
bellard 已提交
215
    case 32:
B
blueswir1 已提交
216 217
        f = tcx_draw_line32;
        break;
B
bellard 已提交
218 219
    case 15:
    case 16:
B
blueswir1 已提交
220 221
        f = tcx_draw_line16;
        break;
B
bellard 已提交
222 223
    default:
    case 8:
B
blueswir1 已提交
224 225
        f = tcx_draw_line8;
        break;
B
bellard 已提交
226
    case 0:
B
blueswir1 已提交
227
        return;
B
bellard 已提交
228
    }
229

B
bellard 已提交
230
    for(y = 0; y < ts->height; y += 4, page += TARGET_PAGE_SIZE) {
B
blueswir1 已提交
231 232
        if (cpu_physical_memory_get_dirty(page, VGA_DIRTY_FLAG)) {
            if (y_start < 0)
B
bellard 已提交
233 234 235 236 237
                y_start = y;
            if (page < page_min)
                page_min = page;
            if (page > page_max)
                page_max = page;
B
blueswir1 已提交
238 239 240 241 242 243 244 245 246 247 248 249 250
            f(ts, d, s, ts->width);
            d += dd;
            s += ds;
            f(ts, d, s, ts->width);
            d += dd;
            s += ds;
            f(ts, d, s, ts->width);
            d += dd;
            s += ds;
            f(ts, d, s, ts->width);
            d += dd;
            s += ds;
        } else {
B
bellard 已提交
251 252
            if (y_start >= 0) {
                /* flush to display */
253
                dpy_update(ts->ds, 0, y_start,
B
bellard 已提交
254
                           ts->width, y - y_start);
B
bellard 已提交
255 256
                y_start = -1;
            }
B
blueswir1 已提交
257 258 259
            d += dd * 4;
            s += ds * 4;
        }
B
bellard 已提交
260 261
    }
    if (y_start >= 0) {
B
blueswir1 已提交
262 263 264
        /* flush to display */
        dpy_update(ts->ds, 0, y_start,
                   ts->width, y - y_start);
B
bellard 已提交
265 266
    }
    /* reset modified pages */
267
    if (page_min <= page_max) {
B
bellard 已提交
268 269
        cpu_physical_memory_reset_dirty(page_min, page_max + TARGET_PAGE_SIZE,
                                        VGA_DIRTY_FLAG);
B
bellard 已提交
270
    }
271 272
}

B
blueswir1 已提交
273 274 275 276 277 278 279 280
static void tcx24_update_display(void *opaque)
{
    TCXState *ts = opaque;
    ram_addr_t page, page_min, page_max, cpage, page24;
    int y, y_start, dd, ds;
    uint8_t *d, *s;
    uint32_t *cptr, *s24;

281
    if (ds_get_bits_per_pixel(ts->ds) != 32)
B
blueswir1 已提交
282 283 284 285 286 287 288
            return;
    page = ts->vram_offset;
    page24 = ts->vram24_offset;
    cpage = ts->cplane_offset;
    y_start = -1;
    page_min = 0xffffffff;
    page_max = 0;
289
    d = ds_get_data(ts->ds);
B
blueswir1 已提交
290 291 292
    s = ts->vram;
    s24 = ts->vram24;
    cptr = ts->cplane;
293
    dd = ds_get_linesize(ts->ds);
B
blueswir1 已提交
294 295 296 297
    ds = 1024;

    for(y = 0; y < ts->height; y += 4, page += TARGET_PAGE_SIZE,
            page24 += TARGET_PAGE_SIZE, cpage += TARGET_PAGE_SIZE) {
B
blueswir1 已提交
298
        if (check_dirty(page, page24, cpage)) {
B
blueswir1 已提交
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
            if (y_start < 0)
                y_start = y;
            if (page < page_min)
                page_min = page;
            if (page > page_max)
                page_max = page;
            tcx24_draw_line32(ts, d, s, ts->width, cptr, s24);
            d += dd;
            s += ds;
            cptr += ds;
            s24 += ds;
            tcx24_draw_line32(ts, d, s, ts->width, cptr, s24);
            d += dd;
            s += ds;
            cptr += ds;
            s24 += ds;
            tcx24_draw_line32(ts, d, s, ts->width, cptr, s24);
            d += dd;
            s += ds;
            cptr += ds;
            s24 += ds;
            tcx24_draw_line32(ts, d, s, ts->width, cptr, s24);
            d += dd;
            s += ds;
            cptr += ds;
            s24 += ds;
        } else {
            if (y_start >= 0) {
                /* flush to display */
                dpy_update(ts->ds, 0, y_start,
                           ts->width, y - y_start);
                y_start = -1;
            }
            d += dd * 4;
            s += ds * 4;
            cptr += ds * 4;
            s24 += ds * 4;
        }
    }
    if (y_start >= 0) {
        /* flush to display */
        dpy_update(ts->ds, 0, y_start,
                   ts->width, y - y_start);
    }
    /* reset modified pages */
    if (page_min <= page_max) {
        reset_dirty(ts, page_min, page_max, page24, cpage);
    }
}

P
pbrook 已提交
349
static void tcx_invalidate_display(void *opaque)
350
{
B
bellard 已提交
351 352 353 354
    TCXState *s = opaque;
    int i;

    for (i = 0; i < MAXX*MAXY; i += TARGET_PAGE_SIZE) {
B
blueswir1 已提交
355
        cpu_physical_memory_set_dirty(s->vram_offset + i);
B
bellard 已提交
356
    }
357 358
}

B
blueswir1 已提交
359 360 361 362 363 364 365 366 367 368 369 370
static void tcx24_invalidate_display(void *opaque)
{
    TCXState *s = opaque;
    int i;

    tcx_invalidate_display(s);
    for (i = 0; i < MAXX*MAXY * 4; i += TARGET_PAGE_SIZE) {
        cpu_physical_memory_set_dirty(s->vram24_offset + i);
        cpu_physical_memory_set_dirty(s->cplane_offset + i);
    }
}

B
bellard 已提交
371
static void tcx_save(QEMUFile *f, void *opaque)
372 373
{
    TCXState *s = opaque;
374

B
blueswir1 已提交
375 376 377
    qemu_put_be16s(f, &s->height);
    qemu_put_be16s(f, &s->width);
    qemu_put_be16s(f, &s->depth);
B
bellard 已提交
378 379 380
    qemu_put_buffer(f, s->r, 256);
    qemu_put_buffer(f, s->g, 256);
    qemu_put_buffer(f, s->b, 256);
B
bellard 已提交
381 382
    qemu_put_8s(f, &s->dac_index);
    qemu_put_8s(f, &s->dac_state);
383 384
}

B
bellard 已提交
385
static int tcx_load(QEMUFile *f, void *opaque, int version_id)
386
{
B
bellard 已提交
387
    TCXState *s = opaque;
B
blueswir1 已提交
388 389 390
    uint32_t dummy;

    if (version_id != 3 && version_id != 4)
B
bellard 已提交
391 392
        return -EINVAL;

B
blueswir1 已提交
393
    if (version_id == 3) {
B
blueswir1 已提交
394 395 396
        qemu_get_be32s(f, &dummy);
        qemu_get_be32s(f, &dummy);
        qemu_get_be32s(f, &dummy);
B
blueswir1 已提交
397
    }
B
blueswir1 已提交
398 399 400
    qemu_get_be16s(f, &s->height);
    qemu_get_be16s(f, &s->width);
    qemu_get_be16s(f, &s->depth);
B
bellard 已提交
401 402 403
    qemu_get_buffer(f, s->r, 256);
    qemu_get_buffer(f, s->g, 256);
    qemu_get_buffer(f, s->b, 256);
B
bellard 已提交
404 405
    qemu_get_8s(f, &s->dac_index);
    qemu_get_8s(f, &s->dac_state);
B
bellard 已提交
406
    update_palette_entries(s, 0, 256);
407 408 409 410
    if (s->depth == 24)
        tcx24_invalidate_display(s);
    else
        tcx_invalidate_display(s);
B
blueswir1 已提交
411

B
bellard 已提交
412
    return 0;
413 414
}

B
bellard 已提交
415
static void tcx_reset(void *opaque)
416
{
B
bellard 已提交
417 418 419 420 421 422 423
    TCXState *s = opaque;

    /* Initialize palette */
    memset(s->r, 0, 256);
    memset(s->g, 0, 256);
    memset(s->b, 0, 256);
    s->r[255] = s->g[255] = s->b[255] = 255;
B
bellard 已提交
424
    update_palette_entries(s, 0, 256);
B
bellard 已提交
425
    memset(s->vram, 0, MAXX*MAXY);
B
blueswir1 已提交
426 427
    cpu_physical_memory_reset_dirty(s->vram_offset, s->vram_offset +
                                    MAXX * MAXY * (1 + 4 + 4), VGA_DIRTY_FLAG);
B
bellard 已提交
428 429 430 431 432 433 434 435 436 437 438 439 440
    s->dac_index = 0;
    s->dac_state = 0;
}

static uint32_t tcx_dac_readl(void *opaque, target_phys_addr_t addr)
{
    return 0;
}

static void tcx_dac_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
{
    TCXState *s = opaque;

B
blueswir1 已提交
441
    switch (addr) {
B
bellard 已提交
442
    case 0:
B
blueswir1 已提交
443 444 445
        s->dac_index = val >> 24;
        s->dac_state = 0;
        break;
B
blueswir1 已提交
446
    case 4:
B
blueswir1 已提交
447 448 449
        switch (s->dac_state) {
        case 0:
            s->r[s->dac_index] = val >> 24;
B
bellard 已提交
450
            update_palette_entries(s, s->dac_index, s->dac_index + 1);
B
blueswir1 已提交
451 452 453 454
            s->dac_state++;
            break;
        case 1:
            s->g[s->dac_index] = val >> 24;
B
bellard 已提交
455
            update_palette_entries(s, s->dac_index, s->dac_index + 1);
B
blueswir1 已提交
456 457 458 459
            s->dac_state++;
            break;
        case 2:
            s->b[s->dac_index] = val >> 24;
B
bellard 已提交
460
            update_palette_entries(s, s->dac_index, s->dac_index + 1);
B
blueswir1 已提交
461
            s->dac_index = (s->dac_index + 1) & 255; // Index autoincrement
B
blueswir1 已提交
462 463 464 465 466
        default:
            s->dac_state = 0;
            break;
        }
        break;
B
bellard 已提交
467
    default:
B
blueswir1 已提交
468
        break;
B
bellard 已提交
469 470
    }
    return;
471 472
}

B
bellard 已提交
473
static CPUReadMemoryFunc *tcx_dac_read[3] = {
474 475
    NULL,
    NULL,
B
bellard 已提交
476 477 478 479
    tcx_dac_readl,
};

static CPUWriteMemoryFunc *tcx_dac_write[3] = {
480 481
    NULL,
    NULL,
B
bellard 已提交
482 483 484
    tcx_dac_writel,
};

485 486 487 488 489 490 491 492 493 494 495
static uint32_t tcx_dummy_readl(void *opaque, target_phys_addr_t addr)
{
    return 0;
}

static void tcx_dummy_writel(void *opaque, target_phys_addr_t addr,
                             uint32_t val)
{
}

static CPUReadMemoryFunc *tcx_dummy_read[3] = {
496 497
    NULL,
    NULL,
498 499 500 501
    tcx_dummy_readl,
};

static CPUWriteMemoryFunc *tcx_dummy_write[3] = {
502 503
    NULL,
    NULL,
504 505 506
    tcx_dummy_writel,
};

507
void tcx_init(DisplayState *ds, target_phys_addr_t addr, uint8_t *vram_base,
B
blueswir1 已提交
508 509
              unsigned long vram_offset, int vram_size, int width, int height,
              int depth)
510 511
{
    TCXState *s;
512
    int io_memory, dummy_memory;
B
blueswir1 已提交
513
    int size;
514 515 516

    s = qemu_mallocz(sizeof(TCXState));
    if (!s)
P
pbrook 已提交
517
        return;
518
    s->ds = ds;
B
bellard 已提交
519
    s->addr = addr;
B
bellard 已提交
520
    s->vram_offset = vram_offset;
B
bellard 已提交
521 522
    s->width = width;
    s->height = height;
B
blueswir1 已提交
523 524 525 526 527
    s->depth = depth;

    // 8-bit plane
    s->vram = vram_base;
    size = vram_size;
528
    cpu_register_physical_memory(addr + 0x00800000ULL, size, vram_offset);
B
blueswir1 已提交
529 530
    vram_offset += size;
    vram_base += size;
B
bellard 已提交
531

B
bellard 已提交
532
    io_memory = cpu_register_io_memory(0, tcx_dac_read, tcx_dac_write, s);
B
blueswir1 已提交
533 534
    cpu_register_physical_memory(addr + 0x00200000ULL, TCX_DAC_NREGS,
                                 io_memory);
B
blueswir1 已提交
535

536 537
    dummy_memory = cpu_register_io_memory(0, tcx_dummy_read, tcx_dummy_write,
                                          s);
538
    cpu_register_physical_memory(addr + 0x00700000ULL, TCX_TEC_NREGS,
539
                                 dummy_memory);
B
blueswir1 已提交
540 541 542 543 544
    if (depth == 24) {
        // 24-bit plane
        size = vram_size * 4;
        s->vram24 = (uint32_t *)vram_base;
        s->vram24_offset = vram_offset;
545
        cpu_register_physical_memory(addr + 0x02000000ULL, size, vram_offset);
B
blueswir1 已提交
546 547 548 549 550 551 552
        vram_offset += size;
        vram_base += size;

        // Control plane
        size = vram_size * 4;
        s->cplane = (uint32_t *)vram_base;
        s->cplane_offset = vram_offset;
553
        cpu_register_physical_memory(addr + 0x0a000000ULL, size, vram_offset);
554 555 556
        s->console = graphic_console_init(s->ds, tcx24_update_display,
                                          tcx24_invalidate_display,
                                          tcx24_screen_dump, NULL, s);
B
blueswir1 已提交
557
    } else {
558
        cpu_register_physical_memory(addr + 0x00300000ULL, TCX_THC_NREGS_8,
559
                                     dummy_memory);
560 561 562
        s->console = graphic_console_init(s->ds, tcx_update_display,
                                          tcx_invalidate_display,
                                          tcx_screen_dump, NULL, s);
B
blueswir1 已提交
563
    }
564
    // NetBSD writes here even with 8-bit display
565
    cpu_register_physical_memory(addr + 0x00301000ULL, TCX_THC_NREGS_24,
566
                                 dummy_memory);
B
bellard 已提交
567

B
blueswir1 已提交
568
    register_savevm("tcx", addr, 4, tcx_save, tcx_load, s);
B
bellard 已提交
569 570
    qemu_register_reset(tcx_reset, s);
    tcx_reset(s);
571
    qemu_console_resize(s->console, width, height);
572 573
}

P
pbrook 已提交
574
static void tcx_screen_dump(void *opaque, const char *filename)
B
bellard 已提交
575
{
B
bellard 已提交
576
    TCXState *s = opaque;
B
bellard 已提交
577
    FILE *f;
B
bellard 已提交
578
    uint8_t *d, *d1, v;
B
bellard 已提交
579 580 581 582
    int y, x;

    f = fopen(filename, "wb");
    if (!f)
B
bellard 已提交
583
        return;
B
bellard 已提交
584 585 586
    fprintf(f, "P6\n%d %d\n%d\n", s->width, s->height, 255);
    d1 = s->vram;
    for(y = 0; y < s->height; y++) {
B
bellard 已提交
587
        d = d1;
B
bellard 已提交
588
        for(x = 0; x < s->width; x++) {
B
bellard 已提交
589
            v = *d;
B
bellard 已提交
590 591 592
            fputc(s->r[v], f);
            fputc(s->g[v], f);
            fputc(s->b[v], f);
B
bellard 已提交
593 594
            d++;
        }
B
bellard 已提交
595
        d1 += MAXX;
B
bellard 已提交
596 597 598 599 600
    }
    fclose(f);
    return;
}

B
blueswir1 已提交
601 602 603 604 605 606 607
static void tcx24_screen_dump(void *opaque, const char *filename)
{
    TCXState *s = opaque;
    FILE *f;
    uint8_t *d, *d1, v;
    uint32_t *s24, *cptr, dval;
    int y, x;
B
bellard 已提交
608

B
blueswir1 已提交
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
    f = fopen(filename, "wb");
    if (!f)
        return;
    fprintf(f, "P6\n%d %d\n%d\n", s->width, s->height, 255);
    d1 = s->vram;
    s24 = s->vram24;
    cptr = s->cplane;
    for(y = 0; y < s->height; y++) {
        d = d1;
        for(x = 0; x < s->width; x++, d++, s24++) {
            if ((*cptr++ & 0xff000000) == 0x03000000) { // 24-bit direct
                dval = *s24 & 0x00ffffff;
                fputc((dval >> 16) & 0xff, f);
                fputc((dval >> 8) & 0xff, f);
                fputc(dval & 0xff, f);
            } else {
                v = *d;
                fputc(s->r[v], f);
                fputc(s->g[v], f);
                fputc(s->b[v], f);
            }
        }
        d1 += MAXX;
    }
    fclose(f);
    return;
}