Bemanitools v5.26 release
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
libs += p3io
|
||||
|
||||
src_p3io := \
|
||||
cmd.c \
|
||||
guid.c \
|
||||
frame.c \
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include "p3io/cmd.h"
|
||||
|
||||
#include "util/log.h"
|
||||
|
||||
uint8_t p3io_req_cmd(const union p3io_req_any *src)
|
||||
{
|
||||
log_assert(src != NULL);
|
||||
|
||||
/* In requests, the command byte is the first byte after the header. */
|
||||
|
||||
return src->raw[sizeof(struct p3io_hdr)];
|
||||
}
|
||||
|
||||
void p3io_resp_init(
|
||||
struct p3io_hdr *dest,
|
||||
size_t nbytes,
|
||||
const struct p3io_hdr *req)
|
||||
{
|
||||
log_assert(dest != NULL);
|
||||
log_assert(req != NULL);
|
||||
log_assert(nbytes < 0x100);
|
||||
|
||||
/* Length byte in this packet format counts everything from the length
|
||||
byte onwards. The length byte itself occurs at the start of the frame. */
|
||||
|
||||
dest->nbytes = nbytes - 1;
|
||||
dest->seq_no = req->seq_no;
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
#ifndef P3IO_CMD_H
|
||||
#define P3IO_CMD_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "p3io/frame.h"
|
||||
|
||||
enum {
|
||||
P3IO_CMD_GET_VERSION = 0x01,
|
||||
P3IO_CMD_SET_WATCHDOG = 0x05,
|
||||
P3IO_CMD_POWEROFF = 0x22,
|
||||
P3IO_CMD_SET_OUTPUTS = 0x24,
|
||||
P3IO_CMD_READ_PLUG = 0x25,
|
||||
P3IO_CMD_GET_CAB_TYPE_OR_DIPSW = 0x27,
|
||||
P3IO_CMD_GET_VIDEO_FREQ = 0x29,
|
||||
P3IO_CMD_SET_MODE = 0x2F,
|
||||
P3IO_CMD_GET_COINSTOCK = 0x31,
|
||||
P3IO_CMD_SET_COINCOUNTER = 0x32,
|
||||
P3IO_CMD_RS232_OPEN_CLOSE = 0x38,
|
||||
P3IO_CMD_RS232_WRITE = 0x3A,
|
||||
P3IO_CMD_RS232_READ = 0x3B,
|
||||
};
|
||||
|
||||
enum {
|
||||
P3IO_RS232_CMD_OPEN = 0x00,
|
||||
P3IO_RS232_CMD_CLOSE = 0xFF,
|
||||
};
|
||||
|
||||
enum {
|
||||
P3IO_RS232_BAUD_19200 = 0x02,
|
||||
P3IO_RS232_BAUD_38400 = 0x03,
|
||||
P3IO_RS232_BAUD_57600 = 0x04,
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
struct p3io_hdr {
|
||||
uint8_t nbytes;
|
||||
uint8_t seq_no;
|
||||
};
|
||||
|
||||
struct p3io_req_u8 {
|
||||
struct p3io_hdr hdr;
|
||||
uint8_t cmd;
|
||||
uint8_t u8;
|
||||
};
|
||||
|
||||
struct p3io_req_get_cab_type_or_dipsw {
|
||||
struct p3io_hdr hdr;
|
||||
uint8_t cmd;
|
||||
uint8_t cab_type_or_dipsw;
|
||||
};
|
||||
|
||||
struct p3io_req_set_coin_counter {
|
||||
struct p3io_hdr hdr;
|
||||
uint8_t cmd;
|
||||
uint8_t coin_counter[2];
|
||||
};
|
||||
|
||||
struct p3io_req_set_outputs {
|
||||
struct p3io_hdr hdr;
|
||||
uint8_t cmd;
|
||||
uint8_t unk_00;
|
||||
uint32_t outputs;
|
||||
};
|
||||
|
||||
struct p3io_req_read_plug {
|
||||
struct p3io_hdr hdr;
|
||||
uint8_t cmd;
|
||||
uint8_t flags;
|
||||
};
|
||||
|
||||
struct p3io_req_rs232_open_close {
|
||||
struct p3io_hdr hdr;
|
||||
uint8_t cmd;
|
||||
uint8_t port_no;
|
||||
uint8_t subcmd;
|
||||
uint8_t baud_code;
|
||||
};
|
||||
|
||||
struct p3io_req_rs232_read {
|
||||
struct p3io_hdr hdr;
|
||||
uint8_t cmd;
|
||||
uint8_t port_no;
|
||||
uint8_t nbytes;
|
||||
};
|
||||
|
||||
struct p3io_req_rs232_write {
|
||||
struct p3io_hdr hdr;
|
||||
uint8_t cmd;
|
||||
uint8_t port_no;
|
||||
uint8_t nbytes;
|
||||
uint8_t bytes[128];
|
||||
};
|
||||
|
||||
union p3io_req_any {
|
||||
struct p3io_hdr hdr;
|
||||
struct p3io_req_u8 u8;
|
||||
struct p3io_req_get_cab_type_or_dipsw cab_type_or_dipsw;
|
||||
struct p3io_req_set_coin_counter set_coin_counter;
|
||||
struct p3io_req_set_outputs set_outputs;
|
||||
struct p3io_req_read_plug read_plug;
|
||||
struct p3io_req_rs232_open_close rs232_open_close;
|
||||
struct p3io_req_rs232_read rs232_read;
|
||||
struct p3io_req_rs232_write rs232_write;
|
||||
uint8_t raw[128];
|
||||
};
|
||||
|
||||
struct p3io_resp_u8 {
|
||||
struct p3io_hdr hdr;
|
||||
uint8_t status;
|
||||
uint8_t u8;
|
||||
};
|
||||
|
||||
struct p3io_resp_get_cab_type_or_dipsw {
|
||||
struct p3io_hdr hdr;
|
||||
uint8_t status;
|
||||
};
|
||||
|
||||
struct p3io_resp_coin_stock {
|
||||
struct p3io_hdr hdr;
|
||||
uint8_t status;
|
||||
uint8_t error;
|
||||
uint16_t slots[2];
|
||||
};
|
||||
|
||||
struct p3io_resp_read_plug {
|
||||
struct p3io_hdr hdr;
|
||||
uint8_t status;
|
||||
uint8_t present;
|
||||
uint8_t rom[8];
|
||||
uint8_t eeprom[32];
|
||||
};
|
||||
|
||||
struct p3io_resp_rs232_read {
|
||||
struct p3io_hdr hdr;
|
||||
uint8_t status;
|
||||
uint8_t nbytes;
|
||||
uint8_t bytes[126];
|
||||
};
|
||||
|
||||
struct p3io_resp_rs232_write {
|
||||
struct p3io_hdr hdr;
|
||||
uint8_t status;
|
||||
uint8_t nbytes;
|
||||
};
|
||||
|
||||
struct p3io_resp_version {
|
||||
struct p3io_hdr hdr;
|
||||
uint8_t status;
|
||||
char str[4];
|
||||
uint32_t major;
|
||||
uint32_t minor;
|
||||
uint32_t patch;
|
||||
};
|
||||
|
||||
union p3io_resp_any {
|
||||
struct p3io_hdr hdr;
|
||||
struct p3io_resp_u8 u8;
|
||||
struct p3io_resp_get_cab_type_or_dipsw cab_type_or_dipsw;
|
||||
struct p3io_resp_coin_stock coin_stock;
|
||||
struct p3io_resp_read_plug read_plug;
|
||||
struct p3io_resp_rs232_read rs232_read;
|
||||
struct p3io_resp_rs232_write rs232_write;
|
||||
struct p3io_resp_version version;
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
uint8_t p3io_req_cmd(const union p3io_req_any *src);
|
||||
|
||||
void p3io_resp_init(
|
||||
struct p3io_hdr *dest,
|
||||
size_t nbytes,
|
||||
const struct p3io_hdr *req);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,108 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "p3io/frame.h"
|
||||
|
||||
#include "util/iobuf.h"
|
||||
#include "util/log.h"
|
||||
|
||||
HRESULT p3io_frame_encode(
|
||||
struct iobuf *dest,
|
||||
const void *ptr,
|
||||
size_t nbytes)
|
||||
{
|
||||
const uint8_t *bytes;
|
||||
uint8_t b;
|
||||
size_t i;
|
||||
|
||||
log_assert(dest != NULL);
|
||||
log_assert(ptr != NULL);
|
||||
|
||||
bytes = ptr;
|
||||
|
||||
if (dest->pos >= dest->nbytes) {
|
||||
goto trunc;
|
||||
}
|
||||
|
||||
dest->bytes[dest->pos++] = 0xAA;
|
||||
|
||||
for (i = 0 ; i < nbytes ; i++) {
|
||||
b = bytes[i];
|
||||
|
||||
if (b == 0xAA || b == 0xFF) {
|
||||
if (dest->pos + 1 >= dest->nbytes) {
|
||||
goto trunc;
|
||||
}
|
||||
|
||||
dest->bytes[dest->pos++] = 0xFF;
|
||||
dest->bytes[dest->pos++] = ~b;
|
||||
} else {
|
||||
if (dest->pos >= dest->nbytes) {
|
||||
goto trunc;
|
||||
}
|
||||
|
||||
dest->bytes[dest->pos++] = b;
|
||||
}
|
||||
}
|
||||
|
||||
if (i < nbytes) {
|
||||
goto trunc;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
|
||||
trunc:
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
HRESULT p3io_frame_decode(
|
||||
struct iobuf *dest,
|
||||
struct const_iobuf *src)
|
||||
{
|
||||
bool escape;
|
||||
uint8_t b;
|
||||
|
||||
log_assert(dest != NULL);
|
||||
log_assert(src != NULL);
|
||||
|
||||
if (src->pos >= src->nbytes || src->bytes[src->pos] != 0xAA) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
src->pos++;
|
||||
escape = false;
|
||||
|
||||
while (src->pos < src->nbytes) {
|
||||
if (dest->pos >= dest->nbytes) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
b = src->bytes[src->pos++];
|
||||
|
||||
if (b == 0xAA) {
|
||||
return E_FAIL;
|
||||
} else if (b == 0xFF) {
|
||||
if (escape) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
escape = true;
|
||||
} else {
|
||||
if (escape) {
|
||||
dest->bytes[dest->pos++] = ~b;
|
||||
} else {
|
||||
dest->bytes[dest->pos++] = b;
|
||||
}
|
||||
|
||||
escape = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (escape) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef P3IO_P3IO_H
|
||||
#define P3IO_P3IO_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "util/iobuf.h"
|
||||
|
||||
HRESULT p3io_frame_encode(
|
||||
struct iobuf *dest,
|
||||
const void *bytes,
|
||||
size_t nbytes);
|
||||
|
||||
HRESULT p3io_frame_decode(
|
||||
struct iobuf *dest,
|
||||
struct const_iobuf *src);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,4 @@
|
||||
#include <windows.h>
|
||||
#include <initguid.h>
|
||||
|
||||
#include "p3io/guid.h"
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef P3IO_GUID_H
|
||||
#define P3IO_GUID_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
DEFINE_GUID(
|
||||
p3io_guid,
|
||||
0x1FA4A480,
|
||||
0xAC60,
|
||||
0x40C7,
|
||||
0xA7, 0xAC, 0x52, 0x79, 0x0F, 0x34, 0x57, 0x5A);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef P3IO_IOCTL_H
|
||||
#define P3IO_IOCTL_H
|
||||
|
||||
enum {
|
||||
P3IO_IOCTL_READ_JAMMA = 0x00222068,
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user