From ec17bbc82c9878b03804fcda38243b3f8260a345 Mon Sep 17 00:00:00 2001 From: esterTion Date: Wed, 4 Mar 2020 20:14:24 +0800 Subject: [PATCH] function key input from shared memory --- aimeio/aimeio.c | 43 ++++++++++++++++++++++++++++++++++++++++++- chuniio/chuniio.c | 25 +++++++++++++++++-------- 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/aimeio/aimeio.c b/aimeio/aimeio.c index 747205d..3234f99 100644 --- a/aimeio/aimeio.c +++ b/aimeio/aimeio.c @@ -26,6 +26,40 @@ static uint8_t aime_io_felica_id[8]; static bool aime_io_aime_id_present; static bool aime_io_felica_id_present; +struct IPCMemoryInfo +{ + uint8_t airIoStatus[6]; + uint8_t sliderIoStatus[32]; + uint8_t ledRgbData[32 * 3]; + uint8_t testBtn; + uint8_t serviceBtn; + uint8_t coinInsertion; + uint8_t cardRead; +}; +typedef struct IPCMemoryInfo IPCMemoryInfo; +static HANDLE FileMappingHandle; +IPCMemoryInfo* FileMapping; + +void initSharedMemory() +{ + if (FileMapping) + { + return; + } + if ((FileMappingHandle = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, sizeof(IPCMemoryInfo), "Local\\BROKENITHM_SHARED_BUFFER")) == 0) + { + return; + } + + if ((FileMapping = (IPCMemoryInfo*)MapViewOfFile(FileMappingHandle, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(IPCMemoryInfo))) == 0) + { + return; + } + + memset(FileMapping, 0, sizeof(IPCMemoryInfo)); + SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_CONTINUOUS); +} + static void aime_io_config_read( struct aime_io_config *cfg, const wchar_t *filename); @@ -166,6 +200,8 @@ HRESULT aime_io_init(void) { aime_io_config_read(&aime_io_cfg, L".\\segatools.ini"); + initSharedMemory(); + return S_OK; } @@ -189,7 +225,12 @@ HRESULT aime_io_nfc_poll(uint8_t unit_no) /* Don't do anything more if the scan key is not held */ - sense = GetAsyncKeyState(aime_io_cfg.vk_scan) & 0x8000; + if (FileMapping && FileMapping->cardRead) { + sense = true; + FileMapping->cardRead = 0; + } else { + sense = GetAsyncKeyState(aime_io_cfg.vk_scan) & 0x8000; + } if (!sense) { return S_OK; diff --git a/chuniio/chuniio.c b/chuniio/chuniio.c index 0a0af71..4e27c12 100644 --- a/chuniio/chuniio.c +++ b/chuniio/chuniio.c @@ -20,6 +20,10 @@ struct IPCMemoryInfo uint8_t airIoStatus[6]; uint8_t sliderIoStatus[32]; uint8_t ledRgbData[32 * 3]; + uint8_t testBtn; + uint8_t serviceBtn; + uint8_t coinInsertion; + uint8_t cardRead; }; typedef struct IPCMemoryInfo IPCMemoryInfo; static HANDLE FileMappingHandle; @@ -60,13 +64,18 @@ void chuni_io_jvs_read_coin_counter(uint16_t *out) return; } - if (GetAsyncKeyState(chuni_io_cfg.vk_coin)) { - if (!chuni_io_coin) { - chuni_io_coin = true; - chuni_io_coins++; - } + if (FileMapping && FileMapping->coinInsertion) { + chuni_io_coins++; + FileMapping->coinInsertion = 0; } else { - chuni_io_coin = false; + if (GetAsyncKeyState(chuni_io_cfg.vk_coin)) { + if (!chuni_io_coin) { + chuni_io_coin = true; + chuni_io_coins++; + } + } else { + chuni_io_coin = false; + } } *out = chuni_io_coins; @@ -76,11 +85,11 @@ void chuni_io_jvs_poll(uint8_t *opbtn, uint8_t *beams) { size_t i; - if (GetAsyncKeyState(chuni_io_cfg.vk_test)) { + if ((FileMapping && FileMapping->testBtn) || GetAsyncKeyState(chuni_io_cfg.vk_test)) { *opbtn |= 0x01; /* Test */ } - if (GetAsyncKeyState(chuni_io_cfg.vk_service)) { + if ((FileMapping && FileMapping->serviceBtn) || GetAsyncKeyState(chuni_io_cfg.vk_service)) { *opbtn |= 0x02; /* Service */ }