summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/machine/e05a03.c
blob: ba5725311b06d26405d95ac5bb0d43b2e1784c21 (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
/***************************************************************************

    E05A03 Gate Array (used in the Epson LX-800)

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

#include "emu.h"
#include "e05a03.h"


/***************************************************************************
    TYPE DEFINITIONS
***************************************************************************/

struct e05a03_state
{
	/* 24-bit shift register, port 0x00, 0x01 and 0x02 */
	UINT32 shift;

	/* port 0x03 */
	int busy_leading;
	int busy_software;
	int nlqlp;
	int cndlp;

#if 0
	int pe;
	int pelp;
#endif

	/* port 0x04 and 0x05 (9-bit) */
	UINT16 printhead;

	/* port 0x06 (4-bit) */
	UINT8 pf_motor;

	/* port 0x07 (4-bit) */
	UINT8 cr_motor;

	/* callbacks */
	devcb_resolved_write_line out_nlq_lp_func; /* pin 2, nlq lamp output */
	devcb_resolved_write_line out_pe_lp_func;  /* pin 3, paper empty lamp output */
	devcb_resolved_write_line out_reso_func;   /* pin 25, reset output */
	devcb_resolved_write_line out_pe_func;     /* pin 35, centronics pe output */
	devcb_resolved_read8 in_data_func;         /* pin 47-54, centronics data input */
};


/*****************************************************************************
    INLINE FUNCTIONS
*****************************************************************************/

INLINE e05a03_state *get_safe_token(device_t *device)
{
	assert(device != NULL);
	assert(device->type() == E05A03);

	return (e05a03_state *)downcast<e05a03_device *>(device)->token();
}


/*****************************************************************************
    DEVICE INTERFACE
*****************************************************************************/

static DEVICE_START( e05a03 )
{
	e05a03_state *e05a03 = get_safe_token(device);
	const e05a03_interface *intf = (const e05a03_interface *)device->static_config();

	/* validate some basic stuff */
	assert(device->static_config() != NULL);

	/* resolve callbacks */
	e05a03->out_nlq_lp_func.resolve(intf->out_nlq_lp_func, *device);
	e05a03->out_pe_lp_func.resolve(intf->out_pe_lp_func, *device);
	e05a03->out_reso_func.resolve(intf->out_reso_func, *device);
	e05a03->out_pe_func.resolve(intf->out_pe_func, *device);
	e05a03->in_data_func.resolve(intf->in_data_func, *device);

	/* register for state saving */
	device->save_item(NAME(e05a03->shift));
	device->save_item(NAME(e05a03->busy_leading));
	device->save_item(NAME(e05a03->busy_software));
	device->save_item(NAME(e05a03->nlqlp));
	device->save_item(NAME(e05a03->cndlp));
#if 0
	device->save_item(NAME(e05a03->pe));
	device->save_item(NAME(e05a03->pelp));
#endif
	device->save_item(NAME(e05a03->printhead));
	device->save_item(NAME(e05a03->pf_motor));
	device->save_item(NAME(e05a03->cr_motor));
}

static DEVICE_RESET( e05a03 )
{
	e05a03_state *e05a03 = get_safe_token(device);

	e05a03->printhead = 0x00;
	e05a03->pf_motor = 0x00;
	e05a03->cr_motor = 0x0f;

	e05a03->out_pe_func(0);
	e05a03->out_pe_lp_func(1);

	e05a03->busy_software = 1;
	e05a03->nlqlp = 1;
	e05a03->cndlp = 1;
}

/***************************************************************************
    IMPLEMENTATION
***************************************************************************/

WRITE8_DEVICE_HANDLER( e05a03_w )
{
	e05a03_state *e05a03 = get_safe_token(device);

	logerror("%s: e05a03_w(%02x): %02x\n", space.machine().describe_context(), offset, data);

	switch (offset)
	{
	/* shift register */
	case 0x00: e05a03->shift = (e05a03->shift & 0x00ffff) | (data << 16); break;
	case 0x01: e05a03->shift = (e05a03->shift & 0xff00ff) | (data << 8); break;
	case 0x02: e05a03->shift = (e05a03->shift & 0xffff00) | (data << 0); break;

	case 0x03:
		e05a03->busy_leading = BIT(data, 7);
		e05a03->busy_software = BIT(data, 6);
		e05a03->nlqlp = BIT(data, 4);
		e05a03->cndlp = BIT(data, 3);

		e05a03->out_pe_func(BIT(data, 2));
		e05a03->out_pe_lp_func(!BIT(data, 2));

#if 0
		e05a03->pe = BIT(data, 2);
		e05a03->pelp = !BIT(data, 2);
#endif

		break;

	/* printhead */
	case 0x04: e05a03->printhead = (e05a03->printhead & 0x100) | !data; break;
	case 0x05: e05a03->printhead = (e05a03->printhead & 0x0ff) | (!(BIT(data, 7) << 8)); break;

	/* paper feed and carriage motor phase data*/
	case 0x06: e05a03->pf_motor = (data & 0xf0) >> 4; break;
	case 0x07: e05a03->cr_motor = (data & 0x0f) >> 0; break;
	}
}

READ8_DEVICE_HANDLER( e05a03_r )
{
	e05a03_state *e05a03 = get_safe_token(device);
	UINT8 result = 0;

	logerror("%s: e05a03_r(%02x)\n", space.machine().describe_context(), offset);

	switch (offset)
	{
	case 0x00:
		break;

	case 0x01:
		break;

	case 0x02:
		result = e05a03->in_data_func(0);
		break;

	case 0x03:
		result |= BIT(e05a03->shift, 23) << 7;
		e05a03->shift <<= 1;
		break;
	}

	return result;
}

/* home position signal */
WRITE_LINE_DEVICE_HANDLER( e05a03_home_w )
{
}

/* printhead solenoids trigger */
WRITE_LINE_DEVICE_HANDLER( e05a03_fire_w )
{
}

WRITE_LINE_DEVICE_HANDLER( e05a03_strobe_w )
{
}

READ_LINE_DEVICE_HANDLER( e05a03_busy_r )
{
	return 1;
}

WRITE_LINE_DEVICE_HANDLER( e05a03_resi_w )
{
	e05a03_state *e05a03 = get_safe_token(device);

	if (!state)
	{
		DEVICE_RESET_CALL( e05a03 );
		e05a03->out_reso_func(1);
	}
}

WRITE_LINE_DEVICE_HANDLER( e05a03_init_w )
{
	e05a03_resi_w(device, state);
}

const device_type E05A03 = &device_creator<e05a03_device>;

e05a03_device::e05a03_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
	: device_t(mconfig, E05A03, "E05A03", tag, owner, clock)
{
	m_token = global_alloc_clear(e05a03_state);
}

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

void e05a03_device::device_config_complete()
{
}

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

void e05a03_device::device_start()
{
	DEVICE_START_NAME( e05a03 )(this);
}

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

void e05a03_device::device_reset()
{
	DEVICE_RESET_NAME( e05a03 )(this);
}