From a0da500c381c85940c894e25f105f334e3a01987 Mon Sep 17 00:00:00 2001 From: starfrost013 Date: Mon, 16 Jun 2025 20:45:11 +0100 Subject: [PATCH 01/15] Add MDA colour support. Kind of crappy implementatio --- src/include/86box/vid_mda.h | 2 +- src/video/vid_mda.c | 88 +++++++++++++++++++++++++++++-------- 2 files changed, 71 insertions(+), 19 deletions(-) diff --git a/src/include/86box/vid_mda.h b/src/include/86box/vid_mda.h index e8ccd8602..d7d51fe44 100644 --- a/src/include/86box/vid_mda.h +++ b/src/include/86box/vid_mda.h @@ -61,7 +61,7 @@ typedef enum mda_crtc_registers_e typedef enum mda_mode_flags_e { MDA_MODE_HIGHRES = 1 << 0, // MUST be enabled for sane operation - MDA_MODE_BLACKANDWHITE = 1 << 1, // UNUSED in most cases. Not present on Hercules + MDA_MODE_BW = 1 << 1, // UNUSED in most cases. Not present on Hercules MDA_MODE_VIDEO_ENABLE = 1 << 3, MDA_MODE_BLINK = 1 << 5, } mda_mode_flags; diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index f3d881769..7c4251285 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -6,7 +6,7 @@ * * This file is part of the 86Box distribution. * - * MDA emulation. + * IBM Monochrome Display and Printer Adapter emulation. * * * @@ -18,6 +18,7 @@ * Copyright 2016-2025 Miran Grca. * Copyright 2025 starfrost / Connor Hyde */ +#include #include #include #include @@ -35,6 +36,17 @@ #include <86box/vid_mda.h> #include <86box/plat_unused.h> +// Enumerates MDA monitor types +enum mda_monitor_type_e +{ + MDA_MONITOR_TYPE_DEFAULT = 0, // Default MDA monitor type. + MDA_MONITOR_TYPE_GREEN = 1, // Green phosphor + MDA_MONITOR_TYPE_AMBER = 2, // Amber phosphor + MDA_MONITOR_TYPE_GRAY = 3, // Gray phosphor + MDA_MONITOR_TYPE_RGBI = 4, // RGBI colour monitor with modified rev1 or rev0 MDA card for colour support +} mda_monitor_type; + +// [attr][blink][fg] static int mda_attr_to_color_table[256][2][2]; static video_timings_t timing_mda = { .type = VIDEO_ISA, .write_b = 8, .write_w = 16, .write_l = 32, .read_b = 8, .read_w = 16, .read_l = 32 }; @@ -155,32 +167,66 @@ mda_poll(void *priv) scanline_old = mda->scanline; if ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3) mda->scanline = (mda->scanline << 1) & 7; - if (mda->dispon) { - if (mda->displine < mda->firstline) { + if (mda->dispon) + { + if (mda->displine < mda->firstline) + { mda->firstline = mda->displine; video_wait_for_buffer(); } mda->lastline = mda->displine; - for (x = 0; x < mda->crtc[MDA_CRTC_HDISP]; x++) { + + for (x = 0; x < mda->crtc[MDA_CRTC_HDISP]; x++) + { chr = mda->vram[(mda->memaddr << 1) & 0xfff]; attr = mda->vram[((mda->memaddr << 1) + 1) & 0xfff]; drawcursor = ((mda->memaddr == cursoraddr) && mda->cursorvisible && mda->cursoron); blink = ((mda->blink & 16) && (mda->mode & MDA_MODE_BLINK) && (attr & 0x80) && !drawcursor); - if (mda->scanline == 12 && ((attr & 7) == 1)) { + + int32_t color_bg = 0, color_fg = 0; + + // If we are using an RGBI monitor allow colour + //if (cga_palette == MDA_MONITOR_TYPE_RGBI) + //{ + if (!(mda->mode & MDA_MODE_BW)) + { + color_bg = (attr >> 4) & 0x0F; + color_fg = (attr & 0x0F); + } + + //} + + if (mda->scanline == 12 && ((attr & 7) == 1)) { // underline for (c = 0; c < 9; c++) - buffer32->line[mda->displine][(x * 9) + c] = mda_attr_to_color_table[attr][blink][1]; + buffer32->line[mda->displine][(x * 9) + c] = mda_attr_to_color_table[attr][blink][1] | color_bg; } else { for (c = 0; c < 8; c++) - buffer32->line[mda->displine][(x * 9) + c] = mda_attr_to_color_table[attr][blink][(fontdatm[chr + mda->fontbase][mda->scanline] & (1 << (c ^ 7))) ? 1 : 0]; + { + //bg=0, fg=1 + bool is_fg = (fontdatm[chr + mda->fontbase][mda->scanline] & (1 << (c ^ 7))) ? 1 : 0; + + uint32_t font_char = mda_attr_to_color_table[attr][blink][is_fg]; + + if (!(mda->mode & MDA_MODE_BW)) + { + if (!is_fg) + font_char = 16 + color_bg; + else + font_char = 16 + color_fg; + } + + buffer32->line[mda->displine][(x * 9) + c] = font_char; + + } if ((chr & ~0x1f) == 0xc0) buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][fontdatm[chr + mda->fontbase][mda->scanline] & 1]; else - buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][0]; + buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][0] | color_bg; } mda->memaddr++; if (drawcursor) { for (c = 0; c < 9; c++) - buffer32->line[mda->displine][(x * 9) + c] ^= mda_attr_to_color_table[attr][0][1]; + buffer32->line[mda->displine][(x * 9) + c] ^= mda_attr_to_color_table[attr][0][1] | color_fg; } } @@ -289,6 +335,7 @@ mda_poll(void *priv) void mda_init(mda_t *mda) { + for (uint16_t c = 0; c < 256; c++) { mda_attr_to_color_table[c][0][0] = mda_attr_to_color_table[c][1][0] = mda_attr_to_color_table[c][1][1] = 16; if (c & 8) @@ -308,6 +355,7 @@ mda_init(mda_t *mda) mda_attr_to_color_table[0x08][0][1] = mda_attr_to_color_table[0x08][1][1] = 16; mda_attr_to_color_table[0x80][0][1] = mda_attr_to_color_table[0x80][1][1] = 16; mda_attr_to_color_table[0x88][0][1] = mda_attr_to_color_table[0x88][1][1] = 16; + overscan_x = overscan_y = 0; mda->monitor_index = monitor_index_global; @@ -387,6 +435,7 @@ mda_speed_changed(void *priv) mda_recalctimings(mda); } + static const device_config_t mda_config[] = { // clang-format off { @@ -397,12 +446,14 @@ static const device_config_t mda_config[] = { .default_int = 0, .file_filter = NULL, .spinner = { 0 }, - .selection = { - { .description = "Default", .value = 0 }, - { .description = "Green", .value = 1 }, - { .description = "Amber", .value = 2 }, - { .description = "Gray", .value = 3 }, - { .description = "" } + .selection = + { + { .description = "Default", .value = MDA_MONITOR_TYPE_DEFAULT }, + { .description = "Green", .value = MDA_MONITOR_TYPE_GREEN }, + { .description = "Amber", .value = MDA_MONITOR_TYPE_AMBER }, + { .description = "Gray", .value = MDA_MONITOR_TYPE_GRAY }, + { .description = "Generic RGBI color monitor", .value = MDA_MONITOR_TYPE_RGBI }, + { .description = "" } }, .bios = { { 0 } } }, @@ -414,12 +465,13 @@ static const device_config_t mda_config[] = { .default_int = 0, .file_filter = NULL, .spinner = { 0 }, - .selection = { - { .description = "US (CP 437)", .value = 0 }, + .selection = + { + { .description = "US (CP 437)", .value = 0 }, { .description = "IBM Nordic (CP 437-Nordic)", .value = 1 }, { .description = "Czech Kamenicky (CP 895) #1", .value = 2 }, { .description = "Czech Kamenicky (CP 895) #2", .value = 3 }, - { .description = "" } + { .description = "" } }, .bios = { { 0 } } }, From a64fafcf614f0625706d3dc594a0fa7d778ff9c2 Mon Sep 17 00:00:00 2001 From: starfrost013 Date: Mon, 16 Jun 2025 20:48:38 +0100 Subject: [PATCH 02/15] Only enable colour support if we are using an RGBI monitor --- src/include/86box/vid_mda.h | 49 +++++++++++++++++++------------------ src/video/vid_mda.c | 9 ++++--- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/include/86box/vid_mda.h b/src/include/86box/vid_mda.h index d7d51fe44..105159b0f 100644 --- a/src/include/86box/vid_mda.h +++ b/src/include/86box/vid_mda.h @@ -69,34 +69,35 @@ typedef enum mda_mode_flags_e typedef struct mda_t { mem_mapping_t mapping; - uint8_t crtc[MDA_CRTC_NUM_REGISTERS]; - int crtcreg; + uint8_t crtc[MDA_CRTC_NUM_REGISTERS]; + int32_t crtcreg; - uint8_t mode; - uint8_t status; + uint8_t mode; + uint8_t status; - uint64_t dispontime; - uint64_t dispofftime; - pc_timer_t timer; + uint64_t dispontime; + uint64_t dispofftime; + pc_timer_t timer; - int firstline; - int lastline; + int32_t firstline; + int32_t lastline; - int fontbase; - int linepos; - int displine; - int vc; - int scanline; - uint16_t memaddr; - uint16_t memaddr_backup; - int cursorvisible; - int cursoron; - int dispon; - int blink; - int vsynctime; - int vadj; - int monitor_index; - int prev_monitor_index; + int32_t fontbase; + int32_t linepos; + int32_t displine; + int32_t vc; + int32_t scanline; + uint16_t memaddr; + uint16_t memaddr_backup; + int32_t cursorvisible; + int32_t cursoron; + int32_t dispon; + int32_t blink; + int32_t vsynctime; + int32_t vadj; + int32_t monitor_index; + int32_t prev_monitor_index; + int32_t monitor_type; // Used for MDA Colour support (REV0 u64) uint8_t *vram; } mda_t; diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index 7c4251285..a0bd61010 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -186,15 +186,15 @@ mda_poll(void *priv) int32_t color_bg = 0, color_fg = 0; // If we are using an RGBI monitor allow colour - //if (cga_palette == MDA_MONITOR_TYPE_RGBI) - //{ + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI) + { if (!(mda->mode & MDA_MODE_BW)) { color_bg = (attr >> 4) & 0x0F; color_fg = (attr & 0x0F); } - //} + } if (mda->scanline == 12 && ((attr & 7) == 1)) { // underline for (c = 0; c < 9; c++) @@ -360,7 +360,8 @@ mda_init(mda_t *mda) overscan_x = overscan_y = 0; mda->monitor_index = monitor_index_global; - cga_palette = device_get_config_int("rgb_type") << 1; + mda->monitor_type = device_get_config_int("rgb_type"); + cga_palette = mda->monitor_type << 1; if (cga_palette > 6) { cga_palette = 0; } From 23414bafcbedad45efe3815551b90c77dad83693 Mon Sep 17 00:00:00 2001 From: starfrost013 Date: Mon, 16 Jun 2025 20:53:27 +0100 Subject: [PATCH 03/15] Fix non-RGBI monitors --- src/video/vid_mda.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index a0bd61010..d900df69e 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -198,7 +198,7 @@ mda_poll(void *priv) if (mda->scanline == 12 && ((attr & 7) == 1)) { // underline for (c = 0; c < 9; c++) - buffer32->line[mda->displine][(x * 9) + c] = mda_attr_to_color_table[attr][blink][1] | color_bg; + buffer32->line[mda->displine][(x * 9) + c] = mda_attr_to_color_table[attr][blink][1] | color_fg; } else { for (c = 0; c < 8; c++) { @@ -207,7 +207,8 @@ mda_poll(void *priv) uint32_t font_char = mda_attr_to_color_table[attr][blink][is_fg]; - if (!(mda->mode & MDA_MODE_BW)) + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI + && !(mda->mode & MDA_MODE_BW)) { if (!is_fg) font_char = 16 + color_bg; From 0e7be429ca859b03c9418ebe21d8d0612b2203dc Mon Sep 17 00:00:00 2001 From: starfrost013 Date: Mon, 16 Jun 2025 21:00:36 +0100 Subject: [PATCH 04/15] more accuracy --- src/video/vid_mda.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index d900df69e..35026318b 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -217,10 +217,16 @@ mda_poll(void *priv) } buffer32->line[mda->displine][(x * 9) + c] = font_char; - } if ((chr & ~0x1f) == 0xc0) - buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][fontdatm[chr + mda->fontbase][mda->scanline] & 1]; + { + bool is_fg = fontdatm[chr + mda->fontbase][mda->scanline] & 1; + + if (is_fg) + buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][is_fg] | color_fg; + else + buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][is_fg] | color_bg; + } else buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][0] | color_bg; } From d63d1342de39e03ea122f65077ef04bb32fac96a Mon Sep 17 00:00:00 2001 From: starfrost013 Date: Mon, 16 Jun 2025 21:12:22 +0100 Subject: [PATCH 05/15] Don't set colour in blink mode --- src/video/vid_mda.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index 35026318b..d8f349ae9 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -192,8 +192,14 @@ mda_poll(void *priv) { color_bg = (attr >> 4) & 0x0F; color_fg = (attr & 0x0F); - } - + + // turn off bright bg colours in blink mode + if ((mda->mode & MDA_MODE_BLINK) + && (color_bg & 0x8)) + { + color_bg & ~(0x8); + } + } } if (mda->scanline == 12 && ((attr & 7) == 1)) { // underline @@ -222,10 +228,10 @@ mda_poll(void *priv) { bool is_fg = fontdatm[chr + mda->fontbase][mda->scanline] & 1; - if (is_fg) - buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][is_fg] | color_fg; - else + if (!is_fg) buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][is_fg] | color_bg; + else + buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][is_fg] | color_fg; } else buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][0] | color_bg; From 89b8652792982f0bbddc44c9cc6b87148dfb9479 Mon Sep 17 00:00:00 2001 From: starfrost013 Date: Mon, 16 Jun 2025 21:52:18 +0100 Subject: [PATCH 06/15] Fix the underlines --- src/include/86box/video.h | 4 ++++ src/video/vid_mda.c | 34 +++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/include/86box/video.h b/src/include/86box/video.h index 6ab375370..db7d5bfa0 100644 --- a/src/include/86box/video.h +++ b/src/include/86box/video.h @@ -187,6 +187,10 @@ extern bitmap_t *buffer32; #define efscrnsz_y (monitors[monitor_index_global].mon_efscrnsz_y) #define unscaled_size_x (monitors[monitor_index_global].mon_unscaled_size_x) #define unscaled_size_y (monitors[monitor_index_global].mon_unscaled_size_y) + +#define CGAPAL_CGA_START 16 // Where the 16-color cga text/composite starts + + extern PALETTE cgapal; extern PALETTE cgapal_mono[6]; #if 0 diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index d8f349ae9..fe382101f 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -196,16 +196,22 @@ mda_poll(void *priv) // turn off bright bg colours in blink mode if ((mda->mode & MDA_MODE_BLINK) && (color_bg & 0x8)) - { color_bg & ~(0x8); - } } } if (mda->scanline == 12 && ((attr & 7) == 1)) { // underline for (c = 0; c < 9; c++) - buffer32->line[mda->displine][(x * 9) + c] = mda_attr_to_color_table[attr][blink][1] | color_fg; - } else { + { + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI + && !(mda->mode & MDA_MODE_BW)) + { + buffer32->line[mda->displine][(x * 9) + c] = CGAPAL_CGA_START + color_fg; + } + else + buffer32->line[mda->displine][(x * 9) + c] = mda_attr_to_color_table[attr][blink][1]; + } + } else { // main text for (c = 0; c < 8; c++) { //bg=0, fg=1 @@ -217,13 +223,14 @@ mda_poll(void *priv) && !(mda->mode & MDA_MODE_BW)) { if (!is_fg) - font_char = 16 + color_bg; + font_char = CGAPAL_CGA_START + color_bg; else - font_char = 16 + color_fg; + font_char = CGAPAL_CGA_START + color_fg; } buffer32->line[mda->displine][(x * 9) + c] = font_char; } + if ((chr & ~0x1f) == 0xc0) { bool is_fg = fontdatm[chr + mda->fontbase][mda->scanline] & 1; @@ -237,6 +244,7 @@ mda_poll(void *priv) buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][0] | color_bg; } mda->memaddr++; + if (drawcursor) { for (c = 0; c < 9; c++) buffer32->line[mda->displine][(x * 9) + c] ^= mda_attr_to_color_table[attr][0][1] | color_fg; @@ -357,13 +365,13 @@ mda_init(mda_t *mda) mda_attr_to_color_table[c][0][1] = 7 + 16; } mda_attr_to_color_table[0x70][0][1] = 16; - mda_attr_to_color_table[0x70][0][0] = mda_attr_to_color_table[0x70][1][0] = mda_attr_to_color_table[0x70][1][1] = 16 + 15; + mda_attr_to_color_table[0x70][0][0] = mda_attr_to_color_table[0x70][1][0] = mda_attr_to_color_table[0x70][1][1] = CGAPAL_CGA_START + 15; mda_attr_to_color_table[0xF0][0][1] = 16; - mda_attr_to_color_table[0xF0][0][0] = mda_attr_to_color_table[0xF0][1][0] = mda_attr_to_color_table[0xF0][1][1] = 16 + 15; - mda_attr_to_color_table[0x78][0][1] = 16 + 7; - mda_attr_to_color_table[0x78][0][0] = mda_attr_to_color_table[0x78][1][0] = mda_attr_to_color_table[0x78][1][1] = 16 + 15; - mda_attr_to_color_table[0xF8][0][1] = 16 + 7; - mda_attr_to_color_table[0xF8][0][0] = mda_attr_to_color_table[0xF8][1][0] = mda_attr_to_color_table[0xF8][1][1] = 16 + 15; + mda_attr_to_color_table[0xF0][0][0] = mda_attr_to_color_table[0xF0][1][0] = mda_attr_to_color_table[0xF0][1][1] = CGAPAL_CGA_START + 15; + mda_attr_to_color_table[0x78][0][1] = CGAPAL_CGA_START + 7; + mda_attr_to_color_table[0x78][0][0] = mda_attr_to_color_table[0x78][1][0] = mda_attr_to_color_table[0x78][1][1] = CGAPAL_CGA_START + 15; + mda_attr_to_color_table[0xF8][0][1] = CGAPAL_CGA_START + 7; + mda_attr_to_color_table[0xF8][0][0] = mda_attr_to_color_table[0xF8][1][0] = mda_attr_to_color_table[0xF8][1][1] = CGAPAL_CGA_START + 15; mda_attr_to_color_table[0x00][0][1] = mda_attr_to_color_table[0x00][1][1] = 16; mda_attr_to_color_table[0x08][0][1] = mda_attr_to_color_table[0x08][1][1] = 16; mda_attr_to_color_table[0x80][0][1] = mda_attr_to_color_table[0x80][1][1] = 16; @@ -429,7 +437,7 @@ mda_standalone_init(UNUSED(const device_t *info)) void mda_setcol(int chr, int blink, int fg, uint8_t cga_ink) { - mda_attr_to_color_table[chr][blink][fg] = 16 + cga_ink; + mda_attr_to_color_table[chr][blink][fg] = CGAPAL_CGA_START + cga_ink; } void From 00ceaa3a39be0b9a9ae002a4ba645e144bf88a59 Mon Sep 17 00:00:00 2001 From: starfrost013 Date: Mon, 16 Jun 2025 21:56:01 +0100 Subject: [PATCH 07/15] Slightly better syntatical sugar --- src/video/vid_mda.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index fe382101f..2f02be80a 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -183,24 +183,24 @@ mda_poll(void *priv) drawcursor = ((mda->memaddr == cursoraddr) && mda->cursorvisible && mda->cursoron); blink = ((mda->blink & 16) && (mda->mode & MDA_MODE_BLINK) && (attr & 0x80) && !drawcursor); + // Colours that will be used int32_t color_bg = 0, color_fg = 0; // If we are using an RGBI monitor allow colour - if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI) + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI + && !(mda->mode & MDA_MODE_BW)) { - if (!(mda->mode & MDA_MODE_BW)) - { - color_bg = (attr >> 4) & 0x0F; - color_fg = (attr & 0x0F); + color_bg = (attr >> 4) & 0x0F; + color_fg = (attr & 0x0F); - // turn off bright bg colours in blink mode - if ((mda->mode & MDA_MODE_BLINK) - && (color_bg & 0x8)) - color_bg & ~(0x8); - } + // turn off bright bg colours in blink mode + if ((mda->mode & MDA_MODE_BLINK) + && (color_bg & 0x8)) + color_bg & ~(0x8); } - if (mda->scanline == 12 && ((attr & 7) == 1)) { // underline + if (mda->scanline == 12 && ((attr & 7) == 1)) + { // underline for (c = 0; c < 9; c++) { if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI @@ -243,9 +243,11 @@ mda_poll(void *priv) else buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][0] | color_bg; } + mda->memaddr++; - if (drawcursor) { + if (drawcursor) + { for (c = 0; c < 9; c++) buffer32->line[mda->displine][(x * 9) + c] ^= mda_attr_to_color_table[attr][0][1] | color_fg; } From 091c0aa32e97ad0edbcb595663333382fc499574 Mon Sep 17 00:00:00 2001 From: starfrost013 Date: Mon, 16 Jun 2025 22:08:07 +0100 Subject: [PATCH 08/15] c -> attr --- src/video/vid_mda.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index 2f02be80a..c4fb4be74 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -359,12 +359,13 @@ void mda_init(mda_t *mda) { - for (uint16_t c = 0; c < 256; c++) { - mda_attr_to_color_table[c][0][0] = mda_attr_to_color_table[c][1][0] = mda_attr_to_color_table[c][1][1] = 16; - if (c & 8) - mda_attr_to_color_table[c][0][1] = 15 + 16; + for (uint16_t attr = 0; attr < 256; attr++) + { + mda_attr_to_color_table[attr][0][0] = mda_attr_to_color_table[attr][1][0] = mda_attr_to_color_table[attr][1][1] = 16; + if (attr & 8) + mda_attr_to_color_table[attr][0][1] = 15 + 16; else - mda_attr_to_color_table[c][0][1] = 7 + 16; + mda_attr_to_color_table[attr][0][1] = 7 + 16; } mda_attr_to_color_table[0x70][0][1] = 16; mda_attr_to_color_table[0x70][0][0] = mda_attr_to_color_table[0x70][1][0] = mda_attr_to_color_table[0x70][1][1] = CGAPAL_CGA_START + 15; From 7b044e808463498f58d18059d72a3484ab5b6ad8 Mon Sep 17 00:00:00 2001 From: starfrost013 Date: Mon, 16 Jun 2025 23:21:40 +0100 Subject: [PATCH 09/15] much cleaned up code with fixed 9th column support, gray/black background special treatment --- src/video/vid_mda.c | 68 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 15 deletions(-) diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index c4fb4be74..ed99a169b 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -152,7 +152,7 @@ mda_poll(void *priv) uint16_t cursoraddr = (mda->crtc[MDA_CRTC_CURSOR_ADDR_LOW] | (mda->crtc[MDA_CRTC_CURSOR_ADDR_HIGH] << 8)) & 0x3fff; int drawcursor; int x; - int c; + int column; int oldvc; uint8_t chr; uint8_t attr; @@ -197,25 +197,38 @@ mda_poll(void *priv) if ((mda->mode & MDA_MODE_BLINK) && (color_bg & 0x8)) color_bg & ~(0x8); + + // black-on-non black or white colours forced to white + // grey-on-colours forced to bright white + + bool special_treatment = (color_bg != 0 && color_bg != 7); + + if (color_fg == 7 + && special_treatment) + color_fg = 15; + + if (color_fg == 0 + && special_treatment) + color_fg = 7; } if (mda->scanline == 12 && ((attr & 7) == 1)) { // underline - for (c = 0; c < 9; c++) + for (column = 0; column < 9; column++) { if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI && !(mda->mode & MDA_MODE_BW)) { - buffer32->line[mda->displine][(x * 9) + c] = CGAPAL_CGA_START + color_fg; + buffer32->line[mda->displine][(x * 9) + column] = CGAPAL_CGA_START + color_fg; } else - buffer32->line[mda->displine][(x * 9) + c] = mda_attr_to_color_table[attr][blink][1]; + buffer32->line[mda->displine][(x * 9) + column] = mda_attr_to_color_table[attr][blink][1]; } - } else { // main text - for (c = 0; c < 8; c++) + } else { // character + for (column = 0; column < 8; column++) { //bg=0, fg=1 - bool is_fg = (fontdatm[chr + mda->fontbase][mda->scanline] & (1 << (c ^ 7))) ? 1 : 0; + bool is_fg = (fontdatm[chr + mda->fontbase][mda->scanline] & (1 << (column ^ 7))) ? 1 : 0; uint32_t font_char = mda_attr_to_color_table[attr][blink][is_fg]; @@ -228,28 +241,53 @@ mda_poll(void *priv) font_char = CGAPAL_CGA_START + color_fg; } - buffer32->line[mda->displine][(x * 9) + c] = font_char; + buffer32->line[mda->displine][(x * 9) + column] = font_char; } if ((chr & ~0x1f) == 0xc0) { bool is_fg = fontdatm[chr + mda->fontbase][mda->scanline] & 1; + uint32_t final_result = mda_attr_to_color_table[attr][blink][is_fg]; + + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI + && !(mda->mode & MDA_MODE_BW)) + { + if (!is_fg) + final_result = CGAPAL_CGA_START + color_bg; + else + final_result = CGAPAL_CGA_START + color_fg; + } + + buffer32->line[mda->displine][(x * 9) + 8] = final_result; - if (!is_fg) - buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][is_fg] | color_bg; - else - buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][is_fg] | color_fg; } else - buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][0] | color_bg; + { + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI + && !(mda->mode & MDA_MODE_BW)) + { + buffer32->line[mda->displine][(x * 9) + 8] = CGAPAL_CGA_START + color_bg; + + } + else + buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][0]; + } } mda->memaddr++; if (drawcursor) { - for (c = 0; c < 9; c++) - buffer32->line[mda->displine][(x * 9) + c] ^= mda_attr_to_color_table[attr][0][1] | color_fg; + for (column = 0; column < 9; column++) + { + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI + && !(mda->mode & MDA_MODE_BW)) + { + buffer32->line[mda->displine][(x * 9) + column] ^= CGAPAL_CGA_START + color_fg; + } + else + buffer32->line[mda->displine][(x * 9) + column] ^= mda_attr_to_color_table[attr][0][1]; + } } } From a925076a7a1a0724073fdc7f94e3580393d95206 Mon Sep 17 00:00:00 2001 From: starfrost013 Date: Mon, 16 Jun 2025 23:23:47 +0100 Subject: [PATCH 10/15] implement gray being black on fg and bg being gray --- src/video/vid_mda.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index ed99a169b..6c4070d8c 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -210,6 +210,11 @@ mda_poll(void *priv) if (color_fg == 0 && special_treatment) color_fg = 7; + + // gray is black + if (color_fg == 7 + && color_bg == 7) + color_fg = 0; } if (mda->scanline == 12 && ((attr & 7) == 1)) From a530f9365b69559eee40f3ef2f541bd4283abbcc Mon Sep 17 00:00:00 2001 From: starfrost013 Date: Mon, 16 Jun 2025 23:25:27 +0100 Subject: [PATCH 11/15] missed one --- src/video/vid_mda.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index 6c4070d8c..bfdc50352 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -213,7 +213,7 @@ mda_poll(void *priv) // gray is black if (color_fg == 7 - && color_bg == 7) + && (color_bg == 7 || color_bg == 0)) color_fg = 0; } From 0109f0b81109f19fc451772329f3d63f3bbabb8c Mon Sep 17 00:00:00 2001 From: starfrost013 Date: Mon, 16 Jun 2025 23:33:43 +0100 Subject: [PATCH 12/15] make gray actually gray --- src/video/vid_mda.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index bfdc50352..65e57a8e0 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -203,17 +203,17 @@ mda_poll(void *priv) bool special_treatment = (color_bg != 0 && color_bg != 7); - if (color_fg == 7 + if (color_fg == 8 && special_treatment) color_fg = 15; if (color_fg == 0 && special_treatment) - color_fg = 7; + color_fg = 8; // gray is black - if (color_fg == 7 - && (color_bg == 7 || color_bg == 0)) + if (color_fg == 8 + && (color_bg == 8 || color_bg == 0)) color_fg = 0; } @@ -225,7 +225,7 @@ mda_poll(void *priv) && !(mda->mode & MDA_MODE_BW)) { buffer32->line[mda->displine][(x * 9) + column] = CGAPAL_CGA_START + color_fg; - } + 1 } else buffer32->line[mda->displine][(x * 9) + column] = mda_attr_to_color_table[attr][blink][1]; } From 3c29c00a94f9c567e3834bb602b1320c8b8fe6ff Mon Sep 17 00:00:00 2001 From: starfrost013 Date: Mon, 16 Jun 2025 23:38:05 +0100 Subject: [PATCH 13/15] mda_poll: make drawcursor a bool; localise the scope of various variables; de-same-line-braceify for readability --- src/video/vid_mda.c | 58 ++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index 65e57a8e0..6e5298201 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -150,23 +150,24 @@ mda_poll(void *priv) { mda_t *mda = (mda_t *) priv; uint16_t cursoraddr = (mda->crtc[MDA_CRTC_CURSOR_ADDR_LOW] | (mda->crtc[MDA_CRTC_CURSOR_ADDR_HIGH] << 8)) & 0x3fff; - int drawcursor; - int x; - int column; - int oldvc; + bool drawcursor; + int32_t oldvc; uint8_t chr; uint8_t attr; - int scanline_old; - int blink; + int32_t scanline_old; + int32_t blink; VIDEO_MONITOR_PROLOGUE() - if (!mda->linepos) { + + if (!mda->linepos) + { timer_advance_u64(&mda->timer, mda->dispofftime); mda->status |= 1; mda->linepos = 1; scanline_old = mda->scanline; if ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3) mda->scanline = (mda->scanline << 1) & 7; + if (mda->dispon) { if (mda->displine < mda->firstline) @@ -176,7 +177,7 @@ mda_poll(void *priv) } mda->lastline = mda->displine; - for (x = 0; x < mda->crtc[MDA_CRTC_HDISP]; x++) + for (uint32_t x = 0; x < mda->crtc[MDA_CRTC_HDISP]; x++) { chr = mda->vram[(mda->memaddr << 1) & 0xfff]; attr = mda->vram[((mda->memaddr << 1) + 1) & 0xfff]; @@ -217,20 +218,23 @@ mda_poll(void *priv) color_fg = 0; } - if (mda->scanline == 12 && ((attr & 7) == 1)) + if (mda->scanline == 12 + && ((attr & 7) == 1)) { // underline - for (column = 0; column < 9; column++) + for (uint32_t column = 0; column < 9; column++) { if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI && !(mda->mode & MDA_MODE_BW)) { buffer32->line[mda->displine][(x * 9) + column] = CGAPAL_CGA_START + color_fg; - 1 } + } else buffer32->line[mda->displine][(x * 9) + column] = mda_attr_to_color_table[attr][blink][1]; } - } else { // character - for (column = 0; column < 8; column++) + } + else + { // character + for (uint32_t column = 0; column < 8; column++) { //bg=0, fg=1 bool is_fg = (fontdatm[chr + mda->fontbase][mda->scanline] & (1 << (column ^ 7))) ? 1 : 0; @@ -249,6 +253,7 @@ mda_poll(void *priv) buffer32->line[mda->displine][(x * 9) + column] = font_char; } + // these characters (C0-DF) have their background extended to their 9th column if ((chr & ~0x1f) == 0xc0) { bool is_fg = fontdatm[chr + mda->fontbase][mda->scanline] & 1; @@ -283,7 +288,7 @@ mda_poll(void *priv) if (drawcursor) { - for (column = 0; column < 9; column++) + for (uint32_t column = 0; column < 9; column++) { if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI && !(mda->mode & MDA_MODE_BW)) @@ -310,30 +315,39 @@ mda_poll(void *priv) if (mda->dispon) mda->status &= ~1; mda->linepos = 0; - if (mda->vsynctime) { + + if (mda->vsynctime) + { mda->vsynctime--; - if (!mda->vsynctime) { + if (!mda->vsynctime) + { mda->status &= ~8; } } if (mda->scanline == (mda->crtc[MDA_CRTC_CURSOR_END] & 31) || ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3 - && mda->scanline == ((mda->crtc[MDA_CRTC_CURSOR_END] & 31) >> 1))) { + && mda->scanline == ((mda->crtc[MDA_CRTC_CURSOR_END] & 31) >> 1))) + { mda->cursorvisible = 0; } - if (mda->vadj) { + + if (mda->vadj) + { mda->scanline++; mda->scanline &= 31; mda->memaddr = mda->memaddr_backup; mda->vadj--; - if (!mda->vadj) { + if (!mda->vadj) + { mda->dispon = 1; mda->memaddr = mda->memaddr_backup = (mda->crtc[MDA_CRTC_START_ADDR_LOW] | (mda->crtc[MDA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; mda->scanline = 0; } - } else if (mda->scanline == mda->crtc[MDA_CRTC_MAX_SCANLINE_ADDR] + } + else if (mda->scanline == mda->crtc[MDA_CRTC_MAX_SCANLINE_ADDR] || ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3 - && mda->scanline == (mda->crtc[MDA_CRTC_MAX_SCANLINE_ADDR] >> 1))) { + && mda->scanline == (mda->crtc[MDA_CRTC_MAX_SCANLINE_ADDR] >> 1))) + { mda->memaddr_backup = mda->memaddr; mda->scanline = 0; oldvc = mda->vc; @@ -359,7 +373,7 @@ mda_poll(void *priv) mda->displine = 0; mda->vsynctime = 16; if (mda->crtc[MDA_CRTC_VSYNC]) { - x = mda->crtc[MDA_CRTC_HDISP] * 9; + uint32_t x = mda->crtc[MDA_CRTC_HDISP] * 9; mda->lastline++; if ((x != xsize) || ((mda->lastline - mda->firstline) != ysize) || video_force_resize_get()) { xsize = x; From b732ece04d8bea1ffcaa2d238d80c7b6f2757a13 Mon Sep 17 00:00:00 2001 From: starfrost013 Date: Mon, 16 Jun 2025 23:41:01 +0100 Subject: [PATCH 14/15] Conform to the style guide --- src/video/vid_mda.c | 235 ++++++++++++++++++-------------------------- 1 file changed, 98 insertions(+), 137 deletions(-) diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index 6e5298201..36e486b2d 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -37,13 +37,12 @@ #include <86box/plat_unused.h> // Enumerates MDA monitor types -enum mda_monitor_type_e -{ - MDA_MONITOR_TYPE_DEFAULT = 0, // Default MDA monitor type. - MDA_MONITOR_TYPE_GREEN = 1, // Green phosphor - MDA_MONITOR_TYPE_AMBER = 2, // Amber phosphor - MDA_MONITOR_TYPE_GRAY = 3, // Gray phosphor - MDA_MONITOR_TYPE_RGBI = 4, // RGBI colour monitor with modified rev1 or rev0 MDA card for colour support +enum mda_monitor_type_e { + MDA_MONITOR_TYPE_DEFAULT = 0, // Default MDA monitor type. + MDA_MONITOR_TYPE_GREEN = 1, // Green phosphor + MDA_MONITOR_TYPE_AMBER = 2, // Amber phosphor + MDA_MONITOR_TYPE_GRAY = 3, // Gray phosphor + MDA_MONITOR_TYPE_RGBI = 4, // RGBI colour monitor with modified rev1 or rev0 MDA card for colour support } mda_monitor_type; // [attr][blink][fg] @@ -58,12 +57,11 @@ mda_out(uint16_t addr, uint8_t val, void *priv) { mda_t *mda = (mda_t *) priv; - if (addr < MDA_REGISTER_START - || addr > MDA_REGISTER_CRT_STATUS) // Maintain old behaviour for printer registers, just in case + if (addr < MDA_REGISTER_START + || addr > MDA_REGISTER_CRT_STATUS) // Maintain old behaviour for printer registers, just in case return; - switch (addr) - { + switch (addr) { case MDA_REGISTER_MODE_CONTROL: mda->mode = val; return; @@ -73,20 +71,17 @@ mda_out(uint16_t addr, uint8_t val, void *priv) // addr & 1 == 1 = MDA_REGISTER_CRTC_DATA // otherwise MDA_REGISTER_CRTC_INDEX - if (addr & 1) - { + if (addr & 1) { mda->crtc[mda->crtcreg] = val; - if (mda->crtc[MDA_CRTC_CURSOR_START] == 6 + if (mda->crtc[MDA_CRTC_CURSOR_START] == 6 && mda->crtc[MDA_CRTC_CURSOR_END] == 7) /*Fix for Generic Turbo XT BIOS, which sets up cursor registers wrong*/ { mda->crtc[MDA_CRTC_CURSOR_START] = 0xb; - mda->crtc[MDA_CRTC_CURSOR_END] = 0xc; + mda->crtc[MDA_CRTC_CURSOR_END] = 0xc; } mda_recalctimings(mda); - } - else + } else mda->crtcreg = val & 31; - } uint8_t @@ -94,19 +89,18 @@ mda_in(uint16_t addr, void *priv) { const mda_t *mda = (mda_t *) priv; - switch (addr) - { + switch (addr) { case MDA_REGISTER_CRT_STATUS: return mda->status | 0xF0; default: - if (addr < MDA_REGISTER_START - || addr > MDA_REGISTER_CRT_STATUS) // Maintain old behaviour for printer registers, just in case + if (addr < MDA_REGISTER_START + || addr > MDA_REGISTER_CRT_STATUS) // Maintain old behaviour for printer registers, just in case return 0xFF; // MDA_REGISTER_CRTC_DATA if (addr & 1) return mda->crtc[mda->crtcreg]; - else + else return mda->crtcreg; break; @@ -148,8 +142,8 @@ mda_recalctimings(mda_t *mda) void mda_poll(void *priv) { - mda_t *mda = (mda_t *) priv; - uint16_t cursoraddr = (mda->crtc[MDA_CRTC_CURSOR_ADDR_LOW] | (mda->crtc[MDA_CRTC_CURSOR_ADDR_HIGH] << 8)) & 0x3fff; + mda_t *mda = (mda_t *) priv; + uint16_t cursoraddr = (mda->crtc[MDA_CRTC_CURSOR_ADDR_LOW] | (mda->crtc[MDA_CRTC_CURSOR_ADDR_HIGH] << 8)) & 0x3fff; bool drawcursor; int32_t oldvc; uint8_t chr; @@ -159,44 +153,39 @@ mda_poll(void *priv) VIDEO_MONITOR_PROLOGUE() - if (!mda->linepos) - { + if (!mda->linepos) { timer_advance_u64(&mda->timer, mda->dispofftime); mda->status |= 1; mda->linepos = 1; - scanline_old = mda->scanline; + scanline_old = mda->scanline; if ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3) mda->scanline = (mda->scanline << 1) & 7; - if (mda->dispon) - { - if (mda->displine < mda->firstline) - { + if (mda->dispon) { + if (mda->displine < mda->firstline) { mda->firstline = mda->displine; video_wait_for_buffer(); } mda->lastline = mda->displine; - for (uint32_t x = 0; x < mda->crtc[MDA_CRTC_HDISP]; x++) - { + for (uint32_t x = 0; x < mda->crtc[MDA_CRTC_HDISP]; x++) { chr = mda->vram[(mda->memaddr << 1) & 0xfff]; attr = mda->vram[((mda->memaddr << 1) + 1) & 0xfff]; drawcursor = ((mda->memaddr == cursoraddr) && mda->cursorvisible && mda->cursoron); blink = ((mda->blink & 16) && (mda->mode & MDA_MODE_BLINK) && (attr & 0x80) && !drawcursor); // Colours that will be used - int32_t color_bg = 0, color_fg = 0; - + int32_t color_bg = 0, color_fg = 0; + // If we are using an RGBI monitor allow colour if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI - && !(mda->mode & MDA_MODE_BW)) - { + && !(mda->mode & MDA_MODE_BW)) { color_bg = (attr >> 4) & 0x0F; - color_fg = (attr & 0x0F); + color_fg = (attr & 0x0F); // turn off bright bg colours in blink mode if ((mda->mode & MDA_MODE_BLINK) - && (color_bg & 0x8)) + && (color_bg & 0x8)) color_bg & ~(0x8); // black-on-non black or white colours forced to white @@ -204,98 +193,80 @@ mda_poll(void *priv) bool special_treatment = (color_bg != 0 && color_bg != 7); - if (color_fg == 8 - && special_treatment) + if (color_fg == 8 + && special_treatment) color_fg = 15; - + if (color_fg == 0 - && special_treatment) + && special_treatment) color_fg = 8; - // gray is black + // gray is black if (color_fg == 8 - && (color_bg == 8 || color_bg == 0)) + && (color_bg == 8 || color_bg == 0)) color_fg = 0; } - if (mda->scanline == 12 - && ((attr & 7) == 1)) - { // underline - for (uint32_t column = 0; column < 9; column++) - { - if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI - && !(mda->mode & MDA_MODE_BW)) - { + if (mda->scanline == 12 + && ((attr & 7) == 1)) { // underline + for (uint32_t column = 0; column < 9; column++) { + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI + && !(mda->mode & MDA_MODE_BW)) { buffer32->line[mda->displine][(x * 9) + column] = CGAPAL_CGA_START + color_fg; - } - else + } else buffer32->line[mda->displine][(x * 9) + column] = mda_attr_to_color_table[attr][blink][1]; } - } - else - { // character - for (uint32_t column = 0; column < 8; column++) - { - //bg=0, fg=1 + } else { // character + for (uint32_t column = 0; column < 8; column++) { + // bg=0, fg=1 bool is_fg = (fontdatm[chr + mda->fontbase][mda->scanline] & (1 << (column ^ 7))) ? 1 : 0; uint32_t font_char = mda_attr_to_color_table[attr][blink][is_fg]; - if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI - && !(mda->mode & MDA_MODE_BW)) - { + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI + && !(mda->mode & MDA_MODE_BW)) { if (!is_fg) - font_char = CGAPAL_CGA_START + color_bg; - else - font_char = CGAPAL_CGA_START + color_fg; + font_char = CGAPAL_CGA_START + color_bg; + else + font_char = CGAPAL_CGA_START + color_fg; } - + buffer32->line[mda->displine][(x * 9) + column] = font_char; } - + // these characters (C0-DF) have their background extended to their 9th column - if ((chr & ~0x1f) == 0xc0) - { - bool is_fg = fontdatm[chr + mda->fontbase][mda->scanline] & 1; + if ((chr & ~0x1f) == 0xc0) { + bool is_fg = fontdatm[chr + mda->fontbase][mda->scanline] & 1; uint32_t final_result = mda_attr_to_color_table[attr][blink][is_fg]; - if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI - && !(mda->mode & MDA_MODE_BW)) - { + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI + && !(mda->mode & MDA_MODE_BW)) { if (!is_fg) - final_result = CGAPAL_CGA_START + color_bg; + final_result = CGAPAL_CGA_START + color_bg; else - final_result = CGAPAL_CGA_START + color_fg; + final_result = CGAPAL_CGA_START + color_fg; } - buffer32->line[mda->displine][(x * 9) + 8] = final_result; + buffer32->line[mda->displine][(x * 9) + 8] = final_result; - } - else - { - if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI - && !(mda->mode & MDA_MODE_BW)) - { - buffer32->line[mda->displine][(x * 9) + 8] = CGAPAL_CGA_START + color_bg; + } else { + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI + && !(mda->mode & MDA_MODE_BW)) { + buffer32->line[mda->displine][(x * 9) + 8] = CGAPAL_CGA_START + color_bg; - } - else - buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][0]; + } else + buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][0]; } } - + mda->memaddr++; - if (drawcursor) - { - for (uint32_t column = 0; column < 9; column++) - { - if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI - && !(mda->mode & MDA_MODE_BW)) - { - buffer32->line[mda->displine][(x * 9) + column] ^= CGAPAL_CGA_START + color_fg; - } - else + if (drawcursor) { + for (uint32_t column = 0; column < 9; column++) { + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI + && !(mda->mode & MDA_MODE_BW)) { + buffer32->line[mda->displine][(x * 9) + column] ^= CGAPAL_CGA_START + color_fg; + } else buffer32->line[mda->displine][(x * 9) + column] ^= mda_attr_to_color_table[attr][0][1]; } } @@ -316,41 +287,34 @@ mda_poll(void *priv) mda->status &= ~1; mda->linepos = 0; - if (mda->vsynctime) - { + if (mda->vsynctime) { mda->vsynctime--; - if (!mda->vsynctime) - { + if (!mda->vsynctime) { mda->status &= ~8; } } - if (mda->scanline == (mda->crtc[MDA_CRTC_CURSOR_END] & 31) - || ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3 - && mda->scanline == ((mda->crtc[MDA_CRTC_CURSOR_END] & 31) >> 1))) - { - mda->cursorvisible = 0; + if (mda->scanline == (mda->crtc[MDA_CRTC_CURSOR_END] & 31) + || ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3 + && mda->scanline == ((mda->crtc[MDA_CRTC_CURSOR_END] & 31) >> 1))) { + mda->cursorvisible = 0; } - if (mda->vadj) - { + if (mda->vadj) { mda->scanline++; mda->scanline &= 31; mda->memaddr = mda->memaddr_backup; mda->vadj--; - if (!mda->vadj) - { - mda->dispon = 1; + if (!mda->vadj) { + mda->dispon = 1; mda->memaddr = mda->memaddr_backup = (mda->crtc[MDA_CRTC_START_ADDR_LOW] | (mda->crtc[MDA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; - mda->scanline = 0; + mda->scanline = 0; } - } - else if (mda->scanline == mda->crtc[MDA_CRTC_MAX_SCANLINE_ADDR] - || ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3 - && mda->scanline == (mda->crtc[MDA_CRTC_MAX_SCANLINE_ADDR] >> 1))) - { + } else if (mda->scanline == mda->crtc[MDA_CRTC_MAX_SCANLINE_ADDR] + || ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3 + && mda->scanline == (mda->crtc[MDA_CRTC_MAX_SCANLINE_ADDR] >> 1))) { mda->memaddr_backup = mda->memaddr; - mda->scanline = 0; - oldvc = mda->vc; + mda->scanline = 0; + oldvc = mda->vc; mda->vc++; mda->vc &= 127; if (mda->vc == mda->crtc[MDA_CRTC_VDISP]) @@ -403,9 +367,9 @@ mda_poll(void *priv) mda->memaddr = mda->memaddr_backup; } - if (mda->scanline == (mda->crtc[MDA_CRTC_CURSOR_START] & 31) - || ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3 - && mda->scanline == ((mda->crtc[MDA_CRTC_CURSOR_START] & 31) >> 1))) { + if (mda->scanline == (mda->crtc[MDA_CRTC_CURSOR_START] & 31) + || ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3 + && mda->scanline == ((mda->crtc[MDA_CRTC_CURSOR_START] & 31) >> 1))) { mda->cursorvisible = 1; } } @@ -415,9 +379,8 @@ mda_poll(void *priv) void mda_init(mda_t *mda) { - - for (uint16_t attr = 0; attr < 256; attr++) - { + + for (uint16_t attr = 0; attr < 256; attr++) { mda_attr_to_color_table[attr][0][0] = mda_attr_to_color_table[attr][1][0] = mda_attr_to_color_table[attr][1][1] = 16; if (attr & 8) mda_attr_to_color_table[attr][0][1] = 15 + 16; @@ -426,23 +389,22 @@ mda_init(mda_t *mda) } mda_attr_to_color_table[0x70][0][1] = 16; mda_attr_to_color_table[0x70][0][0] = mda_attr_to_color_table[0x70][1][0] = mda_attr_to_color_table[0x70][1][1] = CGAPAL_CGA_START + 15; - mda_attr_to_color_table[0xF0][0][1] = 16; + mda_attr_to_color_table[0xF0][0][1] = 16; mda_attr_to_color_table[0xF0][0][0] = mda_attr_to_color_table[0xF0][1][0] = mda_attr_to_color_table[0xF0][1][1] = CGAPAL_CGA_START + 15; - mda_attr_to_color_table[0x78][0][1] = CGAPAL_CGA_START + 7; + mda_attr_to_color_table[0x78][0][1] = CGAPAL_CGA_START + 7; mda_attr_to_color_table[0x78][0][0] = mda_attr_to_color_table[0x78][1][0] = mda_attr_to_color_table[0x78][1][1] = CGAPAL_CGA_START + 15; - mda_attr_to_color_table[0xF8][0][1] = CGAPAL_CGA_START + 7; + mda_attr_to_color_table[0xF8][0][1] = CGAPAL_CGA_START + 7; mda_attr_to_color_table[0xF8][0][0] = mda_attr_to_color_table[0xF8][1][0] = mda_attr_to_color_table[0xF8][1][1] = CGAPAL_CGA_START + 15; mda_attr_to_color_table[0x00][0][1] = mda_attr_to_color_table[0x00][1][1] = 16; mda_attr_to_color_table[0x08][0][1] = mda_attr_to_color_table[0x08][1][1] = 16; mda_attr_to_color_table[0x80][0][1] = mda_attr_to_color_table[0x80][1][1] = 16; mda_attr_to_color_table[0x88][0][1] = mda_attr_to_color_table[0x88][1][1] = 16; - overscan_x = overscan_y = 0; mda->monitor_index = monitor_index_global; mda->monitor_type = device_get_config_int("rgb_type"); - cga_palette = mda->monitor_type << 1; + cga_palette = mda->monitor_type << 1; if (cga_palette > 6) { cga_palette = 0; } @@ -460,7 +422,7 @@ mda_standalone_init(UNUSED(const device_t *info)) mda->vram = malloc(0x1000); - switch(device_get_config_int("font")) { + switch (device_get_config_int("font")) { case 0: loadfont(FONT_IBM_MDA_437_PATH, 0); break; @@ -517,9 +479,8 @@ mda_speed_changed(void *priv) mda_recalctimings(mda); } - static const device_config_t mda_config[] = { - // clang-format off + // clang-format off { .name = "rgb_type", .description = "Display type", @@ -558,7 +519,7 @@ static const device_config_t mda_config[] = { .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } - // clang-format on + // clang-format on }; const device_t mda_device = { From 07b418d470440bc96d62197c5059d7c484998719 Mon Sep 17 00:00:00 2001 From: starfrost013 Date: Mon, 16 Jun 2025 23:47:15 +0100 Subject: [PATCH 15/15] add the mda_colors enum and use it instead of magic numbers in the colour fixup code --- src/include/86box/vid_mda.h | 20 ++++++++++++++++++++ src/video/vid_mda.c | 12 ++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/include/86box/vid_mda.h b/src/include/86box/vid_mda.h index 105159b0f..13aa70594 100644 --- a/src/include/86box/vid_mda.h +++ b/src/include/86box/vid_mda.h @@ -66,6 +66,26 @@ typedef enum mda_mode_flags_e MDA_MODE_BLINK = 1 << 5, } mda_mode_flags; +typedef enum mda_colors_e +{ + MDA_COLOR_BLACK = 0, + MDA_COLOR_BLUE = 1, + MDA_COLOR_GREEN = 2, + MDA_COLOR_CYAN = 3, + MDA_COLOR_RED = 4, + MDA_COLOR_MAGENTA = 5, + MDA_COLOR_BROWN = 6, + MDA_COLOR_WHITE = 7, + MDA_COLOR_GREY = 8, + MDA_COLOR_BRIGHT_BLUE = 9, + MDA_COLOR_BRIGHT_GREEN = 10, + MDA_COLOR_BRIGHT_CYAN = 11, + MDA_COLOR_BRIGHT_RED = 12, + MDA_COLOR_BRIGHT_MAGENTA = 13, + MDA_COLOR_BRIGHT_YELLOW = 14, + MDA_COLOR_BRIGHT_WHITE = 15, +} mda_colors; + typedef struct mda_t { mem_mapping_t mapping; diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index 36e486b2d..b0cbd203e 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -193,18 +193,18 @@ mda_poll(void *priv) bool special_treatment = (color_bg != 0 && color_bg != 7); - if (color_fg == 8 + if (color_fg == MDA_COLOR_GREY && special_treatment) - color_fg = 15; + color_fg = MDA_COLOR_BRIGHT_WHITE; if (color_fg == 0 && special_treatment) - color_fg = 8; + color_fg = MDA_COLOR_GREY; // gray is black - if (color_fg == 8 - && (color_bg == 8 || color_bg == 0)) - color_fg = 0; + if (color_fg == MDA_COLOR_GREY + && (color_bg == MDA_COLOR_GREY || color_bg == MDA_COLOR_BLACK)) + color_fg = MDA_COLOR_BLACK; } if (mda->scanline == 12