[Separate translation units] [th02] input_sense()

Finishing this push with some semi-maintenance… and yet another `inline`
function replacing a `#define` ASM macro with fully idiomatic C++ code.

Completes P0136, funded by [Anonymous].
This commit is contained in:
nmlgc 2021-03-19 19:27:11 +01:00
parent af13720486
commit 07bfcf2841
7 changed files with 85 additions and 104 deletions

View File

@ -80,17 +80,17 @@ bin\th02\zun_res.com: th02\zun_res1.cpp th02\zun_res2.c th02\zun_res3.c
$**
| masters.lib
bin\th02\op.exe: th02\op_01.cpp bin\exit_dos.obj bin\th02\zunerror.obj bin\th02\grppsafx.obj bin\th02\op.obj th02\op_02_1.cpp bin\th02\pi_load.obj bin\th02\grp_rect.obj bin\frmdely2.obj th02\op_02_2.cpp bin\th02\initop.obj bin\th02\exit.obj bin\th02\snd_mmdr.obj bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th02\snd_load.obj bin\th02\pi_put.obj bin\th02\snd_kaja.obj th02\op_02_3.cpp bin\th02\snd_se.obj bin\frmdely1.obj th02\op_03.cpp th02\op_04.cpp th02\op_05.cpp th02\op_06.cpp
bin\th02\op.exe: th02\op_01.cpp bin\exit_dos.obj bin\th02\zunerror.obj bin\th02\grppsafx.obj bin\th02\op.obj th02\op_02_1.cpp bin\th02\pi_load.obj bin\th02\grp_rect.obj bin\frmdely2.obj bin\th02\input_s.obj bin\th02\initop.obj bin\th02\exit.obj bin\th02\snd_mmdr.obj bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th02\snd_load.obj bin\th02\pi_put.obj bin\th02\snd_kaja.obj th02\op_02_3.cpp bin\th02\snd_se.obj bin\frmdely1.obj th02\op_03.cpp th02\op_04.cpp th02\op_05.cpp th02\op_06.cpp
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -Z -DGAME=2 -nbin\th02\ -eOP.EXE @&&|
$**
|
bin\th02\main.exe: bin\th02\main.obj bin\th02\zunerror.obj th02\main02_1.cpp bin\th02\pi_load.obj bin\th02\vector.obj bin\frmdely1.obj th02\main02_2.cpp bin\th02\exit.obj bin\th02\snd_mmdr.obj bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th02\snd_dlyv.obj bin\th02\snd_load.obj th02\mptn_i.cpp bin\th02\initmain.obj bin\th02\pi_put.obj bin\th02\snd_kaja.obj bin\th02\snd_dlym.obj bin\th02\snd_se.obj th02\main_03.cpp
bin\th02\main.exe: bin\th02\main.obj bin\th02\zunerror.obj th02\main02_1.cpp bin\th02\pi_load.obj bin\th02\vector.obj bin\frmdely1.obj bin\th02\input_s.obj bin\th02\exit.obj bin\th02\snd_mmdr.obj bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th02\snd_dlyv.obj bin\th02\snd_load.obj th02\mptn_i.cpp bin\th02\initmain.obj bin\th02\pi_put.obj bin\th02\snd_kaja.obj bin\th02\snd_dlym.obj bin\th02\snd_se.obj th02\main_03.cpp
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -Z -DGAME=2 -nbin\th02\ -eMAIN.EXE @&&|
$**
|
bin\th02\maine.exe: bin\th02\maine.obj bin\th02\grppsafx.obj th02\maine021.cpp bin\th02\pi_load.obj bin\frmdely1.obj th02\maine022.cpp bin\th02\exit.obj bin\th02\snd_mmdr.obj bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th02\snd_load.obj bin\th02\initmain.obj bin\th02\pi_put.obj bin\th02\snd_kaja.obj bin\th02\snd_dlym.obj th02\maine_03.c th02\maine_04.cpp th02\maine_05.cpp
bin\th02\maine.exe: bin\th02\maine.obj bin\th02\grppsafx.obj th02\maine021.cpp bin\th02\pi_load.obj bin\frmdely1.obj th02\maine022.cpp bin\th02\input_s.obj bin\th02\exit.obj bin\th02\snd_mmdr.obj bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th02\snd_load.obj bin\th02\initmain.obj bin\th02\pi_put.obj bin\th02\snd_kaja.obj bin\th02\snd_dlym.obj th02\maine_03.c th02\maine_04.cpp th02\maine_05.cpp
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -3 -Z -DGAME=2 -nbin\th02\ -eMAINE.EXE @&&|
$**
|

View File

@ -1,5 +1,6 @@
typedef uint16_t input_t;
static const input_t INPUT_NONE = 0x0000;
static const input_t INPUT_UP = 0x0001;
static const input_t INPUT_DOWN = 0x0002;
static const input_t INPUT_LEFT = 0x0004;

View File

@ -1,67 +1,80 @@
#include "pc98kbd.h"
#pragma option -k-
void input_sense(void)
{
#define KEYGROUP_SENSE(group) __asm { \
mov al, group; \
mov ah, 4; \
int 0x18; \
}
key_det = 0;
KEYGROUP_SENSE(7);
_BH = _AH;
KEYGROUP_SENSE(8);
if(_BH & K7_ARROW_UP || _AH & K8_NUM_8) {
key_det |= INPUT_UP;
}
if(_BH & K7_ARROW_LEFT || _AH & K8_NUM_4) {
key_det |= INPUT_LEFT;
}
if(_AH & K8_NUM_7) {
key_det |= INPUT_UP_LEFT;
}
if(_AH & K8_NUM_9) {
key_det |= INPUT_UP_RIGHT;
}
KEYGROUP_SENSE(9);
if(_BH & K7_ARROW_DOWN || _AH & K9_NUM_2) {
key_det |= INPUT_DOWN;
}
if(_BH & K7_ARROW_RIGHT || _AH & K9_NUM_6) {
key_det |= INPUT_RIGHT;
}
if(_AH & K9_NUM_1) {
key_det |= INPUT_DOWN_LEFT;
}
if(_AH & K9_NUM_3) {
key_det |= INPUT_DOWN_RIGHT;
}
KEYGROUP_SENSE(5);
if(_AH & K5_Z) {
key_det |= INPUT_SHOT;
}
if(_AH & K5_X) {
key_det |= INPUT_BOMB;
}
KEYGROUP_SENSE(0);
if(_AH & K0_ESC) {
key_det |= INPUT_CANCEL;
}
KEYGROUP_SENSE(3);
if(_AH & K3_RETURN) {
key_det |= INPUT_OK;
}
KEYGROUP_SENSE(2);
if(_AH & K2_Q) {
key_det |= INPUT_Q;
}
KEYGROUP_SENSE(6);
if(_AH & K6_SPACE) {
key_det |= INPUT_SHOT;
}
}
#pragma codestring "\x90"
#pragma option -k
#pragma codeseg SHARED
#pragma option -k-
extern "C" {
#include "platform.h"
#include "x86real.h"
#include "pc98kbd.h"
#include "th02/hardware/input.hpp"
inline uint8_t keygroup_sense(uint8_t group) {
_AL = group;
_AH = 0x04;
geninterrupt(0x18);
return _AH;
}
void input_sense(void)
{
key_det = INPUT_NONE;
_BH = keygroup_sense(7);
_AH = keygroup_sense(8);
if(_BH & K7_ARROW_UP || _AH & K8_NUM_8) {
key_det |= INPUT_UP;
}
if(_BH & K7_ARROW_LEFT || _AH & K8_NUM_4) {
key_det |= INPUT_LEFT;
}
if(_AH & K8_NUM_7) {
key_det |= INPUT_UP_LEFT;
}
if(_AH & K8_NUM_9) {
key_det |= INPUT_UP_RIGHT;
}
_AH = keygroup_sense(9);
if(_BH & K7_ARROW_DOWN || _AH & K9_NUM_2) {
key_det |= INPUT_DOWN;
}
if(_BH & K7_ARROW_RIGHT || _AH & K9_NUM_6) {
key_det |= INPUT_RIGHT;
}
if(_AH & K9_NUM_1) {
key_det |= INPUT_DOWN_LEFT;
}
if(_AH & K9_NUM_3) {
key_det |= INPUT_DOWN_RIGHT;
}
_AH = keygroup_sense(5);
if(_AH & K5_Z) {
key_det |= INPUT_SHOT;
}
if(_AH & K5_X) {
key_det |= INPUT_BOMB;
}
_AH = keygroup_sense(0);
if(_AH & K0_ESC) {
key_det |= INPUT_CANCEL;
}
_AH = keygroup_sense(3);
if(_AH & K3_RETURN) {
key_det |= INPUT_OK;
}
_AH = keygroup_sense(2);
if(_AH & K2_Q) {
key_det |= INPUT_Q;
}
_AH = keygroup_sense(6);
if(_AH & K6_SPACE) {
key_det |= INPUT_SHOT;
}
}
#pragma codestring "\x90"
}

1
th02/input_s.cpp Normal file
View File

@ -0,0 +1 @@
#include "th02/hardware/input_s.cpp"

View File

@ -1,16 +0,0 @@
/* ReC98
* -----
* 2nd part of code segment #2 of TH02's MAIN.EXE
*/
#pragma codeseg SHARED
#pragma option -3
extern "C" {
#include "platform.h"
#include "master.hpp"
#include "th02/hardware/frmdelay.h"
#include "th02/hardware/input.hpp"
#include "th02/hardware/input.c"
}

View File

@ -8,12 +8,8 @@
extern "C" {
#include "platform.h"
#include "master.hpp"
#include "th02/hardware/frmdelay.h"
#include "th02/hardware/input.hpp"
#include "th02/formats/pf.hpp"
#include "th02/snd/data.c"
extern const char pf_fn[] = PF_FN;
#include "th02/hardware/input.c"
}

View File

@ -1,14 +0,0 @@
/* ReC98
* -----
* 2nd part of code segment #2 of TH02's OP.EXE
*/
#pragma codeseg SHARED
#pragma option -3
extern "C" {
#include "platform.h"
#include "th02/hardware/input.hpp"
#include "th02/hardware/input.c"
}