Skip to content

Commit

Permalink
[Reverse-engineering] Assign names to all graph_putsa_fx() effects
Browse files Browse the repository at this point in the history
And get rid of the constraining FX() macro, with its spacing parameter
that we haven't even seen used so far.

Part of P0124, funded by [Anonymous] and Blue Bolt.
  • Loading branch information
nmlgc committed Nov 2, 2020
1 parent 774b172 commit f1c63ab
Show file tree
Hide file tree
Showing 26 changed files with 318 additions and 208 deletions.
2 changes: 1 addition & 1 deletion th01/fuuin_04.cpp
Expand Up @@ -14,7 +14,7 @@ extern "C" {
#include "th01/end/type.h"

#define TYPE_DELAY 3
#define TYPE_FX FX(15, 0, 0)
#define TYPE_FX (15 | FX_WEIGHT_NORMAL)

#define TONE_STEP_PER_FRAME 5

Expand Down
30 changes: 19 additions & 11 deletions th01/hardware/graph.cpp
Expand Up @@ -697,10 +697,18 @@ void graph_r_box(
graph_r_hline(left, right, bottom, col);
}

pixel_t text_extent_fx(int fx, const unsigned char *str)
inline int fx_weight_from(int col_and_fx) {
return ((col_and_fx / 0x10) % 4);
}

inline pixel_t fx_spacing_from(int col_and_fx) {
return ((col_and_fx / 0x40) % 8);
}

pixel_t text_extent_fx(int col_and_fx, const unsigned char *str)
{
register pixel_t ret = 0;
register pixel_t spacing = (fx / 0x40) % 8;
register pixel_t spacing = fx_spacing_from(col_and_fx);
while(*str) {
if(_ismbblead(str[0])) {
uint16_t codepoint = ((char)str[0] << 8) + str[0];
Expand All @@ -725,7 +733,7 @@ pixel_t text_extent_fx(int fx, const unsigned char *str)
#include "th01/hardware/grppsafx.cpp"

void graph_putsa_fx(
screen_x_t left, vram_y_t top, int fx, const unsigned char *str
screen_x_t left, vram_y_t top, int16_t col_and_fx, const unsigned char *str
)
{
register screen_x_t x = left;
Expand All @@ -734,30 +742,30 @@ void graph_putsa_fx(
unsigned char far *vram;
int fullwidth;
int first_bit;
int weight = (fx / 0x10) % 4;
pixel_t spacing = (fx / 0x40) % 8;
int clear_bg = (fx & FX_CLEAR_BG);
int underline = (fx & FX_UNDERLINE);
int reverse = (fx & FX_REVERSE);
int weight = fx_weight_from(col_and_fx);
pixel_t spacing = fx_spacing_from(col_and_fx);
int clear_bg = (col_and_fx & FX_CLEAR_BG);
int underline = (col_and_fx & FX_UNDERLINE);
int reverse = (col_and_fx & FX_REVERSE);
pixel_t w;
pixel_t line;
dots16_t glyph[GLYPH_H];
register dots16_t glyph_row_tmp;

if(clear_bg) {
w = text_extent_fx(fx, str);
w = text_extent_fx(col_and_fx, str);
if(underline) {
z_grcg_boxfill(x, top, (x + w - 1), (top + GLYPH_H + 1), 0);
graph_r_hline(x, (x + w - 1), (top + GLYPH_H + 1), 7);
} else {
z_grcg_boxfill(x, top, (x + w - 1), (top + GLYPH_H - 1), 0);
}
} else if(underline) {
w = text_extent_fx(fx, str);
w = text_extent_fx(col_and_fx, str);
graph_r_hline(x, (x + w - 1), (top + GLYPH_H + 1), 7);
}

grcg_setcolor_rmw(fx);
grcg_setcolor_rmw(col_and_fx);
OUTB(0x68, 0xB); // CG ROM dot access

while(str[0]) {
Expand Down
14 changes: 1 addition & 13 deletions th01/hardware/graph.h
Expand Up @@ -97,19 +97,7 @@ void graph_r_lineloop_unput(
// Calculates the width of [str], displayed with the given [fx].
int text_extent_fx(int fx, const unsigned char *str);

// TH01-exclusive effects
// ----------------------
// Puts a black background behind the text. Useful if the text is rendered
// onto the back page and should then be 2✕ scaled onto the front page.
#define FX_CLEAR_BG 0x200

#define FX_UNDERLINE 0x400
#define FX_REVERSE 0x800
// ----------------------
#include "th01/hardware/grppsafx.h"
void graph_printf_fx(
screen_x_t left, vram_y_t top, int fx, const char *fmt, ...
);

// Puts the rightmost N [digits] of [num] onto the graphics RAM, using
// full-width digits, and applying the given effect. (Consequently, the units
Expand All @@ -118,7 +106,7 @@ void graph_printf_fx(
// only blits the digits of [num] that differ from those in [num_prev].
// Will put nothing if [put_leading_zeroes] is false and [num] is 0.
void graph_putfwnum_fx(
screen_x_t left, vram_y_t top, int fx, int digits,
screen_x_t left, vram_y_t top, int16_t col_and_fx, int digits,
long num, long num_prev, bool16 put_leading_zeroes
);
/// ----
Expand Down
4 changes: 2 additions & 2 deletions th01/hardware/grppffx.c
Expand Up @@ -4,13 +4,13 @@
#include "th01/hardware/graph.h"

void graph_printf_fx(
screen_x_t left, vram_y_t top, int fx, const char *fmt, ...
screen_x_t left, vram_y_t top, int16_t col_and_fx, const char *fmt, ...
)
{
char str[256];
va_list ap;

va_start(ap, fmt);
vsprintf(str, fmt, ap);
graph_putsa_fx(left, top, fx, str);
graph_putsa_fx(left, top, col_and_fx, str);
}
4 changes: 2 additions & 2 deletions th01/hardware/grppfnfx.cpp
Expand Up @@ -2,7 +2,7 @@ struct hack { const char* NUM[10]; }; // XXX
extern const hack FULLWIDTH_NUMBERS;

void graph_putfwnum_fx(
screen_x_t left, vram_y_t top, int fx, int digits,
screen_x_t left, vram_y_t top, int16_t col_and_fx, int digits,
long num, long num_prev, bool16 put
)
{
Expand All @@ -29,7 +29,7 @@ void graph_putfwnum_fx(
put = true;
}
if(put && ((digit != digit_prev) || !num_prev)) {
graph_putsa_fx(x, top, fx, FW.NUM[digit]);
graph_putsa_fx(x, top, col_and_fx, FW.NUM[digit]);
}
x += GLYPH_FULL_W;
} while(divisor > 1);
Expand Down
6 changes: 3 additions & 3 deletions th01/hardware/grppsafx.cpp
Expand Up @@ -50,13 +50,13 @@
#define apply_weight(row_out, row_in, row_tmp, weight) \
row_out = row_in; \
switch(weight) { \
case 1: \
case WEIGHT_HEAVY: \
glyph_double(row_out, row_tmp); \
break; \
case 3: \
case WEIGHT_BLACK: \
glyph_double(row_out, row_tmp); \
/* fallthrough */ \
case 2: \
case WEIGHT_BOLD: \
glyph_double(row_out, row_tmp); \
row_tmp ^= row_out; \
row_out &= ~(row_tmp << 1); \
Expand Down
64 changes: 57 additions & 7 deletions th01/hardware/grppsafx.h
@@ -1,7 +1,57 @@
// Puts the given [str] onto the graphics RAM at the given position, applying
// the given effect.
#define FX(color, weight, spacing) \
((color) | (weight & 3) << 4 | (spacing & 7) << 6)
void graph_putsa_fx(
screen_x_t left, vram_y_t top, int fx, const unsigned char *str
);
// Font weights
// ------------

// As stored in font ROM
#define WEIGHT_NORMAL 0

// Naively adds one pixel of boldness, to the left
#define WEIGHT_HEAVY 1

// Adds one pixel of boldness to the left, but preserves holes inbetween
// strokes.
#define WEIGHT_BOLD 2

// Adding another pixel of boldness, to the left, on top of WEIGHT_BOLD.
// (Very thicc!)
#define WEIGHT_BLACK 3

#define WEIGHT_COUNT 4
// ------------

#if (GAME == 1)
// TH01-exclusive effects
// ----------------------
// Puts a black background behind the text. Useful if the text is rendered
// onto the back page and should then be 2✕ scaled onto the front page.
#define FX_CLEAR_BG 0x200

#define FX_UNDERLINE 0x400
#define FX_REVERSE 0x800
// ----------------------
#endif

#if (GAME <= 3)
#define FX_WEIGHT_NORMAL (WEIGHT_NORMAL << 4)
#define FX_WEIGHT_HEAVY (WEIGHT_HEAVY << 4)
#define FX_WEIGHT_BOLD (WEIGHT_BOLD << 4)
#define FX_WEIGHT_BLACK (WEIGHT_BLACK << 4)

#define FX_SPACING(spacing) \
(spacing & 7) << 6)

// Puts the given [str] onto the graphics RAM at the given position,
// with the given graphics color and effect.
void graph_putsa_fx(
screen_x_t left,
vram_y_t top,
int16_t col_and_fx,
const unsigned char *str
);
#endif

#if (GAME == 1)
// Variadic version of graph_putsa_fx().
void graph_printf_fx(
screen_x_t left, vram_y_t top, int16_t col_and_fx, const char *fmt, ...
);
#endif
18 changes: 18 additions & 0 deletions th01/hardware/grppsafx.inc
@@ -0,0 +1,18 @@
WEIGHT_NORMAL = 0
WEIGHT_HEAVY = 1
WEIGHT_BOLD = 2
WEIGHT_BLACK = 3
WEIGHT_COUNT = 4

if (GAME eq 1)
FX_CLEAR_BG = 200h
FX_UNDERLINE = 400h
FX_REVERSE = 800h
endif

if (GAME le 3)
FX_WEIGHT_NORMAL = (WEIGHT_NORMAL shl 4)
FX_WEIGHT_HEAVY = (WEIGHT_HEAVY shl 4)
FX_WEIGHT_BOLD = (WEIGHT_BOLD shl 4)
FX_WEIGHT_BLACK = (WEIGHT_BLACK shl 4)
endif

0 comments on commit f1c63ab

Please sign in to comment.