[Decompilation] [th05] input_reset_sense_held(), input_wait_for_change()

Nope, not keeping this in ASM just because of some function calls
either.

Part of P0133, funded by [Anonymous].
This commit is contained in:
nmlgc 2021-01-09 20:43:48 +01:00
parent 4229054137
commit 6e91c4f99a
9 changed files with 78 additions and 63 deletions

View File

@ -150,17 +150,17 @@ 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\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\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 @&&|
$**
|
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 bin\th05\frmdelay.obj bin\th04\cdg_load.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 bin\th05\inp_h_w.obj bin\th05\frmdelay.obj bin\th04\cdg_load.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 th05\maine011.cpp th05\regist.cpp th05\staff.cpp 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\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 @&&|
$**
|

62
th05/hardware/inp_h_w.cpp Normal file
View File

@ -0,0 +1,62 @@
#pragma codeseg SHARED_
extern "C" {
#include <dos.h>
#include "platform.h"
#include "decomp.h"
#include "master.hpp"
#include "th05/hardware/input.h"
}
#pragma option -k-
// The key state is checked twice, 614.4 µs apart, to ignore the momentary
// "key released" events sent by PC-98 keyboards at the typematic rate if a
// key is held down. This ensures that the game consistently sees that
// specific input being pressed. See the HOLDKEY example in the `Research/`
// subdirectory for more explanation and sample code showing off this effect.
int16_t input_reset_sense_held()
{
/* TODO: Replace with the decompiled call
* input_reset_sense();
* once the segmentation allows us to, if ever */
__asm { push cs; call near ptr input_reset_sense; }
_CX = 1024; // * 0.6 µs
delay_loop: __asm {
out 0x5F, al;
loop delay_loop;
}
/* TODO: Replace with the decompiled call
* return input_sense();
* once the segmentation allows us to, if ever */
__asm { push cs; call near ptr input_sense; }
return _AX;
}
#pragma option -k
int16_t pascal input_wait_for_change(int frames)
{
#define frames_left _BP
while(input_reset_sense_held()) {
}
frames_left = frames;
do {
if(input_reset_sense_held()) {
return _AX;
}
_AX = vsync_Count1;
while(_AX == vsync_Count1) {
}
if(frames_left) {
frames_left--;
if(FLAGS_ZERO) {
break;
}
}
} while(1);
return _AX;
#undef frames_left
}

View File

@ -3,19 +3,19 @@
#define INPUT_REPLAY_END (~INPUT_MOVEMENT)
// Resets, updates, and returns [key_det].
int input_reset_sense();
int16_t input_reset_sense();
// input_reset_sense() with accurate detection of held keyboard keys.
int input_reset_sense_held();
int16_t input_reset_sense_held();
// ORs the current keyboard and joystick state into [key_det], sets
// [shiftkey], and returns [key_det].
int input_sense();
int16_t input_sense();
// Input sense function used in UIs
#define input_reset_sense_interface input_reset_sense_held
// Waits for all held inputs to be released, then waits the given number of
// [frames] for an input to be pressed and returns [key_det].
// Set [frames] to 0 to wait forever.
int pascal input_wait_for_change(int frames);
// [frames] for an input to be pressed. Set [frames] to 0 to wait forever.
// Returns garbage.
int16_t pascal input_wait_for_change(int frames);

View File

@ -1,17 +0,0 @@
; The key state is checked twice, 614.4 µs apart, to ignore the momentary "key
; released" events sent by PC-98 keyboards at the typematic rate if a key is
; held down. This ensures that the game consistently sees that specific input
; being pressed. See the HOLDKEY example in the Research/ subdirectory for
; more explanation and sample code showing off this effect.
;
public _input_reset_sense_held
_input_reset_sense_held proc far
call _input_reset_sense
mov cx, 1024
@@wait:
out 5Fh, al
loop @@wait
call _input_sense
retf
_input_reset_sense_held endp

View File

@ -1,31 +0,0 @@
public INPUT_WAIT_FOR_CHANGE
input_wait_for_change proc far
@@frames = word ptr 6
push bp
mov bp, sp
@@release_loop:
call _input_reset_sense_held
or ax, ax
jnz short @@release_loop
mov bp, [bp+@@frames]
@@press_loop:
call _input_reset_sense_held
or ax, ax
jnz short @@ret
mov ax, vsync_Count1
@@vsync:
cmp ax, vsync_Count1
jz short @@vsync
or bp, bp
jz short @@press_loop
dec bp
jnz short @@press_loop
@@ret:
pop bp
retf 2
input_wait_for_change endp

1
th05/inp_h_w.cpp Normal file
View File

@ -0,0 +1 @@
#include "th05/hardware/inp_h_w.cpp"

View File

@ -10565,8 +10565,8 @@ include th05/snd/load.asm
include th05/snd/kajaint.asm
include th02/initmain.asm
include th04/hardware/input_sense.asm
include th05/hardware/input_held.asm
include th05/hardware/input_wait.asm
extern _input_reset_sense_held:proc
extern INPUT_WAIT_FOR_CHANGE:proc
extern FRAME_DELAY:proc
extern CDG_LOAD_ALL_NOALPHA:proc
extern CDG_LOAD_ALL:proc

View File

@ -7545,8 +7545,8 @@ include th05/formats/pi_palette_apply.asm
include th05/formats/pi_free.asm
include th02/initmain.asm
include th04/hardware/input_sense.asm
include th05/hardware/input_held.asm
include th05/hardware/input_wait.asm
extern _input_reset_sense_held:proc
extern INPUT_WAIT_FOR_CHANGE:proc
extern _snd_bgm_measure:proc
extern SND_DELAY_UNTIL_MEASURE:proc
extern FRAME_DELAY:proc

View File

@ -2550,8 +2550,8 @@ include th05/formats/pi_palette_apply.asm
include th05/formats/pi_free.asm
include th02/initop.asm
include th04/hardware/input_sense.asm
include th05/hardware/input_held.asm
include th05/hardware/input_wait.asm
extern _input_reset_sense_held:proc
extern INPUT_WAIT_FOR_CHANGE:proc
extern SND_DELAY_UNTIL_MEASURE:proc
extern CDG_PUT_NOCOLORS_8:proc
extern FRAME_DELAY:proc