2004-10-01 02:13:50 +04:00
|
|
|
/*
|
2005-03-13 12:43:36 +03:00
|
|
|
* QEMU TCX Frame buffer
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2005-03-13 12:43:36 +03:00
|
|
|
* Copyright (c) 2003-2005 Fabrice Bellard
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2004-10-01 02:13:50 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
2007-11-17 20:14:51 +03:00
|
|
|
#include "hw.h"
|
|
|
|
#include "sun4m.h"
|
|
|
|
#include "console.h"
|
2007-06-10 20:06:20 +04:00
|
|
|
#include "pixel_ops.h"
|
2004-10-01 02:13:50 +04:00
|
|
|
|
|
|
|
#define MAXX 1024
|
|
|
|
#define MAXY 768
|
2005-03-13 12:43:36 +03:00
|
|
|
#define TCX_DAC_NREGS 16
|
2007-05-06 21:39:55 +04:00
|
|
|
#define TCX_THC_NREGS_8 0x081c
|
|
|
|
#define TCX_THC_NREGS_24 0x1000
|
|
|
|
#define TCX_TEC_NREGS 0x1000
|
2004-10-01 02:13:50 +04:00
|
|
|
|
|
|
|
typedef struct TCXState {
|
2007-05-19 16:58:30 +04:00
|
|
|
target_phys_addr_t addr;
|
2004-10-01 02:13:50 +04:00
|
|
|
DisplayState *ds;
|
2004-10-05 01:23:09 +04:00
|
|
|
uint8_t *vram;
|
2007-04-21 23:45:49 +04:00
|
|
|
uint32_t *vram24, *cplane;
|
|
|
|
ram_addr_t vram_offset, vram24_offset, cplane_offset;
|
|
|
|
uint16_t width, height, depth;
|
2004-12-20 02:18:01 +03:00
|
|
|
uint8_t r[256], g[256], b[256];
|
2006-09-09 15:31:34 +04:00
|
|
|
uint32_t palette[256];
|
2005-03-13 12:43:36 +03:00
|
|
|
uint8_t dac_index, dac_state;
|
2004-10-01 02:13:50 +04:00
|
|
|
} TCXState;
|
|
|
|
|
2006-04-09 05:06:34 +04:00
|
|
|
static void tcx_screen_dump(void *opaque, const char *filename);
|
2007-04-21 23:45:49 +04:00
|
|
|
static void tcx24_screen_dump(void *opaque, const char *filename);
|
2007-06-01 20:58:29 +04:00
|
|
|
static void tcx_invalidate_display(void *opaque);
|
|
|
|
static void tcx24_invalidate_display(void *opaque);
|
2006-04-09 05:06:34 +04:00
|
|
|
|
2006-09-09 15:31:34 +04:00
|
|
|
static void update_palette_entries(TCXState *s, int start, int end)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = start; i < end; i++) {
|
2008-11-24 22:29:13 +03:00
|
|
|
switch(ds_get_bits_per_pixel(s->ds)) {
|
2006-09-09 15:31:34 +04:00
|
|
|
default:
|
|
|
|
case 8:
|
|
|
|
s->palette[i] = rgb_to_pixel8(s->r[i], s->g[i], s->b[i]);
|
|
|
|
break;
|
|
|
|
case 15:
|
2009-01-16 01:07:16 +03:00
|
|
|
s->palette[i] = rgb_to_pixel15(s->r[i], s->g[i], s->b[i]);
|
2006-09-09 15:31:34 +04:00
|
|
|
break;
|
|
|
|
case 16:
|
2009-01-16 01:07:16 +03:00
|
|
|
s->palette[i] = rgb_to_pixel16(s->r[i], s->g[i], s->b[i]);
|
2006-09-09 15:31:34 +04:00
|
|
|
break;
|
|
|
|
case 32:
|
2009-03-13 18:02:13 +03:00
|
|
|
if (is_surface_bgr(s->ds->surface))
|
|
|
|
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]);
|
2006-09-09 15:31:34 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-06-01 20:58:29 +04:00
|
|
|
if (s->depth == 24)
|
|
|
|
tcx24_invalidate_display(s);
|
|
|
|
else
|
|
|
|
tcx_invalidate_display(s);
|
2006-09-09 15:31:34 +04:00
|
|
|
}
|
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
static void tcx_draw_line32(TCXState *s1, uint8_t *d,
|
2007-10-06 15:28:21 +04:00
|
|
|
const uint8_t *s, int width)
|
2004-10-01 02:13:50 +04:00
|
|
|
{
|
2004-12-20 02:18:01 +03:00
|
|
|
int x;
|
|
|
|
uint8_t val;
|
2006-12-21 20:24:45 +03:00
|
|
|
uint32_t *p = (uint32_t *)d;
|
2004-12-20 02:18:01 +03:00
|
|
|
|
|
|
|
for(x = 0; x < width; x++) {
|
2007-10-06 15:28:21 +04:00
|
|
|
val = *s++;
|
2006-12-21 20:24:45 +03:00
|
|
|
*p++ = s1->palette[val];
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
2004-10-01 02:13:50 +04:00
|
|
|
}
|
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
static void tcx_draw_line16(TCXState *s1, uint8_t *d,
|
2007-10-06 15:28:21 +04:00
|
|
|
const uint8_t *s, int width)
|
2004-12-20 02:18:01 +03:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
uint8_t val;
|
2006-12-21 20:24:45 +03:00
|
|
|
uint16_t *p = (uint16_t *)d;
|
2004-10-05 01:23:09 +04:00
|
|
|
|
2004-12-20 02:18:01 +03:00
|
|
|
for(x = 0; x < width; x++) {
|
2007-10-06 15:28:21 +04:00
|
|
|
val = *s++;
|
2006-12-21 20:24:45 +03:00
|
|
|
*p++ = s1->palette[val];
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
static void tcx_draw_line8(TCXState *s1, uint8_t *d,
|
2007-10-06 15:28:21 +04:00
|
|
|
const uint8_t *s, int width)
|
2004-10-01 02:13:50 +04:00
|
|
|
{
|
2004-12-20 02:18:01 +03:00
|
|
|
int x;
|
|
|
|
uint8_t val;
|
|
|
|
|
|
|
|
for(x = 0; x < width; x++) {
|
2007-10-06 15:28:21 +04:00
|
|
|
val = *s++;
|
2006-09-09 15:31:34 +04:00
|
|
|
*d++ = s1->palette[val];
|
2004-10-01 02:13:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-24 15:26:38 +04:00
|
|
|
/*
|
|
|
|
XXX Could be much more optimal:
|
|
|
|
* detect if line/page/whole screen is in 24 bit mode
|
|
|
|
* if destination is also BGR, use memcpy
|
|
|
|
*/
|
2007-04-21 23:45:49 +04:00
|
|
|
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)
|
|
|
|
{
|
2009-03-13 18:02:13 +03:00
|
|
|
int x, bgr, r, g, b;
|
2008-07-24 15:26:38 +04:00
|
|
|
uint8_t val, *p8;
|
2007-04-21 23:45:49 +04:00
|
|
|
uint32_t *p = (uint32_t *)d;
|
|
|
|
uint32_t dval;
|
|
|
|
|
2009-03-13 18:02:13 +03:00
|
|
|
bgr = is_surface_bgr(s1->ds->surface);
|
2007-04-21 23:45:49 +04:00
|
|
|
for(x = 0; x < width; x++, s++, s24++) {
|
2008-07-24 15:26:38 +04:00
|
|
|
if ((be32_to_cpu(*cplane++) & 0xff000000) == 0x03000000) {
|
|
|
|
// 24-bit direct, BGR order
|
|
|
|
p8 = (uint8_t *)s24;
|
|
|
|
p8++;
|
|
|
|
b = *p8++;
|
|
|
|
g = *p8++;
|
|
|
|
r = *p8++;
|
2009-03-13 18:02:13 +03:00
|
|
|
if (bgr)
|
|
|
|
dval = rgb_to_pixel32bgr(r, g, b);
|
|
|
|
else
|
|
|
|
dval = rgb_to_pixel32(r, g, b);
|
2007-04-21 23:45:49 +04:00
|
|
|
} else {
|
|
|
|
val = *s;
|
|
|
|
dval = s1->palette[val];
|
|
|
|
}
|
|
|
|
*p++ = dval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-10 14:12:00 +04:00
|
|
|
static inline int check_dirty(ram_addr_t page, ram_addr_t page24,
|
2007-04-21 23:45:49 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2004-12-20 02:18:01 +03:00
|
|
|
/* Fixed line length 1024 allows us to do nice tricks not possible on
|
|
|
|
VGA... */
|
2006-04-09 05:06:34 +04:00
|
|
|
static void tcx_update_display(void *opaque)
|
2004-10-01 02:13:50 +04:00
|
|
|
{
|
2004-12-20 02:18:01 +03:00
|
|
|
TCXState *ts = opaque;
|
2006-08-03 02:19:33 +04:00
|
|
|
ram_addr_t page, page_min, page_max;
|
|
|
|
int y, y_start, dd, ds;
|
2004-12-20 02:18:01 +03:00
|
|
|
uint8_t *d, *s;
|
2007-06-25 23:56:13 +04:00
|
|
|
void (*f)(TCXState *s1, uint8_t *dst, const uint8_t *src, int width);
|
2004-12-20 02:18:01 +03:00
|
|
|
|
2008-11-24 22:29:13 +03:00
|
|
|
if (ds_get_bits_per_pixel(ts->ds) == 0)
|
2007-10-06 15:28:21 +04:00
|
|
|
return;
|
2005-03-13 12:43:36 +03:00
|
|
|
page = ts->vram_offset;
|
2004-12-20 02:18:01 +03:00
|
|
|
y_start = -1;
|
2009-04-27 22:10:37 +04:00
|
|
|
page_min = -1;
|
2006-08-03 02:19:33 +04:00
|
|
|
page_max = 0;
|
2008-11-24 22:29:13 +03:00
|
|
|
d = ds_get_data(ts->ds);
|
2005-03-13 12:43:36 +03:00
|
|
|
s = ts->vram;
|
2008-11-24 22:29:13 +03:00
|
|
|
dd = ds_get_linesize(ts->ds);
|
2004-12-20 02:18:01 +03:00
|
|
|
ds = 1024;
|
|
|
|
|
2008-11-24 22:29:13 +03:00
|
|
|
switch (ds_get_bits_per_pixel(ts->ds)) {
|
2004-12-20 02:18:01 +03:00
|
|
|
case 32:
|
2007-10-06 15:28:21 +04:00
|
|
|
f = tcx_draw_line32;
|
|
|
|
break;
|
2006-09-09 15:31:34 +04:00
|
|
|
case 15:
|
|
|
|
case 16:
|
2007-10-06 15:28:21 +04:00
|
|
|
f = tcx_draw_line16;
|
|
|
|
break;
|
2004-12-20 02:18:01 +03:00
|
|
|
default:
|
|
|
|
case 8:
|
2007-10-06 15:28:21 +04:00
|
|
|
f = tcx_draw_line8;
|
|
|
|
break;
|
2004-12-20 02:18:01 +03:00
|
|
|
case 0:
|
2007-10-06 15:28:21 +04:00
|
|
|
return;
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2005-03-13 12:43:36 +03:00
|
|
|
for(y = 0; y < ts->height; y += 4, page += TARGET_PAGE_SIZE) {
|
2007-10-06 15:28:21 +04:00
|
|
|
if (cpu_physical_memory_get_dirty(page, VGA_DIRTY_FLAG)) {
|
|
|
|
if (y_start < 0)
|
2004-12-20 02:18:01 +03:00
|
|
|
y_start = y;
|
|
|
|
if (page < page_min)
|
|
|
|
page_min = page;
|
|
|
|
if (page > page_max)
|
|
|
|
page_max = page;
|
2007-10-06 15:28:21 +04:00
|
|
|
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 {
|
2004-12-20 02:18:01 +03:00
|
|
|
if (y_start >= 0) {
|
|
|
|
/* flush to display */
|
2007-09-17 01:08:06 +04:00
|
|
|
dpy_update(ts->ds, 0, y_start,
|
2005-03-13 12:43:36 +03:00
|
|
|
ts->width, y - y_start);
|
2004-12-20 02:18:01 +03:00
|
|
|
y_start = -1;
|
|
|
|
}
|
2007-10-06 15:28:21 +04:00
|
|
|
d += dd * 4;
|
|
|
|
s += ds * 4;
|
|
|
|
}
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
|
|
|
if (y_start >= 0) {
|
2007-10-06 15:28:21 +04:00
|
|
|
/* flush to display */
|
|
|
|
dpy_update(ts->ds, 0, y_start,
|
|
|
|
ts->width, y - y_start);
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
|
|
|
/* reset modified pages */
|
2009-04-27 22:10:37 +04:00
|
|
|
if (page_max >= page_min) {
|
2005-02-11 01:00:27 +03:00
|
|
|
cpu_physical_memory_reset_dirty(page_min, page_max + TARGET_PAGE_SIZE,
|
|
|
|
VGA_DIRTY_FLAG);
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
2004-10-01 02:13:50 +04:00
|
|
|
}
|
|
|
|
|
2007-04-21 23:45:49 +04:00
|
|
|
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;
|
|
|
|
|
2008-11-24 22:29:13 +03:00
|
|
|
if (ds_get_bits_per_pixel(ts->ds) != 32)
|
2007-04-21 23:45:49 +04:00
|
|
|
return;
|
|
|
|
page = ts->vram_offset;
|
|
|
|
page24 = ts->vram24_offset;
|
|
|
|
cpage = ts->cplane_offset;
|
|
|
|
y_start = -1;
|
2009-04-27 22:10:37 +04:00
|
|
|
page_min = -1;
|
2007-04-21 23:45:49 +04:00
|
|
|
page_max = 0;
|
2008-11-24 22:29:13 +03:00
|
|
|
d = ds_get_data(ts->ds);
|
2007-04-21 23:45:49 +04:00
|
|
|
s = ts->vram;
|
|
|
|
s24 = ts->vram24;
|
|
|
|
cptr = ts->cplane;
|
2008-11-24 22:29:13 +03:00
|
|
|
dd = ds_get_linesize(ts->ds);
|
2007-04-21 23:45:49 +04:00
|
|
|
ds = 1024;
|
|
|
|
|
|
|
|
for(y = 0; y < ts->height; y += 4, page += TARGET_PAGE_SIZE,
|
|
|
|
page24 += TARGET_PAGE_SIZE, cpage += TARGET_PAGE_SIZE) {
|
2008-05-10 14:12:00 +04:00
|
|
|
if (check_dirty(page, page24, cpage)) {
|
2007-04-21 23:45:49 +04:00
|
|
|
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 */
|
2009-04-27 22:10:37 +04:00
|
|
|
if (page_max >= page_min) {
|
2007-04-21 23:45:49 +04:00
|
|
|
reset_dirty(ts, page_min, page_max, page24, cpage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-09 05:06:34 +04:00
|
|
|
static void tcx_invalidate_display(void *opaque)
|
2004-10-01 02:13:50 +04:00
|
|
|
{
|
2004-12-20 02:18:01 +03:00
|
|
|
TCXState *s = opaque;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAXX*MAXY; i += TARGET_PAGE_SIZE) {
|
2007-10-06 15:28:21 +04:00
|
|
|
cpu_physical_memory_set_dirty(s->vram_offset + i);
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
2004-10-01 02:13:50 +04:00
|
|
|
}
|
|
|
|
|
2007-04-21 23:45:49 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-20 02:18:01 +03:00
|
|
|
static void tcx_save(QEMUFile *f, void *opaque)
|
2004-10-01 02:13:50 +04:00
|
|
|
{
|
|
|
|
TCXState *s = opaque;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2008-10-02 23:14:17 +04:00
|
|
|
qemu_put_be16s(f, &s->height);
|
|
|
|
qemu_put_be16s(f, &s->width);
|
|
|
|
qemu_put_be16s(f, &s->depth);
|
2004-12-20 02:18:01 +03:00
|
|
|
qemu_put_buffer(f, s->r, 256);
|
|
|
|
qemu_put_buffer(f, s->g, 256);
|
|
|
|
qemu_put_buffer(f, s->b, 256);
|
2005-03-13 12:43:36 +03:00
|
|
|
qemu_put_8s(f, &s->dac_index);
|
|
|
|
qemu_put_8s(f, &s->dac_state);
|
2004-10-01 02:13:50 +04:00
|
|
|
}
|
|
|
|
|
2004-12-20 02:18:01 +03:00
|
|
|
static int tcx_load(QEMUFile *f, void *opaque, int version_id)
|
2004-10-01 02:13:50 +04:00
|
|
|
{
|
2004-12-20 02:18:01 +03:00
|
|
|
TCXState *s = opaque;
|
2007-07-03 13:55:03 +04:00
|
|
|
uint32_t dummy;
|
|
|
|
|
|
|
|
if (version_id != 3 && version_id != 4)
|
2004-12-20 02:18:01 +03:00
|
|
|
return -EINVAL;
|
|
|
|
|
2007-07-03 13:55:03 +04:00
|
|
|
if (version_id == 3) {
|
2008-10-02 23:14:17 +04:00
|
|
|
qemu_get_be32s(f, &dummy);
|
|
|
|
qemu_get_be32s(f, &dummy);
|
|
|
|
qemu_get_be32s(f, &dummy);
|
2007-07-03 13:55:03 +04:00
|
|
|
}
|
2008-10-02 23:14:17 +04:00
|
|
|
qemu_get_be16s(f, &s->height);
|
|
|
|
qemu_get_be16s(f, &s->width);
|
|
|
|
qemu_get_be16s(f, &s->depth);
|
2004-12-20 02:18:01 +03:00
|
|
|
qemu_get_buffer(f, s->r, 256);
|
|
|
|
qemu_get_buffer(f, s->g, 256);
|
|
|
|
qemu_get_buffer(f, s->b, 256);
|
2005-03-13 12:43:36 +03:00
|
|
|
qemu_get_8s(f, &s->dac_index);
|
|
|
|
qemu_get_8s(f, &s->dac_state);
|
2006-09-09 15:31:34 +04:00
|
|
|
update_palette_entries(s, 0, 256);
|
2007-06-01 20:58:29 +04:00
|
|
|
if (s->depth == 24)
|
|
|
|
tcx24_invalidate_display(s);
|
|
|
|
else
|
|
|
|
tcx_invalidate_display(s);
|
2007-04-13 23:24:07 +04:00
|
|
|
|
2004-12-20 02:18:01 +03:00
|
|
|
return 0;
|
2004-10-01 02:13:50 +04:00
|
|
|
}
|
|
|
|
|
2004-12-20 02:18:01 +03:00
|
|
|
static void tcx_reset(void *opaque)
|
2004-10-01 02:13:50 +04:00
|
|
|
{
|
2004-12-20 02:18:01 +03:00
|
|
|
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;
|
2006-09-09 15:31:34 +04:00
|
|
|
update_palette_entries(s, 0, 256);
|
2004-12-20 02:18:01 +03:00
|
|
|
memset(s->vram, 0, MAXX*MAXY);
|
2007-04-21 23:45:49 +04:00
|
|
|
cpu_physical_memory_reset_dirty(s->vram_offset, s->vram_offset +
|
|
|
|
MAXX * MAXY * (1 + 4 + 4), VGA_DIRTY_FLAG);
|
2005-03-13 12:43:36 +03:00
|
|
|
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;
|
|
|
|
|
2008-12-02 20:47:02 +03:00
|
|
|
switch (addr) {
|
2005-03-13 12:43:36 +03:00
|
|
|
case 0:
|
2007-10-06 15:28:21 +04:00
|
|
|
s->dac_index = val >> 24;
|
|
|
|
s->dac_state = 0;
|
|
|
|
break;
|
2008-12-02 20:47:02 +03:00
|
|
|
case 4:
|
2007-10-06 15:28:21 +04:00
|
|
|
switch (s->dac_state) {
|
|
|
|
case 0:
|
|
|
|
s->r[s->dac_index] = val >> 24;
|
2006-09-09 15:31:34 +04:00
|
|
|
update_palette_entries(s, s->dac_index, s->dac_index + 1);
|
2007-10-06 15:28:21 +04:00
|
|
|
s->dac_state++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
s->g[s->dac_index] = val >> 24;
|
2006-09-09 15:31:34 +04:00
|
|
|
update_palette_entries(s, s->dac_index, s->dac_index + 1);
|
2007-10-06 15:28:21 +04:00
|
|
|
s->dac_state++;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
s->b[s->dac_index] = val >> 24;
|
2006-09-09 15:31:34 +04:00
|
|
|
update_palette_entries(s, s->dac_index, s->dac_index + 1);
|
2007-04-17 23:42:21 +04:00
|
|
|
s->dac_index = (s->dac_index + 1) & 255; // Index autoincrement
|
2007-10-06 15:28:21 +04:00
|
|
|
default:
|
|
|
|
s->dac_state = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2005-03-13 12:43:36 +03:00
|
|
|
default:
|
2007-10-06 15:28:21 +04:00
|
|
|
break;
|
2005-03-13 12:43:36 +03:00
|
|
|
}
|
|
|
|
return;
|
2004-10-01 02:13:50 +04:00
|
|
|
}
|
|
|
|
|
2005-03-13 12:43:36 +03:00
|
|
|
static CPUReadMemoryFunc *tcx_dac_read[3] = {
|
2008-01-01 20:06:38 +03:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2005-03-13 12:43:36 +03:00
|
|
|
tcx_dac_readl,
|
|
|
|
};
|
|
|
|
|
|
|
|
static CPUWriteMemoryFunc *tcx_dac_write[3] = {
|
2008-01-01 20:06:38 +03:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2005-03-13 12:43:36 +03:00
|
|
|
tcx_dac_writel,
|
|
|
|
};
|
|
|
|
|
2007-05-06 21:39:55 +04:00
|
|
|
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] = {
|
2008-01-01 20:06:38 +03:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2007-05-06 21:39:55 +04:00
|
|
|
tcx_dummy_readl,
|
|
|
|
};
|
|
|
|
|
|
|
|
static CPUWriteMemoryFunc *tcx_dummy_write[3] = {
|
2008-01-01 20:06:38 +03:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2007-05-06 21:39:55 +04:00
|
|
|
tcx_dummy_writel,
|
|
|
|
};
|
|
|
|
|
2009-04-10 02:21:07 +04:00
|
|
|
void tcx_init(target_phys_addr_t addr, int vram_size, int width, int height,
|
2007-04-21 23:45:49 +04:00
|
|
|
int depth)
|
2004-10-01 02:13:50 +04:00
|
|
|
{
|
|
|
|
TCXState *s;
|
2007-05-06 21:39:55 +04:00
|
|
|
int io_memory, dummy_memory;
|
2009-04-10 02:21:07 +04:00
|
|
|
ram_addr_t vram_offset;
|
2007-04-21 23:45:49 +04:00
|
|
|
int size;
|
2009-04-10 02:21:07 +04:00
|
|
|
uint8_t *vram_base;
|
|
|
|
|
2009-04-11 20:55:44 +04:00
|
|
|
vram_offset = qemu_ram_alloc(vram_size * (1 + 4 + 4));
|
2009-04-10 02:21:07 +04:00
|
|
|
vram_base = qemu_get_ram_ptr(vram_offset);
|
2004-10-01 02:13:50 +04:00
|
|
|
|
|
|
|
s = qemu_mallocz(sizeof(TCXState));
|
2004-10-05 01:23:09 +04:00
|
|
|
s->addr = addr;
|
2004-12-20 02:18:01 +03:00
|
|
|
s->vram_offset = vram_offset;
|
2005-03-13 12:43:36 +03:00
|
|
|
s->width = width;
|
|
|
|
s->height = height;
|
2007-04-21 23:45:49 +04:00
|
|
|
s->depth = depth;
|
|
|
|
|
|
|
|
// 8-bit plane
|
|
|
|
s->vram = vram_base;
|
|
|
|
size = vram_size;
|
2007-05-19 16:58:30 +04:00
|
|
|
cpu_register_physical_memory(addr + 0x00800000ULL, size, vram_offset);
|
2007-04-21 23:45:49 +04:00
|
|
|
vram_offset += size;
|
|
|
|
vram_base += size;
|
2004-12-20 02:18:01 +03:00
|
|
|
|
2005-03-13 12:43:36 +03:00
|
|
|
io_memory = cpu_register_io_memory(0, tcx_dac_read, tcx_dac_write, s);
|
2008-05-12 20:13:33 +04:00
|
|
|
cpu_register_physical_memory(addr + 0x00200000ULL, TCX_DAC_NREGS,
|
|
|
|
io_memory);
|
2007-04-21 23:45:49 +04:00
|
|
|
|
2007-05-06 21:39:55 +04:00
|
|
|
dummy_memory = cpu_register_io_memory(0, tcx_dummy_read, tcx_dummy_write,
|
|
|
|
s);
|
2007-05-19 16:58:30 +04:00
|
|
|
cpu_register_physical_memory(addr + 0x00700000ULL, TCX_TEC_NREGS,
|
2007-05-06 21:39:55 +04:00
|
|
|
dummy_memory);
|
2007-04-21 23:45:49 +04:00
|
|
|
if (depth == 24) {
|
|
|
|
// 24-bit plane
|
|
|
|
size = vram_size * 4;
|
|
|
|
s->vram24 = (uint32_t *)vram_base;
|
|
|
|
s->vram24_offset = vram_offset;
|
2007-05-19 16:58:30 +04:00
|
|
|
cpu_register_physical_memory(addr + 0x02000000ULL, size, vram_offset);
|
2007-04-21 23:45:49 +04:00
|
|
|
vram_offset += size;
|
|
|
|
vram_base += size;
|
|
|
|
|
|
|
|
// Control plane
|
|
|
|
size = vram_size * 4;
|
|
|
|
s->cplane = (uint32_t *)vram_base;
|
|
|
|
s->cplane_offset = vram_offset;
|
2007-05-19 16:58:30 +04:00
|
|
|
cpu_register_physical_memory(addr + 0x0a000000ULL, size, vram_offset);
|
2009-01-16 22:04:14 +03:00
|
|
|
s->ds = graphic_console_init(tcx24_update_display,
|
|
|
|
tcx24_invalidate_display,
|
|
|
|
tcx24_screen_dump, NULL, s);
|
2007-04-21 23:45:49 +04:00
|
|
|
} else {
|
2007-05-19 16:58:30 +04:00
|
|
|
cpu_register_physical_memory(addr + 0x00300000ULL, TCX_THC_NREGS_8,
|
2007-05-06 21:39:55 +04:00
|
|
|
dummy_memory);
|
2009-01-16 22:04:14 +03:00
|
|
|
s->ds = graphic_console_init(tcx_update_display,
|
|
|
|
tcx_invalidate_display,
|
|
|
|
tcx_screen_dump, NULL, s);
|
2007-04-21 23:45:49 +04:00
|
|
|
}
|
2007-05-17 23:34:41 +04:00
|
|
|
// NetBSD writes here even with 8-bit display
|
2007-05-19 16:58:30 +04:00
|
|
|
cpu_register_physical_memory(addr + 0x00301000ULL, TCX_THC_NREGS_24,
|
2007-05-17 23:34:41 +04:00
|
|
|
dummy_memory);
|
2004-12-20 02:18:01 +03:00
|
|
|
|
2007-07-03 13:55:03 +04:00
|
|
|
register_savevm("tcx", addr, 4, tcx_save, tcx_load, s);
|
2009-05-02 02:29:37 +04:00
|
|
|
qemu_register_reset(tcx_reset, 0, s);
|
2004-12-20 02:18:01 +03:00
|
|
|
tcx_reset(s);
|
2009-01-16 22:04:14 +03:00
|
|
|
qemu_console_resize(s->ds, width, height);
|
2004-10-01 02:13:50 +04:00
|
|
|
}
|
|
|
|
|
2006-04-09 05:06:34 +04:00
|
|
|
static void tcx_screen_dump(void *opaque, const char *filename)
|
2004-10-05 01:23:09 +04:00
|
|
|
{
|
2004-12-20 02:18:01 +03:00
|
|
|
TCXState *s = opaque;
|
2004-10-05 01:23:09 +04:00
|
|
|
FILE *f;
|
2004-12-20 02:18:01 +03:00
|
|
|
uint8_t *d, *d1, v;
|
2004-10-05 01:23:09 +04:00
|
|
|
int y, x;
|
|
|
|
|
|
|
|
f = fopen(filename, "wb");
|
|
|
|
if (!f)
|
2004-12-20 02:18:01 +03:00
|
|
|
return;
|
2005-03-13 12:43:36 +03:00
|
|
|
fprintf(f, "P6\n%d %d\n%d\n", s->width, s->height, 255);
|
|
|
|
d1 = s->vram;
|
|
|
|
for(y = 0; y < s->height; y++) {
|
2004-10-05 01:23:09 +04:00
|
|
|
d = d1;
|
2005-03-13 12:43:36 +03:00
|
|
|
for(x = 0; x < s->width; x++) {
|
2004-10-05 01:23:09 +04:00
|
|
|
v = *d;
|
2004-12-20 02:18:01 +03:00
|
|
|
fputc(s->r[v], f);
|
|
|
|
fputc(s->g[v], f);
|
|
|
|
fputc(s->b[v], f);
|
2004-10-05 01:23:09 +04:00
|
|
|
d++;
|
|
|
|
}
|
2004-12-20 02:18:01 +03:00
|
|
|
d1 += MAXX;
|
2004-10-05 01:23:09 +04:00
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-04-21 23:45:49 +04:00
|
|
|
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;
|
2004-10-05 01:23:09 +04:00
|
|
|
|
2007-04-21 23:45:49 +04:00
|
|
|
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;
|
|
|
|
}
|