[Decompilation] [th03/th04/th05] 2D direction vector construction

Hey, a disgustingly impossible "decompilation" again, for a change!

Completes P0137, funded by [Anonymous].
This commit is contained in:
nmlgc 2021-04-03 20:12:08 +02:00
parent bda7b16758
commit 8d953dc42e
14 changed files with 67 additions and 110 deletions

View File

@ -85,7 +85,7 @@ bin\th02\op.exe: th02\op_01.cpp bin\exit_dos.obj bin\th02\zunerror.obj bin\th02\
$**
|
bin\th02\main.exe: bin\th02\main.obj bin\th02\zunerror.obj th02\main02_1.cpp bin\th02\pi_load.obj bin\th02\vector.obj bin\frmdely1.obj bin\th02\input_s.obj bin\th02\exit.obj bin\th02\snd_mmdr.obj bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th02\snd_dlyv.obj bin\th02\snd_load.obj th02\mptn_i.cpp bin\th02\initmain.obj bin\th02\pi_put.obj bin\th02\snd_kaja.obj bin\th02\snd_dlym.obj bin\th02\snd_se_r.obj bin\th02\snd_se.obj th02\main_03.cpp
bin\th02\main.exe: bin\th02\main.obj bin\th02\zunerror.obj th02\main02_1.cpp bin\th02\pi_load.obj bin\th02\vector2.obj bin\frmdely1.obj bin\th02\input_s.obj bin\th02\exit.obj bin\th02\snd_mmdr.obj bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th02\snd_dlyv.obj bin\th02\snd_load.obj th02\mptn_i.cpp bin\th02\initmain.obj bin\th02\pi_put.obj bin\th02\snd_kaja.obj bin\th02\snd_dlym.obj bin\th02\snd_se_r.obj bin\th02\snd_se.obj th02\main_03.cpp
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -Z -DGAME=2 -nbin\th02\ -eMAIN.EXE @&&|
$**
|
@ -110,12 +110,12 @@ bin\th03\op.exe: th03\op_01.cpp bin\th03\op.obj bin\th03\exit.obj bin\th03\vecto
$**
|
bin\th03\main.exe: bin\th03\main.obj th03\main_01.cpp bin\th03\exit.obj bin\th03\vector1.obj bin\frmdely1.obj bin\th03\input_s.obj bin\th02\snd_se_r.obj bin\th03\snd_se.obj bin\th03\snd_kaja.obj bin\th03\initmain.obj bin\th03\pi_load.obj bin\th03\inp_m_w.obj bin\hfliplut.obj th03\mrs.cpp th03\sprite16.cpp
bin\th03\main.exe: bin\th03\main.obj th03\main_01.cpp bin\th03\vector2.obj bin\th03\exit.obj bin\th03\vector1.obj bin\frmdely1.obj bin\th03\input_s.obj bin\th02\snd_se_r.obj bin\th03\snd_se.obj bin\th03\snd_kaja.obj bin\th03\initmain.obj bin\th03\pi_load.obj bin\th03\inp_m_w.obj bin\hfliplut.obj th03\mrs.cpp th03\sprite16.cpp
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -Z -DGAME=3 -nbin\th03\ -eMAIN.EXE @&&|
$**
|
bin\th03\mainl.exe: bin\th03\mainl.obj bin\th03\exit.obj bin\th03\cdg_put.obj bin\frmdely1.obj bin\th03\input_s.obj bin\th03\pi_put.obj bin\th03\pi_put_i.obj bin\th02\snd_se_r.obj bin\th03\snd_se.obj bin\th03\snd_kaja.obj bin\th03\initmain.obj bin\th03\cdg_load.obj th03\exitmain.cpp bin\th03\grppsafx.obj bin\th03\snd_dlym.obj bin\th03\inp_wait.obj bin\th03\pi_load.obj bin\th03\pi_put_q.obj bin\th03\inp_m_w.obj bin\th03\cdg_p_na.obj bin\hfliplut.obj
bin\th03\mainl.exe: bin\th03\mainl.obj bin\th03\vector2.obj bin\th03\exit.obj bin\th03\cdg_put.obj bin\frmdely1.obj bin\th03\input_s.obj bin\th03\pi_put.obj bin\th03\pi_put_i.obj bin\th02\snd_se_r.obj bin\th03\snd_se.obj bin\th03\snd_kaja.obj bin\th03\initmain.obj bin\th03\cdg_load.obj th03\exitmain.cpp bin\th03\grppsafx.obj bin\th03\snd_dlym.obj bin\th03\inp_wait.obj bin\th03\pi_load.obj bin\th03\pi_put_q.obj bin\th03\inp_m_w.obj bin\th03\cdg_p_na.obj bin\hfliplut.obj
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -DGAME=3 -nbin\th03\ -eMAINL.EXE @&&|
$**
|
@ -138,7 +138,7 @@ bin\th04\op.exe: bin\th04\op.obj th04\m_char.cpp bin\th04\exit.obj bin\th04\init
$**
|
bin\th04\main.exe: bin\th04\main.obj bin\th04\scoreupd.obj th04\main011.cpp bin\th04\exit.obj bin\frmdely1.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 bin\hfliplut.obj th04\main032.cpp
bin\th04\main.exe: bin\th04\main.obj bin\th04\scoreupd.obj th04\main011.cpp bin\th03\vector2.obj bin\th04\exit.obj bin\frmdely1.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 bin\hfliplut.obj th04\main032.cpp
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -DGAME=4 -DBINARY='M' -3 -Z -nbin\th04\ -eMAIN.EXE @&&|
$**
|
@ -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 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\hfliplut.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 th05\main031.cpp th05\main032.cpp th05\main033.cpp th05\main034.cpp
bin\th05\main.exe: bin\th05\main.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\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 th05\main031.cpp th05\main032.cpp th05\main033.cpp th05\main034.cpp
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -3 -Z -DGAME=5 -DBINARY='M' -nbin\th05\ -eMAIN.EXE @&&|
$**
|

View File

@ -1 +0,0 @@
#include "th02/math/vector.cpp"

1
th02/vector2.cpp Normal file
View File

@ -0,0 +1 @@
#include "th02/math/vector2.cpp"

View File

@ -1,17 +1,6 @@
#include "th02/math/vector.hpp"
#if GAME == 3
// (different calling convention than the TH04/TH05 one)
int __cdecl vector1_at(int origin, int length, int angle);
#endif
int pascal vector2(int &ret_x, int &ret_y, unsigned char angle, int length);
int pascal vector2_between_plus(
int x1,
int y1,
int x2,
int y2,
unsigned char plus_angle,
int &ret_x,
int &ret_y,
int length
);

View File

@ -1,6 +1,8 @@
#pragma option -zCSHARED -3
extern "C" {
#include "platform.h"
#include "pc98.h"
#include "th03/math/vector.hpp"
int vector1_at(int origin, int length, int angle)

View File

@ -1,32 +0,0 @@
public VECTOR2
vector2 proc far
@@r = word ptr 6
@@angle = byte ptr 8
@@_dy = dword ptr 0Ah
@@_dx = dword ptr 0Eh
push bp
mov bp, sp
push si
mov dl, [bp+@@angle]
mov si, [bp+@@r]
movsx eax, si
mov dh, 0
add dx, dx
mov bx, dx
movsx edx, _CosTable8[bx]
movsx ecx, _SinTable8[bx]
imul eax, edx
sar eax, 8
les bx, [bp+@@_dx]
mov es:[bx], ax
movsx eax, si
imul eax, ecx
sar eax, 8
les bx, [bp+@@_dy]
mov es:[bx], ax
pop si
pop bp
retf 0Ch
vector2 endp

50
th03/math/vector2.cpp Normal file
View File

@ -0,0 +1,50 @@
#pragma option -zCSHARED -3
extern "C" {
#include <stddef.h>
#include "platform.h"
#include "pc98.h"
#include "master.hpp"
#include "th01/math/vector.hpp"
#include "th03/math/vector.hpp"
// Completely disgusting. TH02's version was fine!
#define vector2_raw(ret_x, ret_y, angle, length) \
_DL = angle; \
_SI = length; \
_EAX = static_cast<int16_t>(_SI); \
_DH = 0; \
_DX += _DX; /* *= sizeof(short) */ \
_BX = _DX; \
__asm { \
db 0x66, 0x0F, 0xBF, 0x97; /* MOVSX EDX, */ \
dw offset CosTable8; /* CosTable8[bx]; */ \
db 0x66, 0x0F, 0xBF, 0x8F; /* MOVSX ECX, */ \
dw offset SinTable8; /* SinTable8[bx]; */ \
} \
ret_x = (static_cast<long>(_EAX * _EDX) >> 8); \
ret_y = (static_cast<long>(static_cast<int16_t>(_SI) * _ECX) >> 8);
void pascal vector2(int &ret_x, int &ret_y, unsigned char angle, int length)
{
vector2_raw(ret_x, ret_y, angle, length);
}
#pragma codestring "\x90"
void pascal vector2_between_plus(
int x1,
int y1,
int x2,
int y2,
unsigned char plus_angle,
int &ret_x,
int &ret_y,
int length
)
{
_SI = length;
vector2_raw(ret_x, ret_y, (iatan2((y2 - y1), (x2 - x1)) + plus_angle), _SI);
}
}

View File

@ -1,44 +0,0 @@
public VECTOR2_BETWEEN_PLUS
vector2_between_plus proc far
@@r = word ptr 6
@@_dx = dword ptr 8
@@_dy = dword ptr 0Ch
@@plus_angle = byte ptr 10h
@@y2 = word ptr 12h
@@x2 = word ptr 14h
@@y1 = word ptr 16h
@@x1 = word ptr 18h
push bp
mov bp, sp
push si
mov si, [bp+@@r]
mov ax, [bp+@@y2]
sub ax, [bp+@@y1]
push ax
mov ax, [bp+@@x2]
sub ax, [bp+@@x1]
push ax
call iatan2
add al, [bp+@@plus_angle]
mov dl, al
movsx eax, si
mov dh, 0
add dx, dx
mov bx, dx
movsx edx, _CosTable8[bx]
movsx ecx, _SinTable8[bx]
imul eax, edx
sar eax, 8
les bx, [bp+@@_dy]
mov es:[bx], ax
movsx eax, si
imul eax, ecx
sar eax, 8
les bx, [bp+@@_dx]
mov es:[bx], ax
pop si
pop bp
retf 14h
vector2_between_plus endp

1
th03/vector2.cpp Normal file
View File

@ -0,0 +1 @@
#include "th03/math/vector2.cpp"

View File

@ -8880,9 +8880,8 @@ include th01/hardware/vram_planes_set.asm
db 0
include th02/snd/detmode.asm
include th02/snd/pmd_res.asm
include th03/math/vector2.asm
nop
include th03/math/vector2_between_plus.asm
extern VECTOR2:proc
extern VECTOR2_BETWEEN_PLUS:proc
extern _game_exit:proc
extern _vector1_at:proc
extern FRAME_DELAY:proc

View File

@ -5519,9 +5519,7 @@ include th02/snd/detmode.asm
include th02/snd/pmd_res.asm
include th02/snd/delayvol.asm
include th02/snd/load.asm
include th03/math/vector2.asm
nop
include th03/math/vector2_between_plus.asm
extern VECTOR2:proc
extern _game_exit:proc
extern CDG_PUT_8:proc
extern CDG_PUT_HFLIP_8:proc

View File

@ -12977,9 +12977,7 @@ SHARED segment word public 'CODE' use16
assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing
include th01/hardware/vram_planes_set.asm
include th03/math/vector2.asm
nop
include th03/math/vector2_between_plus.asm
extern VECTOR2:proc
extern FRAME_DELAY:proc
SHARED ends

View File

@ -10541,12 +10541,8 @@ main_01_TEXT ends
; Segment type: Pure code
SHARED segment word public 'CODE' use16
assume cs:g_SHARED
;org 3
assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing
include th03/math/vector2.asm
nop
include th03/math/vector2_between_plus.asm
extern VECTOR2:proc
extern VECTOR2_BETWEEN_PLUS:proc
SHARED ends
SHARED_ segment word public 'CODE' use16