mirror of https://github.com/nmlgc/ReC98.git
[Maintenance] [th02] Score: Consolidate rendering functions
Part of P0278, funded by Yanga.
This commit is contained in:
parent
57211ac4d9
commit
459cdd6fe0
|
@ -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; \
|
||||||
|
} \
|
||||||
|
}
|
|
@ -3,7 +3,9 @@
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "pc98.h"
|
#include "pc98.h"
|
||||||
#include "master.hpp"
|
#include "master.hpp"
|
||||||
|
#include "th02/score.h"
|
||||||
#include "th02/gaiji/gaiji.h"
|
#include "th02/gaiji/gaiji.h"
|
||||||
|
#include "th02/gaiji/score_p.hpp"
|
||||||
#include "th02/main/playfld.hpp"
|
#include "th02/main/playfld.hpp"
|
||||||
#include "th02/main/hud/overlay.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
|
tram_x_t left, tram_y_t y, int digits, long val
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
enum {
|
#define on_digit(i, gaiji) { \
|
||||||
DIGITS_MAX = 8,
|
gaiji_putca((left + (i * GAIJI_TRAM_W)), y, gaiji, TX_WHITE); \
|
||||||
};
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
gaiji_score_put_digits(val, digits, on_digit);
|
||||||
|
#undef on_digit
|
||||||
}
|
}
|
||||||
|
|
||||||
void overlay_wipe(void)
|
void overlay_wipe(void)
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "th02/hardware/input.hpp"
|
#include "th02/hardware/input.hpp"
|
||||||
#include "th02/core/globals.hpp"
|
#include "th02/core/globals.hpp"
|
||||||
#include "th02/gaiji/gaiji.h"
|
#include "th02/gaiji/gaiji.h"
|
||||||
|
#include "th02/gaiji/score_p.hpp"
|
||||||
#include "th02/formats/scoredat.hpp"
|
#include "th02/formats/scoredat.hpp"
|
||||||
|
|
||||||
#include "th02/score.c"
|
#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)
|
void pascal score_put(tram_y_t y, score_t score, tram_atrb2 atrb)
|
||||||
{
|
{
|
||||||
tram_x_t x;
|
#define on_digit_at(x, gaiji) { \
|
||||||
int digit;
|
gaiji_putca(x, y, gaiji, atrb); \
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
gaiji_score_put_to(26, score, on_digit_at);
|
||||||
|
#undef on_digit_at
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ALPHABET_PUTCA(col, row, atrb) \
|
#define ALPHABET_PUTCA(col, row, atrb) \
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "th02/core/globals.hpp"
|
#include "th02/core/globals.hpp"
|
||||||
#include "th02/formats/scoredat.hpp"
|
#include "th02/formats/scoredat.hpp"
|
||||||
#include "th02/gaiji/gaiji.h"
|
#include "th02/gaiji/gaiji.h"
|
||||||
|
#include "th02/gaiji/score_p.hpp"
|
||||||
#include "th02/op/op.h"
|
#include "th02/op/op.h"
|
||||||
|
|
||||||
#include "th02/score.c"
|
#include "th02/score.c"
|
||||||
|
@ -40,25 +41,13 @@ unsigned int score_duration;
|
||||||
|
|
||||||
#include "th02/scorelod.c"
|
#include "th02/scorelod.c"
|
||||||
|
|
||||||
// Slightly differs from the same function in MAINE.EXE!
|
void pascal near score_put(tram_y_t y, score_t score, tram_atrb2 atrb)
|
||||||
void pascal near score_put(unsigned y, score_t score, tram_atrb2 atrb)
|
|
||||||
{
|
{
|
||||||
unsigned digit = gb_0_;
|
#define on_digit(i, gaiji) { \
|
||||||
score_t divisor = 10000000;
|
gaiji_putca((26 + (i * GAIJI_TRAM_W)), y, gaiji, atrb); \
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
gaiji_score_put(score, on_digit, true);
|
||||||
|
#undef on_digit
|
||||||
}
|
}
|
||||||
|
|
||||||
void pascal near shottype_put(tram_y_t y, int type, tram_atrb2 atrb)
|
void pascal near shottype_put(tram_y_t y, int type, tram_atrb2 atrb)
|
||||||
|
|
Loading…
Reference in New Issue