[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].
This commit is contained in:
nmlgc 2021-02-15 14:54:13 +01:00
parent ffcc46d32f
commit 76cefb1e37
4 changed files with 25 additions and 31 deletions

View File

@ -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<uint16_t>(pi_buffers);
imul_di(sizeof(PiHeader));
_DI += reinterpret_cast<uint16_t>(pi_headers);
return graph_pi_load_pack(
fn,
reinterpret_cast<PiHeader near *>(_DI),
reinterpret_cast<void far *near *>(_SI)
);
}
void DEFCONV pi_put_8(screen_x_t left, vram_y_t top, int slot)
{
#define rowloop_func __asm { \

View File

@ -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

View File

@ -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

View File

@ -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