Previous 15994 Revisions Next

r11238 Monday 18th April, 2011 at 19:14:58 UTC by Curt Coder
Refactored the Commodore 1551 disk drive into a C++ device. (no whatsnew)
[src/mess/drivers]c16.c
[src/mess/machine]6525tpi.c 6525tpi.h c1551.c c1551.h

src/mess/machine/c1551.c
r11237r11238
1717
1818*/
1919
20#include "emu.h"
2120#include "c1551.h"
22#include "cpu/m6502/m6502.h"
23#include "imagedev/flopdrv.h"
24#include "formats/d64_dsk.h"
25#include "formats/g64_dsk.h"
26#include "machine/6525tpi.h"
21#include "machine/devhelpr.h"
2722
28/***************************************************************************
29    PARAMETERS
30***************************************************************************/
3123
24
25//**************************************************************************
26//  MACROS / CONSTANTS
27//**************************************************************************
28
3229#define M6510T_TAG      "u2"
3330#define M6523_0_TAG      "u3"
3431#define M6523_1_TAG      "ci_u2"
3532
3633#define SYNC \
37   !(c1551->mode && ((c1551->data & G64_SYNC_MARK) == G64_SYNC_MARK))
34   !(m_mode && ((m_data & G64_SYNC_MARK) == G64_SYNC_MARK))
3835
39/***************************************************************************
40    TYPE DEFINITIONS
41***************************************************************************/
42
43typedef struct _c1551_t c1551_t;
44struct _c1551_t
36enum
4537{
46   /* TCBM bus */
47   int address;                     /* device address - 8 */
48   UINT8 tcbm_data;                  /* data */
49   int status;                        /* status */
50   int dav;                        /* data valid */
51   int ack;                        /* acknowledge */
38   LED_POWER = 0,
39   LED_ACT
40};
5241
53   /* motors */
54   int stp;                        /* stepper motor phase */
55   int mtr;                        /* spindle motor on */
5642
57   /* track */
58   UINT8 track_buffer[G64_BUFFER_SIZE];   /* track data buffer */
59   int track_len;                     /* track length */
60   int buffer_pos;                     /* current byte position within track buffer */
61   int bit_pos;                     /* current bit position within track buffer byte */
62   int bit_count;                     /* current data byte bit counter */
63   UINT16 data;                     /* data shift register */
64   UINT8 yb;                        /* GCR data byte */
6543
66   /* signals */
67   int ds;                           /* density select */
68   int soe;                        /* s? output enable */
69   int byte;                        /* byte ready */
70   int mode;                        /* mode (0 = write, 1 = read) */
44//**************************************************************************
45//  DEVICE DEFINITIONS
46//**************************************************************************
7147
72   /* devices */
73   device_t *cpu;
74   device_t *tpi0;
75   device_t *tpi1;
76   device_t *image;
48const device_type C1551 = c1551_device_config::static_alloc_device_config;
7749
78   /* timers */
79   emu_timer *bit_timer;
80};
8150
82/***************************************************************************
83    INLINE FUNCTIONS
84***************************************************************************/
8551
86INLINE c1551_t *get_safe_token(device_t *device)
87{
88   assert(device != NULL);
89   assert(device->type() == C1551);
90   return (c1551_t *)downcast<legacy_device_base *>(device)->token();
91}
52//**************************************************************************
53//  DEVICE CONFIGURATION
54//**************************************************************************
9255
93INLINE c1551_config *get_safe_config(device_t *device)
94{
95   assert(device != NULL);
96   assert(device->type() == C1551);
97   return (c1551_config *)downcast<const legacy_device_config_base &>(device->baseconfig()).inline_config();
98}
56GENERIC_DEVICE_CONFIG_SETUP(c1551, "C1551");
9957
100/***************************************************************************
101    IMPLEMENTATION
102***************************************************************************/
10358
104/*-------------------------------------------------
105    TIMER_DEVICE_CALLBACK( irq_tick )
106-------------------------------------------------*/
59//-------------------------------------------------
60//  device_config_complete - perform any
61//  operations now that the configuration is
62//  complete
63//-------------------------------------------------
10764
108static TIMER_DEVICE_CALLBACK( irq_tick )
65void c1551_device_config::device_config_complete()
10966{
110   c1551_t *c1551 = get_safe_token(timer.owner());
111
112   device_set_input_line(c1551->cpu, M6502_IRQ_LINE, ASSERT_LINE);
113   device_set_input_line(c1551->cpu, M6502_IRQ_LINE, CLEAR_LINE);
67   m_shortname = "c1551";
11468}
11569
116/*-------------------------------------------------
117    TIMER_CALLBACK( bit_tick )
118-------------------------------------------------*/
11970
120static TIMER_CALLBACK( bit_tick )
71//-------------------------------------------------
72//  static_set_config - configuration helper
73//-------------------------------------------------
74
75void c1551_device_config::static_set_config(device_config *device, int address)
12176{
122   device_t *device = (device_t *)ptr;
123   c1551_t *c1551 = get_safe_token(device);
124   int byte = 0;
77   c1551_device_config *c1551 = downcast<c1551_device_config *>(device);
12578
126   /* shift in data from the read head */
127   c1551->data <<= 1;
128   c1551->data |= BIT(c1551->track_buffer[c1551->buffer_pos], c1551->bit_pos);
129   c1551->bit_pos--;
130   c1551->bit_count++;
79   assert((address > 7) && (address < 10));
13180
132   if (c1551->bit_pos < 0)
133   {
134      c1551->bit_pos = 7;
135      c1551->buffer_pos++;
136
137      if (c1551->buffer_pos >= c1551->track_len)
138      {
139         /* loop to the start of the track */
140         c1551->buffer_pos = 0;
141      }
142   }
143
144   if (!SYNC)
145   {
146      /* SYNC detected */
147      c1551->bit_count = 0;
148   }
149
150   if (c1551->bit_count > 7)
151   {
152      /* byte ready */
153      c1551->bit_count = 0;
154      byte = 1;
155
156      c1551->yb = c1551->data & 0xff;
157
158      if (!c1551->yb)
159      {
160         /* simulate weak bits with randomness */
161         c1551->yb = machine.rand() & 0xff;
162      }
163
164      c1551->byte = byte;
165   }
81   c1551->m_address = address - 8;
16682}
16783
168/*-------------------------------------------------
169    c1551_port_r - M6510T port read
170-------------------------------------------------*/
17184
172static void read_current_track(c1551_t *c1551)
173{
174   c1551->track_len = G64_BUFFER_SIZE;
175   c1551->buffer_pos = 0;
176   c1551->bit_pos = 7;
177   c1551->bit_count = 0;
85//-------------------------------------------------
86//  ROM( c1551 )
87//-------------------------------------------------
17888
179   /* read track data */
180   floppy_drive_read_track_data_info_buffer(c1551->image, 0, c1551->track_buffer, &c1551->track_len);
89ROM_START( c1551 ) // schematic 251860
90   ROM_REGION( 0x4000, "c1551", 0 )
91   ROM_LOAD( "318001-01.u4", 0x0000, 0x4000, CRC(6d16d024) SHA1(fae3c788ad9a6cc2dbdfbcf6c0264b2ca921d55e) )
92ROM_END
18193
182   /* extract track length */
183   c1551->track_len = floppy_drive_get_current_track_size(c1551->image, 0);
184}
18594
186/*-------------------------------------------------
187    on_disk_change - disk change handler
188-------------------------------------------------*/
95//-------------------------------------------------
96//  rom_region - device-specific ROM region
97//-------------------------------------------------
18998
190static void on_disk_change(device_image_interface &image)
99const rom_entry *c1551_device_config::device_rom_region() const
191100{
192   c1551_t *c1551 = get_safe_token(image.device().owner());
193
194   read_current_track(c1551);
101   return ROM_NAME( c1551 );
195102}
196103
197/*-------------------------------------------------
198    spindle_motor - spindle motor control
199-------------------------------------------------*/
200104
201static void spindle_motor(c1551_t *c1551, int mtr)
202{
203   if (c1551->mtr != mtr)
204   {
205      if (mtr)
206      {
207         /* read track data */
208         read_current_track(c1551);
209      }
105//-------------------------------------------------
106//  m6502_interface m6510t_intf
107//-------------------------------------------------
210108
211      floppy_mon_w(c1551->image, !mtr);
212      c1551->bit_timer->enable(mtr);
213
214      c1551->mtr = mtr;
215   }
216}
217
218/*-------------------------------------------------
219    step_motor - stepper motor control
220-------------------------------------------------*/
221
222static void step_motor(c1551_t *c1551, int mtr, int stp)
109READ8_MEMBER( c1551_device::port_r )
223110{
224   if (mtr && (c1551->stp != stp))
225   {
226      int tracks = 0;
227
228      switch (c1551->stp)
229      {
230      case 0:   if (stp == 1) tracks++; else if (stp == 3) tracks--; break;
231      case 1:   if (stp == 2) tracks++; else if (stp == 0) tracks--; break;
232      case 2: if (stp == 3) tracks++; else if (stp == 1) tracks--; break;
233      case 3: if (stp == 0) tracks++; else if (stp == 2) tracks--; break;
234      }
235
236      if (tracks != 0)
237      {
238         /* step read/write head */
239         floppy_drive_seek(c1551->image, tracks);
240
241         /* read new track data */
242         read_current_track(c1551);
243      }
244
245      c1551->stp = stp;
246   }
247}
248
249/*-------------------------------------------------
250    c1551_port_r - M6510T port read
251-------------------------------------------------*/
252
253static READ8_DEVICE_HANDLER( c1551_port_r )
254{
255111   /*
256112
257113        bit     description
r11237r11238
265121        P6      DS1
266122        P7      BYTE LTCHED
267123
268    */
124   */   
269125
270   c1551_t *c1551 = get_safe_token(device->owner());
271126   UINT8 data = 0;
272127
273   /* write protect sense */
274   data |= !floppy_wpt_r(c1551->image) << 4;
128   // write protect sense
129   data |= !floppy_wpt_r(m_image) << 4;
275130
276   /* byte latched */
277   data |= (c1551->soe & c1551->byte) << 7;
131   // byte latched
132   data |= (m_soe & m_byte) << 7;
278133
279134   return data;
280135}
281136
282/*-------------------------------------------------
283    c1551_port_w - M6510T port write
284-------------------------------------------------*/
285137
286static WRITE8_DEVICE_HANDLER( c1551_port_w )
138WRITE8_MEMBER( c1551_device::port_w )
287139{
288140   /*
289141
r11237r11238
298150        P6      DS1
299151        P7      BYTE LTCHED
300152
301    */
153   */
302154
303   c1551_t *c1551 = get_safe_token(device->owner());
304
305   /* spindle motor */
155   // spindle motor
306156   int mtr = BIT(data, 2);
307   spindle_motor(c1551, mtr);
157   spindle_motor(mtr);
308158
309   /* stepper motor */
159   // stepper motor
310160   int stp = data & 0x03;
311   step_motor(c1551, mtr, stp);
161   step_motor(mtr, stp);
312162
313   /* TODO activity LED */
163   // activity LED
164   output_set_led_value(LED_ACT, BIT(data, 6));
314165
315   /* density select */
166   // density select
316167   int ds = (data >> 5) & 0x03;
317168
318   if (c1551->ds != ds)
169   if (m_ds != ds)
319170   {
320      c1551->bit_timer->adjust(attotime::zero, 0, attotime::from_hz(C2040_BITRATE[ds]/4));
321      c1551->ds = ds;
171      m_bit_timer->adjust(attotime::zero, 0, attotime::from_hz(C2040_BITRATE[ds]/4));
172      m_ds = ds;
322173   }
323174}
324175
176
325177static const m6502_interface m6510t_intf =
326178{
327   NULL,         /* read_indexed_func */
328   NULL,         /* write_indexed_func */
329   DEVCB_HANDLER(c1551_port_r),   /* port_read_func */
330   DEVCB_HANDLER(c1551_port_w)   /* port_write_func */
179   NULL,         // read_indexed_func
180   NULL,         // write_indexed_func
181   DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, port_r),
182   DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, port_w)
331183};
332184
333/*-------------------------------------------------
334    ADDRESS_MAP( c1551_map )
335-------------------------------------------------*/
336185
337static ADDRESS_MAP_START( c1551_map, AS_PROGRAM, 8 )
338   AM_RANGE(0x0000, 0x07ff) AM_MIRROR(0x0800) AM_RAM
339   AM_RANGE(0x4000, 0x4007) AM_MIRROR(0x3ff8) AM_DEVREADWRITE(M6523_0_TAG, tpi6525_r, tpi6525_w)
340   AM_RANGE(0xc000, 0xffff) AM_ROM AM_REGION("c1551:c1551", 0)
341ADDRESS_MAP_END
186//-------------------------------------------------
187//  tpi6525_interface tpi0_intf
188//-------------------------------------------------
342189
343/*-------------------------------------------------
344    tpi6525_interface tpi0_intf
345-------------------------------------------------*/
346
347static READ8_DEVICE_HANDLER( tpi0_pa_r )
190READ8_MEMBER( c1551_device::tcbm_data_r )
348191{
349192   /*
350193
r11237r11238
359202        PA6     TCBM PA6
360203        PA7     TCBM PA7
361204
362    */
205   */
363206
364   c1551_t *c1551 = get_safe_token(device->owner());
365
366   return c1551->tcbm_data;
207   return m_tcbm_data;
367208}
368209
369static WRITE8_DEVICE_HANDLER( tpi0_pa_w )
210
211WRITE8_MEMBER( c1551_device::tcbm_data_w )
370212{
371213   /*
372214
r11237r11238
381223        PA6     TCBM PA6
382224        PA7     TCBM PA7
383225
384    */
226   */
385227
386   c1551_t *c1551 = get_safe_token(device->owner());
387
388   c1551->tcbm_data = data;
228   m_tcbm_data = data;
389229}
390230
391static READ8_DEVICE_HANDLER( tpi0_pb_r )
231
232READ8_MEMBER( c1551_device::yb_r )
392233{
393234   /*
394235
r11237r11238
403244        PB6     YB6
404245        PB7     YB7
405246
406    */
247   */
407248
408   c1551_t *c1551 = get_safe_token(device->owner());
249   m_byte = 0;
409250
410   c1551->byte = 0;
411
412   return c1551->yb;
251   return m_yb;
413252}
414253
415static WRITE8_DEVICE_HANDLER( tpi0_pb_w )
254
255WRITE8_MEMBER( c1551_device::yb_w )
416256{
417257   /*
418258
r11237r11238
427267        PB6     YB6
428268        PB7     YB7
429269
430    */
270   */
431271
432   c1551_t *c1551 = get_safe_token(device->owner());
433
434   c1551->yb = data;
272   m_yb = data;
435273}
436274
437static READ8_DEVICE_HANDLER( tpi0_pc_r )
275
276READ8_MEMBER( c1551_device::tpi0_pc_r )
438277{
439278   /*
440279
441280        bit     description
442281
443        PC0     TCBM STATUS0
444        PC1     TCBM STATUS1
445        PC2     TCBM DEV
446        PC3     TCBM ACK
447        PC4     MODE
282        PC0     
283        PC1     
284        PC2     
285        PC3     
286        PC4     
448287        PC5     JP1
449288        PC6     _SYNC
450289        PC7     TCBM DAV
451290
452    */
291   */
453292
454   c1551_t *c1551 = get_safe_token(device->owner());
455293   UINT8 data = 0;
456294
457   /* JP1 */
458   data |= c1551->address << 5;
295   // JP1
296   data |= m_config.m_address << 5;
459297
460   /* SYNC detect line */
298   // SYNC detect line
461299   data |= SYNC << 6;
462300
463   /* TCBM data valid */
464   data |= c1551->dav << 7;
301   // TCBM data valid
302   data |= m_dav << 7;
465303
466304   return data;
467305}
468306
469static WRITE8_DEVICE_HANDLER( tpi0_pc_w )
307
308WRITE8_MEMBER( c1551_device::tpi0_pc_w )
470309{
471310   /*
472311
r11237r11238
477316        PC2     TCBM DEV
478317        PC3     TCBM ACK
479318        PC4     MODE
480        PC5     JP1
481        PC6     _SYNC
482        PC7     TCBM DAV
319        PC5     
320        PC6     
321        PC7     
483322
484    */
323   */
485324
486   c1551_t *c1551 = get_safe_token(device->owner());
325   // TCBM status
326   m_status = data & 0x03;
487327
488   /* TCBM status */
489   c1551->status = data & 0x03;
328   // TODO TCBM device number
490329
491   /* TODO TCBM device number */
330   // TCBM acknowledge
331   m_ack = BIT(data, 3);
492332
493   /* TCBM acknowledge */
494   c1551->ack = BIT(data, 3);
495
496   /* read/write mode */
497   c1551->mode = BIT(data, 4);
333   // read/write mode
334   m_mode = BIT(data, 4);
498335}
499336
337
500338static const tpi6525_interface tpi0_intf =
501339{
502340   DEVCB_NULL,
503   DEVCB_HANDLER(tpi0_pa_r),
504   DEVCB_HANDLER(tpi0_pa_w),
505   DEVCB_HANDLER(tpi0_pb_r),
506   DEVCB_HANDLER(tpi0_pb_w),
507   DEVCB_HANDLER(tpi0_pc_r),
508   DEVCB_HANDLER(tpi0_pc_w),
341   DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, tcbm_data_r),
342   DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, tcbm_data_w),
343   DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, yb_r),
344   DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, yb_w),
345   DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, tpi0_pc_r),
346   DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, tpi0_pc_w),
509347   DEVCB_NULL,
510348   DEVCB_NULL
511349};
512350
513/*-------------------------------------------------
514    tpi6525_interface tpi1_intf
515-------------------------------------------------*/
516351
517static READ8_DEVICE_HANDLER( tpi1_pa_r )
518{
519   /*
352//-------------------------------------------------
353//  tpi6525_interface tpi1_intf
354//-------------------------------------------------
520355
521        bit     description
522
523        PA0     TCBM PA0
524        PA1     TCBM PA1
525        PA2     TCBM PA2
526        PA3     TCBM PA3
527        PA4     TCBM PA4
528        PA5     TCBM PA5
529        PA6     TCBM PA6
530        PA7     TCBM PA7
531
532    */
533
534   c1551_t *c1551 = get_safe_token(device->owner());
535
536   return c1551->tcbm_data;
537}
538
539static WRITE8_DEVICE_HANDLER( tpi1_pa_w )
356READ8_MEMBER( c1551_device::tpi1_pb_r )
540357{
541358   /*
542359
543360        bit     description
544361
545        PA0     TCBM PA0
546        PA1     TCBM PA1
547        PA2     TCBM PA2
548        PA3     TCBM PA3
549        PA4     TCBM PA4
550        PA5     TCBM PA5
551        PA6     TCBM PA6
552        PA7     TCBM PA7
553
554    */
555
556   c1551_t *c1551 = get_safe_token(device->owner());
557
558   c1551->tcbm_data = data;
559}
560
561static READ8_DEVICE_HANDLER( tpi1_pb_r )
562{
563   /*
564
565        bit     description
566
567362        PB0     STATUS0
568363        PB1     STATUS1
569364        PB2
r11237r11238
573368        PB6
574369        PB7
575370
576    */
371   */
577372
578   c1551_t *c1551 = get_safe_token(device->owner());
579
580   return c1551->status;
373   return m_status & 0x03;
581374}
582375
583static READ8_DEVICE_HANDLER( tpi1_pc_r )
376
377READ8_MEMBER( c1551_device::tpi1_pc_r )
584378{
585379   /*
586380
r11237r11238
595389        PC6     TCBM DAV
596390        PC7     TCBM ACK
597391
598    */
392   */
599393
600   c1551_t *c1551 = get_safe_token(device->owner());
601
602394   UINT8 data = 0;
603395
604   /* TCBM acknowledge */
605   data |= c1551->ack << 7;
396   // TCBM acknowledge
397   data |= m_ack << 7;
606398
607399   return data;
608400}
609401
610static WRITE8_DEVICE_HANDLER( tpi1_pc_w )
402
403WRITE8_MEMBER( c1551_device::tpi1_pc_w )
611404{
612405   /*
613406
r11237r11238
622415        PC6     TCBM DAV
623416        PC7     TCBM ACK
624417
625    */
418   */
626419
627   c1551_t *c1551 = get_safe_token(device->owner());
628
629   /* TCBM data valid */
630   c1551->dav = BIT(data, 6);
420   // TCBM data valid
421   m_dav = BIT(data, 6);
631422}
632423
424
633425static const tpi6525_interface tpi1_intf =
634426{
635427   DEVCB_NULL,
636   DEVCB_HANDLER(tpi1_pa_r),
637   DEVCB_HANDLER(tpi1_pa_w),
638   DEVCB_HANDLER(tpi1_pb_r),
428   DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, tcbm_data_r),
429   DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, tcbm_data_w),
430   DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, tpi1_pb_r),
639431   DEVCB_NULL,
640   DEVCB_HANDLER(tpi1_pc_r),
641   DEVCB_HANDLER(tpi1_pc_w),
432   DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, tpi1_pc_r),
433   DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, tpi1_pc_w),
642434   DEVCB_NULL,
643435   DEVCB_NULL
644436};
645437
646/*-------------------------------------------------
647    FLOPPY_OPTIONS( c1551 )
648-------------------------------------------------*/
649438
439//-------------------------------------------------
440//  ADDRESS_MAP( c1551_mem )
441//-------------------------------------------------
442
443static ADDRESS_MAP_START( c1551_mem, AS_PROGRAM, 8, c1551_device )
444   AM_RANGE(0x0000, 0x07ff) AM_MIRROR(0x0800) AM_RAM
445   AM_RANGE(0x4000, 0x4007) AM_MIRROR(0x3ff8) AM_DEVREADWRITE_LEGACY(M6523_0_TAG, tpi6525_r, tpi6525_w)
446   AM_RANGE(0xc000, 0xffff) AM_ROM AM_REGION("c1551:c1551", 0)
447ADDRESS_MAP_END
448
449
450//-------------------------------------------------
451//  FLOPPY_OPTIONS( c1551 )
452//-------------------------------------------------
453
650454static FLOPPY_OPTIONS_START( c1551 )
651455   FLOPPY_OPTION( c1551, "g64", "Commodore 1551 GCR Disk Image", g64_dsk_identify, g64_dsk_construct, NULL )
652456   FLOPPY_OPTION( c1551, "d64", "Commodore 1551 Disk Image", d64_dsk_identify, d64_dsk_construct, NULL )
653457FLOPPY_OPTIONS_END
654458
655/*-------------------------------------------------
656    floppy_config c1551_floppy_config
657-------------------------------------------------*/
658459
460//-------------------------------------------------
461//  floppy_config c1551_floppy_config
462//-------------------------------------------------
463
659464static const floppy_config c1551_floppy_config =
660465{
661466   DEVCB_NULL,
r11237r11238
668473   NULL
669474};
670475
671/*-------------------------------------------------
672    MACHINE_DRIVER( c1551 )
673-------------------------------------------------*/
674476
477//-------------------------------------------------
478//  MACHINE_DRIVER( c1551 )
479//-------------------------------------------------
480
675481static MACHINE_CONFIG_FRAGMENT( c1551 )
676482   MCFG_CPU_ADD(M6510T_TAG, M6510T, XTAL_16MHz/8)
677   MCFG_CPU_PROGRAM_MAP(c1551_map)
483   MCFG_CPU_PROGRAM_MAP(c1551_mem)
678484   MCFG_CPU_CONFIG(m6510t_intf)
679485
680   MCFG_TPI6525_ADD(M6523_0_TAG, tpi0_intf) // 6523
681   MCFG_TPI6525_ADD(M6523_1_TAG, tpi1_intf) // 6523
486   MCFG_TPI6525_ADD(M6523_0_TAG, tpi0_intf)
487   MCFG_TPI6525_ADD(M6523_1_TAG, tpi1_intf)
682488
683   MCFG_TIMER_ADD_PERIODIC("irq", irq_tick, attotime::from_hz(120))
684
685489   MCFG_FLOPPY_DRIVE_ADD(FLOPPY_0, c1551_floppy_config)
686490MACHINE_CONFIG_END
687491
688/*-------------------------------------------------
689    ROM( c1551 )
690-------------------------------------------------*/
691492
692ROM_START( c1551 ) // schematic 251860
693   ROM_REGION( 0x4000, "c1551", ROMREGION_LOADBYNAME )
694   ROM_LOAD( "318001-01.u4", 0x0000, 0x4000, CRC(6d16d024) SHA1(fae3c788ad9a6cc2dbdfbcf6c0264b2ca921d55e) )
695ROM_END
493//-------------------------------------------------
494//  machine_config_additions - device-specific
495//  machine configurations
496//-------------------------------------------------
696497
697/*-------------------------------------------------
698    DEVICE_START( c1551 )
699-------------------------------------------------*/
498machine_config_constructor c1551_device_config::device_mconfig_additions() const
499{
500   return MACHINE_CONFIG_NAME( c1551 );
501}
700502
701static DEVICE_START( c1551 )
503
504
505//**************************************************************************
506//  INLINE HELPERS
507//**************************************************************************
508
509//-------------------------------------------------
510//  read_current_track -
511//-------------------------------------------------
512
513inline void c1551_device::read_current_track()
702514{
703   c1551_t *c1551 = get_safe_token(device);
704   const c1551_config *config = get_safe_config(device);
515   m_track_len = G64_BUFFER_SIZE;
516   m_buffer_pos = 0;
517   m_bit_pos = 7;
518   m_bit_count = 0;
705519
706   /* set address */
707   assert((config->address > 7) && (config->address < 10));
708   c1551->address = config->address - 8;
520   // read track data
521   floppy_drive_read_track_data_info_buffer(m_image, 0, m_track_buffer, &m_track_len);
709522
710   /* find our CPU */
711   c1551->cpu = device->subdevice(M6510T_TAG);
523   // extract track length
524   m_track_len = floppy_drive_get_current_track_size(m_image, 0);
525}
712526
713   /* find devices */
714   c1551->tpi0 = device->subdevice(M6523_0_TAG);
715   c1551->tpi1 = device->subdevice(M6523_1_TAG);
716   c1551->image = device->subdevice(FLOPPY_0);
717527
718   /* install image callbacks */
719   floppy_install_unload_proc(c1551->image, on_disk_change);
720   floppy_install_load_proc(c1551->image, on_disk_change);
528//-------------------------------------------------
529//  on_disk_change -
530//-------------------------------------------------
721531
722   /* allocate data timer */
723   c1551->bit_timer = device->machine().scheduler().timer_alloc(FUNC(bit_tick), (void *)device);
532void c1551_device::on_disk_change(device_image_interface &image)
533{
534    c1551_device *c1551 = static_cast<c1551_device *>(image.device().owner());
724535
725   /* map TPI1 to host CPU memory space */
726   address_space *program = device->machine().device(config->cpu_tag)->memory().space(AS_PROGRAM);
727   UINT32 start_address = c1551->address ? 0xfec0 : 0xfef0;
536   c1551->read_current_track();
537}
728538
729   program->install_legacy_readwrite_handler(*c1551->tpi1, start_address, start_address + 7, FUNC(tpi6525_r), FUNC(tpi6525_w));
730539
731   /* register for state saving */
732   device->save_item(NAME(c1551->tcbm_data));
733   device->save_item(NAME(c1551->status));
734   device->save_item(NAME(c1551->dav));
735   device->save_item(NAME(c1551->ack));
736   device->save_item(NAME(c1551->stp));
737   device->save_item(NAME(c1551->mtr));
738   device->save_item(NAME(c1551->track_len));
739   device->save_item(NAME(c1551->buffer_pos));
740   device->save_item(NAME(c1551->bit_pos));
741   device->save_item(NAME(c1551->bit_count));
742   device->save_item(NAME(c1551->data));
743   device->save_item(NAME(c1551->yb));
744   device->save_item(NAME(c1551->ds));
745   device->save_item(NAME(c1551->soe));
746   device->save_item(NAME(c1551->byte));
747   device->save_item(NAME(c1551->mode));
540//-------------------------------------------------
541//  spindle_motor -
542//-------------------------------------------------
543
544inline void c1551_device::spindle_motor(int mtr)
545{
546   if (m_mtr != mtr)
547   {
548      if (mtr)
549      {
550         // read track data
551         read_current_track();
552      }
553
554      floppy_mon_w(m_image, !mtr);
555      m_bit_timer->enable(mtr);
556
557      m_mtr = mtr;
558   }
748559}
749560
750/*-------------------------------------------------
751    DEVICE_RESET( c1551 )
752-------------------------------------------------*/
753561
754static DEVICE_RESET( c1551 )
562//-------------------------------------------------
563//  step_motor -
564//-------------------------------------------------
565
566inline void c1551_device::step_motor(int mtr, int stp)
755567{
756   c1551_t *c1551 = get_safe_token(device);
568   if (mtr && (m_stp != stp))
569   {
570      int tracks = 0;
757571
758   c1551->cpu->reset();
759   c1551->tpi0->reset();
572      switch (m_stp)
573      {
574      case 0:   if (stp == 1) tracks++; else if (stp == 3) tracks--; break;
575      case 1:   if (stp == 2) tracks++; else if (stp == 0) tracks--; break;
576      case 2: if (stp == 3) tracks++; else if (stp == 1) tracks--; break;
577      case 3: if (stp == 0) tracks++; else if (stp == 2) tracks--; break;
578      }
760579
761   c1551->soe = 1;
580      if (tracks != 0)
581      {
582         // step read/write head
583         floppy_drive_seek(m_image, tracks);
584
585         // read new track data
586         read_current_track();
587      }
588
589      m_stp = stp;
590   }
762591}
763592
764/*-------------------------------------------------
765    DEVICE_GET_INFO( c1551 )
766-------------------------------------------------*/
767593
768DEVICE_GET_INFO( c1551 )
594//-------------------------------------------------
595//  receive_bit -
596//-------------------------------------------------
597
598inline void c1551_device::receive_bit()
769599{
770   switch (state)
600   int byte = 0;
601
602   // shift in data from the read head
603   m_data <<= 1;
604   m_data |= BIT(m_track_buffer[m_buffer_pos], m_bit_pos);
605   m_bit_pos--;
606   m_bit_count++;
607
608   if (m_bit_pos < 0)
771609   {
772      /* --- the following bits of info are returned as 64-bit signed integers --- */
773      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(c1551_t);                           break;
774      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = sizeof(c1551_config);                        break;
610      m_bit_pos = 7;
611      m_buffer_pos++;
775612
776      /* --- the following bits of info are returned as pointers --- */
777      case DEVINFO_PTR_ROM_REGION:               info->romregion = ROM_NAME(c1551);                     break;
778      case DEVINFO_PTR_MACHINE_CONFIG:            info->machine_config = MACHINE_CONFIG_NAME(c1551);         break;
613      if (m_buffer_pos >= m_track_len)
614      {
615         // loop to the start of the track
616         m_buffer_pos = 0;
617      }
618   }
779619
780      /* --- the following bits of info are returned as pointers to data or functions --- */
781      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(c1551);                  break;
782      case DEVINFO_FCT_STOP:                     /* Nothing */                                    break;
783      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(c1551);                  break;
620   if (!SYNC)
621   {
622      // SYNC detected
623      m_bit_count = 0;
624   }
784625
785      /* --- the following bits of info are returned as NULL-terminated strings --- */
786      case DEVINFO_STR_NAME:                     strcpy(info->s, "Commodore 1551");                     break;
787      case DEVINFO_STR_SHORTNAME:                  strcpy(info->s, "c1551");                           break;           
788      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "Commodore Plus/4");                  break;
789      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                              break;
790      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);                           break;
791      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright the MESS Team");             break;
626   if (m_bit_count > 7)
627   {
628      // byte ready
629      m_bit_count = 0;
630      byte = 1;
631
632      m_yb = m_data & 0xff;
633
634      if (!m_yb)
635      {
636         // simulate weak bits with randomness
637         m_yb = m_machine.rand() & 0xff;
638      }
639
640      m_byte = byte;
792641   }
793642}
794643
795DEFINE_LEGACY_DEVICE(C1551, c1551);
644
645//**************************************************************************
646//  LIVE DEVICE
647//**************************************************************************
648
649//-------------------------------------------------
650//  c1551_device - constructor
651//-------------------------------------------------
652
653c1551_device::c1551_device(running_machine &_machine, const c1551_device_config &_config)
654    : device_t(_machine, _config),
655     m_maincpu(*this, M6510T_TAG),
656     m_tpi0(*this, M6523_0_TAG),
657     m_tpi1(*this, M6523_1_TAG),
658     m_image(*this, FLOPPY_0),
659     m_tcbm_data(0),
660     m_status(0),
661     m_dav(0),
662     m_ack(0),
663     m_stp(0),
664     m_mtr(0),
665     m_ds(0),
666     m_soe(0),
667     m_byte(0),
668     m_mode(0),
669      m_config(_config)
670{
671}
672
673
674//-------------------------------------------------
675//  device_start - device-specific startup
676//-------------------------------------------------
677
678void c1551_device::device_start()
679{
680   // install image callbacks
681   floppy_install_unload_proc(m_image, c1551_device::on_disk_change);
682   floppy_install_load_proc(m_image, c1551_device::on_disk_change);
683
684   // allocate data timer
685   m_bit_timer = timer_alloc(TIMER_BIT);
686   m_irq_timer = timer_alloc(TIMER_IRQ);
687   m_irq_timer->adjust(attotime::from_hz(120), 0, attotime::from_hz(120));
688
689   // map TPI1 to host CPU memory space
690   address_space *program = m_machine.firstcpu->memory().space(AS_PROGRAM);
691   UINT32 start_address = m_config.m_address ? 0xfec0 : 0xfef0;
692
693   program->install_legacy_readwrite_handler(*m_tpi1, start_address, start_address + 7, FUNC(tpi6525_r), FUNC(tpi6525_w));
694
695   // register for state saving
696   save_item(NAME(m_tcbm_data));
697   save_item(NAME(m_status));
698   save_item(NAME(m_dav));
699   save_item(NAME(m_ack));
700   save_item(NAME(m_stp));
701   save_item(NAME(m_mtr));
702   save_item(NAME(m_track_len));
703   save_item(NAME(m_buffer_pos));
704   save_item(NAME(m_bit_pos));
705   save_item(NAME(m_bit_count));
706   save_item(NAME(m_data));
707   save_item(NAME(m_yb));
708   save_item(NAME(m_ds));
709   save_item(NAME(m_soe));
710   save_item(NAME(m_byte));
711   save_item(NAME(m_mode));
712}
713
714
715//-------------------------------------------------
716//  device_reset - device-specific reset
717//-------------------------------------------------
718
719void c1551_device::device_reset()
720{
721   m_soe = 1;
722}
723
724
725//-------------------------------------------------
726//  device_timer - handler timer events
727//-------------------------------------------------
728
729void c1551_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
730{
731   switch (id)
732   {
733   case TIMER_BIT:
734      receive_bit();
735      break;
736
737   case TIMER_IRQ:
738      m_maincpu->set_input_line(M6502_IRQ_LINE, ASSERT_LINE);
739      m_maincpu->set_input_line(M6502_IRQ_LINE, CLEAR_LINE);
740      break;
741   }
742}
src/mess/machine/c1551.h
r11237r11238
77
88**********************************************************************/
99
10#pragma once
11
1012#ifndef __C1551__
1113#define __C1551__
1214
15#define ADDRESS_MAP_MODERN
16
1317#include "emu.h"
18#include "cpu/m6502/m6502.h"
19#include "imagedev/flopdrv.h"
20#include "formats/d64_dsk.h"
21#include "formats/g64_dsk.h"
22#include "machine/6525tpi.h"
1423
15/***************************************************************************
16    MACROS / CONSTANTS
17***************************************************************************/
1824
19DECLARE_LEGACY_DEVICE(C1551, c1551);
2025
21#define MCFG_C1551_ADD(_tag, _cpu_tag, _address) \
22   MCFG_DEVICE_ADD(_tag, C1551, 0) \
23   MCFG_DEVICE_CONFIG_DATAPTR(c1551_config, cpu_tag, _cpu_tag) \
24   MCFG_DEVICE_CONFIG_DATA32(c1551_config, address, _address)
26//**************************************************************************
27//  INTERFACE CONFIGURATION MACROS
28//**************************************************************************
2529
26/***************************************************************************
27    TYPE DEFINITIONS
28***************************************************************************/
30#define MCFG_C1551_ADD(_tag, _address) \
31    MCFG_DEVICE_ADD(_tag, C1551, 0) \
32   c1551_device_config::static_set_config(device, _address);
2933
30typedef struct _c1551_config c1551_config;
31struct _c1551_config
34
35
36//**************************************************************************
37//  TYPE DEFINITIONS
38//**************************************************************************
39
40// ======================> c1551_device_config
41
42class c1551_device_config :   public device_config
3243{
33   const char *cpu_tag;      /* CPU to hook into */
34   int address;            /* bus address */
44    friend class c1551_device;
45
46    // construction/destruction
47    c1551_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
48
49public:
50    // allocators
51    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
52    virtual device_t *alloc_device(running_machine &machine) const;
53
54   // inline configuration helpers
55   static void static_set_config(device_config *device, int address);
56
57   // optional information overrides
58   virtual const rom_entry *device_rom_region() const;
59   virtual machine_config_constructor device_mconfig_additions() const;
60
61protected:
62    // device_config overrides
63    virtual void device_config_complete();
64   
65private:
66   const char *m_cpu_tag;
67   int m_address;
3568};
69
70
71// ======================> c1551_device
72
73class c1551_device :  public device_t
74{
75    friend class c1551_device_config;
76
77    // construction/destruction
78    c1551_device(running_machine &_machine, const c1551_device_config &_config);
79
80public:
81   // not really public
82   static void on_disk_change(device_image_interface &image);
83
84   READ8_MEMBER( port_r );
85   WRITE8_MEMBER( port_w );
86   READ8_MEMBER( tcbm_data_r );
87   WRITE8_MEMBER( tcbm_data_w );
88   READ8_MEMBER( yb_r );
89   WRITE8_MEMBER( yb_w );
90   READ8_MEMBER( tpi0_pc_r );
91   WRITE8_MEMBER( tpi0_pc_w );
92   READ8_MEMBER( tpi1_pa_r );
93   WRITE8_MEMBER( tpi1_pa_w );
94   READ8_MEMBER( tpi1_pb_r );
95   READ8_MEMBER( tpi1_pc_r );
96   WRITE8_MEMBER( tpi1_pc_w );
97
98protected:
99    // device-level overrides
100    virtual void device_start();
101   virtual void device_reset();
102   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
103
104   inline void read_current_track();
105   inline void spindle_motor(int mtr);
106   inline void step_motor(int mtr, int stp);
107   inline void receive_bit();
108
109private:
110   static const device_timer_id TIMER_BIT = 0;
111   static const device_timer_id TIMER_IRQ = 1;
112
113   required_device<cpu_device> m_maincpu;
114   required_device<device_t> m_tpi0;
115   required_device<device_t> m_tpi1;
116   required_device<device_t> m_image;
117
118   // TCBM bus
119   UINT8 m_tcbm_data;                  // data
120   int m_status;                     // status
121   int m_dav;                        // data valid
122   int m_ack;                        // acknowledge
123
124   // motors
125   int m_stp;                        // stepper motor phase
126   int m_mtr;                        // spindle motor on
127
128   // track
129   UINT8 m_track_buffer[G64_BUFFER_SIZE];   // track data buffer
130   int m_track_len;                  // track length
131   int m_buffer_pos;                  // current byte position within track buffer
132   int m_bit_pos;                     // current bit position within track buffer byte
133   int m_bit_count;                  // current data byte bit counter
134   UINT16 m_data;                     // data shift register
135   UINT8 m_yb;                        // GCR data byte
136
137   // signals
138   int m_ds;                        // density select
139   int m_soe;                        // s? output enable
140   int m_byte;                        // byte ready
141   int m_mode;                        // mode (0 = write, 1 = read)
142
143   // timers
144   emu_timer *m_bit_timer;
145   emu_timer *m_irq_timer;
146
147    const c1551_device_config &m_config;
148};
149
150
151
152// device type definition
153extern const device_type C1551;
154
155
156
36157#endif
src/mess/machine/6525tpi.c
r11237r11238
109109typedef struct _tpi6525_state tpi6525_state;
110110struct _tpi6525_state
111111{
112   devcb_resolved_write_line out_irq_func;
113   devcb_resolved_read8 in_pa_func;
114   devcb_resolved_write8 out_pa_func;
115   devcb_resolved_read8 in_pb_func;
116   devcb_resolved_write8 out_pb_func;
117   devcb_resolved_read8 in_pc_func;
118   devcb_resolved_write8 out_pc_func;
119   devcb_resolved_write_line out_ca_func;
120   devcb_resolved_write_line out_cb_func;   
112   devcb_resolved_write_line   out_irq_func;
113   devcb_resolved_read8      in_pa_func;
114   devcb_resolved_write8      out_pa_func;
115   devcb_resolved_read8      in_pb_func;
116   devcb_resolved_write8      out_pb_func;
117   devcb_resolved_read8      in_pc_func;
118   devcb_resolved_write8      out_pc_func;
119   devcb_resolved_write_line   out_ca_func;
120   devcb_resolved_write_line   out_cb_func;   
121121   
122122   UINT8 port_a, ddr_a, in_a;
123123   UINT8 port_b, ddr_b, in_b;
r11237r11238
191191{
192192   tpi6525_state *tpi6525 = get_safe_token(device);
193193
194   /* clear old values */
195   memset(tpi6525, 0, sizeof(*tpi6525));
196
197194   /* setup some initial values */
198195   tpi6525->in_a = 0xff;
199196   tpi6525->in_b = 0xff;
src/mess/machine/6525tpi.h
r11237r11238
3737typedef struct _tpi6525_interface tpi6525_interface;
3838struct _tpi6525_interface
3939{
40   devcb_write_line out_irq_func;
40   devcb_write_line   out_irq_func;
4141
42   devcb_read8 in_pa_func;
43   devcb_write8 out_pa_func;
42   devcb_read8         in_pa_func;
43   devcb_write8      out_pa_func;
4444
45   devcb_read8 in_pb_func;
46   devcb_write8 out_pb_func;
45   devcb_read8         in_pb_func;
46   devcb_write8      out_pb_func;
4747
48   devcb_read8 in_pc_func;
49   devcb_write8 out_pc_func;
48   devcb_read8         in_pc_func;
49   devcb_write8      out_pc_func;
5050
51   devcb_write_line out_ca_func;
52   devcb_write_line out_cb_func;
51   devcb_write_line   out_ca_func;
52   devcb_write_line   out_cb_func;
5353};
5454
5555
src/mess/drivers/c16.c
r11237r11238
512512
513513static MACHINE_CONFIG_DERIVED( c16c, c16 )
514514
515   MCFG_C1551_ADD("c1551", "maincpu", 8)
515   MCFG_C1551_ADD("c1551", 8)
516516
517517#ifdef CPU_SYNC
518518   MCFG_QUANTUM_TIME(attotime::from_hz(60))
r11237r11238
549549   MCFG_DEVICE_REMOVE("ted7360")
550550   MCFG_TED7360_ADD("ted7360", plus4_ted7360_intf)
551551   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
552
552   
553553   /* internal ram */
554554   MCFG_RAM_MODIFY(RAM_TAG)
555555   MCFG_RAM_DEFAULT_SIZE("64K")
r11237r11238
558558
559559static MACHINE_CONFIG_DERIVED( plus4c, plus4 )
560560
561   MCFG_C1551_ADD("c1551", "maincpu", 8)
561   MCFG_C1551_ADD("c1551", 8)
562562
563563   MCFG_SCREEN_MODIFY("screen")
564564   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team