Skip to content

Commit

Permalink
[Maintenance] [th02] Score: Consolidate rendering functions
Browse files Browse the repository at this point in the history
Part of P0278, funded by Yanga.
  • Loading branch information
nmlgc committed Apr 11, 2024
1 parent 57211ac commit 459cdd6
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 59 deletions.
87 changes: 87 additions & 0 deletions 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; \
} \
}
32 changes: 6 additions & 26 deletions th02/main/hud/overlay.cpp
Expand Up @@ -3,41 +3,21 @@
#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"

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)
Expand Down
21 changes: 5 additions & 16 deletions th02/maine_04.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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) \
Expand Down
23 changes: 6 additions & 17 deletions th02/op_04.cpp
Expand Up @@ -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"
Expand All @@ -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)
Expand Down

0 comments on commit 459cdd6

Please sign in to comment.