Previous 15994 Revisions Next

r3312 Sunday 21st September, 2008 at 19:41:03 UTC by Fabio Priuli
[CBM] moved D64->GCR conversion at loading time
[src/mess/includes]vc1541.h
[src/mess/machine]vc1541.c

src/mess/includes/vc1541.h
r3311r3312
3131
3232enum {
3333format_d64 = 0,
34format_d64_err,
3435format_d64_40t,
36format_d64_40t_err,
37format_d67,
3538format_d71,
39format_d71_err,
3640format_d81,
3741format_d80,
3842format_d82,
3943format_g64,
4044};
4145
42DEVICE_IMAGE_LOAD(vc1541);
43DEVICE_IMAGE_UNLOAD(vc1541);
4446
4547int drive_config(int type, int id, int mode, int cpunr, int devicenr);
4648void drive_reset(void);
src/mess/machine/vc1541.c
r3311r3312
9898 */
9999/* 2008-09 FP
100100started some work on the floppy emulation code:
101   + made the functions / structs less vc1541-centric   
101   + made the functions / structs less vc1541-centric & d64-centric
102102   + unified config & reset functions, using type variable
103103      to choose the actions to be done
104   + moved GCR encoding at loading time (wip untested code)
104105 
105106a limitation is clear: only a single occurrence of emulated drive
106107is expected.
r3311r3312
108109an index to choose between the drives
109110
110111current status:
111   + preliminary vc1541 & c1551 implementation (I still have to
112      investigate how good)
112   + preliminary vc1541 & c1551 implementation (seems very slow)
113113   + no support for other drive types (even if now I list all
114114      the variants supported by Vice in the enum)
115   + communications between the drive CPU and the computer CPU have
116      to be checked, debugged and improved
117   + most functions / constants are d64 independent, even if other
118      formats are not supported yet!
119   + the floppy handling still uses CBM_Drive_Emu struct instead of
120      functions similar to other floppy formats
115121*/
116122
117123#include "driver.h"
r3311r3312
138144
139145#define XTAL_16_MHz   16000000
140146
147
148/*
149 * only for testing at the moment
150 */
151
152#define WRITEPROTECTED 0
153
154
155/*******************************************
156
157   Structures
158
159*******************************************/
160
161/* 0 summarized, 1 computer, 2 vc1541 */
162static struct
163{
164   int atn[3], data[3], clock[3];
165}
166serial;
167
168/* Legacy code. At a later stage, we should really use code more similar
169to the MESS core floppy code. However, fixing the C64 / Floppy drive
170communications is a priority over the clean up of this part */
171typedef struct
172{
173   int cpunumber;
174   int type;
175   union {
176      struct {
177         int deviceid;
178         int serial_atn, serial_clock, serial_data;
179         int acka, data;
180      } serial;
181      struct {
182         int deviceid;
183      } ieee488;
184      struct {
185         UINT8 cpu_ddr, cpu_port;
186         void *irq_timer;
187      } c1551;
188   } drive;
189
190   int via0irq, via1irq;
191
192   int led, motor, frequency;
193
194   double track;
195   int clock;
196   int pos;      // from the beginning of the current track!
197
198   void *timer;
199
200   struct {
201      int sync;            // active after > 9 '1's
202      int ready;            // needed for 1551
203      int ones_count;         // still needed?
204      UINT8 data[0x500000];   // entire d64 image encoded at loading time
205   } gcr;
206} CBM_Drive_Emu;
207
208static CBM_Drive_Emu drive_static= { 0 }, *drive = &drive_static;
209
210
211
212/*******************************************
213
214   Format specific code
215
216*******************************************/
217
218
141219/* Are there other formats to support which could require more tracks? */
142220#define IMAGE_MAX_TRACKS 154
143221
r3311r3312
203281static int image_offset[IMAGE_MAX_TRACKS] = { 0 };
204282
205283
284/*******************************************
285
286   Offset initialization
287
288*******************************************/
289
290
206291static void offset_init (int format)
207292{
208293   int i;
r3311r3312
213298   switch (format)
214299   {
215300      case format_d64:
301      case format_d64_err:
216302         for (i = 1; i <= D64_MAX_TRACKS; i++)
217303            image_offset[i] = image_offset[i - 1] + d64_sectors_per_track[i - 1] * 256;
218304         break;
219305
220306      case format_d64_40t:
307      case format_d64_40t_err:
221308         for (i = 1; i <= D64_40T_MAX_TRACKS; i++)
222309            image_offset[i] = image_offset[i - 1] + d64_sectors_per_track[i - 1] * 256;
223310         break;
224311
225312      case format_d71:
313      case format_d71_err:
226314         for (i = 1; i <= D71_MAX_TRACKS; i++)
227315            image_offset[i] = image_offset[i - 1] + d71_sectors_per_track[i - 1] * 256;
228316         break;
r3311r3312
243331         break;
244332
245333      default:
246         logerror("Unsupported format");
334         /* Still have to work on d67 & g64 images */
335         logerror("Unsupported format\n");
247336         break;
248337   }
249338}
250339
251340
252/* calculates offset to beginning of the image file for sector beginning */
253/* since sectors are always 256 bytes large, this works for each file format! */
341/*******************************************
342
343   Generic image handling
344
345*******************************************/
346
347
348/* This calculates starting offset (from the beginning of the image file) of a sector */
349/* Since sectors are always 256 bytes large, this works no matter the file format! */
254350static int image_tracksector2offset (int track, int sector)
255351{
256352   return image_offset[track - 1] + sector * 256;
257353}
258354
259
260#define D64_TRACK_ID1   (image_tracksector2offset(18,0)+162)
261#define D64_TRACK_ID2   (image_tracksector2offset(18,0)+163)
262
263355/*
264 * only for testing at the moment
265 */
356// WARNING: this would work with a d64 image... it has to be adapted to work with GCR image we store at loading time
357static void image_offset2tracksector (int offset)
358{
359   int track = 0, sector = 0, helper, i = 0;
360   
361   helper = offset;
362   
363   do
364   {
365   helper -= (d64_sectors_per_track[++i] * 256);
366   } while ( helper > 0);
367   
368   track = i;
266369
267#define WRITEPROTECTED 0
370   sector = (offset - image_offset[track]) / 256;
268371
269/* 0 summarized, 1 computer, 2 vc1541 */
270static struct
271{
272   int atn[3], data[3], clock[3];
372   logerror("We are reading at offset %d, which is in track %d and sector %d \n", offset, track, sector);
273373}
274serial;
374*/
275375
276/* G64 or D64 image
277 implementation as writeback system
278 */
279376
280typedef struct
377/* These functions return the Disk ID stored in the disk BAM */
378/* It is not necessarily the one some copy protection checks, and
379   indeed, in these cases a g64 image is needed (which stores the
380   Disk ID as coded in the GCR data) */
381
382static int disk_id1 (int format)
281383{
282   int cpunumber;
283   int type;
284   union {
285      struct {
286         int deviceid;
287         int serial_atn, serial_clock, serial_data;
288         int acka, data;
289      } serial;
290      struct {
291         int deviceid;
292      } ieee488;
293      struct {
294         UINT8 cpu_ddr, cpu_port;
295         void *irq_timer;
296      } c1551;
297   } drive;
384   int id1 = 0;
298385
299   int via0irq, via1irq;
386   switch (format)
387   {
388      case format_d64:
389      case format_d64_err:
390      case format_d64_40t:
391      case format_d64_40t_err:
392      case format_d71:
393      case format_d71_err:
394         id1 = image_tracksector2offset(18, 0) + 0xa2;
395         break;
300396
301   int led, motor, frequency;
397      case format_d81:
398         id1 = image_tracksector2offset(40, 0) + 0x16;
399         break;
302400
303   double track;
304   int clock;
401      case format_d80:
402      case format_d82:
403         id1 = image_tracksector2offset(39, 0) + 0x18;
404         break;
305405
306   void *timer;
406      default:
407         /* Still have to work on d67 & g64 images */
408         logerror("Unsupported format\n");
409         break;
410   }
411   
412   return id1;
413}
307414
308   struct {
309      UINT8 data[(1+2+2+1+256/4+4)*5];
310      int sync;
311      int ready;
312      int ffcount;
313   } head;
314415
315   struct {
316      int pos; /* position  in sector */
317      int sector;
318      UINT8 *data;
319   } image;
320} CBM_Drive_Emu;
416static int disk_id2 (int format)
417{
418   int id2 = 0;
321419
322static CBM_Drive_Emu drive_static= { 0 }, *drive = &drive_static;
420   switch (format)
421   {
422      case format_d64:
423      case format_d64_err:
424      case format_d64_40t:
425      case format_d64_40t_err:
426      case format_d71:
427      case format_d71_err:
428         id2 = image_tracksector2offset(18, 0) + 0xa3;
429         break;
323430
431      case format_d81:
432         id2 = image_tracksector2offset(40, 0) + 0x17;
433         break;
324434
325/**************************************
435      case format_d80:
436      case format_d82:
437         id2 = image_tracksector2offset(39, 0) + 0x19;
438         break;
326439
327   Generic image handling
440      default:
441         /* Still have to work on d67 & g64 images */
442         logerror("Unsupported format\n");
443         break;
444   }
445   
446   return id2;
447}
328448
329**************************************/
330449
331
332/* four different frequencies for the 4 different zones on the disk */
333static const double drive_times[4]= {
334   13/16e6, 14/16e6, 15/16e6, 16/16e6
450/* Four different frequencies for the 4 different zones on the disk */
451/* These work for 1541 drives, are the same for other drives? */
452static const double drive_times[4]=
453{
454   XTAL_16_MHz / 13, XTAL_16_MHz / 14, XTAL_16_MHz / 15, XTAL_16_MHz / 16
335455};
336456
457
458/* Commodore GCR format */
337459/*
338 * gcr encoding 4 bits to 5 bits
339 * 1 change, 0 none
340 *
341 * physical encoding of the data on a track
342 * sector header
343 *  sync (5x 0xff not gcr encoded)
344 *  sync mark (0x08)
345 *  checksum (chksum xor sector xor track xor id1 xor id2 gives 0)
346 *  sector#
347 *  track#
348 *  id2 (disk id to prevent writing to disk after disk change)
349 *  id1
350 *  0x0f
351 *  0x0f
352 * cap normally 10 (min 5) byte?
353 * sector data
354 *  sync (5x 0xff not gcr encoded)
355 *  sync mark (0x07)
356 *  256 bytes
357 *  checksum (256 bytes xored)
358 * cap
359 *
360 * max 42 tracks, stepper resolution 84 tracks
361 */
460Original   Encoded
4614 bits      5 bits
462
4630000   ->   01010 = 0x0a
4640001   ->   01011 = 0x0b
4650010   ->   10010 = 0x12
4660011   ->   10011 = 0x13
4670100   ->   01110 = 0x0e
4680101   ->   01111 = 0x0f
4690110   ->   10110 = 0x16
4700111   ->   10111 = 0x17
4711000   ->   01001 = 0x09
4721001   ->   11001 = 0x19
4731010   ->   11010 = 0x1a
4741011   ->   11011 = 0x1b
4751100   ->   01101 = 0x0d
4761101   ->   11101 = 0x1d
4771110   ->   11110 = 0x1e
4781111   ->   10101 = 0x15
479
480We use the encoded values in bytes because we use them to encode
481groups of 4 bytes into groups of 5 bytes, below.
482*/
483
362484static const int bin_2_gcr[] =
363485{
364486   0x0a, 0x0b, 0x12, 0x13, 0x0e, 0x0f, 0x16, 0x17,
365487   0x09, 0x19, 0x1a, 0x1b, 0x0d, 0x1d, 0x1e, 0x15
366488};
367489
368#if 0
369static const int gcr_2_bin[] = {
370   -1, -1, -1, -1,
371   -1, -1, -1, -1,
372   -1, 8, 0, 1,
373   -1, 0xc, 4, 5,
374   -1, -1, 2, 3,
375   -1, 0xf, 6, 7,
376   -1, 9, 0xa, 0xb,
377   -1, 0xd, 0xe, -1
490
491/* This could be of use if we ever implement saving in .d64 format, to convert back GCR -> d64 */
492/*
493static const int gcr_2_bin[] =
494{
495   -1, -1,   -1,   -1,
496   -1, -1,   -1,   -1,
497   -1, 0x08, 0x00, 0x01,
498   -1, 0x0c, 0x04, 0x05,
499   -1, -1,   0x02, 0x03,
500   -1, 0x0f, 0x06, 0x07,
501   -1, 0x09, 0x0a, 0x0b,
502   -1, 0x0d, 0x0e, -1
378503};
379#endif
504*/
380505
506
507/* gcr_double_2_gcr takes 4 bytes (a, b, c, d) and shuffles their nibbles to obtain 5 bytes in dest */
508/* The result is basically res = (enc(a) << 15) | (enc(b) << 10) | (enc(c) << 5) | enc(d)
509 * with res being 5 bytes long and enc(x) being the GCR encode of x.
510 * In fact, we store the result as five separate bytes in the dest argument
511 */
381512static void gcr_double_2_gcr(UINT8 a, UINT8 b, UINT8 c, UINT8 d, UINT8 *dest)
382513{
383514   UINT8 gcr[8];
384   gcr[0]=bin_2_gcr[a>>4];
385   gcr[1]=bin_2_gcr[a&0xf];
386   gcr[2]=bin_2_gcr[b>>4];
387   gcr[3]=bin_2_gcr[b&0xf];
388   gcr[4]=bin_2_gcr[c>>4];
389   gcr[5]=bin_2_gcr[c&0xf];
390   gcr[6]=bin_2_gcr[d>>4];
391   gcr[7]=bin_2_gcr[d&0xf];
392   dest[0]=(gcr[0]<<3)|(gcr[1]>>2);
393   dest[1]=(gcr[1]<<6)|(gcr[2]<<1)|(gcr[3]>>4);
394   dest[2]=(gcr[3]<<4)|(gcr[4]>>1);
395   dest[3]=(gcr[4]<<7)|(gcr[5]<<2)|(gcr[6]>>3);
396   dest[4]=(gcr[6]<<5)|gcr[7];
397}
398515
399static struct {
400   int count;
401   int data[4];
402} gcr_helper;
516   /* Encode each nibble to 5 bits */
517   gcr[0] = bin_2_gcr[a >> 4];
518   gcr[1] = bin_2_gcr[a & 0x0f];
519   gcr[2] = bin_2_gcr[b >> 4];
520   gcr[3] = bin_2_gcr[b & 0x0f];
521   gcr[4] = bin_2_gcr[c >> 4];
522   gcr[5] = bin_2_gcr[c & 0x0f];
523   gcr[6] = bin_2_gcr[d >> 4];
524   gcr[7] = bin_2_gcr[d & 0x0f];
403525
404static void drive_sector_start(void)
405{
406   gcr_helper.count=0;
526   /* Re-order the encoded data to only keep the 5 lower bits of each byte */
527   dest[0] = (gcr[0] << 3) | (gcr[1] >> 2);
528   dest[1] = (gcr[1] << 6) | (gcr[2] << 1) | (gcr[3] >> 4);
529   dest[2] = (gcr[3] << 4) | (gcr[4] >> 1);
530   dest[3] = (gcr[4] << 7) | (gcr[5] << 2) | (gcr[6] >> 3);
531   dest[4] = (gcr[6] << 5) | gcr[7];
407532}
408533
409static void drive_sector_data(UINT8 data, int *pos)
410{
411   gcr_helper.data[gcr_helper.count++]=data;
412   if (gcr_helper.count==4) {
413      gcr_double_2_gcr(gcr_helper.data[0], gcr_helper.data[1],
414                   gcr_helper.data[2], gcr_helper.data[3],
415                   drive->head.data+*pos);
416      *pos=*pos+5;
417      gcr_helper.count=0;
418   }
419}
420534
421static void drive_sector_end(int *pos)
422{
423   assert(gcr_helper.count==0);
424}
425
426static void drive_sector_to_gcr(int track, int sector)
427{
428   int i=0, j, offset, chksum=0;
429
430   if (drive->image.data==NULL) return;
431   drive->head.data[i++]=0xff;
432   drive->head.data[i++]=0xff;
433   drive->head.data[i++]=0xff;
434   drive->head.data[i++]=0xff;
435   drive->head.data[i++]=0xff;
436   drive_sector_start();
437
438   drive_sector_data(8, &i);
439   chksum= sector^track
440      ^drive->image.data[D64_TRACK_ID1]^drive->image.data[D64_TRACK_ID2];
441   drive_sector_data(chksum, &i);
442   drive_sector_data(sector, &i);
443   drive_sector_data(track, &i);
444   drive_sector_data(drive->image.data[D64_TRACK_ID1], &i);
445   drive_sector_data(drive->image.data[D64_TRACK_ID2], &i);
446   drive_sector_data(0xf, &i);
447   drive_sector_data(0xf, &i);
448   drive_sector_end(&i);
449
450   /* 5 - 10 gcr bytes cap */
451   gcr_double_2_gcr(0, 0, 0, 0, drive->head.data+i);i+=5;
452   gcr_double_2_gcr(0, 0, 0, 0, drive->head.data+i);i+=5;
453   drive->head.data[i++]=0xff;
454   drive->head.data[i++]=0xff;
455   drive->head.data[i++]=0xff;
456   drive->head.data[i++]=0xff;
457   drive->head.data[i++]=0xff;
458   drive_sector_data(0x7, &i);
459
460   chksum=0;
461   for (offset=image_tracksector2offset(track,sector), j=0; j<256; j++) {
462      chksum^=drive->image.data[offset];
463      drive_sector_data(drive->image.data[offset++], &i);
464   }
465   drive_sector_data(chksum, &i);
466   drive_sector_data(0, &i); /* padding up */
467   drive_sector_data(0, &i);
468   drive_sector_end(&i);
469   gcr_double_2_gcr(0, 0, 0, 0, drive->head.data+i);i+=5;
470   gcr_double_2_gcr(0, 0, 0, 0, drive->head.data+i);i+=5;
471}
472
473
474535/**************************************
475536
476537   1541 / 1541II
r3311r3312
480541
481542static ADDRESS_MAP_START( _1541_map, ADDRESS_SPACE_PROGRAM, 8 )
482543   AM_RANGE(0x0000, 0x07ff) AM_RAM
483   AM_RANGE(0x1800, 0x180f) AM_READWRITE(via_2_r, via_2_w)  /* 0 and 1 used in vc20 */
484   AM_RANGE(0x1810, 0x189f) AM_READ(SMH_NOP) /* for debugger */
544   AM_RANGE(0x1800, 0x180f) AM_READWRITE(via_2_r, via_2_w)   /* 0 and 1 used in vc20 */
545   AM_RANGE(0x1810, 0x189f) AM_READ(SMH_NOP)            /* for debugger */
485546   AM_RANGE(0x1c00, 0x1c0f) AM_READWRITE(via_3_r, via_3_w)
486   AM_RANGE(0x1c10, 0x1c9f) AM_READ(SMH_NOP) /* for debugger */
547   AM_RANGE(0x1c10, 0x1c9f) AM_READ(SMH_NOP)            /* for debugger */
487548   AM_RANGE(0xc000, 0xffff) AM_ROM
488549ADDRESS_MAP_END
489550
490551
491552static ADDRESS_MAP_START( dolphin_map, ADDRESS_SPACE_PROGRAM, 8 )
492553   AM_RANGE(0x0000, 0x07ff) AM_RAM
493   AM_RANGE(0x1800, 0x180f) AM_READWRITE(via_2_r, via_2_w)  /* 0 and 1 used in vc20 */
554   AM_RANGE(0x1800, 0x180f) AM_READWRITE(via_2_r, via_2_w)   /* 0 and 1 used in vc20 */
494555   AM_RANGE(0x1c00, 0x1c0f) AM_READWRITE(via_3_r, via_3_w)
495556   AM_RANGE(0x8000, 0x9fff) AM_RAM
496557   AM_RANGE(0xa000, 0xffff) AM_ROM
497558ADDRESS_MAP_END
498559
499560
500#if 0
501INPUT_PORTS_START (vc1541)
502PORT_START
503PORT_DIPNAME (0x60, 0x00, "Device #", CODE_NONE)
504PORT_DIPSETTING (0x00, "8")
505PORT_DIPSETTING (0x20, "9")
506PORT_DIPSETTING (0x40, "10")
507PORT_DIPSETTING (0x60, "11")
508INPUT_PORTS_END
509#endif
510
511561static TIMER_CALLBACK(drive_timer)
512562{
513   if (drive->clock==0) {
514      drive->clock=1;
515      drive->head.ready=0;
516      drive->head.sync=0;
517      if (drive->type==type_1541) {
563   if (drive->clock == 0)
564   {
565      drive->gcr.ready = 0;
566      // why put sync back to 0 here?!? it would break the sync count, isn't it?
567      // or is it the way the serial port reads the sync count?!?
568      drive->gcr.sync = 0;
569   
570      if (drive->type == type_1541)
571      {
518572         cpunum_set_input_line(machine, drive->cpunumber, M6502_SET_OVERFLOW, 1);
519573         via_3_ca1_w(machine, 0,1);
520574      }
575
576      drive->clock = 1;
521577      return;
522578   }
523   if (++(drive->image.pos)>=sizeof(drive->head.data)) {
524      if (++(drive->image.sector)>=
525         d64_sectors_per_track[(int)drive->track-1]) {
526         drive->image.sector=0;
527      }
528      drive_sector_to_gcr((int)drive->track,drive->image.sector);
529      drive->image.pos=0;
579
580   // this code has 2 effects: move on the pos on the data and reset it to 0 at the end of the track!
581   // size of the track is: (# sectors in the track) * (size of sector GCR endoded)
582   // Here, size of sector is 368 because of our choices in the loading: 9 bytes of header gap & 14 bytes of sector gap
583   // We will need to set the size at loading time when adding support for G64 images
584   if (++(drive->pos) >= (d64_sectors_per_track[(int)drive->track - 1] * 368))
585      drive->pos = 0;
586   // should we check if there is a change of track? to reset the pos in that case as well?
587
588   drive->gcr.ready = 1;
589
590   // notice that if there is a sequence of more than 40 1s it correctly does not reset the sync
591   // counter until a 0 is found
592   if (drive->gcr.data[drive->pos] == 0xff)
593   {
594      drive->gcr.ones_count++;
595
596//      if (drive->gcr.ones_count == 2) // 9 ones should already mark it as a sync, even if CBM chose to use 40 of them
597      if (drive->gcr.ones_count == 5)
598         drive->gcr.sync = 1;
599   }
600   else
601   {
602      drive->gcr.ones_count = 0;
603      drive->gcr.sync = 0;
530604   }
531   drive->head.ready=1;
532   if (drive->head.data[drive->image.pos]==0xff) {
533      drive->head.ffcount++;
534      if (drive->head.ffcount==5) {
535         drive->head.sync=1;
536      }
537   } else {
538      drive->head.ffcount=0;
539      drive->head.sync=0;
540   }
541   if (drive->type==type_1541) {
605
606   if (drive->type == type_1541)
607   {
542608      cpunum_set_input_line(machine, drive->cpunumber, M6502_SET_OVERFLOW, 0);
543      via_3_ca1_w(machine, 0,0);
609      via_3_ca1_w(machine, 0, 0);
544610   }
545   drive->clock=0;
611
612   drive->clock = 0;
546613}
547614
615
548616/*
549617 * via 6522 at 0x1800
550618 * port b
r3311r3312
560628 * also ca1 (books says cb2)
561629 * irq to m6502 irq connected (or with second via irq)
562630 */
631
563632static void vc1541_via0_irq (running_machine *machine, int level)
564633{
565634   drive->via0irq = level;
566635   DBG_LOG(2, "vc1541 via0 irq",("level %d %d\n",drive->via0irq,drive->via1irq));
567   cpunum_set_input_line (machine, drive->cpunumber,
568                 M6502_IRQ_LINE, drive->via1irq || drive->via0irq);
636
637   cpunum_set_input_line (machine, drive->cpunumber, M6502_IRQ_LINE, drive->via1irq || drive->via0irq);
569638}
570639
571640static READ8_HANDLER( vc1541_via0_read_portb )
572641{
573   static int old=-1;
574642   int value = 0x7a;
575643
576644   if (!drive->drive.serial.serial_data || !serial.data[0])
577645      value |= 1;
646
578647   if (!drive->drive.serial.serial_clock || !serial.clock[0])
579648      value |= 4;
649
580650   if (!serial.atn[0]) value |= 0x80;
581651
582652   switch (drive->drive.serial.deviceid)
583653   {
584   case 8:
585      value &= ~0x60;
586      break;
587   case 9:
588      value &= ~0x40;
589      break;
590   case 10:
591      value &= ~0x20;
592      break;
593   case 11:
594      break;
654      case 8:
655         value &= ~0x60;
656         break;
657      case 9:
658         value &= ~0x40;
659         break;
660      case 10:
661         value &= ~0x20;
662         break;
663      case 11:
664         break;
595665   }
596   if (value!=old) {
597666
598      DBG_LOG(2, "vc1541 serial read",("%s %s %s\n",
599                               serial.atn[0]?"ATN":"atn",
600                               serial.clock[0]?"CLOCK":"clock",
601                               serial.data[0]?"DATA":"data"));
602
603      DBG_LOG(2, "vc1541 serial read",("%s %s %s\n",
604                               value&0x80?"ATN":"atn",
605                               value&4?"CLOCK":"clock",
606                               value&1?"DATA":"data"));
607      old=value;
608   }
609
610667   return value;
611668}
612669
613670static WRITE8_HANDLER( vc1541_via0_write_portb )
614671{
615672   DBG_LOG(2, "vc1541 serial write",("%s %s %s\n",
616                            data&0x10?"ATN":"atn",
617                            data&8?"CLOCK":"clock",
618                            data&2?"DATA":"data"));
673                            data & 0x10 ? "ATN"   : "atn",
674                            data & 0x08 ? "CLOCK" : "clock",
675                            data & 0x02 ? "DATA"  : "data"));
619676
620   drive->drive.serial.data=data&2?0:1;
621   drive->drive.serial.acka=(data&0x10)?1:0;
677   drive->drive.serial.data = data & 0x02 ? 0 : 1;
678   drive->drive.serial.acka = data & 0x10 ? 1 : 0;
622679
623   if ((!(data & 2)) != drive->drive.serial.serial_data)
680   if ((!(data & 0x02)) != drive->drive.serial.serial_data)
624681   {
625      vc1541_serial_data_write (1, drive->drive.serial.serial_data = !(data & 2));
682      vc1541_serial_data_write (1, drive->drive.serial.serial_data = !(data & 0x02));
626683   }
627684
628   if ((!(data & 8)) != drive->drive.serial.serial_clock)
685   if ((!(data & 0x08)) != drive->drive.serial.serial_clock)
629686   {
630      vc1541_serial_clock_write (1, drive->drive.serial.serial_clock = !(data & 8));
687      vc1541_serial_clock_write (1, drive->drive.serial.serial_clock = !(data & 0x08));
631688   }
689
632690   vc1541_serial_atn_write (machine, 1, drive->drive.serial.serial_atn = 1);
633691}
634692
693
635694/*
636695 * via 6522 at 0x1c00
637696 * port a
r3311r3312
659718 *
660719 * irq to m6502 irq connected
661720 */
721
662722static void vc1541_via1_irq (running_machine *machine, int level)
663723{
664724   drive->via1irq = level;
665   DBG_LOG(2, "vc1541 via1 irq",("level %d %d\n",drive->via0irq,drive->via1irq));
666   cpunum_set_input_line (machine, drive->cpunumber,
667                 M6502_IRQ_LINE, drive->via1irq || drive->via0irq);
725   DBG_LOG(2, "vc1541 via1 irq", ("level %d %d\n", drive->via0irq, drive->via1irq));
726
727   cpunum_set_input_line (machine, drive->cpunumber, M6502_IRQ_LINE, drive->via1irq || drive->via0irq);
668728}
669729
670730static READ8_HANDLER( vc1541_via1_read_porta )
671731{
672   int data=drive->head.data[drive->image.pos];
673   DBG_LOG(2, "vc1541 drive",("port a read %.2x\n", data));
732   int data = drive->gcr.data[drive->pos];
733   DBG_LOG(2, "vc1541 drive", ("port a read %.2x\n", data));
674734   return data;
675735}
676736
677737static WRITE8_HANDLER( vc1541_via1_write_porta )
678738{
679   DBG_LOG(1, "vc1541 drive",("port a write %.2x\n", data));
739   DBG_LOG(1, "vc1541 drive", ("port a write %.2x\n", data));
680740}
681741
682742static  READ8_HANDLER( vc1541_via1_read_portb )
r3311r3312
687747   if (WRITEPROTECTED)
688748      value &= ~0x10;
689749#endif
690   if (drive->head.sync) {
691      value&=~0x80;
750
751   if (drive->gcr.sync)
752   {
753      value &= ~0x80;
692754   }
693755
694756   return value;
695757}
696758
759static int old = 0;
760
697761static WRITE8_HANDLER( vc1541_via1_write_portb )
698762{
699   static int old=0;
700   if (data!=old) {
763   if (data != old)
764   {
701765      DBG_LOG(1, "vc1541 drive",("%.2x\n", data));
702      if ((old&3)!=(data&3)) {
703         switch (old&3) {
766
767      if ((old & 0x03) != (data & 0x03))
768      {
769         switch (old & 0x03)
770         {
704771         case 0:
705            if ((data&3)==1) drive->track+=0.5;
706            else if ((data&3)==3) drive->track-=0.5;
772            if ((data & 0x03) == 1)
773               drive->track += 0.5;
774            else if ((data & 0x03) == 3)
775               drive->track -= 0.5;
707776            break;
777
708778         case 1:
709            if ((data&3)==2) drive->track+=0.5;
710            else if ((data&3)==0) drive->track-=0.5;
779            if ((data & 0x03) == 2)
780               drive->track += 0.5;
781            else if ((data & 0x03) == 0)
782               drive->track -= 0.5;
711783            break;
784
712785         case 2:
713            if ((data&3)==3) drive->track+=0.5;
714            else if ((data&3)==1) drive->track-=0.5;
786            if ((data & 0x03) == 3)
787               drive->track += 0.5;
788            else if ((data & 0x03) == 1)
789               drive->track -= 0.5;
715790            break;
791
716792         case 3:
717            if ((data&3)==0) drive->track+=0.5;
718            else if ((data&3)==2) drive->track-=0.5;
793            if ((data & 0x03) == 0)
794               drive->track += 0.5;
795            else if ((data & 0x03) == 2)
796               drive->track -= 0.5;
719797            break;
720798         }
721         if (drive->track<1) drive->track=1.0;
722         if (drive->track>35) drive->track=35;
799
800         logerror("Track #: %f\n", drive->track);
801
802         /* If we have reached the first or last track, we cannot proceed further! */
803         if (drive->track < 1)
804            drive->track = 1.0;
805         if (drive->track > 35)
806            drive->track = 35.0;
723807      }
724      if ( (drive->motor!=(data&4))||(drive->frequency!=(data&0x60)) )
808
809      if ((drive->motor != (data & 0x04)) || (drive->frequency != (data & 0x60)))
725810      {
726811         double tme;
727         drive->motor = data & 4;
812         drive->motor = data & 0x04;
728813         drive->frequency = data & 0x60;
729         tme=drive_times[drive->frequency>>5]*8*2;
814         tme = drive_times[drive->frequency >> 5];
815
730816         if (drive->motor)
731817         {
732818            if (attotime_to_double(timer_timeelapsed(drive->timer)) > 1.0e29)
819            {
733820               timer_reset(drive->timer, attotime_never);
821            }
734822            else
735               timer_adjust_periodic(drive->timer, attotime_zero, 0, double_to_attotime(tme));
823            {
824               timer_adjust_periodic(drive->timer, attotime_zero, 0, ATTOTIME_IN_HZ(tme));
825            }
736826         }
737827         else
738828         {
739829            timer_reset(drive->timer, attotime_never);
740830         }
741831      }
742      old=data;
832      old = data;
743833   }
744   drive->led = data & 8;
834   drive->led = data & 0x08;
745835}
746836
837static WRITE8_HANDLER( vc1541_via1_write_portca1 )
838{
839}
840
841static WRITE8_HANDLER( vc1541_via1_write_portca2 )
842{
843}
844
747845static const struct via6522_interface via2 =
748846{
749847   0,                           /*vc1541_via0_read_porta, */
r3311r3312
769867   0,                           /*via3_read_cb2, */
770868   vc1541_via1_write_porta,
771869   vc1541_via1_write_portb,
772   0,                                 /*via3_write_ca1, */
870   vc1541_via1_write_portca1,         /*via3_write_ca1, */
773871   0,                                 /*via3_write_cb1, */
774   0,                           /*via3_write_ca2, */
872   vc1541_via1_write_portca2,         /*via3_write_ca2, */
775873   0,                           /*via3_write_cb2, */
776874   vc1541_via1_irq
777875};
r3311r3312
9621060  5,6: output frequency select
9631061  7: input byte ready
9641062 */
1063
9651064static WRITE8_HANDLER ( c1551_port_w )
9661065{
967   static int old=0;
968   if (offset) {
969      DBG_LOG(1, "c1551 port",("write %.2x\n",data));
970      drive->drive.c1551.cpu_port=data;
1066   if (offset)
1067   {
1068      DBG_LOG(1, "c1551 port",("write %.2x\n", data));
1069      drive->drive.c1551.cpu_port = data;
9711070
972      if (data!=old) {
1071      if (data != old)
1072      {
9731073         DBG_LOG(1, "vc1541 drive",("%.2x\n", data));
974         if ((old&3)!=(data&3)) {
975            switch (old&3) {
1074     
1075         if ((old & 0x03) != (data & 0x03))
1076         {
1077            switch (old & 0x03)
1078            {
9761079            case 0:
977               if ((data&3)==1) drive->track+=0.5;
978               else if ((data&3)==3) drive->track-=0.5;
1080               if ((data & 0x03) == 1)
1081                  drive->track += 0.5;
1082               else if ((data & 0x03) == 3)
1083                  drive->track -= 0.5;
9791084               break;
1085
9801086            case 1:
981               if ((data&3)==2) drive->track+=0.5;
982               else if ((data&3)==0) drive->track-=0.5;
1087               if ((data & 0x03) == 2)
1088                  drive->track += 0.5;
1089               else if ((data & 0x03) == 0)
1090                  drive->track -= 0.5;
9831091               break;
1092
9841093            case 2:
985               if ((data&3)==3) drive->track+=0.5;
986               else if ((data&3)==1) drive->track-=0.5;
1094               if ((data & 0x03) == 3)
1095                  drive->track += 0.5;
1096               else if ((data & 0x03) == 1)
1097                  drive->track -= 0.5;
9871098               break;
1099
9881100            case 3:
989               if ((data&3)==0) drive->track+=0.5;
990               else if ((data&3)==2) drive->track-=0.5;
1101               if ((data & 0x03) == 0)
1102                  drive->track += 0.5;
1103               else if ((data & 0x03) == 2)
1104                  drive->track -= 0.5;
9911105               break;
9921106            }
993            if (drive->track<1) drive->track=1.0;
994            if (drive->track>35) drive->track=35;
1107
1108            /* If we have reached the first or last track, we cannot proceed further! */
1109            if (drive->track < 1)
1110               drive->track = 1.0;
1111            if (drive->track > 35)
1112               drive->track = 35.0;
9951113         }
996         if ( (drive->motor!=(data&4))||(drive->frequency!=(data&0x60)) ) {
1114
1115         if ( (drive->motor != (data & 0x04)) || (drive->frequency != (data & 0x60)) )
1116         {
9971117            double tme;
998            drive->motor = data & 4;
1118            drive->motor = data & 0x04;
9991119            drive->frequency = data & 0x60;
1000            tme=drive_times[drive->frequency>>5]*8*2;
1120
1121            tme = drive_times[drive->frequency >> 5];
10011122            if (drive->motor)
10021123            {
10031124               if (attotime_to_double(timer_timeelapsed(drive->timer)) > 1.0e29)
10041125                  timer_reset(drive->timer, attotime_never);
10051126               else
1006                  timer_adjust_periodic(drive->timer, attotime_zero, 0, double_to_attotime(tme));
1127                  timer_adjust_periodic(drive->timer, attotime_zero, 0, ATTOTIME_IN_HZ(tme));
10071128            }
10081129            else
10091130            {
10101131               timer_reset(drive->timer, attotime_never);
10111132            }
10121133         }
1013         old=data;
1134         old = data;
10141135      }
1015      drive->led = data & 8;
1016   } else {
1017      drive->drive.c1551.cpu_ddr=data;
1018      DBG_LOG(1, "c1551 ddr",("write %.2x\n",data));
1136      drive->led = data & 0x08;
1137   }
1138   else
1139   {
1140      drive->drive.c1551.cpu_ddr = data;
1141      DBG_LOG(1, "c1551 ddr", ("write %.2x\n", data));
10191142   }
10201143}
10211144
r3311r3312
10231146{
10241147   int data;
10251148
1026   if (offset) {
1027      data=0x7f;
1149   if (offset)
1150   {
1151      data = 0x7f;
10281152#if 0
10291153      if (WRITEPROTECTED)
10301154         data &= ~0x10;
10311155#endif
1032      if (drive->head.ready) {
1033         data|=0x80;
1034         drive->head.ready=0;
1156      if (drive->gcr.ready)
1157      {
1158         data |= 0x80;
1159         drive->gcr.ready = 0;
10351160      }
1036      data&=~drive->drive.c1551.cpu_ddr;
1037      data|=drive->drive.c1551.cpu_ddr&drive->drive.c1551.cpu_port;
1161
1162      data &= ~drive->drive.c1551.cpu_ddr;
1163      data |= drive->drive.c1551.cpu_ddr & drive->drive.c1551.cpu_port;
10381164      DBG_LOG(3, "c1551 port",("read %.2x\n", data));
1039   } else {
1040      data=drive->drive.c1551.cpu_ddr;
1165   }
1166   else
1167   {
1168      data = drive->drive.c1551.cpu_ddr;
10411169      DBG_LOG(3, "c1551 ddr",("read %.2x\n", data));
10421170   }
10431171   return data;
r3311r3312
10611189 */
10621190static int c1551_port_c_r(void)
10631191{
1064   int data=0xff;
1065   data&=~0x20;
1066   if (drive->head.sync) data&=~0x40;
1192   int data = 0xff;
1193   
1194   data &= ~0x20;
1195
1196   if (drive->gcr.sync)
1197      data &= ~0x40;
1198
10671199   return data;
10681200}
10691201
10701202static int c1551_port_b_r (void)
10711203{
1072   int data=drive->head.data[drive->image.pos];
1204   int data = drive->gcr.data[drive->pos];
10731205   DBG_LOG(2, "c1551 drive",("port a read %.2x\n", data));
10741206   return data;
10751207}
r3311r3312
10851217
10861218static void c1551x_write_data (running_machine *machine, TPI6525 *This, int data)
10871219{
1088   DBG_LOG(1, "c1551 cpu", ("%d write data %.2x\n",
1089                   cpu_getactivecpu (), data));
1220   DBG_LOG(1, "c1551 cpu", ("%d write data %.2x\n", cpu_getactivecpu (), data));
10901221#ifdef CPU_SYNC
10911222   cpu_sync();
10921223#endif
1224
10931225   tpi6525_0_port_a_w(machine, 0,data);
10941226}
10951227
10961228static int c1551x_read_data (running_machine *machine, TPI6525 *This)
10971229{
1098   int data=0xff;
1230   int data = 0xff;
10991231#ifdef CPU_SYNC
11001232   cpu_sync ();
11011233#endif
1102   data=tpi6525_0_port_a_r(machine, 0);
1103   DBG_LOG(2, "c1551 cpu",("%d read data %.2x\n",
1104                   cpu_getactivecpu (), data));
1234
1235   data = tpi6525_0_port_a_r(machine, 0);
1236   DBG_LOG(2, "c1551 cpu",("%d read data %.2x\n", cpu_getactivecpu (), data));
11051237   return data;
11061238}
11071239
11081240static void c1551x_write_handshake (running_machine *machine, TPI6525 *This, int data)
11091241{
1110   DBG_LOG(1, "c1551 cpu",("%d write handshake %.2x\n",
1111                   cpu_getactivecpu (), data));
1242   DBG_LOG(1, "c1551 cpu",("%d write handshake %.2x\n", cpu_getactivecpu (), data));
11121243#ifdef CPU_SYNC
11131244   cpu_sync();
11141245#endif
1246
11151247   tpi6525_0_port_c_w(machine, 0,data&0x40?0xff:0x7f);
11161248}
11171249
11181250static int c1551x_read_handshake (running_machine *machine, TPI6525 *This)
11191251{
1120   int data=0xff;
1252   int data = 0xff;
11211253#ifdef CPU_SYNC
11221254   cpu_sync();
11231255#endif
1124   data=tpi6525_0_port_c_r(machine, 0)&8?0x80:0;
1125   DBG_LOG(2, "c1551 cpu",("%d read handshake %.2x\n",
1126                   cpu_getactivecpu (), data));
1256
1257   data = tpi6525_0_port_c_r(machine, 0) & 0x08 ? 0x80 : 0x00;
1258   DBG_LOG(2, "c1551 cpu",("%d read handshake %.2x\n", cpu_getactivecpu (), data));
11271259   return data;
11281260}
11291261
11301262static int c1551x_read_status (running_machine *machine, TPI6525 *This)
11311263{
1132   int data=0xff;
1264   int data = 0xff;
11331265#ifdef CPU_SYNC
11341266   cpu_sync();
11351267#endif
1136   data=tpi6525_0_port_c_r(machine, 0)&3;
1137   DBG_LOG(1, "c1551 cpu",("%d read status %.2x\n",
1138                   cpu_getactivecpu (), data));
1268
1269   data = tpi6525_0_port_c_r(machine, 0) & 0x03;
1270   DBG_LOG(1, "c1551 cpu",("%d read status %.2x\n", cpu_getactivecpu (), data));
1271
11391272   return data;
11401273}
11411274
r3311r3312
11701303
11711304**************************************/
11721305
1173
11741306int drive_config (int type, int id, int mode, int cpunr, int devicenr)
11751307{
11761308   drive->type = type;
r3311r3312
11861318
11871319   if (type == type_1551)
11881320   {
1189      tpi6525[0].c.read=c1551_port_c_r;
1190      tpi6525[0].b.read=c1551_port_b_r;
1321      tpi6525[0].c.read = c1551_port_c_r;
1322      tpi6525[0].b.read = c1551_port_b_r;
11911323
11921324      /* time should be small enough to allow quitting of the irq
11931325      line before the next interrupt is triggered */
r3311r3312
12571389   MDRV_CPU_PROGRAM_MAP(_1571_map, 0)
12581390MACHINE_DRIVER_END
12591391
1392
12601393/**************************************
12611394
12621395   Device configurations
12631396
12641397**************************************/
12651398
1266DEVICE_IMAGE_LOAD(vc1541)
1399/* At a later stage we should move the loading and encoding part to an external function
1400for all formats / drive and then call it here and in similar DEVICE_IMAGE_LOADs for
1401the other drive types with 'image' as a parameter */
1402static DEVICE_IMAGE_LOAD( _1541 )
12671403{
1268   offset_init (format_d64);
1404   UINT8 sector_checksum, format_id_1, format_id_2;
1405   int i = 0, j, k, l;
1406   int format = 0, pos, filesize;
1407   UINT8 *temp_copy = NULL;
1408   const char *filetype;
12691409
1270   /* Fix me: we should load directly the GCR data */
1271   drive->image.data = image_ptr(image);
1272   if (!drive->image.data)
1410   filesize = image_length(image);
1411   filetype = image_filetype(image);
1412
1413   /* Find out which type of image we are loading */
1414   if (!mame_stricmp (filetype, "d64"))
1415   {
1416      switch (filesize)
1417      {
1418         case 0x2ab00:
1419            format = format_d64;
1420            break;
1421         case (0x2ab00 + 0x2ab):
1422            format = format_d64_err;
1423            break;
1424         case 0x30000:
1425            format = format_d64_40t;
1426            break;
1427         case (0x30000 + 0x300):
1428            format = format_d64_40t_err;
1429            break;
1430         default:
1431            logerror("The image you're trying to load has not the regular size of a .d64 image: \n");
1432            logerror("Image %s size %d\n", image_filename(image), filesize);
1433            return INIT_FAIL;
1434      }
1435   }
1436   // these are not supported yet!
1437   else if (!mame_stricmp (filetype, "d71"))
1438   {
1439      switch (filesize)
1440      {
1441         case 0x55600:
1442            format = format_d71;
1443            break;
1444         case (0x55600 + 0x556):
1445            format = format_d71_err;
1446            break;
1447         default:
1448            logerror("The image you're trying to load has not the regular size of a .d71 image: \n");
1449            logerror("Image %s size %d\n", image_filename(image), filesize);
1450            return INIT_FAIL;
1451      }
1452   }
1453   else if (!mame_stricmp (filetype, "d81"))
1454      format = format_d81;
1455   else if (!mame_stricmp (filetype, "d80"))
1456      format = format_d80;
1457   else if (!mame_stricmp (filetype, "d82"))
1458      format = format_d82;
1459   else
1460   {
1461      /* Still have to work on d67 & g64 images */
1462      logerror("Unsupported format\n");
12731463      return INIT_FAIL;
1464   }
1465   
1466   /* Set up track / sector map according to the format of the image */
1467   offset_init (format);
12741468
1275   logerror("floppy image %s loaded\n", image_filename(image));
1469   /* Claim memory */
1470   temp_copy = auto_malloc(filesize);
12761471
1472   if ((image_fread( image, temp_copy, filesize ) != filesize) || !filesize)
1473      return INIT_FAIL;
1474
1475   /* Start GCR encoding */
1476   format_id_1 = temp_copy[disk_id1(format)];   // can be modified by error code 29 -> ^ 0xff
1477   format_id_2 = temp_copy[disk_id2(format)];
1478
1479   for (k = 1; k <= D64_MAX_TRACKS; k++)
1480   {
1481/*      logerror("decoding track %d offset %d %d %d %d %d\n", k,
1482                  image_tracksector2offset(k, 0) / (16*16*16*16),
1483                  (image_tracksector2offset(k, 0) % (16*16*16*16)) / (16*16*16),
1484                  (image_tracksector2offset(k, 0) % (16*16*16)) / (16*16),
1485                  (image_tracksector2offset(k, 0) % (16*16)) / 16,
1486                  image_tracksector2offset(k, 0) % 16);
1487*/
1488
1489      for (l = 0; l < d64_sectors_per_track[k - 1]; l++)
1490      {
1491         // here we convert the sector data to gcr directly!
1492         // IMPORTANT: we shall implement errors in reading sectors!
1493         // these can modify e.g. header info $01 & $05
1494
1495         // first we set the position at which sector data starts in the image
1496         pos = image_tracksector2offset(k, l);
1497
1498         /*
1499            1. Header sync       FF FF FF FF FF (40 'on' bits, not GCR encoded)
1500            2. Header info       52 54 B5 29 4B 7A 5E 95 55 55 (10 GCR bytes)
1501            3. Header gap        55 55 55 55 55 55 55 55 55 (9 bytes, never read)
1502            4. Data sync         FF FF FF FF FF (40 'on' bits, not GCR encoded)
1503            5. Data block        55...4A (325 GCR bytes)
1504            6. Inter-sector gap  55 55 55 55...55 55 (4 to 19 bytes, never read)
1505         */
1506
1507         /* Header sync */
1508         for (j = 0; j < 5; j++)
1509            drive->gcr.data[i + j] = 0xff;
1510         i += 5;
1511
1512         /* Header info */
1513         /* These are 8 bytes unencoded, which become 10 bytes encoded */
1514         // $00 - header block ID ($08)                  // this byte can be modified by error code 20 -> 0xff
1515         // $01 - header block checksum (EOR of $02-$05)      // this byte can be modified by error code 27 -> ^ 0xff
1516         // $02 - Sector# of data block
1517         // $03 - Track# of data block
1518         gcr_double_2_gcr(0x08, l ^ k ^ format_id_2 ^ format_id_1, l, k, drive->gcr.data + i);   
1519         i += 5;
1520
1521         // $04 - Format ID byte #2
1522         // $05 - Format ID byte #1
1523         // $06 - $0F ("off" byte)
1524         // $07 - $0F ("off" byte)
1525         gcr_double_2_gcr(format_id_2, format_id_1, 0x0f, 0x0f, drive->gcr.data + i);
1526         i += 5;
1527
1528         /* Header gap */
1529         for (j = 0; j < 9; j++)
1530            drive->gcr.data[i + j] = 0x55;
1531         i += 9;
1532
1533         /* Data sync */
1534         for (j = 0; j < 5; j++)
1535            drive->gcr.data[i + j] = 0xff;
1536         i += 5;
1537
1538         /* Data block */
1539         // we first need to calculate the checksum of the 256 bytes of the sector
1540         sector_checksum = temp_copy[pos];
1541         for (j = 1; j < 256; j++)
1542            sector_checksum ^= temp_copy[pos + j];
1543
1544         /*
1545            $00      - data block ID ($07)
1546            $01-100  - 256 bytes sector data
1547            $101     - data block checksum (EOR of $01-100)
1548            $102-103 - $00 ("off" bytes, to make the sector size a multiple of 5)
1549         */
1550         gcr_double_2_gcr(0x07, temp_copy[pos], temp_copy[pos + 1],
1551                        temp_copy[pos + 2], drive->gcr.data + i);
1552         i += 5;
1553
1554         for (j = 1; j < 64; j++)
1555         {
1556            gcr_double_2_gcr(temp_copy[pos + 4 * j - 1], temp_copy[pos + 4 * j],
1557                           temp_copy[pos + 4 * j + 1], temp_copy[pos + 4 * j + 2], drive->gcr.data + i);
1558            i += 5;
1559         }
1560   
1561         gcr_double_2_gcr(temp_copy[pos + 255], sector_checksum, 0x00, 0x00, drive->gcr.data + i);
1562         i += 5;
1563
1564         /* Inter-sector gap */
1565         // "In tests that the author conducted on a real 1541 disk, gap sizes of 8  to  19 bytes were seen."
1566         // Here we put 14 as an average...
1567         for (j = 0; j < 14; j++)
1568            drive->gcr.data[i + j] = 0x55;
1569         i += 14;
1570      }
1571   }
1572
1573   logerror("Floppy image %s successfully loaded\n", image_filename(image));
12771574   return INIT_PASS;
12781575}
12791576
1280DEVICE_IMAGE_UNLOAD(vc1541)
1577static DEVICE_IMAGE_UNLOAD( _1541 )
12811578{
1282   /* writeback of image data */
1283   drive->image.data = NULL;
12841579}
12851580
12861581void vc1541_device_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
r3311r3312
12961591      case MESS_DEVINFO_INT_RESET_ON_LOAD:      info->i = 1; break;
12971592
12981593      /* --- the following bits of info are returned as pointers to data or functions --- */
1299      case MESS_DEVINFO_PTR_LOAD:               info->load = DEVICE_IMAGE_LOAD_NAME(vc1541); break;
1300      case MESS_DEVINFO_PTR_UNLOAD:            info->unload = DEVICE_IMAGE_UNLOAD_NAME(vc1541); break;
1594      case MESS_DEVINFO_PTR_LOAD:               info->load = DEVICE_IMAGE_LOAD_NAME(_1541); break;
1595      case MESS_DEVINFO_PTR_UNLOAD:            info->unload = DEVICE_IMAGE_UNLOAD_NAME(_1541); break;
13011596      case MESS_DEVINFO_PTR_DEV_SPECIFIC:         info->f = (genf *) drive_config; break;
13021597
13031598      /* --- the following bits of info are returned as NULL-terminated strings --- */
r3311r3312
13061601}
13071602
13081603
1309
13101604void c2031_device_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
13111605{
13121606   vc1541_device_getinfo(devclass, state, info);
13131607}
13141608
13151609
1316
13171610void c1551_device_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
13181611{
13191612   switch(state)
r3311r3312
13261619}
13271620
13281621
1329
13301622void c1571_device_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
13311623{
13321624   vc1541_device_getinfo(devclass, state, info);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team