summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/machine/i8212.c
blob: fe2f94ebc22406d8223434e11be38a6307cc080b (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**********************************************************************

    Intel 8212 8-Bit Input/Output Port emulation

    Copyright MESS Team.
    Visit http://mamedev.org for licensing and usage restrictions.

**********************************************************************/

#include "emu.h"
#include "i8212.h"



//**************************************************************************
//  MACROS / CONSTANTS
//**************************************************************************

#define LOG 0



//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

// device type definition
const device_type I8212 = &device_creator<i8212_device>;

//-------------------------------------------------
//  i8212_device - constructor
//-------------------------------------------------

i8212_device::i8212_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
	: device_t(mconfig, I8212, "Intel 8212", tag, owner, clock),
		m_md(I8212_MODE_INPUT),
		m_stb(0)
{

}


//-------------------------------------------------
//  device_config_complete - perform any
//  operations now that the configuration is
//  complete
//-------------------------------------------------

void i8212_device::device_config_complete()
{
	// inherit a copy of the static data
	const i8212_interface *intf = reinterpret_cast<const i8212_interface *>(static_config());
	if (intf != NULL)
		*static_cast<i8212_interface *>(this) = *intf;

	// or initialize to defaults if none provided
	else
	{
		memset(&m_out_int_cb, 0, sizeof(m_out_int_cb));
		memset(&m_in_di_cb, 0, sizeof(m_in_di_cb));
		memset(&m_out_do_cb, 0, sizeof(m_out_do_cb));
	}
}


//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void i8212_device::device_start()
{
	// resolve callbacks
	m_out_int_func.resolve(m_out_int_cb, *this);
	m_in_di_func.resolve(m_in_di_cb, *this);
	m_out_do_func.resolve(m_out_do_cb, *this);

	// register for state saving
	save_item(NAME(m_md));
	save_item(NAME(m_stb));
	save_item(NAME(m_data));
}


//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void i8212_device::device_reset()
{
	m_data = 0;

	if (m_md == I8212_MODE_OUTPUT)
	{
		// output data
		m_out_do_func(0, m_data);
	}
}


//-------------------------------------------------
//  data_r - data latch read
//-------------------------------------------------

READ8_MEMBER( i8212_device::data_r )
{
	// clear interrupt line
	m_out_int_func(CLEAR_LINE);

	if (LOG) logerror("I8212 '%s' INT: %u\n", tag(), CLEAR_LINE);

	return m_data;
}


//-------------------------------------------------
//  data_w - data latch write
//-------------------------------------------------

WRITE8_MEMBER( i8212_device::data_w )
{
	// latch data
	m_data = data;

	// output data
	m_out_do_func(0, m_data);
}


//-------------------------------------------------
//  md_w - mode write
//-------------------------------------------------

WRITE_LINE_MEMBER( i8212_device::md_w )
{
	if (LOG) logerror("I8212 '%s' Mode: %s\n", tag(), state ? "output" : "input");

	m_md = state;
}


//-------------------------------------------------
//  stb_w - data strobe write
//-------------------------------------------------

WRITE_LINE_MEMBER( i8212_device::stb_w )
{
	if (LOG) logerror("I8212 '%s' STB: %u\n", tag(), state);

	if (m_md == I8212_MODE_INPUT)
	{
		if (m_stb && !state)
		{
			// input data
			m_data = m_in_di_func(0);

			// assert interrupt line
			m_out_int_func(ASSERT_LINE);

			if (LOG) logerror("I8212 '%s' INT: %u\n", tag(), ASSERT_LINE);
		}
	}

	m_stb = state;
}