From 76cefb1e37fc228a4b7adbd69190fd9da58d924c Mon Sep 17 00:00:00 2001 From: nmlgc Date: Mon, 15 Feb 2021 14:54:13 +0100 Subject: [PATCH] [Decompilation] [th05] pi_load() That assembly is *worse* than what you would have gotten out of your 1994 C++ compiler with the 386 code generation switch! Part of P0134, funded by [Anonymous]. --- th05/formats/pi_cpp_2.cpp | 23 +++++++++++++++++++++++ th05/formats/pi_load.asm | 29 ----------------------------- th05_maine.asm | 2 +- th05_op.asm | 2 +- 4 files changed, 25 insertions(+), 31 deletions(-) delete mode 100644 th05/formats/pi_load.asm diff --git a/th05/formats/pi_cpp_2.cpp b/th05/formats/pi_cpp_2.cpp index 83dc8141..166a2006 100644 --- a/th05/formats/pi_cpp_2.cpp +++ b/th05/formats/pi_cpp_2.cpp @@ -18,6 +18,29 @@ void pascal near pi_put_8_rowloop( screen_x_t left, vram_y_t top, pixel_t w, size_t stride_packed ); +int DEFCONV pi_load(int slot, const char *fn) +{ + _DI = slot; + /* TODO: Replace with the decompiled call + * pi_free(slot); + * once the segmentation allows us to, if ever */ + __asm { push di; push cs; call near ptr pi_free; } + + /* Actually, also replace this garbage with simply + * return graph_pi_load_pack(fn, &pi_headers[slot], &pi_buffers[slot]); + * Even Turbo C++ can generate better code than *that*. */ + _SI = _DI; + _SI <<= 2; // *= sizeof(void far *) + _SI += reinterpret_cast(pi_buffers); + imul_di(sizeof(PiHeader)); + _DI += reinterpret_cast(pi_headers); + return graph_pi_load_pack( + fn, + reinterpret_cast(_DI), + reinterpret_cast(_SI) + ); +} + void DEFCONV pi_put_8(screen_x_t left, vram_y_t top, int slot) { #define rowloop_func __asm { \ diff --git a/th05/formats/pi_load.asm b/th05/formats/pi_load.asm deleted file mode 100644 index 0e4aef44..00000000 --- a/th05/formats/pi_load.asm +++ /dev/null @@ -1,29 +0,0 @@ -public PI_LOAD -func pi_load - ; (PASCAL calling convention, parameter list needs to be reversed here) - arg @@fn:ptr, @@slot:word - - push bp - mov bp, sp - push si - push di - mov di, @@slot - push di - call pi_free - mov si, di - shl si, 2 - add si, offset _pi_buffers - imul di, size PiHeader - add di, offset _pi_headers - push word ptr @@fn+2 - push word ptr @@fn - push ds - push di - push ds - push si - call graph_pi_load_pack - pop di - pop si - pop bp - ret 6 -endfunc diff --git a/th05_maine.asm b/th05_maine.asm index 6528702b..0bd31b55 100644 --- a/th05_maine.asm +++ b/th05_maine.asm @@ -7539,7 +7539,7 @@ include th04/bgimage_put_rect.asm include th05/snd/load.asm include th05/snd/kajaint.asm include th05/formats/pi_put_masked.asm -include th05/formats/pi_load.asm + extern PI_LOAD:proc extern PI_PUT_8:proc extern PI_PUT_QUARTER_8:proc extern PI_PALETTE_APPLY:proc diff --git a/th05_op.asm b/th05_op.asm index e1e46976..fe3f4a33 100644 --- a/th05_op.asm +++ b/th05_op.asm @@ -2544,7 +2544,7 @@ include th04/bgimage_put_rect.asm include th05/snd/load.asm include th05/snd/kajaint.asm include th05/formats/pi_put_masked.asm -include th05/formats/pi_load.asm + extern PI_LOAD:proc extern PI_PUT_8:proc extern PI_PALETTE_APPLY:proc extern PI_FREE:proc