From f2b454dfc61ed5359b4246e6562da0966eedf58d Mon Sep 17 00:00:00 2001 From: nmlgc Date: Tue, 3 Mar 2020 11:45:03 +0100 Subject: [PATCH] [Decompilation] Overload operator[] for palettes Which has no run-time cost in almost all cases. Part of P0080, funded by Ember2528 and Splashman. --- pc98.h | 4 ++++ th01/hardware/graph.cpp | 16 ++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pc98.h b/pc98.h index 028acb67..94d189cc 100644 --- a/pc98.h +++ b/pc98.h @@ -34,6 +34,10 @@ typedef bool page_t; template struct Palette { RGBType colors[COLOR_COUNT]; + + RGBType& operator [](int col) { + return colors[col]; + } }; // The 16-color mode supports 4 bits per RGB component, for a total of diff --git a/th01/hardware/graph.cpp b/th01/hardware/graph.cpp index 977d1e75..d3b69794 100644 --- a/th01/hardware/graph.cpp +++ b/th01/hardware/graph.cpp @@ -559,18 +559,18 @@ void z_palette_fade_from( fadepal[i].c.g = from_g; fadepal[i].c.b = from_b; } else { - fadepal[i].c.r = z_Palettes.colors[i].c.r; - fadepal[i].c.g = z_Palettes.colors[i].c.g; - fadepal[i].c.b = z_Palettes.colors[i].c.b; + fadepal[i].c.r = z_Palettes[i].c.r; + fadepal[i].c.g = z_Palettes[i].c.g; + fadepal[i].c.b = z_Palettes[i].c.b; } } for(i = 0; i < 16; 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.colors[col].v[comp]) { + if(fadepal[col].v[comp] != z_Palettes[col].v[comp]) { fadepal[col].v[comp] += - (fadepal[col].v[comp] < z_Palettes.colors[col].v[comp]) + (fadepal[col].v[comp] < z_Palettes[col].v[comp]) ? 1 : -1; } @@ -717,9 +717,9 @@ int z_respal_set(void) if(respal_seg) { grb_t *respal = respal_seg->pal; for(i = 0; i < COLOR_COUNT; i++) { - respal->g = z_Palettes.colors[i].c.g; - respal->r = z_Palettes.colors[i].c.r; - respal->b = z_Palettes.colors[i].c.b; + respal->g = z_Palettes[i].c.g; + respal->r = z_Palettes[i].c.r; + respal->b = z_Palettes[i].c.b; respal++; } return 0;