forked from Hay1tsme/segatools
add ipc component
This commit is contained in:
parent
4c67843f08
commit
57debc7cb9
|
@ -1,6 +1,8 @@
|
|||
#include <windows.h>
|
||||
|
||||
#include <process.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <process.h>
|
||||
|
||||
|
@ -8,6 +10,8 @@
|
|||
#include "mercuryio/config.h"
|
||||
#include "mercuryhook/elisabeth.h"
|
||||
|
||||
#include "util/dprintf.h"
|
||||
|
||||
static unsigned int __stdcall mercury_io_touch_thread_proc(void *ctx);
|
||||
|
||||
static uint8_t mercury_opbtn;
|
||||
|
@ -16,6 +20,42 @@ static struct mercury_io_config mercury_io_cfg;
|
|||
static bool mercury_io_touch_stop_flag;
|
||||
static HANDLE mercury_io_touch_thread;
|
||||
|
||||
struct IPCMemoryInfo
|
||||
{
|
||||
uint8_t testBtn;
|
||||
uint8_t serviceBtn;
|
||||
uint8_t coinBtn;
|
||||
uint8_t cardRead;
|
||||
uint8_t TouchIoStatus[240];
|
||||
uint8_t RGBAData[480 * 4];
|
||||
};
|
||||
|
||||
typedef struct IPCMemoryInfo IPCMemoryInfo;
|
||||
static HANDLE FileMappingHandle;
|
||||
IPCMemoryInfo* FileMapping;
|
||||
|
||||
void initSharedMemory()
|
||||
{
|
||||
dprintf("initSharedMemory\n");
|
||||
dprintf("SharedMemory Size: %d\n", (char)sizeof(IPCMemoryInfo));
|
||||
if (FileMapping)
|
||||
return;
|
||||
if ((FileMappingHandle = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, sizeof(IPCMemoryInfo), "Local\\WACVR_SHARED_BUFFER")) == 0)
|
||||
{
|
||||
dprintf("FileMappingHandle Error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((FileMapping = (IPCMemoryInfo*)MapViewOfFile(FileMappingHandle, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(IPCMemoryInfo))) == 0)
|
||||
{
|
||||
dprintf("FileMapping Error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
memset(FileMapping, 0, sizeof(IPCMemoryInfo));
|
||||
SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_CONTINUOUS);
|
||||
}
|
||||
|
||||
uint16_t mercury_io_get_api_version(void)
|
||||
{
|
||||
return 0x0100;
|
||||
|
@ -25,6 +65,8 @@ HRESULT mercury_io_init(void)
|
|||
{
|
||||
mercury_io_config_load(&mercury_io_cfg, L".\\segatools.ini");
|
||||
|
||||
initSharedMemory();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
@ -33,15 +75,15 @@ HRESULT mercury_io_poll(void)
|
|||
mercury_opbtn = 0;
|
||||
mercury_gamebtn = 0;
|
||||
|
||||
if (GetAsyncKeyState(mercury_io_cfg.vk_test)) {
|
||||
if ((FileMapping && FileMapping->testBtn) || GetAsyncKeyState(mercury_io_cfg.vk_test)) {
|
||||
mercury_opbtn |= MERCURY_IO_OPBTN_TEST;
|
||||
}
|
||||
|
||||
if (GetAsyncKeyState(mercury_io_cfg.vk_service)) {
|
||||
if ((FileMapping && FileMapping->serviceBtn) || GetAsyncKeyState(mercury_io_cfg.vk_service)) {
|
||||
mercury_opbtn |= MERCURY_IO_OPBTN_SERVICE;
|
||||
}
|
||||
|
||||
if (GetAsyncKeyState(mercury_io_cfg.vk_coin)) {
|
||||
if ((FileMapping && FileMapping->coinBtn) || GetAsyncKeyState(mercury_io_cfg.vk_coin)) {
|
||||
mercury_opbtn |= MERCURY_IO_OPBTN_COIN;
|
||||
}
|
||||
|
||||
|
@ -93,29 +135,29 @@ void mercury_io_touch_start(mercury_io_touch_callback_t callback)
|
|||
|
||||
void mercury_io_touch_set_leds(struct led_data data)
|
||||
{
|
||||
|
||||
if (FileMapping)
|
||||
{
|
||||
data.rgba[3] = 0xFF; //IPC idle flag
|
||||
memcpy(FileMapping->RGBAData, data.rgba, 480 * 4);
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned int __stdcall mercury_io_touch_thread_proc(void *ctx)
|
||||
{
|
||||
mercury_io_touch_callback_t callback;
|
||||
bool cellPressed[240];
|
||||
size_t i;
|
||||
|
||||
callback = ctx;
|
||||
|
||||
while (!mercury_io_touch_stop_flag) {
|
||||
for (i = 0 ; i < _countof(cellPressed) ; i++) {
|
||||
if (GetAsyncKeyState(mercury_io_cfg.vk_cell[i])) {
|
||||
cellPressed[i] = true;
|
||||
} else {
|
||||
cellPressed[i] = false;
|
||||
}
|
||||
if (FileMapping) {
|
||||
memcpy(cellPressed, FileMapping->TouchIoStatus, 240);
|
||||
}
|
||||
|
||||
callback(cellPressed);
|
||||
Sleep(1);
|
||||
}
|
||||
|
||||
FileMapping->RGBAData[3] = 0x00; //IPC idle flag
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -4,10 +4,22 @@ mercuryio_lib = static_library(
|
|||
include_directories : inc,
|
||||
implicit_include_directories : false,
|
||||
c_pch : '../precompiled.h',
|
||||
link_with : [
|
||||
util_lib,
|
||||
],
|
||||
sources : [
|
||||
'mercuryio.c',
|
||||
'mercuryio.h',
|
||||
'config.c',
|
||||
'config.h',
|
||||
],
|
||||
)
|
||||
|
||||
shared_library(
|
||||
'mercuryio',
|
||||
name_prefix : '',
|
||||
vs_module_defs : 'mercuryio.def',
|
||||
link_with : [
|
||||
mercuryio_lib,
|
||||
],
|
||||
)
|
Loading…
Reference in New Issue