[Decompilation] [th03] Lookup table for horizontally flipping planar pixels

In which we exchange variable names for the ability to decompile more
than just 3 instructions here.
… yeah, "decompilation" is still a stretch.

Part of P0114, funded by Lmocinemod.
This commit is contained in:
nmlgc 2020-09-05 19:03:48 +02:00
parent 6204fdd450
commit ecc1372842
15 changed files with 109 additions and 35 deletions

View File

@ -38,6 +38,9 @@ bin\th01\zunsoft.com: th01\zunsoft.c
# ---------------------------------
bin\frmdely2.obj: th02\frmdely2.c
$(CC) $(CFLAGS) -ml -n$(@D) -c $**
bin\hfliplut.obj: th03\hfliplut.c
$(CC) $(CFLAGS) -ml -n$(@D) -c $**
# ---------------------------------
bin\th01\op.exe: bin\piloadc.obj bin\th01\op.obj th01\op_01.cpp th01\op_02.c th01\op_03.c th01\op_04.c th01\op_05.c th01\op_06.cpp th01\op_07.cpp th01\op_08.c th01\op_09.cpp th01\op_10.c th01\op_11.c th01\op_12.cpp
@ -80,7 +83,7 @@ bin\th03\res_yume.com: th03\res_yume.cpp
$**
| masters.lib
bin\th03\op.exe: bin\th03\op.obj bin\frmdely2.obj
bin\th03\op.exe: bin\th03\op.obj bin\hfliplut.obj bin\frmdely2.obj
$(CC) $(CFLAGS) -ml -DGAME=3 -nbin\th03\ -eOP.EXE @&&|
$**
|
@ -90,6 +93,11 @@ bin\th03\main.exe: bin\th03\main.obj th03\main_01.cpp th03\sprite16.cpp
$**
|
bin\th03\mainl.exe: bin\th03\mainl.obj bin\hfliplut.obj
$(CC) $(CFLAGS) -ml -DGAME=3 -nbin\th03\ -eMAINL.EXE @&&|
$**
|
bin\th04\res_huma.com: th04\res_huma.cpp
$(CC) $(CFLAGS) -mt -lt -Z -DGAME=4 -nbin\th04\ -eRES_HUMA.COM @&&|
$**
@ -100,26 +108,36 @@ bin\th04\op.exe: bin\th04\op.obj th04\op_01.cpp bin\frmdely2.obj
$**
|
bin\th04\main.exe: bin\th04\main.obj bin\th04\scoreupd.obj th04\main011.cpp th04\main032.cpp
bin\th04\main.exe: bin\th04\main.obj bin\th04\scoreupd.obj th04\main011.cpp bin\hfliplut.obj th04\main032.cpp
$(CC) $(CFLAGS) -ml -DGAME=4 -DBINARY='M' -3 -Z -nbin\th04\ -eMAIN.EXE @&&|
$**
|
bin\th04\maine.exe: bin\th04\maine.obj bin\hfliplut.obj
$(CC) $(CFLAGS) -ml -DGAME=4 -DBINARY='E' -nbin\th04\ -eMAINE.EXE @&&|
$**
|
bin\th05\res_kso.com: th05\res_kso.cpp
$(CC) $(CFLAGS) -mt -lt -Z -DGAME=5 -nbin\th05\ -eRES_KSO.COM @&&|
$**
| masters.lib
bin\th05\op.exe: bin\th05\op.obj th05\op_01.cpp
bin\th05\op.exe: bin\th05\op.obj th05\op_01.cpp bin\hfliplut.obj
$(CC) $(CFLAGS) -ml -DGAME=5 -DBINARY='O' -nbin\th05\ -eOP.EXE @&&|
$**
|
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\th05\bullet.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\hfliplut.obj bin\th05\bullet.obj th05\main031.cpp th05\main032.cpp th05\main033.cpp th05\main034.cpp
$(CC) $(CFLAGS) -ml -3 -Z -DGAME=5 -DBINARY='M' -nbin\th05\ -eMAIN.EXE @&&|
$**
|
bin\th05\maine.exe: bin\th05\maine.obj bin\hfliplut.obj
$(CC) $(CFLAGS) -ml -DGAME=5 -DBINARY='E' -nbin\th05\ -eMAINE.EXE @&&|
$**
|
# ZUN.COM packing
{bin\zuncom}.obj{bin\zuncom}.bin:

View File

@ -7,6 +7,7 @@
// ----------------
// When used inside a conditional expression like
// if(FLAGS_*) { goto some_label; | return; }
// these assemble into the single given instruction.
// these assemble into the single given instruction. Apply the ! operator to
// get the N versions.
#define FLAGS_ZERO (_FLAGS & 0x40) /* JZ */
// ----------------

View File

@ -40,7 +40,7 @@ proc_defconv cdg_put_hflip
add ax, 0A800h
mov es, ax
assume es:nothing
mov bx, offset hflip_lut
mov bx, offset _hflip_lut
mov fs, [si+cdg_t.seg_alpha]
xor si, si

View File

@ -1,11 +1,8 @@
; Generates a lookup table for flipping one byte, interpreted as a horizontal
; line of 8 pixels in a single bitplane.
; int DEFCONV hflip_lut_generate()
proc_defconv hflip_lut_generate
public _hflip_lut_generate
_hflip_lut_generate proc
push di
xor ax, ax
mov di, offset hflip_lut
mov di, offset _hflip_lut
xor dl, dl
jmp short @@check
@ -25,4 +22,4 @@ proc_defconv hflip_lut_generate
jnz short @@outer
pop di
ret
endp_defconv
_hflip_lut_generate endp

5
th03/formats/hfliplut.h Normal file
View File

@ -0,0 +1,5 @@
// Lookup table for horizontally flipping a dots8_t.
extern dots8_t hflip_lut[256];
// Fills [hflip_lut].
void hflip_lut_generate(void);

View File

@ -1 +1,2 @@
hflip_lut db 100h dup(?)
public _hflip_lut
_hflip_lut db 100h dup(?)

34
th03/hfliplut.c Normal file
View File

@ -0,0 +1,34 @@
#include "platform.h"
#include "pc98.h"
#include "planar.h"
#include "decomp.h"
#include "th03/formats/hfliplut.h"
#pragma codeseg seg2
#pragma option -k-
void hflip_lut_generate(void)
{
#define p (dots8_t near *)(_DI)
_AX = 0;
p = hflip_lut;
_DL ^= _DL;
goto set_and_loop;
permutation_loop:
_DL ^= _DL;
_CX = BYTE_DOTS;
generation_loop: __asm {
rol al, 1
rcr dl, 1
loop generation_loop
}
set_and_loop:
*(p++) = _DL;
_AL++;
if(!FLAGS_ZERO) {
goto permutation_loop;
}
#undef p
}

View File

@ -615,7 +615,7 @@ var_2 = word ptr -2
call sub_13CDD
mov byte_207E3, 0
call sub_9EBF
call hflip_lut_generate
call _hflip_lut_generate
nopcall sub_D5A2
mov byte_23AFA, 0
les bx, _resident
@ -9228,7 +9228,7 @@ loc_F0A9:
mov bx, [bp+arg_0]
shl bx, 2
les di, [bx+1D64h]
mov bx, offset hflip_lut
mov bx, offset _hflip_lut
loc_F0BB:
mov al, es:[di]

View File

@ -906,7 +906,7 @@ loc_9DAD:
call gaiji_entry_bfnt
call snd_load c, offset aYume_efc, ds, SND_LOAD_SE
call snd_se_reset
call hflip_lut_generate
call _hflip_lut_generate
les bx, _resident
cmp es:[bx+resident_t.show_score_menu], 0
jz short loc_9E04
@ -5588,7 +5588,7 @@ include th03/hardware/input_modes.asm
include th03/hardware/input_wait.asm
db 0
include th03/formats/cdg_put_noalpha.asm
include th03/formats/hfliplut.asm
extern _hflip_lut_generate:proc
seg2 ends
.data

View File

@ -2328,7 +2328,7 @@ sub_B38D proc near
push bp
mov bp, sp
push si
call hflip_lut_generate
call _hflip_lut_generate
xor si, si
jmp short loc_B3B0
; ---------------------------------------------------------------------------
@ -3642,7 +3642,7 @@ include th03/hardware/input_modes.asm
include th03/hardware/input_wait.asm
db 0
include th03/formats/cdg_put_noalpha.asm
include th03/formats/hfliplut.asm
extern _hflip_lut_generate:proc
extern FRAME_DELAY_2:proc
seg2 ends

View File

@ -47,6 +47,7 @@ include th04/main/enemy/enemy.inc
.seq
main_01 group main_0_TEXT, main_01_TEXT, main_012_TEXT
g_seg2 group seg2, seg2_
main_03 group main_032_TEXT, main_033_TEXT
; ===========================================================================
@ -13167,7 +13168,7 @@ main_012_TEXT ends
; Segment type: Pure code
seg2 segment word public 'CODE' use16
assume cs:seg2
assume cs:g_seg2
;org 0Dh
assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing
@ -13176,7 +13177,9 @@ include th03/math/vector2.asm
nop
include th03/math/vector2_between_plus.asm
include th02/hardware/frame_delay.asm
include th03/formats/hfliplut.asm
seg2 ends
seg2_ segment word public 'CODE' use16
; =============== S U B R O U T I N E =======================================
@ -13323,7 +13326,7 @@ include th04/formats/cdg_put_plane_roll.asm
include th04/hardware/input_sense.asm
include th04/snd/se.asm
include th04/formats/cdg_load.asm
seg2 ends
seg2_ ends
; ===========================================================================

View File

@ -28,6 +28,8 @@ include th04/th04.inc
extern _tolower:proc
extern __ctype:byte
g_seg2 group seg2, seg2_
; ===========================================================================
; Segment type: Pure code
@ -4694,7 +4696,7 @@ maine_01_TEXT ends
; Segment type: Pure code
seg2 segment word public 'CODE' use16
assume cs:seg2
assume cs:g_seg2
;org 0Ah
assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing
@ -4704,7 +4706,9 @@ include th02/formats/pi_slot_palette_apply.asm
include th02/formats/pi_slot_put.asm
include th02/formats/pi_slot_load.asm
include th03/formats/pi_slot_put_quarter.asm
include th03/formats/hfliplut.asm
seg2 ends
seg2_ segment word public 'CODE' use16
include th04/hardware/input_wait.asm
include th04/math/vector1_at.asm
include th04/math/vector2_at.asm
@ -4726,7 +4730,7 @@ include th04/snd/se.asm
include th04/bgimage.asm
include th04/bgimage_put_rect.asm
include th04/formats/cdg_load.asm
seg2 ends
seg2_ ends
.data

View File

@ -39,6 +39,7 @@ include th05/main/enemy/enemy.inc
.seq
main_01 group main_TEXT, main__TEXT, main_0_TEXT, main_01_TEXT
g_seg2 group seg2, seg2_
main_03 group main_031_TEXT, main_032_TEXT, main_033_TEXT, main_034_TEXT, main_035_TEXT
; ===========================================================================
@ -10746,14 +10747,16 @@ main_01_TEXT ends
; Segment type: Pure code
seg2 segment word public 'CODE' use16
assume cs:seg2
assume cs:g_seg2
;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
include th03/formats/hfliplut.asm
seg2 ends
seg2_ segment word public 'CODE' use16
include th04/snd/pmd_res.asm
include th02/snd/mmd_res.asm
include th04/snd/detmodes.asm
@ -10772,7 +10775,7 @@ include th05/hardware/input_wait.asm
include th05/hardware/frame_delay.asm
db 0
include th04/formats/cdg_load.asm
seg2 ends
seg2_ ends
; ===========================================================================

View File

@ -27,6 +27,8 @@ include th05/th05.inc
extern _tolower:proc
extern __ctype:byte
g_seg2 group seg2, seg2_
; ===========================================================================
; Segment type: Pure code
@ -7771,11 +7773,13 @@ maine_01_TEXT ends
; Segment type: Pure code
seg2 segment word public 'CODE' use16
assume cs:seg2
seg2 ends
seg2_ segment word public 'CODE' use16
assume cs:g_seg2
;org 0Ch
assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing
include th03/formats/hfliplut.asm
include th04/snd/pmd_res.asm
include th02/snd/mmd_res.asm
include th04/snd/detmodes.asm
@ -7804,7 +7808,7 @@ include th05/hardware/frame_delay.asm
db 0
include th04/formats/cdg_load.asm
include th04/hardware/egccopyr.asm
seg2 ends
seg2_ ends
.data

View File

@ -30,6 +30,8 @@ include th05/music/piano.inc
extern _getch:proc
extern _strlen:proc
g_seg2 group seg2, seg2_
; ===========================================================================
; Segment type: Pure code
@ -3486,11 +3488,13 @@ op_01_TEXT ends
; Segment type: Pure code
seg2 segment word public 'CODE' use16
assume cs:seg2
seg2 ends
seg2_ segment word public 'CODE' use16
assume cs:g_seg2
; org 4
assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing
include th03/formats/hfliplut.asm
include th04/snd/pmd_res.asm
include th02/snd/mmd_res.asm
include th04/snd/detmodes.asm
@ -3527,7 +3531,7 @@ include th05/hardware/frame_delay.asm
include th04/formats/cdg_load.asm
include th04/hardware/egccopyr.asm
even
seg2 ends
seg2_ ends
.data