From 614e6c9d5e5b44c11f11f3432a8f44f1652cdda4 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Tue, 24 Oct 2023 18:34:15 +0300 Subject: [PATCH] MSDOS: implement inverse text attribute --- doc/fixes3-7-0.txt | 1 + sys/msdos/video.c | 19 +++++++++++-------- sys/msdos/vidvesa.c | 12 ++++++++++++ sys/msdos/vidvga.c | 7 +++++++ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index c04beeb23..e1eeb00f9 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -1856,6 +1856,7 @@ macOS: Xcode project was failing to build if the path to the NetHack source MS-DOS: add -DSTATUES_LOOK_LIKE_MONSTERS to Makefile1.cross so the VESA mode can display statue glyphs MS-DOS: sample config file had same MENUCOLOR flaw as Windows (see below) +MS-DOS: implement inverse text attribute Qt: quit if can't load tiles file instead of continuing and then segfaulting Qt: [later] tiles load failure at startup now continues using an ascii map Qt: use more columns for extended command selection dialog so that the number diff --git a/sys/msdos/video.c b/sys/msdos/video.c index 86b49c96c..c23445f87 100644 --- a/sys/msdos/video.c +++ b/sys/msdos/video.c @@ -128,6 +128,7 @@ int savevmode; /* store the original video mode in here */ int curcol, currow; /* graphics mode current cursor locations */ int g_attribute; /* Current attribute to use */ int monoflag; /* 0 = not monochrome, else monochrome */ +int inversed; int attrib_text_normal; /* text mode normal attribute */ int attrib_gr_normal; /* graphics mode normal attribute */ int attrib_text_intense; /* text mode intense attribute */ @@ -296,10 +297,12 @@ void term_end_attr(int attr) { switch (attr) { + case ATR_INVERSE: + inversed = 0; + /*FALLTHRU*/ case ATR_ULINE: case ATR_BOLD: case ATR_BLINK: - case ATR_INVERSE: default: g_attribute = iflags.grmode ? attrib_gr_normal : attrib_text_normal; } @@ -343,13 +346,8 @@ term_start_attr(int attr) } break; case ATR_INVERSE: - if (monoflag) { - g_attribute = ATTRIB_MONO_REVERSE; - } else { - g_attribute = - iflags.grmode ? attrib_gr_intense : attrib_text_intense; - } - break; + inversed = 1; + /*FALLTHRU*/ default: g_attribute = iflags.grmode ? attrib_gr_normal : attrib_text_normal; break; @@ -477,6 +475,8 @@ tty_startup(int *wid, int *hgt) #else monoflag = 0; #endif + + inversed = 0; } void @@ -600,6 +600,9 @@ xputc(int ch) /* write out character (and attribute) */ } if (!iflags.grmode) { + if (inversed) { + attribute = (g_attribute % 8) << 4; + } txt_xputc(ch, attribute); #ifdef SCREEN_VGA } else if (iflags.usevga) { diff --git a/sys/msdos/vidvesa.c b/sys/msdos/vidvesa.c index 81f1bc167..a6afbc80f 100644 --- a/sys/msdos/vidvesa.c +++ b/sys/msdos/vidvesa.c @@ -24,6 +24,7 @@ extern int total_tiles_used, Tile_corr, Tile_unexplored; /* from tile.c */ struct VesaCharacter { uint32 colour, bgcolour; uint32 chr; + char inverse; }; static unsigned long vesa_SetWindow(int window, unsigned long offset); @@ -69,6 +70,7 @@ extern int clipx, clipxmax; /* current clipping column from wintty.c */ extern int clipy, clipymax; /* current clipping row from wintty.c */ extern int curcol, currow; /* current column and row */ extern int g_attribute; +extern int inversed; extern int attrib_text_normal; /* text mode normal attribute */ extern int attrib_gr_normal; /* graphics mode normal attribute */ extern int attrib_gr_intense; /* graphics mode intense attribute */ @@ -1603,6 +1605,7 @@ vesa_WriteCharXY(uint32 chr, int pixx, int pixy, uint32 colour) } chr_cache_lastx = pixx; chr_cache[chr_cache_size].chr = chr; + chr_cache[chr_cache_size].inverse = inversed; chr_cache[chr_cache_size].colour = colour; chr_cache[chr_cache_size].bgcolour = BACKGROUND_VESA_COLOR; ++chr_cache_size; @@ -1694,6 +1697,15 @@ vesa_WriteTextRow(int pixx, int pixy, struct VesaCharacter const *t_row, fg[2] = (pix >> 16) & 0xFF; fg[3] = (pix >> 24) & 0xFF; } + + if (t_row[i].inverse) { + unsigned char tmpx[4]; + tmpx[0] = bg[0]; bg[0] = fg[0]; fg[0] = tmpx[0]; + tmpx[1] = bg[1]; bg[1] = fg[1]; fg[1] = tmpx[1]; + tmpx[2] = bg[2]; bg[2] = fg[2]; fg[2] = tmpx[2]; + tmpx[3] = bg[3]; bg[3] = fg[3]; fg[3] = tmpx[3]; + } + /* Third loop: draw eight pixels */ for (px = 0; px < (int) vesa_char_width; px += 8) { /* Fourth loop: draw one pixel */ diff --git a/sys/msdos/vidvga.c b/sys/msdos/vidvga.c index aa287e83e..c5e887703 100644 --- a/sys/msdos/vidvga.c +++ b/sys/msdos/vidvga.c @@ -138,6 +138,7 @@ extern boolean clipping; /* clipping on? from wintty.c */ extern int savevmode; /* store the original video mode */ extern int curcol, currow; /* current column and row */ extern int g_attribute; +extern int inversed; extern int attrib_text_normal; /* text mode normal attribute */ extern int attrib_gr_normal; /* graphics mode normal attribute */ extern int attrib_text_intense; /* text mode intense attribute */ @@ -965,6 +966,12 @@ vga_WriteChar(uint32 chr, int col, int row, int colour) else bgcolor = BACKGROUND_VGA_COLOR; + if (inversed) { + int tmpc = actual_colour; + actual_colour = bgcolor; + bgcolor = tmpc; + } + x = min(col, (CO - 1)); /* min() used protection from callers */ pixy = min(row, (LI - 1)) * 16; /* assumes 8 x 16 char set */ vplane = ~actual_colour & ~bgcolor & 0xF;