butchered fastio

This commit is contained in:
Hay1tsme
2026-03-14 21:44:00 -04:00
parent 7e7197b108
commit c9a97c3fdb
6 changed files with 88 additions and 53 deletions
-1
View File
@@ -22,7 +22,6 @@ HRESULT gc_fastio_init(struct fastio_node *out)
assert(out != NULL);
out->next = NULL;
out->digital_in = gc_fastio_digital_read;
out->coins_in = gc_fastio_coin_read;
+21 -1
View File
@@ -4,7 +4,7 @@
#include "jvs/jvs-bus.h"
#include "idmac/fastio.h"
enum {
/* enum {
GC_SWITCH_RIGHT_BUTTON = 0x000080,
GC_SWITCH_RIGHT_UP = 0x010000,
GC_SWITCH_RIGHT_DOWN = 0x040000,
@@ -20,6 +20,26 @@ enum {
GC_SWITCH_SYS_SELECT = 0x000008,
GC_SWITCH_SYS_ENTER = 0x000010,
GC_SWITCH_SYS_COIN = 0x000001,
}; */
enum {
GC_SWITCH_SYS_SERVICE = (1 << 1),
//P1_SERVICE_F1 = (1 << 2),
//P1_SERVICE_P = (1 << 3),
GC_SWITCH_SYS_SELECT = (1 << 4), // P1 start
GC_SWITCH_SYS_TEST = (1 << 6), // Test
GC_SWITCH_RIGHT_UP = (1 << 8), // P1 up
GC_SWITCH_LEFT_UP = (1 << 9), // P2 up
GC_SWITCH_RIGHT_DOWN = (1 << 10), // P1 down
GC_SWITCH_LEFT_DOWN = (1 << 11), // P2 down
GC_SWITCH_RIGHT_LEFT = (1 << 12), // P1 left
GC_SWITCH_LEFT_LEFT = (1 << 13), // P2 left
GC_SWITCH_RIGHT_RIGHT = (1 << 14), // P1 right
GC_SWITCH_LEFT_RIGHT = (1 << 15), // P2 right
GC_SWITCH_RIGHT_BUTTON = (1 << 16), // P1 btn1
GC_SWITCH_LEFT_BUTTON = (1 << 17), // P2 btn2
//P2_SERVICE = (1 << 2), // P2 service
GC_SWITCH_SYS_ENTER = (1 << 5), // P2 start
};
HRESULT gc_fastio_init(struct fastio_node *out);
+61 -48
View File
@@ -4,8 +4,8 @@
#include "idmac/fastio.h"
#include "util/dprintf.h"
static struct fastio_node fio_main;
static struct fastio_node fio_sub;
static struct fastio_node *fio_main = NULL;
static struct fastio_node *fio_sub = NULL;
HRESULT fastio_hook_init(fastio_provider_t main, fastio_provider_t sub)
{
@@ -15,8 +15,14 @@ HRESULT fastio_hook_init(fastio_provider_t main, fastio_provider_t sub)
dprintf("FastIO: Init main %p sub %p\n", main, sub);
if (main != NULL) {
fio_main.board_no = 0; // Maybe 0 should be the PCB itself and connected IO boards start at 1?
hr = main(&fio_main);
if (fio_main != NULL) {
free(fio_main);
fio_main = NULL;
}
fio_main = malloc(sizeof(struct fastio_node));
fio_main->board_no = 0; // Maybe 0 should be the PCB itself and connected IO boards start at 1?
hr = main(fio_main);
}
if (FAILED(hr)) {
@@ -25,98 +31,105 @@ HRESULT fastio_hook_init(fastio_provider_t main, fastio_provider_t sub)
if (sub != NULL) {
// TODO: Unsure if "sub" is treated as input from another box, or just a 2nd link in the chain
fio_sub.board_no = 1;
hr = sub(&fio_sub);
if (fio_sub != NULL) {
free(fio_sub);
fio_sub = NULL;
}
fio_sub = malloc(sizeof(struct fastio_node));
fio_sub->board_no = 1;
hr = sub(fio_sub);
}
return hr;
}
// TODO: Sub-board support
/// Itterate over the chain of connected boards and return a pointer to the board with the requested number
void fastio_match_board_number(uint8_t board_no, struct fastio_node root, struct fastio_node *board)
// FIXME This entire file is a horrific mess...
void fastio_find_board(uint8_t board_no, struct fastio_node **out)
{
assert(&root != NULL);
// FIXME
board = &root;
while (board->next != NULL && board->next->board_no != board_no) {
board = board->next;
if (fio_main != NULL) {
*out = fio_main;
/* while (out->next != NULL && out->next->board_no != board_no) {
out = out->next;
}
if (out->board_no == board_no) { return; } */
}
if (board->board_no != board_no) {
// We've exhausted our boards, give a warning and set boards to NULL
#if 0
dprintf("FastIO: Could not find board number %d\n", board_no);
#endif
board = NULL;
if (fio_sub != NULL) {
*out = fio_sub;
/*while (out->next != NULL && out->next->board_no != board_no) {
out = out->next;
}
if (out->board_no != board_no) { out = NULL; }*/
}
}
void fastio_reset(void* ctx, uint8_t board_no, uint32_t in) {
struct fastio_node *req_board = NULL;
fastio_match_board_number(board_no, fio_main, req_board);
void fastio_reset(void* ctx, uint8_t board_no, uint32_t in)
{
//struct fastio_node *req_board = board_no ? fio_sub : fio_main;
//fastio_find_board(board_no, &req_board);
// If we fail to find, or the board we found doesn't have the handler we need,
// quietly return with out unmodified
if (req_board != NULL && req_board->reset != NULL) {
fio_main.reset(ctx, in);
if (fio_main != NULL && fio_main->reset != NULL) {
fio_main->reset(ctx, in);
}
}
void fastio_digital_read(void* ctx, uint8_t board_no, uint32_t *out)
{
struct fastio_node *req_board = NULL;
fastio_match_board_number(board_no, fio_main, req_board);
//struct fastio_node *req_board = board_no ? fio_sub : fio_main;
//fastio_find_board(board_no, &req_board);
// If we fail to find, or the board we found doesn't have the handler we need,
// quietly return with out unmodified
if (req_board != NULL && req_board->digital_in != NULL) {
//if (fio_main.digital_in != NULL) {
fio_main.digital_in(ctx, out);
if (board_no == 0 && fio_main != NULL && fio_main->digital_in != NULL) {
fio_main->digital_in(ctx, out);
} else if (board_no == 1 && fio_sub != NULL && fio_sub->digital_in != NULL) {
fio_sub->digital_in(ctx, out);
}
}
void fastio_coins_in(void* ctx, uint8_t board_no, uint8_t slot_no, uint32_t *out)
{
struct fastio_node *req_board = NULL;
fastio_match_board_number(board_no, fio_main, req_board);
//struct fastio_node *req_board = board_no ? fio_sub : fio_main;
//fastio_find_board(board_no, &req_board);
// If we fail to find, or the board we found doesn't have the handler we need,
// quietly return with out unmodified
if (req_board != NULL && req_board->coins_in != NULL) {
fio_main.coins_in(ctx, slot_no, out);
if (fio_main != NULL && fio_main->coins_in != NULL) {
fio_main->coins_in(ctx, slot_no, out);
}
}
void fastio_analog_in(void* ctx, uint8_t board_no, uint8_t analog_no, uint32_t *out)
{
struct fastio_node *req_board = NULL;
fastio_match_board_number(board_no, fio_main, req_board);
//struct fastio_node *req_board = board_no ? fio_sub : fio_main;
//fastio_find_board(board_no, &req_board);
// If we fail to find, or the board we found doesn't have the handler we need,
// quietly return with out unmodified
if (req_board != NULL && req_board->analog_in != NULL) {
fio_main.analog_in(ctx, analog_no, out);
if (fio_main != NULL && fio_main->analog_in != NULL) {
fio_main->analog_in(ctx, analog_no, out);
}
}
void fastio_coins_out(void* ctx, uint8_t board_no, uint8_t slot_no, uint32_t in) {
struct fastio_node *req_board = NULL;
fastio_match_board_number(board_no, fio_main, req_board);
//struct fastio_node *req_board = board_no ? fio_sub : fio_main;
//fastio_find_board(board_no, &req_board);
// If we fail to find, or the board we found doesn't have the handler we need,
// quietly return with out unmodified
if (req_board != NULL && req_board->coins_out != NULL) {
fio_main.coins_out(ctx, slot_no, in);
if (fio_main != NULL && fio_main->coins_out != NULL) {
fio_main->coins_out(ctx, slot_no, in);
}
}
void fastio_gpio_out(void* ctx, uint8_t board_no, uint8_t channel, uint32_t in) {
struct fastio_node *req_board = NULL;
fastio_match_board_number(board_no, fio_main, req_board);
//struct fastio_node *req_board = board_no ? fio_sub : fio_main;
//fastio_find_board(board_no, &req_board);
// If we fail to find, or the board we found doesn't have the handler we need,
// quietly return with out unmodified
if (req_board != NULL && req_board->gpio_out != NULL) {
fio_main.gpio_out(ctx, channel, in);
if (fio_main != NULL && fio_main->gpio_out != NULL) {
fio_main->gpio_out(ctx, channel, in);
}
}
-1
View File
@@ -4,7 +4,6 @@
#pragma pack(push, 1)
struct fastio_node {
struct fastio_node *next;
uint8_t board_no;
// Unlike JVS, FastIO comms are done on the game side through
// DMA register reads and writes, meaning we need to have
+6 -1
View File
@@ -26,6 +26,7 @@
static uint8_t dipsw = 0;
static HANDLE idmac_fd;
static CRITICAL_SECTION idmac_critsec;
static HRESULT idmac_handle_irp(struct irp *irp);
static HRESULT idmac_handle_open(struct irp *irp);
@@ -192,6 +193,8 @@ HRESULT idmac_hook_init(const struct idmac_config *cfg, struct idmac_hardware *h
return hr;
}
InitializeCriticalSection(&idmac_critsec);
return S_OK;
}
@@ -310,7 +313,7 @@ static int hook_iDmacDrvRegisterRead(HANDLE a1, DWORD register_id, DWORD* regist
*err = 0;
switch (register_id) {
case 0x0400: break; // DMA card ID
case 0x0400: *register_val = 0x00010201; break; // DMA card ID
// Magic values taken from https://github.com/asesidaa/GCLoader-new/blob/main/iDmacDrv32.cpp
// Both of these were set to -2 prior to work with TFFAC...
@@ -318,7 +321,9 @@ static int hook_iDmacDrvRegisterRead(HANDLE a1, DWORD register_id, DWORD* regist
case 0x4004: *register_val = 0x00FF0000; break; // Sub Status
case 0x4120: // Main Buttons
EnterCriticalSection(&idmac_critsec);
fastio_digital_read(NULL, 0, (uint32_t *)register_val);
LeaveCriticalSection(&idmac_critsec);
break;
case 0x4124: // Analog 1
-1
View File
@@ -22,7 +22,6 @@ HRESULT siva_fastio_init(struct fastio_node *out)
assert(out != NULL);
out->next = NULL;
out->digital_in = siva_fastio_digital_read;
out->coins_in = siva_fastio_coin_read;