Previous 15994 Revisions Next

r6645 Tuesday 15th December, 2009 at 16:48:25 UTC by Curt Coder
[C1571] Added serial interface.
[src/mess/machine]c1551.c c1571.c

src/mess/machine/c1551.c
r6644r6645
242242-------------------------------------------------*/
243243
244244static FLOPPY_OPTIONS_START( c1551 )
245   FLOPPY_OPTION( c1551, "g64", "Commodore 1541 GCR Disk Image", g64_dsk_identify, g64_dsk_construct, NULL )
245246//   FLOPPY_OPTION( c1551, "d64", "Commodore 1541 Disk Image", d64_dsk_identify, d64_dsk_construct, NULL )
246   FLOPPY_OPTION( c1551, "g64", "Commodore 1541 GCR Disk Image", g64_dsk_identify, g64_dsk_construct, NULL )
247247FLOPPY_OPTIONS_END
248248
249249/*-------------------------------------------------
src/mess/machine/c1571.c
r6644r6645
3636typedef struct _c1571_t c1571_t;
3737struct _c1571_t
3838{
39   /* abstractions */
40   int address;
41 
42   /* signals */
43   int data_out;
44   int atn_ack;
45   int soe;                     /* s? output enable */
46   int mode;                     /* mode (0 = write, 1 = read) */
47 
48   /* interrupts */
49   int via0_irq;                  /* VIA #0 interrupt request */
50   int via1_irq;                  /* VIA #1 interrupt request */
51   int cia_irq;                  /* CIA interrupt request */
52 
3953   /* devices */
4054   const device_config *cpu;
4155   const device_config *via0;
r6644r6645
7084***************************************************************************/
7185 
7286/*-------------------------------------------------
87    c1571_atn_w - serial bus attention
88-------------------------------------------------*/
89 
90static CBMSERIAL_ATN( c1571 )
91{
92   c1571_t *c1571 = get_safe_token(device);
93   int data_out = !c1571->data_out && !(c1571->atn_ack ^ !state);
94 
95   via_ca1_w(c1571->via0, 0, !state);
96 
97   cbmserial_data_w(c1571->serial_bus, device, data_out);
98}
99 
100/*-------------------------------------------------
101    c1571_reset_w - serial bus reset
102-------------------------------------------------*/
103 
104static CBMSERIAL_RESET( c1571 )
105{
106   if (!state)
107   {
108      device_reset(device);
109   }
110}
111 
112/*-------------------------------------------------
73113    ADDRESS_MAP( c1570_map )
74114-------------------------------------------------*/
75115 
r6644r6645
114154    via6522_interface c1571_via0_intf
115155-------------------------------------------------*/
116156 
157static WRITE_LINE_DEVICE_HANDLER( via0_irq_w )
158{
159   c1571_t *c1571 = get_safe_token(device->owner);
160 
161   c1571->via0_irq = state;
162 
163   cpu_set_input_line(c1571->cpu, INPUT_LINE_IRQ0, (c1571->via0_irq | c1571->via1_irq | c1571->cia_irq) ? ASSERT_LINE : CLEAR_LINE);
164}
165 
166static READ8_DEVICE_HANDLER( via0_pa_r )
167{
168   /*
169 
170      bit      description
171 
172      PA0      TRK0 SNS
173      PA1      SER DIR
174      PA2      SIDE
175      PA3       
176      PA4       
177      PA5      _1/2 MHZ
178      PA6      ATN OUT
179      PA7      BYTE RDY
180 
181   */
182 
183   c1571_t *c1571 = get_safe_token(device->owner);
184 
185   return floppy_tk00_r(c1571->image);
186}
187 
188static WRITE8_DEVICE_HANDLER( via0_pa_w )
189{
190   /*
191 
192      bit      description
193 
194      PA0      TRK0 SNS
195      PA1      SER DIR
196      PA2      SIDE
197      PA3       
198      PA4       
199      PA5      _1/2 MHZ
200      PA6      ATN OUT
201      PA7      BYTE RDY
202 
203   */
204 
205   c1571_t *c1571 = get_safe_token(device->owner);
206 
207   /* side */
208   wd17xx_set_side(c1571->wd1770, BIT(data, 2));
209}
210 
211static READ8_DEVICE_HANDLER( via0_pb_r )
212{
213   /*
214 
215      bit      description
216 
217      PB0      DATA IN
218      PB1      DATA OUT
219      PB2      CLK IN
220      PB3      CLK OUT
221      PB4      ATN ACK
222      PB5      DEV# SEL
223      PB6      DEV# SEL
224      PB7      ATN IN
225 
226   */
227 
228   c1571_t *c1571 = get_safe_token(device->owner);
229   UINT8 data = 0;
230 
231   /* data in */
232   data = !cbmserial_data_r(c1571->serial_bus);
233 
234   /* clock in */
235   data |= !cbmserial_clk_r(c1571->serial_bus) << 2;
236 
237   /* serial bus address */
238   data |= c1571->address << 5;
239 
240   /* attention in */
241   data |= !cbmserial_atn_r(c1571->serial_bus) << 7;
242 
243   return data;
244}
245 
246static WRITE8_DEVICE_HANDLER( via0_pb_w )
247{
248   /*
249 
250      bit      description
251 
252      PB0      DATA IN
253      PB1      DATA OUT
254      PB2      CLK IN
255      PB3      CLK OUT
256      PB4      ATN ACK
257      PB5      DEV# SEL
258      PB6      DEV# SEL
259      PB7      ATN IN
260 
261   */
262 
263   c1571_t *c1571 = get_safe_token(device->owner);
264 
265   int data_out = BIT(data, 1);
266   int clk_out = BIT(data, 3);
267   int atn_ack = BIT(data, 4);
268 
269   /* data out */
270   int serial_data = !data_out && !(atn_ack ^ !cbmserial_atn_r(c1571->serial_bus));
271   cbmserial_data_w(c1571->serial_bus, device->owner, serial_data);
272   c1571->data_out = data_out;
273 
274   /* clock out */
275   cbmserial_clk_w(c1571->serial_bus, device->owner, !clk_out);
276 
277   /* attention acknowledge */
278   c1571->atn_ack = atn_ack;
279}
280 
117281static const via6522_interface c1571_via0_intf =
118282{
283   DEVCB_HANDLER(via0_pa_r),
284   DEVCB_HANDLER(via0_pb_r),
119285   DEVCB_NULL,
120286   DEVCB_NULL,
121287   DEVCB_NULL,
122288   DEVCB_NULL,
123   DEVCB_NULL,
124   DEVCB_NULL,
125289 
290   DEVCB_HANDLER(via0_pa_w),
291   DEVCB_HANDLER(via0_pb_w),
292   DEVCB_NULL, /* ATN IN */
126293   DEVCB_NULL,
294   DEVCB_NULL, /* _WPRT */
127295   DEVCB_NULL,
128   DEVCB_NULL,
129   DEVCB_NULL,
130   DEVCB_NULL,
131   DEVCB_NULL,
132296 
133   DEVCB_NULL
297   DEVCB_LINE(via0_irq_w)
134298};
135299 
136300/*-------------------------------------------------
137301    via6522_interface c1571_via1_intf
138302-------------------------------------------------*/
139303 
304static WRITE_LINE_DEVICE_HANDLER( via1_irq_w )
305{
306   c1571_t *c1571 = get_safe_token(device->owner);
307 
308   c1571->via1_irq = state;
309 
310   cpu_set_input_line(c1571->cpu, INPUT_LINE_IRQ0, (c1571->via0_irq | c1571->via1_irq | c1571->cia_irq) ? ASSERT_LINE : CLEAR_LINE);
311}
312 
313static READ8_DEVICE_HANDLER( yb_r )
314{
315   /*
316 
317      bit      description
318 
319      PA0      YB0
320      PA1      YB1
321      PA2      YB2
322      PA3      YB3
323      PA4      YB4
324      PA5      YB5
325      PA6      YB6
326      PA7      YB7
327 
328   */
329 
330   return 0;
331}
332 
333static WRITE8_DEVICE_HANDLER( yb_w )
334{
335   /*
336 
337      bit      description
338 
339      PA0      YB0
340      PA1      YB1
341      PA2      YB2
342      PA3      YB3
343      PA4      YB4
344      PA5      YB5
345      PA6      YB6
346      PA7      YB7
347 
348   */
349}
350 
351static READ8_DEVICE_HANDLER( via1_pb_r )
352{
353   /*
354 
355      bit      signal      description
356 
357      PB0      STP0      stepping motor bit 0
358      PB1      STP1      stepping motor bit 1
359      PB2      MTR         motor ON/OFF
360      PB3      ACT         drive 0 LED
361      PB4      _WPRT      write protect sense
362      PB5      DS0         density select 0
363      PB6      DS1         density select 1
364      PB7      _SYNC      SYNC detect line
365 
366   */
367 
368   c1571_t *c1571 = get_safe_token(device->owner);
369   UINT8 data = 0;
370 
371   /* write protect sense */
372   data |= !floppy_wpt_r(c1571->image) << 4;
373 
374   /* SYNC detect line */
375 
376   return data;
377}
378 
379static WRITE8_DEVICE_HANDLER( via1_pb_w )
380{
381   /*
382 
383      bit      signal      description
384 
385      PB0      STP0      stepping motor bit 0
386      PB1      STP1      stepping motor bit 1
387      PB2      MTR         motor ON/OFF
388      PB3      ACT         drive 0 LED
389      PB4      _WPRT      write protect sense
390      PB5      DS0         density select 0
391      PB6      DS1         density select 1
392      PB7      _SYNC      SYNC detect line
393 
394   */
395}
396 
397static WRITE_LINE_DEVICE_HANDLER( soe_w )
398{
399   c1571_t *c1571 = get_safe_token(device->owner);
400 
401   c1571->soe = state;
402}
403 
404static WRITE_LINE_DEVICE_HANDLER( mode_w )
405{
406   c1571_t *c1571 = get_safe_token(device->owner);
407 
408   c1571->mode = state;
409}
410 
140411static const via6522_interface c1571_via1_intf =
141412{
413   DEVCB_HANDLER(yb_r),
414   DEVCB_HANDLER(via1_pb_r),
415   DEVCB_NULL, /* BYTE READY */
142416   DEVCB_NULL,
143417   DEVCB_NULL,
144418   DEVCB_NULL,
145   DEVCB_NULL,
146   DEVCB_NULL,
147   DEVCB_NULL,
148419 
420   DEVCB_HANDLER(yb_w),
421   DEVCB_HANDLER(via1_pb_w),
149422   DEVCB_NULL,
150423   DEVCB_NULL,
151   DEVCB_NULL,
152   DEVCB_NULL,
153   DEVCB_NULL,
154   DEVCB_NULL,
424   DEVCB_LINE(soe_w),
425   DEVCB_LINE(mode_w),
155426 
156   DEVCB_NULL
427   DEVCB_LINE(via1_irq_w)
157428};
158429 
159430/*-------------------------------------------------
160431    cia6526_interface c1571_cia_intf
161432-------------------------------------------------*/
162433 
434static WRITE_LINE_DEVICE_HANDLER( cia_irq_w )
435{
436   c1571_t *c1571 = get_safe_token(device->owner);
437 
438   c1571->cia_irq = state;
439 
440   cpu_set_input_line(c1571->cpu, INPUT_LINE_IRQ0, (c1571->via0_irq | c1571->via1_irq | c1571->cia_irq) ? ASSERT_LINE : CLEAR_LINE);
441}
442 
163443static const cia6526_interface c1571_cia_intf =
164444{
445   DEVCB_LINE(cia_irq_w),
165446   DEVCB_NULL,
166   DEVCB_NULL,
167447   10, /* 1/10 second */
168448   {
169449      { DEVCB_NULL, DEVCB_NULL },
r6644r6645
187467-------------------------------------------------*/
188468 
189469static FLOPPY_OPTIONS_START( c1571 )
470   FLOPPY_OPTION( c1571, "g64", "Commodore 1541 GCR Disk Image", g64_dsk_identify, g64_dsk_construct, NULL )
190471//   FLOPPY_OPTION( c1571, "d64", "Commodore 1541 Disk Image", d64_dsk_identify, d64_dsk_construct, NULL )
191472//   FLOPPY_OPTION( c1571, "d71", "Commodore 1571 Disk Image", d64_dsk_identify, d64_dsk_construct, NULL )
192   FLOPPY_OPTION( c1571, "g64", "Commodore 1571 GCR Disk Image", g64_dsk_identify, g64_dsk_construct, NULL )
193473FLOPPY_OPTIONS_END
194474 
195475/*-------------------------------------------------
r6644r6645
306586 
307587static DEVICE_START( c1571 )
308588{
589   c1571_t *c1571 = get_safe_token(device);
590   const c1571_config *config = get_safe_config(device);
591 
592   /* set serial address */
593   assert((config->address > 7) && (config->address < 12));
594   c1571->address = config->address - 8;
595 
596   /* find our CPU */
597   c1571->cpu = device_find_child_by_tag(device, M6502_TAG);
598 
599   /* find devices */
600   c1571->via0 = device_find_child_by_tag(device, M6522_0_TAG);
601   c1571->via1 = device_find_child_by_tag(device, M6522_1_TAG);
602   c1571->cia = device_find_child_by_tag(device, M6526_TAG);
603   c1571->wd1770 = device_find_child_by_tag(device, WD1770_TAG);
604   c1571->serial_bus = devtag_get_device(device->machine, config->serial_bus_tag);
605   c1571->image = device_find_child_by_tag(device, FLOPPY_0);
606 
607   /* register for state saving */
309608}
310609 
311610/*-------------------------------------------------
r6644r6645
314613 
315614static DEVICE_RESET( c1571 )
316615{
616   c1571_t *c1571 = get_safe_token(device);
617 
618   device_reset(c1571->cpu);
619   device_reset(c1571->via0);
620   device_reset(c1571->via1);
621   device_reset(c1571->cia);
622   device_reset(c1571->wd1770);
317623}
318624 
319625/*-------------------------------------------------
r6644r6645
337643      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(c1571);                  break;
338644      case DEVINFO_FCT_STOP:                     /* Nothing */                                    break;
339645      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(c1571);                  break;
646      case DEVINFO_FCT_CBM_SERIAL_ATN:            info->f = (genf *)CBMSERIAL_ATN_NAME(c1571);            break;
647      case DEVINFO_FCT_CBM_SERIAL_RESET:            info->f = (genf *)CBMSERIAL_RESET_NAME(c1571);            break;
340648 
341649      /* --- the following bits of info are returned as NULL-terminated strings --- */
342650      case DEVINFO_STR_NAME:                     strcpy(info->s, "Commodore 1570");                     break;
r6644r6645
368676      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(c1571);                  break;
369677      case DEVINFO_FCT_STOP:                     /* Nothing */                                    break;
370678      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(c1571);                  break;
679      case DEVINFO_FCT_CBM_SERIAL_ATN:            info->f = (genf *)CBMSERIAL_ATN_NAME(c1571);            break;
680      case DEVINFO_FCT_CBM_SERIAL_RESET:            info->f = (genf *)CBMSERIAL_RESET_NAME(c1571);            break;
371681 
372682      /* --- the following bits of info are returned as NULL-terminated strings --- */
373683      case DEVINFO_STR_NAME:                     strcpy(info->s, "Commodore 1571");                     break;
r6644r6645
399709      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(c1571);                  break;
400710      case DEVINFO_FCT_STOP:                     /* Nothing */                                    break;
401711      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(c1571);                  break;
712      case DEVINFO_FCT_CBM_SERIAL_ATN:            info->f = (genf *)CBMSERIAL_ATN_NAME(c1571);            break;
713      case DEVINFO_FCT_CBM_SERIAL_RESET:            info->f = (genf *)CBMSERIAL_RESET_NAME(c1571);            break;
402714 
403715      /* --- the following bits of info are returned as NULL-terminated strings --- */
404716      case DEVINFO_STR_NAME:                     strcpy(info->s, "Commodore 1571CR");                  break;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team