working jvs reader (thanks szymex73!)

This commit is contained in:
Hay1tsme
2025-04-27 12:16:35 -04:00
parent a5241fbb4e
commit 565632d7fb
10 changed files with 87 additions and 92 deletions
+12
View File
@@ -14,3 +14,15 @@ void io4_config_load(struct io4_config *cfg, const wchar_t *filename)
cfg->enable = GetPrivateProfileIntW(L"io4", L"enable", 1, filename);
}
void k92x0249_config_load(struct k92x0249_config *cfg, const wchar_t *filename)
{
assert(cfg != NULL);
assert(filename != NULL);
wchar_t wserial[17];
cfg->read_button = GetPrivateProfileIntW(L"reader", L"read_button", VK_RETURN, filename);
GetPrivateProfileStringW(L"reader", L"card_serial", L"7020392000000000", wserial, _countof(wserial), filename);
wcstombs_s(NULL, cfg->serial, sizeof(cfg->serial), wserial, sizeof(cfg->serial) - 1);
}
+2
View File
@@ -4,5 +4,7 @@
#include <stddef.h>
#include "board/io4.h"
#include "board/k92x0249.h"
void io4_config_load(struct io4_config *cfg, const wchar_t *filename);
void k92x0249_config_load(struct k92x0249_config *cfg, const wchar_t *filename);
+63 -39
View File
@@ -7,6 +7,7 @@
#include <stdlib.h>
#include "board/k92x0249.h"
#include "board/config.h"
#include "jvs/jvs-bus.h"
#include "jvs/jvs-cmd.h"
@@ -17,7 +18,9 @@
// JVS card reader, A/B/C vairants
static const uint8_t k92x0249_ident[] = "TAITO CORP.;RFID CTRL P.C.B.;Ver1.11;"; // non-AICC: TAITO CORP.;JVS Reader;Ver1.00;
static const uint8_t k92x0249_ident[] = "TAITO CORP.;RFID CTRL P.C.B.;Ver1.00;";
static const uint8_t card_uid[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00 };
static struct k92x0249_config cfg;
static uint8_t k92x0249_features[] = {
// Misc. SW
@@ -57,17 +60,16 @@ static HRESULT k92x0249_cmd_get_jvs_version(struct k92x0249 *k92x0249, struct co
static HRESULT k92x0249_cmd_get_comm_version(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, struct iobuf *resp_buf);
static HRESULT k92x0249_cmd_get_features(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, struct iobuf *resp_buf);
static HRESULT k92x0249_cmd_write_gpio1(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, struct iobuf *resp_buf);
static HRESULT k92x0249_cmd_read_misc_switches(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, uint8_t req_len, struct iobuf *resp_buf);
static HRESULT k92x0249_cmd_nesica_read(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, uint8_t req_len, struct iobuf *resp_buf);
static HRESULT k92x0249_cmd_read_misc_switches(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, struct iobuf *resp_buf);
void k92x0249_init(
struct k92x0249 *k92x0249,
struct jvs_node *next,
const struct k92x0249_ops *ops,
void *ops_ctx)
{
assert(k92x0249 != NULL);
assert(ops != NULL);
k92x0249_config_load(&cfg, L".\\taitools.ini");
k92x0249->jvs.next = next;
k92x0249->jvs.transact = k92x0249_transact;
@@ -75,7 +77,6 @@ void k92x0249_init(
k92x0249->jvs.sense_out = true;
k92x0249->addr = 0xFF;
k92x0249->state = IDLE;
k92x0249->ops = ops;
k92x0249->ops_ctx = ops_ctx;
}
@@ -120,9 +121,6 @@ static HRESULT k92x0249_cmd(
struct iobuf *resp)
{
struct k92x0249 *k92x0249;
uint8_t req_len;
iobuf_read_8(req, &req_len); // Read the length for variable-length commands
k92x0249 = (struct k92x0249 *)ctx;
@@ -152,15 +150,14 @@ static HRESULT k92x0249_cmd(
return k92x0249_cmd_write_gpio1(k92x0249, req, resp);
case JVS_CMD_READ_MISC_SWITCHES: // used to check reader state?
return k92x0249_cmd_read_misc_switches(k92x0249, req, req_len, resp);
case JVS_CMD_TAITO_NESICA_READ:
return k92x0249_cmd_nesica_read(k92x0249, req, req_len, resp);
return k92x0249_cmd_read_misc_switches(k92x0249, req, resp);
default:
dprintf("K92X0249: Node %02x: Unhandled command byte %02x\n",
dprintf("K92X0249: Node %02x: Unhandled command byte @ %02X %02x\n",
k92x0249->addr,
req->pos,
req->bytes[req->pos]);
dump_const_iobuf(req);
return E_NOTIMPL;
}
@@ -181,11 +178,7 @@ static HRESULT k92x0249_cmd_reset(struct k92x0249 *k92x0249, struct const_iobuf
dprintf("K92X0249: Reset (param %02x)\n", req.unknown);
k92x0249->addr = 0xFF;
k92x0249->jvs.sense_out = false; // ?
if (k92x0249->ops->reset != NULL) {
k92x0249->ops->reset(k92x0249->ops_ctx);
}
k92x0249->jvs.sense_out = false;
/* No ack for this since it really is addressed to everybody */
@@ -330,31 +323,66 @@ static HRESULT k92x0249_cmd_get_features(struct k92x0249 *k92x0249, struct const
static HRESULT k92x0249_cmd_write_gpio1(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, struct iobuf *resp_buf)
{
uint8_t state;
HRESULT hr = iobuf_read_8(req_buf, &state); // set reader state
uint8_t unk;
uint8_t num_io;
uint8_t io_state[255];
HRESULT hr = iobuf_read_8(req_buf, &unk);
if (FAILED(hr)) {
return hr;
}
hr = iobuf_read_8(req_buf, &num_io);
if (FAILED(hr)) {
return hr;
}
k92x0249->state = state;
hr = iobuf_read(req_buf, io_state, num_io);
dprintf("K92X0249: Set state %02X", state);
return iobuf_write_8(resp_buf, 0x01); /* Write report byte */
if (FAILED(hr)) {
return hr;
}
if (k92x0249->state != io_state[0]) {
dprintf("K92X0249: Update state %02X\n", io_state[0]);
}
k92x0249->state = io_state[0];
hr = iobuf_write_8(resp_buf, 0x01); /* Write report byte */
if (FAILED(hr)) {
return hr;
}
hr = iobuf_write(resp_buf, card_uid, 8);
if (FAILED(hr)) {
return hr;
}
return iobuf_write(resp_buf, cfg.serial, 16);
}
static HRESULT k92x0249_cmd_read_misc_switches(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, uint8_t req_len, struct iobuf *resp_buf)
static HRESULT k92x0249_cmd_read_misc_switches(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, struct iobuf *resp_buf)
{
uint8_t req[255];
uint8_t cmd;
uint8_t num_switches;
uint8_t switches[255];
HRESULT hr;
#if 0
dprintf("K92X0249: Read misc switches\n");
dump_const_iobuf(req_buf);
#endif
// data bytes: 01 61 32 01 80
hr = iobuf_read(req_buf, &req, req_len - 1); // duno what these bytes mean...
hr = iobuf_read_8(req_buf, &cmd);
if (FAILED(hr)) {
return hr;
}
hr = iobuf_read_8(req_buf, &num_switches);
if (FAILED(hr)) {
return hr;
}
hr = iobuf_read(req_buf, switches, num_switches);
if (FAILED(hr)) {
return hr;
@@ -366,14 +394,10 @@ static HRESULT k92x0249_cmd_read_misc_switches(struct k92x0249 *k92x0249, struct
return hr;
}
if (k92x0249->state == POLL_NESICA && (GetAsyncKeyState(VK_RETURN) & 0x8000)) {
if (k92x0249->state == POLL_AICC && (GetAsyncKeyState(cfg.read_button) & 0x8000)) {
dprintf("K92X0249: Detect Card\n");
return iobuf_write_8(resp_buf, BLUE_NESICA | CARD_TOUCHED | SUCCESS);
}
return iobuf_write_8(resp_buf, NO_CARD); /* Write status byte */
}
static HRESULT k92x0249_cmd_nesica_read(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, uint8_t req_len, struct iobuf *resp_buf)
{
return iobuf_write_8(resp_buf, 0x01); /* Write status byte */
}
+5 -8
View File
@@ -4,20 +4,18 @@
#include "jvs/jvs-bus.h"
#pragma pack(push,1)
struct k92x0249_ops {
void (*reset)(void *ctx);
void (*write_led)(void *ctx, uint32_t state);
void (*poll_card)(void *ctx, char *serial);
};
struct k92x0249 {
struct jvs_node jvs;
uint8_t state;
uint8_t addr;
const struct k92x0249_ops *ops;
void *ops_ctx;
};
struct k92x0249_config {
uint8_t read_button;
char serial[17];
};
#pragma pack(pop)
enum k92x0249_state {
@@ -42,7 +40,6 @@ enum k92x0249_card_status {
void k92x0249_init(
struct k92x0249 *k92x0249,
struct jvs_node *next,
const struct k92x0249_ops *ops,
void *ops_ctx);
struct jvs_node *k92x0249_to_jvs_node(struct k92x0249 *k92x0249);