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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
|
// license:BSD-3-Clause
// copyright-holders:MetalliC
/*********************************************************************
Common printer interfaces
ZX Lprint
(c) 1983 Euroelectronics (UK)
ZX Lprint III
(c) 1984 Euroelectronics (UK)
Centronics and RS232 interface, most common printer interface for ZX-Spectrum.
Hilderbay Interface (c) 1983 Hilderbay Ltd (UK)
AKA
Kempston Centronics S Interface (c) 1983 Kempston Micro Electronics Ltd (UK)
ROM-less device, require printer driver to be loaded from tape.
Kempston Centronics E Interface
(c) 1984 Kempston Micro Electronics Ltd (UK)
Notes/TODOs:
- add information and docs
*********************************************************************/
#include "emu.h"
#include "lprint.h"
#include <algorithm>
/***************************************************************************
DEVICE DEFINITIONS
***************************************************************************/
DEFINE_DEVICE_TYPE(SPECTRUM_LPRINT, spectrum_lprint_device, "spectrum_lprint", "ZX Lprint")
DEFINE_DEVICE_TYPE(SPECTRUM_LPRINT3, spectrum_lprint3_device, "spectrum_lprint3", "ZX Lprint III")
DEFINE_DEVICE_TYPE(SPECTRUM_KEMPCENTRS, spectrum_kempcentrs_device, "spectrum_kempcentrs", "Hilderbay / Kempston Centronics S")
DEFINE_DEVICE_TYPE(SPECTRUM_KEMPCENTREF, spectrum_kempcentre_device, "spectrum_kempcentref", "Kempston Centronics E (flat)")
DEFINE_DEVICE_TYPE(SPECTRUM_KEMPCENTREU, spectrum_kempcentreu_device, "spectrum_kempcentreu", "Kempston Centronics E (upright)")
//-------------------------------------------------
// ROMs
//-------------------------------------------------
ROM_START(lprint)
ROM_REGION(0x800, "rom", 0)
ROM_LOAD("lprint.rom", 0x0000, 0x0800, CRC(3c3483e5) SHA1(3e4c7ecd8c3eb011cdf75eb23faf8d8ea8329757)) // permanently overlay 0x0800-0x0fff ROM area
ROM_END
ROM_START(lprint3)
ROM_REGION(0x800, "rom", 0)
ROM_DEFAULT_BIOS("v2")
// original
ROM_SYSTEM_BIOS(0, "v1", "v1.0")
ROMX_LOAD("v10.rom", 0x0000, 0x0800, CRC(a5014f40) SHA1(fe823a8b87a8bdacb14aac848bc7fe946f76faae), ROM_BIOS(0))
ROM_SYSTEM_BIOS(1, "v2", "v2.0")
ROMX_LOAD("v20.rom", 0x0000, 0x0800, CRC(b8f9a58d) SHA1(4966664badbed44ddb1c1a2ca01bdef60f0a30f8), ROM_BIOS(1))
// clones
ROM_SYSTEM_BIOS(2, "kp", "Sandy") // from Sandy Disco V3 (Kempston Disc clone) lower PCB, also have joystick port and passthru connector
ROMX_LOAD("sandy.rom", 0x0000, 0x0800, CRC(77e752f2) SHA1(11f44c5e743a413e8bc0d07c4249f36d2c0a172a), ROM_BIOS(2))
ROM_SYSTEM_BIOS(3, "rus", "Art East Computers (RU)") // added support for popular Soviet and Eastern Bloc made printers
ROMX_LOAD("himak.rom", 0x0000, 0x0800, CRC(b1f15976) SHA1(d9c0297c05e8092fb7e0198f4172d3d4e6ed252c), ROM_BIOS(3))
ROM_END
ROM_START(kempcentref)
ROM_REGION(0x800, "rom", 0)
ROM_LOAD("kemp-e.rom", 0x0000, 0x0800, CRC(a58b1e97) SHA1(b26e9f720a215019b8710a4a094d6fde6ecae5fd))
ROM_END
ROM_START(kempcentreu)
ROM_REGION(0x800, "rom", 0)
ROM_LOAD("7f.rom", 0x0000, 0x0800, CRC(b67a416d) SHA1(6d0772e81cfd9bc994b1c91d4e01b45e0fc0d3d3)) // scrambled
ROM_END
//-------------------------------------------------
// device_add_mconfig - add device configuration
//-------------------------------------------------
void spectrum_lprint_device::device_add_mconfig(machine_config &config)
{
CENTRONICS(config, m_centronics, centronics_devices, "printer");
m_centronics->busy_handler().set(FUNC(spectrum_lprint_device::busy_w));
}
void spectrum_lprint3_device::device_add_mconfig(machine_config &config)
{
CENTRONICS(config, m_centronics, centronics_devices, "printer");
m_centronics->busy_handler().set(FUNC(spectrum_lprint3_device::busy_w));
RS232_PORT(config, m_rs232, default_rs232_devices, nullptr);
// passthru
// this is not really accurate, original ZX-Lprint boards had no passthru connector, but only some of clones
// TODO: populate expansion port only for devices which really had it
SPECTRUM_EXPANSION_SLOT(config, m_exp, spectrum_expansion_devices, nullptr);
m_exp->irq_handler().set(DEVICE_SELF_OWNER, FUNC(spectrum_expansion_slot_device::irq_w));
m_exp->nmi_handler().set(DEVICE_SELF_OWNER, FUNC(spectrum_expansion_slot_device::nmi_w));
}
void spectrum_kempcentrs_device::device_add_mconfig(machine_config &config)
{
CENTRONICS(config, m_centronics, centronics_devices, "printer");
m_centronics->busy_handler().set(FUNC(spectrum_kempcentrs_device::busy_w));
}
void spectrum_kempcentre_device::device_add_mconfig(machine_config &config)
{
CENTRONICS(config, m_centronics, centronics_devices, "printer");
m_centronics->busy_handler().set(FUNC(spectrum_kempcentre_device::busy_w));
}
const tiny_rom_entry *spectrum_lprint_device::device_rom_region() const
{
return ROM_NAME(lprint);
}
const tiny_rom_entry *spectrum_lprint3_device::device_rom_region() const
{
return ROM_NAME(lprint3);
}
const tiny_rom_entry *spectrum_kempcentre_device::device_rom_region() const
{
return ROM_NAME(kempcentref);
}
const tiny_rom_entry *spectrum_kempcentreu_device::device_rom_region() const
{
return ROM_NAME(kempcentreu);
}
//**************************************************************************
// LIVE DEVICE
//**************************************************************************
//-------------------------------------------------
// spectrum_lprint_device - constructors
//-------------------------------------------------
spectrum_lprint_device::spectrum_lprint_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: device_t(mconfig, SPECTRUM_LPRINT, tag, owner, clock)
, device_spectrum_expansion_interface(mconfig, *this)
, m_rom(*this, "rom")
, m_centronics(*this, "centronics")
{
}
spectrum_lprint3_device::spectrum_lprint3_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: device_t(mconfig, SPECTRUM_LPRINT3, tag, owner, clock)
, device_spectrum_expansion_interface(mconfig, *this)
, m_rom(*this, "rom")
, m_centronics(*this, "centronics")
, m_rs232(*this, "rs232")
, m_exp(*this, "exp")
{
}
spectrum_kempcentrs_device::spectrum_kempcentrs_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: device_t(mconfig, SPECTRUM_KEMPCENTRS, tag, owner, clock)
, device_spectrum_expansion_interface(mconfig, *this)
, m_centronics(*this, "centronics")
{
}
spectrum_kempcentre_device::spectrum_kempcentre_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
: device_t(mconfig, type, tag, owner, clock)
, device_spectrum_expansion_interface(mconfig, *this)
, m_rom(*this, "rom")
, m_centronics(*this, "centronics")
{
}
spectrum_kempcentre_device::spectrum_kempcentre_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: spectrum_kempcentre_device(mconfig, SPECTRUM_KEMPCENTREF, tag, owner, clock)
{
}
spectrum_kempcentreu_device::spectrum_kempcentreu_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: spectrum_kempcentre_device(mconfig, SPECTRUM_KEMPCENTREU, tag, owner, clock)
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void spectrum_lprint_device::device_start()
{
m_busy = 0;
save_item(NAME(m_romcs));
save_item(NAME(m_busy));
}
void spectrum_lprint3_device::device_start()
{
m_busy = 0;
save_item(NAME(m_romcs));
save_item(NAME(m_busy));
}
void spectrum_kempcentrs_device::device_start()
{
m_busy = 0;
save_item(NAME(m_busy));
}
void spectrum_kempcentre_device::device_start()
{
m_busy = 0;
save_item(NAME(m_active));
save_item(NAME(m_romcs));
save_item(NAME(m_busy));
}
//-------------------------------------------------
// device_reset - device-specific reset
//-------------------------------------------------
void spectrum_lprint_device::device_reset()
{
m_romcs = 0;
m_centronics->write_strobe(1);
}
void spectrum_lprint3_device::device_reset()
{
m_romcs = 0;
m_centronics->write_strobe(1);
}
void spectrum_kempcentrs_device::device_reset()
{
m_centronics->write_strobe(1);
}
void spectrum_kempcentre_device::device_reset()
{
m_active = 0;
m_romcs = 0;
m_centronics->write_strobe(1);
}
//**************************************************************************
// IMPLEMENTATION (lprint)
//**************************************************************************
READ_LINE_MEMBER(spectrum_lprint_device::romcs)
{
return m_romcs;
}
void spectrum_lprint_device::pre_opcode_fetch(offs_t offset)
{
if (!machine().side_effects_disabled())
m_romcs = offset >= 0x0800 && offset < 0x1000;
}
void spectrum_lprint_device::pre_data_fetch(offs_t offset)
{
if (!machine().side_effects_disabled())
m_romcs = offset >= 0x0800 && offset < 0x1000;
}
uint8_t spectrum_lprint_device::mreq_r(offs_t offset)
{
uint8_t data = 0xff;
if (m_romcs)
data = m_rom->base()[offset & 0x7ff];
return data;
}
uint8_t spectrum_lprint_device::iorq_r(offs_t offset)
{
uint8_t data = 0xff;
if (!BIT(offset, 2))
{
// code check this like - if (value & 0xe0) == 0x40, bit 6 probably /BUSY
data &= ~0xe0;
data |= !m_busy << 6;
}
return data;
}
void spectrum_lprint_device::iorq_w(offs_t offset, uint8_t data)
{
if (!BIT(offset, 2))
{
m_centronics->write_data0(BIT(data, 0));
m_centronics->write_data1(BIT(data, 1));
m_centronics->write_data2(BIT(data, 2));
m_centronics->write_data3(BIT(data, 3));
m_centronics->write_data4(BIT(data, 4));
m_centronics->write_data5(BIT(data, 5));
m_centronics->write_data6(BIT(data, 6));
m_centronics->write_data7(BIT(data, 7));
m_centronics->write_strobe(1); // strobe probably fired automatically
m_centronics->write_strobe(0);
m_centronics->write_strobe(1);
}
}
//**************************************************************************
// IMPLEMENTATION (lprint3)
//**************************************************************************
READ_LINE_MEMBER(spectrum_lprint3_device::romcs)
{
return m_romcs | m_exp->romcs();
}
uint8_t spectrum_lprint3_device::iorq_r(offs_t offset)
{
uint8_t data = m_exp->iorq_r(offset);
if (!BIT(offset, 2))
{
if (!machine().side_effects_disabled())
m_romcs = BIT(offset, 7);
data &= ~0xc0;
data |= !m_rs232->dsr_r() << 6;
data |= m_busy << 7;
}
return data;
}
void spectrum_lprint3_device::iorq_w(offs_t offset, uint8_t data)
{
if (!BIT(offset, 2))
{
m_centronics->write_data0(BIT(data, 0));
m_centronics->write_data1(BIT(data, 1));
m_centronics->write_data2(BIT(data, 2));
m_centronics->write_data3(BIT(data, 3));
m_centronics->write_data4(BIT(data, 4));
m_centronics->write_data5(BIT(data, 5));
m_centronics->write_data6(BIT(data, 6));
m_centronics->write_data7(BIT(data, 7));
m_centronics->write_strobe(BIT(offset, 7));
m_rs232->write_txd(!BIT(data, 7));
}
m_exp->iorq_w(offset, data);
}
uint8_t spectrum_lprint3_device::mreq_r(offs_t offset)
{
uint8_t data = 0xff;
if (m_romcs)
data = m_rom->base()[offset & 0x7ff];
if (m_exp->romcs())
data &= m_exp->mreq_r(offset);
return data;
}
//**************************************************************************
// IMPLEMENTATION (kempcentrs)
//**************************************************************************
uint8_t spectrum_kempcentrs_device::iorq_r(offs_t offset)
{
uint8_t data = 0xff;
switch (offset)
{
case 0xe2bf:
data &= ~1;
data |= m_busy << 0;
break;
}
return data;
}
void spectrum_kempcentrs_device::iorq_w(offs_t offset, uint8_t data)
{
switch (offset)
{
case 0xe0bf:
m_centronics->write_data0(BIT(data, 0));
m_centronics->write_data1(BIT(data, 1));
m_centronics->write_data2(BIT(data, 2));
m_centronics->write_data3(BIT(data, 3));
m_centronics->write_data4(BIT(data, 4));
m_centronics->write_data5(BIT(data, 5));
m_centronics->write_data6(BIT(data, 6));
m_centronics->write_data7(BIT(data, 7));
break;
case 0xe3bf:
// bit 0 is /STROBE, other bits not known, upon init driver writes to this port 0x81 then 0x0f
m_centronics->write_strobe(BIT(data, 0));
break;
}
}
//**************************************************************************
// IMPLEMENTATION (kempcentre)
//**************************************************************************
READ_LINE_MEMBER(spectrum_kempcentre_device::romcs)
{
return m_romcs;
}
void spectrum_kempcentre_device::pre_opcode_fetch(offs_t offset)
{
if (!machine().side_effects_disabled())
m_romcs = m_active && offset >= 0x0800 && offset < 0x1000;
}
void spectrum_kempcentre_device::pre_data_fetch(offs_t offset)
{
if (!machine().side_effects_disabled())
m_romcs = m_active && offset >= 0x0800 && offset < 0x1000;
}
uint8_t spectrum_kempcentre_device::iorq_r(offs_t offset)
{
uint8_t data = 0xff;
if (!BIT(offset, 2)) // earlier version ? uses same paging as Lprint III
{
if (!machine().side_effects_disabled())
m_active = BIT(offset, 7);
}
if ((offset & 0xf0) == 0xb0) // BB or BF, actual address decode is not known
{
data &= ~0xc0;
data |= m_busy << 6;
}
return data;
}
void spectrum_kempcentre_device::iorq_w(offs_t offset, uint8_t data)
{
if ((offset & 0xf0) == 0xb0) // BB or BF, actual address decode is not known
{
m_centronics->write_data0(BIT(data, 0));
m_centronics->write_data1(BIT(data, 1));
m_centronics->write_data2(BIT(data, 2));
m_centronics->write_data3(BIT(data, 3));
m_centronics->write_data4(BIT(data, 4));
m_centronics->write_data5(BIT(data, 5));
m_centronics->write_data6(BIT(data, 6));
m_centronics->write_data7(BIT(data, 7));
m_centronics->write_strobe(BIT(offset, 2));
}
}
uint8_t spectrum_kempcentre_device::mreq_r(offs_t offset)
{
uint8_t data = 0xff;
if (m_romcs)
data = m_rom->base()[offset & 0x7ff];
return data;
}
//**************************************************************************
// IMPLEMENTATION (kempcentreu)
//**************************************************************************
void spectrum_kempcentreu_device::device_start()
{
// descramble ROM
std::vector<uint8_t> temp(m_rom->bytes());
std::copy_n(m_rom->base(), m_rom->bytes(), &temp[0]);
for (int i = 0; i < m_rom->bytes(); i++)
{
uint16_t addr = bitswap<11>(i, 10, 1, 0, 3, 7, 2, 6, 5, 4, 8, 9);
m_rom->base()[i] = bitswap<8>(temp[addr], 4, 5, 0, 1, 6, 7, 2, 3);
}
spectrum_kempcentre_device::device_start();
}
void spectrum_kempcentreu_device::pre_opcode_fetch(offs_t offset)
{
if (!machine().side_effects_disabled())
{
if (offset == 0x09F4 || offset == 0x0eb4) // later version ? paged at PRINT and COPY routines
m_active = 1;
m_romcs = m_active && offset >= 0x0800 && offset < 0x1000;
}
}
uint8_t spectrum_kempcentreu_device::iorq_r(offs_t offset)
{
uint8_t data = 0xff;
if ((offset & 0xf0) == 0xb0) // BB or BF, actual address decode is not known
{
if (!machine().side_effects_disabled())
m_active = !BIT(offset, 2);
data &= ~0xc0;
data |= m_busy << 6;
//data |= something_centronics << 7; // wired to centronics port, but connected to GND via wire-mod
}
return data;
}
|