From 8d953dc42e1b31eee572299475c6012e68490992 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Sat, 3 Apr 2021 20:12:08 +0200 Subject: [PATCH] [Decompilation] [th03/th04/th05] 2D direction vector construction Hey, a disgustingly impossible "decompilation" again, for a change! Completes P0137, funded by [Anonymous]. --- Makefile.mak | 10 +++--- th02/math/{vector.cpp => vector2.cpp} | 0 th02/vector.cpp | 1 - th02/vector2.cpp | 1 + th03/math/vector.hpp | 15 ++------ th03/math/vector1.cpp | 2 ++ th03/math/vector2.asm | 32 ----------------- th03/math/vector2.cpp | 50 +++++++++++++++++++++++++++ th03/math/vector2_between_plus.asm | 44 ----------------------- th03/vector2.cpp | 1 + th03_main.asm | 5 ++- th03_mainl.asm | 4 +-- th04_main.asm | 4 +-- th05_main.asm | 8 ++--- 14 files changed, 67 insertions(+), 110 deletions(-) rename th02/math/{vector.cpp => vector2.cpp} (100%) delete mode 100644 th02/vector.cpp create mode 100644 th02/vector2.cpp delete mode 100644 th03/math/vector2.asm create mode 100644 th03/math/vector2.cpp delete mode 100644 th03/math/vector2_between_plus.asm create mode 100644 th03/vector2.cpp diff --git a/Makefile.mak b/Makefile.mak index c57f0c33..77d4b5a0 100644 --- a/Makefile.mak +++ b/Makefile.mak @@ -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 @&&| $** | diff --git a/th02/math/vector.cpp b/th02/math/vector2.cpp similarity index 100% rename from th02/math/vector.cpp rename to th02/math/vector2.cpp diff --git a/th02/vector.cpp b/th02/vector.cpp deleted file mode 100644 index 8dd3dbca..00000000 --- a/th02/vector.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "th02/math/vector.cpp" diff --git a/th02/vector2.cpp b/th02/vector2.cpp new file mode 100644 index 00000000..0107416a --- /dev/null +++ b/th02/vector2.cpp @@ -0,0 +1 @@ +#include "th02/math/vector2.cpp" diff --git a/th03/math/vector.hpp b/th03/math/vector.hpp index ce3178c6..4b43df61 100644 --- a/th03/math/vector.hpp +++ b/th03/math/vector.hpp @@ -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 -); diff --git a/th03/math/vector1.cpp b/th03/math/vector1.cpp index 221996fb..76264434 100644 --- a/th03/math/vector1.cpp +++ b/th03/math/vector1.cpp @@ -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) diff --git a/th03/math/vector2.asm b/th03/math/vector2.asm deleted file mode 100644 index 12a9c0ad..00000000 --- a/th03/math/vector2.asm +++ /dev/null @@ -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 diff --git a/th03/math/vector2.cpp b/th03/math/vector2.cpp new file mode 100644 index 00000000..6264d7fe --- /dev/null +++ b/th03/math/vector2.cpp @@ -0,0 +1,50 @@ +#pragma option -zCSHARED -3 + +extern "C" { +#include +#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(_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(_EAX * _EDX) >> 8); \ + ret_y = (static_cast(static_cast(_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); +} + +} diff --git a/th03/math/vector2_between_plus.asm b/th03/math/vector2_between_plus.asm deleted file mode 100644 index 7abce091..00000000 --- a/th03/math/vector2_between_plus.asm +++ /dev/null @@ -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 diff --git a/th03/vector2.cpp b/th03/vector2.cpp new file mode 100644 index 00000000..77ca3047 --- /dev/null +++ b/th03/vector2.cpp @@ -0,0 +1 @@ +#include "th03/math/vector2.cpp" diff --git a/th03_main.asm b/th03_main.asm index 4b9a8233..18d23732 100644 --- a/th03_main.asm +++ b/th03_main.asm @@ -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 diff --git a/th03_mainl.asm b/th03_mainl.asm index 21c50750..334a6705 100644 --- a/th03_mainl.asm +++ b/th03_mainl.asm @@ -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 diff --git a/th04_main.asm b/th04_main.asm index 9b4d01c5..e554dc8a 100644 --- a/th04_main.asm +++ b/th04_main.asm @@ -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 diff --git a/th05_main.asm b/th05_main.asm index eceffd93..32cc5b98 100644 --- a/th05_main.asm +++ b/th05_main.asm @@ -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