From 3229b2285d300756ce4070850606ea6429b76cc5 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Sun, 1 Mar 2020 12:24:18 +0100 Subject: [PATCH] [Decompilation] Encode the per-component range in the RGB color template Allowing us to then retrieve it using a function call with no run-time cost, although we do have to be careful with the types here. Also, is that another solution to decompilation puzzles that involve types of number literals? Part of P0080, funded by Ember2528 and Splashman. --- ReC98.h | 2 +- pc98.h | 17 +++++++++++++++-- th01/hardware/graph.cpp | 6 +++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ReC98.h b/ReC98.h index 8e426140..447860d1 100644 --- a/ReC98.h +++ b/ReC98.h @@ -17,7 +17,7 @@ #ifdef __cplusplus // master.lib palettes use twice the bits per RGB component for more // toning precision - typedef RGB RGB8; + typedef RGB RGB8; typedef Palette Palette8; #endif // --------------------- diff --git a/pc98.h b/pc98.h index 94d189cc..63ba7b78 100644 --- a/pc98.h +++ b/pc98.h @@ -25,16 +25,29 @@ typedef bool page_t; #pragma option -a1 #ifdef __cplusplus - template union RGB { + template union RGB { struct { ComponentType r, g, b; } c; ComponentType v[3]; + + // Yes, we actually need this function in certain cases where code + // generation calls for a 0 in the ComponentType. + static ComponentType min() { + return 0; + } + static ComponentType max() { + return (Range - 1); + } }; template struct Palette { RGBType colors[COLOR_COUNT]; + static int range() { + return RGBType::Range; + } + RGBType& operator [](int col) { return colors[col]; } @@ -44,7 +57,7 @@ typedef bool page_t; // 4,096 colors typedef int8_t uint4_t; - typedef RGB RGB4; + typedef RGB RGB4; typedef Palette Palette4; #endif diff --git a/th01/hardware/graph.cpp b/th01/hardware/graph.cpp index d3b69794..bd1d79e6 100644 --- a/th01/hardware/graph.cpp +++ b/th01/hardware/graph.cpp @@ -547,7 +547,7 @@ void z_palette_fade_from( unsigned int step_ms ) { - RGB4 fadepal[COLOR_COUNT]; + Palette4 fadepal; int i; int col; int comp; @@ -564,12 +564,12 @@ void z_palette_fade_from( fadepal[i].c.b = z_Palettes[i].c.b; } } - for(i = 0; i < 16; i++) { + for(i = 0; i < fadepal.range(); i++) { z_vsync_wait(); for(col = 0; col < COLOR_COUNT; col++) { for(comp = 0; comp < sizeof(RGB4); comp++) { if(fadepal[col].v[comp] != z_Palettes[col].v[comp]) { - fadepal[col].v[comp] += + fadepal.colors[col].v[comp] += (fadepal[col].v[comp] < z_Palettes[col].v[comp]) ? 1 : -1;