Skip to content

Commit

Permalink
[Decompilation] [th03] Win screen: Loading images and messages
Browse files Browse the repository at this point in the history
…immediately lift the text and character arrays into C land here.

Part of P0261, funded by [Anonymous] and Yanga.
  • Loading branch information
nmlgc committed Nov 1, 2023
1 parent a314a0f commit ffb8b14
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 153 deletions.
7 changes: 7 additions & 0 deletions th03/formats/win.hpp
@@ -0,0 +1,7 @@
// TH03's win screen lines are stored in another simple plaintext file that
// contains one 3×60-byte block of lines per playchar, followed by two more
// fixed blocks shown at the end of stages 6 and 7. In contrast to TH02's
// dialog text files, these don't use any padding bytes.

static const int WIN_LINES = 3;
static const int WIN_LINE_SIZE = 60;
95 changes: 94 additions & 1 deletion th03/mainl/screens.cpp
@@ -1,7 +1,100 @@
#include <stddef.h>
#include "platform.h"
#include "pc98.h"
#include "planar.h"
#include "shiftjis.hpp"
#include "master.hpp"
#include "th03/common.h"
#include "th03/playchar.hpp"
#include "th03/score.h"
#include "th03/resident.hpp"
extern "C" {
#include "th03/formats/cdg.h"
}
#include "th03/formats/win.hpp"

extern const char near* PIC_FN[PLAYCHAR_COUNT];
shiftjis_t win_text[WIN_LINES][WIN_LINE_SIZE + 1];
PlaycharPaletted playchar[PLAYER_COUNT];

// Win screen
// ----------

static const int LOGO_FADE_CELS = 5;

enum win_cdg_slot_t {
CDG_LOGO_FADE = 0,
CDG_LOGO = (CDG_LOGO_FADE + LOGO_FADE_CELS),
CDG_PIC_WINNER,
};

inline playchar_t loser_char_id(void) {
return static_cast<playchar_t>((resident->pid_winner == 0)
? playchar[1].char_id()
: playchar[0].char_id()
);
}

void near win_load(void)
{
extern const char logo0_rgb[];
extern const char logo_cd2[];
extern const char logo5_cdg[];
extern const char* WIN_MESSAGE_FN[PLAYCHAR_COUNT];

playchar_paletted_t playchar_winner;
uint8_t message_id;

// MODDERS: [playchar_winner] has to be declared as a scalar type to cause
// Turbo C++ 4.0J to place it at its original stack position, and I'd like
// to still use the `PlaycharPaletted` methods. Just turn [playchar_winner]
// into a `PlaycharPaletted` and remove this macro.
#define playchar_winner ( \
reinterpret_cast<PlaycharPaletted &>(playchar_winner) \
)

palette_entry_rgb_show(logo0_rgb);
cdg_load_all_noalpha(CDG_LOGO_FADE, logo_cd2);
cdg_load_single(CDG_LOGO, logo5_cdg, 0);

// ZUN bloat: playchar[resident->pid_winner]
playchar_winner = ((resident->pid_winner == 0) ? playchar[0] : playchar[1]);

if(resident->pid_winner == 0) {
// The usually 0-based [story_stage] has already been incremented when
// we get here, so these refer to the *next* stage, not the one that
// has just been won.
if(resident->story_stage == STAGE_DECISIVE) {
message_id = (PLAYCHAR_COUNT + 0);
} else if(resident->story_stage == STAGE_CHIYURI) {
message_id = (PLAYCHAR_COUNT + 1);
} else {
message_id = loser_char_id();
}
} else {
message_id = loser_char_id();
}

cdg_load_single_noalpha(
CDG_PIC_WINNER,
PIC_FN[playchar_winner.char_id_16()],
playchar_winner.palette_id()
);

static_assert(WIN_LINES == 3);
file_ropen(WIN_MESSAGE_FN[playchar_winner.char_id_16()]);
file_seek((message_id * (WIN_LINES * WIN_LINE_SIZE)), SEEK_SET);
file_read(win_text[0], WIN_LINE_SIZE); win_text[0][WIN_LINE_SIZE] = '\0';
file_read(win_text[1], WIN_LINE_SIZE); win_text[1][WIN_LINE_SIZE] = '\0';
file_read(win_text[2], WIN_LINE_SIZE); win_text[2][WIN_LINE_SIZE] = '\0';
file_close();

#undef playchar_winner
}
// ----------

// Stage splash screen
// -------------------

extern bool do_not_show_stage_number;
bool do_not_show_stage_number;
// -------------------
9 changes: 8 additions & 1 deletion th03/playchar.hpp
Expand Up @@ -11,6 +11,8 @@ typedef enum {
PLAYCHAR_COUNT = 9,
} playchar_t;

typedef unsigned char playchar_paletted_t;

// Uses 0 to indicate "no character" and shifts all IDs up by 1.
struct PlaycharOptional {
unsigned char v;
Expand All @@ -27,12 +29,17 @@ struct PlaycharOptional {
// Encodes a playchar_t together with its alternate palette flag in the lowest
// bit.
struct PlaycharPaletted {
unsigned char v;
playchar_paletted_t v;

playchar_t char_id() const {
return static_cast<playchar_t>(v / 2);
}

// ZUN bloat
int char_id_16() const {
return (v / 2);
}

bool16 palette_id() const {
return (v & 1);
}
Expand Down
6 changes: 5 additions & 1 deletion th03/resident.hpp
Expand Up @@ -20,11 +20,15 @@ enum game_mode_t {
GM_VS_CPU_CPU = GM_VS + VS_CPU_CPU,
};

#define STAGE_DECISIVE 6
#define STAGE_CHIYURI 7
#define STAGE_YUMEMI 8
#define STAGE_COUNT 9

// Won't enter [score_last[0]] into YUME.NEM, even if it's high enough for a
// place. Also used for just showing the high scores from the main menu.
#define STAGE_NONE -1
#define STAGE_ALL 99
#define STAGE_COUNT 9

#define CREDIT_LIVES 2

Expand Down

0 comments on commit ffb8b14

Please sign in to comment.