summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/hp_hil/hlebase.cpp
blob: b43271f705a4eddc70ab21c9027fad3274619032 (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
// license:BSD-3-Cl ause
// copyright-holders:Sergey Svishchev
#include "emu.h"
#include "hlebase.h"

//#define VERBOSE 1
#include "logmacro.h"

namespace bus::hp_hil {

/***************************************************************************
    BASE HLE KEYBOARD DEVICE
***************************************************************************/

/*--------------------------------------------------
    hle_device_base::hle_device_base
    designated device constructor
--------------------------------------------------*/

hle_device_base::hle_device_base(machine_config const &mconfig, device_type type, char const *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, type, tag, owner, clock)
	, device_hp_hil_interface(mconfig, *this)
	, m_powerup(true)
	, m_passthru(false)
{ }


/*--------------------------------------------------
    hle_device_base::~hle_device_base
    destructor
--------------------------------------------------*/

hle_device_base::~hle_device_base()
{ }


/*--------------------------------------------------
    hle_device_base::device_start
    perform expensive initialisations, allocate
    resources, register for save state
--------------------------------------------------*/

void hle_device_base::device_start()
{

	save_item(NAME(m_powerup));
	save_item(NAME(m_passthru));

	set_hp_hil_mlc_device();

	m_powerup = true;
	m_passthru = false;
}


/*--------------------------------------------------
    hle_device_base::device_reset
    perform startup tasks, also used for host
    requested reset
--------------------------------------------------*/

void hle_device_base::device_reset()
{
}

bool hle_device_base::hil_write(uint16_t *pdata)
{
	int frames = 0;
	uint8_t addr = (*pdata >> 8) & 7;
	uint8_t data = *pdata & 0xff;
	bool command = BIT(*pdata, 11);

	LOG("%d: rx from mlc %04X (%s addr %d, data %02X)\n", m_device_id, *pdata,
		command ? "command" : "data", addr, data);

	if (!command)
		goto out;

	if (addr != 0 && addr != m_device_id)
		goto out;

	switch (data)
	{
	case HPHIL_IFC:
		m_powerup = false;
		break;

	case HPHIL_EPT:
		m_passthru = true;
		break;

	case HPHIL_ELB:
		m_passthru = false;
		break;

	case 0x09:
	case 0x0a:
	case 0x0b:
	case 0x0c:
	case 0x0d:
	case 0x0e:
	case 0x0f:
		m_device_id = data - 8;
		m_device_id16 = (data - 8) << 8;
		*pdata &= ~7;
		*pdata += (data - 7);
		break;

	case HPHIL_POL:
	case HPHIL_POL+1:
	case HPHIL_POL+2:
	case HPHIL_POL+3:
	case HPHIL_POL+4:
	case HPHIL_POL+5:
	case HPHIL_POL+6:
	case HPHIL_POL+7:
	case HPHIL_POL+8:
	case HPHIL_POL+9:
	case HPHIL_POL+10:
	case HPHIL_POL+11:
	case HPHIL_POL+12:
	case HPHIL_POL+13:
	case HPHIL_POL+14:
	case HPHIL_POL+15:
		frames = hil_poll();
		*pdata += frames;
		break;

	case HPHIL_DSR:
		m_device_id = m_device_id16 = 0;
		m_powerup = true;
		break;

	case HPHIL_IDD:
		hil_idd();
		break;

	case HPHIL_DHR:
		m_powerup = true;
		m_passthru = false;
		device_reset();
		return true;
		break;

	case HPHIL_DKA:
	case HPHIL_EK1:
	case HPHIL_EK2:
		hil_typematic(data);
		break;

	default:
		LOG("command %02X unknown\n", data);
		break;
	}
out:
	if (!m_passthru)
		m_hp_hil_mlc->hil_write(*pdata);
	return m_passthru;
}

} // namespace bus::hp_hil