diff --git a/th02/gaiji/score_p.hpp b/th02/gaiji/score_p.hpp new file mode 100644 index 00000000..23688d2f --- /dev/null +++ b/th02/gaiji/score_p.hpp @@ -0,0 +1,87 @@ +// ZUN bloat: The divisor can never be 0. This separate function is just meant +// to work around the resulting `Condition is always true/false` and +// `Unreachable code` warnings. +#ifndef gaiji_score_put + inline score_t gaiji_score_divide( + const score_t& score, const score_t& divisor, bool check_divisor + ) { + if(check_divisor) { + return (divisor ? ((score / divisor) % 10) : (score % 10)); + } else { + return ((score / divisor) % 10); + } + } +#endif + +#define gaiji_score_put_update( \ + gaiji, past_leading_zeroes, divisor, digit, score, check_divisor \ +) { \ + digit = gaiji_score_divide(score, divisor, check_divisor); \ + divisor /= 10; \ + gaiji = (gb_0_ + digit); \ + if(digit) { \ + past_leading_zeroes = true; \ + } \ +} + +#define gaiji_score_put(score, on_digit, check_divisor) { \ + /* ZUN bloat: Initialized inside the loop. */ \ + int gaiji = gb_0_; /* ACTUAL TYPE: gaiji_th02_t */ \ + \ + score_t divisor = 10000000; /* Must match SCORE_DIGITS! */ \ + score_t digit; \ + bool past_leading_zeroes = false; \ + for(int i = 0; i < SCORE_DIGITS; i++) { \ + gaiji_score_put_update( \ + gaiji, past_leading_zeroes, divisor, digit, score, check_divisor \ + ); \ + if(past_leading_zeroes) { \ + on_digit(i, gaiji); \ + } \ + } \ +} + +// ZUN bloat: Could have been merged into the function above. +#define gaiji_score_put_digits(score, digits, on_digit) { \ + int i; \ + \ + /* ZUN bloat: Initialized inside the loop. */ \ + int gaiji = gb_0_; /* ACTUAL TYPE: gaiji_th02_t */ \ + \ + score_t divisor = 10000000; /* Must match SCORE_DIGITS! */ \ + score_t digit; \ + bool past_leading_zeroes = false; \ + \ + for(i = SCORE_DIGITS; i > digits; i--) { \ + divisor /= 10; \ + } \ + for(i = 0; i < digits; i++) { \ + gaiji_score_put_update( \ + gaiji, past_leading_zeroes, divisor, digit, score, false \ + ); \ + if(i == (digits - 1)) { \ + past_leading_zeroes = true; \ + } \ + if(past_leading_zeroes) { \ + on_digit(i, gaiji); \ + } \ + } \ +} + +// ZUN bloat: Also equivalent to the first function. +#define gaiji_score_put_to(left, score, on_digit_at) { \ + int gaiji; /* ACTUAL TYPE: gaiji_th02_t */ \ + score_t divisor = 10000000; /* Must match SCORE_DIGITS! */ \ + score_t digit; \ + bool past_leading_zeroes = false; \ + tram_x_t x = left; \ + while(x < (left + (SCORE_DIGITS * GAIJI_TRAM_W))) { \ + gaiji_score_put_update( \ + gaiji, past_leading_zeroes, divisor, digit, score, false \ + ); \ + if(past_leading_zeroes) { \ + on_digit_at(x, gaiji); \ + } \ + x += GAIJI_TRAM_W; \ + } \ +} diff --git a/th02/main/hud/overlay.cpp b/th02/main/hud/overlay.cpp index 3fa7fc4d..a86b4069 100644 --- a/th02/main/hud/overlay.cpp +++ b/th02/main/hud/overlay.cpp @@ -3,7 +3,9 @@ #include "platform.h" #include "pc98.h" #include "master.hpp" +#include "th02/score.h" #include "th02/gaiji/gaiji.h" +#include "th02/gaiji/score_p.hpp" #include "th02/main/playfld.hpp" #include "th02/main/hud/overlay.hpp" @@ -11,33 +13,11 @@ void pascal near overlay_uint_put( tram_x_t left, tram_y_t y, int digits, long val ) { - enum { - DIGITS_MAX = 8, - }; - - int i; - int gaiji = gb_0_; // ACTUAL TYPE: gaiji_th02_t - long divisor = 10000000; // Must match DIGITS_MAX! - long digit; - bool past_leading_zeroes = false; - - for(i = DIGITS_MAX; i > digits; i--) { - divisor /= 10; - } - for(i = 0; i < digits; i++) { - digit = ((val / divisor) % 10); - divisor /= 10; - gaiji = (digit + gb_0_); - if(digit != 0) { - past_leading_zeroes = true; - } - if(i == (digits - 1)) { - past_leading_zeroes = true; - } - if(past_leading_zeroes) { - gaiji_putca((left + (i * GAIJI_TRAM_W)), y, gaiji, TX_WHITE); - } + #define on_digit(i, gaiji) { \ + gaiji_putca((left + (i * GAIJI_TRAM_W)), y, gaiji, TX_WHITE); \ } + gaiji_score_put_digits(val, digits, on_digit); + #undef on_digit } void overlay_wipe(void) diff --git a/th02/maine_04.cpp b/th02/maine_04.cpp index ffb266dd..a1c375d1 100644 --- a/th02/maine_04.cpp +++ b/th02/maine_04.cpp @@ -14,6 +14,7 @@ #include "th02/hardware/input.hpp" #include "th02/core/globals.hpp" #include "th02/gaiji/gaiji.h" +#include "th02/gaiji/score_p.hpp" #include "th02/formats/scoredat.hpp" #include "th02/score.c" @@ -51,25 +52,13 @@ inline void scoredat_init() { } } -// Slightly differs from the same function in OP.EXE! void pascal score_put(tram_y_t y, score_t score, tram_atrb2 atrb) { - tram_x_t x; - int digit; - score_t divisor = 10000000; - score_t result; - char putting = 0; - for(x = 26; x < 26 + (8 * 2); x += 2) { - result = (score / divisor) % 10; - divisor /= 10; - digit = result + gb_0_; - if(result) { - putting = 1; - } - if(putting) { - gaiji_putca(x, y, digit, atrb); - } + #define on_digit_at(x, gaiji) { \ + gaiji_putca(x, y, gaiji, atrb); \ } + gaiji_score_put_to(26, score, on_digit_at); + #undef on_digit_at } #define ALPHABET_PUTCA(col, row, atrb) \ diff --git a/th02/op_04.cpp b/th02/op_04.cpp index 8716ffdb..f320530a 100644 --- a/th02/op_04.cpp +++ b/th02/op_04.cpp @@ -17,6 +17,7 @@ #include "th02/core/globals.hpp" #include "th02/formats/scoredat.hpp" #include "th02/gaiji/gaiji.h" +#include "th02/gaiji/score_p.hpp" #include "th02/op/op.h" #include "th02/score.c" @@ -40,25 +41,13 @@ unsigned int score_duration; #include "th02/scorelod.c" -// Slightly differs from the same function in MAINE.EXE! -void pascal near score_put(unsigned y, score_t score, tram_atrb2 atrb) +void pascal near score_put(tram_y_t y, score_t score, tram_atrb2 atrb) { - unsigned digit = gb_0_; - score_t divisor = 10000000; - score_t result; - char putting = 0; - int i; - for(i = 0; i < 8; i++) { - result = divisor ? ((score / divisor) % 10) : (score % 10); - divisor /= 10; - digit = result + gb_0_; - if(result) { - putting = 1; - } - if(putting) { - gaiji_putca((i * 2) + 26, y, digit, atrb); - } + #define on_digit(i, gaiji) { \ + gaiji_putca((26 + (i * GAIJI_TRAM_W)), y, gaiji, atrb); \ } + gaiji_score_put(score, on_digit, true); + #undef on_digit } void pascal near shottype_put(tram_y_t y, int type, tram_atrb2 atrb)