Previous 15994 Revisions Next

r3254 Saturday 13th September, 2008 at 15:57:38 UTC by Fabio Priuli
[CBM] Renamed some other function / variable to avoid confusion. Separated drive initialization between simulated and emulated drives.
[src/mess/machine]c16.c c64.c cbmdrive.c cbmserb.c vc20.c

src/mess/machine/c16.c
r3253r3254
581581      memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xfec0, 0xfedf, 0, 0, SMH_NOP);
582582   }
583583
584   cbm_drive_0_config (SERIAL, 8);
585   cbm_drive_1_config (SERIAL, 9);
586
587584   if (has_c1551 || has_vc1541)      /* c1551 or vc1541 */
585   {
588586      drive_reset ();
589
590   cbm_serial_reset_write (0);
587   }
588   else                        /* simulated drives */
589   {
590      cbm_serial_reset_write (0);
591      cbm_drive_0_config (SERIAL, 8);
592      cbm_drive_1_config (SERIAL, 9);
593   }
591594}
592595
593596
src/mess/machine/cbmdrive.c
r3253r3254
2020      } \
2121   }
2222
23/***********************************************
2324
25   D64 images handling
26
27***********************************************/
28
2429/* tracks 1 to 35
2530 * sectors number from 0
2631 * each sector holds 256 data bytes
r3253r3254
129134}
130135
131136/* reads file into buffer */
132static void d64_readprg (CBM_Drive * c1551, int pos)
137static void d64_readprg (CBM_Drive * drive, int pos)
133138{
134139   int i;
135140
136141   for (i = 0; i < 16; i++)
137      c1551->filename[i] = toupper (c1551->image[pos + i + 3]);
142      drive->filename[i] = toupper (drive->image[pos + i + 3]);
138143
139   c1551->filename[i] = 0;
144   drive->filename[i] = 0;
140145
141   pos = d64_tracksector2offset (c1551->image[pos + 1], c1551->image[pos + 2]);
146   pos = d64_tracksector2offset (drive->image[pos + 1], drive->image[pos + 2]);
142147
143148   i = pos;
144   c1551->size = 0;
145   while (c1551->image[i] != 0)
149   drive->size = 0;
150   while (drive->image[i] != 0)
146151   {
147      c1551->size += 254;
148      i = d64_tracksector2offset (c1551->image[i], c1551->image[i + 1]);
152      drive->size += 254;
153      i = d64_tracksector2offset (drive->image[i], drive->image[i + 1]);
149154   }
150   c1551->size += c1551->image[i + 1];
155   drive->size += drive->image[i + 1];
151156
152   DBG_LOG (3, "d64 readprg", ("size %d\n", c1551->size));
157   DBG_LOG (3, "d64 readprg", ("size %d\n", drive->size));
153158
154   c1551->buffer = (UINT8*)realloc (c1551->buffer, c1551->size);
155   if (!c1551->buffer)
159   drive->buffer = (UINT8*)realloc (drive->buffer, drive->size);
160   if (!drive->buffer)
156161      fatalerror("out of memory %s %d\n", __FILE__, __LINE__);
157162
158   c1551->size--;
163   drive->size--;
159164
160165   DBG_LOG (3, "d64 readprg", ("track: %d sector: %d\n",
161                        c1551->image[pos + 1],
162                        c1551->image[pos + 2]));
166                        drive->image[pos + 1],
167                        drive->image[pos + 2]));
163168
164   for (i = 0; i < c1551->size; i += 254)
169   for (i = 0; i < drive->size; i += 254)
165170   {
166      if (i + 254 < c1551->size)
171      if (i + 254 < drive->size)
167172      {                        /* not last sector */
168         memcpy (c1551->buffer + i, c1551->image + pos + 2, 254);
169         pos = d64_tracksector2offset (c1551->image[pos + 0],
170                             c1551->image[pos + 1]);
173         memcpy (drive->buffer + i, drive->image + pos + 2, 254);
174         pos = d64_tracksector2offset (drive->image[pos + 0],
175                             drive->image[pos + 1]);
171176         DBG_LOG (3, "d64 readprg", ("track: %d sector: %d\n",
172                              c1551->image[pos],
173                              c1551->image[pos + 1]));
177                              drive->image[pos],
178                              drive->image[pos + 1]));
174179      }
175180      else
176181      {
177         memcpy (c1551->buffer + i, c1551->image + pos + 2, c1551->size - i);
182         memcpy (drive->buffer + i, drive->image + pos + 2, drive->size - i);
178183      }
179184   }
180185}
181186
182187/* reads sector into buffer */
183static void d64_read_sector (CBM_Drive * c1551, int track, int sector)
188static void d64_read_sector (CBM_Drive * drive, int track, int sector)
184189{
185190   int pos;
186191
187   snprintf (c1551->filename, sizeof (c1551->filename),
192   snprintf (drive->filename, sizeof (drive->filename),
188193           "track %d sector %d", track, sector);
189194
190195   pos = d64_tracksector2offset (track, sector);
191196
192   c1551->buffer = (UINT8*)realloc (c1551->buffer,256);
193   if (!c1551->buffer)
197   drive->buffer = (UINT8*)realloc (drive->buffer,256);
198   if (!drive->buffer)
194199      fatalerror("out of memory %s %d\n", __FILE__, __LINE__);
195200
196201   logerror("d64 read track %d sector %d\n", track, sector);
197202
198   memcpy (c1551->buffer, c1551->image + pos, 256);
199   c1551->size = 256;
200   c1551->pos = 0;
203   memcpy (drive->buffer, drive->image + pos, 256);
204   drive->size = 256;
205   drive->pos = 0;
201206}
202207
203208/* reads directory into buffer */
204static void d64_read_directory (CBM_Drive * c1551)
209static void d64_read_directory (CBM_Drive * drive)
205210{
206211   int pos, track, sector, i, j, blocksfree, addr = 0x0101/*0x1001*/;
207212
208   c1551->buffer = (UINT8*)realloc (c1551->buffer, 8 * 18 * 25);
209   if (!c1551->buffer)
213   drive->buffer = (UINT8*)realloc (drive->buffer, 8 * 18 * 25);
214   if (!drive->buffer)
210215      fatalerror("out of memory %s %d\n", __FILE__, __LINE__);
211216
212   c1551->size = 0;
217   drive->size = 0;
213218
214219   pos = d64_tracksector2offset (18, 0);
215   track = c1551->image[pos];
216   sector = c1551->image[pos + 1];
220   track = drive->image[pos];
221   sector = drive->image[pos + 1];
217222
218223   blocksfree = 0;
219224   for (j = 1, i = 4; j <= 35; j++, i += 4)
220225   {
221      blocksfree += c1551->image[pos + i];
226      blocksfree += drive->image[pos + i];
222227   }
223   c1551->buffer[c1551->size++] = addr & 0xff;
224   c1551->buffer[c1551->size++] = addr >> 8;
228   drive->buffer[drive->size++] = addr & 0xff;
229   drive->buffer[drive->size++] = addr >> 8;
225230   addr += 29;
226   c1551->buffer[c1551->size++] = addr & 0xff;
227   c1551->buffer[c1551->size++] = addr >> 8;
228   c1551->buffer[c1551->size++] = 0;
229   c1551->buffer[c1551->size++] = 0;
230   c1551->buffer[c1551->size++] = '\"';
231   drive->buffer[drive->size++] = addr & 0xff;
232   drive->buffer[drive->size++] = addr >> 8;
233   drive->buffer[drive->size++] = 0;
234   drive->buffer[drive->size++] = 0;
235   drive->buffer[drive->size++] = '\"';
231236   for (j = 0; j < 16; j++)
232      c1551->buffer[c1551->size++] = c1551->image[pos + 0x90 + j];
233/*memcpy(c1551->buffer+c1551->size,c1551->image+pos+0x90, 16);c1551->size+=16; */
234   c1551->buffer[c1551->size++] = '\"';
235   c1551->buffer[c1551->size++] = ' ';
236   c1551->buffer[c1551->size++] = c1551->image[pos + 162];
237   c1551->buffer[c1551->size++] = c1551->image[pos + 163];
238   c1551->buffer[c1551->size++] = ' ';
239   c1551->buffer[c1551->size++] = c1551->image[pos + 165];
240   c1551->buffer[c1551->size++] = c1551->image[pos + 166];
241   c1551->buffer[c1551->size++] = 0;
237      drive->buffer[drive->size++] = drive->image[pos + 0x90 + j];
238/*memcpy(drive->buffer+drive->size,drive->image+pos+0x90, 16);drive->size+=16; */
239   drive->buffer[drive->size++] = '\"';
240   drive->buffer[drive->size++] = ' ';
241   drive->buffer[drive->size++] = drive->image[pos + 162];
242   drive->buffer[drive->size++] = drive->image[pos + 163];
243   drive->buffer[drive->size++] = ' ';
244   drive->buffer[drive->size++] = drive->image[pos + 165];
245   drive->buffer[drive->size++] = drive->image[pos + 166];
246   drive->buffer[drive->size++] = 0;
242247
243248   while ((track >= 1) && (track <= 35))
244249   {
245250      pos = d64_tracksector2offset (track, sector);
246251      for (i = 2; i < 256; i += 32)
247252      {
248         if (c1551->image[pos + i] & 0x80)
253         if (drive->image[pos + i] & 0x80)
249254         {
250            int len, blocks = c1551->image[pos + i + 28]
251            + 256 * c1551->image[pos + i + 29];
255            int len, blocks = drive->image[pos + i + 28]
256            + 256 * drive->image[pos + i + 29];
252257            char dummy[10];
253258
254259            sprintf (dummy, "%d", blocks);
255260            len = strlen (dummy);
256261            addr += 29 - len;
257            c1551->buffer[c1551->size++] = addr & 0xff;
258            c1551->buffer[c1551->size++] = addr >> 8;
259            c1551->buffer[c1551->size++] = c1551->image[pos + i + 28];
260            c1551->buffer[c1551->size++] = c1551->image[pos + i + 29];
262            drive->buffer[drive->size++] = addr & 0xff;
263            drive->buffer[drive->size++] = addr >> 8;
264            drive->buffer[drive->size++] = drive->image[pos + i + 28];
265            drive->buffer[drive->size++] = drive->image[pos + i + 29];
261266            for (j = 4; j > len; j--)
262               c1551->buffer[c1551->size++] = ' ';
263            c1551->buffer[c1551->size++] = '\"';
267               drive->buffer[drive->size++] = ' ';
268            drive->buffer[drive->size++] = '\"';
264269            for (j = 0; j < 16; j++)
265               c1551->buffer[c1551->size++] = c1551->image[pos + i + 3 + j];
266            c1551->buffer[c1551->size++] = '\"';
267            c1551->buffer[c1551->size++] = ' ';
268            switch (c1551->image[pos + i] & 0x3f)
270               drive->buffer[drive->size++] = drive->image[pos + i + 3 + j];
271            drive->buffer[drive->size++] = '\"';
272            drive->buffer[drive->size++] = ' ';
273            switch (drive->image[pos + i] & 0x3f)
269274            {
270275            case 0:
271               c1551->buffer[c1551->size++] = 'D';
272               c1551->buffer[c1551->size++] = 'E';
273               c1551->buffer[c1551->size++] = 'L';
276               drive->buffer[drive->size++] = 'D';
277               drive->buffer[drive->size++] = 'E';
278               drive->buffer[drive->size++] = 'L';
274279               break;
275280            case 1:
276               c1551->buffer[c1551->size++] = 'S';
277               c1551->buffer[c1551->size++] = 'E';
278               c1551->buffer[c1551->size++] = 'Q';
281               drive->buffer[drive->size++] = 'S';
282               drive->buffer[drive->size++] = 'E';
283               drive->buffer[drive->size++] = 'Q';
279284               break;
280285            case 2:
281               c1551->buffer[c1551->size++] = 'P';
282               c1551->buffer[c1551->size++] = 'R';
283               c1551->buffer[c1551->size++] = 'G';
286               drive->buffer[drive->size++] = 'P';
287               drive->buffer[drive->size++] = 'R';
288               drive->buffer[drive->size++] = 'G';
284289               break;
285290            case 3:
286               c1551->buffer[c1551->size++] = 'U';
287               c1551->buffer[c1551->size++] = 'S';
288               c1551->buffer[c1551->size++] = 'R';
291               drive->buffer[drive->size++] = 'U';
292               drive->buffer[drive->size++] = 'S';
293               drive->buffer[drive->size++] = 'R';
289294               break;
290295            case 4:
291               c1551->buffer[c1551->size++] = 'R';
292               c1551->buffer[c1551->size++] = 'E';
293               c1551->buffer[c1551->size++] = 'L';
296               drive->buffer[drive->size++] = 'R';
297               drive->buffer[drive->size++] = 'E';
298               drive->buffer[drive->size++] = 'L';
294299               break;
295300            }
296            c1551->buffer[c1551->size++] = 0;
301            drive->buffer[drive->size++] = 0;
297302         }
298303      }
299      track = c1551->image[pos];
300      sector = c1551->image[pos + 1];
304      track = drive->image[pos];
305      sector = drive->image[pos + 1];
301306   }
302307   addr += 14;
303   c1551->buffer[c1551->size++] = addr & 0xff;
304   c1551->buffer[c1551->size++] = addr >> 8;
305   c1551->buffer[c1551->size++] = blocksfree & 0xff;
306   c1551->buffer[c1551->size++] = blocksfree >> 8;
307   memcpy (c1551->buffer + c1551->size, "BLOCKS FREE", 11);
308   c1551->size += 11;
309   c1551->buffer[c1551->size++] = 0;
308   drive->buffer[drive->size++] = addr & 0xff;
309   drive->buffer[drive->size++] = addr >> 8;
310   drive->buffer[drive->size++] = blocksfree & 0xff;
311   drive->buffer[drive->size++] = blocksfree >> 8;
312   memcpy (drive->buffer + drive->size, "BLOCKS FREE", 11);
313   drive->size += 11;
314   drive->buffer[drive->size++] = 0;
310315
311   strcpy (c1551->filename, "$");
316   strcpy (drive->filename, "$");
312317}
313318
314static int c1551_d64_command (CBM_Drive * c1551, unsigned char *name)
319static int d64_command (CBM_Drive * drive, unsigned char *name)
315320{
316321   int pos;
317322
r3253r3254
319324
320325   if (mame_stricmp ((char *) name, (char *) "$") == 0)
321326   {
322      d64_read_directory (c1551);
327      d64_read_directory (drive);
323328   }
324329   else
325330   {
326      if ((pos = d64_find (c1551, name)) == -1)
331      if ((pos = d64_find (drive, name)) == -1)
327332      {
328333         return 1;
329334      }
330      d64_readprg (c1551, pos);
335      d64_readprg (drive, pos);
331336   }
332337   return 0;
333338}
r3253r3254
435440      if (drive->drive == D64_IMAGE)
436441      {
437442         if ((type == 'P') || (type == 'S'))
438            rc = c1551_d64_command (drive, name);
443            rc = d64_command (drive, name);
439444      }
440445      if (!rc)
441446      {
r3253r3254
496501   drive->cmdpos = 0;
497502}
498503
504
505/***********************************************
506
507   Drive state update
508
509***********************************************/
510
511
499512 /*
500513  * 0x55 begin of command
501514  *
r3253r3254
513526  * status 3 for file not found
514527  * or filedata ended with status 3
515528  */
516void c1551_state (CBM_Drive * c1551)
529void c1551_state (CBM_Drive * drive)
517530{
518531   static int oldstate;
519532
520   oldstate = c1551->i.iec.state;
533   oldstate = drive->i.iec.state;
521534
522   switch (c1551->i.iec.state)
535   switch (drive->i.iec.state)
523536   {
524537   case -1:                     /* currently neccessary for correct init */
525      if (c1551->i.iec.handshakein)
538      if (drive->i.iec.handshakein)
526539      {
527         c1551->i.iec.state++;
540         drive->i.iec.state++;
528541      }
529542      break;
530543   case 0:
531      if (c1551->i.iec.datain == 0x55)
544      if (drive->i.iec.datain == 0x55)
532545      {
533         c1551->i.iec.status = 0;
534         c1551->i.iec.state++;
546         drive->i.iec.status = 0;
547         drive->i.iec.state++;
535548      }
536549      break;
537550   case 1:
538      if (c1551->i.iec.datain != 0x55)
551      if (drive->i.iec.datain != 0x55)
539552      {
540         c1551->i.iec.state = 10;
553         drive->i.iec.state = 10;
541554      }
542555      break;
543556   case 10:
544      if (c1551->i.iec.datain != 0)
557      if (drive->i.iec.datain != 0)
545558      {
546         c1551->i.iec.handshakeout = 0;
547         if (c1551->i.iec.datain == 0x84)
559         drive->i.iec.handshakeout = 0;
560         if (drive->i.iec.datain == 0x84)
548561         {
549            c1551->i.iec.state = 20;
550            if (c1551->pos + 1 == c1551->size)
551               c1551->i.iec.status = 3;
562            drive->i.iec.state = 20;
563            if (drive->pos + 1 == drive->size)
564               drive->i.iec.status = 3;
552565         }
553         else if (c1551->i.iec.datain == 0x83)
566         else if (drive->i.iec.datain == 0x83)
554567         {
555            c1551->i.iec.state = 40;
568            drive->i.iec.state = 40;
556569         }
557570         else
558571         {
559            c1551->i.iec.status = 0;
560            c1551->i.iec.state++;
572            drive->i.iec.status = 0;
573            drive->i.iec.state++;
561574         }
562575      }
563576      break;
564577   case 11:
565      if (!c1551->i.iec.handshakein)
578      if (!drive->i.iec.handshakein)
566579      {
567         c1551->i.iec.state++;
568         DBG_LOG(1,"c1551",("taken data %.2x\n",c1551->i.iec.datain));
569         if (c1551->cmdpos < sizeof (c1551->cmdbuffer))
570            c1551->cmdbuffer[c1551->cmdpos++] = c1551->i.iec.datain;
571         if ((c1551->i.iec.datain == 0x3f) || (c1551->i.iec.datain == 0x5f))
580         drive->i.iec.state++;
581         DBG_LOG(1,"c1551",("taken data %.2x\n",drive->i.iec.datain));
582         if (drive->cmdpos < sizeof (drive->cmdbuffer))
583            drive->cmdbuffer[drive->cmdpos++] = drive->i.iec.datain;
584         if ((drive->i.iec.datain == 0x3f) || (drive->i.iec.datain == 0x5f))
572585         {
573            cbm_command (c1551);
574            c1551->i.iec.state = 30;
586            cbm_command (drive);
587            drive->i.iec.state = 30;
575588         }
576         else if (((c1551->i.iec.datain & 0xf0) == 0x60))
589         else if (((drive->i.iec.datain & 0xf0) == 0x60))
577590         {
578            cbm_command (c1551);
579            if (c1551->state == READING)
591            cbm_command (drive);
592            if (drive->state == READING)
580593            {
581594            }
582            else if (c1551->state == WRITING)
595            else if (drive->state == WRITING)
583596            {
584597            }
585598            else
586               c1551->i.iec.status = 3;
599               drive->i.iec.status = 3;
587600         }
588         c1551->i.iec.handshakeout = 1;
601         drive->i.iec.handshakeout = 1;
589602      }
590603      break;
591604   case 12:
592      if (c1551->i.iec.datain == 0)
605      if (drive->i.iec.datain == 0)
593606      {
594         c1551->i.iec.state++;
607         drive->i.iec.state++;
595608      }
596609      break;
597610   case 13:
598      if (c1551->i.iec.handshakein)
611      if (drive->i.iec.handshakein)
599612      {
600         c1551->i.iec.state = 10;
613         drive->i.iec.state = 10;
601614      }
602615      break;
603616
604617   case 20:                     /* reading data */
605      if (!c1551->i.iec.handshakein)
618      if (!drive->i.iec.handshakein)
606619      {
607         c1551->i.iec.handshakeout = 1;
608         if (c1551->state == READING)
609            c1551->i.iec.dataout = c1551->buffer[c1551->pos++];
610         c1551->i.iec.state++;
620         drive->i.iec.handshakeout = 1;
621         if (drive->state == READING)
622            drive->i.iec.dataout = drive->buffer[drive->pos++];
623         drive->i.iec.state++;
611624      }
612625      break;
613626   case 21:                     /* reading data */
614      if (c1551->i.iec.handshakein)
627      if (drive->i.iec.handshakein)
615628      {
616         c1551->i.iec.handshakeout = 0;
617         c1551->i.iec.state++;
629         drive->i.iec.handshakeout = 0;
630         drive->i.iec.state++;
618631      }
619632      break;
620633   case 22:
621      if (c1551->i.iec.datain == 0)
634      if (drive->i.iec.datain == 0)
622635      {
623         c1551->i.iec.state++;
636         drive->i.iec.state++;
624637      }
625638      break;
626639   case 23:
627      if (!c1551->i.iec.handshakein)
640      if (!drive->i.iec.handshakein)
628641      {
629         c1551->i.iec.handshakeout = 1;
630         if (c1551->state == READING)
631            c1551->i.iec.state = 10;
642         drive->i.iec.handshakeout = 1;
643         if (drive->state == READING)
644            drive->i.iec.state = 10;
632645         else
633            c1551->i.iec.state = 0;
646            drive->i.iec.state = 0;
634647      }
635648      break;
636649
637650   case 30:                     /* end of command */
638      if (c1551->i.iec.datain == 0)
651      if (drive->i.iec.datain == 0)
639652      {
640         c1551->i.iec.state++;
653         drive->i.iec.state++;
641654      }
642655      break;
643656   case 31:
644      if (c1551->i.iec.handshakein)
657      if (drive->i.iec.handshakein)
645658      {
646         c1551->i.iec.state = 0;
659         drive->i.iec.state = 0;
647660      }
648661      break;
649662
650663   case 40:                     /* simple write */
651      if (!c1551->i.iec.handshakein)
664      if (!drive->i.iec.handshakein)
652665      {
653         c1551->i.iec.state++;
654         if ((c1551->state == 0) || (c1551->state == OPEN))
666         drive->i.iec.state++;
667         if ((drive->state == 0) || (drive->state == OPEN))
655668         {
656669            DBG_LOG (1, "c1551", ("taken data %.2x\n",
657                             c1551->i.iec.datain));
658            if (c1551->cmdpos < sizeof (c1551->cmdbuffer))
659               c1551->cmdbuffer[c1551->cmdpos++] = c1551->i.iec.datain;
670                             drive->i.iec.datain));
671            if (drive->cmdpos < sizeof (drive->cmdbuffer))
672               drive->cmdbuffer[drive->cmdpos++] = drive->i.iec.datain;
660673         }
661         else if (c1551->state == WRITING)
674         else if (drive->state == WRITING)
662675         {
663            DBG_LOG (1, "c1551", ("written data %.2x\n", c1551->i.iec.datain));
676            DBG_LOG (1, "c1551", ("written data %.2x\n", drive->i.iec.datain));
664677         }
665         c1551->i.iec.handshakeout = 1;
678         drive->i.iec.handshakeout = 1;
666679      }
667680      break;
668681   case 41:
669      if (c1551->i.iec.datain == 0)
682      if (drive->i.iec.datain == 0)
670683      {
671         c1551->i.iec.state++;
684         drive->i.iec.state++;
672685      }
673686      break;
674687   case 42:
675      if (c1551->i.iec.handshakein)
688      if (drive->i.iec.handshakein)
676689      {
677         c1551->i.iec.state = 10;
690         drive->i.iec.state = 10;
678691      }
679692      break;
680693   }
681694
682   if (oldstate != c1551->i.iec.state)
683      if (VERBOSE_LEVEL >= 1) logerror("state %d->%d %d\n", oldstate, c1551->i.iec.state, c1551->state);
695   if (oldstate != drive->i.iec.state)
696      if (VERBOSE_LEVEL >= 1) logerror("state %d->%d %d\n", oldstate, drive->i.iec.state, drive->state);
684697}
685698
686static int vc1541_time_greater(CBM_Drive * vc1541, attotime threshold)
699static int vc1541_time_greater(CBM_Drive * drive, attotime threshold)
687700{
688701   return attotime_compare(
689      attotime_sub(timer_get_time (), vc1541->i.serial.time),
702      attotime_sub(timer_get_time (), drive->i.serial.time),
690703      threshold) > 0;
691704}
692705
693void vc1541_state (CBM_Drive * vc1541)
706void vc1541_state (CBM_Drive * drive)
694707{
695   int oldstate = vc1541->i.serial.state;
708   int oldstate = drive->i.serial.state;
696709
697   switch (vc1541->i.serial.state)
710   switch (drive->i.serial.state)
698711   {
699712   case 0:
700713      if (!cbm_serial.atn[0] && !cbm_serial.clock[0])
701714      {
702         vc1541->i.serial.data = 0;
703         vc1541->i.serial.state = 2;
715         drive->i.serial.data = 0;
716         drive->i.serial.state = 2;
704717         break;
705718      }
706      if (!cbm_serial.clock[0] && vc1541->i.serial.forme)
719      if (!cbm_serial.clock[0] && drive->i.serial.forme)
707720      {
708         vc1541->i.serial.data = 0;
709         vc1541->i.serial.state++;
721         drive->i.serial.data = 0;
722         drive->i.serial.state++;
710723         break;
711724      }
712725      break;
713726   case 1:
714727      if (!cbm_serial.atn[0])
715728      {
716         vc1541->i.serial.state++;
729         drive->i.serial.state++;
717730         break;
718731      }
719732      if (cbm_serial.clock[0])
720733      {
721         vc1541->i.serial.broadcast = 0;
722         vc1541->i.serial.data = 1;
723         vc1541->i.serial.state = 100;
724         vc1541->i.serial.last = 0;
725         vc1541->i.serial.value = 0;
726         vc1541->i.serial.time = timer_get_time ();
734         drive->i.serial.broadcast = 0;
735         drive->i.serial.data = 1;
736         drive->i.serial.state = 100;
737         drive->i.serial.last = 0;
738         drive->i.serial.value = 0;
739         drive->i.serial.time = timer_get_time ();
727740         break;
728741      }
729742      break;
730743   case 2:
731744      if (cbm_serial.clock[0])
732745      {
733         vc1541->i.serial.broadcast = 1;
734         vc1541->i.serial.data = 1;
735         vc1541->i.serial.state = 100;
736         vc1541->i.serial.last = 0;
737         vc1541->i.serial.value = 0;
738         vc1541->i.serial.time = timer_get_time ();
746         drive->i.serial.broadcast = 1;
747         drive->i.serial.data = 1;
748         drive->i.serial.state = 100;
749         drive->i.serial.last = 0;
750         drive->i.serial.value = 0;
751         drive->i.serial.time = timer_get_time ();
739752         break;
740753      }
741754      break;
r3253r3254
743756   case 100:
744757      if (!cbm_serial.clock[0])
745758      {
746         vc1541->i.serial.state++;
759         drive->i.serial.state++;
747760         break;
748761      }
749762      break;
r3253r3254
755768   case 112:
756769   case 114:
757770      if (!cbm_serial.clock[0])
758         vc1541->i.serial.state++;
771         drive->i.serial.state++;
759772      break;
760773   case 101:
761774      if (cbm_serial.clock[0])
762775      {
763         vc1541->i.serial.value |= cbm_serial.data[0] ? 1 : 0;
764         vc1541->i.serial.state++;
776         drive->i.serial.value |= cbm_serial.data[0] ? 1 : 0;
777         drive->i.serial.state++;
765778      }
766779      break;
767780   case 103:
768781      if (cbm_serial.clock[0])
769782      {
770         vc1541->i.serial.value |= cbm_serial.data[0] ? 2 : 0;
771         vc1541->i.serial.state++;
783         drive->i.serial.value |= cbm_serial.data[0] ? 2 : 0;
784         drive->i.serial.state++;
772785      }
773786      break;
774787   case 105:
775788      if (cbm_serial.clock[0])
776789      {
777         vc1541->i.serial.value |= cbm_serial.data[0] ? 4 : 0;
778         vc1541->i.serial.state++;
790         drive->i.serial.value |= cbm_serial.data[0] ? 4 : 0;
791         drive->i.serial.state++;
779792      }
780793      break;
781794   case 107:
782795      if (cbm_serial.clock[0])
783796      {
784         vc1541->i.serial.value |= cbm_serial.data[0] ? 8 : 0;
785         vc1541->i.serial.state++;
797         drive->i.serial.value |= cbm_serial.data[0] ? 8 : 0;
798         drive->i.serial.state++;
786799      }
787800      break;
788801   case 109:
789802      if (cbm_serial.clock[0])
790803      {
791         vc1541->i.serial.value |= cbm_serial.data[0] ? 0x10 : 0;
792         vc1541->i.serial.state++;
804         drive->i.serial.value |= cbm_serial.data[0] ? 0x10 : 0;
805         drive->i.serial.state++;
793806      }
794807      break;
795808   case 111:
796809      if (cbm_serial.clock[0])
797810      {
798         vc1541->i.serial.value |= cbm_serial.data[0] ? 0x20 : 0;
799         vc1541->i.serial.state++;
811         drive->i.serial.value |= cbm_serial.data[0] ? 0x20 : 0;
812         drive->i.serial.state++;
800813      }
801814      break;
802815   case 113:
803816      if (cbm_serial.clock[0])
804817      {
805         vc1541->i.serial.value |= cbm_serial.data[0] ? 0x40 : 0;
806         vc1541->i.serial.state++;
818         drive->i.serial.value |= cbm_serial.data[0] ? 0x40 : 0;
819         drive->i.serial.state++;
807820      }
808821      break;
809822   case 115:
810823      if (cbm_serial.clock[0])
811824      {
812         vc1541->i.serial.value |= cbm_serial.data[0] ? 0x80 : 0;
813         if (vc1541->i.serial.broadcast
814            && (((vc1541->i.serial.value & 0xf0) == 0x20)
815               || ((vc1541->i.serial.value & 0xf0) == 0x40)))
825         drive->i.serial.value |= cbm_serial.data[0] ? 0x80 : 0;
826         if (drive->i.serial.broadcast
827            && (((drive->i.serial.value & 0xf0) == 0x20)
828               || ((drive->i.serial.value & 0xf0) == 0x40)))
816829         {
817            vc1541->i.serial.forme = (vc1541->i.serial.value & 0xf)
818               == vc1541->i.serial.device;
819            if (!vc1541->i.serial.forme)
830            drive->i.serial.forme = (drive->i.serial.value & 0xf)
831               == drive->i.serial.device;
832            if (!drive->i.serial.forme)
820833            {
821               vc1541->i.serial.state = 160;
834               drive->i.serial.state = 160;
822835               break;
823836            }
824837         }
825         if (vc1541->i.serial.forme)
838         if (drive->i.serial.forme)
826839         {
827            if (vc1541->cmdpos < sizeof (vc1541->cmdbuffer))
828               vc1541->cmdbuffer[vc1541->cmdpos++] = vc1541->i.serial.value;
840            if (drive->cmdpos < sizeof (drive->cmdbuffer))
841               drive->cmdbuffer[drive->cmdpos++] = drive->i.serial.value;
829842            DBG_LOG (1, "serial read", ("%s %s %.2x\n",
830                     vc1541->i.serial.broadcast ? "broad" : "",
831                     vc1541->i.serial.last ? "last" : "",
832                                 vc1541->i.serial.value));
843                     drive->i.serial.broadcast ? "broad" : "",
844                     drive->i.serial.last ? "last" : "",
845                                 drive->i.serial.value));
833846         }
834         vc1541->i.serial.state++;
847         drive->i.serial.state++;
835848      }
836849      break;
837850   case 116:
838851      if (!cbm_serial.clock[0])
839852      {
840         if (vc1541->i.serial.last)
841            vc1541->i.serial.state = 130;
853         if (drive->i.serial.last)
854            drive->i.serial.state = 130;
842855         else
843            vc1541->i.serial.state++;
844         if (vc1541->i.serial.broadcast &&
845            ((vc1541->i.serial.value == 0x3f) || (vc1541->i.serial.value == 0x5f)
846             || ((vc1541->i.serial.value & 0xf0) == 0x60)))
856            drive->i.serial.state++;
857         if (drive->i.serial.broadcast &&
858            ((drive->i.serial.value == 0x3f) || (drive->i.serial.value == 0x5f)
859             || ((drive->i.serial.value & 0xf0) == 0x60)))
847860         {
848            cbm_command (vc1541);
861            cbm_command (drive);
849862         }
850         vc1541->i.serial.time = timer_get_time ();
851         vc1541->i.serial.data = 0;
863         drive->i.serial.time = timer_get_time ();
864         drive->i.serial.data = 0;
852865         break;
853866      }
854867      break;
855868   case 117:
856      if (vc1541->i.serial.forme && ((vc1541->i.serial.value & 0xf0) == 0x60)
857         && vc1541->i.serial.broadcast && cbm_serial.atn[0])
869      if (drive->i.serial.forme && ((drive->i.serial.value & 0xf0) == 0x60)
870         && drive->i.serial.broadcast && cbm_serial.atn[0])
858871      {
859         if (vc1541->state == READING)
872         if (drive->state == READING)
860873         {
861            vc1541->i.serial.state = 200;
874            drive->i.serial.state = 200;
862875            break;
863876         }
864         else if (vc1541->state != WRITING)
877         else if (drive->state != WRITING)
865878         {
866            vc1541->i.serial.state = 150;
879            drive->i.serial.state = 150;
867880            break;
868881         }
869882      }
870      if (((vc1541->i.serial.value == 0x3f)
871          || (vc1541->i.serial.value == 0x5f))
872         && vc1541->i.serial.broadcast && cbm_serial.atn[0])
883      if (((drive->i.serial.value == 0x3f)
884          || (drive->i.serial.value == 0x5f))
885         && drive->i.serial.broadcast && cbm_serial.atn[0])
873886      {
874         vc1541->i.serial.data = 1;
875         vc1541->i.serial.state = 140;
887         drive->i.serial.data = 1;
888         drive->i.serial.state = 140;
876889         break;
877890      }
878891      if (cbm_serial.clock[0])
879892      {
880         vc1541->i.serial.time = timer_get_time ();
881         vc1541->i.serial.broadcast = !cbm_serial.atn[0];
882         vc1541->i.serial.data = 1;
883         vc1541->i.serial.value = 0;
884         vc1541->i.serial.state++;
893         drive->i.serial.time = timer_get_time ();
894         drive->i.serial.broadcast = !cbm_serial.atn[0];
895         drive->i.serial.data = 1;
896         drive->i.serial.value = 0;
897         drive->i.serial.state++;
885898         break;
886899      }
887900      break;
r3253r3254
890903   case 118:
891904      if (!cbm_serial.clock[0])
892905      {
893         vc1541->i.serial.value = 0;
894         vc1541->i.serial.state = 101;
895         vc1541->i.serial.data = 1;
906         drive->i.serial.value = 0;
907         drive->i.serial.state = 101;
908         drive->i.serial.data = 1;
896909         break;
897910      }
898      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(200)))
911      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(200)))
899912      {
900         vc1541->i.serial.data = 0;
901         vc1541->i.serial.last = 1;
902         vc1541->i.serial.state++;
903         vc1541->i.serial.time = timer_get_time ();
913         drive->i.serial.data = 0;
914         drive->i.serial.last = 1;
915         drive->i.serial.state++;
916         drive->i.serial.time = timer_get_time ();
904917         break;
905918      }
906919      break;
907920   case 119:
908      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(60)))
921      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(60)))
909922      {
910         vc1541->i.serial.value = 0;
911         vc1541->i.serial.data = 1;
912         vc1541->i.serial.state = 100;
923         drive->i.serial.value = 0;
924         drive->i.serial.data = 1;
925         drive->i.serial.state = 100;
913926         break;
914927      }
915928      break;
916929
917930   case 130:                     /* last byte of talk */
918      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(60)))
931      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(60)))
919932      {
920         vc1541->i.serial.data = 1;
921         vc1541->i.serial.state = 0;
933         drive->i.serial.data = 1;
934         drive->i.serial.state = 0;
922935         break;
923936      }
924937      break;
r3253r3254
926939   case 131:
927940      if (cbm_serial.clock[0])
928941      {
929         vc1541->i.serial.state = 0;
942         drive->i.serial.state = 0;
930943      }
931944      break;
932945
933946   case 140:                     /* end of talk */
934947      if (cbm_serial.clock[0])
935948      {
936         vc1541->i.serial.state = 0;
949         drive->i.serial.state = 0;
937950      }
938951      break;
939952
940953   case 150:                     /* file not found */
941954      if (cbm_serial.atn[0])
942955      {
943         vc1541->i.serial.state++;
944         vc1541->i.serial.time = timer_get_time ();
956         drive->i.serial.state++;
957         drive->i.serial.time = timer_get_time ();
945958         break;
946959      }
947960      break;
948961   case 151:
949      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(1000)))
962      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(1000)))
950963      {
951         vc1541->i.serial.state++;
952         vc1541->i.serial.clock = 0;
953         vc1541->i.serial.time = timer_get_time ();
964         drive->i.serial.state++;
965         drive->i.serial.clock = 0;
966         drive->i.serial.time = timer_get_time ();
954967         break;
955968      }
956969      break;
957970   case 152:
958      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(50)))
971      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(50)))
959972      {
960         vc1541->i.serial.state++;
961         vc1541->i.serial.clock = 1;
973         drive->i.serial.state++;
974         drive->i.serial.clock = 1;
962975         break;
963976      }
964977      break;
965978   case 153:
966979      if (cbm_serial.clock[0])
967980      {
968         vc1541->i.serial.state = 0;
981         drive->i.serial.state = 0;
969982      }
970983      break;
971984
972985   case 160:                     /* not for me */
973986      if (cbm_serial.atn[0])
974987      {
975         vc1541->i.serial.state = 0;
976         vc1541->i.serial.time = timer_get_time ();
988         drive->i.serial.state = 0;
989         drive->i.serial.time = timer_get_time ();
977990         break;
978991      }
979992      break;
r3253r3254
981994   case 200:
982995      if (cbm_serial.clock[0])
983996      {
984         vc1541->i.serial.state++;
985         vc1541->i.serial.clock = 0;
986         vc1541->i.serial.time = timer_get_time ();
997         drive->i.serial.state++;
998         drive->i.serial.clock = 0;
999         drive->i.serial.time = timer_get_time ();
9871000         break;
9881001      }
9891002      break;
9901003   case 201:
991      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(80)))
1004      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(80)))
9921005      {
993         vc1541->i.serial.clock = 1;
994         vc1541->i.serial.data = 1;
995         vc1541->i.serial.state = 300;
1006         drive->i.serial.clock = 1;
1007         drive->i.serial.data = 1;
1008         drive->i.serial.state = 300;
9961009         break;
9971010      }
9981011      break;
r3253r3254
10001013   case 300:
10011014      if (!cbm_serial.atn[0])
10021015      {
1003         vc1541->i.serial.state = 330;
1004         vc1541->i.serial.data = 1;
1005         vc1541->i.serial.clock = 1;
1016         drive->i.serial.state = 330;
1017         drive->i.serial.data = 1;
1018         drive->i.serial.clock = 1;
10061019         break;
10071020      }
10081021      if (cbm_serial.data[0])
10091022      {
1010         vc1541->i.serial.value = vc1541->buffer[vc1541->pos];
1011         vc1541->i.serial.clock = 0;
1012         vc1541->i.serial.data = (vc1541->i.serial.value & 1) ? 1 : 0;
1013         vc1541->i.serial.state++;
1014         vc1541->i.serial.time = timer_get_time ();
1023         drive->i.serial.value = drive->buffer[drive->pos];
1024         drive->i.serial.clock = 0;
1025         drive->i.serial.data = (drive->i.serial.value & 1) ? 1 : 0;
1026         drive->i.serial.state++;
1027         drive->i.serial.time = timer_get_time ();
10151028         break;
10161029      }
10171030      break;
10181031   case 301:
10191032      if (!cbm_serial.atn[0])
10201033      {
1021         vc1541->i.serial.state = 330;
1022         vc1541->i.serial.data = 1;
1023         vc1541->i.serial.clock = 1;
1034         drive->i.serial.state = 330;
1035         drive->i.serial.data = 1;
1036         drive->i.serial.clock = 1;
10241037         break;
10251038      }
1026      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(40)))
1039      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(40)))
10271040      {
1028         vc1541->i.serial.clock = 1;
1029         vc1541->i.serial.state++;
1030         vc1541->i.serial.time = timer_get_time ();
1041         drive->i.serial.clock = 1;
1042         drive->i.serial.state++;
1043         drive->i.serial.time = timer_get_time ();
10311044         break;
10321045      }
10331046      break;
r3253r3254
10401053   case 315:
10411054      if (!cbm_serial.atn[0])
10421055      {
1043         vc1541->i.serial.state = 330;
1044         vc1541->i.serial.data = 1;
1045         vc1541->i.serial.clock = 1;
1056         drive->i.serial.state = 330;
1057         drive->i.serial.data = 1;
1058         drive->i.serial.clock = 1;
10461059         break;
10471060      }
1048      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(20)))
1061      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(20)))
10491062      {
1050         vc1541->i.serial.clock = 1;
1051         vc1541->i.serial.state++;
1052         vc1541->i.serial.time = timer_get_time ();
1063         drive->i.serial.clock = 1;
1064         drive->i.serial.state++;
1065         drive->i.serial.time = timer_get_time ();
10531066         break;
10541067      }
10551068      break;
10561069   case 302:
10571070      if (!cbm_serial.atn[0])
10581071      {
1059         vc1541->i.serial.state = 330;
1060         vc1541->i.serial.data = 1;
1061         vc1541->i.serial.clock = 1;
1072         drive->i.serial.state = 330;
1073         drive->i.serial.data = 1;
1074         drive->i.serial.clock = 1;
10621075         break;
10631076      }
1064      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(20)))
1077      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(20)))
10651078      {
1066         vc1541->i.serial.data = vc1541->i.serial.value & 2 ? 1 : 0;
1067         vc1541->i.serial.clock = 0;
1068         vc1541->i.serial.state++;
1069         vc1541->i.serial.time = timer_get_time ();
1079         drive->i.serial.data = drive->i.serial.value & 2 ? 1 : 0;
1080         drive->i.serial.clock = 0;
1081         drive->i.serial.state++;
1082         drive->i.serial.time = timer_get_time ();
10701083         break;
10711084      }
10721085      break;
10731086   case 304:
10741087      if (!cbm_serial.atn[0])
10751088      {
1076         vc1541->i.serial.state = 330;
1077         vc1541->i.serial.data = 1;
1078         vc1541->i.serial.clock = 1;
1089         drive->i.serial.state = 330;
1090         drive->i.serial.data = 1;
1091         drive->i.serial.clock = 1;
10791092         break;
10801093      }
1081      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(20)))
1094      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(20)))
10821095      {
1083         vc1541->i.serial.data = vc1541->i.serial.value & 4 ? 1 : 0;
1084         vc1541->i.serial.clock = 0;
1085         vc1541->i.serial.state++;
1086         vc1541->i.serial.time = timer_get_time ();
1096         drive->i.serial.data = drive->i.serial.value & 4 ? 1 : 0;
1097         drive->i.serial.clock = 0;
1098         drive->i.serial.state++;
1099         drive->i.serial.time = timer_get_time ();
10871100         break;
10881101      }
10891102      break;
10901103   case 306:
10911104      if (!cbm_serial.atn[0])
10921105      {
1093         vc1541->i.serial.state = 330;
1094         vc1541->i.serial.data = 1;
1095         vc1541->i.serial.clock = 1;
1106         drive->i.serial.state = 330;
1107         drive->i.serial.data = 1;
1108         drive->i.serial.clock = 1;
10961109         break;
10971110      }
1098      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(20)))
1111      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(20)))
10991112      {
1100         vc1541->i.serial.data = vc1541->i.serial.value & 8 ? 1 : 0;
1101         vc1541->i.serial.clock = 0;
1102         vc1541->i.serial.state++;
1103         vc1541->i.serial.time = timer_get_time ();
1113         drive->i.serial.data = drive->i.serial.value & 8 ? 1 : 0;
1114         drive->i.serial.clock = 0;
1115         drive->i.serial.state++;
1116         drive->i.serial.time = timer_get_time ();
11041117         break;
11051118      }
11061119      break;
11071120   case 308:
11081121      if (!cbm_serial.atn[0])
11091122      {
1110         vc1541->i.serial.state = 330;
1111         vc1541->i.serial.data = 1;
1112         vc1541->i.serial.clock = 1;
1123         drive->i.serial.state = 330;
1124         drive->i.serial.data = 1;
1125         drive->i.serial.clock = 1;
11131126         break;
11141127      }
1115      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(20)))
1128      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(20)))
11161129      {
1117         vc1541->i.serial.data = vc1541->i.serial.value & 0x10 ? 1 : 0;
1118         vc1541->i.serial.clock = 0;
1119         vc1541->i.serial.state++;
1120         vc1541->i.serial.time = timer_get_time ();
1130         drive->i.serial.data = drive->i.serial.value & 0x10 ? 1 : 0;
1131         drive->i.serial.clock = 0;
1132         drive->i.serial.state++;
1133         drive->i.serial.time = timer_get_time ();
11211134         break;
11221135      }
11231136      break;
11241137   case 310:
11251138      if (!cbm_serial.atn[0])
11261139      {
1127         vc1541->i.serial.state = 330;
1128         vc1541->i.serial.data = 1;
1129         vc1541->i.serial.clock = 1;
1140         drive->i.serial.state = 330;
1141         drive->i.serial.data = 1;
1142         drive->i.serial.clock = 1;
11301143         break;
11311144      }
1132      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(20)))
1145      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(20)))
11331146      {
1134         vc1541->i.serial.data = vc1541->i.serial.value & 0x20 ? 1 : 0;
1135         vc1541->i.serial.clock = 0;
1136         vc1541->i.serial.state++;
1137         vc1541->i.serial.time = timer_get_time ();
1147         drive->i.serial.data = drive->i.serial.value & 0x20 ? 1 : 0;
1148         drive->i.serial.clock = 0;
1149         drive->i.serial.state++;
1150         drive->i.serial.time = timer_get_time ();
11381151         break;
11391152      }
11401153      break;
11411154   case 312:
11421155      if (!cbm_serial.atn[0])
11431156      {
1144         vc1541->i.serial.state = 330;
1145         vc1541->i.serial.data = 1;
1146         vc1541->i.serial.clock = 1;
1157         drive->i.serial.state = 330;
1158         drive->i.serial.data = 1;
1159         drive->i.serial.clock = 1;
11471160         break;
11481161      }
1149      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(20)))
1162      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(20)))
11501163      {
1151         vc1541->i.serial.data = vc1541->i.serial.value & 0x40 ? 1 : 0;
1152         vc1541->i.serial.clock = 0;
1153         vc1541->i.serial.state++;
1154         vc1541->i.serial.time = timer_get_time ();
1164         drive->i.serial.data = drive->i.serial.value & 0x40 ? 1 : 0;
1165         drive->i.serial.clock = 0;
1166         drive->i.serial.state++;
1167         drive->i.serial.time = timer_get_time ();
11551168         break;
11561169      }
11571170      break;
11581171   case 314:
11591172      if (!cbm_serial.atn[0])
11601173      {
1161         vc1541->i.serial.state = 330;
1162         vc1541->i.serial.data = 1;
1163         vc1541->i.serial.clock = 1;
1174         drive->i.serial.state = 330;
1175         drive->i.serial.data = 1;
1176         drive->i.serial.clock = 1;
11641177         break;
11651178      }
1166      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(20)))
1179      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(20)))
11671180      {
1168         vc1541->i.serial.data = vc1541->i.serial.value & 0x80 ? 1 : 0;
1169         vc1541->i.serial.clock = 0;
1170         vc1541->i.serial.state++;
1171         vc1541->i.serial.time = timer_get_time ();
1181         drive->i.serial.data = drive->i.serial.value & 0x80 ? 1 : 0;
1182         drive->i.serial.clock = 0;
1183         drive->i.serial.state++;
1184         drive->i.serial.time = timer_get_time ();
11721185         break;
11731186      }
11741187      break;
11751188   case 316:
11761189      if (!cbm_serial.atn[0])
11771190      {
1178         vc1541->i.serial.state = 330;
1179         vc1541->i.serial.data = 1;
1180         vc1541->i.serial.clock = 1;
1191         drive->i.serial.state = 330;
1192         drive->i.serial.data = 1;
1193         drive->i.serial.clock = 1;
11811194         break;
11821195      }
1183      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(20)))
1196      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(20)))
11841197      {
1185         DBG_LOG (1, "vc1541", ("%.2x written\n", vc1541->i.serial.value));
1186         vc1541->i.serial.data = 1;
1187         vc1541->i.serial.clock = 0;
1188         vc1541->i.serial.state++;
1189         vc1541->i.serial.time = timer_get_time ();
1198         DBG_LOG (1, "vc1541", ("%.2x written\n", drive->i.serial.value));
1199         drive->i.serial.data = 1;
1200         drive->i.serial.clock = 0;
1201         drive->i.serial.state++;
1202         drive->i.serial.time = timer_get_time ();
11901203         break;
11911204      }
11921205      break;
11931206   case 317:
11941207      if (!cbm_serial.atn[0])
11951208      {
1196         vc1541->i.serial.state = 330;
1197         vc1541->i.serial.data = 1;
1198         vc1541->i.serial.clock = 1;
1209         drive->i.serial.state = 330;
1210         drive->i.serial.data = 1;
1211         drive->i.serial.clock = 1;
11991212         break;
12001213      }
12011214      if (!cbm_serial.data[0])
12021215      {
1203         vc1541->i.serial.state++;
1204         vc1541->i.serial.time = timer_get_time ();
1216         drive->i.serial.state++;
1217         drive->i.serial.time = timer_get_time ();
12051218         break;
12061219      }
12071220      break;
12081221   case 318:
12091222      if (!cbm_serial.atn[0])
12101223      {
1211         vc1541->i.serial.state = 330;
1212         vc1541->i.serial.data = 1;
1213         vc1541->i.serial.clock = 1;
1224         drive->i.serial.state = 330;
1225         drive->i.serial.data = 1;
1226         drive->i.serial.clock = 1;
12141227         break;
12151228      }
1216      if (vc1541->pos + 1 == vc1541->size)
1229      if (drive->pos + 1 == drive->size)
12171230      {
1218         vc1541->i.serial.clock = 1;
1219         vc1541->i.serial.state = 0;
1231         drive->i.serial.clock = 1;
1232         drive->i.serial.state = 0;
12201233         break;
12211234      }
1222      if (vc1541->pos + 2 == vc1541->size)
1235      if (drive->pos + 2 == drive->size)
12231236      {
1224         vc1541->pos++;
1225         vc1541->i.serial.state = 320;
1237         drive->pos++;
1238         drive->i.serial.state = 320;
12261239         break;
12271240      }
1228      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(100)))
1241      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(100)))
12291242      {
1230         vc1541->pos++;
1231         vc1541->i.serial.clock = 1;
1232         vc1541->i.serial.state = 300;
1243         drive->pos++;
1244         drive->i.serial.clock = 1;
1245         drive->i.serial.state = 300;
12331246         break;
12341247      }
12351248      break;
12361249   case 320:
12371250      if (!cbm_serial.atn[0])
12381251      {
1239         vc1541->i.serial.state = 330;
1240         vc1541->i.serial.data = 1;
1241         vc1541->i.serial.clock = 1;
1252         drive->i.serial.state = 330;
1253         drive->i.serial.data = 1;
1254         drive->i.serial.clock = 1;
12421255         break;
12431256      }
1244      if (vc1541_time_greater(vc1541, ATTOTIME_IN_USEC(100)))
1257      if (vc1541_time_greater(drive, ATTOTIME_IN_USEC(100)))
12451258      {
1246         vc1541->i.serial.clock = 1;
1247         vc1541->i.serial.state++;
1259         drive->i.serial.clock = 1;
1260         drive->i.serial.state++;
12481261         break;
12491262      }
12501263      break;
12511264   case 321:
12521265      if (!cbm_serial.atn[0])
12531266      {
1254         vc1541->i.serial.state = 330;
1255         vc1541->i.serial.data = 1;
1256         vc1541->i.serial.clock = 1;
1267         drive->i.serial.state = 330;
1268         drive->i.serial.data = 1;
1269         drive->i.serial.clock = 1;
12571270         break;
12581271      }
12591272      if (cbm_serial.data[0])
12601273      {
1261         vc1541->i.serial.state++;
1274         drive->i.serial.state++;
12621275      }
12631276      break;
12641277   case 322:
12651278      if (!cbm_serial.atn[0])
12661279      {
1267         vc1541->i.serial.state = 330;
1268         vc1541->i.serial.data = 1;
1269         vc1541->i.serial.clock = 1;
1280         drive->i.serial.state = 330;
1281         drive->i.serial.data = 1;
1282         drive->i.serial.clock = 1;
12701283         break;
12711284      }
12721285      if (!cbm_serial.data[0])
12731286      {
1274         vc1541->i.serial.state++;
1287         drive->i.serial.state++;
12751288      }
12761289      break;
12771290   case 323:
12781291      if (!cbm_serial.atn[0])
12791292      {
1280         vc1541->i.serial.state = 330;
1281         vc1541->i.serial.data = 1;
1282         vc1541->i.serial.clock = 1;
1293         drive->i.serial.state = 330;
1294         drive->i.serial.data = 1;
1295         drive->i.serial.clock = 1;
12831296         break;
12841297      }
12851298      if (cbm_serial.data[0])
12861299      {
1287         vc1541->i.serial.state = 300;
1300         drive->i.serial.state = 300;
12881301      }
12891302      break;
12901303   case 330:                     /* computer breaks receiving */
1291      vc1541->i.serial.state = 0;
1304      drive->i.serial.state = 0;
12921305      break;
12931306   }
12941307
1295   if (oldstate != vc1541->i.serial.state)
1308   if (oldstate != drive->i.serial.state)
12961309      if (VERBOSE_LEVEL >= 1) logerror("%d state %d->%d %d %s %s %s\n",
1297             vc1541->i.serial.device,
1310             drive->i.serial.device,
12981311             oldstate,
1299             vc1541->i.serial.state, vc1541->state,
1312             drive->i.serial.state, drive->state,
13001313             cbm_serial.atn[0] ? "ATN" : "atn",
13011314             cbm_serial.clock[0] ? "CLOCK" : "clock",
13021315             cbm_serial.data[0] ? "DATA" : "data");
src/mess/machine/cbmserb.c
r3253r3254
99
1010#include "includes/cbmserb.h"
1111
12static void vc1541_reset_write (CBM_Drive * vc1541, int level);
12/***********************************************
1313
14   Drive handling
15
16***********************************************/
17
18static void drive_reset_write (CBM_Drive * drive, int level);
19
1420CBM_Drive cbm_drive[2];
1521
1622CBM_Serial cbm_serial;
r3253r3254
9197   else if (drive->interface == SERIAL)
9298   {
9399      cbm_serial.drives[cbm_serial.count++] = drive;
94      vc1541_reset_write(drive, 0);
100      drive_reset_write(drive, 0);
95101   }
96102}
97103
r3253r3254
105111}
106112
107113
108
109static DEVICE_START( cbm_drive )
114static void drive_reset_write (CBM_Drive * drive, int level)
110115{
111   int id = image_index_in_device(device);
112   if (id == 0)
113      cbm_drive_open();   /* boy these C64 drivers are butt ugly */
114   return DEVICE_START_OK;
116   if (level == 0)
117   {
118      drive->i.serial.data =
119         drive->i.serial.clock =
120         drive->i.serial.atn = 1;
121      drive->i.serial.state = 0;
122   }
115123}
116124
117static DEVICE_STOP( cbm_drive )
118{
119   int id = image_index_in_device(device);
120   if (id == 0)
121      cbm_drive_close();   /* boy these C64 drivers are butt ugly */
122}
123125
126/**************************************
124127
128   C1551
125129
126/* open an d64 image */
127static DEVICE_IMAGE_LOAD( cbm_drive )
128{
129   int id = image_index_in_device(image);
130**************************************/
130131
131   cbm_drive[id].drive = 0;
132   cbm_drive[id].image = NULL;
133132
134   cbm_drive[id].image = image_ptr(image);
135   if (!cbm_drive[id].image)
136      return INIT_FAIL;
137
138   cbm_drive[id].drive = D64_IMAGE;
139   return 0;
140}
141
142static DEVICE_IMAGE_UNLOAD( cbm_drive )
133static void c1551_write_data (CBM_Drive * drive, int data)
143134{
144   int id = image_index_in_device(image);
145
146   cbm_drive[id].drive = 0;
147   cbm_drive[id].image = NULL;
135   drive->i.iec.datain = data;
136   c1551_state (drive);
148137}
149138
150
151static void c1551_write_data (CBM_Drive * c1551, int data)
139static int c1551_read_data (CBM_Drive * drive)
152140{
153   c1551->i.iec.datain = data;
154   c1551_state (c1551);
141   c1551_state (drive);
142   return drive->i.iec.dataout;
155143}
156144
157static int c1551_read_data (CBM_Drive * c1551)
145static void c1551_write_handshake (CBM_Drive * drive, int data)
158146{
159   c1551_state (c1551);
160   return c1551->i.iec.dataout;
147   drive->i.iec.handshakein = data&0x40?1:0;
148   c1551_state (drive);
161149}
162150
163static void c1551_write_handshake (CBM_Drive * c1551, int data)
151static int c1551_read_handshake (CBM_Drive * drive)
164152{
165   c1551->i.iec.handshakein = data&0x40?1:0;
166   c1551_state (c1551);
153   c1551_state (drive);
154   return drive->i.iec.handshakeout?0x80:0;
167155}
168156
169static int c1551_read_handshake (CBM_Drive * c1551)
157static int c1551_read_status (CBM_Drive * drive)
170158{
171   c1551_state (c1551);
172   return c1551->i.iec.handshakeout?0x80:0;
159   c1551_state (drive);
160   return drive->i.iec.status;
173161}
174162
175static int c1551_read_status (CBM_Drive * c1551)
176{
177   c1551_state (c1551);
178   return c1551->i.iec.status;
179}
180
181163void c1551_0_write_data (int data)
182164{
183165   c1551_write_data (cbm_drive, data);
r3253r3254
220202   return c1551_read_status (cbm_drive + 1);
221203}
222204
223static void vc1541_reset_write (CBM_Drive * vc1541, int level)
224{
225   if (level == 0)
226   {
227      vc1541->i.serial.data =
228         vc1541->i.serial.clock =
229         vc1541->i.serial.atn = 1;
230      vc1541->i.serial.state = 0;
231   }
232}
205/**************************************
233206
234static int vc1541_atn_read (CBM_Drive * vc1541)
207   VC1541
208
209**************************************/
210
211static int vc1541_atn_read (CBM_Drive * drive)
235212{
236   vc1541_state (vc1541);
237   return vc1541->i.serial.atn;
213   vc1541_state (drive);
214   return drive->i.serial.atn;
238215}
239216
240static int vc1541_data_read (CBM_Drive * vc1541)
217static int vc1541_data_read (CBM_Drive * drive)
241218{
242   vc1541_state (vc1541);
243   return vc1541->i.serial.data;
219   vc1541_state (drive);
220   return drive->i.serial.data;
244221}
245222
246static int vc1541_clock_read (CBM_Drive * vc1541)
223static int vc1541_clock_read (CBM_Drive * drive)
247224{
248   vc1541_state (vc1541);
249   return vc1541->i.serial.clock;
225   vc1541_state (drive);
226   return drive->i.serial.clock;
250227}
251228
252static void vc1541_data_write (CBM_Drive * vc1541, int level)
229static void vc1541_data_write (CBM_Drive * drive, int level)
253230{
254   vc1541_state (vc1541);
231   vc1541_state (drive);
255232}
256233
257static void vc1541_clock_write (CBM_Drive * vc1541, int level)
234static void vc1541_clock_write (CBM_Drive * drive, int level)
258235{
259   vc1541_state (vc1541);
236   vc1541_state (drive);
260237}
261238
262static void vc1541_atn_write (CBM_Drive * vc1541, int level)
239static void vc1541_atn_write (CBM_Drive * drive, int level)
263240{
264   vc1541_state (vc1541);
241   vc1541_state (drive);
265242}
266243
267244
245
246/**************************************
247
248   Serial communications
249
250**************************************/
251
252
253
268254/* bus handling */
269255void cbm_serial_reset_write (int level)
270256{
271257   int i;
272258
273259   for (i = 0; i < cbm_serial.count; i++)
274      vc1541_reset_write (cbm_serial.drives[i], level);
260      drive_reset_write (cbm_serial.drives[i], level);
275261   /* init bus signals */
276262}
277263
r3253r3254
360346      vc1541_atn_write (cbm_serial.drives[i], cbm_serial.atn[0]);
361347}
362348
363/* delivers status for displaying */
364static void cbm_drive_status (CBM_Drive * c1551, char *text, int size)
349
350/**************************************
351
352   Device configurations
353
354**************************************/
355
356
357static DEVICE_START( cbm_drive )
365358{
366   text[0] = 0;
367#if 0
368   if ((c1551->interface == SERIAL) /*&&(c1551->i.serial.device==8) */ )
369   {
370      snprintf (text, size, "%d state:%d %d %d %s %s %s",
371              c1551->state, c1551->i.serial.state, c1551->pos, c1551->size,
372              cbm_serial.atn[0] ? "ATN" : "atn",
373              cbm_serial.clock[0] ? "CLOCK" : "clock",
374              cbm_serial.data[0] ? "DATA" : "data");
375      return;
376   }
377   if ((c1551->interface == IEC) /*&&(c1551->i.serial.device==8) */ )
378   {
379      snprintf (text, size, "%d state:%d %d %d",
380              c1551->state, c1551->i.iec.state, c1551->pos, c1551->size);
381      return;
382   }
383#endif
384   if (c1551->drive == D64_IMAGE)
385   {
386      switch (c1551->state)
387      {
388      case OPEN:
389         snprintf (text, size, "Image File %s open",
390                 c1551->filename);
391         break;
392      case READING:
393         snprintf (text, size, "Image File %s loading %d",
394                 c1551->filename,
395                 c1551->size - c1551->pos - 1);
396         break;
397      case WRITING:
398         snprintf (text, size, "Image File %s saving %d",
399                 c1551->filename, c1551->pos);
400         break;
401      }
402   }
359   int id = image_index_in_device(device);
360   if (id == 0)
361      cbm_drive_open();   /* boy these C64 drivers are butt ugly */
362   return DEVICE_START_OK;
403363}
404364
405void cbm_drive_0_status (char *text, int size)
365static DEVICE_STOP( cbm_drive )
406366{
407   cbm_drive_status (cbm_drive, text, size);
367   int id = image_index_in_device(device);
368   if (id == 0)
369      cbm_drive_close();   /* boy these C64 drivers are butt ugly */
408370}
409371
410void cbm_drive_1_status (char *text, int size)
372
373
374/* open an d64 image */
375static DEVICE_IMAGE_LOAD( cbm_drive )
411376{
412   cbm_drive_status (cbm_drive + 1, text, size);
377   int id = image_index_in_device(image);
378
379   cbm_drive[id].drive = 0;
380   cbm_drive[id].image = NULL;
381
382   cbm_drive[id].image = image_ptr(image);
383   if (!cbm_drive[id].image)
384      return INIT_FAIL;
385
386   cbm_drive[id].drive = D64_IMAGE;
387   return 0;
413388}
414389
390static DEVICE_IMAGE_UNLOAD( cbm_drive )
391{
392   int id = image_index_in_device(image);
393
394   cbm_drive[id].drive = 0;
395   cbm_drive[id].image = NULL;
396}
397
398
415399void cbmfloppy_device_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
416400{
417401   switch(state)
src/mess/machine/vc20.c
r3253r3254
562562#ifdef VC1541
563563   drive_config (type_1541, 0, 0, 1, 8);
564564#endif
565
565566   via_config (0, &via0);
566567   via_config (1, &via1);
567568}
r3253r3254
596597
597598MACHINE_RESET( vic20 )
598599{
599   cbm_serial_reset_write (0);
600600#ifdef VC1541
601601   drive_reset ();
602602#endif
603603
604   cbm_serial_reset_write (0);
605
604606   if (ieee)
605607   {
606608      cbm_drive_0_config (IEEE, 8);
src/mess/machine/c64.c
r3253r3254
10581058   if (is_sx64)
10591059      drive_reset ();
10601060
1061   if (c64_cia1_on)
1061   else if (c64_cia1_on)
10621062   {
10631063      cbm_serial_reset_write (0);
10641064      cbm_drive_0_config (SERIAL, is_c65(machine) ? 10 : 8);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team