diff --git a/ReC98.h b/ReC98.h index 7a7b9c89..24919f3e 100644 --- a/ReC98.h +++ b/ReC98.h @@ -11,29 +11,4 @@ #include "pc98.h" #include "planar.h" -// Macros -// ------ -#ifdef __cplusplus - // This is, in fact, the only way to circumvent 16-bit promotion inside - // comparisons between two 8-bit values in C++. I kid you not. - static inline char ring_min() { - return 0; - } -#else - #define ring_min() 0 -#endif - -#define RING_INC(val, ring_end) \ - (val)++; \ - if((val) > (ring_end)) { \ - (val) = 0; \ - } - -#define RING_DEC(val, ring_end) \ - (val)--; \ - if(val < ring_min()) { \ - (val) = ring_end; \ - } -// ------ - #endif /* REC98_H */ diff --git a/th01/math/clamp.hpp b/th01/math/clamp.hpp index 4fc712ce..7b0d9af4 100644 --- a/th01/math/clamp.hpp +++ b/th01/math/clamp.hpp @@ -18,3 +18,25 @@ if((v) < (min)) { \ (v) = (min); \ } + +#ifdef __cplusplus + // This is, in fact, the only way to circumvent 16-bit promotion inside + // comparisons between two 8-bit values in C++. I kid you not. + static inline char ring_min() { + return 0; + } +#else + #define ring_min() 0 +#endif + +#define ring_inc(val, ring_end) \ + (val)++; \ + if((val) > (ring_end)) { \ + (val) = 0; \ + } + +#define ring_dec(val, ring_end) \ + (val)--; \ + if(val < ring_min()) { \ + (val) = ring_end; \ + } diff --git a/th02/maine_04.cpp b/th02/maine_04.cpp index 4742c22f..4e769d3b 100644 --- a/th02/maine_04.cpp +++ b/th02/maine_04.cpp @@ -193,16 +193,16 @@ void pascal score_enter(void) input_sense(); if(!input_locked) { if(key_det & INPUT_UP) { - alphabet_cursor_move(row, ALPHABET_ROWS, RING_DEC, col, row); + alphabet_cursor_move(row, ALPHABET_ROWS, ring_dec, col, row); } if(key_det & INPUT_DOWN) { - alphabet_cursor_move(row, ALPHABET_ROWS, RING_INC, col, row); + alphabet_cursor_move(row, ALPHABET_ROWS, ring_inc, col, row); } if(key_det & INPUT_LEFT) { - alphabet_cursor_move(col, ALPHABET_COLS, RING_DEC, col, row); + alphabet_cursor_move(col, ALPHABET_COLS, ring_dec, col, row); } if(key_det & INPUT_RIGHT) { - alphabet_cursor_move(col, ALPHABET_COLS, RING_INC, col, row); + alphabet_cursor_move(col, ALPHABET_COLS, ring_inc, col, row); } if(key_det & INPUT_SHOT || key_det & INPUT_OK) { /* Yeah, it sucks that ZUN checks against the indices into the diff --git a/th02/op_01.cpp b/th02/op_01.cpp index cc6f8977..778afa88 100644 --- a/th02/op_01.cpp +++ b/th02/op_01.cpp @@ -10,6 +10,7 @@ extern "C" { #include "th02/resident.hpp" #include "master.hpp" #include "libs/kaja/kaja.h" +#include "th01/math/clamp.hpp" #include "th02/hardware/frmdelay.h" #include "th02/hardware/grp_rect.h" #include "th02/hardware/input.hpp" @@ -585,10 +586,10 @@ void option_update_and_render(void) menu_sel_move(6, 1); } if(key_det & INPUT_RIGHT) { - option_change(RING_INC); + option_change(ring_inc); } if(key_det & INPUT_LEFT) { - option_change(RING_DEC); + option_change(ring_dec); } if(key_det & INPUT_SHOT || key_det & INPUT_OK) { switch(menu_sel) { diff --git a/th02/op_05.cpp b/th02/op_05.cpp index f7760098..f2497a2d 100644 --- a/th02/op_05.cpp +++ b/th02/op_05.cpp @@ -7,6 +7,7 @@ extern "C" { #include "th02/th02.h" #include "x86real.h" #include "master.hpp" +#include "th01/math/clamp.hpp" #include "th02/resident.hpp" #include "th02/hardware/frmdelay.h" #include "th02/hardware/grp_rect.h" @@ -188,7 +189,7 @@ void pascal shottype_menu(void) frame_delay(1); darken_pic_at(pic_x[sel] + 8, pic_y[sel] + 8); - RING_DEC(sel, sel_ring_end()); + ring_dec(sel, sel_ring_end()); draw_new_sel(pic_x, pic_y); } if(key_det & INPUT_RIGHT) { @@ -200,7 +201,7 @@ void pascal shottype_menu(void) frame_delay(1); darken_pic_at(pic_x[sel] + 8, pic_y[sel] + 8); - RING_INC(sel, sel_ring_end()); + ring_inc(sel, sel_ring_end()); draw_new_sel(pic_x, pic_y); } if(key_det & INPUT_SHOT || key_det & INPUT_OK) {