diff --git a/pc98.h b/pc98.h index 1bd1f52f..884d75a5 100644 --- a/pc98.h +++ b/pc98.h @@ -117,6 +117,25 @@ typedef int8_t uint4_t; typedef RGB RGB4; typedef Palette Palette4; + + #define palette_foreach(tmp_col, tmp_comp, func) { \ + for(tmp_col = 0; tmp_col < COLOR_COUNT; tmp_col++) { \ + for(tmp_comp = 0; tmp_comp < COMPONENT_COUNT; tmp_comp++) { \ + func \ + } \ + } \ + } + + // Sets all components of all colors to the given grayscale [value]. + #define palette_set_grayscale(dst, value, tmp_col, tmp_comp) \ + palette_foreach(tmp_col, tmp_comp, { \ + dst[tmp_col].v[tmp_comp] = value; \ + }) + + #define palette_copy(dst, src, tmp_col, tmp_comp) \ + palette_foreach(tmp_col, tmp_comp, { \ + dst[col].v[comp] = src[col].v[comp]; \ + }) #endif /// -------- diff --git a/th01/formats/grp.cpp b/th01/formats/grp.cpp index 59b58cf1..6ce8313b 100644 --- a/th01/formats/grp.cpp +++ b/th01/formats/grp.cpp @@ -58,11 +58,9 @@ int getkanji(FILE *fp) void grp_palette_set_all(const Palette4& pal) { - for(int col = 0; col < COLOR_COUNT; col++) { - for(int comp = 0; comp < COMPONENT_COUNT; comp++) { - grp_palette[col].v[comp] = pal[col].v[comp]; - } - } + int col; + int comp; + palette_copy(grp_palette, pal, col, comp); } int grp_put_palette_show(const char *fn) diff --git a/th01/hardware/palette.h b/th01/hardware/palette.h index 330e9470..0d733161 100644 --- a/th01/hardware/palette.h +++ b/th01/hardware/palette.h @@ -44,19 +44,16 @@ void z_palette_white_in(void); void z_palette_black_out(void); void z_palette_white_out(void); -#define z_Palettes_set_func_and_show(tmp_col, tmp_comp, func) \ - for(tmp_col = 0; tmp_col < COLOR_COUNT; tmp_col++) { \ - for(tmp_comp = 0; tmp_comp < COMPONENT_COUNT; tmp_comp++) { \ - func \ - } \ - } \ - z_palette_set_all_show(z_Palettes); +#define z_Palettes_set_func_and_show(tmp_col, tmp_comp, func) { \ + palette_foreach(tmp_col, tmp_comp, func); \ + z_palette_set_all_show(z_Palettes); \ +} // Sets all colors in both the hardware palette and z_Palettes to #000. -#define z_palette_set_black(tmp_col, tmp_comp) \ - z_Palettes_set_func_and_show(tmp_col, tmp_comp, { \ - z_Palettes[tmp_col].v[tmp_comp] = 0; \ - }) +#define z_palette_set_black(tmp_col, tmp_comp) { \ + palette_set_grayscale(z_Palettes, 0, tmp_col, tmp_comp); \ + z_palette_set_all_show(z_Palettes); \ +} // Performs a single black-out step. #define z_palette_black_out_step(tmp_col, tmp_comp) \ diff --git a/th01/hardware/ptrans_d.cpp b/th01/hardware/ptrans_d.cpp index 0520bf6a..7f51a964 100644 --- a/th01/hardware/ptrans_d.cpp +++ b/th01/hardware/ptrans_d.cpp @@ -75,17 +75,15 @@ void pagetrans_diagonal_8x8_with_palette( : (tip_top + INTERLEAVE_H); if((frame % (FRAME_COUNT / COLOR_COUNT)) == 0) { - for(col = 0; col < COLOR_COUNT; col++) { - // Not identical to the ramping loop in z_palette_fade_from()! - for(comp = 0; comp < COMPONENT_COUNT; comp++) { - if(pal_cur[col].v[comp] != pal_target[col].v[comp]) { - pal_cur.colors[col].v[comp] += - (pal_cur[col].v[comp] > pal_target[col].v[comp]) - ? -1 - : 1; - } + // Not identical to the ramping loop in z_palette_fade_from()! + palette_foreach(col, comp, { + if(pal_cur[col].v[comp] != pal_target[col].v[comp]) { + pal_cur.colors[col].v[comp] += + (pal_cur[col].v[comp] > pal_target[col].v[comp]) + ? -1 + : 1; } - } + }); z_palette_set_all_show(pal_cur); } diff --git a/th01/main/boss/palette.hpp b/th01/main/boss/palette.hpp index 8ec90706..5b534ba2 100644 --- a/th01/main/boss/palette.hpp +++ b/th01/main/boss/palette.hpp @@ -1,12 +1,11 @@ // The intended palette for a boss, with no effects applied. extern Palette4 boss_palette; -#define boss_palette_snap_inlined() \ - for(int col = 0; col < COLOR_COUNT; col++) { \ - for(int comp = 0; comp < COMPONENT_COUNT; comp++) { \ - boss_palette[col].v[comp] = z_Palettes[col].v[comp]; \ - } \ - } +#define boss_palette_snap_inlined() { \ + int col; \ + int comp; \ + palette_copy(boss_palette, z_Palettes, col, comp); \ +} // Overwrites [boss_palette] with [z_Palettes]. void boss_palette_snap(void); diff --git a/th01/main/stage/palette.cpp b/th01/main/stage/palette.cpp index b9b4b665..28e3a561 100644 --- a/th01/main/stage/palette.cpp +++ b/th01/main/stage/palette.cpp @@ -2,9 +2,7 @@ void stage_palette_set(const Palette4 &pal) { - for(int col = 0; col < COLOR_COUNT; col++) { - for(int comp = 0; comp < COMPONENT_COUNT; comp++) { - stage_palette[col].v[comp] = pal[col].v[comp]; - } - } + int col; + int comp; + palette_copy(stage_palette, pal, col, comp); }