From c00c432398dd2d1a7f0c2bfe20a5f9756867e894 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 29 Mar 2025 00:10:39 +0100 Subject: [PATCH] EGA: Fix colors in mono mode and attribute registers, fixes #5395. --- src/video/vid_ega.c | 11 +++++++---- src/video/vid_ega_render.c | 10 +++++++--- src/video/vid_jega.c | 15 ++++++++------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/video/vid_ega.c b/src/video/vid_ega.c index 17b3fb593..f002ef999 100644 --- a/src/video/vid_ega.c +++ b/src/video/vid_ega.c @@ -112,10 +112,13 @@ ega_out(uint16_t addr, uint8_t val, void *priv) ega->fullchange = changeframecount; if (ega->attraddr == 0x10 || ega->attraddr == 0x14 || ega->attraddr < 0x10) { for (uint8_t c = 0; c < 16; c++) { - if (ega->attrregs[0x10] & 0x80) - ega->egapal[c] = (ega->attrregs[c] & 0xf) | ((ega->attrregs[0x14] & 0xf) << 4); - else - ega->egapal[c] = (ega->attrregs[c] & 0x3f) | ((ega->attrregs[0x14] & 0xc) << 4); + if (ega->chipset) { + if (ega->attrregs[0x10] & 0x80) + ega->egapal[c] = (ega->attrregs[c] & 0xf) | ((ega->attrregs[0x14] & 0xf) << 4); + else + ega->egapal[c] = (ega->attrregs[c] & 0x3f) | ((ega->attrregs[0x14] & 0xc) << 4); + } else + ega->egapal[c] = ega->attrregs[c] & 0x3f; } ega->fullchange = changeframecount; } diff --git a/src/video/vid_ega_render.c b/src/video/vid_ega_render.c index 261474742..10667084a 100644 --- a/src/video/vid_ega_render.c +++ b/src/video/vid_ega_render.c @@ -172,15 +172,19 @@ ega_render_text(ega_t *ega) uint32_t dat = ega->vram[charaddr + (ega->sc << 2)]; dat <<= 1; - if ((chr & ~0x1F) == 0xC0 && attrlinechars) + if (((chr & ~0x1f) == 0xc0) && attrlinechars) dat |= (dat >> 1) & 1; for (int xx = 0; xx < charwidth; xx++) { if (monoattrs) { + int bit = (dat & (0x100 >> (xx >> dwshift))) ? 1 : 0; + int blink = (!drawcursor && (attr & 0x80) && attrblink && blinked); if ((ega->sc == ega->crtc[0x14]) && ((attr & 7) == 1)) - p[xx] = ega->mdacols[attr][attrblink][1]; + p[xx] = ega->mdacols[attr][blink][1]; else - p[xx] = ega->mdacols[attr][attrblink][dat & (0x100 >> (xx >> dwshift))]; + p[xx] = ega->mdacols[attr][blink][bit]; + if (drawcursor) + p[xx] ^= ega->mdacols[attr][0][1]; p[xx] = ega->pallook[ega->egapal[p[xx] & 0x0f]]; } else p[xx] = (dat & (0x100 >> (xx >> dwshift))) ? fg : bg; diff --git a/src/video/vid_jega.c b/src/video/vid_jega.c index 3d1cfe476..11c9cbf8d 100644 --- a/src/video/vid_jega.c +++ b/src/video/vid_jega.c @@ -430,14 +430,15 @@ jega_out(uint16_t addr, uint8_t val, void *priv) jega->attrregs[jega->attraddr & 31] = val; if (jega->attraddr < 0x10) { for (uint8_t c = 0; c < 16; c++) { - if (!jega->is_vga) + if (jega->is_vga) { + if (jega->attrregs[0x10] & 0x80) + jega->egapal[c] = (jega->attrregs[c] & 0xf) | ((jega->attrregs[0x14] & 0xf) << 4); + else if (jega->vga.svga.ati_4color) + jega->egapal[c] = pal4to16[(c & 0x03) | ((val >> 2) & 0xc)]; + else + jega->egapal[c] = (jega->attrregs[c] & 0x3f) | ((jega->attrregs[0x14] & 0xc) << 4); + } else jega->egapal[c] = jega->attrregs[c] & 0x3f; - else if (jega->attrregs[0x10] & 0x80) - jega->egapal[c] = (jega->attrregs[c] & 0xf) | ((jega->attrregs[0x14] & 0xf) << 4); - else if (jega->vga.svga.ati_4color) - jega->egapal[c] = pal4to16[(c & 0x03) | ((val >> 2) & 0xc)]; - else - jega->egapal[c] = (jega->attrregs[c] & 0x3f) | ((jega->attrregs[0x14] & 0xc) << 4); } if (jega->is_vga) jega->vga.svga.fullchange = changeframecount;