summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/machine/aakart.c
blob: bf35b0e7dbfe1fdf7d40b1e9823012cebc968743 (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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/***************************************************************************

Acorn Archimedes KART interface

TODO:
- FIFO

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

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



//**************************************************************************
//  GLOBAL VARIABLES
//**************************************************************************

// device type definition
const device_type AAKART = &device_creator<aakart_device>;

#define HRST 0xff
#define RAK1 0xfe
#define RAK2 0xfd
#define BACK 0x3f
#define SMAK 0x33   /* keyboard + mouse ack */
#define MACK 0x32   /* mouse ack */
#define SACK 0x31   /* keyboard ack */
#define NACK 0x30   /* no data ack */
#define RQID 0x20

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

//-------------------------------------------------
//  aakart_device - constructor
//-------------------------------------------------

aakart_device::aakart_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
	: device_t(mconfig, AAKART, "aakart", tag, owner, clock)
{

}


//-------------------------------------------------
//  device_validity_check - perform validity checks
//  on this device
//-------------------------------------------------

void aakart_device::device_validity_check(validity_checker &valid) const
{
}


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

void aakart_device::device_start()
{
	m_out_tx_func.resolve(m_out_tx_cb, *this);
	m_out_rx_func.resolve(m_out_rx_cb, *this);
	m_rxtimer = timer_alloc(RX_TIMER);
	m_rxtimer->adjust(attotime::from_hz(clock()), 0, attotime::from_hz(clock()));
	m_txtimer = timer_alloc(TX_TIMER);
	m_txtimer->adjust(attotime::from_hz(clock()), 0, attotime::from_hz(clock()));
	m_mousetimer = timer_alloc(MOUSE_TIMER);
	m_mousetimer->adjust(attotime::from_hz(clock()), 0, attotime::from_hz(clock()));
	m_keybtimer = timer_alloc(KEYB_TIMER);
	m_keybtimer->adjust(attotime::from_hz(clock()), 0, attotime::from_hz(clock()));
}

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

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

	// or initialize to defaults if none provided
	else
	{
		memset(&m_out_tx_cb, 0, sizeof(m_out_tx_cb));
		memset(&m_out_rx_cb, 0, sizeof(m_out_rx_cb));
	}
}

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

void aakart_device::device_reset()
{
	m_status = STATUS_NORMAL;
	m_new_command = 0;
	m_rx = -1;
}

//-------------------------------------------------
//  device_timer - handler timer events
//-------------------------------------------------

void aakart_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
	#if 0
	if(id == KEYB_TIMER && m_keyb_enable && m_status == STATUS_NORMAL)
	{
		m_new_command |= 2;
		m_rx_latch = 0xd0 | 0; // keyb scancode (0xd0=up 0xc0=down, bits 3-0 row)
		m_status = STATUS_KEYUP;
		//m_ff ^= 1;
		return;
	}
	#endif

	if(id == MOUSE_TIMER && m_mouse_enable && m_status == STATUS_NORMAL)
	{
		m_new_command |= 2;
		m_rx_latch = 0; // mouse X position
		m_status = STATUS_MOUSE;
		//m_ff ^= 1;
		return;
	}

	if(m_new_command == 0)
		return;

	if(id == RX_TIMER && m_new_command & 2)
	{
		m_out_rx_func(ASSERT_LINE);
		m_new_command &= ~2;
		m_rx = m_rx_latch;
		return;
	}

	if(id == TX_TIMER && m_new_command & 1)
	{
		switch(m_status)
		{
			case STATUS_NORMAL:
			{
				switch(m_tx_latch)
				{
					case 0x00: // set leds
						break;
					case RQID:
						m_rx_latch = 0x81; //keyboard ID
						break;
					case SMAK:
					case MACK:
					case SACK:
					case NACK:
						if(m_tx_latch & 2) { m_mouse_enable = 1; }
						if(m_tx_latch & 1) { m_keyb_enable = 1; }
						break;
					case HRST:
						m_rx_latch = HRST;
						m_status = STATUS_HRST;
						break;
					default:
						//printf("%02x\n",m_tx_latch);
						break;
				}
				break;
			}
			case STATUS_KEYDOWN:
			{
				switch(m_tx_latch)
				{
					case BACK:
						m_rx_latch = 0xc0 | 0; // keyb scancode (0xd0=up 0xc0=down, bits 3-0 col)
						m_status = STATUS_NORMAL;
						break;
					case HRST:
						m_rx_latch = HRST;
						m_status = STATUS_HRST;
						break;
				}
				break;
			}
			case STATUS_KEYUP:
			{
				switch(m_tx_latch)
				{
					case BACK:
						m_rx_latch = 0xd0 | 0; // keyb scancode (0xd0=up 0xc0=down, bits 3-0 col)
						m_status = STATUS_NORMAL;
						break;
					case HRST:
						m_rx_latch = HRST;
						m_status = STATUS_HRST;
						break;
				}
				break;
			}
			case STATUS_MOUSE:
			{
				switch(m_tx_latch)
				{
					case BACK:
						m_rx_latch = 0; // mouse Y
						m_status = STATUS_NORMAL;
						break;
					case HRST:
						m_rx_latch = HRST;
						m_status = STATUS_HRST;
						break;
				}
				break;
			}
			case STATUS_HRST:
			{
				switch(m_tx_latch)
				{
					case HRST:  { m_rx_latch = HRST; m_keyb_enable = m_mouse_enable = 0; break; }
					case RAK1:  { m_rx_latch = RAK1; m_keyb_enable = m_mouse_enable = 0; break; }
					case RAK2:  { m_rx_latch = RAK2; m_status = STATUS_NORMAL; break; }
				}
				break;
			}
		}
		m_out_tx_func(ASSERT_LINE);
		m_new_command &= ~1;
		m_new_command |= 2;
	}
}

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

READ8_MEMBER( aakart_device::read )
{
	m_out_tx_func(CLEAR_LINE);
	return m_rx;
}

WRITE8_MEMBER( aakart_device::write )
{
	if(m_new_command)
		printf("skip cmd %02x\n",data);

	m_tx_latch = data;
	m_new_command |= 1;
	m_out_rx_func(CLEAR_LINE);
}