main
io.h
1/*
2 Copyright 2013 Michael Pavone
3 This file is part of BlastEm.
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
5*/
6#ifndef IO_H_
7#define IO_H_
8#include <stdint.h>
9#include "tern.h"
10#include "romdb.h"
11#include "serialize.h"
12
13enum {
14 IO_NONE,
15 IO_GAMEPAD2,
16 IO_GAMEPAD3,
17 IO_GAMEPAD6,
18 IO_MOUSE,
19 IO_SATURN_KEYBOARD,
20 IO_XBAND_KEYBOARD,
21 IO_MENACER,
22 IO_JUSTIFIER,
23 IO_SEGA_MULTI,
24 IO_EA_MULTI_A,
25 IO_EA_MULTI_B,
26 IO_SEGA_PARALLEL,
27 IO_GENERIC
28};
29
30typedef struct {
31 union {
32 struct {
33 uint32_t timeout_cycle;
34 uint16_t th_counter;
35 uint16_t gamepad_num;
36 } pad;
37 struct {
38 int data_fd;
39 int listen_fd;
40 } stream;
41 struct {
42 uint32_t ready_cycle;
43 uint16_t last_read_x;
44 uint16_t last_read_y;
45 uint16_t cur_x;
46 uint16_t cur_y;
47 uint16_t latched_x;
48 uint16_t latched_y;
49 uint8_t tr_counter;
50 uint8_t mouse_num;
51 } mouse;
52 struct {
53 uint16_t events[8];
54 uint8_t read_pos;
55 uint8_t write_pos;
56 uint8_t tr_counter;
57 uint8_t mode;
58 uint8_t cmd;
59 } keyboard;
60 } device;
61 uint8_t output;
62 uint8_t control;
63 uint8_t input[3];
64 uint32_t slow_rise_start[8];
65 uint8_t serial_out;
66 uint8_t serial_in;
67 uint8_t serial_ctrl;
68 uint8_t device_type;
69} io_port;
70
71typedef struct {
72 io_port ports[3];
73} sega_io;
74
75//pseudo gamepad for buttons on main console unit
76#define GAMEPAD_MAIN_UNIT 255
77
78enum {
79 BUTTON_INVALID,
80 DPAD_UP,
81 DPAD_DOWN,
82 DPAD_LEFT,
83 DPAD_RIGHT,
84 BUTTON_A,
85 BUTTON_B,
86 BUTTON_C,
87 BUTTON_START,
88 BUTTON_X,
89 BUTTON_Y,
90 BUTTON_Z,
91 BUTTON_MODE,
92 NUM_GAMEPAD_BUTTONS
93};
94
95enum {
96 MAIN_UNIT_PAUSE
97};
98
99enum {
100 MOUSE_LEFT = 1,
101 MOUSE_RIGHT = 2,
102 MOUSE_MIDDLE = 4,
103 MOUSE_START = 8,
104 PSEUDO_BUTTON_MOTION=0xFF
105};
106
107void setup_io_devices(tern_node * config, rom_info *rom, sega_io *io);
108void io_adjust_cycles(io_port * pad, uint32_t current_cycle, uint32_t deduction);
109void io_control_write(io_port *port, uint8_t value, uint32_t current_cycle);
110void io_data_write(io_port * pad, uint8_t value, uint32_t current_cycle);
111uint8_t io_data_read(io_port * pad, uint32_t current_cycle);
112void io_serialize(io_port *port, serialize_buffer *buf);
113void io_deserialize(deserialize_buffer *buf, void *vport);
114
115void io_port_gamepad_down(io_port *port, uint8_t button);
116void io_port_gamepad_up(io_port *port, uint8_t button);
117void io_gamepad_down(sega_io *io, uint8_t gamepad_num, uint8_t button);
118void io_gamepad_up(sega_io *io, uint8_t gamepad_num, uint8_t button);
119void io_mouse_down(sega_io *io, uint8_t mouse_num, uint8_t button);
120void io_mouse_up(sega_io *io, uint8_t mouse_num, uint8_t button);
121void io_mouse_motion_absolute(sega_io *io, uint8_t mouse_num, uint16_t x, uint16_t y);
122void io_mouse_motion_relative(sega_io *io, uint8_t mouse_num, int32_t x, int32_t y);
123void io_keyboard_down(sega_io *io, uint8_t scancode);
124void io_keyboard_up(sega_io *io, uint8_t scancode);
125uint8_t io_has_keyboard(sega_io *io);
126
127extern const char * device_type_names[];
128
129#endif //IO_H_
130