forked from Dniel97/segatools
board/sg-reader.c: Streamline further
Remove remaining pointless boilerplate, turn it into a free- standing hook, since its aimeio.dll dependency forces it to be a singleton anyway.
This commit is contained in:
parent
8158d01ed9
commit
b172c22322
@ -17,18 +17,14 @@
|
||||
#include "util/dprintf.h"
|
||||
#include "util/dump.h"
|
||||
|
||||
static HRESULT sg_reader_handle_irp_locked(
|
||||
struct sg_reader *reader,
|
||||
struct irp *irp);
|
||||
|
||||
static HRESULT sg_reader_handle_irp(struct irp *irp);
|
||||
static HRESULT sg_reader_handle_irp_locked(struct irp *irp);
|
||||
static HRESULT sg_reader_mifare_poll(void *ctx, uint32_t *uid);
|
||||
|
||||
static HRESULT sg_reader_mifare_read_luid(
|
||||
void *ctx,
|
||||
uint32_t uid,
|
||||
uint8_t *luid,
|
||||
size_t luid_size);
|
||||
|
||||
static void sg_reader_led_set_color(void *ctx, uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
static const struct sg_nfc_ops sg_reader_nfc_ops = {
|
||||
@ -40,59 +36,55 @@ static const struct sg_led_ops sg_reader_led_ops = {
|
||||
.set_color = sg_reader_led_set_color,
|
||||
};
|
||||
|
||||
HRESULT sg_reader_init(
|
||||
struct sg_reader *reader,
|
||||
unsigned int port_no)
|
||||
static CRITICAL_SECTION sg_reader_lock;
|
||||
static struct uart sg_reader_uart;
|
||||
static uint8_t sg_reader_written_bytes[520];
|
||||
static uint8_t sg_reader_readable_bytes[520];
|
||||
static struct sg_nfc sg_reader_nfc;
|
||||
static struct sg_led sg_reader_led;
|
||||
|
||||
HRESULT sg_reader_hook_init(unsigned int port_no)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
assert(reader != NULL);
|
||||
|
||||
hr = aime_io_init();
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
sg_nfc_init(&reader->nfc, 0x00, &sg_reader_nfc_ops, reader);
|
||||
sg_led_init(&reader->led, 0x08, &sg_reader_led_ops, reader);
|
||||
sg_nfc_init(&sg_reader_nfc, 0x00, &sg_reader_nfc_ops, NULL);
|
||||
sg_led_init(&sg_reader_led, 0x08, &sg_reader_led_ops, NULL);
|
||||
|
||||
InitializeCriticalSection(&reader->lock);
|
||||
InitializeCriticalSection(&sg_reader_lock);
|
||||
|
||||
uart_init(&reader->uart, port_no);
|
||||
reader->uart.written.bytes = reader->written_bytes;
|
||||
reader->uart.written.nbytes = sizeof(reader->written_bytes);
|
||||
reader->uart.readable.bytes = reader->readable_bytes;
|
||||
reader->uart.readable.nbytes = sizeof(reader->readable_bytes);
|
||||
uart_init(&sg_reader_uart, port_no);
|
||||
sg_reader_uart.written.bytes = sg_reader_written_bytes;
|
||||
sg_reader_uart.written.nbytes = sizeof(sg_reader_written_bytes);
|
||||
sg_reader_uart.readable.bytes = sg_reader_readable_bytes;
|
||||
sg_reader_uart.readable.nbytes = sizeof(sg_reader_readable_bytes);
|
||||
|
||||
return S_OK;
|
||||
return iohook_push_handler(sg_reader_handle_irp);
|
||||
}
|
||||
|
||||
bool sg_reader_match_irp(const struct sg_reader *reader, const struct irp *irp)
|
||||
{
|
||||
assert(reader != NULL);
|
||||
assert(irp != NULL);
|
||||
|
||||
return uart_match_irp(&reader->uart, irp);
|
||||
}
|
||||
|
||||
HRESULT sg_reader_handle_irp(struct sg_reader *reader, struct irp *irp)
|
||||
static HRESULT sg_reader_handle_irp(struct irp *irp)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
assert(reader != NULL);
|
||||
assert(irp != NULL);
|
||||
|
||||
EnterCriticalSection(&reader->lock);
|
||||
hr = sg_reader_handle_irp_locked(reader, irp);
|
||||
LeaveCriticalSection(&reader->lock);
|
||||
if (!uart_match_irp(&sg_reader_uart, irp)) {
|
||||
return iohook_invoke_next(irp);
|
||||
}
|
||||
|
||||
EnterCriticalSection(&sg_reader_lock);
|
||||
hr = sg_reader_handle_irp_locked(irp);
|
||||
LeaveCriticalSection(&sg_reader_lock);
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT sg_reader_handle_irp_locked(
|
||||
struct sg_reader *reader,
|
||||
struct irp *irp)
|
||||
static HRESULT sg_reader_handle_irp_locked(struct irp *irp)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
@ -106,29 +98,29 @@ static HRESULT sg_reader_handle_irp_locked(
|
||||
#if 0
|
||||
if (irp->op == IRP_OP_READ) {
|
||||
dprintf("READ:\n");
|
||||
dump_iobuf(&reader->uart.readable);
|
||||
dump_iobuf(&sg_reader_uart.readable);
|
||||
}
|
||||
#endif
|
||||
|
||||
hr = uart_handle_irp(&reader->uart, irp);
|
||||
hr = uart_handle_irp(&sg_reader_uart, irp);
|
||||
|
||||
if (FAILED(hr) || irp->op != IRP_OP_WRITE) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
sg_nfc_transact(
|
||||
&reader->nfc,
|
||||
&reader->uart.readable,
|
||||
reader->uart.written.bytes,
|
||||
reader->uart.written.pos);
|
||||
&sg_reader_nfc,
|
||||
&sg_reader_uart.readable,
|
||||
sg_reader_uart.written.bytes,
|
||||
sg_reader_uart.written.pos);
|
||||
|
||||
sg_led_transact(
|
||||
&reader->led,
|
||||
&reader->uart.readable,
|
||||
reader->uart.written.bytes,
|
||||
reader->uart.written.pos);
|
||||
&sg_reader_led,
|
||||
&sg_reader_uart.readable,
|
||||
sg_reader_uart.written.bytes,
|
||||
sg_reader_uart.written.pos);
|
||||
|
||||
reader->uart.written.pos = 0;
|
||||
sg_reader_uart.written.pos = 0;
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
@ -2,27 +2,4 @@
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "board/sg-led.h"
|
||||
#include "board/sg-nfc.h"
|
||||
|
||||
#include "hooklib/uart.h"
|
||||
|
||||
struct sg_reader {
|
||||
CRITICAL_SECTION lock;
|
||||
struct uart uart;
|
||||
uint8_t written_bytes[520];
|
||||
uint8_t readable_bytes[520];
|
||||
struct sg_nfc nfc;
|
||||
struct sg_led led;
|
||||
};
|
||||
|
||||
HRESULT sg_reader_init(
|
||||
struct sg_reader *reader,
|
||||
unsigned int port_no);
|
||||
|
||||
bool sg_reader_match_irp(const struct sg_reader *reader, const struct irp *irp);
|
||||
|
||||
HRESULT sg_reader_handle_irp(struct sg_reader *reader, struct irp *irp);
|
||||
HRESULT sg_reader_hook_init(unsigned int port_no);
|
||||
|
@ -1,37 +0,0 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "board/sg-reader.h"
|
||||
|
||||
#include "cardhook/_com12.h"
|
||||
|
||||
#include "hook/iohook.h"
|
||||
|
||||
static HRESULT com12_handle_irp(struct irp *irp);
|
||||
|
||||
static struct sg_reader com12_reader;
|
||||
|
||||
HRESULT com12_hook_init(void)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
hr = sg_reader_init(&com12_reader, 12);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
return iohook_push_handler(com12_handle_irp);
|
||||
}
|
||||
|
||||
static HRESULT com12_handle_irp(struct irp *irp)
|
||||
{
|
||||
assert(irp != NULL);
|
||||
|
||||
if (!sg_reader_match_irp(&com12_reader, irp)) {
|
||||
return iohook_invoke_next(irp);
|
||||
}
|
||||
|
||||
return sg_reader_handle_irp(&com12_reader, irp);
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
HRESULT com12_hook_init(void);
|
@ -1,6 +1,6 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include "cardhook/_com12.h"
|
||||
#include "board/sg-reader.h"
|
||||
|
||||
#include "hook/process.h"
|
||||
|
||||
@ -15,9 +15,10 @@ static DWORD CALLBACK app_pre_startup(void)
|
||||
{
|
||||
dprintf("--- Begin %s ---\n", __func__);
|
||||
|
||||
serial_hook_init();
|
||||
spike_hook_init("cardspike.txt");
|
||||
com12_hook_init();
|
||||
|
||||
serial_hook_init();
|
||||
sg_reader_hook_init(12);
|
||||
|
||||
dprintf("--- End %s ---\n", __func__);
|
||||
|
||||
|
@ -14,7 +14,6 @@ shared_library(
|
||||
util_lib,
|
||||
],
|
||||
sources : [
|
||||
'_com12.c',
|
||||
'dllmain.c',
|
||||
],
|
||||
)
|
||||
|
@ -1,38 +0,0 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "board/sg-reader.h"
|
||||
|
||||
#include "divahook/_com10.h"
|
||||
|
||||
#include "hook/iohook.h"
|
||||
|
||||
static HRESULT com10_handle_irp(struct irp *irp);
|
||||
|
||||
static struct sg_reader com10_reader;
|
||||
|
||||
HRESULT com10_hook_init(void)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
hr = sg_reader_init(&com10_reader, 10);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
return iohook_push_handler(com10_handle_irp);
|
||||
}
|
||||
|
||||
static HRESULT com10_handle_irp(struct irp *irp)
|
||||
{
|
||||
assert(irp != NULL);
|
||||
|
||||
if (!sg_reader_match_irp(&com10_reader, irp)) {
|
||||
return iohook_invoke_next(irp);
|
||||
}
|
||||
|
||||
return sg_reader_handle_irp(&com10_reader, irp);
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
HRESULT com10_hook_init(void);
|
@ -9,7 +9,8 @@
|
||||
#include "amex/jvs.h"
|
||||
#include "amex/sram.h"
|
||||
|
||||
#include "divahook/_com10.h"
|
||||
#include "board/sg-reader.h"
|
||||
|
||||
#include "divahook/jvs.h"
|
||||
#include "divahook/slider.h"
|
||||
|
||||
@ -51,8 +52,8 @@ static DWORD CALLBACK diva_pre_startup(void)
|
||||
|
||||
/* Initialize Project Diva I/O board emulation */
|
||||
|
||||
com10_hook_init();
|
||||
diva_jvs_init();
|
||||
sg_reader_hook_init(10);
|
||||
slider_hook_init();
|
||||
|
||||
/* Initialize debug helpers */
|
||||
|
@ -19,7 +19,6 @@ shared_library(
|
||||
util_lib,
|
||||
],
|
||||
sources : [
|
||||
'_com10.c',
|
||||
'dllmain.c',
|
||||
'jvs.c',
|
||||
'jvs.h',
|
||||
|
@ -1,38 +0,0 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "board/sg-reader.h"
|
||||
|
||||
#include "hook/iohook.h"
|
||||
|
||||
#include "idzhook/_com10.h"
|
||||
|
||||
static HRESULT com10_handle_irp(struct irp *irp);
|
||||
|
||||
static struct sg_reader com10_reader;
|
||||
|
||||
HRESULT com10_hook_init(void)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
hr = sg_reader_init(&com10_reader, 10);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
return iohook_push_handler(com10_handle_irp);
|
||||
}
|
||||
|
||||
static HRESULT com10_handle_irp(struct irp *irp)
|
||||
{
|
||||
assert(irp != NULL);
|
||||
|
||||
if (!sg_reader_match_irp(&com10_reader, irp)) {
|
||||
return iohook_invoke_next(irp);
|
||||
}
|
||||
|
||||
return sg_reader_handle_irp(&com10_reader, irp);
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
HRESULT com10_hook_init(void);
|
@ -9,11 +9,12 @@
|
||||
#include "amex/jvs.h"
|
||||
#include "amex/sram.h"
|
||||
|
||||
#include "board/sg-reader.h"
|
||||
|
||||
#include "hook/process.h"
|
||||
|
||||
#include "hooklib/serial.h"
|
||||
|
||||
#include "idzhook/_com10.h"
|
||||
#include "idzhook/jvs.h"
|
||||
|
||||
#include "platform/hwmon.h"
|
||||
@ -50,8 +51,8 @@ static DWORD CALLBACK idz_pre_startup(void)
|
||||
|
||||
/* Initialize Initial D Zero I/O board emulation */
|
||||
|
||||
com10_hook_init();
|
||||
idz_jvs_init();
|
||||
sg_reader_hook_init(10);
|
||||
|
||||
/* Initialize debug helpers */
|
||||
|
||||
|
@ -19,7 +19,6 @@ shared_library(
|
||||
util_lib,
|
||||
],
|
||||
sources : [
|
||||
'_com10.c',
|
||||
'dllmain.c',
|
||||
'jvs.c',
|
||||
'jvs.h',
|
||||
|
Loading…
Reference in New Issue
Block a user