Previous 15994 Revisions Next

r6620 Sunday 13th December, 2009 at 19:34:01 UTC by Curt Coder
[C1541] WIP, loading $ returns file not found.
[src/mess/drivers]c64.c
[src/mess/formats]g64_dsk.c g64_dsk.h
[src/mess/machine]c1541.c c64.c cbmserial.c cbmserial.h

src/mess/machine/cbmserial.c
r6619r6620
199199
200200#define LOG 0
201201
202enum
203{
204   SRQ = 0,
205   ATN,
206   CLK,
207   DATA,
208   RESET,
209   SIGNAL_COUNT
210};
211
212static const char *const SIGNAL_NAME[] = { "SRQ", "ATN", "CLK", "DATA", "RESET" };
213
202214/***************************************************************************
203215    TYPE DEFINITIONS
204216***************************************************************************/
r6619r6620
209221   cbmserial_daisy_state      *next;         /* next device */
210222   const device_config         *device;      /* associated device */
211223
212   devcb_resolved_write_line   out_srq_func;
213   devcb_resolved_write_line   out_atn_func;
214   devcb_resolved_write_line   out_clk_func;
215   devcb_resolved_write_line   out_data_func;
216   devcb_resolved_write_line   out_reset_func;
224   int line[SIGNAL_COUNT];            /* serial signal states */
225
226   cbmserial_line            out_line_func[SIGNAL_COUNT];
217227};
218228
219229typedef struct _cbmserial_t cbmserial_t;
220230struct _cbmserial_t
221231{
222232   cbmserial_daisy_state *daisy_state;
223
224   int srq;         /* serial service request */
225   int atn;         /* attention */
226   int clk;         /* clock */
227   int data;         /* data */
228   int reset;         /* reset */
229233};
230234
231235/***************************************************************************
r6619r6620
247251   return (const cbmserial_daisy_chain *) device->static_config;
248252}
249253
250/***************************************************************************
251    IMPLEMENTATION
252***************************************************************************/
253
254WRITE_LINE_DEVICE_HANDLER( cbmserial_srq_w )
254INLINE int get_signal(const device_config *device, int line)
255255{
256256   cbmserial_t *cbmserial = get_safe_token(device);
257257   cbmserial_daisy_state *daisy = cbmserial->daisy_state;
258   int state = 1;
258259
259   cbmserial->srq = state;
260
261260   for ( ; daisy != NULL; daisy = daisy->next)
262261   {
263      devcb_call_write_line(&daisy->out_srq_func, state);
262      if (!daisy->line[line])
263      {
264         state = 0;
265         break;
266      }
264267   }
265}
266268
267READ_LINE_DEVICE_HANDLER( cbmserial_srq_r )
268{
269   cbmserial_t *cbmserial = get_safe_token(device);
270
271   return cbmserial->srq;
269   return state;
272270}
273271
274WRITE_LINE_DEVICE_HANDLER( cbmserial_atn_w )
272INLINE void set_signal(const device_config *serial_bus_device, const device_config *calling_device, int line, int state)
275273{
276   cbmserial_t *cbmserial = get_safe_token(device);
274   cbmserial_t *cbmserial = get_safe_token(serial_bus_device);
277275   cbmserial_daisy_state *daisy = cbmserial->daisy_state;
276   int data = 1;
278277
279   cbmserial->atn = state;
278   for ( ; daisy != NULL; daisy = daisy->next)
279   {
280      if (!strcmp(daisy->device->tag, calling_device->tag))
281      {
282         if (daisy->line[line] != state)
283         {
284            logerror("CBM serial bus device '%s' %s %u\n", calling_device->tag, SIGNAL_NAME[line], state);
285            daisy->line[line] = state;
286         }
287         break;
288      }
289   }
280290
291   data = get_signal(serial_bus_device, line);
292   daisy = cbmserial->daisy_state;
293
281294   for ( ; daisy != NULL; daisy = daisy->next)
282295   {
283      devcb_call_write_line(&daisy->out_atn_func, state);
296      if (daisy->out_line_func[line]) (daisy->out_line_func[line])(daisy->device, data);
284297   }
298
299   logerror("SRQ %u ATN %u CLK %u DATA %u RESET %u\n", get_signal(serial_bus_device, SRQ),get_signal(serial_bus_device, ATN),get_signal(serial_bus_device, CLK),get_signal(serial_bus_device, DATA),get_signal(serial_bus_device, RESET));
285300}
286301
287READ_LINE_DEVICE_HANDLER( cbmserial_atn_r )
302/***************************************************************************
303    IMPLEMENTATION
304***************************************************************************/
305
306void cbmserial_srq_w(const device_config *serial_bus_device, const device_config *calling_device, int state)
288307{
289   cbmserial_t *cbmserial = get_safe_token(device);
308   set_signal(serial_bus_device, calling_device, SRQ, state);
309}
290310
291   return cbmserial->atn;
311READ_LINE_DEVICE_HANDLER( cbmserial_srq_r )
312{
313   return get_signal(device, SRQ);
292314}
293315
294WRITE_LINE_DEVICE_HANDLER( cbmserial_clk_w )
316void cbmserial_atn_w(const device_config *serial_bus_device, const device_config *calling_device, int state)
295317{
296   cbmserial_t *cbmserial = get_safe_token(device);
297   cbmserial_daisy_state *daisy = cbmserial->daisy_state;
318   set_signal(serial_bus_device, calling_device, ATN, state);
319}
298320
299   cbmserial->clk = state;
321READ_LINE_DEVICE_HANDLER( cbmserial_atn_r )
322{
323   return get_signal(device, ATN);
324}
300325
301   for ( ; daisy != NULL; daisy = daisy->next)
302   {
303      devcb_call_write_line(&daisy->out_clk_func, state);
304   }
326void cbmserial_clk_w(const device_config *serial_bus_device, const device_config *calling_device, int state)
327{
328   set_signal(serial_bus_device, calling_device, CLK, state);
305329}
306330
307331READ_LINE_DEVICE_HANDLER( cbmserial_clk_r )
308332{
309   cbmserial_t *cbmserial = get_safe_token(device);
310
311   return cbmserial->clk;
333   return get_signal(device, CLK);
312334}
313335
314WRITE_LINE_DEVICE_HANDLER( cbmserial_data_w )
336void cbmserial_data_w(const device_config *serial_bus_device, const device_config *calling_device, int state)
315337{
316   cbmserial_t *cbmserial = get_safe_token(device);
317   cbmserial_daisy_state *daisy = cbmserial->daisy_state;
318
319   cbmserial->data = state;
320
321   for ( ; daisy != NULL; daisy = daisy->next)
322   {
323      devcb_call_write_line(&daisy->out_data_func, state);
324   }
338   set_signal(serial_bus_device, calling_device, DATA, state);
325339}
326340
327341READ_LINE_DEVICE_HANDLER( cbmserial_data_r )
328342{
329   cbmserial_t *cbmserial = get_safe_token(device);
330
331   return cbmserial->data;
343   return get_signal(device, DATA);
332344}
333345
334WRITE_LINE_DEVICE_HANDLER( cbmserial_reset_w )
346void cbmserial_reset_w(const device_config *serial_bus_device, const device_config *calling_device, int state)
335347{
336   cbmserial_t *cbmserial = get_safe_token(device);
337   cbmserial_daisy_state *daisy = cbmserial->daisy_state;
338
339   cbmserial->reset = state;
340
341   for ( ; daisy != NULL; daisy = daisy->next)
342   {
343      devcb_call_write_line(&daisy->out_reset_func, state);
344   }
348   set_signal(serial_bus_device, calling_device, RESET, state);
345349}
346350
347351READ_LINE_DEVICE_HANDLER( cbmserial_reset_r )
348352{
349   cbmserial_t *cbmserial = get_safe_token(device);
350
351   return cbmserial->reset;
353   return get_signal(device, RESET);
352354}
353355
354356/*-------------------------------------------------
r6619r6620
357359
358360static DEVICE_START( cbmserial )
359361{
360   //cbmserial_t *cbmserial = get_safe_token(device);
362   cbmserial_t *cbmserial = get_safe_token(device);
361363   const cbmserial_daisy_chain *daisy = get_interface(device);
364   int i;
362365
363366   astring *tempstring = astring_alloc();
364367   cbmserial_daisy_state *head = NULL;
r6619r6620
378381         fatalerror("Unable to locate device '%s'", daisy->tag);
379382      }
380383
381      devcb_resolve_write_line(&((*tailptr)->out_srq_func), (const devcb_write_line *)device_get_info_fct((*tailptr)->device, DEVINFO_FCT_CBM_SERIAL_SRQ), (*tailptr)->device);
382      devcb_resolve_write_line(&((*tailptr)->out_atn_func), (const devcb_write_line *)device_get_info_fct((*tailptr)->device, DEVINFO_FCT_CBM_SERIAL_ATN), (*tailptr)->device);
383      devcb_resolve_write_line(&((*tailptr)->out_clk_func), (const devcb_write_line *)device_get_info_fct((*tailptr)->device, DEVINFO_FCT_CBM_SERIAL_CLK), (*tailptr)->device);
384      devcb_resolve_write_line(&((*tailptr)->out_data_func), (const devcb_write_line *)device_get_info_fct((*tailptr)->device, DEVINFO_FCT_CBM_SERIAL_DATA), (*tailptr)->device);
385      devcb_resolve_write_line(&((*tailptr)->out_reset_func), (const devcb_write_line *)device_get_info_fct((*tailptr)->device, DEVINFO_FCT_CBM_SERIAL_RESET), (*tailptr)->device);
384      for (i = SRQ; i < SIGNAL_COUNT; i++)
385      {
386         (*tailptr)->line[i] = 1;
387      }
386388
389      (*tailptr)->out_line_func[SRQ] = (cbmserial_line)device_get_info_fct((*tailptr)->device, DEVINFO_FCT_CBM_SERIAL_SRQ);
390      (*tailptr)->out_line_func[ATN] = (cbmserial_line)device_get_info_fct((*tailptr)->device, DEVINFO_FCT_CBM_SERIAL_ATN);
391      (*tailptr)->out_line_func[CLK] = (cbmserial_line)device_get_info_fct((*tailptr)->device, DEVINFO_FCT_CBM_SERIAL_CLK);
392      (*tailptr)->out_line_func[DATA] = (cbmserial_line)device_get_info_fct((*tailptr)->device, DEVINFO_FCT_CBM_SERIAL_DATA);
393      (*tailptr)->out_line_func[RESET] = (cbmserial_line)device_get_info_fct((*tailptr)->device, DEVINFO_FCT_CBM_SERIAL_RESET);
394
387395      tailptr = &(*tailptr)->next;
388396   }
389397
398   cbmserial->daisy_state = head;
399
390400   astring_free(tempstring);
391401
392402   /* register for state saving */
src/mess/machine/cbmserial.h
r6619r6620
3434   DEVINFO_FCT_CBM_SERIAL_RESET
3535};
3636
37#define CBMSERIAL_SRQ_NAME(name)   cbmserial_srq_##name
38#define CBMSERIAL_SRQ(name)         void CBMSERIAL_SRQ_NAME(name)(const device_config *device, int state)
39
40#define CBMSERIAL_ATN_NAME(name)   cbmserial_atn_##name
41#define CBMSERIAL_ATN(name)         void CBMSERIAL_ATN_NAME(name)(const device_config *device, int state)
42
43#define CBMSERIAL_CLK_NAME(name)   cbmserial_clk_##name
44#define CBMSERIAL_CLK(name)         void CBMSERIAL_CLK_NAME(name)(const device_config *device, int state)
45
46#define CBMSERIAL_DATA_NAME(name)   cbmserial_data_##name
47#define CBMSERIAL_DATA(name)      void CBMSERIAL_DATA_NAME(name)(const device_config *device, int state)
48
49#define CBMSERIAL_RESET_NAME(name)   cbmserial_reset_##name
50#define CBMSERIAL_RESET(name)      void CBMSERIAL_RESET_NAME(name)(const device_config *device, int state)
51
3752/***************************************************************************
3853    TYPE DEFINITIONS
3954***************************************************************************/
r6619r6620
4459   const char *tag;   /* device tag */
4560};
4661
62typedef void (*cbmserial_line)(const device_config *device, int state);
63
64
4765/***************************************************************************
4866    PROTOTYPES
4967***************************************************************************/
r6619r6620
5270DEVICE_GET_INFO( cbmserial );
5371
5472/* serial service request */
55WRITE_LINE_DEVICE_HANDLER( cbmserial_srq_w );
73void cbmserial_srq_w(const device_config *serial_bus_device, const device_config *calling_device, int state);
5674READ_LINE_DEVICE_HANDLER( cbmserial_srq_r );
5775
5876/* attention */
59WRITE_LINE_DEVICE_HANDLER( cbmserial_atn_w );
77void cbmserial_atn_w(const device_config *serial_bus_device, const device_config *calling_device, int state);
6078READ_LINE_DEVICE_HANDLER( cbmserial_atn_r );
6179
6280/* clock */
63WRITE_LINE_DEVICE_HANDLER( cbmserial_clk_w );
81void cbmserial_clk_w(const device_config *serial_bus_device, const device_config *calling_device, int state);
6482READ_LINE_DEVICE_HANDLER( cbmserial_clk_r );
6583
6684/* data */
67WRITE_LINE_DEVICE_HANDLER( cbmserial_data_w );
85void cbmserial_data_w(const device_config *serial_bus_device, const device_config *calling_device, int state);
6886READ_LINE_DEVICE_HANDLER( cbmserial_data_r );
6987
7088/* reset */
71WRITE_LINE_DEVICE_HANDLER( cbmserial_reset_w );
89void cbmserial_reset_w(const device_config *serial_bus_device, const device_config *calling_device, int state);
7290READ_LINE_DEVICE_HANDLER( cbmserial_reset_r );
7391
7492#endif
src/mess/machine/c1541.c
r6619r6620
118118
119119   TODO:
120120
121   - mechanical track 0 sensing
122   - get floppy image to driver state
123   - allocate track buffer
121   - get track length from image
122   - attention acknowledge
123   - mechanical track 0 sensing?
124124   - activity led
125   - read G64
126125   - write G64
127126   - D64 to G64 conversion
128127   - accurate timing
r6619r6620
148147#define M6522_1_TAG      "ucd4"
149148#define TIMER_BIT_TAG   "ue7"
150149
150#define FLOPPY_TAG      "c1541_floppy"
151
151152static const double C1541_BITRATE[4] =
152153{
153154   XTAL_16MHz/13.0, XTAL_16MHz/14.0, XTAL_16MHz/15.0, XTAL_16MHz/16.0
r6619r6620
164165{
165166   /* abstractions */
166167   int address;                  /* serial bus address - 8 */
167   UINT8 *track_buffer;            /* track data buffer */
168   UINT8 track_buffer[8192];         /* track data buffer */
169   int track_len;                  /* track length */
168170   int track;                     /* current position of the actuator (half track) */
169171   int buffer_pos;                  /* current byte position within track buffer */
170172   int bit_pos;                  /* current bit position within track buffer byte */
r6619r6620
175177   int atna;                     /* attention acknowledge */
176178   int ds;                        /* data speed */
177179   int stp;                     /* stepper motor phase */
178   int soe;                     /* s? output enable */
180   int soe : 1;                  /* s? output enable */
179181   int mode;                     /* mode (0 = write, 1 = read) */
180182
183   /* serial bus */
184   int data_out;
185
181186   /* devices */
182187   const device_config *cpu;
183188   const device_config *via0;
r6619r6620
218223
219224static TIMER_CALLBACK( bit_tick )
220225{
221   const device_config *device = (device_config *)(FPTR) param;
226   const device_config *device = (device_config *)ptr;
222227   c1541_t *c1541 = get_safe_token(device);
223228   int byte = 0;
224229
r6619r6620
226231   {
227232      c1541->yb = c1541->track_buffer[c1541->buffer_pos];
228233      c1541->buffer_pos++;
234
235      if (c1541->buffer_pos > c1541->track_len)
236      {
237         c1541->buffer_pos = 0;
238      }
239
229240      c1541->bit_pos = 0;
230241
231242      byte = 1;
r6619r6620
237248
238249   if (c1541->byte != byte)
239250   {
240      int byte_ready = !(c1541->soe && byte);
251      int byte_ready = !(byte && c1541->soe);
241252
242253      cpu_set_input_line(c1541->cpu, M6502_SET_OVERFLOW, byte_ready);
243254      via_ca1_w(c1541->via1, 0, byte_ready);
r6619r6620
250261    c1541_atn_w - serial bus attention
251262-------------------------------------------------*/
252263
253static WRITE_LINE_DEVICE_HANDLER( c1541_atn_w )
264static void cbmserial_atn_c1541(const device_config *device, int state)
265//static CBM_SERIAL_ATN( c1541 )
254266{
255267   c1541_t *c1541 = get_safe_token(device);
268   int serial_data = !c1541->data_out && !(c1541->atna ^ !state);
256269
257   via_ca1_w(c1541->via0, 0, state);
270   via_ca1_w(c1541->via0, 0, !state);
271
272   cbmserial_data_w(c1541->serial_bus, device, serial_data);
258273}
259274
260275/*-------------------------------------------------
261276    c1541_reset_w - serial bus reset
262277-------------------------------------------------*/
263278
264static WRITE_LINE_DEVICE_HANDLER( c1541_reset_w )
279static void cbmserial_reset_c1541(const device_config *device, int state)
280//static CBM_SERIAL_RESET( c1541 )
265281{
266282   c1541_t *c1541 = get_safe_token(device);
267283
268   if (state)
284   if (!state)
269285   {
270286      device_reset(c1541->cpu);
271287      device_reset(c1541->via0);
r6619r6620
281297   AM_RANGE(0x0000, 0x07ff) AM_RAM
282298   AM_RANGE(0x1800, 0x180f) AM_DEVREADWRITE(M6522_0_TAG, via_r, via_w)
283299   AM_RANGE(0x1c00, 0x1c0f) AM_DEVREADWRITE(M6522_1_TAG, via_r, via_w)
284   AM_RANGE(0xc000, 0xffff) AM_ROM AM_REGION("c1541", 0)
300   AM_RANGE(0xc000, 0xffff) AM_ROM AM_REGION("c1541", 0xc000)
285301ADDRESS_MAP_END
286302
287303/*-------------------------------------------------
288304    via6522_interface c1541_via0_intf
289305-------------------------------------------------*/
290306
291static READ8_DEVICE_HANDLER( via0_pa_r )
307static READ8_DEVICE_HANDLER( via0_pb_r )
292308{
293309   /*
294310
295311      bit      description
296312
313      PB0      DATA IN
314      PB1      DATA OUT
315      PB2      CLK IN
316      PB3      CLK OUT
317      PB4      ATNA
318      PB5      J1
319      PB6      J2
320      PB7      ATN IN
321
322   */
323
324   c1541_t *c1541 = get_safe_token(device->owner);
325   UINT8 data = 0;
326
327   /* data in */
328   data = !cbmserial_data_r(c1541->serial_bus);
329
330   /* clock in */
331   data |= !cbmserial_clk_r(c1541->serial_bus) << 2;
332
333   /* serial bus address */
334   data |= c1541->address << 5;
335
336   /* attention in */
337   data |= !cbmserial_atn_r(c1541->serial_bus) << 7;
338
339   return data;
340}
341
342static WRITE8_DEVICE_HANDLER( via0_pb_w )
343{
344   /*
345
346      bit      description
347
348      PB0      DATA IN
349      PB1      DATA OUT
350      PB2      CLK IN
351      PB3      CLK OUT
352      PB4      ATNA
353      PB5      J1
354      PB6      J2
355      PB7      ATN IN
356
357   */
358
359   c1541_t *c1541 = get_safe_token(device->owner);
360   int data_out = BIT(data, 1);
361   int clk_out = BIT(data, 3);
362   int atna = BIT(data, 4);
363
364   /* data out */
365   int serial_data = !data_out && !(atna ^ !cbmserial_atn_r(c1541->serial_bus));
366   cbmserial_data_w(c1541->serial_bus, device->owner, serial_data);
367   c1541->data_out = data_out;
368
369   /* clock out */
370   cbmserial_clk_w(c1541->serial_bus, device->owner, !clk_out);
371
372   /* attention acknowledge */
373   c1541->atna = atna;
374}
375
376static const via6522_interface c1541_via0_intf =
377{
378   DEVCB_NULL,
379   DEVCB_HANDLER(via0_pb_r),
380   DEVCB_NULL,
381   DEVCB_NULL,
382   DEVCB_NULL,
383   DEVCB_NULL,
384
385   DEVCB_NULL,
386   DEVCB_HANDLER(via0_pb_w),
387   DEVCB_NULL, // ATN IN
388   DEVCB_NULL,
389   DEVCB_NULL,
390   DEVCB_NULL,
391
392   DEVCB_CPU_INPUT_LINE(M6502_TAG, INPUT_LINE_IRQ0)
393};
394
395/*-------------------------------------------------
396    via6522_interface c1541_via1_intf
397-------------------------------------------------*/
398
399static READ8_DEVICE_HANDLER( yb_r )
400{
401   /*
402
403      bit      description
404
297405      PA0      YB0
298406      PA1      YB1
299407      PA2      YB2
r6619r6620
305413
306414   */
307415
308   c1541_t *c1541 = get_safe_token(device);
416   c1541_t *c1541 = get_safe_token(device->owner);
309417
310418   return c1541->yb;
311419}
312420
313static WRITE8_DEVICE_HANDLER( via0_pa_w )
421static WRITE8_DEVICE_HANDLER( yb_w )
314422{
315423   /*
316424
r6619r6620
327435
328436   */
329437
330   c1541_t *c1541 = get_safe_token(device);
438   c1541_t *c1541 = get_safe_token(device->owner);
331439
332440   c1541->yb = data;
333441}
334442
335static READ8_DEVICE_HANDLER( via0_pb_r )
443static READ8_DEVICE_HANDLER( via1_pb_r )
336444{
337445   /*
338446
r6619r6620
349457
350458   */
351459
352   c1541_t *c1541 = get_safe_token(device);
460   c1541_t *c1541 = get_safe_token(device->owner);
353461   UINT8 data = 0;
354462
355463   /* write protect sensor */
356   data |= (floppy_drive_get_flag_state(c1541->image, FLOPPY_DRIVE_DISK_WRITE_PROTECTED)) << 4;
464   data |= (floppy_drive_get_flag_state(c1541->image, FLOPPY_DRIVE_DISK_WRITE_PROTECTED) == FLOPPY_DRIVE_DISK_WRITE_PROTECTED) << 4;
357465
358466   /* SYNC detected */
359467   data |= !(c1541->mode && (c1541->yb == 0xff)) << 7;
r6619r6620
361469   return data;
362470}
363471
364static WRITE8_DEVICE_HANDLER( via0_pb_w )
472static WRITE8_DEVICE_HANDLER( via1_pb_w )
365473{
366474   /*
367475
r6619r6620
378486
379487   */
380488
381   c1541_t *c1541 = get_safe_token(device);
489   c1541_t *c1541 = get_safe_token(device->owner);
382490   int stp = data & 0x03;
383491   int ds = (data >> 5) & 0x03;
492   int mtr = BIT(data, 2);
384493
385494   /* stepper motor */
386495   if (c1541->stp != stp)
387496   {
388497      int tracks = 0;
389      int length;
390498
391499      switch (c1541->stp)
392500      {
r6619r6620
398506
399507      floppy_drive_seek(c1541->image, tracks);
400508
401//      if (c1541->track < 0) c1541->track = 0; // BUMP!
402//      if (c1541->track > 83) c1541->track = 83;
509      c1541->track += tracks;
403510
404//      if (LOG) logerror("C1541 Track: %f\n", (float)c1541->track / 2);
511      if (c1541->track < 0) c1541->track = 0; // BUMP!
512      if (c1541->track > 83) c1541->track = 83;
405513
406      floppy_drive_read_track_data_info_buffer(c1541->image, 0, c1541->track_buffer, &length);
514      if (LOG) logerror("C1541 Track: %0.1f\n", (float)(c1541->track / 2) + 1);
515     
516      c1541->track_len = 8192;
517      floppy_drive_read_track_data_info_buffer(c1541->image, 0, c1541->track_buffer, &c1541->track_len);
518      c1541->buffer_pos = 0;
519      c1541->bit_pos = 0;
407520
408      if (LOG) logerror("C1541 Track length %u\n", length);
521      if (LOG) logerror("C1541 Track length %u\n", c1541->track_len);
409522
410523      c1541->stp = stp;
411524   }
412525
413526   /* spindle motor */
414   floppy_drive_set_motor_state(c1541->image, BIT(data, 2) ? FLOPPY_DRIVE_MOTOR_ON : 0);
415   timer_enable(c1541->bit_timer, BIT(data, 2));
527   floppy_drive_set_motor_state(c1541->image, mtr ? FLOPPY_DRIVE_MOTOR_ON : 0);
528   timer_enable(c1541->bit_timer, mtr);
416529
417530   /* activity LED */
418531
r6619r6620
426539
427540static WRITE_LINE_DEVICE_HANDLER( soe_w )
428541{
429   c1541_t *c1541 = get_safe_token(device);
542   c1541_t *c1541 = get_safe_token(device->owner);
430543   int byte_ready = !(state && c1541->byte);
431544
432545   c1541->soe = state;
433546
434547   cpu_set_input_line(c1541->cpu, M6502_SET_OVERFLOW, byte_ready);
435   via_ca1_w(c1541->via0, 0, byte_ready);
548   via_ca1_w(device, 0, byte_ready);
436549}
437550
438551static WRITE_LINE_DEVICE_HANDLER( mode_w )
439552{
440   c1541_t *c1541 = get_safe_token(device);
553   c1541_t *c1541 = get_safe_token(device->owner);
441554
442555   c1541->mode = state;
443556}
444557
445static const via6522_interface c1541_via0_intf =
558static const via6522_interface c1541_via1_intf =
446559{
447   DEVCB_HANDLER(via0_pa_r),
448   DEVCB_HANDLER(via0_pb_r),
560   DEVCB_HANDLER(yb_r),
561   DEVCB_HANDLER(via1_pb_r),
449562   DEVCB_NULL, // BYTE REDY
450563   DEVCB_NULL,
451564   DEVCB_NULL,
452565   DEVCB_NULL,
453566
454   DEVCB_HANDLER(via0_pa_w),
455   DEVCB_HANDLER(via0_pb_w),
567   DEVCB_HANDLER(yb_w),
568   DEVCB_HANDLER(via1_pb_w),
456569   DEVCB_NULL,
457570   DEVCB_NULL,
458571   DEVCB_LINE(soe_w),
r6619r6620
462575};
463576
464577/*-------------------------------------------------
465    via6522_interface c1541_via1_intf
466-------------------------------------------------*/
467
468static READ8_DEVICE_HANDLER( via1_pb_r )
469{
470   /*
471
472      bit      description
473
474      PB0      DATA IN
475      PB1      DATA OUT
476      PB2      CLK IN
477      PB3      CLK OUT
478      PB4      ATNA
479      PB5      J1
480      PB6      J2
481      PB7      ATN IN
482
483   */
484
485   c1541_t *c1541 = get_safe_token(device);
486   UINT8 data = 0;
487
488   /* data in */
489   data = cbmserial_data_r(c1541->serial_bus);
490
491   /* clock in */
492   data |= cbmserial_clk_r(c1541->serial_bus) << 2;
493
494   /* serial bus address */
495   data |= c1541->address << 5;
496
497   /* attention in */
498   data |= cbmserial_atn_r(c1541->serial_bus) << 7;
499
500   return data;
501}
502
503static WRITE8_DEVICE_HANDLER( via1_pb_w )
504{
505   /*
506
507      bit      description
508
509      PB0      DATA IN
510      PB1      DATA OUT
511      PB2      CLK IN
512      PB3      CLK OUT
513      PB4      ATNA
514      PB5      J1
515      PB6      J2
516      PB7      ATN IN
517
518   */
519
520   c1541_t *c1541 = get_safe_token(device);
521
522   /* data out */
523   cbmserial_data_w(c1541->serial_bus, BIT(data, 1));
524
525   /* clock out */
526   cbmserial_clk_w(c1541->serial_bus, BIT(data, 3));
527
528   /* attention acknowledge */
529   c1541->atna = BIT(data, 4);
530}
531
532static const via6522_interface c1541_via1_intf =
533{
534   DEVCB_NULL,
535   DEVCB_HANDLER(via1_pb_r),
536   DEVCB_NULL,
537   DEVCB_NULL,
538   DEVCB_NULL,
539   DEVCB_NULL,
540
541   DEVCB_NULL,
542   DEVCB_HANDLER(via1_pb_w),
543   DEVCB_NULL, // ATN IN
544   DEVCB_NULL,
545   DEVCB_NULL,
546   DEVCB_NULL,
547
548   DEVCB_CPU_INPUT_LINE(M6502_TAG, INPUT_LINE_IRQ0)
549};
550
551/*-------------------------------------------------
552578    FLOPPY_OPTIONS( c1541 )
553579-------------------------------------------------*/
554580
r6619r6620
568594   DEVCB_NULL,
569595   DEVCB_NULL,
570596   DEVCB_NULL,
571   FLOPPY_DRIVE_SS_40,
597   FLOPPY_DRIVE_SS_80,
572598   FLOPPY_OPTIONS_NAME(c1541),
573599   DO_NOT_KEEP_GEOMETRY
574600};
r6619r6620
584610   MDRV_VIA6522_ADD(M6522_0_TAG, XTAL_16MHz/16, c1541_via0_intf)
585611   MDRV_VIA6522_ADD(M6522_1_TAG, XTAL_16MHz/16, c1541_via1_intf)
586612
587   MDRV_FLOPPY_DRIVE_ADD("c1541_drive", c1541_floppy_config)
613   MDRV_FLOPPY_DRIVE_ADD(FLOPPY_TAG, c1541_floppy_config)
588614MACHINE_DRIVER_END
589615
590616/*-------------------------------------------------
r6619r6620
602628-------------------------------------------------*/
603629
604630ROM_START( c1541 ) // schematic 1540008
605   ROM_REGION( 0x1000, "c1541", ROMREGION_LOADBYNAME )
631   ROM_REGION( 0x10000, "c1541", ROMREGION_LOADBYNAME )
606632   ROM_LOAD( "325302-01.uab4", 0xc000, 0x2000, CRC(29ae9752) SHA1(8e0547430135ba462525c224e76356bd3d430f11) )
607633   ROM_LOAD( "901229-01.uab5", 0xe000, 0x2000, CRC(9a48d3f0) SHA1(7a1054c6156b51c25410caec0f609efb079d3a77) )
608634   ROM_LOAD( "901229-02.uab5", 0xe000, 0x2000, CRC(b29bab75) SHA1(91321142e226168b1139c30c83896933f317d000) )
609635   ROM_LOAD( "901229-03.uab5", 0xe000, 0x2000, CRC(9126e74a) SHA1(03d17bd745066f1ead801c5183ac1d3af7809744) )
610636   ROM_LOAD( "901229-04.uab5", 0xe000, 0x2000, NO_DUMP )
611   ROM_LOAD( "901229-05.uab5", 0xe000, 0x2000, CRC(361c9f37) SHA1(f5d60777440829e46dc91285e662ba072acd2d8b) )
612   ROM_LOAD( "901229-06aa.uab5", 0xe000, 0x2000, CRC(3a235039) SHA1(c7f94f4f51d6de4cdc21ecbb7e57bb209f0530c0) )
637   ROM_LOAD( "901229-05 ae.uab5", 0xe000, 0x2000, CRC(361c9f37) SHA1(f5d60777440829e46dc91285e662ba072acd2d8b) )
638//   ROM_LOAD( "901229-06 aa.uab5", 0xe000, 0x2000, CRC(3a235039) SHA1(c7f94f4f51d6de4cdc21ecbb7e57bb209f0530c0) )
613639ROM_END
614640
615641/*-------------------------------------------------
r6619r6620
617643-------------------------------------------------*/
618644
619645ROM_START( c1541cr ) // schematic 1540049
620   ROM_REGION( 0x1000, "c1541cr", ROMREGION_LOADBYNAME )
646   ROM_REGION( 0x10000, "c1541cr", ROMREGION_LOADBYNAME )
621647   ROM_LOAD( "325302-01.ub3", 0xc000, 0x2000, CRC(29ae9752) SHA1(8e0547430135ba462525c224e76356bd3d430f11) )
622648   ROM_LOAD( "901229-01.ub4", 0xe000, 0x2000, CRC(9a48d3f0) SHA1(7a1054c6156b51c25410caec0f609efb079d3a77) )
623649   ROM_LOAD( "901229-02.ub4", 0xe000, 0x2000, CRC(b29bab75) SHA1(91321142e226168b1139c30c83896933f317d000) )
624650   ROM_LOAD( "901229-03.ub4", 0xe000, 0x2000, CRC(9126e74a) SHA1(03d17bd745066f1ead801c5183ac1d3af7809744) )
625651   ROM_LOAD( "901229-04.ub4", 0xe000, 0x2000, NO_DUMP )
626   ROM_LOAD( "901229-05.ub4", 0xe000, 0x2000, CRC(361c9f37) SHA1(f5d60777440829e46dc91285e662ba072acd2d8b) )
627   ROM_LOAD( "901229-06aa.ub4", 0xe000, 0x2000, CRC(3a235039) SHA1(c7f94f4f51d6de4cdc21ecbb7e57bb209f0530c0) )
652   ROM_LOAD( "901229-05 ae.ub4", 0xe000, 0x2000, CRC(361c9f37) SHA1(f5d60777440829e46dc91285e662ba072acd2d8b) )
653   ROM_LOAD( "901229-06 aa.ub4", 0xe000, 0x2000, CRC(3a235039) SHA1(c7f94f4f51d6de4cdc21ecbb7e57bb209f0530c0) )
628654ROM_END
629655
630656/*-------------------------------------------------
r6619r6620
644670-------------------------------------------------*/
645671
646672ROM_START( c1541b ) // schematic ?
647   ROM_REGION( 0x1000, "c1541b", ROMREGION_LOADBYNAME )
673   ROM_REGION( 0x10000, "c1541b", ROMREGION_LOADBYNAME )
648674   ROM_LOAD( "251968-01.ua2", 0xc000, 0x4000, CRC(1b3ca08d) SHA1(8e893932de8cce244117fcea4c46b7c39c6a7765) )
649675   ROM_LOAD( "251968-02.ua2", 0xc000, 0x4000, CRC(2d862d20) SHA1(38a7a489c7bbc8661cf63476bf1eb07b38b1c704) )
650676ROM_END
r6619r6620
660686-------------------------------------------------*/
661687
662688ROM_START( c1541ii ) // schematic 340503
663   ROM_REGION( 0x1000, "c1541ii", ROMREGION_LOADBYNAME )
689   ROM_REGION( 0x10000, "c1541ii", ROMREGION_LOADBYNAME )
664690   ROM_LOAD( "251968-03.u4", 0xc000, 0x4000, CRC(899fa3c5) SHA1(d3b78c3dbac55f5199f33f3fe0036439811f7fb3) )
665691   ROM_LOAD( "355640-01.u4", 0xc000, 0x4000, CRC(57224cde) SHA1(ab16f56989b27d89babe5f89c5a8cb3da71a82f0) )
666692ROM_END
r6619r6620
685711   c1541->via0 = device_find_child_by_tag(device, M6522_0_TAG);
686712   c1541->via1 = device_find_child_by_tag(device, M6522_1_TAG);
687713   c1541->serial_bus = devtag_get_device(device->machine, config->serial_bus_tag);
688   c1541->image = device_find_child_by_tag(device, "c1541_drive");
714   c1541->image = device_find_child_by_tag(device, FLOPPY_TAG);
689715
690716   /* allocate data timer */
691717   c1541->bit_timer = timer_alloc(device->machine, bit_tick, (void *)device);
692   timer_adjust_periodic(c1541->bit_timer, attotime_zero, 0, ATTOTIME_IN_HZ(C1541_BITRATE[0]));
718//   timer_adjust_periodic(c1541->bit_timer, attotime_zero, 0, ATTOTIME_IN_HZ(C1541_BITRATE[0]));
719//   timer_enable(c1541->bit_timer, 0);
693720
694721   /* register for state saving */
695722//   state_save_register_device_item(device, 0, c1541->);
r6619r6620
725752      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(c1541);                  break;
726753      case DEVINFO_FCT_STOP:                     /* Nothing */                                    break;
727754      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(c1541);                  break;
728      case DEVINFO_FCT_CBM_SERIAL_ATN:            info->f = (genf *)c1541_atn_w;                        break;
729      case DEVINFO_FCT_CBM_SERIAL_RESET:            info->f = (genf *)c1541_reset_w;                     break;
755      case DEVINFO_FCT_CBM_SERIAL_ATN:            info->f = (genf *)cbmserial_atn_c1541;            break;
756      case DEVINFO_FCT_CBM_SERIAL_RESET:            info->f = (genf *)cbmserial_reset_c1541;            break;
730757
731758      /* --- the following bits of info are returned as NULL-terminated strings --- */
732759      case DEVINFO_STR_NAME:                     strcpy(info->s, "Commodore 1541");                     break;
src/mess/machine/c64.c
r6619r6620
1919#include "cpu/z80/z80.h"
2020#include "sound/sid6581.h"
2121#include "machine/6526cia.h"
22#include "machine/cbmserial.h"
2223#include "video/vic6567.h"
2324#include "video/vdc8563.h"
2425
2526#include "includes/cbm.h"
26#include "includes/cbmserb.h"
2727#include "includes/cbmdrive.h"
2828#include "includes/vc1541.h"
2929
r6619r6620
205205   UINT8 value = 0xff;
206206   const device_config *serbus = devtag_get_device(device->machine, "serial_bus");
207207
208   if (!serial_clock || !cbm_serial_clock_read(serbus, 0))
208   if (!cbmserial_clk_r(serbus))
209209      value &= ~0x40;
210210
211   if (!serial_data || !cbm_serial_data_read(serbus, 0))
211   if (!cbmserial_data_r(serbus))
212212      value &= ~0x80;
213213
214214   return value;
r6619r6620
219219   static const int helper[4] = {0xc000, 0x8000, 0x4000, 0x0000};
220220   const device_config *serbus = devtag_get_device(device->machine, "serial_bus");
221221
222   cbm_serial_clock_write(serbus, 0, serial_clock = !(data & 0x10));
223   cbm_serial_data_write(serbus, 0, serial_data = !(data & 0x20));
224   cbm_serial_atn_write(serbus, 0, serial_atn = !(data & 0x08));
222   cbmserial_clk_w(serbus, device, !(data & 0x10));
223   cbmserial_data_w(serbus, device, !(data & 0x20));
224   cbmserial_atn_w(serbus, device, !(data & 0x08));
225225   c64_vicaddr = c64_memory + helper[data & 0x03];
226226}
227227
src/mess/formats/g64_dsk.c
r6619r6620
2727
2828*/
2929
30/*
31
32   TODO:
33
34   - speed zones
35   - writing
36
37*/
38
3039#include "driver.h"
3140#include "formats/flopimg.h"
3241#include "devices/flopdrv.h"
r6619r6620
4554   UINT32 speed_zone_offset[HALF_TRACKS]; /* offset within data for each half track */
4655};
4756
57INLINE float get_track_index(int track)
58{
59   return ((float)track / 2) + 1;
60}
61
4862static struct g64dsk_tag *get_tag(floppy_image *floppy)
4963{
5064   struct g64dsk_tag *tag;
r6619r6620
5266   return tag;
5367}
5468
69static int g64_get_heads_per_disk(floppy_image *floppy)
70{
71   return 1;
72}
73
74static int g64_get_tracks_per_disk(floppy_image *floppy)
75{
76   return get_tag(floppy)->tracks;
77}
78
5579static floperr_t get_track_offset(floppy_image *floppy, int track, UINT64 *offset)
5680{
5781   struct g64dsk_tag *tag = get_tag(floppy);
r6619r6620
6892   return FLOPPY_ERROR_SUCCESS;
6993}
7094
95floperr_t g64_get_track_length(floppy_image *floppy, int track, UINT64 *length)
96{
97   floperr_t err;
98   UINT64 track_offset;
99   UINT64 track_length;
100   UINT8 header[2];
101
102   /* get track offset */
103   err = get_track_offset(floppy, track, &track_offset);
104   
105   if (err)
106      return err;
107
108   /* get track length */
109   floppy_image_read(floppy, header, track_offset, 2);
110   track_length = (header[1] << 8) | header[0];
111
112   if (length)
113      *length = track_length;
114
115   return FLOPPY_ERROR_SUCCESS;
116}
117
71118static floperr_t g64_read_track(floppy_image *floppy, int head, int track, UINT64 offset, void *buffer, size_t buflen)
72119{
73120   floperr_t err;
r6619r6620
84131   /* get track length */
85132   floppy_image_read(floppy, header, track_offset, 2);
86133   track_length = (header[1] << 8) | header[0];
134   logerror("G64 track %.1f length %u\n", get_track_index(track), track_length);
87135
88136   /* read track */
89137   floppy_image_read(floppy, buffer, track_offset, buflen);
r6619r6620
150198   {
151199      floppy_image_read(floppy, header, pos, 4); pos += 4;
152200      tag->track_offset[i] = (header[3] << 24) | (header[2] << 16) | (header[1] << 8) | header[0];
153      logerror("G64 track %f data offset: %04x\n", ((i * 0.5) + 1), tag->track_offset[i]);
201      logerror("G64 track %.1f data offset: %04x\n", get_track_index(i), tag->track_offset[i]);
154202   }
155203
156204   /* speed zone offsets */
r6619r6620
158206   {
159207      floppy_image_read(floppy, header, pos, 4); pos += 4;
160208      tag->speed_zone_offset[i] = (header[3] << 24) | (header[2] << 16) | (header[1] << 8) | header[0];
161      logerror("G64 track %f speed zone offset: %04x\n", ((i * 0.5) + 1), tag->speed_zone_offset[i]);
209      if (tag->speed_zone_offset[i] < 4)
210         logerror("G64 track %.1f speed zone: %u\n", get_track_index(i), tag->speed_zone_offset[i]);
211      else
212         logerror("G64 track %.1f speed zone offset: %04x\n", get_track_index(i), tag->speed_zone_offset[i]);
162213   }
163214
164215   /* set callbacks */
r6619r6620
166217
167218   callbacks->read_track = g64_read_track;
168219   callbacks->write_track = g64_write_track;
220   callbacks->get_heads_per_disk = g64_get_heads_per_disk;
221   callbacks->get_tracks_per_disk = g64_get_tracks_per_disk;
169222
170223   return FLOPPY_ERROR_SUCCESS;
171224}
src/mess/formats/g64_dsk.h
r6619r6620
1111
1212#include "formats/flopimg.h"
1313
14floperr_t g64_get_track_length(floppy_image *floppy, int track, UINT64 *length);
15
1416FLOPPY_IDENTIFY( g64_dsk_identify );
1517FLOPPY_CONSTRUCT( g64_dsk_construct );
1618
src/mess/drivers/c64.c
r6619r6620
333333
334334/* devices config */
335335#include "includes/cbm.h"
336#include "includes/cbmserb.h"   // needed for MDRV_DEVICE_REMOVE
337336#include "includes/cbmdrive.h"
338337#include "includes/vc1541.h"
338#include "machine/cbmserial.h"
339#include "machine/c1541.h"
339340
340341#include "includes/c64.h"
341342
r6619r6620
478479   c64_m6510_port_write
479480};
480481
482static CBMSERIAL_DAISY( cbmserial_daisy )
483{
484   { "cia_1" },
485   { "c1541" },
486   { NULL}
487};
481488
482489/*************************************
483490 *
r6619r6620
522529   MDRV_CIA6526_ADD("cia_1", CIA6526R1, VIC6567_CLOCK, c64_ntsc_cia1)
523530
524531   /* floppy from serial bus */
525   MDRV_IMPORT_FROM(simulated_drive)
532   MDRV_CBMSERIAL_ADD("serial_bus", cbmserial_daisy)
533   MDRV_C1541_ADD("c1541", "serial_bus", 8)
526534
527535   MDRV_IMPORT_FROM(c64_cartslot)
528536MACHINE_DRIVER_END
r6619r6620
563571   MDRV_CIA6526_ADD("cia_1", CIA6526R1, VIC6569_CLOCK, c64_pal_cia1)
564572
565573   /* floppy from serial bus */
566   MDRV_IMPORT_FROM(simulated_drive)
574   MDRV_CBMSERIAL_ADD("serial_bus", cbmserial_daisy)
575   MDRV_C1541_ADD("c1541", "serial_bus", 8)
567576
568577   MDRV_IMPORT_FROM(c64_cartslot)
569578MACHINE_DRIVER_END

Previous 15994 Revisions Next


© 1998-2018 The MESS Team