[Decompilation] [th04] Player: Input → movement velocity

That's not nice to the call site!

Part of P0228, funded by [Anonymous] and nrook.
This commit is contained in:
nmlgc 2023-01-09 02:49:30 +01:00
parent bfd24c6ae3
commit a31c5a4a4f
9 changed files with 79 additions and 131 deletions

View File

@ -126,7 +126,7 @@ bin\th04\op.exe: bin\th04\op.obj th04\m_char.cpp bin\th01\vplanset.obj bin\th02\
$**
|
bin\th04\main.exe: bin\th04\main.obj bin\th04\slowdown.obj th04\demo.cpp th04\ems.cpp th04\playfld.cpp th04\f_dialog.cpp th04\dialog.cpp bin\th04\player_p.obj bin\th04\scoreupd.obj th04\hud_ovrl.cpp bin\th04\cfg_lres.obj bin\th04\mb_inv.obj bin\th04\boss_bd.obj bin\th01\vplanset.obj bin\th03\vector2.obj bin\th02\frmdely1.obj bin\th03\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\midboss.cpp bin\th04\hud_hp.obj th04\mb_dft.cpp bin\th04\vector2n.obj bin\th04\spark_a.obj bin\th04\grcg_3.obj bin\th04\it_spl_u.obj th04\boss_4m.cpp th04\bullet_u.cpp th04\bullet_a.cpp th04\boss.cpp th04\boss_4r.cpp th04\boss_x2.cpp
bin\th04\main.exe: bin\th04\main.obj bin\th04\slowdown.obj th04\demo.cpp th04\ems.cpp th04\playfld.cpp th04\f_dialog.cpp th04\dialog.cpp th04\player_m.cpp bin\th04\player_p.obj bin\th04\scoreupd.obj th04\hud_ovrl.cpp bin\th04\cfg_lres.obj bin\th04\mb_inv.obj bin\th04\boss_bd.obj bin\th01\vplanset.obj bin\th03\vector2.obj bin\th02\frmdely1.obj bin\th03\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\midboss.cpp bin\th04\hud_hp.obj th04\mb_dft.cpp bin\th04\vector2n.obj bin\th04\spark_a.obj bin\th04\grcg_3.obj bin\th04\it_spl_u.obj th04\boss_4m.cpp th04\bullet_u.cpp th04\bullet_a.cpp th04\boss.cpp th04\boss_4r.cpp th04\boss_x2.cpp
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -DGAME=4 -DBINARY='M' -3 -Z -nbin\th04\ -eMAIN.EXE @&&|
$**
|

View File

@ -1,117 +0,0 @@
; move_ret_t pascal near player_move(int input);
public PLAYER_MOVE
player_move proc near
@@input_local = word ptr -2
@@input = word ptr 4
enter 2, 0
mov dl, MOVE_VALID
mov ax, [bp+@@input]
mov [bp+@@input_local], ax
mov cx, @@num_cases
mov bx, offset @@switch_table
@@case_lookup:
mov ax, cs:[bx]
cmp ax, [bp+@@input_local]
jz short @@switch
add bx, 2
loop @@case_lookup
jmp short @@default
; ---------------------------------------------------------------------------
@@switch:
jmp word ptr cs:[bx+@@case_to_target] ; switch jump
@@standing_still:
mov dl, MOVE_NOINPUT
jmp short @@ret
; ---------------------------------------------------------------------------
@@left:
mov _player_pos.velocity.x, -playchar_speed_aligned
jmp short @@ret
; ---------------------------------------------------------------------------
@@down_left:
mov _player_pos.velocity.x, -playchar_speed_diagonal
mov _player_pos.velocity.y, playchar_speed_diagonal
jmp short @@ret
; ---------------------------------------------------------------------------
@@down:
mov _player_pos.velocity.y, playchar_speed_aligned
jmp short @@ret
; ---------------------------------------------------------------------------
@@down_right:
mov _player_pos.velocity.x, playchar_speed_diagonal
mov _player_pos.velocity.y, playchar_speed_diagonal
jmp short @@ret
; ---------------------------------------------------------------------------
@@right:
mov _player_pos.velocity.x, playchar_speed_aligned
jmp short @@ret
; ---------------------------------------------------------------------------
@@up_right:
mov _player_pos.velocity.x, playchar_speed_diagonal
jmp short @@up_left_y
; ---------------------------------------------------------------------------
@@up:
mov _player_pos.velocity.y, -playchar_speed_aligned
jmp short @@ret
; ---------------------------------------------------------------------------
@@up_left:
mov _player_pos.velocity.x, -playchar_speed_diagonal
@@up_left_y:
mov _player_pos.velocity.y, -playchar_speed_diagonal
jmp short @@ret
; ---------------------------------------------------------------------------
@@default:
mov dl, MOVE_INVALID
@@ret:
mov al, dl
leave
retn 2
; ---------------------------------------------------------------------------
db 0
@@switch_table label word
; value table for switch statement
dw INPUT_NONE
dw INPUT_UP
dw INPUT_DOWN
dw INPUT_LEFT
dw INPUT_UP or INPUT_LEFT
dw INPUT_DOWN or INPUT_LEFT
dw INPUT_RIGHT
dw INPUT_UP or INPUT_RIGHT
dw INPUT_DOWN or INPUT_RIGHT
dw INPUT_UP_LEFT
dw INPUT_UP_RIGHT
dw INPUT_DOWN_LEFT
dw INPUT_DOWN_RIGHT
@@case_to_target = $ - @@switch_table
@@num_cases = @@case_to_target shr 1
; jump table for switch statement
dw offset @@standing_still
dw offset @@up
dw offset @@down
dw offset @@left
dw offset @@up_left
dw offset @@down_left
dw offset @@right
dw offset @@up_right
dw offset @@down_right
dw offset @@up_left
dw offset @@up_right
dw offset @@down_left
dw offset @@down_right
player_move endp

45
th04/main/player/move.cpp Normal file
View File

@ -0,0 +1,45 @@
#pragma option -zPmain_01
#include "platform.h"
#include "pc98.h"
#include "th01/math/subpixel.hpp"
#include "th04/math/motion.hpp"
#include "th04/hardware/inputvar.h"
#include "th04/main/playfld.hpp"
#include "th04/main/player/player.hpp"
#include "th04/main/player/move.hpp"
#pragma option -a2
inline void move(int direction_x, int direction_y) {
if((direction_x != 0) && (direction_y != 0)) {
player_pos.velocity.x.v = (direction_x * playchar_speed_diagonal);
player_pos.velocity.y.v = (direction_y * playchar_speed_diagonal);
} else if(direction_x != 0) {
player_pos.velocity.x.v = (direction_x * playchar_speed_aligned);
} else if(direction_y != 0) {
player_pos.velocity.y.v = (direction_y * playchar_speed_aligned);
}
}
move_ret_t pascal near player_move(input_t input)
{
move_ret_t ret = MOVE_VALID;
switch(input) {
case INPUT_NONE: ret = MOVE_NOINPUT; break;
case INPUT_LEFT: move(-1, 0); break;
case (INPUT_DOWN | INPUT_LEFT):
case INPUT_DOWN_LEFT: move(-1, +1); break;
case INPUT_DOWN: move( 0, +1); break;
case (INPUT_DOWN | INPUT_RIGHT):
case INPUT_DOWN_RIGHT: move(+1, +1); break;
case INPUT_RIGHT: move(+1, 0); break;
case (INPUT_UP | INPUT_RIGHT):
case INPUT_UP_RIGHT: move(+1, -1); break;
case INPUT_UP: move( 0, -1); break;
case (INPUT_UP | INPUT_LEFT):
case INPUT_UP_LEFT: move(-1, -1); break;
default: ret = MOVE_INVALID; break;
}
return ret;
}

19
th04/main/player/move.hpp Normal file
View File

@ -0,0 +1,19 @@
// All values are signed. (Yes, allowing you to invert the controls with
// negative values!)
#if (GAME == 5)
extern subpixel_t playchar_speed_aligned;
extern subpixel_t playchar_speed_diagonal;
#else
static const subpixel_t playchar_speed_aligned = TO_SP(4);
static const subpixel_t playchar_speed_diagonal = TO_SP(3);
#endif
enum move_ret_t {
MOVE_INVALID = 0,
MOVE_VALID = 1,
MOVE_NOINPUT = 2,
};
// Applies the given [input] to the player's velocity. Both games assume
// [player_pos.velocity] to be (0, 0) prior to calling this function.
move_ret_t pascal near player_move(input_t input);

1
th04/player_m.cpp Normal file
View File

@ -0,0 +1 @@
#include "th04/main/player/move.cpp"

View File

@ -48,7 +48,4 @@ resident_t struc
db 54 dup(?)
resident_t ends
playchar_speed_aligned = 4 shl 4
playchar_speed_diagonal = 3 shl 4
BOMB_INVINCIBILITY_FRAMES = 255

View File

@ -43,7 +43,7 @@ include th04/main/enemy/enemy.inc
extern _tolower:proc
extern __ctype:byte
main_01 group SLOWDOWN_TEXT, ma_TEXT, DEMO_TEXT, EMS_TEXT, mai_TEXT, PLAYFLD_TEXT, main_TEXT, DIALOG_TEXT, main__TEXT, PLAYER_P_TEXT, main_0_TEXT, HUD_OVRL_TEXT, main_01_TEXT, main_012_TEXT, CFG_LRES_TEXT, main_013_TEXT, MB_INV_TEXT, BOSS_BD_TEXT, BOSS_BG_TEXT
main_01 group SLOWDOWN_TEXT, ma_TEXT, DEMO_TEXT, EMS_TEXT, mai_TEXT, PLAYFLD_TEXT, main_TEXT, DIALOG_TEXT, main__TEXT, PLAYER_M_TEXT, PLAYER_P_TEXT, main_0_TEXT, HUD_OVRL_TEXT, main_01_TEXT, main_012_TEXT, CFG_LRES_TEXT, main_013_TEXT, MB_INV_TEXT, BOSS_BD_TEXT, BOSS_BG_TEXT
g_SHARED group SHARED, SHARED_
main_03 group GATHER_TEXT, SCROLLY3_TEXT, MOTION_3_TEXT, main_032_TEXT, VECTOR2N_TEXT, SPARK_A_TEXT, GRCG_3_TEXT, IT_SPL_U_TEXT, B4M_UPDATE_TEXT, main_033_TEXT, MIDBOSS_TEXT, HUD_HP_TEXT, MB_DFT_TEXT, main_034_TEXT, BULLET_U_TEXT, BULLET_A_TEXT, main_035_TEXT, BOSS_TEXT, main_036_TEXT
@ -8661,9 +8661,13 @@ loc_10704:
include th04/main/enemy/render.asm
include th04/main/player/invalidate.asm
include th04/main/player/move.asm
main__TEXT ends
PLAYER_M_TEXT segment byte public 'CODE' use16
@PLAYER_MOVE$QUI procdesc pascal near \
input:word
PLAYER_M_TEXT ends
PLAYER_P_TEXT segment byte public 'CODE' use16
_player_pos_update_and_clamp procdesc near
PLAYER_P_TEXT ends
@ -8830,9 +8834,9 @@ loc_10B11:
mov [bp+var_1], 1
loc_10B32:
call main_01:player_move pascal, si
call @player_move$qui pascal, si
mov [bp+@@move_ret], al
cmp [bp+@@move_ret], 0
cmp [bp+@@move_ret], MOVE_INVALID
jnz short loc_10B58
cmp [bp+var_1], 0
jz short loc_10B58

View File

@ -84,9 +84,8 @@ PLAYER_INVALIDATE endp
even
; move_ret_t pascal near player_move(int input);
public PLAYER_MOVE
PLAYER_MOVE proc near
public @PLAYER_MOVE$QUI
@player_move$qui proc near
arg_bx near, @input:word
@@diagonal_x equ ax
@ -183,7 +182,7 @@ arg_bx near, @input:word
dw @@invalid
dw @@invalid
dw @@down_right
PLAYER_MOVE endp
@player_move$qui endp
MAIN_01_TEXT ends
end

View File

@ -7050,7 +7050,7 @@ loc_12188:
mov [bp+var_1], 1
loc_121A9:
call player_move pascal, si
call @player_move$qui pascal, si
or al, al
jnz short loc_121CA
cmp [bp+var_1], 0
@ -7818,7 +7818,7 @@ sub_12842 endp
SHOT_YUUKA_L8 procdesc pascal near
SHOT_YUUKA_L9 procdesc pascal near
PLAYER_INVALIDATE procdesc pascal near
PLAYER_MOVE procdesc pascal near \
@PLAYER_MOVE$QUI procdesc pascal near \
input:word
HUD_BAR_PUT procdesc near
HUD_SCORE_PUT procdesc near