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
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
/**********************************************************************
Commodore IEC Serial Bus emulation
Copyright MESS Team.
Visit http://mamedev.org for licensing and usage restrictions.
**********************************************************************/
/*
C64 SERIAL BUS
Serial Bus Pinouts
Pin Name Description
1 SRQ Serial Service Request In
2 GND Ground
3 ATN Serial Attention In/Out
4 CLK Serial Clock In/Out
5 DATA Serial Data In/Out
6 RESET Serial Reset
All signals are active low.
SRQ: Serial Service Request In
This signal is not used on the C64. On C128 it is replaced with Fast Serial
Clock for the 1571 disk drive.
ATN: Serial Attention In/Out
Sending any byte with the ATN line low (sending under attention) causes it
to be interpreted as a Bus Command for peripherals on the serial bus.
When the C64 brings this signal LOW, all other devices start listening for
it to transmit an address. The device addressed must respond in a preset
period of time; otherwise, the C64 will assume that the device addressed is
not on the bus, and will return an error in the STATUS word.
Usually, the address byte will be followed by one to two commands for the
device addressed, meaning the secondary address and channel on the peripheral.
Such a command can be one of the following:
20
40
60
E0
F0
CLK: Serial Clock In/Out
This signal is for timing the data sent on the serial bus. This signal is
always generated by the active TALKER. RISING EDGE OF THE CLOCK means data
bit is valid.
DATA: Serial Data In/Out
Data on the serial bus is transmitted bit by bit at a time on this line.
RESET: Serial Reset
You may disconnect this line to save your disk drive. The easiest way is to
do that on the cable, thus avoiding any modifications on your peripherals.
Serial Bus Timing
___
CLK |____|~~~~| Ts Bit Set-up time
: Ts : Tv : Tv Bit Valid time
|<--------- Byte sent under attention (to devices) ------------>|
___ ____ _____ _____
ATN |________________________________________________________|
: :
___ ______ ________ ___ ___ ___ ___ ___ ___ ___ ___ :
CLK : |_____| |_| |_| |_| |_| |_| |_| |_| |_| |______________ _____
: : : : :
: Tat : :Th: Tne : : Tf : Tr :
____ ________ : : :___________________________________:____:
DATA ___|\\\\\\\\\\__:__| |__||__||__||__||__||__||__||__| |_________ _____
: 0 1 2 3 4 5 6 7 :
: LSB MSB :
: : :
: : Data Valid Listener: Data Accepted
: Listener READY-FOR-DATA
END-OR-IDENTIFY HANDSHAKE (LAST BYTE IN MESSAGE)
___ _______________________________________________________________________
ATN
___ ___ ___ ________________ ___ ___ ___ ___ ___ ___ ___ ___ __
CLK _| |_| |______| |_| |_| |_| |_| |_| |_| |_| |_| |_______|_
: : : : :
:Tf:Tbb:Th:Tye:Tei:Try: :Tf :Tfr:
____ __________: : :___: :_______________________________________: :_
DATA |__||__| |______| |___| : |___|_
6 7 : : : : : :
MSB : : : : : Talker Sending :
: : : : Listener READY-FOR-DATA System
: : : EOI-Timeout Handshake Line Release
: : Listener READY-FOR-DATA
: Talker Ready-To-Send
TALK-ATTENTION TURN AROUND (TALKER AND LISTENER REVERSED)
___ _________________________________________________________
ATN _____________|
:
___ ___ ___ : _____ ________ ___ ___ ___ ___ ___ ___ ___ ___
CLK _| |_| |_________| |___| |_| |_| |_| |_| |_| |_| |_| |_| |_____
: : : : : : :
:Tf:Tr:Ttk:Tdc:Tda:Th:Try: :Tf :
____ __________: : : : :_______________________________________:
DATA |__||__| |_________________| :|__||__||__||__||__||__||__||__| |_
6 7 : : : : : : 0 1 2 3 4 5 6 7
MSB : : : : : :LSB MSB
: : : : : :
: : : : : : Data Valid
: : : : : Listener READY-FOR-DATA
: : : : Talker Ready-To-Send
: : : Device acknowledges it's now TALKER.
: : Becomes LISTENER, Clock = High, Data = Low
: Talker Ready-To-Send
___ _____________________________________________________________________
ATN
___ _________ ___ ___ ___ ___ ___ ___ ___ ___ ________ ___ ___
CLK ____| |_| |_| |_| |_| |_| |_| |_| |_| |_______| |_| |_| |_
: : : : :
:Th :Tne: :Tf :Tbb:Th:Tne:
____ : :___:___________________________________: :_____________
DATA ________| :|__||__||__||__||__||__||__||__| |______|
: : : 0 1 2 3 4 5 6 7 :
: : :LSB MSB :
: : : :
: : : TALKER SENDING Listener: Data Accepted
: : LISTENER READY-FOR-DATA
: TALKER READY-TO-SEND
Serial Bus Timing
Description Symbol Min Typ Max
ATN Response (required) 1) Tat - - 1000us
Listener Hold-Off Th 0 - oo
Non-EOI Response to RFD 2) Tne - 40us 200us
Bit Set-Up Talker 4) Ts 20us 70us -
Data Valid Tv 20us 20us -
Frame Handshake 3) Tf 0 20 1000us
Frame to Release of ATN Tr 20us - -
Between Bytes Time Tbb 100us - -
EOI Response Time Tye 200us 250us -
EOI Response Hold Time 5) Tei 60us - -
Talker Response Limit Try 0 30us 60us
Byte-Acknowledge 4) Tpr 20us 30us -
Talk-Attention Release Ttk 20us 30us 100us
Talk-Attention Acknowledge Tdc 0 - -
Talk-Attention Ack. Hold Tda 80us - -
EOI Acknowledge Tfr 60us - -
Notes:
1) If maximum time exceeded, device not present error.
2) If maximum time exceeded, EOI response required.
3) If maximum time exceeded, frame error.
4) Tv and Tpr minimum must be 60us for external device to be a talker.
5) Tei minimum must be 80us for external device to be a listener.
*/
/*
TODO:
- refactor into an actual daisy chain instead of this convenient hack
*/
#include "cbmiec.h"
//**************************************************************************
// MACROS / CONSTANTS
//**************************************************************************
#define LOG 0
static const char *const SIGNAL_NAME[] = { "SRQ", "ATN", "CLK", "DATA", "RESET" };
//**************************************************************************
// DEVICE DEFINITIONS
//**************************************************************************
const device_type CBM_IEC = &device_creator<cbm_iec_device>;
const device_type CBM_IEC_SLOT = &device_creator<cbm_iec_slot_device>;
//**************************************************************************
// DEVICE INTERFACE
//**************************************************************************
//-------------------------------------------------
// device_cbm_iec_interface - constructor
//-------------------------------------------------
device_cbm_iec_interface::device_cbm_iec_interface(const machine_config &mconfig, device_t &device)
: device_slot_card_interface(mconfig, device)
{
}
//-------------------------------------------------
// ~device_cbm_iec_interface - destructor
//-------------------------------------------------
device_cbm_iec_interface::~device_cbm_iec_interface()
{
}
//**************************************************************************
// LIVE DEVICE
//**************************************************************************
//-------------------------------------------------
// cbm_iec_slot_device - constructor
//-------------------------------------------------
cbm_iec_slot_device::cbm_iec_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
device_t(mconfig, CBM_IEC_SLOT, "CBM IEC slot", tag, owner, clock),
device_slot_interface(mconfig, *this)
{
}
//-------------------------------------------------
// static_set_slot -
//-------------------------------------------------
void cbm_iec_slot_device::static_set_slot(device_t &device, int address)
{
cbm_iec_slot_device &cbm_iec_card = dynamic_cast<cbm_iec_slot_device &>(device);
cbm_iec_card.m_address = address;
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void cbm_iec_slot_device::device_start()
{
m_bus = machine().device<cbm_iec_device>(CBM_IEC_TAG);
device_cbm_iec_interface *dev = dynamic_cast<device_cbm_iec_interface *>(get_card_device());
if (dev) m_bus->add_device(get_card_device(), m_address);
}
//**************************************************************************
// INLINE HELPERS
//**************************************************************************
//-------------------------------------------------
// set_signal -
//-------------------------------------------------
inline void cbm_iec_device::set_signal(device_t *device, int signal, int state)
{
bool changed = false;
if (device == this)
{
if (m_line[signal] != state)
{
if (LOG) logerror("CBM IEC: '%s' %s %u\n", tag(), SIGNAL_NAME[signal], state);
m_line[signal] = state;
changed = true;
}
}
else
{
daisy_entry *entry = m_device_list.first();
while (entry)
{
if (!strcmp(entry->m_device->tag(), device->tag()))
{
if (entry->m_line[signal] != state)
{
if (LOG) logerror("CBM IEC: '%s' %s %u\n", device->tag(), SIGNAL_NAME[signal], state);
entry->m_line[signal] = state;
changed = true;
}
}
entry = entry->next();
}
}
if (changed)
{
switch (signal)
{
case SRQ: m_write_srq(state); break;
case ATN: m_write_atn(state); break;
case CLK: m_write_clk(state); break;
case DATA: m_write_data(state); break;
case RESET: m_write_reset(state);break;
}
daisy_entry *entry = m_device_list.first();
while (entry)
{
switch (signal)
{
case SRQ:
entry->m_interface->cbm_iec_srq(state);
break;
case ATN:
entry->m_interface->cbm_iec_atn(state);
break;
case CLK:
entry->m_interface->cbm_iec_clk(state);
break;
case DATA:
entry->m_interface->cbm_iec_data(state);
break;
case RESET:
entry->m_interface->cbm_iec_reset(state);
break;
}
entry = entry->next();
}
if (LOG) logerror("CBM IEC: SRQ %u ATN %u CLK %u DATA %u RESET %u\n",
get_signal(SRQ), get_signal(ATN), get_signal(CLK), get_signal(DATA), get_signal(RESET));
}
}
//-------------------------------------------------
// get_signal -
//-------------------------------------------------
inline int cbm_iec_device::get_signal(int signal)
{
int state = m_line[signal];
if (state)
{
daisy_entry *entry = m_device_list.first();
while (entry)
{
if (!entry->m_line[signal])
{
state = 0;
break;
}
entry = entry->next();
}
}
return state;
}
//**************************************************************************
// LIVE DEVICE
//**************************************************************************
//-------------------------------------------------
// cbm_iec_device - constructor
//-------------------------------------------------
cbm_iec_device::cbm_iec_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, CBM_IEC, "CBM IEC bus", tag, owner, clock),
m_write_srq(*this),
m_write_atn(*this),
m_write_clk(*this),
m_write_data(*this),
m_write_reset(*this)
{
for (int i = 0; i < SIGNAL_COUNT; i++)
{
m_line[i] = 1;
}
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void cbm_iec_device::device_start()
{
// resolve callbacks
m_write_srq.resolve_safe();
m_write_atn.resolve_safe();
m_write_clk.resolve_safe();
m_write_data.resolve_safe();
m_write_reset.resolve_safe();
}
//-------------------------------------------------
// device_reset - device-specific reset
//-------------------------------------------------
void cbm_iec_device::device_reset()
{
reset_w(0);
reset_w(1);
}
//-------------------------------------------------
// device_stop - device-specific stop
//-------------------------------------------------
void cbm_iec_device::device_stop()
{
m_device_list.reset();
}
//-------------------------------------------------
// add_device -
//-------------------------------------------------
void cbm_iec_device::add_device(device_t *target, int address)
{
daisy_entry *entry = auto_alloc(machine(), daisy_entry(target));
entry->m_interface->m_bus = this;
entry->m_interface->m_address = address;
m_device_list.append(*entry);
}
//-------------------------------------------------
// daisy_entry - constructor
//-------------------------------------------------
cbm_iec_device::daisy_entry::daisy_entry(device_t *device)
: m_next(NULL),
m_device(device),
m_interface(NULL)
{
for (int i = 0; i < SIGNAL_COUNT; i++)
{
m_line[i] = 1;
}
device->interface(m_interface);
}
//-------------------------------------------------
// srq_r -
//-------------------------------------------------
READ_LINE_MEMBER( cbm_iec_device::srq_r )
{
return get_signal(SRQ);
}
//-------------------------------------------------
// atn_r -
//-------------------------------------------------
READ_LINE_MEMBER( cbm_iec_device::atn_r )
{
return get_signal(ATN);
}
//-------------------------------------------------
// clk_r -
//-------------------------------------------------
READ_LINE_MEMBER( cbm_iec_device::clk_r )
{
return get_signal(CLK);
}
//-------------------------------------------------
// data_r -
//-------------------------------------------------
READ_LINE_MEMBER( cbm_iec_device::data_r )
{
return get_signal(DATA);
}
//-------------------------------------------------
// reset_r -
//-------------------------------------------------
READ_LINE_MEMBER( cbm_iec_device::reset_r )
{
return get_signal(RESET);
}
//-------------------------------------------------
// srq_w -
//-------------------------------------------------
WRITE_LINE_MEMBER( cbm_iec_device::srq_w )
{
set_signal(this, SRQ, state);
}
//-------------------------------------------------
// atn_w -
//-------------------------------------------------
WRITE_LINE_MEMBER( cbm_iec_device::atn_w )
{
set_signal(this, ATN, state);
}
//-------------------------------------------------
// clk_w -
//-------------------------------------------------
WRITE_LINE_MEMBER( cbm_iec_device::clk_w )
{
set_signal(this, CLK, state);
}
//-------------------------------------------------
// data_w -
//-------------------------------------------------
WRITE_LINE_MEMBER( cbm_iec_device::data_w )
{
set_signal(this, DATA, state);
}
//-------------------------------------------------
// reset_w -
//-------------------------------------------------
WRITE_LINE_MEMBER( cbm_iec_device::reset_w )
{
set_signal(this, RESET, state);
}
//-------------------------------------------------
// srq_w -
//-------------------------------------------------
void cbm_iec_device::srq_w(device_t *device, int state)
{
set_signal(device, SRQ, state);
}
//-------------------------------------------------
// atn_w -
//-------------------------------------------------
void cbm_iec_device::atn_w(device_t *device, int state)
{
set_signal(device, ATN, state);
}
//-------------------------------------------------
// clk_w -
//-------------------------------------------------
void cbm_iec_device::clk_w(device_t *device, int state)
{
set_signal(device, CLK, state);
}
//-------------------------------------------------
// data_w -
//-------------------------------------------------
void cbm_iec_device::data_w(device_t *device, int state)
{
set_signal(device, DATA, state);
}
//-------------------------------------------------
// reset_w -
//-------------------------------------------------
void cbm_iec_device::reset_w(device_t *device, int state)
{
set_signal(device, RESET, state);
}
|