From 2777bae55b3849c1b36c6624e39e2bd5d4cace13 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Fri, 12 Feb 2021 17:39:51 +0100 Subject: [PATCH] [Separate translation units] [th05] pi_free() (undecompilable) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Well, it *would* have been decompilable, but that ridiculous placement of the nullptr assignment would have forced the entire function call to be spelled out in inline ASM, verbatim. No amount of comma operator trickery would have generated the same instructions either. And for a function this small and obvious in what its decompilation *should* be, it really defeated the purpose of adding a separate translation unit… Part of P0134, funded by [Anonymous]. --- Makefile.mak | 4 ++-- Tupfile | 1 + Tupfile.bat | 1 + libs/master.lib/master.inc | 3 +++ th05/formats/pi.h | 2 +- th05/formats/pi_asm_2.asm | 42 ++++++++++++++++++++++++++++++++++++++ th05/formats/pi_free.asm | 21 ------------------- th05/pi_asm_2.asm | 1 + th05_maine.asm | 2 +- th05_op.asm | 2 +- 10 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 th05/formats/pi_asm_2.asm delete mode 100644 th05/formats/pi_free.asm create mode 100644 th05/pi_asm_2.asm diff --git a/Makefile.mak b/Makefile.mak index 3607ec71..2b3903e4 100644 --- a/Makefile.mak +++ b/Makefile.mak @@ -150,7 +150,7 @@ bin\th05\res_kso.com: th05\res_kso.cpp $** | masters.lib -bin\th05\op.exe: th05\op010.cpp bin\th05\op.obj th05\op011.cpp th05\m_char.cpp bin\th05\initop.obj bin\th05\input_s.obj bin\th05\inp_h_w.obj bin\th05\snd_dlym.obj th05\cdg_p_nc.cpp bin\th05\frmdelay.obj bin\th04\cdg_load.obj bin\th05\egcrect.obj bin\hfliplut.obj +bin\th05\op.exe: th05\op010.cpp bin\th05\op.obj th05\op011.cpp th05\m_char.cpp bin\th05\pi_asm_2.obj bin\th05\initop.obj bin\th05\input_s.obj bin\th05\inp_h_w.obj bin\th05\snd_dlym.obj th05\cdg_p_nc.cpp bin\th05\frmdelay.obj bin\th04\cdg_load.obj bin\th05\egcrect.obj bin\hfliplut.obj $(CC) $(CFLAGS) -ml -DGAME=5 -DBINARY='O' -3 -Z -nbin\th05\ -eOP.EXE @&&| $** | @@ -160,7 +160,7 @@ bin\th05\main.exe: bin\th05\main.obj th05\main010.cpp th05\main011.cpp th05\p_co $** | -bin\th05\maine.exe: bin\th05\maine.obj th05\maine011.cpp th05\regist.cpp th05\staff.cpp bin\th05\initmain.obj bin\th05\input_s.obj bin\th05\inp_h_w.obj bin\th05\snd_dlym.obj bin\th05\frmdelay.obj bin\th04\cdg_load.obj bin\th05\egcrect.obj bin\hfliplut.obj +bin\th05\maine.exe: bin\th05\maine.obj th05\maine011.cpp th05\regist.cpp th05\staff.cpp bin\th05\pi_asm_2.obj bin\th05\initmain.obj bin\th05\input_s.obj bin\th05\inp_h_w.obj bin\th05\snd_dlym.obj bin\th05\frmdelay.obj bin\th04\cdg_load.obj bin\th05\egcrect.obj bin\hfliplut.obj $(CC) $(CFLAGS) -ml -DGAME=5 -DBINARY='E' -Z -nbin\th05\ -eMAINE.EXE @&&| $** | diff --git a/Tupfile b/Tupfile index 2ec35c01..acdbd901 100644 --- a/Tupfile +++ b/Tupfile @@ -109,6 +109,7 @@ BMP2ARR = bin\\Pipeline\\bmp2arr.exe : th05\\player.asm |> !as5 |> : th05\\hud_bar.asm |> !as5 |> : th05\\bullet.asm |> !as5 |> +: th05\\pi_asm_2.asm |> !as5 |> : th05_op.asm | \ th05/sprites/piano_l.asp \ |> !as |> bin\\th05\\op.obj diff --git a/Tupfile.bat b/Tupfile.bat index e9e9d93a..d3396f18 100644 --- a/Tupfile.bat +++ b/Tupfile.bat @@ -50,6 +50,7 @@ tasm32 /m /mx /kh32768 /t /dGAME=5 th04\scoreupd.asm bin\th05\scoreupd.obj tasm32 /m /mx /kh32768 /t /dGAME=5 th05\player.asm bin\th05\player.obj tasm32 /m /mx /kh32768 /t /dGAME=5 th05\hud_bar.asm bin\th05\hud_bar.obj tasm32 /m /mx /kh32768 /t /dGAME=5 th05\bullet.asm bin\th05\bullet.obj +tasm32 /m /mx /kh32768 /t /dGAME=5 th05\pi_asm_2.asm bin\th05\pi_asm_2.obj tasm32 /m /mx /kh32768 /t th05_op.asm bin\th05\op.obj tasm32 /m /mx /kh32768 /t th05_main.asm bin\th05\main.obj tasm32 /m /mx /kh32768 /t th05_maine.asm bin\th05\maine.obj diff --git a/libs/master.lib/master.inc b/libs/master.lib/master.inc index 50cd7a65..2fa5305b 100644 --- a/libs/master.lib/master.inc +++ b/libs/master.lib/master.inc @@ -7,3 +7,6 @@ include libs/master.lib/macros.inc GAIJI_PUTSA procdesc pascal far \ x:word, y:word, strp_seg:word, strp_off:word, atrb:word +GRAPH_PI_FREE procdesc pascal far \ + header:far ptr, image:far ptr +PALETTE_SHOW procdesc pascal far diff --git a/th05/formats/pi.h b/th05/formats/pi.h index b8020d5f..2120e637 100644 --- a/th05/formats/pi.h +++ b/th05/formats/pi.h @@ -1,7 +1,7 @@ #include "th03/formats/pi.h" #undef pi_free -int pascal pi_free(int slot); +void pascal pi_free(int slot); // Like pi_put_8() and pi_put_quarter_8(), but applying the mask with the given // ID while blitting. diff --git a/th05/formats/pi_asm_2.asm b/th05/formats/pi_asm_2.asm new file mode 100644 index 00000000..b2b3f14c --- /dev/null +++ b/th05/formats/pi_asm_2.asm @@ -0,0 +1,42 @@ +; Second TH05 .PI assembly translation unit. + + .386 + .model large + locals + +include pc98.inc +include libs/master.lib/func.inc +include libs/master.lib/master.inc +include th03/arg_bx.inc + + extrn _pi_headers:PiHeader + extrn _pi_buffers:far ptr + +SHARED_ segment word public 'CODE' use16 + assume cs:SHARED_ + +public PI_FREE +func pi_free +arg_bx far, @slot:word + + mov bx, @slot + mov ax, bx + shl bx, 2 + add bx, offset _pi_buffers + cmp dword ptr [bx], 0 + jz short @@ret + imul ax, size PiHeader + add ax, offset _pi_headers + push ds + push ax + push word ptr [bx+2] + push word ptr [bx] + mov dword ptr [bx], 0 + call graph_pi_free +@@ret: + ret 2 +endfunc + +SHARED_ ends + + end diff --git a/th05/formats/pi_free.asm b/th05/formats/pi_free.asm deleted file mode 100644 index 5f2f9124..00000000 --- a/th05/formats/pi_free.asm +++ /dev/null @@ -1,21 +0,0 @@ -public PI_FREE -func pi_free -arg_bx far, @slot:word - - mov bx, @slot - mov ax, bx - shl bx, 2 - add bx, offset _pi_buffers - cmp dword ptr [bx], 0 - jz short @@ret - imul ax, size PiHeader - add ax, offset _pi_headers - push ds - push ax - push word ptr [bx+2] - push word ptr [bx] - mov dword ptr [bx], 0 - call graph_pi_free -@@ret: - ret_bx -endfunc diff --git a/th05/pi_asm_2.asm b/th05/pi_asm_2.asm new file mode 100644 index 00000000..27fb67f6 --- /dev/null +++ b/th05/pi_asm_2.asm @@ -0,0 +1 @@ +include th05/formats/pi_asm_2.asm diff --git a/th05_maine.asm b/th05_maine.asm index b702ae68..4fa25a2d 100644 --- a/th05_maine.asm +++ b/th05_maine.asm @@ -7542,7 +7542,7 @@ include th05/formats/pi_put_masked.asm include th05/formats/pi_load.asm include th05/formats/pi_put.asm include th05/formats/pi_palette_apply.asm -include th05/formats/pi_free.asm + extern PI_FREE:proc extern GAME_INIT_MAIN:proc extern _input_reset_sense_held:proc extern INPUT_WAIT_FOR_CHANGE:proc diff --git a/th05_op.asm b/th05_op.asm index 03a30cf3..a371a564 100644 --- a/th05_op.asm +++ b/th05_op.asm @@ -2547,7 +2547,7 @@ include th05/formats/pi_put_masked.asm include th05/formats/pi_load.asm include th05/formats/pi_put.asm include th05/formats/pi_palette_apply.asm -include th05/formats/pi_free.asm + extern PI_FREE:proc extern _game_init_op:proc extern _input_reset_sense_held:proc extern INPUT_WAIT_FOR_CHANGE:proc