[Decompilation] [th04/th05] bgimage_snap(), bgimage_put(), bgimage_free()

Eh, REP MOVSD is used too inconsistently across the games to justify
replacing these macros with an `inline` function. Still can use a
custom one here to make the register usage a bit more explicit, though.

Part of P0136, funded by [Anonymous].
This commit is contained in:
nmlgc 2021-03-10 22:13:50 +01:00
parent 85019517e2
commit 8164c71d22
11 changed files with 120 additions and 116 deletions

View File

@ -133,7 +133,7 @@ bin\th04\res_huma.com: th04\res_huma.cpp
$**
| masters.lib
bin\th04\op.exe: bin\th04\op.obj th04\m_char.cpp bin\th04\bgimager.obj bin\th04\cdg_load.obj th04\frmdely2.c
bin\th04\op.exe: bin\th04\op.obj th04\m_char.cpp bin\th04\bgimage.obj bin\th04\bgimager.obj bin\th04\cdg_load.obj th04\frmdely2.c
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -DGAME=4 -DBINARY='O' -3 -Z -d -nbin\th04\ -eOP.EXE @&&|
$**
|
@ -143,7 +143,7 @@ bin\th04\main.exe: bin\th04\main.obj bin\th04\scoreupd.obj th04\main011.cpp bin\
$**
|
bin\th04\maine.exe: bin\th04\maine.obj th04\maine011.cpp bin\th04\bgimager.obj bin\th03\pi_load.obj bin\th03\pi_put_q.obj bin\th04\cdg_load.obj bin\hfliplut.obj
bin\th04\maine.exe: bin\th04\maine.obj th04\maine011.cpp bin\th04\bgimage.obj bin\th04\bgimager.obj bin\th03\pi_load.obj bin\th03\pi_put_q.obj bin\th04\cdg_load.obj bin\hfliplut.obj
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -DGAME=4 -DBINARY='E' -Z -nbin\th04\ -eMAINE.EXE @&&|
$**
|
@ -156,7 +156,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\cdg_put.obj bin\th04\exit.obj bin\th05\vector.obj bin\th05\musicp_c.obj bin\th05\musicp_a.obj bin\th05\bgimager.obj bin\th05\snd_load.obj bin\th05\snd_kaja.obj bin\th05\pi_cpp_1.obj bin\th05\pi_asm_1.obj bin\th05\pi_cpp_2.obj 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
bin\th05\op.exe: th05\op010.cpp bin\th05\op.obj th05\op011.cpp th05\m_char.cpp bin\th04\bgimage.obj bin\th05\cdg_put.obj bin\th04\exit.obj bin\th05\vector.obj bin\th05\musicp_c.obj bin\th05\musicp_a.obj bin\th05\bgimager.obj bin\th05\snd_load.obj bin\th05\snd_kaja.obj bin\th05\pi_cpp_1.obj bin\th05\pi_asm_1.obj bin\th05\pi_cpp_2.obj 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) $(LARGE_LFLAGS) -DGAME=5 -DBINARY='O' -3 -Z -nbin\th05\ -eOP.EXE @&&|
$**
|
@ -166,7 +166,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\th04\exit.obj bin\th05\vector.obj bin\th05\bgimager.obj bin\th05\snd_load.obj bin\th05\snd_kaja.obj bin\th05\pi_cpp_1.obj bin\th05\pi_asm_1.obj bin\th05\pi_cpp_2.obj 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
bin\th05\maine.exe: bin\th05\maine.obj th05\maine011.cpp th05\regist.cpp th05\staff.cpp bin\th04\bgimage.obj bin\th04\exit.obj bin\th05\vector.obj bin\th05\bgimager.obj bin\th05\snd_load.obj bin\th05\snd_kaja.obj bin\th05\pi_cpp_1.obj bin\th05\pi_asm_1.obj bin\th05\pi_cpp_2.obj 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) $(LARGE_LFLAGS) -DGAME=5 -DBINARY='E' -Z -nbin\th05\ -eMAINE.EXE @&&|
$**
|

1
th04/bgimage.cpp Normal file
View File

@ -0,0 +1 @@
#include "th04/hardware/bgimage.cpp"

View File

@ -1,88 +0,0 @@
public BGIMAGE_SNAP
bgimage_snap proc far
push si
push di
cmp bgimage_PL_B, 0
jnz short @@already_allocated
call hmem_allocbyte pascal, PLANE_SIZE
mov bgimage_PL_B, ax
call hmem_allocbyte pascal, PLANE_SIZE
mov bgimage_PL_R, ax
call hmem_allocbyte pascal, PLANE_SIZE
mov bgimage_PL_G, ax
call hmem_allocbyte pascal, PLANE_SIZE
mov bgimage_PL_E, ax
@@already_allocated:
mov dl, 4
push ds
push 0E000h
push bgimage_PL_E
push 0B800h
push bgimage_PL_G
push 0B000h
push bgimage_PL_R
push 0A800h
push bgimage_PL_B
@@next_plane:
pop es
pop ds
xor si, si
xor di, di
mov cx, (PLANE_SIZE / 4)
rep movsd
dec dl
jnz short @@next_plane
pop ds
pop di
pop si
retf
bgimage_snap endp
public BGIMAGE_PUT
bgimage_put proc far
push si
push di
mov dl, 4
push ds
push 0E000h
push bgimage_PL_E
push 0B800h
push bgimage_PL_G
push 0B000h
push bgimage_PL_R
push 0A800h
push bgimage_PL_B
@@next_plane:
pop ds
pop es
xor si, si
xor di, di
mov cx, (PLANE_SIZE / 4)
rep movsd
dec dl
jnz short @@next_plane
pop ds
pop di
pop si
retf
bgimage_put endp
even
public BGIMAGE_FREE
bgimage_free proc far
cmp bgimage_PL_B, 0
jz short @@ret
call hmem_free pascal, bgimage_PL_B
call hmem_free pascal, bgimage_PL_R
call hmem_free pascal, bgimage_PL_G
call hmem_free pascal, bgimage_PL_E
mov bgimage_PL_B, 0
@@ret:
retf
bgimage_free endp

82
th04/hardware/bgimage.cpp Normal file
View File

@ -0,0 +1,82 @@
#pragma codeseg SHARED_
#pragma option -k-
extern "C" {
#include <mem.h>
#include <stddef.h>
#include "platform.h"
#include "x86real.h"
#include "pc98.h"
#include "planar.h"
#include "decomp.hpp"
#include "master.hpp"
#include "th04/hardware/bgimage.hpp"
inline void memcpy_movsd(
uint16_t, uint16_t dst_off, uint16_t, uint16_t src_off, size_t size
) {
_SI = src_off;
_DI = dst_off;
_CX = (size / sizeof(uint32_t));
REP MOVSD;
}
#define bgimage_push() __asm { \
push SEG_PLANE_E; \
push word ptr [bgimage.E]; \
push SEG_PLANE_G; \
push word ptr [bgimage.G]; \
push SEG_PLANE_R; \
push word ptr [bgimage.R]; \
push SEG_PLANE_B; \
push word ptr [bgimage.B]; \
}
void bgimage_snap(void)
{
if(bgimage.B == NULL) {
bgimage.B = reinterpret_cast<dots8_t __seg *>(hmem_allocbyte(PLANE_SIZE));
bgimage.R = reinterpret_cast<dots8_t __seg *>(hmem_allocbyte(PLANE_SIZE));
bgimage.G = reinterpret_cast<dots8_t __seg *>(hmem_allocbyte(PLANE_SIZE));
bgimage.E = reinterpret_cast<dots8_t __seg *>(hmem_allocbyte(PLANE_SIZE));
}
_DL = PLANE_COUNT;
__asm { push ds; }
bgimage_push();
do {
__asm { pop es; }
__asm { pop ds; }
memcpy_movsd(_ES, 0, _DS, 0, PLANE_SIZE);
_DL--;
} while(!FLAGS_ZERO);
__asm { pop ds; }
}
void bgimage_put(void)
{
_DL = PLANE_COUNT;
__asm { push ds; }
bgimage_push();
do {
__asm { pop ds; }
__asm { pop es; }
memcpy_movsd(_ES, 0, _DS, 0, PLANE_SIZE);
_DL--;
} while(!FLAGS_ZERO);
__asm { pop ds; }
}
#pragma codestring "\x90"
void bgimage_free(void)
{
if(bgimage.B != NULL) {
hmem_free(FP_SEG(bgimage.B));
hmem_free(FP_SEG(bgimage.R));
hmem_free(FP_SEG(bgimage.G));
hmem_free(FP_SEG(bgimage.E));
bgimage.B = NULL;
}
}
}

View File

@ -1,9 +1,12 @@
// Additional 640×400 4-plane background image buffer.
extern Planar<dots8_t __seg *> bgimage;
void pascal bgimage_snap(void);
void pascal bgimage_put(void);
void pascal bgimage_free(void);
void bgimage_snap(void);
// Blits garbage data if bgimage_snap() wasn't called before.
void bgimage_put(void);
void bgimage_free(void);
// Blits the rectangle from (⌊x/16⌋*16, y) to (⌈((x + w)/16)*16⌉, (y + h))
// on the [bgimage] to the same position in VRAM.
void pascal bgimage_put_rect(

View File

@ -263,7 +263,7 @@ else
endif
push 0
call graph_copy_page
call bgimage_snap
call _bgimage_snap
graph_accesspage 1
call graph_clear
graph_accesspage 0
@ -420,7 +420,7 @@ frame_68: ; case 68
call zunsoft_pyro_new
@@no_new_pyro_this_frame:
call bgimage_put ; default
call _bgimage_put ; default
call zunsoft_update_and_render
if GAME eq 4
call _input_reset_sense
@ -475,7 +475,7 @@ endif
@@ret:
call super_free
call bgimage_free
call _bgimage_free
pop di
pop si
leave

View File

@ -2344,7 +2344,7 @@ sub_B44D proc near
call pi_put_8 pascal, large 0, 0
freePISlotLarge 0
call graph_copy_page pascal, 0
call bgimage_snap
call _bgimage_snap
kajacall KAJA_SONG_STOP
call snd_load pascal, ds, offset aStaff, SND_LOAD_SONG
kajacall KAJA_SONG_PLAY
@ -2392,7 +2392,7 @@ sub_B44D proc near
call pi_put_8 pascal, large 0, 0
freePISlotLarge 0
call graph_copy_page pascal, 0
call bgimage_snap
call _bgimage_snap
push 4
call palette_black_in
call cdg_load_single pascal, 2, ds, offset aSff4_cdg, 0
@ -2455,7 +2455,7 @@ sub_B44D proc near
call sub_B291
push 3000A0h
call snd_delay_until_measure
call bgimage_free
call _bgimage_free
call cdg_free_all
push 4
call palette_black_out
@ -4615,7 +4615,8 @@ include th02/initmain.asm
db 0
include th04/hardware/input_s.asm
include th04/snd/se.asm
include th04/hardware/bgimage.asm
extern _bgimage_snap:proc
extern _bgimage_free:proc
extern BGIMAGE_PUT_RECT:proc
extern CDG_LOAD_SINGLE_NOALPHA:proc
extern CDG_LOAD_SINGLE:proc

View File

@ -1811,7 +1811,7 @@ _musicroom proc near
mov _music_sel, al
call draw_tracks pascal, word ptr _music_sel
call graph_copy_page pascal, 0
call bgimage_snap
call _bgimage_snap
graph_accesspage 1
graph_showpage 0
call screen_back_B_snap
@ -1917,7 +1917,7 @@ loc_C544:
graph_accesspage al
push 1
call palette_black_out
call bgimage_free
call _bgimage_free
call snd_load pascal, ds, offset aOp_2, SND_LOAD_SONG
kajacall KAJA_SONG_PLAY
pop bp
@ -2667,10 +2667,12 @@ include th04/formats/cdg_put_noalpha.asm
include th04/hardware/input_s.asm
include th04/snd/se.asm
include th04/hardware/egcrect.asm
include th04/hardware/bgimage.asm
SHARED ends
SHARED_ segment word public 'CODE' use16
extern _bgimage_snap:proc
extern _bgimage_put:proc
extern _bgimage_free:proc
extern BGIMAGE_PUT_RECT:proc
extern CDG_LOAD_ALL_NOALPHA:proc
extern CDG_LOAD_ALL:proc

View File

@ -14,7 +14,7 @@ extern "C" {
#include "th01/ranks.h"
#include "th02/hardware/frmdelay.h"
#include "th04/formats/cdg.h"
#include "th04/hardware/bgimage.h"
#include "th04/hardware/bgimage.hpp"
#include "th04/score.h"
#include "th04/common.h"
#include "th05/chars.h"

View File

@ -980,7 +980,7 @@ loc_ACAA:
call graph_clear
graph_accesspage 0
call graph_clear
call bgimage_snap
call _bgimage_snap
jmp loc_AF8F ; default
; ---------------------------------------------------------------------------
@ -1004,7 +1004,7 @@ loc_ACF4:
call pi_put_8 pascal, large 0, 0
call graph_copy_page pascal, 0
graph_accesspage 0
call bgimage_snap
call _bgimage_snap
jmp loc_AF8F ; default
; ---------------------------------------------------------------------------
@ -1492,7 +1492,7 @@ loc_B18D:
; ---------------------------------------------------------------------------
loc_B196:
call bgimage_free
call _bgimage_free
call pi_free pascal, 0
pop si
leave
@ -3465,7 +3465,7 @@ loc_C2BB:
call graph_putsa_fx pascal, (120 shl 16) or 192, 2, ds, offset aGxgnbGvbGhvV_0
loc_C2EB:
call bgimage_snap
call _bgimage_snap
les bx, _resident
cmp es:[bx+resident_t.end_sequence], ES_EXTRA
jb short loc_C307
@ -3475,7 +3475,7 @@ loc_C2EB:
loc_C307:
call graph_copy_page pascal, 1
call bgimage_snap
call _bgimage_snap
kajacall KAJA_SONG_STOP
call snd_load pascal, ds, offset aName, SND_LOAD_SONG
kajacall KAJA_SONG_PLAY
@ -3779,7 +3779,7 @@ loc_C5C3:
call input_wait_for_change pascal, 0
loc_C5CD:
call bgimage_free
call _bgimage_free
call super_free
call text_clear
push 1
@ -7531,7 +7531,8 @@ include th04/snd/detmodes.asm
include th04/hardware/grppsafx.asm
include th04/formats/cdg_put_noalpha.asm
include th04/snd/se.asm
include th04/hardware/bgimage.asm
extern _bgimage_snap:proc
extern _bgimage_free:proc
extern _game_exit:proc
extern VECTOR2_AT:proc
extern BGIMAGE_PUT_RECT:proc

View File

@ -1926,7 +1926,7 @@ _musicroom proc near
call pi_free pascal, 0
call _piano_setup_and_put_initial
call screen_back_B_snap
call bgimage_snap
call _bgimage_snap
call draw_tracks pascal, word ptr _music_sel
call graph_copy_page pascal, 0
graph_accesspage 1
@ -2138,7 +2138,7 @@ loc_C790:
graph_accesspage al
push 1
call palette_black_out
call bgimage_free
call _bgimage_free
call snd_load pascal, ds, offset aH_op+2, SND_LOAD_SONG
kajacall KAJA_SONG_PLAY
pop si
@ -2532,7 +2532,9 @@ include th02/exit_dos.asm
include th04/hardware/grppsafx.asm
include th04/formats/cdg_put_noalpha.asm
include th04/snd/se.asm
include th04/hardware/bgimage.asm
extern _bgimage_snap:proc
extern _bgimage_put:proc
extern _bgimage_free:proc
extern CDG_PUT_8:proc
extern _game_exit:proc
extern VECTOR1_AT:proc