Skip to content

Commit

Permalink
[Decompilation] [th04/th05] Stage and BGM title popups
Browse files Browse the repository at this point in the history
Completes P0089, funded by [Anonymous] and Blue Bolt.
  • Loading branch information
nmlgc committed May 4, 2020
1 parent e1f3af5 commit 90252cc
Show file tree
Hide file tree
Showing 12 changed files with 359 additions and 837 deletions.
6 changes: 3 additions & 3 deletions Makefile.mak
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ $**
|

bin\th04\scoreupd.obj: th04\scoreupd.asm
bin\th04\main.exe: bin\th04\main.obj bin\th04\scoreupd.obj
$(CC) $(CFLAGS) -ml -DGAME=4 -DBINARY='M' -nbin\th04\ -eMAIN.EXE @&&|
bin\th04\main.exe: bin\th04\main.obj bin\th04\scoreupd.obj th04\main011.cpp
$(CC) $(CFLAGS) -ml -DGAME=4 -DBINARY='M' -3 -Z -nbin\th04\ -eMAIN.EXE @&&|
$**
|

Expand All @@ -128,7 +128,7 @@ bin\th05\op.exe: bin\th05\op.obj th05\op_01.cpp
$**
|

bin\th05\main.exe: bin\th05\main.obj th05\p_common.cpp th05\p_reimu.cpp th05\p_marisa.cpp th05\p_mima.cpp th05\p_yuuka.cpp bin\th05\player.obj bin\th05\hud_bar.obj bin\th05\scoreupd.obj th05\main012.cpp
bin\th05\main.exe: bin\th05\main.obj th05\p_common.cpp th05\p_reimu.cpp th05\p_marisa.cpp th05\p_mima.cpp th05\p_yuuka.cpp bin\th05\player.obj bin\th05\hud_bar.obj bin\th05\scoreupd.obj th05\main011.cpp th05\main012.cpp
$(CC) $(CFLAGS) -ml -3 -Z -DGAME=5 -DBINARY='M' -nbin\th05\ -eMAIN.EXE @&&|
$**
|
Expand Down
2 changes: 2 additions & 0 deletions th02/main/playfld.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#define PLAYFIELD_TRAM_X (PLAYFIELD_X / 8)
#define PLAYFIELD_TRAM_Y (PLAYFIELD_Y / 16)
#define PLAYFIELD_TRAM_W (PLAYFIELD_W / 8)
#define PLAYFIELD_TRAM_CENTER_X \
((PLAYFIELD_X + (PLAYFIELD_W / 2)) / GLYPH_HALF_W)
#define PLAYFIELD_TRAM_RIGHT (PLAYFIELD_RIGHT / 8)
#define PLAYFIELD_TRAM_BOTTOM (PLAYFIELD_BOTTOM / 16)

Expand Down
5 changes: 5 additions & 0 deletions th04/formats/bb.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ void pascal near bb_stage_load(const char far* fn);
#define BB_TXT_H 32
#define BB_TXT_VRAM_W (BB_TXT_W / 8)

#define BB_TXT_IN_SPRITE 16
#define BB_TXT_IN_CELS 8
#define BB_TXT_OUT_SPRITE 0
#define BB_TXT_OUT_CELS 16

// Puts the given TXT*.BB sprite at (⌊left/8⌋*8, top). Assumptions:
// • ES is already be set to the beginning of a VRAM segment
// • The GRCG is active, and set to the intended color
Expand Down
286 changes: 286 additions & 0 deletions th04/main/hud/popup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
#include "ReC98.h"
#include "th03/math/subpixel.hpp"
#include "th04/gaiji/gaiji.h"
#include "th04/formats/bb.h"
#include "th04/hardware/grcg.h"
#include "th04/math/motion.hpp"
#include "th04/main/null.hpp"
#include "th04/main/playfld.h"
#include "th04/main/tile.hpp"
#include "th04/main/scroll.hpp"
#include "th04/main/hud/popup.hpp"
#include "th04/main/stage/stage.hpp"
#include "th04/main/item/items.hpp"

#if (GAME == 4)
#include "th04/chars.h"
#endif

// See tile.hpp for the reason this declaration is necessary
void pascal near tiles_invalidate_around(
subpixel_t center_y, subpixel_t center_x
);

/// Stage and BGM titles
/// --------------------
extern unsigned char popup_dissolve_sprite;
extern int stage_title_len;
extern int stage_bgm_title_len;
extern int boss_bgm_title_len;
#if (GAME == 5)
extern char *stage_title;
extern char *stage_bgm_title;
extern char *boss_bgm_title;
#else
extern unsigned char stage_title_id;
extern const char* BGM_TITLES[];
extern const char* STAGE_TITLES[];
#define stage_title (STAGE_TITLES[stage_title_id])
#define stage_bgm_title (BGM_TITLES[bgm_title_id])
#define boss_bgm_title stage_bgm_title
#endif
extern char gStage_1[8];
extern const char gFINAL_STAGE[12];
extern const char gEXTRA_STAGE[12];

#define STAGE_NUM_CENTER_Y 168
#define STAGE_TITLE_CENTER_Y 200
#define BGM_CENTER_Y 360

#define POPUP_FRAMES_UNTIL_OUT_DISSOLVE 192

#define vram_y_to_tram(y) (PLAYFIELD_TRAM_Y + (y / GLYPH_H))

#define STAGE_NUM_W ((sizeof(gStage_1) - 1) * GAIJI_TRAM_W)
#define STAGE_NUM_FE_W ((sizeof(gFINAL_STAGE) - 1) * GAIJI_TRAM_W)
#define STAGE_NUM_TRAM_LEFT (PLAYFIELD_TRAM_CENTER_X - (STAGE_NUM_W / 2))
#define STAGE_NUM_FE_TRAM_LEFT (PLAYFIELD_TRAM_CENTER_X - (STAGE_NUM_FE_W / 2))

#define STAGE_NUM_TRAM_CENTER_Y (vram_y_to_tram(STAGE_NUM_CENTER_Y))
#define STAGE_TITLE_TRAM_CENTER_Y (vram_y_to_tram(STAGE_TITLE_CENTER_Y))
#define BGM_TRAM_CENTER_Y (vram_y_to_tram(BGM_CENTER_Y))
#define BGM_TRAM_RIGHT (PLAYFIELD_TRAM_RIGHT - 1)

inline int bgm_note_tram_left(int title_len)
{
return ((BGM_TRAM_RIGHT - (GAIJI_TRAM_W + 1)) - title_len);
}
inline int bgm_title_tram_left(int title_len)
{
return (BGM_TRAM_RIGHT - title_len);
}

// Draws [popup_dissolve_sprite] onto the graphics RAM along a row of text
// with the given halfwidth length, starting at the given text RAM X column
// and playfield-space Y position.
// Assumes that the GRCG is active, and set to the intended color.
void pascal near popup_dissolve_put(int tram_left, subpixel_t top, int ank_len)
{
int vram_left = tram_left;
int vram_right = ank_len;

vram_left--;
vram_right += vram_left;

vram_right *= GLYPH_HALF_W;
vram_left *= GLYPH_HALF_W;
top = scroll_subpixel_y_to_vram_seg1(top);

_ES = SEG_PLANE_B;
while(vram_left < vram_right) {
bb_txt_put_8(vram_left, top, popup_dissolve_sprite);
vram_left += GLYPH_FULL_W;
}
}

void pascal near popup_titles_invalidate(void)
{
unsigned char frames = (popup_titles_frame + popup_boss_bgm_frame);
if(frames == 0) {
return;
}
if(frames >= POPUP_FRAMES_UNTIL_OUT_DISSOLVE || frames <= 34) {
tile_invalidate_box.x = PLAYFIELD_W;
tile_invalidate_box.y = BB_TXT_H;
tiles_invalidate_around_vram_xy(PLAYFIELD_W / 2, STAGE_NUM_CENTER_Y);
tiles_invalidate_around_vram_xy(PLAYFIELD_W / 2, STAGE_TITLE_CENTER_Y);
tiles_invalidate_around_vram_xy(PLAYFIELD_W / 2, BGM_CENTER_Y);
}
}

inline void bgm_note_dissolve_put(const int& len)
{
popup_dissolve_put(
bgm_note_tram_left(len), to_sp(BGM_CENTER_Y), GAIJI_TRAM_W
);
}

inline void bgm_title_dissolve_put(const int& len)
{
popup_dissolve_put(bgm_title_tram_left(len), to_sp(BGM_CENTER_Y), len);
}

#define bgm_string_put(str, len) \
gaiji_putca(bgm_note_tram_left(len), BGM_TRAM_CENTER_Y, 3, TX_YELLOW); \
text_putsa(bgm_title_tram_left(len), BGM_TRAM_CENTER_Y, str, TX_WHITE);

inline void titles_dissolve_put(const int& bgm_len)
{
grcg_setmode_rmw_seg1();

grcg_setcolor_direct_seg1(11); // Yellow
if(stage_id < 5) {
popup_dissolve_put(
STAGE_NUM_TRAM_LEFT, to_sp(STAGE_NUM_CENTER_Y), STAGE_NUM_W
);
} else {
popup_dissolve_put(
STAGE_NUM_FE_TRAM_LEFT, to_sp(STAGE_NUM_CENTER_Y), STAGE_NUM_FE_W
);
}
bgm_note_dissolve_put(bgm_len);

grcg_setcolor_direct_seg1(15); // White
bgm_title_dissolve_put(bgm_len);
popup_dissolve_put(
(PLAYFIELD_TRAM_CENTER_X - (stage_title_len / 2)),
to_sp(STAGE_TITLE_CENTER_Y),
stage_title_len
);
grcg_off();
}

#define titles_strings_put(bgm_str, bgm_len) \
gStage_1[6] = (gb_1_ + stage_id); \
if(stage_id == 5) { \
gaiji_putsa( \
STAGE_NUM_FE_TRAM_LEFT, \
STAGE_NUM_TRAM_CENTER_Y, \
gFINAL_STAGE, \
TX_YELLOW \
); \
} else if(stage_id == 6) { \
gaiji_putsa( \
STAGE_NUM_FE_TRAM_LEFT, \
STAGE_NUM_TRAM_CENTER_Y, \
gEXTRA_STAGE, \
TX_YELLOW \
); \
} else { \
gaiji_putsa( \
STAGE_NUM_TRAM_LEFT, STAGE_NUM_TRAM_CENTER_Y, gStage_1, TX_YELLOW \
); \
} \
text_putsa( \
(PLAYFIELD_TRAM_CENTER_X - (stage_title_len / 2)), \
STAGE_TITLE_TRAM_CENTER_Y, \
stage_title, \
TX_WHITE \
); \
bgm_string_put(bgm_str, bgm_len);

static inline void boss_bgm_dissolve_put(const int& bgm_len)
{
grcg_setmode_rmw_seg1();

grcg_setcolor_direct_seg1(11); // Yellow
bgm_note_dissolve_put(bgm_len);

grcg_setcolor_direct_seg1(15); // White
bgm_title_dissolve_put(bgm_len);

grcg_off();
}

#define dissolve_in_update(frame) \
if((frame & 3) == 0) { \
if(frame != 0) { \
popup_dissolve_sprite++; \
if(popup_dissolve_sprite >= (BB_TXT_IN_SPRITE + BB_TXT_IN_CELS)) { \
popup_dissolve_sprite = 0; \
} \
} \
}

#define dissolve_out_update(frame) \
if(frame == POPUP_FRAMES_UNTIL_OUT_DISSOLVE) { \
playfield_tram_wipe(); \
popup_dissolve_sprite = BB_TXT_OUT_SPRITE; \
} else { \
if((frame & 1) == 0) { \
popup_dissolve_sprite++; \
} \
}

void pascal near popup_titles_update_and_render(void)
{
#define frames popup_titles_frame
if(frames >= POPUP_FRAMES_UNTIL_OUT_DISSOLVE) {
dissolve_out_update(frames);
if(popup_dissolve_sprite >= (BB_TXT_OUT_SPRITE + BB_TXT_OUT_CELS)) {
if(frames & 1) {
overlay_text = nullfunc_near;
frames = 0;
popup_dissolve_sprite = 0;
return;
}
} else {
titles_dissolve_put(stage_bgm_title_len);
}
} else {
if(frames == 0) {
popup_dissolve_sprite = BB_TXT_IN_SPRITE;
#if (GAME == 4)
stage_title_id = (stage_id + 1);
bgm_title_id = ((stage_id * 2) + 1);
if(stage_id == 0 && playchar == PLAYCHAR_REIMU) {
stage_title_id = 0;
bgm_title_id = 0;
}
#endif
stage_title_len = strlen(stage_title);
stage_bgm_title_len = strlen(stage_bgm_title);
}
if(popup_dissolve_sprite >= BB_TXT_IN_SPRITE) {
if(popup_dissolve_sprite == (BB_TXT_IN_SPRITE + 6)) {
titles_strings_put(stage_bgm_title, stage_bgm_title_len);
}
titles_dissolve_put(stage_bgm_title_len);
dissolve_in_update(frames);
}
}
frames++;
#undef frames
}

void pascal near popup_boss_bgm_update_and_render(void)
{
#define frames popup_boss_bgm_frame
if(frames >= POPUP_FRAMES_UNTIL_OUT_DISSOLVE) {
dissolve_out_update(frames);
if(popup_dissolve_sprite >= (BB_TXT_OUT_SPRITE + BB_TXT_OUT_CELS)) {
if(frames & 1) {
overlay_text = nullfunc_near;
frames = 0;
return;
}
} else {
boss_bgm_dissolve_put(boss_bgm_title_len);
}
} else {
if(frames == 0) {
popup_dissolve_sprite = BB_TXT_IN_SPRITE;
boss_bgm_title_len = strlen(boss_bgm_title);
}
if(popup_dissolve_sprite >= BB_TXT_IN_SPRITE) {
if(popup_dissolve_sprite == (BB_TXT_IN_SPRITE + 6)) {
bgm_string_put(boss_bgm_title, boss_bgm_title_len);
}
boss_bgm_dissolve_put(boss_bgm_title_len);
dissolve_in_update(frames);
}
}
frames++;
#undef frames
}
/// --------------------
10 changes: 10 additions & 0 deletions th04/main/hud/popup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ extern nearfunc_t_near popup;
extern unsigned long popup_bonus;

void pascal near popup_update_and_render(void);

/// Stage and BGM titles
/// --------------------
extern unsigned char popup_boss_bgm_frame;
extern unsigned char popup_titles_frame;

void pascal near popup_titles_invalidate(void);
void pascal near popup_titles_update_and_render(void);
void pascal near popup_boss_bgm_update_and_render(void);
/// --------------------
4 changes: 2 additions & 2 deletions th04/main/hud/popup[bss].asm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _boss_bgm_title_len dw ?

public _popup_gaiji_len, _popup_id_cur, _popup_dest_reached, _popup_shiftbuf
public _popup_cur_tram_x, _popup_dest_tram_x, _bgm_title_id, _popup_id_new
public _overlay_text, _popup, _popup_byte_unknown, _popup_bonus
public _overlay_text, _popup, _popup_titles_frame, _popup_bonus
_popup_gaiji_len dw ?
_popup_id_cur db ?
_popup_dest_reached db ?
Expand All @@ -28,6 +28,6 @@ _bgm_title_id db ?
_popup_id_new db ?
_overlay_text dw ?
_popup dw ?
_popup_byte_unknown db ?
_popup_titles_frame db ?
db ?
_popup_bonus dd ?
11 changes: 8 additions & 3 deletions th04/main/hud/popup[data].asm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
gStage_1 db 0BCh, 0BDh, 0AAh, 0B0h, 0AEh, 2, 0A1h, 0
gFINAL_STAGE db 0AFh, 0B2h, 0B7h, 0AAh, 0B5h, 2, 0BCh, 0BDh, 0AAh, 0B0h, 0AEh, 0
gEXTRA_STAGE db 0AEh, 0C1h, 0BDh, 0BBh, 0AAh, 2, 0BCh, 0BDh, 0AAh, 0B0h, 0AEh, 0
public _gStage_1, _gFINAL_STAGE, _gEXTRA_STAGE
_gStage_1 db 0BCh, 0BDh, 0AAh, 0B0h, 0AEh, 2, 0A1h, 0
_gFINAL_STAGE db 0AFh, 0B2h, 0B7h, 0AAh, 0B5h, 2, 0BCh, 0BDh, 0AAh, 0B0h, 0AEh, 0
_gEXTRA_STAGE db 0AEh, 0C1h, 0BDh, 0BBh, 0AAh, 2, 0BCh, 0BDh, 0AAh, 0B0h, 0AEh, 0
gpHISCORE_ENTRY db 40h, 41h, 42h, 43h, 44h, 45h, 46h, 47h, 0
gpEXTEND db 48h, 49h, 4Ah, 4Bh, 4Ch, 0
gpBONUS db 58h, 59h, 5Ah, 5Bh, 0
Expand All @@ -19,3 +20,7 @@ _POPUP_STRINGS label dword
if GAME eq 5
dd gpDREAMBONUS_MAX
endif

public _popup_dissolve_sprite
_popup_dissolve_sprite db 0
evendata
10 changes: 10 additions & 0 deletions th04/main011.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* ReC98
* -----
* 2nd part of code segment #1 of TH04's MAIN.EXE
*/

#pragma codeseg main_0_TEXT main_01

extern "C" {
#include "th04/main/hud/popup.cpp"
}
Loading

0 comments on commit 90252cc

Please sign in to comment.