Skip to content

Commit

Permalink
[Maintenance] Introduce a type for PC-98 text RAM attributes
Browse files Browse the repository at this point in the history
No need for signed variants this time!

Part of P0262, funded by [Anonymous] and Blue Bolt.
  • Loading branch information
nmlgc committed Nov 30, 2023
1 parent ae2fc28 commit 214c404
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 22 deletions.
4 changes: 4 additions & 0 deletions pc98.h
Expand Up @@ -80,6 +80,10 @@ typedef unsigned int utram_y_t;

#define shiftjis_w(literal) \
((sizeof(literal) - 1) * GLYPH_HALF_W)

// Text RAM attribute byte. ZUN bloat: Only keep tram_atrb_t.
typedef uint8_t tram_atrb_t;
typedef uint16_t tram_atrb2;
/// ----

/// Graphics
Expand Down
4 changes: 2 additions & 2 deletions th01/hardware/tram_x16.cpp
@@ -1,4 +1,4 @@
void TRAMCursor::putkanji(jis_t jis_kanji, int atrb)
void TRAMCursor::putkanji(jis_t jis_kanji, tram_atrb2 atrb)
{
// Yes, this is a correct way of writing any fullwidth character to TRAM.
// More research and proof forthcoming...
Expand All @@ -10,7 +10,7 @@ void TRAMCursor::putkanji(jis_t jis_kanji, int atrb)
p++;
}

void TRAMCursor::putkanji_for_5_rows(jis_t jis_kanji, int atrb)
void TRAMCursor::putkanji_for_5_rows(jis_t jis_kanji, tram_atrb2 atrb)
{
for(int y = 0; y < 5; y++) {
for(int x = 0; x < (RES_X / GLYPH_FULL_W); x++) {
Expand Down
6 changes: 3 additions & 3 deletions th01/hardware/tram_x16.hpp
Expand Up @@ -20,15 +20,15 @@ class TRAMCursor {
// Writes the given fullwidth JIS code point with the given attribute to
// the left and right cells at the current cursor position, then advances
// the cursor. Halfwidth code points will also be written to both cells.
void putkanji(jis_t jis_kanji, int atrb);
void putkanji(jis_t jis_kanji, tram_atrb2 atrb);

// Calls putkanji() for the next 5 TRAM rows.
void putkanji_for_5_rows(jis_t jis_kanji, int atrb);
void putkanji_for_5_rows(jis_t jis_kanji, tram_atrb2 atrb);

// ZUN landmine: This is always called at the (0-based) line 21, and
// therefore always ends up writing into the second TRAM page. Luckily,
// that page is unused, and no code cares about it...
void putkanji_until_end(jis_t jis_kanji, int atrb) {
void putkanji_until_end(jis_t jis_kanji, tram_atrb2 atrb) {
putkanji_for_5_rows(jis_kanji, atrb);
}

Expand Down
6 changes: 3 additions & 3 deletions th01/hardware/ztext.cpp
Expand Up @@ -113,15 +113,15 @@ inline uint8_t* tram_jis(uint16_t offset) {
return reinterpret_cast<uint8_t *>(MK_FP(SEG_TRAM_JIS, offset));
}

inline uint16_t* tram_atrb(uint16_t offset) {
return reinterpret_cast<uint16_t *>(MK_FP(SEG_TRAM_ATRB, offset));
inline tram_atrb2* tram_atrb(uint16_t offset) {
return reinterpret_cast<tram_atrb2 *>(MK_FP(SEG_TRAM_ATRB, offset));
}

void z_text_putsa(tram_x_t x, tram_y_t y, int z_atrb, const sshiftjis_t *str)
{
jis_t codepoint;
int p = (((y * text_width()) + x) * 2);
int hw_atrb = 1;
tram_atrb2 hw_atrb = 1;

if(z_atrb & Z_ATRB_BLUE) {
hw_atrb += 0x20;
Expand Down
2 changes: 1 addition & 1 deletion th02/main/dialog/dialog.cpp
Expand Up @@ -326,7 +326,7 @@ void pascal near dialog_face_put(
}

void pascal near dialog_text_put(
tram_cell_amount_t line, const shiftjis_t* str, uint16_t atrb, int n
tram_cell_amount_t line, const shiftjis_t* str, tram_atrb2 atrb, int n
)
{
// ZUN landmine: master.lib has text_putnsa() for this purpose, which works
Expand Down
6 changes: 3 additions & 3 deletions th02/maine_04.cpp
Expand Up @@ -53,7 +53,7 @@ inline void scoredat_init() {
}

// Slightly differs from the same function in OP.EXE!
void pascal score_put(tram_y_t y, long score, unsigned atrb)
void pascal score_put(tram_y_t y, long score, tram_atrb2 atrb)
{
tram_x_t x;
int digit;
Expand All @@ -78,7 +78,7 @@ void pascal score_put(tram_y_t y, long score, unsigned atrb)

void pascal near scores_put(int place_to_highlight)
{
unsigned atrb = TX_WHITE;
tram_atrb2 atrb = TX_WHITE;
int i;
int col;
gaiji_putsa(20, 2, gbHI_SCORE, TX_GREEN);
Expand Down Expand Up @@ -114,7 +114,7 @@ void pascal near scores_put(int place_to_highlight)
}
}

void pascal near alphabet_putca(int col, int row, unsigned atrb)
void pascal near alphabet_putca(int col, int row, tram_atrb2 atrb)
{
ALPHABET_PUTCA(col, row, atrb);
}
Expand Down
6 changes: 3 additions & 3 deletions th02/op_01.cpp
Expand Up @@ -34,7 +34,7 @@ extern "C" {

#pragma option -d -a2

typedef void pascal near putfunc_t(int sel, unsigned int atrb);
typedef void pascal near putfunc_t(int sel, tram_atrb2 atrb);

char menu_sel = 0;
bool in_option = false;
Expand Down Expand Up @@ -347,7 +347,7 @@ void pascal near main_put_shadow(void)
graph_gaiji_puts(308, 372, 16, gbcRANKS[rank], 0);
}

void pascal near main_put(int sel, unsigned int atrb)
void pascal near main_put(int sel, tram_atrb2 atrb)
{
if(sel == 0) {
gaiji_putsa(35, 16, gbSTART, atrb);
Expand Down Expand Up @@ -474,7 +474,7 @@ void pascal near option_put_shadow(void)
graph_gaiji_puts(292, 372, 16, gbQUIT, 0);
}

void pascal near option_put(int sel, unsigned int atrb)
void pascal near option_put(int sel, tram_atrb2 atrb)
{
if(sel == 0) {
gaiji_putsa(24, 16, gbRANK, atrb);
Expand Down
8 changes: 4 additions & 4 deletions th02/op_04.cpp
Expand Up @@ -43,7 +43,7 @@ unsigned int score_duration;
#include "th02/scorelod.c"

// Slightly differs from the same function in MAINE.EXE!
void pascal near score_put(unsigned y, long score, unsigned atrb)
void pascal near score_put(unsigned y, long score, tram_atrb2 atrb)
{
unsigned digit = gb_0_;
long divisor = 10000000;
Expand All @@ -63,7 +63,7 @@ void pascal near score_put(unsigned y, long score, unsigned atrb)
}
}

void pascal near shottype_put(tram_y_t y, int type, int atrb)
void pascal near shottype_put(tram_y_t y, int type, tram_atrb2 atrb)
{
text_putsa(48, y, SHOTTYPES[type], atrb);
}
Expand All @@ -86,7 +86,7 @@ void int_to_string(char *str, int val, int chars)
str[c] = 0;
}

void pascal near scoredat_date_put(tram_y_t y, int place, int atrb)
void pascal near scoredat_date_put(tram_y_t y, int place, tram_atrb2 atrb)
{
char str[6];
int_to_string(str, hi.score.date[place].da_year, 4);
Expand All @@ -101,7 +101,7 @@ void pascal near scoredat_date_put(tram_y_t y, int place, int atrb)

void pascal near scores_put(int place_to_highlight)
{
unsigned atrb = TX_WHITE;
tram_atrb2 atrb = TX_WHITE;
int i;
gaiji_putsa(22, 2, gbHI_SCORE, TX_GREEN);
gaiji_putsa(40, 2, gbcRANKS[rank], TX_GREEN);
Expand Down
2 changes: 1 addition & 1 deletion th04/main/hud/bar_put.asm
@@ -1,5 +1,5 @@
; void pascal far hud_bar_put(
; utram_y_t y, unsigned char value, unsigned int atrb
; utram_y_t y, unsigned char value, tram_atrb2 atrb
; );
public HUD_BAR_PUT
hud_bar_put proc far
Expand Down
2 changes: 1 addition & 1 deletion th05/hud_bar.asm
Expand Up @@ -14,7 +14,7 @@ MAIN_01_TEXT segment word public 'CODE' use16
assume cs:MAIN_01_TEXT

; void pascal near hud_bar_put(
; utram_y_t y, unsigned char value, unsigned int atrb
; utram_y_t y, unsigned char value, tram_atrb2 atrb
; );
public HUD_BAR_PUT
HUD_BAR_PUT proc near
Expand Down
4 changes: 3 additions & 1 deletion th05/main/hud/number_put.asm
@@ -1,6 +1,8 @@
; Prints [val] using the bold gaiji font, right-aligned at ([left+5], [y]),
; with the given attribute.
; void pascal far hud_int_put(utram_x_t left, utram_y_t y, unsigned int val, unsigned int atrb);
; void pascal far hud_int_put(
; utram_x_t left, utram_y_t y, unsigned int val, tram_atrb2 atrb
; );
public HUD_INT_PUT
hud_int_put proc far

Expand Down

0 comments on commit 214c404

Please sign in to comment.