summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/xavix2002_io.cpp
blob: c193aabb02c2faef76dd0ee49cd2576cea2edc8c (plain) (blame)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// license:BSD-3-Clause
// copyright-holders:David Haywood

// has separate input / output addresses but still uses direction registers, or I've misunderstood this entirely.

#include "emu.h"
#include "xavix2002_io.h"

#define VERBOSE 0
#include "logmacro.h"

DEFINE_DEVICE_TYPE(XAVIX2002IO, xavix2002_io_device, "xavix2002io", "XaviX 2002 IO")

xavix2002_io_device::xavix2002_io_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, XAVIX2002IO, tag, owner, clock)
	, m_in0_cb(*this)
	, m_in1_cb(*this)
	, m_in2_cb(*this)
	, m_out0_cb(*this)
	, m_out1_cb(*this)
	, m_out2_cb(*this)
{
}

void xavix2002_io_device::device_start()
{
	m_in0_cb.resolve_safe(0xff);
	m_in1_cb.resolve_safe(0xff);
	m_in2_cb.resolve_safe(0xff);

	m_out0_cb.resolve_safe();
	m_out1_cb.resolve_safe();
	m_out2_cb.resolve_safe();

	save_item(NAME(m_sx_pio_dir));
	save_item(NAME(m_sx_pio_out));
}

void xavix2002_io_device::device_reset()
{
	for (int i = 0; i < 3; i++)
	{
		m_sx_pio_dir[i] = 0;
		m_sx_pio_out[i] = 0;
	}
}

void xavix2002_io_device::pio_dir_w(offs_t offset, uint8_t data)
{
	LOG("%s: superxavix pio_dir_w (port %d) %02x\n", machine().describe_context(), offset, data);

	if (offset < 3)
	{
		m_sx_pio_dir[offset] = data;
		pio_out_w(offset, m_sx_pio_out[offset]);
		// update port?
	}
}

uint8_t xavix2002_io_device::pio_dir_r(offs_t offset)
{
	LOG("%s: superxavix pio_dir_r (port %d)\n", machine().describe_context(), offset);
	uint8_t ret = 0x00;

	if (offset < 3)
	{
		ret = m_sx_pio_dir[offset];
	}

	return ret;
}

void xavix2002_io_device::pio_out_w(offs_t offset, uint8_t data)
{
	LOG("%s: superxavix pio_out_w (port %d) %02x\n", machine().describe_context(), offset, data);

	if (offset < 3)
	{
		m_sx_pio_out[offset] = data;

		// TODO: look at direction register

		uint8_t outdata = m_sx_pio_out[offset] & m_sx_pio_dir[offset];

		switch (offset)
		{
			case 0: m_out0_cb(outdata); break;
			case 1: m_out1_cb(outdata); break;
			case 2: m_out2_cb(outdata); break;
			default: break;
		}
	}
}

uint8_t xavix2002_io_device::pio_out_r(offs_t offset)
{
	// what does this actually read?

	LOG("%s: superxavix pio_out_r (port %d)\n", machine().describe_context(), offset);

	uint8_t ret = 0x00;

	if (offset<3)
		ret = m_sx_pio_out[offset];

	return ret;
}


uint8_t xavix2002_io_device::pio_in_r(offs_t offset)
{
	LOG("%s: superxavix pio_in_r (port %d)\n", machine().describe_context(), offset);

	uint8_t ret = 0x00;

	switch (offset)
	{
		case 0: ret = m_in0_cb(); break;
		case 1: ret = m_in1_cb(); break;
		case 2: ret = m_in2_cb(); break;
		default: ret = 0x00; break;
	}

	// mask with direction register before returning

	return ret;
}