mirror of
https://gitea.tendokyu.moe/TeamTofuShop/taitools.git
synced 2026-10-09 06:59:59 +03:00
156 lines
3.5 KiB
C
156 lines
3.5 KiB
C
#include <windows.h>
|
|
|
|
#include <limits.h>
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <stdbool.h>
|
|
|
|
#include "gcio/gcio.h"
|
|
#include "gcio/config.h"
|
|
#include "ri/ri.h"
|
|
|
|
#include "util/dprintf.h"
|
|
|
|
static bool gc_io_coin = false;
|
|
static bool gc_io_service = false;
|
|
static uint16_t gc_coin_ct = 0;
|
|
static uint16_t gc_service_ct = 0;
|
|
static struct gc_input_config cfg;
|
|
static CRITICAL_SECTION ri_critsec;
|
|
|
|
void ri_mouse_input_cb(PRI_DEVICE dev, PRAWMOUSE mouse);
|
|
void ri_kb_input_cb(PRI_DEVICE dev, PRAWKEYBOARD kb);
|
|
void ri_hid_input_cb(PRI_DEVICE dev, PRAWHID hid);
|
|
|
|
uint16_t gc_io_get_api_version(void)
|
|
{
|
|
return 0x0100;
|
|
}
|
|
|
|
HRESULT gc_io_init(void)
|
|
{
|
|
HRESULT hr = S_OK;
|
|
dprintf("Gc IO: Init\n");
|
|
gc_io_config_load(&cfg, L".\\taitools.ini");
|
|
|
|
if (cfg.is_ri) {
|
|
InitializeCriticalSection(&ri_critsec);
|
|
hr = ri_init(cfg.device_num, ri_mouse_input_cb, ri_kb_input_cb, ri_hid_input_cb);
|
|
|
|
if (FAILED(hr) || hr == S_FALSE) {
|
|
DeleteCriticalSection(&ri_critsec);
|
|
cfg.is_ri = 0;
|
|
}
|
|
}
|
|
return hr;
|
|
}
|
|
|
|
void gc_io_get_btns(uint8_t *btn, uint8_t *stick)
|
|
{
|
|
if (cfg.is_ri) {
|
|
|
|
} else {
|
|
if (GetAsyncKeyState(cfg.btn_l) & 0x8000) {
|
|
*btn |= BTN_LEFT;
|
|
}
|
|
|
|
if (GetAsyncKeyState(cfg.btn_r) & 0x8000) {
|
|
*btn |= BTN_RIGHT;
|
|
}
|
|
|
|
if (GetAsyncKeyState(cfg.stick_l_up) & 0x8000) {
|
|
*stick |= STICK_LEFT_UP;
|
|
}
|
|
|
|
if (GetAsyncKeyState(cfg.stick_l_down) & 0x8000) {
|
|
*stick |= STICK_LEFT_DOWN;
|
|
}
|
|
|
|
if (GetAsyncKeyState(cfg.stick_l_left) & 0x8000) {
|
|
*stick |= STICK_LEFT_LEFT;
|
|
}
|
|
|
|
if (GetAsyncKeyState(cfg.stick_l_right) & 0x8000) {
|
|
*stick |= STICK_LEFT_RIGHT;
|
|
}
|
|
|
|
if (GetAsyncKeyState(cfg.stick_r_up) & 0x8000) {
|
|
*stick |= STICK_RIGHT_UP;
|
|
}
|
|
|
|
if (GetAsyncKeyState(cfg.stick_r_down) & 0x8000) {
|
|
*stick |= STICK_RIGHT_DOWN;
|
|
}
|
|
|
|
if (GetAsyncKeyState(cfg.stick_r_left) & 0x8000) {
|
|
*stick |= STICK_RIGHT_LEFT;
|
|
}
|
|
|
|
if (GetAsyncKeyState(cfg.stick_r_right) & 0x8000) {
|
|
*stick |= STICK_RIGHT_RIGHT;
|
|
}
|
|
}
|
|
|
|
if (GetAsyncKeyState(cfg.test) & 0x8000) {
|
|
*btn |= BTN_TEST;
|
|
}
|
|
|
|
if (GetAsyncKeyState(cfg.service) & 0x8000) {
|
|
*btn |= BTN_SERVICE;
|
|
}
|
|
|
|
if (GetAsyncKeyState(cfg.select) & 0x8000) {
|
|
*btn |= BTN_SELECT;
|
|
}
|
|
|
|
if (GetAsyncKeyState(cfg.enter) & 0x8000) {
|
|
*btn |= BTN_ENTER;
|
|
}
|
|
|
|
}
|
|
|
|
void gc_io_read_coin_counter(uint16_t *coins, uint16_t *services)
|
|
{
|
|
if (GetAsyncKeyState(cfg.coin) & 0x8000) {
|
|
if (!gc_io_coin) {
|
|
gc_io_coin = true;
|
|
gc_coin_ct++;
|
|
}
|
|
} else {
|
|
gc_io_coin = false;
|
|
}
|
|
|
|
if (GetAsyncKeyState(cfg.service) & 0x8000) {
|
|
if (!gc_io_service) {
|
|
gc_io_service = true;
|
|
gc_service_ct++;
|
|
}
|
|
} else {
|
|
gc_io_service = false;
|
|
}
|
|
|
|
*coins = gc_coin_ct;
|
|
*services = gc_service_ct;
|
|
}
|
|
|
|
void ri_mouse_input_cb(PRI_DEVICE dev, PRAWMOUSE mouse)
|
|
{
|
|
|
|
}
|
|
|
|
void ri_kb_input_cb(PRI_DEVICE dev, PRAWKEYBOARD kb)
|
|
{
|
|
|
|
}
|
|
|
|
void ri_hid_input_cb(PRI_DEVICE dev, PRAWHID hid)
|
|
{
|
|
DWORD bfr_size = hid->dwCount * hid->dwSizeHid;
|
|
dprintf("GCIO: HID input - %d elements * %d bytes per element = %d\n", (int)hid->dwCount, (int)hid->dwSizeHid, (int)bfr_size);
|
|
|
|
for (int i = 0; i < bfr_size; i++) {
|
|
dprintf(" %02X", hid->bRawData[i]);
|
|
}
|
|
dprintf("\n");
|
|
}
|