From 0e19e52572b70d48f056f490de48ecfa000b7c52 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Sun, 5 Jan 2020 12:05:42 +0100 Subject: [PATCH] [Maintenance] Templatize RGB and palette types for 4- and 8-bit components MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Right, PC-98 hardware only supports 4 bits per RGB component, for a total of 4,096 possible colors. The 8-bit RGB color values we've been seeing throughout the later games are a master.lib extension, to allow for more toning precision. Which TH01, with all its NIH syndrome, doesn't use. And yup, that means templates in the most basic header files… Since that would have meant renaming *everything* to compile as C++, I simply made these types exclusive to C++ code, thcrap style. Part of P0066, funded by Keyblade Wiedling Neko and Splashman. --- ReC98.h | 17 ++++++----------- pc98.h | 26 ++++++++++++++++++++++++++ pc98.inc | 1 + th03/main_01.cpp | 1 + th04/zunsoft.h | 2 +- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/ReC98.h b/ReC98.h index f8b46504..4578d984 100644 --- a/ReC98.h +++ b/ReC98.h @@ -14,17 +14,12 @@ palette_entry_rgb(fn); \ palette_show(); -// RGB color triple, used for the Palettes structure -typedef union { - struct { - unsigned char r, g, b; - } c; - unsigned char v[3]; -} rgb_t; - -typedef struct { - rgb_t colors[16]; -} palette_t; +#ifdef __cplusplus + // master.lib palettes use twice the bits per RGB component for more + // toning precision + typedef RGB RGB8; + typedef Palette Palette8; +#endif // --------------------- // Macros diff --git a/pc98.h b/pc98.h index a82049a0..8894aa93 100644 --- a/pc98.h +++ b/pc98.h @@ -15,6 +15,32 @@ #define RES_Y 400 #define ROW_SIZE (RES_X / 8) #define PLANE_SIZE (ROW_SIZE * RES_Y) + +#define COLOR_COUNT 16 + +#pragma option -a1 + +#ifdef __cplusplus + template union RGB { + struct { + ComponentType r, g, b; + } c; + ComponentType v[3]; + }; + + template struct Palette { + RGBType colors[COLOR_COUNT]; + }; + + // The 16-color mode supports 4 bits per RGB component, for a total of + // 4,096 colors + typedef int8_t uint4_t; + + typedef RGB RGB4; + typedef Palette Palette4; +#endif + +#pragma option -a. /// -------- /// Keyboard diff --git a/pc98.inc b/pc98.inc index b1eee647..55d49dfb 100644 --- a/pc98.inc +++ b/pc98.inc @@ -16,4 +16,5 @@ RES_Y = 400 ROW_SIZE = (RES_X / 8) ; Collides with master.lib's bfnt_entry_pat.asm ; PLANE_SIZE = (ROW_SIZE * RES_Y) +COLOR_COUNT = 16 ; ======== diff --git a/th03/main_01.cpp b/th03/main_01.cpp index 095a26f3..7833628a 100644 --- a/th03/main_01.cpp +++ b/th03/main_01.cpp @@ -5,6 +5,7 @@ extern "C" { +#include "platform.h" #include "pc98.h" #include "th03/sprite16.hpp" #include "th03/playfld.hpp" diff --git a/th04/zunsoft.h b/th04/zunsoft.h index 02463fd6..128f798c 100644 --- a/th04/zunsoft.h +++ b/th04/zunsoft.h @@ -1,7 +1,7 @@ // Copy of the palette used during the logo, to allow non-blocking fades in // contrast to master.lib's blocking palette_black_in() and palette_black_out() // functions. (Then again, master.lib has the PaletteTone global for that...) -extern rgb_t zunsoft_palette[16]; +extern Palette8 zunsoft_palette; // Spawns [n] new explosions at the given screen-coordinate [origin] position. void pascal zunsoft_pyro_new(Point screen_origin, int n, char patnum_base);