From 92be9c98dfe127aa24d55dcd13513ffe9b2ed3c4 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sun, 19 Feb 2017 16:36:43 +0100 Subject: [PATCH] Added ability to choose monochrome displays (green, amber, and gray) for CGA MDA, and Hercules graphics cards, based on VileRancour's DOSBox patch. --- src/vid_cga.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ src/vid_hercules.c | 47 ++++++++++++++++++++++++++++++++++++++++++ src/vid_mda.c | 47 ++++++++++++++++++++++++++++++++++++++++++ src/video.c | 10 +++++++++ src/video.h | 2 ++ src/win-cgapal.h | 4 ++++ src/win-d3d-fs.cc | 45 +++++++++++++++++++++++++++++++++++++--- src/win-d3d.cc | 27 ++---------------------- src/win-ddraw-fs.cc | 27 ++---------------------- src/win-ddraw.cc | 27 ++---------------------- 10 files changed, 208 insertions(+), 78 deletions(-) create mode 100644 src/win-cgapal.h diff --git a/src/vid_cga.c b/src/vid_cga.c index 6b69e7aca..608599e29 100644 --- a/src/vid_cga.c +++ b/src/vid_cga.c @@ -12,6 +12,9 @@ #include "video.h" #include "vid_cga.h" #include "dosbox/vid_cga_comp.h" +#ifndef __unix +#include "win-cgapal.h" +#endif #define CGA_RGB 0 #define CGA_COMPOSITE 1 @@ -461,6 +464,11 @@ void *cga_standalone_init() io_sethandler(0x03d0, 0x0010, cga_in, NULL, NULL, cga_out, NULL, NULL, cga); overscan_x = overscan_y = 16; + +#ifndef __unix + cga_palette = device_get_config_int("rgb_type"); + rebuild_cgapal(); +#endif return cga; } @@ -522,6 +530,48 @@ static device_config_t cga_config[] = }, .default_int = COMPOSITE_OLD }, +#ifndef __unix + { + .name = "rgb_type", + .description = "RGB type", + .type = CONFIG_SELECTION, + .selection = + { + { + .description = "Full 16-color", + .value = 0 + }, + { + .description = "Green, 4-color", + .value = 1 + }, + { + .description = "Green, 16-color", + .value = 2 + }, + { + .description = "Amber, 4-color", + .value = 3 + }, + { + .description = "Amber, 16-color", + .value = 4 + }, + { + .description = "Gray, 4-color", + .value = 5 + }, + { + .description = "Gray, 16-color", + .value = 6 + }, + { + .description = "" + } + }, + .default_int = 0 + }, +#endif { .name = "snow_enabled", .description = "Snow emulation", diff --git a/src/vid_hercules.c b/src/vid_hercules.c index 9c24d8de5..8ea99e868 100644 --- a/src/vid_hercules.c +++ b/src/vid_hercules.c @@ -9,6 +9,9 @@ #include "timer.h" #include "video.h" #include "vid_hercules.h" +#ifndef __unix +#include "win-cgapal.h" +#endif typedef struct hercules_t { @@ -342,6 +345,11 @@ void *hercules_init() overscan_x = overscan_y = 0; +#ifndef __unix + cga_palette = device_get_config_int("rgb_type"); + rebuild_cgapal(); +#endif + return hercules; } @@ -360,6 +368,40 @@ void hercules_speed_changed(void *p) hercules_recalctimings(hercules); } +#ifndef __unix +static device_config_t hercules_config[] = +{ + { + .name = "rgb_type", + .description = "Display type", + .type = CONFIG_SELECTION, + .selection = + { + { + .description = "Default 4-color", + .value = 0 + }, + { + .description = "Green, 4-color", + .value = 1 + }, + { + .description = "Amber, 4-color", + .value = 3 + }, + { + .description = "Gray, 4-color", + .value = 5 + }, + { + .description = "" + } + }, + .default_int = 0 + } +}; +#endif + device_t hercules_device = { "Hercules", @@ -369,5 +411,10 @@ device_t hercules_device = NULL, hercules_speed_changed, NULL, +#ifdef __unix NULL +#else + NULL, + hercules_config +#endif }; diff --git a/src/vid_mda.c b/src/vid_mda.c index 41461331a..3c3015d07 100644 --- a/src/vid_mda.c +++ b/src/vid_mda.c @@ -10,6 +10,9 @@ #include "timer.h" #include "video.h" #include "vid_mda.h" +#ifndef __unix +#include "win-cgapal.h" +#endif typedef struct mda_t { @@ -298,6 +301,11 @@ void *mda_init() overscan_x = overscan_y = 0; +#ifndef __unix + cga_palette = device_get_config_int("rgb_type"); + rebuild_cgapal(); +#endif + return mda; } @@ -316,6 +324,40 @@ void mda_speed_changed(void *p) mda_recalctimings(mda); } +#ifndef __unix +static mda_config_t hercules_config[] = +{ + { + .name = "rgb_type", + .description = "Display type", + .type = CONFIG_SELECTION, + .selection = + { + { + .description = "Default 4-color", + .value = 0 + }, + { + .description = "Green, 4-color", + .value = 1 + }, + { + .description = "Amber, 4-color", + .value = 3 + }, + { + .description = "Gray, 4-color", + .value = 5 + }, + { + .description = "" + } + }, + .default_int = 0 + } +}; +#endif + device_t mda_device = { "MDA", @@ -325,5 +367,10 @@ device_t mda_device = NULL, mda_speed_changed, NULL, +#ifdef __unix NULL +#else + NULL, + mda_config +#endif }; diff --git a/src/video.c b/src/video.c index 6e86633ca..ee3bdf0d9 100644 --- a/src/video.c +++ b/src/video.c @@ -16,6 +16,9 @@ #include "rom.h" #include "thread.h" #include "timer.h" +#ifndef __unix +#include "win-cgapal.h" +#endif #include "vid_ati18800.h" #include "vid_ati28800.h" @@ -49,6 +52,8 @@ #include "vid_vga.h" #include "vid_wy700.h" +int cga_palette = 0; + typedef struct { char name[64]; @@ -255,6 +260,11 @@ void video_init() { pclog("Video_init %i %i\n",romset,gfxcard); +#ifndef __unix + cga_palette = 0; + cgapal_rebuild(); +#endif + switch (romset) { case ROM_IBMPCJR: diff --git a/src/video.h b/src/video.h index dc9f24eba..effcfb7e3 100644 --- a/src/video.h +++ b/src/video.h @@ -108,3 +108,5 @@ void ddraw_fs_take_screenshot(char *fn); #ifdef __cplusplus } #endif + +extern int cga_palette; diff --git a/src/win-cgapal.h b/src/win-cgapal.h new file mode 100644 index 000000000..d824c8929 --- /dev/null +++ b/src/win-cgapal.h @@ -0,0 +1,4 @@ +extern PALETTE cgapal; +extern PALETTE cgapal_mono[6]; + +void cgapal_rebuild(); diff --git a/src/win-d3d-fs.cc b/src/win-d3d-fs.cc index ad3b2d4a5..6e86d4949 100644 --- a/src/win-d3d-fs.cc +++ b/src/win-d3d-fs.cc @@ -12,6 +12,7 @@ #include "video.h" #include "win-d3d-fs.h" #include "win.h" +#include "win-cgapal.h" extern "C" void fatal(const char *format, ...); extern "C" void pclog(const char *format, ...); @@ -42,7 +43,7 @@ struct CUSTOMVERTEX FLOAT tu, tv; }; -static PALETTE cgapal= +PALETTE cgapal = { {0,0,0},{0,42,0},{42,0,0},{42,21,0}, {0,0,0},{0,42,42},{42,0,42},{42,42,42}, @@ -65,6 +66,34 @@ static PALETTE cgapal= {0,0,0},{0,63,63},{63,0,0},{63,63,63}, }; +PALETTE cgapal_mono[6] = +{ + { // 0 - green, 4-color-optimized contrast + {0x00,0x00,0x00},{0x00,0x0d,0x03},{0x01,0x17,0x05},{0x01,0x1a,0x06},{0x02,0x28,0x09},{0x02,0x2c,0x0a},{0x03,0x39,0x0d},{0x03,0x3c,0x0e}, + {0x00,0x07,0x01},{0x01,0x13,0x04},{0x01,0x1f,0x07},{0x01,0x23,0x08},{0x02,0x31,0x0b},{0x02,0x35,0x0c},{0x05,0x3f,0x11},{0x0d,0x3f,0x17}, + }, + { // 1 - green, 16-color-optimized contrast + {0x00,0x00,0x00},{0x00,0x0d,0x03},{0x01,0x15,0x05},{0x01,0x17,0x05},{0x01,0x21,0x08},{0x01,0x24,0x08},{0x02,0x2e,0x0b},{0x02,0x31,0x0b}, + {0x01,0x22,0x08},{0x02,0x28,0x09},{0x02,0x30,0x0b},{0x02,0x32,0x0c},{0x03,0x39,0x0d},{0x03,0x3b,0x0e},{0x09,0x3f,0x14},{0x0d,0x3f,0x17}, + }, + { // 2 - amber, 4-color-optimized contrast + {0x00,0x00,0x00},{0x15,0x05,0x00},{0x20,0x0b,0x00},{0x24,0x0d,0x00},{0x33,0x18,0x00},{0x37,0x1b,0x00},{0x3f,0x26,0x01},{0x3f,0x2b,0x06}, + {0x0b,0x02,0x00},{0x1b,0x08,0x00},{0x29,0x11,0x00},{0x2e,0x14,0x00},{0x3b,0x1e,0x00},{0x3e,0x21,0x00},{0x3f,0x32,0x0a},{0x3f,0x38,0x0d}, + }, + { // 3 - amber, 16-color-optimized contrast + {0x00,0x00,0x00},{0x15,0x05,0x00},{0x1e,0x09,0x00},{0x21,0x0b,0x00},{0x2b,0x12,0x00},{0x2f,0x15,0x00},{0x38,0x1c,0x00},{0x3b,0x1e,0x00}, + {0x2c,0x13,0x00},{0x32,0x17,0x00},{0x3a,0x1e,0x00},{0x3c,0x1f,0x00},{0x3f,0x27,0x01},{0x3f,0x2a,0x04},{0x3f,0x36,0x0c},{0x3f,0x38,0x0d}, + }, + { // 4 - grey, 4-color-optimized contrast + {0x00,0x00,0x00},{0x0d,0x0d,0x0d},{0x15,0x15,0x15},{0x18,0x18,0x18},{0x24,0x24,0x24},{0x27,0x27,0x27},{0x33,0x33,0x33},{0x37,0x37,0x37}, + {0x08,0x08,0x08},{0x10,0x10,0x10},{0x1c,0x1c,0x1c},{0x20,0x20,0x20},{0x2c,0x2c,0x2c},{0x2f,0x2f,0x2f},{0x3b,0x3b,0x3b},{0x3f,0x3f,0x3f}, + }, + { // 5 - grey, 16-color-optimized contrast + {0x00,0x00,0x00},{0x0d,0x0d,0x0d},{0x12,0x12,0x12},{0x15,0x15,0x15},{0x1e,0x1e,0x1e},{0x20,0x20,0x20},{0x29,0x29,0x29},{0x2c,0x2c,0x2c}, + {0x1f,0x1f,0x1f},{0x23,0x23,0x23},{0x2b,0x2b,0x2b},{0x2d,0x2d,0x2d},{0x34,0x34,0x34},{0x36,0x36,0x36},{0x3d,0x3d,0x3d},{0x3f,0x3f,0x3f}, + }, +}; + static uint32_t pal_lookup[256]; static CUSTOMVERTEX d3d_verts[] = @@ -77,6 +106,17 @@ static CUSTOMVERTEX d3d_verts[] = {2048.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f}, {2048.0f, 2048.0f, 1.0f, 1.0f, 1.0f, 1.0f}, }; + +void cgapal_rebuild() +{ + for (c = 0; c < 256; c++) + pal_lookup[c] = makecol(cgapal[c].r << 2, cgapal[c].g << 2, cgapal[c].b << 2); + if (cga_palette > 1) + { + for (c = 0; c < 16; c++) + pal_lookup[c + 16] = makecol(cgapal_mono[cga_palette - 1][c].r, cgapal_mono[cga_palette - 1][c].g, cgapal_mono[cga_palette - 1][c].b); + } +} void d3d_fs_init(HWND h) { @@ -87,8 +127,7 @@ void d3d_fs_init(HWND h) d3d_fs_w = GetSystemMetrics(SM_CXSCREEN); d3d_fs_h = GetSystemMetrics(SM_CYSCREEN); - for (c = 0; c < 256; c++) - pal_lookup[c] = makecol(cgapal[c].r << 2, cgapal[c].g << 2, cgapal[c].b << 2); + cgapal_rebuild(); d3d_hwnd = h; diff --git a/src/win-d3d.cc b/src/win-d3d.cc index 30eedfdef..46a86ca56 100644 --- a/src/win-d3d.cc +++ b/src/win-d3d.cc @@ -9,6 +9,7 @@ #include "resources.h" #include "win-d3d.h" #include "video.h" +#include "win-cgapal.h" extern "C" void fatal(const char *format, ...); extern "C" void pclog(const char *format, ...); @@ -35,29 +36,6 @@ struct CUSTOMVERTEX FLOAT tu, tv; }; -static PALETTE cgapal= -{ - {0,0,0},{0,42,0},{42,0,0},{42,21,0}, - {0,0,0},{0,42,42},{42,0,42},{42,42,42}, - {0,0,0},{21,63,21},{63,21,21},{63,63,21}, - {0,0,0},{21,63,63},{63,21,63},{63,63,63}, - - {0,0,0},{0,0,42},{0,42,0},{0,42,42}, - {42,0,0},{42,0,42},{42,21,00},{42,42,42}, - {21,21,21},{21,21,63},{21,63,21},{21,63,63}, - {63,21,21},{63,21,63},{63,63,21},{63,63,63}, - - {0,0,0},{0,21,0},{0,0,42},{0,42,42}, - {42,0,21},{21,10,21},{42,0,42},{42,0,63}, - {21,21,21},{21,63,21},{42,21,42},{21,63,63}, - {63,0,0},{42,42,0},{63,21,42},{41,41,41}, - - {0,0,0},{0,42,42},{42,0,0},{42,42,42}, - {0,0,0},{0,42,42},{42,0,0},{42,42,42}, - {0,0,0},{0,63,63},{63,0,0},{63,63,63}, - {0,0,0},{0,63,63},{63,0,0},{63,63,63}, -}; - static uint32_t pal_lookup[256]; static CUSTOMVERTEX d3d_verts[] = @@ -76,8 +54,7 @@ void d3d_init(HWND h) int c; HRESULT hr; - for (c = 0; c < 256; c++) - pal_lookup[c] = makecol(cgapal[c].r << 2, cgapal[c].g << 2, cgapal[c].b << 2); + cgapal_rebuild(); d3d_hwnd = h; diff --git a/src/win-ddraw-fs.cc b/src/win-ddraw-fs.cc index a32f5d105..fdb31313a 100644 --- a/src/win-ddraw-fs.cc +++ b/src/win-ddraw-fs.cc @@ -8,6 +8,7 @@ #include "win-ddraw-fs.h" #include "win-ddraw-screenshot.h" #include "video.h" +#include "win-cgapal.h" extern "C" void fatal(const char *format, ...); extern "C" void pclog(const char *format, ...); @@ -33,29 +34,6 @@ static DDSURFACEDESC2 ddsd; static HWND ddraw_hwnd; static int ddraw_w, ddraw_h; -static PALETTE cgapal = -{ - {0,0,0},{0,42,0},{42,0,0},{42,21,0}, - {0,0,0},{0,42,42},{42,0,42},{42,42,42}, - {0,0,0},{21,63,21},{63,21,21},{63,63,21}, - {0,0,0},{21,63,63},{63,21,63},{63,63,63}, - - {0,0,0},{0,0,42},{0,42,0},{0,42,42}, - {42,0,0},{42,0,42},{42,21,00},{42,42,42}, - {21,21,21},{21,21,63},{21,63,21},{21,63,63}, - {63,21,21},{63,21,63},{63,63,21},{63,63,63}, - - {0,0,0},{0,21,0},{0,0,42},{0,42,42}, - {42,0,21},{21,10,21},{42,0,42},{42,0,63}, - {21,21,21},{21,63,21},{42,21,42},{21,63,63}, - {63,0,0},{42,42,0},{63,21,42},{41,41,41}, - - {0,0,0},{0,42,42},{42,0,0},{42,42,42}, - {0,0,0},{0,42,42},{42,0,0},{42,42,42}, - {0,0,0},{0,63,63},{63,0,0},{63,63,63}, - {0,0,0},{0,63,63},{63,0,0},{63,63,63}, -}; - static uint32_t pal_lookup[256]; void ddraw_fs_init(HWND h) @@ -65,8 +43,7 @@ void ddraw_fs_init(HWND h) ddraw_w = GetSystemMetrics(SM_CXSCREEN); ddraw_h = GetSystemMetrics(SM_CYSCREEN); - for (c = 0; c < 256; c++) - pal_lookup[c] = makecol(cgapal[c].r << 2, cgapal[c].g << 2, cgapal[c].b << 2); + cgapal_rebuild(); if (FAILED(DirectDrawCreate(NULL, &lpdd, NULL))) fatal("DirectDrawCreate failed\n"); diff --git a/src/win-ddraw.cc b/src/win-ddraw.cc index be2291900..44cd43209 100644 --- a/src/win-ddraw.cc +++ b/src/win-ddraw.cc @@ -9,6 +9,7 @@ #include "win-ddraw.h" #include "win-ddraw-screenshot.h" #include "video.h" +#include "win-cgapal.h" extern "C" void fatal(const char *format, ...); extern "C" void pclog(const char *format, ...); @@ -33,37 +34,13 @@ static DDSURFACEDESC2 ddsd; static HWND ddraw_hwnd; -static PALETTE cgapal= -{ - {0,0,0},{0,42,0},{42,0,0},{42,21,0}, - {0,0,0},{0,42,42},{42,0,42},{42,42,42}, - {0,0,0},{21,63,21},{63,21,21},{63,63,21}, - {0,0,0},{21,63,63},{63,21,63},{63,63,63}, - - {0,0,0},{0,0,42},{0,42,0},{0,42,42}, - {42,0,0},{42,0,42},{42,21,00},{42,42,42}, - {21,21,21},{21,21,63},{21,63,21},{21,63,63}, - {63,21,21},{63,21,63},{63,63,21},{63,63,63}, - - {0,0,0},{0,21,0},{0,0,42},{0,42,42}, - {42,0,21},{21,10,21},{42,0,42},{42,0,63}, - {21,21,21},{21,63,21},{42,21,42},{21,63,63}, - {63,0,0},{42,42,0},{63,21,42},{41,41,41}, - - {0,0,0},{0,42,42},{42,0,0},{42,42,42}, - {0,0,0},{0,42,42},{42,0,0},{42,42,42}, - {0,0,0},{0,63,63},{63,0,0},{63,63,63}, - {0,0,0},{0,63,63},{63,0,0},{63,63,63}, -}; - static uint32_t pal_lookup[256]; void ddraw_init(HWND h) { int c; - for (c = 0; c < 256; c++) - pal_lookup[c] = makecol(cgapal[c].r << 2, cgapal[c].g << 2, cgapal[c].b << 2); + cgapal_rebuild(); if (FAILED(DirectDrawCreate(NULL, &lpdd, NULL))) fatal("DirectDrawCreate failed\n");