From e405a67b4f56e393725956cbf06211464979206e Mon Sep 17 00:00:00 2001 From: Tau Date: Fri, 30 Aug 2019 18:49:55 -0400 Subject: [PATCH] mu3io: Add initial IO emu for Ongeki --- meson.build | 1 + mu3io/meson.build | 15 +++++ mu3io/mu3io.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++ mu3io/mu3io.def | 8 +++ mu3io/mu3io.h | 28 +++++++++ 5 files changed, 195 insertions(+) create mode 100644 mu3io/meson.build create mode 100644 mu3io/mu3io.c create mode 100644 mu3io/mu3io.def create mode 100644 mu3io/mu3io.h diff --git a/meson.build b/meson.build index f3b2d53..3ee6f9f 100644 --- a/meson.build +++ b/meson.build @@ -41,6 +41,7 @@ subdir('aimeio') subdir('chuniio') subdir('divaio') subdir('idzio') +subdir('mu3io') subdir('cardhook') subdir('chunihook') diff --git a/mu3io/meson.build b/mu3io/meson.build new file mode 100644 index 0000000..74b91ad --- /dev/null +++ b/mu3io/meson.build @@ -0,0 +1,15 @@ +mu3io_dll = shared_library( + 'mu3io', + name_prefix : '', + include_directories : inc, + implicit_include_directories : false, + vs_module_defs : 'mu3io.def', + c_pch : '../precompiled.h', + dependencies : [ + xinput_lib, + ], + sources : [ + 'mu3io.c', + 'mu3io.h', + ], +) diff --git a/mu3io/mu3io.c b/mu3io/mu3io.c new file mode 100644 index 0000000..f0a9e98 --- /dev/null +++ b/mu3io/mu3io.c @@ -0,0 +1,143 @@ +#include +#include + +#include +#include + +#include "mu3io/mu3io.h" + +static uint8_t mu3_opbtn; +static uint8_t mu3_left_btn; +static uint8_t mu3_right_btn; +static int16_t mu3_lever_pos; +static int16_t mu3_lever_xpos; + +HRESULT mu3_io_init(void) +{ + return S_OK; +} + +HRESULT mu3_io_poll(void) +{ + int lever; + int xlever; + XINPUT_STATE xi; + WORD xb; + + mu3_opbtn = 0; + mu3_left_btn = 0; + mu3_right_btn = 0; + + if (GetAsyncKeyState(VK_F1) & 0x8000) { + mu3_opbtn |= MU3_IO_OPBTN_TEST; + } + + if (GetAsyncKeyState(VK_F2) & 0x8000) { + mu3_opbtn |= MU3_IO_OPBTN_SERVICE; + } + + memset(&xi, 0, sizeof(xi)); + XInputGetState(0, &xi); + xb = xi.Gamepad.wButtons; + + if (xb & XINPUT_GAMEPAD_DPAD_LEFT) { + mu3_left_btn |= MU3_IO_GAMEBTN_1; + } + + if (xb & XINPUT_GAMEPAD_DPAD_UP) { + mu3_left_btn |= MU3_IO_GAMEBTN_2; + } + + if (xb & XINPUT_GAMEPAD_DPAD_RIGHT) { + mu3_left_btn |= MU3_IO_GAMEBTN_3; + } + + if (xb & XINPUT_GAMEPAD_X) { + mu3_right_btn |= MU3_IO_GAMEBTN_1; + } + + if (xb & XINPUT_GAMEPAD_Y) { + mu3_right_btn |= MU3_IO_GAMEBTN_2; + } + + if (xb & XINPUT_GAMEPAD_B) { + mu3_right_btn |= MU3_IO_GAMEBTN_3; + } + + if (xb & XINPUT_GAMEPAD_BACK) { + mu3_left_btn |= MU3_IO_GAMEBTN_MENU; + } + + if (xb & XINPUT_GAMEPAD_START) { + mu3_right_btn |= MU3_IO_GAMEBTN_MENU; + } + + if (xb & XINPUT_GAMEPAD_LEFT_SHOULDER) { + mu3_left_btn |= MU3_IO_GAMEBTN_SIDE; + } + + if (xb & XINPUT_GAMEPAD_RIGHT_SHOULDER) { + mu3_right_btn |= MU3_IO_GAMEBTN_SIDE; + } + + lever = mu3_lever_pos; + + if (abs(xi.Gamepad.sThumbLX) > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) { + lever += xi.Gamepad.sThumbLX / 24; + } + + if (abs(xi.Gamepad.sThumbRX) > XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) { + lever += xi.Gamepad.sThumbRX / 24; + } + + if (lever < INT16_MIN) { + lever = INT16_MIN; + } + + if (lever > INT16_MAX) { + lever = INT16_MAX; + } + + mu3_lever_pos = lever; + + xlever = mu3_lever_pos + + xi.Gamepad.bLeftTrigger * 64 + - xi.Gamepad.bRightTrigger * 64; + + if (xlever < INT16_MIN) { + xlever = INT16_MIN; + } + + if (xlever > INT16_MAX) { + xlever = INT16_MAX; + } + + mu3_lever_xpos = xlever; + + return S_OK; +} + +void mu3_io_get_opbtns(uint8_t *opbtn) +{ + if (opbtn != NULL) { + *opbtn = mu3_opbtn; + } +} + +void mu3_io_get_gamebtns(uint8_t *left, uint8_t *right) +{ + if (left != NULL) { + *left = mu3_left_btn; + } + + if (right != NULL ){ + *right = mu3_right_btn; + } +} + +void mu3_io_get_lever(int16_t *pos) +{ + if (pos != NULL) { + *pos = mu3_lever_xpos; + } +} diff --git a/mu3io/mu3io.def b/mu3io/mu3io.def new file mode 100644 index 0000000..33f747f --- /dev/null +++ b/mu3io/mu3io.def @@ -0,0 +1,8 @@ +LIBRARY mu3io + +EXPORTS + mu3_io_get_gamebtns + mu3_io_get_lever + mu3_io_get_opbtns + mu3_io_init + mu3_io_poll diff --git a/mu3io/mu3io.h b/mu3io/mu3io.h new file mode 100644 index 0000000..fb140eb --- /dev/null +++ b/mu3io/mu3io.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +#include + +enum { + MU3_IO_OPBTN_TEST = 0x01, + MU3_IO_OPBTN_SERVICE = 0x02, +}; + +enum { + MU3_IO_GAMEBTN_1 = 0x01, + MU3_IO_GAMEBTN_2 = 0x02, + MU3_IO_GAMEBTN_3 = 0x04, + MU3_IO_GAMEBTN_SIDE = 0x08, + MU3_IO_GAMEBTN_MENU = 0x10, +}; + +HRESULT mu3_io_init(void); + +HRESULT mu3_io_poll(void); + +void mu3_io_get_opbtns(uint8_t *opbtn); + +void mu3_io_get_gamebtns(uint8_t *left, uint8_t *right); + +void mu3_io_get_lever(int16_t *pos);