Previous 15994 Revisions Next

r11239 Monday 18th April, 2011 at 23:33:34 UTC by Curt Coder
Refactored C1551 disk drive to use 64H156 gate array. (no whatsnew)
[src/mess/machine]64h156.c 64h156.h c1551.c c1551.h

src/mess/machine/64h156.c
r11238r11239
11/**********************************************************************
22
3    Commodore 64H165 Gate Array emulation
3    Commodore 64H156 Gate Array emulation
44
55    Copyright MESS Team.
66    Visit http://mamedev.org for licensing and usage restrictions.
77
88**********************************************************************/
99
10/*
11
12   TODO:
13
14   - serial IEC protocol handling
15   - write to disk image
16
17*/
18
1019#include "emu.h"
1120#include "64h156.h"
1221#include "formats/g64_dsk.h"
22#include "machine/devhelpr.h"
1323
14/***************************************************************************
15    PARAMETERS
16***************************************************************************/
1724
18/***************************************************************************
19    TYPE DEFINITIONS
20***************************************************************************/
2125
22typedef struct _c64h156_t c64h156_t;
23struct _c64h156_t
26//**************************************************************************
27//  MACROS / CONSTANTS
28//**************************************************************************
29
30#define SYNC \
31   !(m_oe && ((m_data & G64_SYNC_MARK) == G64_SYNC_MARK))
32
33#define BYTE \
34   !(m_soe & m_byte)
35
36
37
38//**************************************************************************
39//  DEVICE DEFINITIONS
40//**************************************************************************
41
42const device_type C64H156 = c64h156_device_config::static_alloc_device_config;
43
44
45
46//**************************************************************************
47//  DEVICE CONFIGURATION
48//**************************************************************************
49
50GENERIC_DEVICE_CONFIG_SETUP(c64h156, "64H156");
51
52
53//-------------------------------------------------
54//  device_config_complete - perform any
55//  operations now that the configuration is
56//  complete
57//-------------------------------------------------
58
59void c64h156_device_config::device_config_complete()
2460{
25   /* motors */
26   int stp;                        /* stepper motor phase */
27   int mtr;                        /* spindle motor on */
61   // inherit a copy of the static data
62   const c64h156_interface *intf = reinterpret_cast<const c64h156_interface *>(static_config());
63   if (intf != NULL)
64      *static_cast<c64h156_interface *>(this) = *intf;
2865
29   /* track */
30   UINT8 track_buffer[G64_BUFFER_SIZE];   /* track data buffer */
31   int track_len;                     /* track length */
32   int buffer_pos;                     /* current byte position within track buffer */
33   int bit_pos;                     /* current bit position within track buffer byte */
34   int bit_count;                     /* current data byte bit counter */
35   UINT16 data;                     /* data shift register */
36   UINT8 yb;                        /* GCR data byte to write */
66   // or initialize to defaults if none provided
67   else
68   {
69      memset(&m_out_atn_func, 0, sizeof(m_out_atn_func));
70      memset(&m_out_sync_func, 0, sizeof(m_out_sync_func));
71      memset(&m_out_byte_func, 0, sizeof(m_out_byte_func));
72   }
73}
3774
38   /* signals */
39   int ds;                           /* density select */
40   int soe;                        /* s? output enable */
41   int byte;                        /* byte ready */
42   int mode;                        /* mode (0 = write, 1 = read) */
43};
4475
45/***************************************************************************
46    INLINE FUNCTIONS
47***************************************************************************/
4876
49INLINE c64h156_t *get_safe_token(device_t *device)
77//**************************************************************************
78//  INLINE HELPERS
79//**************************************************************************
80
81//-------------------------------------------------
82//  set_atn_line -
83//-------------------------------------------------
84
85inline void c64h156_device::set_atn_line()
5086{
51   assert(device != NULL);
52   assert(device->type() == C64H156);
53   return (c64h156_t *)downcast<legacy_device_base *>(device)->token();
87   m_atn = !m_atni; // TODO m_atna
88
89   devcb_call_write_line(&m_out_atn_func, m_atn);
5490}
5591
56/***************************************************************************
57    IMPLEMENTATION
58***************************************************************************/
5992
60READ8_DEVICE_HANDLER( c64h156_yb_r )
93//-------------------------------------------------
94//  set_sync_line -
95//-------------------------------------------------
96
97inline void c64h156_device::set_sync_line(int state)
6198{
62   return 0;
99   m_sync = state;
100
101   devcb_call_write_line(&m_out_sync_func, m_sync);
63102}
64103
65WRITE8_DEVICE_HANDLER( c64h156_yb_w )
104
105//-------------------------------------------------
106//  set_byte_line -
107//-------------------------------------------------
108
109inline void c64h156_device::set_byte_line(int state)
66110{
111   m_byte = state;
112
113   devcb_call_write_line(&m_out_byte_func, BYTE);
67114}
68115
69READ_LINE_DEVICE_HANDLER( c64h156_sync_r )
116
117//-------------------------------------------------
118//  read_current_track -
119//-------------------------------------------------
120
121inline void c64h156_device::read_current_track()
70122{
71   return 0;
123   int track_length = G64_BUFFER_SIZE;
124
125   // read track data
126   floppy_drive_read_track_data_info_buffer(m_image, 0, m_track_buffer, &track_length);
127
128   // extract track length
129   m_track_len = floppy_drive_get_current_track_size(m_image, 0);
130
131   // set bit pointer to track start
132   m_buffer_pos = 0;
133   m_bit_pos = 7;
134   m_bit_count = 0;
72135}
73136
74READ_LINE_DEVICE_HANDLER( c64h156_byte_r )
137
138//-------------------------------------------------
139//  receive_bit -
140//-------------------------------------------------
141
142inline void c64h156_device::receive_bit()
75143{
76   return 0;
144   int byte = 0;
145
146   // shift in data from the read head
147   m_data <<= 1;
148   m_data |= BIT(m_track_buffer[m_buffer_pos], m_bit_pos);
149   m_bit_pos--;
150   m_bit_count++;
151
152   if (m_bit_pos < 0)
153   {
154      m_bit_pos = 7;
155      m_buffer_pos++;
156
157      if (m_buffer_pos >= m_track_len)
158      {
159         // loop to the start of the track
160         m_buffer_pos = 0;
161      }
162   }
163
164   set_sync_line(SYNC);
165
166   if (!m_sync)
167   {
168      // SYNC detected
169      m_bit_count = 0;
170   }
171
172   if (m_bit_count > 7)
173   {
174      // byte ready
175      m_bit_count = 0;
176      byte = 1;
177
178      m_yb = m_data & 0xff;
179
180      if (!m_yb)
181      {
182         // simulate weak bits with randomness
183         m_yb = m_machine.rand() & 0xff;
184      }
185
186      set_byte_line(byte);
187   }
77188}
78189
79void c64h156_stp_w(device_t *device, int stp)
190
191
192//**************************************************************************
193//  LIVE DEVICE
194//**************************************************************************
195
196//-------------------------------------------------
197//  c64h156_device - constructor
198//-------------------------------------------------
199
200c64h156_device::c64h156_device(running_machine &_machine, const c64h156_device_config &_config)
201    : device_t(_machine, _config),
202     m_image(*this->owner(), FLOPPY_0),
203     m_stp(-1),
204     m_mtr(0),
205     m_accl(1),
206     m_ds(-1),
207     m_soe(0),
208     m_byte(0),
209     m_oe(0),
210     m_sync(1),
211     m_atn(1),
212     m_atni(1),
213     m_atna(1),
214      m_config(_config)
80215{
81216}
82217
83WRITE_LINE_DEVICE_HANDLER( c64h156_stp1_w )
218
219//-------------------------------------------------
220//  device_start - device-specific startup
221//-------------------------------------------------
222
223void c64h156_device::device_start()
84224{
225   // resolve callbacks
226   devcb_resolve_write_line(&m_out_atn_func, &m_config.m_out_atn_func, this);
227   devcb_resolve_write_line(&m_out_sync_func, &m_config.m_out_sync_func, this);
228   devcb_resolve_write_line(&m_out_byte_func, &m_config.m_out_byte_func, this);
229
230   // allocate timers
231   m_bit_timer = timer_alloc();
232
233   // register for state saving
234   save_item(NAME(m_stp));
235   save_item(NAME(m_mtr));
236   save_item(NAME(m_track_len));
237   save_item(NAME(m_buffer_pos));
238   save_item(NAME(m_bit_pos));
239   save_item(NAME(m_bit_count));
240   save_item(NAME(m_data));
241   save_item(NAME(m_yb));
242   save_item(NAME(m_accl));
243   save_item(NAME(m_ds));
244   save_item(NAME(m_soe));
245   save_item(NAME(m_byte));
246   save_item(NAME(m_oe));
247   save_item(NAME(m_sync));
248   save_item(NAME(m_atn));
249   save_item(NAME(m_atni));
250   save_item(NAME(m_atna));
85251}
86252
87WRITE_LINE_DEVICE_HANDLER( c64h156_mtr_w )
253
254//-------------------------------------------------
255//  device_timer - handler timer events
256//-------------------------------------------------
257
258void c64h156_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
88259{
260   receive_bit();
89261}
90262
91void c64h156_ds_w(device_t *device, int data)
263
264//-------------------------------------------------
265//  yb_r -
266//-------------------------------------------------
267
268READ8_MEMBER( c64h156_device::yb_r )
92269{
270   set_byte_line(0); // TODO remove?
271
272   return m_yb;
93273}
94274
95WRITE_LINE_DEVICE_HANDLER( c64h156_ted_w )
275
276//-------------------------------------------------
277//  yb_w -
278//-------------------------------------------------
279
280WRITE8_MEMBER( c64h156_device::yb_w )
96281{
282   m_yb = data;
97283}
98284
99WRITE_LINE_DEVICE_HANDLER( c64h156_oe_w )
285
286//-------------------------------------------------
287//  test_w -
288//-------------------------------------------------
289
290WRITE_LINE_MEMBER( c64h156_device::test_w )
100291{
101292}
102293
103WRITE_LINE_DEVICE_HANDLER( c64h156_soe_w )
294
295//-------------------------------------------------
296//  accl_w -
297//-------------------------------------------------
298
299WRITE_LINE_MEMBER( c64h156_device::accl_w )
104300{
301   m_accl = state;
105302}
106303
107WRITE_LINE_DEVICE_HANDLER( c64h156_atni_w )
304
305//-------------------------------------------------
306//  sync_r -
307//-------------------------------------------------
308
309READ_LINE_MEMBER( c64h156_device::sync_r )
108310{
311   return m_sync;
109312}
110313
111WRITE_LINE_DEVICE_HANDLER( c64h156_atna_w )
314
315//-------------------------------------------------
316//  byte_r -
317//-------------------------------------------------
318
319READ_LINE_MEMBER( c64h156_device::byte_r )
112320{
321   return BYTE;
113322}
114323
115/*-------------------------------------------------
116    DEVICE_START( c64h156 )
117-------------------------------------------------*/
118324
119static DEVICE_START( c64h156 )
325//-------------------------------------------------
326//  stp_w -
327//-------------------------------------------------
328
329WRITE_LINE_MEMBER( c64h156_device::mtr_w )
120330{
121//  c64h156_t *c64h156 = get_safe_token(device);
331   if (m_mtr != state)
332   {
333      if (state)
334      {
335         // read track data
336         read_current_track();
337      }
122338
123   /* allocate data timer */
124//  c64h156->bit_timer = device->machine().scheduler().timer_alloc(FUNC(bit_tick), (void *)device);
339      floppy_mon_w(m_image, !state);
340      m_bit_timer->enable(state);
125341
126   /* register for state saving */
127//  device->save_item(NAME(c64h156->));
342      m_mtr = state;
343   }
128344}
129345
130/*-------------------------------------------------
131    DEVICE_GET_INFO( c64h156 )
132-------------------------------------------------*/
133346
134DEVICE_GET_INFO( c64h156 )
347//-------------------------------------------------
348//  oe_w -
349//-------------------------------------------------
350
351WRITE_LINE_MEMBER( c64h156_device::oe_w )
135352{
136   switch (state)
353   m_oe = state;
354}
355
356
357//-------------------------------------------------
358//  soe_w -
359//-------------------------------------------------
360
361WRITE_LINE_MEMBER( c64h156_device::soe_w )
362{
363   m_soe = state;
364}
365
366
367//-------------------------------------------------
368//  atn_r -
369//-------------------------------------------------
370
371READ_LINE_MEMBER( c64h156_device::atn_r )
372{
373   return m_atn;
374}
375
376
377//-------------------------------------------------
378//  atni_w -
379//-------------------------------------------------
380
381WRITE_LINE_MEMBER( c64h156_device::atni_w )
382{
383   m_atni = state;
384
385   set_atn_line();
386}
387
388
389//-------------------------------------------------
390//  atna_w -
391//-------------------------------------------------
392
393WRITE_LINE_MEMBER( c64h156_device::atna_w )
394{
395   m_atna = state;
396
397   set_atn_line();
398}
399
400
401//-------------------------------------------------
402//  stp_w -
403//-------------------------------------------------
404
405void c64h156_device::stp_w(int data)
406{
407   if (m_mtr && (m_stp != data))
137408   {
138      /* --- the following bits of info are returned as 64-bit signed integers --- */
139      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(c64h156_t);                        break;
409      int tracks = 0;
140410
141      /* --- the following bits of info are returned as pointers to data or functions --- */
142      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(c64h156);               break;
143      case DEVINFO_FCT_STOP:                     /* Nothing */                                    break;
144      case DEVINFO_FCT_RESET:                     /* Nothing */                                    break;
411      switch (m_stp)
412      {
413      case 0:   if (data == 1) tracks++; else if (data == 3) tracks--; break;
414      case 1:   if (data == 2) tracks++; else if (data == 0) tracks--; break;
415      case 2: if (data == 3) tracks++; else if (data == 1) tracks--; break;
416      case 3: if (data == 0) tracks++; else if (data == 2) tracks--; break;
417      }
145418
146      /* --- the following bits of info are returned as NULL-terminated strings --- */
147      case DEVINFO_STR_NAME:                     strcpy(info->s, "Commodore 64H156");                  break;
148      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "Commodore 1541");                     break;
149      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                              break;
150      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);                           break;
151      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright the MESS Team");             break;
419      if (tracks != 0)
420      {
421         // step read/write head
422         floppy_drive_seek(m_image, tracks);
423
424         // read new track data
425         read_current_track();
426      }
427
428      m_stp = data;
152429   }
153430}
154431
155DEFINE_LEGACY_DEVICE(C64H156, c64h156);
432
433//-------------------------------------------------
434//  ds_w - density select
435//-------------------------------------------------
436
437void c64h156_device::ds_w(int data)
438{
439   if (m_ds != data)
440   {
441      m_bit_timer->adjust(attotime::zero, 0, attotime::from_hz(C2040_BITRATE[data]/4));
442      m_ds = data;
443   }
444}
445
446
447//-------------------------------------------------
448//  on_disk_changed -
449//-------------------------------------------------
450
451void c64h156_device::on_disk_changed()
452{
453   read_current_track();
454}
src/mess/machine/64h156.h
r11238r11239
11/**********************************************************************
22
3    Commodore 64H165 Gate Array emulation
3    Commodore 64H156 Gate Array emulation
44
5    Used in 1541B/1541C/1541-II/1571
5    Used in 1541B/1541C/1541-II/1551/1571
66
77    Copyright MESS Team.
88    Visit http://mamedev.org for licensing and usage restrictions.
r11238r11239
5555
5656**********************************************************************/
5757
58#ifndef __64H156__
59#define __64H156__
58#pragma once
6059
61#include "devcb.h"
60#ifndef __C64H156__
61#define __C64H156__
6262
63/***************************************************************************
64    MACROS / CONSTANTS
65***************************************************************************/
63#define ADDRESS_MAP_MODERN
6664
67DECLARE_LEGACY_DEVICE(C64H156, c64h156);
65#include "emu.h"
66#include "imagedev/flopdrv.h"
67#include "formats/d64_dsk.h"
68#include "formats/g64_dsk.h"
6869
69#define MCFG_64H156_ADD(_tag, _clock, _intrf) \
70
71
72//**************************************************************************
73//  INTERFACE CONFIGURATION MACROS
74//**************************************************************************
75
76#define MCFG_64H156_ADD(_tag, _clock, _config) \
7077   MCFG_DEVICE_ADD(_tag, C64H156, _clock) \
71   MCFG_DEVICE_CONFIG(_intrf)
78   MCFG_DEVICE_CONFIG(_config)
7279
73#define C64H156_INTERFACE(name) \
74   const c64h156_interface (name)=
80#define C64H156_INTERFACE(_name) \
81   const c64h156_interface (_name) =
7582
76/***************************************************************************
77    TYPE DEFINITIONS
78***************************************************************************/
7983
80typedef struct _c64h156_interface c64h156_interface;
81struct _c64h156_interface
84
85//**************************************************************************
86//  TYPE DEFINITIONS
87//**************************************************************************
88
89// ======================> c64h156_interface
90
91struct c64h156_interface
8292{
83   devcb_write_line   out_atn_func;
84   devcb_write_line   out_sync_func;
85   devcb_write_line   out_byte_func;
93   devcb_write_line   m_out_atn_func;
94   devcb_write_line   m_out_sync_func;
95   devcb_write_line   m_out_byte_func;
8696};
8797
88/***************************************************************************
89    PROTOTYPES
90***************************************************************************/
9198
92/* parallel data */
93READ8_DEVICE_HANDLER( c64h156_yb_r );
94WRITE8_DEVICE_HANDLER( c64h156_yb_w );
99// ======================> c64h156_device_config
95100
96/* sync mark detected */
97READ_LINE_DEVICE_HANDLER( c64h156_sync_r );
101class c64h156_device_config :   public device_config,
102                        public c64h156_interface
103{
104    friend class c64h156_device;
98105
99/* byte ready */
100READ_LINE_DEVICE_HANDLER( c64h156_byte_r );
106    // construction/destruction
107    c64h156_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
101108
102/* stepper driver */
103void c64h156_stp_w(device_t *device, int data);
109public:
110    // allocators
111    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
112    virtual device_t *alloc_device(running_machine &machine) const;
104113
105/* stepper motor */
106WRITE_LINE_DEVICE_HANDLER( c64h156_mtr_w );
114protected:
115    // device_config overrides
116    virtual void device_config_complete();
117};
107118
108/* density select */
109void c64h156_ds_w(device_t *device, int data);
110119
111/* */
112WRITE_LINE_DEVICE_HANDLER( c64h156_ted_w );
120// ======================> c64h156_device
113121
114/* mode select */
115WRITE_LINE_DEVICE_HANDLER( c64h156_oe_w );
122class c64h156_device :  public device_t
123{
124    friend class c64h156_device_config;
116125
117/* byte input enable */
118WRITE_LINE_DEVICE_HANDLER( c64h156_soe_w );
126    // construction/destruction
127    c64h156_device(running_machine &_machine, const c64h156_device_config &_config);
119128
120/* attention input */
121WRITE_LINE_DEVICE_HANDLER( c64h156_atni_w );
129public:
130   DECLARE_READ8_MEMBER( yb_r );
131   DECLARE_WRITE8_MEMBER( yb_w );
132   DECLARE_WRITE_LINE_MEMBER( test_w );
133   DECLARE_WRITE_LINE_MEMBER( accl_w );
134   DECLARE_READ_LINE_MEMBER( sync_r );
135   DECLARE_READ_LINE_MEMBER( byte_r );
136   DECLARE_WRITE_LINE_MEMBER( mtr_w );
137   DECLARE_WRITE_LINE_MEMBER( oe_w );
138   DECLARE_WRITE_LINE_MEMBER( soe_w );
139   DECLARE_READ_LINE_MEMBER( atn_r );
140   DECLARE_WRITE_LINE_MEMBER( atni_w );
141   DECLARE_WRITE_LINE_MEMBER( atna_w );
122142
123/* attention acknowledge */
124WRITE_LINE_DEVICE_HANDLER( c64h156_atna_w );
143   void stp_w(int data);
144   void ds_w(int data);
125145
146   void on_disk_changed();
147
148protected:
149    // device-level overrides
150    virtual void device_start();
151   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
152
153   inline void set_atn_line();
154   inline void set_sync_line(int state);
155   inline void set_byte_line(int state);
156   inline void read_current_track();
157   inline void spindle_motor(int mtr);
158   inline void step_motor(int mtr, int stp);
159   inline void receive_bit();
160
161private:
162   devcb_resolved_write_line   m_out_atn_func;
163   devcb_resolved_write_line   m_out_sync_func;
164   devcb_resolved_write_line   m_out_byte_func;
165
166   required_device<device_t> m_image;
167
168   // motors
169   int m_stp;                        // stepper motor phase
170   int m_mtr;                        // spindle motor on
171
172   // track
173   UINT8 m_track_buffer[G64_BUFFER_SIZE];   // track data buffer
174   size_t m_track_len;                  // track length
175   offs_t m_buffer_pos;               // current byte position within track buffer
176   int m_bit_pos;                     // current bit position within track buffer byte
177   int m_bit_count;                  // current data byte bit counter
178   UINT16 m_data;                     // data shift register
179   UINT8 m_yb;                        // GCR data byte
180
181   // signals
182   int m_accl;                        // 1/2 MHz select
183   int m_ds;                        // density select
184   int m_soe;                        // s? output enable
185   int m_byte;                        // byte ready
186   int m_oe;                        // output enable (0 = write, 1 = read)
187   int m_sync;                        // sync character detected
188
189   // IEC
190   int m_atn;                        // attention
191   int m_atni;                        // attention input
192   int m_atna;                        // attention acknowledge
193
194   // timers
195   emu_timer *m_bit_timer;
196
197    const c64h156_device_config &m_config;
198};
199
200
201
202// device type definition
203extern const device_type C64H156;
204
205
206
126207#endif
src/mess/machine/c1551.c
r11238r11239
2929#define M6510T_TAG      "u2"
3030#define M6523_0_TAG      "u3"
3131#define M6523_1_TAG      "ci_u2"
32#define C64H156_TAG      "u6"
3233
33#define SYNC \
34   !(m_mode && ((m_data & G64_SYNC_MARK) == G64_SYNC_MARK))
35
3634enum
3735{
3836   LED_POWER = 0,
r11238r11239
112110
113111        bit     description
114112
115        P0      STP0A
116        P1      STP0B
117        P2      MTR0
118        P3      ACT0
113        P0     
114        P1     
115        P2     
116        P3     
119117        P4      WPS
120        P5      DS0
121        P6      DS1
118        P5     
119        P6     
122120        P7      BYTE LTCHED
123121
124122   */   
r11238r11239
126124   UINT8 data = 0;
127125
128126   // write protect sense
129   data |= !floppy_wpt_r(m_image) << 4;
127   data |= (!floppy_wpt_r(m_image)) << 4;
130128
131129   // byte latched
132   data |= (m_soe & m_byte) << 7;
130   data |= m_ga->atn_r() << 7;
133131
134132   return data;
135133}
r11238r11239
145143        P1      STP0B
146144        P2      MTR0
147145        P3      ACT0
148        P4      WPS
146        P4     
149147        P5      DS0
150148        P6      DS1
151        P7      BYTE LTCHED
149        P7     
152150
153151   */
154152
155153   // spindle motor
156   int mtr = BIT(data, 2);
157   spindle_motor(mtr);
154   m_ga->mtr_w(BIT(data, 2));
158155
159156   // stepper motor
160   int stp = data & 0x03;
161   step_motor(mtr, stp);
157   m_ga->stp_w(data & 0x03);
162158
163159   // activity LED
164   output_set_led_value(LED_ACT, BIT(data, 6));
160   output_set_led_value(LED_ACT, BIT(data, 3));
165161
166162   // density select
167   int ds = (data >> 5) & 0x03;
168
169   if (m_ds != ds)
170   {
171      m_bit_timer->adjust(attotime::zero, 0, attotime::from_hz(C2040_BITRATE[ds]/4));
172      m_ds = ds;
173   }
163   m_ga->ds_w((data >> 5) & 0x03);
174164}
175165
176166
r11238r11239
229219}
230220
231221
232READ8_MEMBER( c1551_device::yb_r )
233{
234   /*
235
236        bit     description
237
238        PB0     YB0
239        PB1     YB1
240        PB2     YB2
241        PB3     YB3
242        PB4     YB4
243        PB5     YB5
244        PB6     YB6
245        PB7     YB7
246
247   */
248
249   m_byte = 0;
250
251   return m_yb;
252}
253
254
255WRITE8_MEMBER( c1551_device::yb_w )
256{
257   /*
258
259        bit     description
260
261        PB0     YB0
262        PB1     YB1
263        PB2     YB2
264        PB3     YB3
265        PB4     YB4
266        PB5     YB5
267        PB6     YB6
268        PB7     YB7
269
270   */
271
272   m_yb = data;
273}
274
275
276222READ8_MEMBER( c1551_device::tpi0_pc_r )
277223{
278224   /*
r11238r11239
296242   data |= m_config.m_address << 5;
297243
298244   // SYNC detect line
299   data |= SYNC << 6;
245   data |= m_ga->sync_r() << 6;
300246
301247   // TCBM data valid
302248   data |= m_dav << 7;
r11238r11239
331277   m_ack = BIT(data, 3);
332278
333279   // read/write mode
334   m_mode = BIT(data, 4);
280   m_ga->oe_w(BIT(data, 4));
335281}
336282
337283
r11238r11239
340286   DEVCB_NULL,
341287   DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, tcbm_data_r),
342288   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),
289   DEVCB_DEVICE_MEMBER(C64H156_TAG, c64h156_device, yb_r),
290   DEVCB_DEVICE_MEMBER(C64H156_TAG, c64h156_device, yb_w),
345291   DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, tpi0_pc_r),
346292   DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, tpi0_pc_w),
347293   DEVCB_NULL,
r11238r11239
386332        PC3
387333        PC4
388334        PC5
389        PC6     TCBM DAV
335        PC6     
390336        PC7     TCBM ACK
391337
392338   */
r11238r11239
413359        PC4
414360        PC5
415361        PC6     TCBM DAV
416        PC7     TCBM ACK
362        PC7     
417363
418364   */
419365
r11238r11239
475421
476422
477423//-------------------------------------------------
424//  C64H156_INTERFACE( ga_intf )
425//-------------------------------------------------
426
427static C64H156_INTERFACE( ga_intf )
428{
429   DEVCB_NULL,
430   DEVCB_NULL,
431   DEVCB_LINE_MEMBER(c64h156_device, atni_w)
432};
433
434
435//-------------------------------------------------
478436//  MACHINE_DRIVER( c1551 )
479437//-------------------------------------------------
480438
r11238r11239
487445   MCFG_TPI6525_ADD(M6523_1_TAG, tpi1_intf)
488446
489447   MCFG_FLOPPY_DRIVE_ADD(FLOPPY_0, c1551_floppy_config)
448   MCFG_64H156_ADD(C64H156_TAG, XTAL_16MHz, ga_intf)
490449MACHINE_CONFIG_END
491450
492451
r11238r11239
503462
504463
505464//**************************************************************************
506//  INLINE HELPERS
507//**************************************************************************
508
509//-------------------------------------------------
510//  read_current_track -
511//-------------------------------------------------
512
513inline void c1551_device::read_current_track()
514{
515   m_track_len = G64_BUFFER_SIZE;
516   m_buffer_pos = 0;
517   m_bit_pos = 7;
518   m_bit_count = 0;
519
520   // read track data
521   floppy_drive_read_track_data_info_buffer(m_image, 0, m_track_buffer, &m_track_len);
522
523   // extract track length
524   m_track_len = floppy_drive_get_current_track_size(m_image, 0);
525}
526
527
528//-------------------------------------------------
529//  on_disk_change -
530//-------------------------------------------------
531
532void c1551_device::on_disk_change(device_image_interface &image)
533{
534    c1551_device *c1551 = static_cast<c1551_device *>(image.device().owner());
535
536   c1551->read_current_track();
537}
538
539
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   }
559}
560
561
562//-------------------------------------------------
563//  step_motor -
564//-------------------------------------------------
565
566inline void c1551_device::step_motor(int mtr, int stp)
567{
568   if (mtr && (m_stp != stp))
569   {
570      int tracks = 0;
571
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      }
579
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   }
591}
592
593
594//-------------------------------------------------
595//  receive_bit -
596//-------------------------------------------------
597
598inline void c1551_device::receive_bit()
599{
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)
609   {
610      m_bit_pos = 7;
611      m_buffer_pos++;
612
613      if (m_buffer_pos >= m_track_len)
614      {
615         // loop to the start of the track
616         m_buffer_pos = 0;
617      }
618   }
619
620   if (!SYNC)
621   {
622      // SYNC detected
623      m_bit_count = 0;
624   }
625
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;
641   }
642}
643
644
645//**************************************************************************
646465//  LIVE DEVICE
647466//**************************************************************************
648467
r11238r11239
655474     m_maincpu(*this, M6510T_TAG),
656475     m_tpi0(*this, M6523_0_TAG),
657476     m_tpi1(*this, M6523_1_TAG),
477     m_ga(*this, C64H156_TAG),
658478     m_image(*this, FLOPPY_0),
659479     m_tcbm_data(0),
660480     m_status(0),
661481     m_dav(0),
662482     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),
669483      m_config(_config)
670484{
671485}
r11238r11239
677491
678492void c1551_device::device_start()
679493{
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);
494   // allocate timers
495   m_irq_timer = timer_alloc();
687496   m_irq_timer->adjust(attotime::from_hz(120), 0, attotime::from_hz(120));
688497
689498   // map TPI1 to host CPU memory space
r11238r11239
692501
693502   program->install_legacy_readwrite_handler(*m_tpi1, start_address, start_address + 7, FUNC(tpi6525_r), FUNC(tpi6525_w));
694503
504   // install image callbacks
505   floppy_install_unload_proc(m_image, c1551_device::on_disk_change);
506   floppy_install_load_proc(m_image, c1551_device::on_disk_change);
507
695508   // register for state saving
696509   save_item(NAME(m_tcbm_data));
697510   save_item(NAME(m_status));
698511   save_item(NAME(m_dav));
699512   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));
712513}
713514
714515
r11238r11239
718519
719520void c1551_device::device_reset()
720521{
721   m_soe = 1;
522   // initialize gate array
523   m_ga->test_w(1);
524   m_ga->soe_w(1);
525   m_ga->accl_w(1);
526   m_ga->atna_w(1);
722527}
723528
724529
r11238r11239
728533
729534void c1551_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
730535{
731   switch (id)
732   {
733   case TIMER_BIT:
734      receive_bit();
735      break;
536   m_maincpu->set_input_line(M6502_IRQ_LINE, ASSERT_LINE);
537   m_maincpu->set_input_line(M6502_IRQ_LINE, CLEAR_LINE);
538}
736539
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   }
540
541//-------------------------------------------------
542//  on_disk_change -
543//-------------------------------------------------
544
545void c1551_device::on_disk_change(device_image_interface &image)
546{
547    c1551_device *c1551 = static_cast<c1551_device *>(image.device().owner());
548
549   c1551->m_ga->on_disk_changed();
742550}
src/mess/machine/c1551.h
r11238r11239
1919#include "imagedev/flopdrv.h"
2020#include "formats/d64_dsk.h"
2121#include "formats/g64_dsk.h"
22#include "machine/64h156.h"
2223#include "machine/6525tpi.h"
2324
2425
r11238r11239
8182   // not really public
8283   static void on_disk_change(device_image_interface &image);
8384
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 );
85   DECLARE_READ8_MEMBER( port_r );
86   DECLARE_WRITE8_MEMBER( port_w );
87   DECLARE_READ8_MEMBER( tcbm_data_r );
88   DECLARE_WRITE8_MEMBER( tcbm_data_w );
89   DECLARE_READ8_MEMBER( yb_r );
90   DECLARE_WRITE8_MEMBER( yb_w );
91   DECLARE_READ8_MEMBER( tpi0_pc_r );
92   DECLARE_WRITE8_MEMBER( tpi0_pc_w );
93   DECLARE_READ8_MEMBER( tpi1_pa_r );
94   DECLARE_WRITE8_MEMBER( tpi1_pa_w );
95   DECLARE_READ8_MEMBER( tpi1_pb_r );
96   DECLARE_READ8_MEMBER( tpi1_pc_r );
97   DECLARE_WRITE8_MEMBER( tpi1_pc_w );
9798
9899protected:
99100    // device-level overrides
r11238r11239
101102   virtual void device_reset();
102103   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
103104
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
109105private:
110   static const device_timer_id TIMER_BIT = 0;
111   static const device_timer_id TIMER_IRQ = 1;
112
113106   required_device<cpu_device> m_maincpu;
114107   required_device<device_t> m_tpi0;
115108   required_device<device_t> m_tpi1;
109   required_device<c64h156_device> m_ga;
116110   required_device<device_t> m_image;
117111
118112   // TCBM bus
r11238r11239
121115   int m_dav;                        // data valid
122116   int m_ack;                        // acknowledge
123117
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
143118   // timers
144   emu_timer *m_bit_timer;
145119   emu_timer *m_irq_timer;
146120
147121    const c1551_device_config &m_config;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team