summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/a2bus/a2parprn.cpp
blob: c79f04f6da882967928c31a247e532c6bf7418c1 (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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
// license:BSD-3-Clause
// copyright-holders:Vas Crabb
#include "emu.h"
#include "a2parprn.h"

#include "bus/centronics/ctronics.h"

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

namespace {

class a2bus_parprn_device : public device_t, public device_a2bus_card_interface
{
public:
	a2bus_parprn_device(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock);

	// device_a2bus_card_interface implementation
	virtual u8 read_c0nx(u8 offset) override;
	virtual void write_c0nx(u8 offset, u8 data) override;
	virtual u8 read_cnxx(u8 offset) override;

protected:
	// device_t implementation
	virtual tiny_rom_entry const *device_rom_region() const override;
	virtual void device_add_mconfig(machine_config &config) override;
	virtual ioport_constructor device_input_ports() const override;
	virtual void device_start() override;
	virtual void device_reset() override;

private:
	// printer status inputs
	DECLARE_WRITE_LINE_MEMBER(ack_w);

	// timer handlers
	TIMER_CALLBACK_MEMBER(update_strobe);

	required_device<centronics_device>      m_printer_conn;
	required_device<output_latch_device>    m_printer_out;
	required_ioport                         m_input_config;
	required_region_ptr<u8>                 m_prom;
	emu_timer *                             m_strobe_timer;

	u8  m_next_strobe;  // B3 pin 13
	u8  m_ack_latch;    // B2 pin 6
	u8  m_ack_in;       // pin 2
};



// FIXME: get proper PROM dumps.
/*
    There are most likely multiple revisions.
    6309 and 74471 PROMs were used.

    Example silkscreen:

    SINGAPORE
    341-0005-00
    cAPPLE 78-02
    SN74S471N

    Example label:

    APPLE
    ©1978

    PROM image here is from entering a listing and zero-filling unused areas.

    ********************************
    *                              *
    *   PRINTER CARD I FIRMWARE    *
    *                              *
    *        WOZ   11/1/77         *
    *     APPLE COMPUTER INC.      *
    *     ALL RIGHTS RESERVED      *
    *                              *
    ********************************
*/
ROM_START(parprn)
	ROM_REGION(0x100, "prom", 0)
	ROM_LOAD( "prom.b4", 0x0000, 0x0100, BAD_DUMP CRC(00b742ca) SHA1(c67888354aa013f9cb882eeeed924e292734e717) )
ROM_END


INPUT_PORTS_START(parprn)
	PORT_START("CFG")
	PORT_CONFNAME(0x01, 0x00, "Acknowledge latching edge")
	PORT_CONFSETTING(   0x00, "Falling (/Y-B)")
	PORT_CONFSETTING(   0x01, "Rising (Y-B)")
	PORT_CONFNAME(0x06, 0x02, "Printer ready")
	PORT_CONFSETTING(   0x00, "Always (S5-C-D)")
	PORT_CONFSETTING(   0x02, "Acknowledge latch (Z-C-D)")
	PORT_CONFSETTING(   0x04, "ACK (Y-C-D)")
	PORT_CONFSETTING(   0x06, "/ACK (/Y-C-D)")
	PORT_CONFNAME(0x08, 0x00, "Strobe polarity")
	PORT_CONFSETTING(   0x00, "Negative (S5-A-/X, GND-X)")
	PORT_CONFSETTING(   0x08, "Positive (S5-X, GND-A-/X)")
	PORT_CONFNAME(0x10, 0x10, "Character width")
	PORT_CONFSETTING(   0x00, "7-bit")
	PORT_CONFSETTING(   0x10, "8-bit")
INPUT_PORTS_END



a2bus_parprn_device::a2bus_parprn_device(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock) :
	device_t(mconfig, A2BUS_PARPRN, tag, owner, clock),
	device_a2bus_card_interface(mconfig, *this),
	m_printer_conn(*this, "prn"),
	m_printer_out(*this, "prn_out"),
	m_input_config(*this, "CFG"),
	m_prom(*this, "prom"),
	m_strobe_timer(nullptr),
	m_next_strobe(0U),
	m_ack_latch(0U),
	m_ack_in(1U)
{
}



//----------------------------------------------
//  device_a2bus_card_interface implementation
//----------------------------------------------

u8 a2bus_parprn_device::read_c0nx(u8 offset)
{
	if (!machine().side_effects_disabled())
	{
		LOG("Read C0n%01X (effective open-bus write)\n", offset);

		// R/W is ignored, so it has the same effect as a write
		// the bus is open, but 74LS logic has low-impedance inputs so it's likely to latch 0xff
		write_c0nx(offset, 0xffU);
	}

	return 0x00U;
}


void a2bus_parprn_device::write_c0nx(u8 offset, u8 data)
{
	LOG("Write C0n%01X=%02X\n", offset, data);
	if (m_ack_latch)
		LOG("Clearing acknowledge latch\n");
	else
		LOG("Previous data not acknowledged\n");

	ioport_value const cfg(m_input_config->read());

	m_printer_out->write(data & (BIT(cfg, 8) ? 0xffU : 0x7fU));
	m_printer_conn->write_strobe(BIT(~cfg, 3));
	m_next_strobe = BIT(cfg, 3);
	m_ack_latch = 0U;
	m_strobe_timer->adjust(attotime::from_ticks(1, clock()));
}


u8 a2bus_parprn_device::read_cnxx(u8 offset)
{
	ioport_value const cfg(m_input_config->read());

	if (BIT(cfg, 2))
	{
		if (!BIT(offset, 6) || (BIT(offset, 7) && (BIT(cfg, 1) != m_ack_in)))
			offset |= 0x40U;
		else
			offset &= 0xbfU;
	}
	else if (BIT(cfg, 1))
	{
		if (!BIT(offset, 6) || (BIT(offset, 7) && !m_ack_latch))
			offset |= 0x40U;
		else
			offset &= 0xbfU;
	}
	else
	{
		offset ^= 0x40U;
	}

	return m_prom[offset];
}



//----------------------------------------------
//  device_t implementation
//----------------------------------------------

tiny_rom_entry const *a2bus_parprn_device::device_rom_region() const
{
	return ROM_NAME(parprn);
}


void a2bus_parprn_device::device_add_mconfig(machine_config &config)
{
	CENTRONICS(config, m_printer_conn, centronics_devices, "printer");
	m_printer_conn->ack_handler().set(FUNC(a2bus_parprn_device::ack_w));

	OUTPUT_LATCH(config, m_printer_out);
	m_printer_conn->set_output_latch(*m_printer_out);
}


ioport_constructor a2bus_parprn_device::device_input_ports() const
{
	return INPUT_PORTS_NAME(parprn);
}


void a2bus_parprn_device::device_start()
{
	m_strobe_timer = timer_alloc(FUNC(a2bus_parprn_device::update_strobe), this);

	save_item(NAME(m_next_strobe));
	save_item(NAME(m_ack_latch));
	save_item(NAME(m_ack_in));
}


void a2bus_parprn_device::device_reset()
{
	m_ack_latch = 1U;
}



//----------------------------------------------
//  printer status inputs
//----------------------------------------------

WRITE_LINE_MEMBER(a2bus_parprn_device::ack_w)
{
	if (bool(state) != bool(m_ack_in))
	{
		m_ack_in = state ? 1U : 0U;
		LOG("ACK=%u\n", m_ack_in);
		if (started() && (m_ack_in == BIT(m_input_config->read(), 0)))
		{
			LOG("Active ACK edge\n");
			m_ack_latch = 1U;
		}
	}
}



//----------------------------------------------
//  timer handlers
//----------------------------------------------

TIMER_CALLBACK_MEMBER(a2bus_parprn_device::update_strobe)
{
	ioport_value const cfg(m_input_config->read());

	LOG("Output /STROBE=%u\n", m_next_strobe);
	m_printer_conn->write_strobe(m_next_strobe);
	if (m_next_strobe == BIT(cfg, 3))
	{
		LOG("Start strobe timer\n");
		m_next_strobe = BIT(~cfg, 3);
		m_strobe_timer->adjust(attotime::from_ticks(1, clock()));
	}
}

} // anonymous namespace



DEFINE_DEVICE_TYPE_PRIVATE(A2BUS_PARPRN, device_a2bus_card_interface, a2bus_parprn_device, "a2parprn", "Apple II Parallel Printer Interface Card")