-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
io-port.c
33 lines (26 loc) · 1.06 KB
/
io-port.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "io-port.h"
#include <string.h>
void IOPort_Initialise(IOPort* const io_port)
{
/* The standard Sega SDK bootcode uses this to detect soft-resets
(it checks if the control value is 0. */
memset(io_port, 0, sizeof(*io_port));
}
void IOPort_SetCallbacks(IOPort* const io_port, const IOPort_ReadCallback read_callback, const IOPort_WriteCallback write_callback)
{
io_port->read_callback = read_callback;
io_port->write_callback = write_callback;
}
cc_u8f IOPort_ReadData(IOPort* const io_port, const cc_u16f cycles, const void *user_data)
{
if (io_port->read_callback == NULL)
return 0;
return (io_port->read_callback((void*)user_data, cycles) & ~io_port->mask) | io_port->cached_write;
}
void IOPort_WriteData(IOPort* const io_port, const cc_u8f value, const cc_u16f cycles, const void *user_data)
{
if (io_port->write_callback == NULL)
return;
io_port->cached_write = value & io_port->mask; /* TODO: Is this really how the real thing does this? */
io_port->write_callback((void*)user_data, io_port->cached_write, cycles);
}