Skip to content

Commit

Permalink
[Decompilation] [th01] REIIDEN.EXE: Move the final pieces of data to …
Browse files Browse the repository at this point in the history
…C land

100%. What a giant, uncategorizable mess of data.

Part of P0215, funded by Ember2528.
  • Loading branch information
nmlgc committed Aug 14, 2022
1 parent 08e064f commit 65ce434
Show file tree
Hide file tree
Showing 24 changed files with 160 additions and 663 deletions.
2 changes: 1 addition & 1 deletion Makefile.mak
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bin\th01\op.exe: bin\piloadc.obj bin\th01\opd.obj th01\op_01.cpp bin\th01\op.obj
$**
|

bin\th01\reiiden.exe: bin\piloadc.obj bin\th01\reiidend.obj th01\main_01.cpp bin\th01\reiiden.obj bin\th01\frmdelay.obj bin\th01\vsync.obj bin\th01\ztext.obj bin\th01\initexit.obj bin\th01\graph.obj bin\th01\ptn_0to1.obj bin\th01\vplanset.obj th01\main_07.cpp bin\th01\ptn.obj th01\main_08.cpp bin\th01\f_imgd.obj bin\th01\grz.obj bin\th01\reiidenm.obj th01\main_09.cpp th01\bullet_l.cpp th01\grpinv32.cpp bin\th01\resstuff.obj th01\scrollup.cpp th01\egcrows.cpp th01\pgtrans.cpp th01\2x_main.cpp th01\egcwave.cpp th01\grph1to0.cpp th01\main_14.cpp th01\main_15.cpp bin\th01\mdrv2.obj th01\main_17.cpp th01\main_18.cpp th01\main_19.cpp th01\main_20.cpp th01\main_21.cpp bin\th01\pf.obj th01\main_23.cpp th01\main_24.cpp th01\main_25.cpp th01\main_26.cpp th01\main_27.cpp th01\main_28.cpp th01\main_29.cpp th01\main_30.cpp th01\main_31.cpp th01\main_32.cpp th01\main_33.cpp th01\main_34.cpp th01\main_35.cpp th01\main_36.cpp th01\main_37.cpp th01\main_38.cpp
bin\th01\reiiden.exe: bin\piloadc.obj th01\main_var.cpp th01\main_01.cpp bin\th01\reiiden.obj bin\th01\frmdelay.obj bin\th01\vsync.obj bin\th01\ztext.obj bin\th01\initexit.obj bin\th01\graph.obj bin\th01\ptn_0to1.obj bin\th01\vplanset.obj th01\main_07.cpp bin\th01\ptn.obj th01\main_08.cpp bin\th01\f_imgd.obj bin\th01\grz.obj bin\th01\reiidenm.obj th01\main_09.cpp th01\bullet_l.cpp th01\grpinv32.cpp bin\th01\resstuff.obj th01\scrollup.cpp th01\egcrows.cpp th01\pgtrans.cpp th01\2x_main.cpp th01\egcwave.cpp th01\grph1to0.cpp th01\main_14.cpp th01\main_15.cpp bin\th01\mdrv2.obj th01\main_17.cpp th01\main_18.cpp th01\main_19.cpp th01\main_20.cpp th01\main_21.cpp bin\th01\pf.obj th01\main_23.cpp th01\main_24.cpp th01\main_25.cpp th01\main_26.cpp th01\main_27.cpp th01\main_28.cpp th01\main_29.cpp th01\main_30.cpp th01\main_31.cpp th01\main_32.cpp th01\main_33.cpp th01\main_34.cpp th01\main_35.cpp th01\main_36.cpp th01\main_37.cpp th01\main_38.cpp
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -3 -Z -d -DGAME=1 -DBINARY='M' -nbin\th01\ -eREIIDEN.EXE @&&|
$**
|
Expand Down
1 change: 0 additions & 1 deletion Tupfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ BMP2ARR = bin\\Pipeline\\bmp2arr.exe
: th01_op_data.asm |> !as |> bin\\th01\\opd.obj
: th01_op.asm |> !as |> bin\\th01\\op.obj
: th01_op_master.asm |> !as |> bin\\th01\\opm.obj
: th01_reiiden_data.asm |> !as |> bin\\th01\\reiidend.obj
: th01_reiiden.asm |> !as |> bin\\th01\\reiiden.obj
: th01_reiiden_master.asm |> !as |> bin\\th01\\reiidenm.obj
: th01_fuuin.asm |> !as |> bin\\th01\\fuuin.obj
Expand Down
1 change: 0 additions & 1 deletion Tupfile.bat
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ tasm32 /m /mx /kh32768 /t zuncom\cstmstub.asm bin\zuncom\cstmstub.obj
tasm32 /m /mx /kh32768 /t th01_op_data.asm bin\th01\opd.obj
tasm32 /m /mx /kh32768 /t th01_op.asm bin\th01\op.obj
tasm32 /m /mx /kh32768 /t th01_op_master.asm bin\th01\opm.obj
tasm32 /m /mx /kh32768 /t th01_reiiden_data.asm bin\th01\reiidend.obj
tasm32 /m /mx /kh32768 /t th01_reiiden.asm bin\th01\reiiden.obj
tasm32 /m /mx /kh32768 /t th01_reiiden_master.asm bin\th01\reiidenm.obj
tasm32 /m /mx /kh32768 /t th01_fuuin.asm bin\th01\fuuin.obj
Expand Down
8 changes: 0 additions & 8 deletions th01/hiscore/hiscore[bss].asm

This file was deleted.

66 changes: 0 additions & 66 deletions th01/main/bullet/pellets[bss].asm

This file was deleted.

6 changes: 3 additions & 3 deletions th01/main/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ void debug_show_game(void)

void debug_vars(void)
{
extern long memory_check_cycle;
extern int heapcheck_ret_prev; // ZUN bloat
extern screen_x_t player_left_prev;
static long memory_check_cycle;
static int heapcheck_ret_prev; // ZUN bloat
static screen_x_t player_left_prev;

memory_check_cycle++;
if((memory_check_cycle % 1000) == 100) {
Expand Down
16 changes: 0 additions & 16 deletions th01/main/player/anim[bss].asm

This file was deleted.

40 changes: 23 additions & 17 deletions th01/main/player/bomb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,15 @@ bool16 bomb_update_and_render(int frame)
KEYFRAME_DONE = 140,
};

#define palette_flash_peak_ bomb_palette_flash_peak_
#define palette_flash_bright bomb_palette_flash_bright
#define white_to_blue_speed bomb_white_to_blue_speed
#define entity bomb_entity

extern const Palette4 palette_flash_peak_;

// Only uses its V_WHITE value. MODDERS: Reduce to a single RGB4 value.
extern Palette4 palette_white;
// ZUN bloat: Only uses its V_WHITE value.
static Palette4 palette_white;

extern Palette4 palette_flash_bright;
extern uint4_t white_to_blue_speed;
static Palette4 palette_flash_bright;
static uint4_t white_to_blue_speed;

extern struct {
static struct {
screen_x_t left[(KUJI_COUNT * KUJI_RINGS) + 9]; // yup, 9 extra
screen_y_t top[(KUJI_COUNT * KUJI_RINGS) + 9]; // yup, 9 extra
unsigned char angle; // should be local
Expand Down Expand Up @@ -75,7 +70,24 @@ bool16 bomb_update_and_render(int frame)
#define col i
#define comp j

Palette4 palette_flash_peak = palette_flash_peak_;
Palette4 palette_flash_peak = {
0xF, 0xF, 0xF, // 0
0xD, 0xD, 0xF, // 1
0xD, 0xD, 0xF, // 2
0xD, 0xD, 0xF, // 3
0xD, 0xD, 0xF, // 4
0xD, 0xD, 0xF, // 5
0xD, 0xD, 0xF, // 6
0xF, 0xF, 0xF, // 7 (V_WHITE)
0xD, 0xD, 0xF, // 8
0xD, 0xD, 0xF, // 9
0xD, 0xD, 0xF, // 10
0xD, 0xD, 0xF, // 11
0xD, 0xD, 0xF, // 12
0xD, 0xD, 0xF, // 13
0xD, 0xD, 0xF, // 14
0x6, 0x6, 0xF, // 15
};

player_invincible = true;
if(frame == 0) {
Expand Down Expand Up @@ -232,10 +244,4 @@ bool16 bomb_update_and_render(int frame)

#undef comp
#undef col

#undef entity
#undef white_to_blue_speed
#undef palette_flash_bright
#undef palette_white
#undef bomb_palette_flash_peak_
}
31 changes: 15 additions & 16 deletions th01/main/player/gameover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ void player_gameover_animate(void)
EFFECT_SPEED = 8,
};

struct hack { bool16 x[EFFECT_COUNT]; }; // XXX
extern const struct hack PLAYER_GAMEOVER_EFFECT_CLIPPED;

int i;
int j;
screen_x_t left[EFFECT_COUNT];
screen_y_t top[EFFECT_COUNT];
struct hack clipped = PLAYER_GAMEOVER_EFFECT_CLIPPED;
bool16 clipped[EFFECT_COUNT] = { false };

#define frame j

Expand All @@ -36,16 +33,18 @@ void player_gameover_animate(void)
z_vsync_wait_and_scrollup(RES_Y - ((j % 2) * 8));
for(i = 0; i < EFFECT_COUNT; i++) {
// ZUN bug: Indexing [clipped] with [frame] rather than [i],
// leading to a out-of-bounds read from frame 5 on.
if(!clipped.x[frame]) {
// Sloppy unblitting is actually a good choice here, since
// Reimu's sprite has also been blitted to VRAM page 1 above,
// and we're inside a blocking animation anyway. But this ends
// up unblitting a rectangle around Reimu with a constant
// height of 32 pixels and only growing on the X axis… OK. It
// probably wasn't meant to "correctly" unblit each effect
// sprite as you would usually expect, as that would look
// rather wimpy in comparison.
// leading to a out-of-bounds read from frame 5 on. In the original
// game, this ends up accessing [top] and [left], whose positions
// can never be 0.
if(!clipped[frame]) {
// ZUN quirk: Sloppy unblitting is actually a good choice here,
// since Reimu's sprite has also been blitted to VRAM page 1
// above, and we're inside a blocking animation anyway. But
// this ends up unblitting a rectangle around Reimu with a
// constant height of 32 pixels and only growing on the X
// axis... Then again, it probably wasn't meant to "correctly"
// unblit each effect sprite as you would usually expect, as
// that would look rather wimpy in comparison.
ptn_sloppy_unput_16(left[i], player_top);
}
}
Expand Down Expand Up @@ -73,9 +72,9 @@ void player_gameover_animate(void)
(left[i] >= (PLAYFIELD_RIGHT - PTN_W)) ||
(left[i] < PLAYFIELD_LEFT)
) {
clipped.x[i] = true;
clipped[i] = true;
}
if(!clipped.x[i]) {
if(!clipped[i]) {
ptn_put_8(left[i], top[i], (PTN_MISS_EFFECT + (frame % 2)));
}
}
Expand Down
6 changes: 2 additions & 4 deletions th01/main/player/inv_spr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ static const int INVINCIBILITY_SPRITES_DONE = 0xFF;
void invincibility_sprites_update_and_render(bool16 invincible)
{
int i;
extern struct {
static struct {
int frame[INVINCIBILITY_SPRITE_COUNT];
screen_x_t left[INVINCIBILITY_SPRITE_COUNT];
vram_y_t top[INVINCIBILITY_SPRITE_COUNT];
} invincibility_sprites;
#define sprites invincibility_sprites
} sprites;

if(!invincible) {
if(sprites.frame[0] == INVINCIBILITY_SPRITES_DONE) {
Expand Down Expand Up @@ -59,5 +58,4 @@ void invincibility_sprites_update_and_render(bool16 invincible)
}
sprites.frame[i]++;
}
#undef sprites
}
7 changes: 0 additions & 7 deletions th01/main/player/inv_spr[bss].asm

This file was deleted.

11 changes: 5 additions & 6 deletions th01/main/player/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ static const int PLAYER_MISS_INVINCIBILITY_FRAMES = 150;

extern screen_x_t player_left;
static const screen_y_t player_top = (PLAYFIELD_BOTTOM - PLAYER_H);
extern bool player_deflecting;
extern bool player_sliding;
extern bool player_is_hit;
extern bool16 player_invincible;
extern int player_invincibility_time;

inline screen_x_t player_center_x(void) {
return (player_left + (PLAYER_W / 2));
Expand Down Expand Up @@ -70,12 +75,6 @@ inline void player_reset(void) {
// to calling this function.
void player_miss_animate_and_update(void);

extern bool player_deflecting;
extern bool player_sliding;
extern bool player_is_hit;
extern bool16 player_invincible;
extern int player_invincibility_time;

extern int lives;
extern int cardcombo_cur;
extern int cardcombo_max;
12 changes: 0 additions & 12 deletions th01/main/player/player[bss].asm

This file was deleted.

17 changes: 17 additions & 0 deletions th01/main/player/shot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ struct CShots {
bool moving[SHOT_COUNT];
unsigned char decay_frame[SHOT_COUNT];

CShots() {
unknown[0] = 0x50;
unknown[1] = 0x60;
unknown[2] = 0x70;

// ZUN bloat: Why no loop?
static_assert(SHOT_COUNT == 8);
moving[0] = false;
moving[1] = false;
moving[2] = false;
moving[3] = false;
moving[4] = false;
moving[5] = false;
moving[6] = false;
moving[7] = false;
}

void add(screen_x_t new_left, screen_y_t new_top);
void unput_and_reset(void);
void unput_update_render(void);
Expand Down
12 changes: 0 additions & 12 deletions th01/main/player/shot[bss].asm

This file was deleted.

5 changes: 0 additions & 5 deletions th01/main/stage/stageobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
// Globals
// -------

struct stage_t {
StupidBytewiseWrapperAround<stagedat_stage_t> dat;
int8_t padding[5];
};

// ZUN bloat: The scene data is immediately converted to an internal
// representation anyway. This could have easily been a local variable… then
// again, storing it in global data is what gives negative "glitch stages"
Expand Down
7 changes: 7 additions & 0 deletions th01/main/stage/stageobj.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ void obstacles_update_and_render(bool16 reset);
// Initialization
// --------------

#ifdef DECOMP_HPP
struct stage_t {
StupidBytewiseWrapperAround<stagedat_stage_t> dat;
int8_t padding[5];
};
#endif

// Copies all stage objects from VRAM page 0 to VRAM page 1.
void stageobjs_copy_0_to_1(int stage_id);

Expand Down
13 changes: 13 additions & 0 deletions th01/main/vars.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "platform.h"
#include "th01/formats/cfg.hpp"
#include "th01/main/vars.hpp"
#include "th01/main/stage/stages.hpp"
#include "th01/main/stage/timer.hpp"

int8_t rank = CFG_RANK_DEFAULT;
int8_t bgm_mode = CFG_BGM_MODE_DEFAULT;
int8_t bombs = CFG_BOMBS_DEFAULT;
int8_t lives_extra = CFG_LIVES_EXTRA_DEFAULT;

int8_t stage_num = 0;
bool bgm_change_blocked = false;
Loading

0 comments on commit 65ce434

Please sign in to comment.