diff options
author | Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 2021-10-07 23:12:49 +0100 |
---|---|---|
committer | Laurent Vivier <laurent@vivier.eu> | 2021-10-08 13:31:03 +0200 |
commit | df8abbbadf743bef6be5543b26f51231285b8923 (patch) | |
tree | 465d528aa19546cdbca56ebd877c83d58605b881 /hw/display | |
parent | 4317c518618adcd5d41637c849be17e94cecf003 (diff) |
macfb: add common monitor modes supported by the MacOS toolbox ROM
The monitor modes table is found by experimenting with the Monitors Control
Panel in MacOS and analysing the reads/writes. From this it can be found that
the mode is controlled by writes to the DAFB_MODE_CTRL1 and DAFB_MODE_CTRL2
registers.
Implement the first block of DAFB registers as a register array including the
existing sense register, the newly discovered control registers above, and also
the DAFB_MODE_VADDR1 and DAFB_MODE_VADDR2 registers which are used by NetBSD to
determine the current video mode.
These experiments also show that the offset of the start of video RAM and the
stride can change depending upon the monitor mode, so update macfb_draw_graphic()
and both the BI_MAC_VADDR and BI_MAC_VROW bootinfo for the q800 machine
accordingly.
Finally update macfb_common_realize() so that only the resolution and depth
supported by the display type can be specified on the command line, and add an
error hint showing the list of supported resolutions and depths if the user tries
to specify an invalid display mode.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20211007221253.29024-10-mark.cave-ayland@ilande.co.uk>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Diffstat (limited to 'hw/display')
-rw-r--r-- | hw/display/macfb.c | 149 | ||||
-rw-r--r-- | hw/display/trace-events | 1 |
2 files changed, 134 insertions, 16 deletions
diff --git a/hw/display/macfb.c b/hw/display/macfb.c index f98bcdec2d..2759fb5e34 100644 --- a/hw/display/macfb.c +++ b/hw/display/macfb.c @@ -22,12 +22,16 @@ #include "migration/vmstate.h" #include "trace.h" -#define VIDEO_BASE 0x00001000 +#define VIDEO_BASE 0x0 #define DAFB_BASE 0x00800000 #define MACFB_PAGE_SIZE 4096 #define MACFB_VRAM_SIZE (4 * MiB) +#define DAFB_MODE_VADDR1 0x0 +#define DAFB_MODE_VADDR2 0x4 +#define DAFB_MODE_CTRL1 0x8 +#define DAFB_MODE_CTRL2 0xc #define DAFB_MODE_SENSE 0x1c #define DAFB_RESET 0x200 #define DAFB_LUT 0x213 @@ -89,6 +93,22 @@ static MacFbSense macfb_sense_table[] = { { MACFB_DISPLAY_SVGA, 0x7, 0x5 }, }; +static MacFbMode macfb_mode_table[] = { + { MACFB_DISPLAY_VGA, 1, 0x100, 0x71e, 640, 480, 0x400, 0x1000 }, + { MACFB_DISPLAY_VGA, 2, 0x100, 0x70e, 640, 480, 0x400, 0x1000 }, + { MACFB_DISPLAY_VGA, 4, 0x100, 0x706, 640, 480, 0x400, 0x1000 }, + { MACFB_DISPLAY_VGA, 8, 0x100, 0x702, 640, 480, 0x400, 0x1000 }, + { MACFB_DISPLAY_VGA, 24, 0x100, 0x7ff, 640, 480, 0x1000, 0x1000 }, + { MACFB_DISPLAY_VGA, 1, 0xd0 , 0x70e, 800, 600, 0x340, 0xe00 }, + { MACFB_DISPLAY_VGA, 2, 0xd0 , 0x706, 800, 600, 0x340, 0xe00 }, + { MACFB_DISPLAY_VGA, 4, 0xd0 , 0x702, 800, 600, 0x340, 0xe00 }, + { MACFB_DISPLAY_VGA, 8, 0xd0, 0x700, 800, 600, 0x340, 0xe00 }, + { MACFB_DISPLAY_VGA, 24, 0x340, 0x100, 800, 600, 0xd00, 0xe00 }, + { MACFB_DISPLAY_APPLE_21_COLOR, 1, 0x90, 0x506, 1152, 870, 0x240, 0x80 }, + { MACFB_DISPLAY_APPLE_21_COLOR, 2, 0x90, 0x502, 1152, 870, 0x240, 0x80 }, + { MACFB_DISPLAY_APPLE_21_COLOR, 4, 0x90, 0x500, 1152, 870, 0x240, 0x80 }, + { MACFB_DISPLAY_APPLE_21_COLOR, 8, 0x120, 0x5ff, 1152, 870, 0x480, 0x80 }, +}; typedef void macfb_draw_line_func(MacfbState *s, uint8_t *d, uint32_t addr, int width); @@ -246,7 +266,7 @@ static void macfb_draw_graphic(MacfbState *s) ram_addr_t page; uint32_t v = 0; int y, ymin; - int macfb_stride = (s->depth * s->width + 7) / 8; + int macfb_stride = s->mode->stride; macfb_draw_line_func *macfb_draw_line; switch (s->depth) { @@ -278,7 +298,7 @@ static void macfb_draw_graphic(MacfbState *s) DIRTY_MEMORY_VGA); ymin = -1; - page = 0; + page = s->mode->offset; for (y = 0; y < s->height; y++, page += macfb_stride) { if (macfb_check_dirty(s, snap, page, macfb_stride)) { uint8_t *data_display; @@ -323,25 +343,26 @@ static uint32_t macfb_sense_read(MacfbState *s) sense = 0; if (!(macfb_sense->ext_sense & 1)) { /* Pins 7-4 together */ - if (~s->sense & 3) { - sense = (~s->sense & 7) | 3; + if (~s->regs[DAFB_MODE_SENSE >> 2] & 3) { + sense = (~s->regs[DAFB_MODE_SENSE >> 2] & 7) | 3; } } if (!(macfb_sense->ext_sense & 2)) { /* Pins 10-7 together */ - if (~s->sense & 6) { - sense = (~s->sense & 7) | 6; + if (~s->regs[DAFB_MODE_SENSE >> 2] & 6) { + sense = (~s->regs[DAFB_MODE_SENSE >> 2] & 7) | 6; } } if (!(macfb_sense->ext_sense & 4)) { /* Pins 4-10 together */ - if (~s->sense & 5) { - sense = (~s->sense & 7) | 5; + if (~s->regs[DAFB_MODE_SENSE >> 2] & 5) { + sense = (~s->regs[DAFB_MODE_SENSE >> 2] & 7) | 5; } } } else { /* Normal sense */ - sense = (~macfb_sense->sense & 7) | (~s->sense & 7); + sense = (~macfb_sense->sense & 7) | + (~s->regs[DAFB_MODE_SENSE >> 2] & 7); } trace_macfb_sense_read(sense); @@ -350,12 +371,84 @@ static uint32_t macfb_sense_read(MacfbState *s) static void macfb_sense_write(MacfbState *s, uint32_t val) { - s->sense = val; + s->regs[DAFB_MODE_SENSE >> 2] = val; trace_macfb_sense_write(val); return; } +static void macfb_update_mode(MacfbState *s) +{ + s->width = s->mode->width; + s->height = s->mode->height; + s->depth = s->mode->depth; + + trace_macfb_update_mode(s->width, s->height, s->depth); + macfb_invalidate_display(s); +} + +static void macfb_mode_write(MacfbState *s) +{ + MacFbMode *macfb_mode; + int i; + + for (i = 0; i < ARRAY_SIZE(macfb_mode_table); i++) { + macfb_mode = &macfb_mode_table[i]; + + if (s->type != macfb_mode->type) { + continue; + } + + if ((s->regs[DAFB_MODE_CTRL1 >> 2] & 0xff) == + (macfb_mode->mode_ctrl1 & 0xff) && + (s->regs[DAFB_MODE_CTRL2 >> 2] & 0xff) == + (macfb_mode->mode_ctrl2 & 0xff)) { + s->mode = macfb_mode; + macfb_update_mode(s); + break; + } + } +} + +static MacFbMode *macfb_find_mode(MacfbDisplayType display_type, + uint16_t width, uint16_t height, + uint8_t depth) +{ + MacFbMode *macfb_mode; + int i; + + for (i = 0; i < ARRAY_SIZE(macfb_mode_table); i++) { + macfb_mode = &macfb_mode_table[i]; + + if (display_type == macfb_mode->type && width == macfb_mode->width && + height == macfb_mode->height && depth == macfb_mode->depth) { + return macfb_mode; + } + } + + return NULL; +} + +static gchar *macfb_mode_list(void) +{ + gchar *list = NULL; + gchar *mode; + MacFbMode *macfb_mode; + int i; + + for (i = 0; i < ARRAY_SIZE(macfb_mode_table); i++) { + macfb_mode = &macfb_mode_table[i]; + + mode = g_strdup_printf(" %dx%dx%d\n", macfb_mode->width, + macfb_mode->height, macfb_mode->depth); + list = g_strconcat(mode, list, NULL); + g_free(mode); + } + + return list; +} + + static void macfb_update_display(void *opaque) { MacfbState *s = opaque; @@ -397,6 +490,12 @@ static uint64_t macfb_ctrl_read(void *opaque, uint64_t val = 0; switch (addr) { + case DAFB_MODE_VADDR1: + case DAFB_MODE_VADDR2: + case DAFB_MODE_CTRL1: + case DAFB_MODE_CTRL2: + val = s->regs[addr >> 2]; + break; case DAFB_MODE_SENSE: val = macfb_sense_read(s); break; @@ -413,6 +512,17 @@ static void macfb_ctrl_write(void *opaque, { MacfbState *s = opaque; switch (addr) { + case DAFB_MODE_VADDR1: + case DAFB_MODE_VADDR2: + s->regs[addr >> 2] = val; + break; + case DAFB_MODE_CTRL1 ... DAFB_MODE_CTRL1 + 3: + case DAFB_MODE_CTRL2 ... DAFB_MODE_CTRL2 + 3: + s->regs[addr >> 2] = val; + if (val) { + macfb_mode_write(s); + } + break; case DAFB_MODE_SENSE: macfb_sense_write(s, val); break; @@ -442,7 +552,7 @@ static const MemoryRegionOps macfb_ctrl_ops = { static int macfb_post_load(void *opaque, int version_id) { - macfb_invalidate_display(opaque); + macfb_mode_write(opaque); return 0; } @@ -455,7 +565,7 @@ static const VMStateDescription vmstate_macfb = { .fields = (VMStateField[]) { VMSTATE_UINT8_ARRAY(color_palette, MacfbState, 256 * 3), VMSTATE_UINT32(palette_current, MacfbState), - VMSTATE_UINT32(sense, MacfbState), + VMSTATE_UINT32_ARRAY(regs, MacfbState, MACFB_NUM_REGS), VMSTATE_END_OF_LIST() } }; @@ -469,9 +579,15 @@ static bool macfb_common_realize(DeviceState *dev, MacfbState *s, Error **errp) { DisplaySurface *surface; - if (s->depth != 1 && s->depth != 2 && s->depth != 4 && s->depth != 8 && - s->depth != 16 && s->depth != 24) { - error_setg(errp, "unknown guest depth %d", s->depth); + s->mode = macfb_find_mode(s->type, s->width, s->height, s->depth); + if (!s->mode) { + gchar *list; + error_setg(errp, "unknown display mode: width %d, height %d, depth %d", + s->width, s->height, s->depth); + list = macfb_mode_list(); + error_append_hint(errp, "Available modes:\n%s", list); + g_free(list); + return false; } @@ -493,6 +609,7 @@ static bool macfb_common_realize(DeviceState *dev, MacfbState *s, Error **errp) s->vram_bit_mask = MACFB_VRAM_SIZE - 1; memory_region_set_coalescing(&s->mem_vram); + macfb_update_mode(s); return true; } diff --git a/hw/display/trace-events b/hw/display/trace-events index 30cb460e4d..3a7a2c957f 100644 --- a/hw/display/trace-events +++ b/hw/display/trace-events @@ -173,3 +173,4 @@ macfb_ctrl_read(uint64_t addr, uint64_t value, unsigned int size) "addr 0x%"PRIx macfb_ctrl_write(uint64_t addr, uint64_t value, unsigned int size) "addr 0x%"PRIx64 " value 0x%"PRIx64 " size %u" macfb_sense_read(uint32_t value) "video sense: 0x%"PRIx32 macfb_sense_write(uint32_t value) "video sense: 0x%"PRIx32 +macfb_update_mode(uint32_t width, uint32_t height, uint8_t depth) "setting mode to width %"PRId32 " height %"PRId32 " size %d" |