From 243ee0632669fc97cb0a3e07cc015ac5139f6564 Mon Sep 17 00:00:00 2001 From: Hay1tsme Date: Fri, 25 Apr 2025 18:49:01 -0400 Subject: [PATCH] card reader: progress --- board/k92x0249.c | 127 ++++++++++++++++------------------------------- board/k92x0249.h | 23 +++++++++ iccard/mifare.h | 8 +++ jvs/jvs-cmd.h | 8 +++ 4 files changed, 81 insertions(+), 85 deletions(-) diff --git a/board/k92x0249.c b/board/k92x0249.c index 6b11ebf..6da4f7a 100644 --- a/board/k92x0249.c +++ b/board/k92x0249.c @@ -17,84 +17,22 @@ // JVS card reader, A/B/C vairants -static const uint8_t k92x0249_ident[] = "TAITO CORP.;JVS Reader;Ver1.00;0000.00.00"; -//static const uint8_t k92x0249_ident[] = "TAITO CORP.;JVS Reader;Ver0.20;0000.00.00"; +static const uint8_t k92x0249_ident[] = "TAITO CORP.;RFID CTRL P.C.B.;Ver1.11;"; // non-AICC: TAITO CORP.;JVS Reader;Ver1.00; static uint8_t k92x0249_features[] = { - /* Feature : 0x01 : Players and switches - Param1 : 1 : Number of players - Param2 : 18 : Number of switches per player - Param3 : 0 : N/A */ - - 0x01, - 0x01, - 0x18, + // Misc. SW + 0x07, + 0x00, + 0x08, 0x00, - /* Feature : 0x02 : Coin slots - Param1 : 2 : Number of coin slots - Param2 : 0 : N/A - Param3 : 0 : N/A */ - - 0x02, - 0x00, - 0x00, - 0x00, - - /* Feature : 0x03 : Analog inputs - Param1 : 8 : Number of ADC channels - Param2 : 10 : Effective bits of resolution per ADC - Param3 : 0 : N/A */ - - 0x03, - 0x00, - 0x00, - 0x00, - - /* Feature : 0x04 : Rotary Input - Param1 : 4 : Number of Rotary channels - Param2 : 0 : N/A - Param3 : 0 : N/A */ - - 0x04, - 0x00, - 0x00, - 0x00, - - /* Feature : 0x12 : GPIO outputs - Param1 : 3 : Number of ports (8 bits per port) - Param2 : 0 : N/A - Param3 : 0 : N/A - */ - + // GPIO Out 0x12, - 0x00, - 0x00, - 0x00, - - /* Feature : 0x13 : Analog outputs - Param1 : 2 : Number of channels - Param2 : 0 : N/A - Param3 : 0 : N/A - */ - - 0x13, - 0x00, + 0x08, 0x00, 0x00, - /* Feature : 0x14 : Character Output - Param1 : 0x50 : Width - Param2 : 0x19 : Height - Param3 : 0 : Type - */ - 0x14, - 0x50, - 0x19, - 0x00, - - /* Feature : 0x00 : End of capabilities */ - + // End 0x00, }; @@ -118,7 +56,9 @@ static HRESULT k92x0249_cmd_get_cmd_version(struct k92x0249 *k92x0249, struct co static HRESULT k92x0249_cmd_get_jvs_version(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, struct iobuf *resp_buf); 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); void k92x0249_init( struct k92x0249 *k92x0249, @@ -134,6 +74,7 @@ void k92x0249_init( k92x0249->jvs.sense = k92x0249_sense; k92x0249->jvs.sense_out = true; k92x0249->addr = 0xFF; + k92x0249->state = IDLE; k92x0249->ops = ops; k92x0249->ops_ctx = ops_ctx; } @@ -183,7 +124,7 @@ static HRESULT k92x0249_cmd( iobuf_read_8(req, &req_len); // Read the length for variable-length commands - k92x0249 = ctx; + k92x0249 = (struct k92x0249 *)ctx; switch (req->bytes[req->pos]) { case JVS_CMD_RESET: @@ -207,8 +148,14 @@ static HRESULT k92x0249_cmd( case JVS_CMD_GET_FEATURES: return k92x0249_cmd_get_features(k92x0249, req, resp); - case JVS_CMD_READ_MISC_SWITCHES: + case JVS_CMD_WRITE_GPIO1: + 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); default: dprintf("K92X0249: Node %02x: Unhandled command byte %02x\n", @@ -381,6 +328,21 @@ static HRESULT k92x0249_cmd_get_features(struct k92x0249 *k92x0249, struct const return iobuf_write(resp_buf, k92x0249_features, sizeof(k92x0249_features)); } +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 + + if (FAILED(hr)) { + return hr; + } + + k92x0249->state = state; + + dprintf("K92X0249: Set state %02X", state); + return iobuf_write_8(resp_buf, 0x01); /* Write report byte */ +} + static HRESULT k92x0249_cmd_read_misc_switches(struct k92x0249 *k92x0249, struct const_iobuf *req_buf, uint8_t req_len, struct iobuf *resp_buf) { uint8_t req[255]; @@ -404,19 +366,14 @@ static HRESULT k92x0249_cmd_read_misc_switches(struct k92x0249 *k92x0249, struct return hr; } - return iobuf_write_8(resp_buf, 0x00); /* Write switch byte */ - // Below will trip a card request with blank info - // hr = iobuf_write(resp_buf, (uint8_t *)"7020000000000000", 16); /* Nesica ID */ + if (k92x0249->state == POLL_NESICA && (GetAsyncKeyState(VK_RETURN) & 0x8000)) { + return iobuf_write_8(resp_buf, BLUE_NESICA | CARD_TOUCHED | SUCCESS); + } - // if (FAILED(hr)) { - // return hr; - // } + return iobuf_write_8(resp_buf, NO_CARD); /* Write status byte */ +} - // hr = iobuf_write(resp_buf, (uint8_t *)"00000000000000000000", 20); /* Access Code */ - - // if (FAILED(hr)) { - // return hr; - // } - - // return iobuf_write_8(resp_buf, 0x01); /* is AICC */ +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 */ } diff --git a/board/k92x0249.h b/board/k92x0249.h index af34d8a..d8aaf4d 100644 --- a/board/k92x0249.h +++ b/board/k92x0249.h @@ -3,6 +3,7 @@ #include "jvs/jvs-bus.h" +#pragma pack(push,1) struct k92x0249_ops { void (*reset)(void *ctx); void (*write_led)(void *ctx, uint32_t state); @@ -11,11 +12,33 @@ struct k92x0249_ops { struct k92x0249 { struct jvs_node jvs; + uint8_t state; uint8_t addr; const struct k92x0249_ops *ops; void *ops_ctx; }; +#pragma pack(pop) + +enum k92x0249_state { + IDLE = 0x00, + READY = 0x80, // unsure + POLL_NESICA = 0xC0, // Blue or red + POLL_AICC = 0xC2, // any AmusementIC card +}; + +enum k92x0249_card_status { + NO_CARD = 0x00, + BLUE_NESICA = 0x01, + AICC = 0x02, + UNK04 = 0x04, + CARD_TOUCHED = 0x08, + SUCCESS = 0x10, + ERR = 0x20, + UNK40 = 0x40, + UNK80 = 0x80, +}; + void k92x0249_init( struct k92x0249 *k92x0249, struct jvs_node *next, diff --git a/iccard/mifare.h b/iccard/mifare.h index 10dbc34..c4f4e83 100644 --- a/iccard/mifare.h +++ b/iccard/mifare.h @@ -2,6 +2,7 @@ #include +#pragma pack(push,1) struct mifare_block { uint8_t bytes[16]; }; @@ -13,3 +14,10 @@ struct mifare_sector { struct mifare { struct mifare_sector sectors[16]; }; + +struct nesica_mifare { + uint8_t uid[7]; + char nesica_id[16]; +}; + +#pragma pack(pop) \ No newline at end of file diff --git a/jvs/jvs-cmd.h b/jvs/jvs-cmd.h index 19a44f6..5e3d328 100644 --- a/jvs/jvs-cmd.h +++ b/jvs/jvs-cmd.h @@ -30,6 +30,14 @@ enum { JVS_CMD_WRITE_GPIO2 = 0x37, JVS_CMD_WRITE_GPIO3 = 0x38, + JVS_CMD_TAITO_60 = 0x60, + JVS_CMD_TAITO_NESICA_READ = 0x61, + JVS_CMD_TAITO_NOOP_62 = 0x62, + JVS_CMD_TAITO_NOOP_63 = 0x63, + JVS_CMD_TAITO_NOOP_64 = 0x64, + JVS_CMD_TAITO_UNK65 = 0x65, + JVS_CMD_TAITO_AIC_READ = 0x65, + JVS_CMD_RESET = 0xF0, JVS_CMD_ASSIGN_ADDR = 0xF1, JVS_CMD_CHANGE_COMM_METHOD = 0xF2,