Skip to content

Commit

Permalink
[Decompilation] [th04/th05] Player position clamping
Browse files Browse the repository at this point in the history
Completes P0148, funded by [Anonymous].
  • Loading branch information
nmlgc committed Jul 20, 2021
1 parent 5392030 commit e1a26bb
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 52 deletions.
4 changes: 2 additions & 2 deletions Makefile.mak
Expand Up @@ -138,7 +138,7 @@ bin\th04\op.exe: bin\th04\op.obj th04\m_char.cpp bin\th01\vplanset.obj bin\frmde
$**
|

bin\th04\main.exe: bin\th04\main.obj bin\th04\scoreupd.obj th04\main011.cpp bin\th04\cfg_lres.obj bin\th01\vplanset.obj bin\th03\vector2.obj bin\frmdely1.obj bin\hfliplut.obj th04\mpn_free.cpp bin\th04\input_w.obj th04\mpn_l_i.cpp bin\th04\vector.obj bin\th04\snd_pmdr.obj bin\th04\snd_mmdr.obj bin\th04\snd_kaja.obj bin\th04\snd_mode.obj bin\th04\snd_load.obj bin\th04\cdg_put.obj bin\th04\exit.obj bin\th04\initmain.obj bin\th04\cdg_p_na.obj bin\th04\cdg_p_pr.obj bin\th04\input_s.obj bin\th04\snd_se_r.obj bin\th04\snd_se.obj bin\th04\cdg_load.obj th04\gather.cpp bin\th04\scrolly3.obj bin\th04\motion_3.obj th04\main032.cpp
bin\th04\main.exe: bin\th04\main.obj bin\th04\player_p.obj bin\th04\scoreupd.obj th04\main011.cpp bin\th04\cfg_lres.obj bin\th01\vplanset.obj bin\th03\vector2.obj bin\frmdely1.obj bin\hfliplut.obj th04\mpn_free.cpp bin\th04\input_w.obj th04\mpn_l_i.cpp bin\th04\vector.obj bin\th04\snd_pmdr.obj bin\th04\snd_mmdr.obj bin\th04\snd_kaja.obj bin\th04\snd_mode.obj bin\th04\snd_load.obj bin\th04\cdg_put.obj bin\th04\exit.obj bin\th04\initmain.obj bin\th04\cdg_p_na.obj bin\th04\cdg_p_pr.obj bin\th04\input_s.obj bin\th04\snd_se_r.obj bin\th04\snd_se.obj bin\th04\cdg_load.obj th04\gather.cpp bin\th04\scrolly3.obj bin\th04\motion_3.obj th04\main032.cpp
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -DGAME=4 -DBINARY='M' -3 -Z -nbin\th04\ -eMAIN.EXE @&&|
$**
|
Expand All @@ -161,7 +161,7 @@ bin\th05\op.exe: th05\op010.cpp bin\th05\op.obj th05\op011.cpp th05\m_char.cpp b
$**
|

bin\th05\main.exe: bin\th05\main.obj bin\th05\cfg_lres.obj th05\main010.cpp th05\main011.cpp 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 th05\main013.cpp bin\th03\vector2.obj bin\hfliplut.obj bin\th04\snd_pmdr.obj bin\th04\snd_mmdr.obj bin\th04\snd_mode.obj bin\th05\bullet.obj bin\th04\cdg_p_na.obj bin\th04\snd_se_r.obj bin\th04\snd_se.obj bin\th05\cdg_put.obj bin\th04\exit.obj bin\th05\vector.obj bin\th05\snd_load.obj bin\th05\snd_kaja.obj bin\th05\initmain.obj bin\th05\input_s.obj bin\th05\inp_h_w.obj bin\th05\frmdelay.obj bin\th04\cdg_load.obj bin\th04\scrolly3.obj bin\th04\motion_3.obj th05\main031.cpp th05\gather.cpp th05\main032.cpp th05\main033.cpp th05\main034.cpp
bin\th05\main.exe: bin\th05\main.obj bin\th05\cfg_lres.obj th05\main010.cpp th05\main011.cpp 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\th04\player_p.obj th05\main013.cpp bin\th03\vector2.obj bin\hfliplut.obj bin\th04\snd_pmdr.obj bin\th04\snd_mmdr.obj bin\th04\snd_mode.obj bin\th05\bullet.obj bin\th04\cdg_p_na.obj bin\th04\snd_se_r.obj bin\th04\snd_se.obj bin\th05\cdg_put.obj bin\th04\exit.obj bin\th05\vector.obj bin\th05\snd_load.obj bin\th05\snd_kaja.obj bin\th05\initmain.obj bin\th05\input_s.obj bin\th05\inp_h_w.obj bin\th05\frmdelay.obj bin\th04\cdg_load.obj bin\th04\scrolly3.obj bin\th04\motion_3.obj th05\main031.cpp th05\gather.cpp th05\main032.cpp th05\main033.cpp th05\main034.cpp
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -3 -Z -DGAME=5 -DBINARY='M' -nbin\th05\ -eMAIN.EXE @&&|
$**
|
Expand Down
6 changes: 1 addition & 5 deletions th04/main/player/player.h
@@ -1,8 +1,4 @@
#include "th02/main/player/player.h"
#define PLAYER_MOVE_MARGIN_LEFT 8
#define PLAYER_MOVE_MARGIN_TOP 8
#define PLAYER_MOVE_MARGIN_RIGHT 8
#define PLAYER_MOVE_MARGIN_BOTTOM 16

#define PLAYER_OPTION_W 16
#define PLAYER_OPTION_H 16
Expand All @@ -12,7 +8,7 @@
extern unsigned int stage_graze;
extern motion_t player_pos;

void pascal near player_pos_update_and_clamp(void);
void near player_pos_update_and_clamp(void);

// Shots
// -----
Expand Down
4 changes: 0 additions & 4 deletions th04/main/player/player.inc
@@ -1,8 +1,4 @@
include th02/main/player/player.inc
PLAYER_MOVE_MARGIN_LEFT = 8
PLAYER_MOVE_MARGIN_TOP = 8
PLAYER_MOVE_MARGIN_RIGHT = 8
PLAYER_MOVE_MARGIN_BOTTOM = 16
PLAYER_OPTION_W = 16
PLAYER_OPTION_H = 16
PLAYER_OPTION_DISTANCE = (PLAYER_W / 2) + (PLAYER_OPTION_W / 2)
Expand Down
35 changes: 35 additions & 0 deletions th04/main/player/pos.cpp
@@ -0,0 +1,35 @@
#pragma option -zPmain_01

extern "C" {
#include "platform.h"
#include "pc98.h"
#include "th01/math/subpixel.hpp"
#include "th04/math/motion.hpp"
#include "th04/main/playfld.hpp"
#include "th04/main/player/player.h"

static const pixel_t MOVE_MARGIN_LEFT = 8;
static const pixel_t MOVE_MARGIN_TOP = 8;
static const pixel_t MOVE_MARGIN_RIGHT = 8;
static const pixel_t MOVE_MARGIN_BOTTOM = 16;

#define clamp(v, min, max) \
/* Sneaky! That's how we can pretend this is an actual function that */ \
/* returns a value. */ \
v; \
if(static_cast<subpixel_t>(v) < to_sp(min)) { \
v = to_sp(min); \
} else if(static_cast<subpixel_t>(v) > to_sp(max)) { \
v = to_sp(max); \
}

void near player_pos_update_and_clamp(void)
{
/* _DX:_AX = */ motion_update_seg1(player_pos);
_AX = clamp(_AX, (0 + MOVE_MARGIN_LEFT), (PLAYFIELD_W - MOVE_MARGIN_RIGHT));
_DX = clamp(_DX, (0 + MOVE_MARGIN_TOP), (PLAYFIELD_H - MOVE_MARGIN_BOTTOM));
player_pos.cur.x.v = _AX;
player_pos.cur.y.v = _DX;
}

}
34 changes: 0 additions & 34 deletions th04/main/player/pos_update_and_clamp.asm

This file was deleted.

1 change: 1 addition & 0 deletions th04/player_p.cpp
@@ -0,0 +1 @@
#include "th04/main/player/pos.cpp"
14 changes: 10 additions & 4 deletions th04_main.asm
Expand Up @@ -44,7 +44,7 @@ include th04/main/enemy/enemy.inc
extern __ctype:byte

.seq
main_01 group main_0_TEXT, main_01_TEXT, main_012_TEXT, CFG_LRES_TEXT, main_013_TEXT
main_01 group main__TEXT, PLAYER_P_TEXT, main_0_TEXT, main_01_TEXT, main_012_TEXT, CFG_LRES_TEXT, main_013_TEXT
g_SHARED group SHARED, SHARED_
main_03 group GATHER_TEXT, SCROLLY3_TEXT, MOTION_3_TEXT, main_032_TEXT, main_033_TEXT

Expand Down Expand Up @@ -267,7 +267,7 @@ _TEXT ends
; ===========================================================================

; Segment type: Pure code
main_0_TEXT segment word public 'CODE' use16
main__TEXT segment word public 'CODE' use16
assume cs:main_01
;org 1
assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing
Expand Down Expand Up @@ -9364,7 +9364,13 @@ sub_105B9 endp
include th04/main/enemy/render.asm
include th04/main/player/invalidate.asm
include th04/main/player/move.asm
include th04/main/player/pos_update_and_clamp.asm
main__TEXT ends

PLAYER_P_TEXT segment byte public 'CODE' use16
_player_pos_update_and_clamp procdesc near
PLAYER_P_TEXT ends

main_0_TEXT segment word public 'CODE' use16

; =============== S U B R O U T I N E =======================================

Expand Down Expand Up @@ -9556,7 +9562,7 @@ loc_10B58:
mov _player_pos.velocity.y, ax

loc_10B75:
call main_01:player_pos_update_and_clamp
call _player_pos_update_and_clamp
cmp [bp+var_1], 0
jz short loc_10B82
mov word_2598C, si
Expand Down
9 changes: 6 additions & 3 deletions th05_main.asm
Expand Up @@ -37,7 +37,7 @@ include th05/main/enemy/enemy.inc
extern _strlen:proc

.seq
main_01 group mai_TEXT, CFG_LRES_TEXT, main_TEXT, main__TEXT, main_0_TEXT, main_01_TEXT
main_01 group mai_TEXT, CFG_LRES_TEXT, main_TEXT, main__TEXT, main_0_TEXT, PLAYER_P_TEXT, main_01_TEXT
g_SHARED group SHARED, SHARED_
main_03 group SCROLLY3_TEXT, MOTION_3_TEXT, main_031_TEXT, main_032_TEXT, main_033_TEXT, main_034_TEXT, main_035_TEXT

Expand Down Expand Up @@ -8320,8 +8320,11 @@ main_0_TEXT ends
POPUP_BOSS_BGM_UPDATE_AND_RENDER procdesc near
POPUP_UPDATE_AND_RENDER procdesc near

PLAYER_P_TEXT segment byte public 'CODE' use16
_player_pos_update_and_clamp procdesc near
PLAYER_P_TEXT ends

main_01_TEXT segment byte public 'CODE' use16
include th04/main/player/pos_update_and_clamp.asm

; =============== S U B R O U T I N E =======================================

Expand Down Expand Up @@ -8506,7 +8509,7 @@ loc_121CA:
mov _player_pos.velocity.y, ax

loc_121E7:
call player_pos_update_and_clamp
call _player_pos_update_and_clamp
cmp [bp+var_1], 0
jz short loc_121F4
mov word_2CE9E, si
Expand Down

0 comments on commit e1a26bb

Please sign in to comment.