summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/vt1682_io.cpp
blob: 5a08ea3c920d64d32c687e5022964a3d2e2a4695 (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
128
129
130
131
132
133
134
135
136
137
// license:BSD-3-Clause
// copyright-holders:David Haywood

#include "emu.h"
#include "machine/vt1682_io.h"

#define LOG_IO     (1U << 1)

#define LOG_ALL           ( LOG_IO )

#define VERBOSE             (0)
#include "logmacro.h"


DEFINE_DEVICE_TYPE(VT_VT1682_IO, vrt_vt1682_io_device, "vt1682io", "VRT VT1682 I/O")

vrt_vt1682_io_device::vrt_vt1682_io_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, VT_VT1682_IO, tag, owner, clock),
	m_porta_out(*this),
	m_portb_out(*this),
	m_portc_out(*this),
	m_portd_out(*this),
	m_porta_in(*this),
	m_portb_in(*this),
	m_portc_in(*this),
	m_portd_in(*this)
{
}

void vrt_vt1682_io_device::device_start()
{
	m_porta_out.resolve_safe();
	m_portb_out.resolve_safe();
	m_portc_out.resolve_safe();
	m_portd_out.resolve_safe();
	m_porta_in.resolve_safe(0);
	m_portb_in.resolve_safe(0);
	m_portc_in.resolve_safe(0);
	m_portd_in.resolve_safe(0);

	save_item(NAME(m_210d_ioconfig));
}

void vrt_vt1682_io_device::device_reset()
{
	m_210d_ioconfig = 0;
}


/*
    Address 0x210d r/w (MAIN CPU)

    0x80 - IOD ENB
    0x40 - IOD OE
    0x20 - IOC ENB
    0x10 - IOC OE
    0x08 - IOB ENB
    0x04 - IOB OE
    0x02 - IOA ENB
    0x01 - IOA OE
*/

READ8_MEMBER(vrt_vt1682_io_device::vt1682_210d_ioconfig_r)
{
	uint8_t ret = m_210d_ioconfig;
	LOGMASKED(LOG_IO, "%s: vt1682_210d_ioconfig_r returning: %02x\n", machine().describe_context(), ret);
	return ret;
}

WRITE8_MEMBER(vrt_vt1682_io_device::vt1682_210d_ioconfig_w)
{
	LOGMASKED(LOG_IO, "%s: vt1682_210d_ioconfig_w writing: %02x ( IOD_ENB:%1x IOD_OE:%1x | IOC_ENB:%1x IOC_OE:%1x | IOB_ENB:%1x IOB_OE:%1x | IOA_ENB:%1x IOA_OE:%1x )\n", machine().describe_context(), data,
		(data & 0x80) ? 1 : 0,
		(data & 0x40) ? 1 : 0,
		(data & 0x20) ? 1 : 0,
		(data & 0x10) ? 1 : 0,
		(data & 0x08) ? 1 : 0,
		(data & 0x04) ? 1 : 0,
		(data & 0x02) ? 1 : 0,
		(data & 0x01) ? 1 : 0);

	m_210d_ioconfig = data;
}

/*
    Address 0x210e r/w (MAIN CPU)

    0x80 - IOB:3
    0x40 - IOB:2
    0x20 - IOB:1
    0x10 - IOB:0
    0x08 - IOA:3
    0x04 - IOA:2
    0x02 - IOA:1
    0x01 - IOA:0
*/

READ8_MEMBER(vrt_vt1682_io_device::vt1682_210e_io_ab_r)
{
	uint8_t ret = (m_porta_in(0, 0x0f) & 0x0f) | ((m_portb_in(0, 0x0f) & 0x0f)<<4);
	LOGMASKED(LOG_IO, "%s: vt1682_210e_io_ab_r returning: %02x\n", machine().describe_context(), ret);
	return ret;
}

WRITE8_MEMBER(vrt_vt1682_io_device::vt1682_210e_io_ab_w)
{
	LOGMASKED(LOG_IO, "%s: vt1682_210e_io_ab_w writing: %02x (portb: %1x porta: %1x)\n", machine().describe_context(), data, (data & 0xf0) >> 4, data & 0x0f);
	m_porta_out(0, (data & 0x0f), 0x0f);
	m_portb_out(0, ((data & 0xf0)>>4), 0x0f);
}

/*
    Address 0x210f r/w (MAIN CPU)

    0x80 - IOD:3
    0x40 - IOD:2
    0x20 - IOD:1
    0x10 - IOD:0
    0x08 - IOC:3
    0x04 - IOC:2
    0x02 - IOC:1
    0x01 - IOC:0
*/

READ8_MEMBER(vrt_vt1682_io_device::vt1682_210f_io_cd_r)
{
	uint8_t ret = (m_portc_in(0, 0x0f) & 0x0f) | ((m_portd_in(0, 0x0f) & 0x0f)<<4);
	LOGMASKED(LOG_IO, "%s: vt1682_210f_io_cd_r returning: %02x\n", machine().describe_context(), ret);
	return ret;
}

WRITE8_MEMBER(vrt_vt1682_io_device::vt1682_210f_io_cd_w)
{
	LOGMASKED(LOG_IO, "%s: vt1682_210f_io_cd_w writing: %02x (portd: %1x portc: %1x)\n", machine().describe_context(), data, (data & 0xf0) >> 4, data & 0x0f);
	m_portc_out(0, (data & 0x0f), 0x0f);
	m_portd_out(0, ((data & 0xf0)>>4), 0x0f);
}