Skip to content

Commit

Permalink
[Reverse-engineering] [th03/th04/th05] Cutscenes: State variables
Browse files Browse the repository at this point in the history
You can fast-forward through cutscenes by holding Escape in these
games?! And the script interpreter adds automatic line breaks?!

Part of P0223, funded by Blue Bolt and rosenrose.
  • Loading branch information
nmlgc committed Nov 30, 2022
1 parent ccd5b70 commit ee717c1
Show file tree
Hide file tree
Showing 10 changed files with 553 additions and 502 deletions.
32 changes: 32 additions & 0 deletions th03/cutscene/cutscene.cpp
@@ -0,0 +1,32 @@
// High-level overview of the differences between the three games that can't be
// easily abstracted away:
//
// 1) TH03 and TH04 allocate dedicated memory for backing up the text box area
// in VRAM ([box_bg]), TH05 uses the bgimage system instead.

#include "platform.h"
#include "pc98.h"
#include "planar.h"
#include "shiftjis.hpp"
#include "master.hpp"

// State
// -----

#if (GAME >= 4)
// Statically allocated. MODDERS: TH03's dynamic allocation was better than
// hardcoding a maximum size...
extern unsigned char script[8192];

extern unsigned char near *script_p;
#else
// Dynamically allocated.
extern unsigned char far *script;

#define script_p script
#endif

extern uint4_t text_col;
extern uint8_t text_fx; // TH04 and TH05 directly set [graph_putsa_fx_func].
extern int script_number_param_default;
// -----
28 changes: 28 additions & 0 deletions th03/cutscene/cutscene.hpp
@@ -0,0 +1,28 @@
static const shiftjis_ank_amount_t NAME_LEN = 6;
static const shiftjis_kanji_amount_t NAME_KANJI_LEN = (
NAME_LEN / sizeof(shiftjis_kanji_t)
);

// Adding a fullwidth colon after the name
static const pixel_t NAME_W = ((NAME_LEN * GLYPH_HALF_W) + GLYPH_FULL_W);

// Note that this does not correspond to the tiled area painted into TH05's
// EDBK?.PI images.
static const screen_x_t BOX_LEFT = 80;
static const screen_y_t BOX_TOP = 320;
static const pixel_t BOX_W = 480;
static const pixel_t BOX_H = (GLYPH_H * 4);

static const vram_byte_amount_t BOX_VRAM_W = (BOX_W / BYTE_DOTS);
static const screen_x_t BOX_RIGHT = (BOX_LEFT + BOX_W);
static const screen_y_t BOX_BOTTOM = (BOX_TOP + BOX_H);

extern Planar<dots16_t>* box_bg;

// Skips most delays during the cutscene if `true`.
extern bool fast_forward;

// [y] is always aligned to GLYPH_H pixels.
extern screen_point_t cursor;

extern int text_interval;
47 changes: 47 additions & 0 deletions th03/cutscene/cutscene[bss].asm
@@ -0,0 +1,47 @@
NAME_LEN = 6
NAME_KANJI_LEN = (NAME_LEN / 2)
NAME_W = ((NAME_LEN * GLYPH_HALF_W) + GLYPH_FULL_W)

BOX_LEFT = 80
BOX_TOP = 320
BOX_W = 480
BOX_H = (GLYPH_H * 4)

BOX_VRAM_W = (BOX_W / BYTE_DOTS)
BOX_RIGHT = (BOX_LEFT + BOX_W)
BOX_BOTTOM = (BOX_TOP + BOX_H)

public _script, _fast_forward, _box_bg
if (GAME ge 4)
public _script_p
_script db 8192 dup(?)
_script_p dw ?
else
_script dd ?
endif
_box_bg dd ?
_fast_forward db ?

if (GAME ge 4)
db 60 dup(?)
endif
if (GAME eq 5)
COLMAP_COUNT = 8

colmap_t struc
CM_values db COLMAP_COUNT dup (?)
CM_keys dw (NAME_KANJI_LEN * COLMAP_COUNT) dup (?)
colmap_t ends

public _colmap
_colmap colmap_t <?>
endif
evendata

public _cursor, _text_interval, _text_col, _text_fx
public _script_number_param_default
_cursor Point <?>
_text_interval dw ?
_text_col db ?
_text_fx db ?
_script_number_param_default dw ?
@@ -1,3 +1,9 @@
if (GAME eq 5)
public _colmap_count
_colmap_count db 0
evendata
endif

public _BOX_MASKS
_BOX_MASKS label word
dw 8888h, 0h, 2222h, 0h
Expand Down

0 comments on commit ee717c1

Please sign in to comment.