2018-11-08 22:11:07 +01:00
|
|
|
#include <windows.h>
|
|
|
|
|
2018-11-23 20:37:42 +01:00
|
|
|
#include <assert.h>
|
2018-11-08 22:11:07 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2019-03-04 23:22:38 +01:00
|
|
|
#include "amex/jvs.h"
|
|
|
|
|
2018-11-08 22:11:07 +01:00
|
|
|
#include "board/io3.h"
|
|
|
|
|
2019-05-03 04:12:06 +02:00
|
|
|
#include "chuniio/chuniio.h"
|
|
|
|
|
2018-11-08 22:11:07 +01:00
|
|
|
#include "jvs/jvs-bus.h"
|
|
|
|
|
|
|
|
#include "util/dprintf.h"
|
|
|
|
|
2019-05-03 04:12:06 +02:00
|
|
|
struct chunithm_jvs_ir_mask {
|
|
|
|
uint16_t p1;
|
|
|
|
uint16_t p2;
|
|
|
|
};
|
|
|
|
|
2018-11-08 22:11:07 +01:00
|
|
|
static void chunithm_jvs_read_switches(void *ctx, struct io3_switch_state *out);
|
2019-08-03 23:41:39 +02:00
|
|
|
static void chunithm_jvs_read_coin_counter(
|
|
|
|
void *ctx,
|
|
|
|
uint8_t slot_no,
|
|
|
|
uint16_t *out);
|
2018-11-08 22:11:07 +01:00
|
|
|
|
|
|
|
static const struct io3_ops chunithm_jvs_io3_ops = {
|
2019-05-03 01:38:39 +02:00
|
|
|
.read_switches = chunithm_jvs_read_switches,
|
|
|
|
.read_coin_counter = chunithm_jvs_read_coin_counter,
|
2018-11-08 22:11:07 +01:00
|
|
|
};
|
|
|
|
|
2019-05-03 04:12:06 +02:00
|
|
|
static const struct chunithm_jvs_ir_mask chunithm_jvs_ir_masks[] = {
|
|
|
|
{ 0x0000, 0x0020 },
|
|
|
|
{ 0x0020, 0x0000 },
|
|
|
|
{ 0x0000, 0x0010 },
|
|
|
|
{ 0x0010, 0x0000 },
|
|
|
|
{ 0x0000, 0x0008 },
|
|
|
|
{ 0x0008, 0x0000 },
|
|
|
|
};
|
|
|
|
|
2018-11-08 22:11:07 +01:00
|
|
|
static struct io3 chunithm_jvs_io3;
|
|
|
|
|
|
|
|
void chunithm_jvs_init(void)
|
|
|
|
{
|
|
|
|
io3_init(&chunithm_jvs_io3, NULL, &chunithm_jvs_io3_ops, NULL);
|
|
|
|
jvs_attach(&chunithm_jvs_io3.jvs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void chunithm_jvs_read_switches(void *ctx, struct io3_switch_state *out)
|
|
|
|
{
|
2019-05-03 04:12:06 +02:00
|
|
|
uint8_t opbtn;
|
|
|
|
uint8_t beams;
|
|
|
|
size_t i;
|
2018-11-08 22:11:07 +01:00
|
|
|
|
2019-05-03 04:12:06 +02:00
|
|
|
assert(out != NULL);
|
2018-11-08 22:11:07 +01:00
|
|
|
|
2019-05-03 04:12:06 +02:00
|
|
|
opbtn = 0;
|
|
|
|
beams = 0;
|
2018-11-08 22:11:07 +01:00
|
|
|
|
2019-05-03 04:12:06 +02:00
|
|
|
chuni_io_jvs_poll(&opbtn, &beams);
|
2018-11-08 22:11:07 +01:00
|
|
|
|
2019-05-03 04:12:06 +02:00
|
|
|
out->system = 0x00;
|
|
|
|
out->p1 = 0x0000;
|
|
|
|
out->p2 = 0x0000;
|
2018-11-08 22:11:07 +01:00
|
|
|
|
2019-05-03 04:12:06 +02:00
|
|
|
if (opbtn & 0x01) {
|
2018-11-08 22:11:07 +01:00
|
|
|
out->system = 0x80;
|
|
|
|
} else {
|
2019-05-03 04:12:06 +02:00
|
|
|
out->system = 0x00;
|
2018-11-08 22:11:07 +01:00
|
|
|
}
|
|
|
|
|
2019-05-03 04:12:06 +02:00
|
|
|
if (opbtn & 0x02) {
|
2018-11-08 22:11:07 +01:00
|
|
|
out->p1 |= 0x4000;
|
|
|
|
}
|
2019-05-03 04:12:06 +02:00
|
|
|
|
|
|
|
for (i = 0 ; i < 6 ; i++) {
|
2019-06-09 21:40:16 +02:00
|
|
|
/* Beam "press" is active-low hence the ~ */
|
|
|
|
if (~beams & (1 << i)) {
|
2019-05-03 04:12:06 +02:00
|
|
|
out->p1 |= chunithm_jvs_ir_masks[i].p1;
|
|
|
|
out->p2 |= chunithm_jvs_ir_masks[i].p2;
|
|
|
|
}
|
|
|
|
}
|
2018-11-08 22:11:07 +01:00
|
|
|
}
|
|
|
|
|
2019-08-03 23:41:39 +02:00
|
|
|
static void chunithm_jvs_read_coin_counter(
|
|
|
|
void *ctx,
|
|
|
|
uint8_t slot_no,
|
|
|
|
uint16_t *out)
|
2018-11-08 22:11:07 +01:00
|
|
|
{
|
2019-08-03 23:41:39 +02:00
|
|
|
assert(out != NULL);
|
|
|
|
|
2018-11-08 22:11:07 +01:00
|
|
|
if (slot_no > 0) {
|
2019-08-03 23:41:39 +02:00
|
|
|
return;
|
2018-11-08 22:11:07 +01:00
|
|
|
}
|
|
|
|
|
2019-08-03 23:41:39 +02:00
|
|
|
chuni_io_jvs_read_coin_counter(out);
|
2018-11-08 22:11:07 +01:00
|
|
|
}
|