From 07bfcf284162c6c6bec4c086eb535fbacc8c4423 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Fri, 19 Mar 2021 19:27:11 +0100 Subject: [PATCH] [Separate translation units] [th02] input_sense() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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]. --- Makefile.mak | 6 +- th02/hardware/input.hpp | 1 + th02/hardware/{input.c => input_s.cpp} | 147 ++++++++++++++----------- th02/input_s.cpp | 1 + th02/main02_2.cpp | 16 --- th02/maine022.cpp | 4 - th02/op_02_2.cpp | 14 --- 7 files changed, 85 insertions(+), 104 deletions(-) rename th02/hardware/{input.c => input_s.cpp} (65%) create mode 100644 th02/input_s.cpp delete mode 100644 th02/main02_2.cpp delete mode 100644 th02/op_02_2.cpp diff --git a/Makefile.mak b/Makefile.mak index d730ee8e..1db6069a 100644 --- a/Makefile.mak +++ b/Makefile.mak @@ -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 @&&| $** | diff --git a/th02/hardware/input.hpp b/th02/hardware/input.hpp index bb7fd527..055d2bfc 100644 --- a/th02/hardware/input.hpp +++ b/th02/hardware/input.hpp @@ -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; diff --git a/th02/hardware/input.c b/th02/hardware/input_s.cpp similarity index 65% rename from th02/hardware/input.c rename to th02/hardware/input_s.cpp index b3055e23..226526cd 100644 --- a/th02/hardware/input.c +++ b/th02/hardware/input_s.cpp @@ -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" + +} diff --git a/th02/input_s.cpp b/th02/input_s.cpp new file mode 100644 index 00000000..17744546 --- /dev/null +++ b/th02/input_s.cpp @@ -0,0 +1 @@ +#include "th02/hardware/input_s.cpp" diff --git a/th02/main02_2.cpp b/th02/main02_2.cpp deleted file mode 100644 index 2c3899cf..00000000 --- a/th02/main02_2.cpp +++ /dev/null @@ -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" -} diff --git a/th02/maine022.cpp b/th02/maine022.cpp index ab6e6895..2c4a8f33 100644 --- a/th02/maine022.cpp +++ b/th02/maine022.cpp @@ -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" } diff --git a/th02/op_02_2.cpp b/th02/op_02_2.cpp deleted file mode 100644 index 84365fdc..00000000 --- a/th02/op_02_2.cpp +++ /dev/null @@ -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" -}