summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/psion_asic5.cpp
blob: 9e002b6f4af2b406c389a33aa4168c94d1235f2e (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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/******************************************************************************

    Psion ASIC5

    ASIC5 is a general purpose I/O chip with a built-in UART that can be set to
    run in a number of different modes thereby simplifying the task of peripheral
    design. For example, it is possible to set up ASIC5 to run as a Centronics
    parallel port interface, an 8-bit parallel I/O port, a serial bar code
    controller or a serial RS232 converter.

    TODO:
    - implement peripheral mode

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

#include "emu.h"
#include "psion_asic5.h"

#define VERBOSE 0
//#define LOG_OUTPUT_FUNC osd_printf_info
#include "logmacro.h"


DEFINE_DEVICE_TYPE(PSION_ASIC5_PACK,       psion_asic5_pack_device,       "psion_asic5_pack",       "Psion ASIC5 (Pack mode)")
DEFINE_DEVICE_TYPE(PSION_ASIC5_PERIPHERAL, psion_asic5_peripheral_device, "psion_asic5_peripheral", "Psion ASIC5 (Peripheral mode)")


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

psion_asic5_device::psion_asic5_device(const machine_config &mconfig, device_type type, const char* tag, device_t* owner, uint32_t clock)
	: device_t(mconfig, type, tag, owner, clock)
	, m_in_a_handler(*this)
	, m_in_b_handler(*this)
	, m_out_a_handler(*this)
	, m_out_b_handler(*this)
	, m_out_c_handler(*this)
	, m_out_d_handler(*this)
{
}

psion_asic5_pack_device::psion_asic5_pack_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: psion_asic5_device(mconfig, PSION_ASIC5_PACK, tag, owner, clock)
{
}

psion_asic5_peripheral_device::psion_asic5_peripheral_device(const machine_config &mconfig, const char * tag, device_t *owner, uint32_t clock)
	: psion_asic5_device(mconfig, PSION_ASIC5_PERIPHERAL, tag, owner, clock)
	, m_serial(*this, "serial")
	//, m_irq4_callback(*this)
	//, m_txd1_callback(*this)
	//, m_dtr1_callback(*this)
	//, m_rts1_callback(*this)
{
}


void psion_asic5_peripheral_device::device_add_mconfig(machine_config &config)
{
	NS16550(config, m_serial, clock() / 13);
	//m_serial->out_int_callback().set([this](int state) { m_irq4_callback(state); });
	//m_serial->out_tx_callback().set([this](int state) { m_txd1_callback(state); });
	//m_serial->out_dtr_callback().set([this](int state) { m_dtr1_callback(state); });
	//m_serial->out_rts_callback().set([this](int state) { m_rts1_callback(state); });
}


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

void psion_asic5_device::device_start()
{
	m_in_a_handler.resolve();
	m_in_b_handler.resolve();
	m_out_a_handler.resolve_safe();
	m_out_b_handler.resolve_safe();
	m_out_c_handler.resolve_safe();
	m_out_d_handler.resolve_safe();
}

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

void psion_asic5_device::device_reset()
{
	m_portb_ctrl = 0x00;
	m_portb_counter = 0x00;
}


//**************************************************************************
//  READ/WRITE HANDLERS
//**************************************************************************

void psion_asic5_device::data_w(uint16_t data)
{
	switch (data & 0x300)
	{
	case NULL_FRAME:
		break;

	case CONTROL_FRAME:
		m_sibo_control = data & 0xff;

		switch (m_sibo_control & 0xc0)
		{
		case 0x80: // SerialWrite
			//if (m_sibo_control == 0x82) // write A3Setup
			if (m_sibo_control == 0x93) // Multi Port D and C writes
				m_port_dc_writes = 0;
			break;
		}
		break;

	case DATA_FRAME:
		data &= 0xff;
		switch (m_sibo_control & 0x0f)
		{
		case 0x00: // Port A write data
			LOG("%s data_w: Port A write data %02x\n", machine().describe_context(), data);
			m_out_a_handler(data);
			break;

		case 0x01: // Port B write data
			LOG("%s data_w: Port B write data %02x\n", machine().describe_context(), data);
			m_out_b_handler(data);
			break;

		case 0x02: // Port B control
			LOG("%s data_w: Port B control %02x\n", machine().describe_context(), data);
			m_portb_ctrl = data;
			break;

		case 0x03: // Port D and C write data
			if (m_port_dc_writes)
			{
				LOG("%s data_w: Port C write data %02x\n", machine().describe_context(), data);
				m_out_c_handler(data);
			}
			else
			{
				LOG("%s data_w: Port D write data %02x\n", machine().describe_context(), data);
				m_out_d_handler(data);
				m_portb_counter = 0x00;
				m_out_b_handler(m_portb_counter);
			}
			m_port_dc_writes++;
			break;

		case 0x06: // Interrupt mask write
			LOG("%s data_w: out int mask %02x\n", machine().describe_context(), data);
			m_interrupt_mask = data;
			break;

		//case 0x07: // Control register
		//  m = data;
		//  break;

		default:
			LOG("%s data_w: unknown control %02x data %02x\n", machine().describe_context(), m_sibo_control, data);
			break;
		}
		break;
	}
}


uint8_t psion_asic5_device::data_r()
{
	uint8_t data = 0x00;

	switch (m_sibo_control & 0xc0)
	{
	case 0x40: // SerialSelect
		if (m_sibo_control == 0x42) // Asic5PackId
			data = m_info_byte; // A3InfoByte
		break;

	case 0xc0: // SerialRead
		switch (m_sibo_control & 0x0f)
		{
		case 0x00: // Port A read data
			data = m_in_a_handler();
			LOG("%s data_r: Port A read data %02x\n", machine().describe_context(), data);
			if (m_sibo_control & 0x90) // Multi, increment Port B
			{
				m_portb_counter++;
				m_out_b_handler(m_portb_counter);
			}
			break;

		case 0x01: // Port B read data
			data = m_in_b_handler();
			LOG("%s data_r: Port B read data %02x\n", machine().describe_context(), data);
			break;

		case 0x02: // Port B counter
			m_portb_counter++;
			m_out_b_handler(m_portb_counter);
			LOG("%s data_r: Port B counter %02x\n", machine().describe_context(), m_portb_counter);
			break;

		case 0x06: // Interrupt mask write
			data = m_interrupt_mask;
			LOG("%s data_r: in int mask %02x\n", machine().describe_context(), data);
			break;

			//case 0x07: // Control register
			//  m = data;
			//  break;

		default:
			LOG("%s data_r: unknown control %02x data %02x\n", machine().describe_context(), m_sibo_control, data);
			break;
		}
		break;
	}

	return data;
}