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;