Previous 15994 Revisions Next

r3283 Wednesday 17th September, 2008 at 06:16:42 UTC by Fabio Priuli
[CBM] Made offset initialization less d64-centric
[src/mess/includes]vc1541.h
[src/mess/machine]vc1541.c

src/mess/includes/vc1541.h
r3282r3283
2929type_8250,
3030};
3131
32enum {
33format_d64 = 0,
34format_d64_40t,
35format_d71,
36format_d81,
37format_d80,
38format_d82,
39format_g64,
40};
41
3242DEVICE_IMAGE_LOAD(vc1541);
3343DEVICE_IMAGE_UNLOAD(vc1541);
3444
src/mess/machine/vc1541.c
r3282r3283
136136      } \
137137   }
138138
139#define XTAL_16_MHz   16000000
140
141/* Are there other formats to support which could require more tracks? */
142#define IMAGE_MAX_TRACKS 154
143
139144#define D64_MAX_TRACKS 35
145#define D64_40T_MAX_TRACKS 40
140146
141147static const int d64_sectors_per_track[] =
142148{
143149   21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
144150   19, 19, 19, 19, 19, 19, 19,
145151   18, 18, 18, 18, 18, 18,
152   17, 17, 17, 17, 17,
153   17, 17, 17, 17, 17      /* only for 40 tracks d64 */
154};
155
156#define D71_MAX_TRACKS 70
157
158static const int d71_sectors_per_track[] =
159{
160   21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
161   19, 19, 19, 19, 19, 19, 19,
162   18, 18, 18, 18, 18, 18,
163   17, 17, 17, 17, 17,
164   21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
165   19, 19, 19, 19, 19, 19, 19,
166   18, 18, 18, 18, 18, 18,
146167   17, 17, 17, 17, 17
147168};
148169
149static int d64_offset[D64_MAX_TRACKS];        /* offset of begin of track in d64 file */
170#define D81_MAX_TRACKS 80
150171
151/* calculates offset to beginning of d64 file for sector beginning */
152static int d64_tracksector2offset (int track, int sector)
172/* Each track in a d81 file has 40 sectors, so no need of a sectors_per_track table */
173
174#define D80_MAX_TRACKS 77
175
176static const int d80_sectors_per_track[] =
153177{
154   return d64_offset[track - 1] + sector * 256;
178   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
179   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
180   27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
181   25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
182   23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23
183};
184
185
186#define D82_MAX_TRACKS 154
187
188static const int d82_sectors_per_track[] =
189{
190   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
191   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
192   27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
193   25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
194   23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
195   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
196   29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
197   27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
198   25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
199   23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23
200};
201
202
203static int image_offset[IMAGE_MAX_TRACKS] = { 0 };
204
205
206static void offset_init (int format)
207{
208   int i;
209
210   /* Track # starts from 1 */
211   image_offset[0] = 0;
212
213   switch (format)
214   {
215      case format_d64:
216         for (i = 1; i <= D64_MAX_TRACKS; i++)
217            image_offset[i] = image_offset[i - 1] + d64_sectors_per_track[i - 1] * 256;
218         break;
219
220      case format_d64_40t:
221         for (i = 1; i <= D64_40T_MAX_TRACKS; i++)
222            image_offset[i] = image_offset[i - 1] + d64_sectors_per_track[i - 1] * 256;
223         break;
224
225      case format_d71:
226         for (i = 1; i <= D71_MAX_TRACKS; i++)
227            image_offset[i] = image_offset[i - 1] + d71_sectors_per_track[i - 1] * 256;
228         break;
229
230      case format_d81:
231         for (i = 1; i <= D81_MAX_TRACKS; i++)
232            image_offset[i] = image_offset[i - 1] + 40 * 256;
233         break;
234
235      case format_d80:
236         for (i = 1; i <= D80_MAX_TRACKS; i++)
237            image_offset[i] = image_offset[i - 1] + d80_sectors_per_track[i - 1] * 256;
238         break;
239
240      case format_d82:
241         for (i = 1; i <= D82_MAX_TRACKS; i++)
242            image_offset[i] = image_offset[i - 1] + d82_sectors_per_track[i - 1] * 256;
243         break;
244
245      default:
246         logerror("Unsupported format");
247         break;
248   }
155249}
156250
157251
158#define D64_TRACK_ID1   (d64_tracksector2offset(18,0)+162)
159#define D64_TRACK_ID2   (d64_tracksector2offset(18,0)+163)
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! */
254static int image_tracksector2offset (int track, int sector)
255{
256   return image_offset[track - 1] + sector * 256;
257}
160258
259
260#define D64_TRACK_ID1   (image_tracksector2offset(18,0)+162)
261#define D64_TRACK_ID2   (image_tracksector2offset(18,0)+163)
262
161263/*
162264 * only for testing at the moment
163265 */
r3282r3283
214316      int pos; /* position  in sector */
215317      int sector;
216318      UINT8 *data;
217   } d64;
319   } image;
218320} CBM_Drive_Emu;
219321
220322static CBM_Drive_Emu drive_static= { 0 }, *drive = &drive_static;
r3282r3283
325427{
326428   int i=0, j, offset, chksum=0;
327429
328   if (drive->d64.data==NULL) return;
430   if (drive->image.data==NULL) return;
329431   drive->head.data[i++]=0xff;
330432   drive->head.data[i++]=0xff;
331433   drive->head.data[i++]=0xff;
r3282r3283
335437
336438   drive_sector_data(8, &i);
337439   chksum= sector^track
338      ^drive->d64.data[D64_TRACK_ID1]^drive->d64.data[D64_TRACK_ID2];
440      ^drive->image.data[D64_TRACK_ID1]^drive->image.data[D64_TRACK_ID2];
339441   drive_sector_data(chksum, &i);
340442   drive_sector_data(sector, &i);
341443   drive_sector_data(track, &i);
342   drive_sector_data(drive->d64.data[D64_TRACK_ID1], &i);
343   drive_sector_data(drive->d64.data[D64_TRACK_ID2], &i);
444   drive_sector_data(drive->image.data[D64_TRACK_ID1], &i);
445   drive_sector_data(drive->image.data[D64_TRACK_ID2], &i);
344446   drive_sector_data(0xf, &i);
345447   drive_sector_data(0xf, &i);
346448   drive_sector_end(&i);
r3282r3283
356458   drive_sector_data(0x7, &i);
357459
358460   chksum=0;
359   for (offset=d64_tracksector2offset(track,sector), j=0; j<256; j++) {
360      chksum^=drive->d64.data[offset];
361      drive_sector_data(drive->d64.data[offset++], &i);
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);
362464   }
363465   drive_sector_data(chksum, &i);
364466   drive_sector_data(0, &i); /* padding up */
r3282r3283
371473
372474/**************************************
373475
374   VC1541
476   1541 / 1541II
375477
376478**************************************/
377479
378480
379static ADDRESS_MAP_START( vc1541_map, ADDRESS_SPACE_PROGRAM, 8 )
481static ADDRESS_MAP_START( _1541_map, ADDRESS_SPACE_PROGRAM, 8 )
380482   AM_RANGE(0x0000, 0x07ff) AM_RAM
381483   AM_RANGE(0x1800, 0x180f) AM_READWRITE(via_2_r, via_2_w)  /* 0 and 1 used in vc20 */
382484   AM_RANGE(0x1810, 0x189f) AM_READ(SMH_NOP) /* for debugger */
r3282r3283
418520      }
419521      return;
420522   }
421   if (++(drive->d64.pos)>=sizeof(drive->head.data)) {
422      if (++(drive->d64.sector)>=
523   if (++(drive->image.pos)>=sizeof(drive->head.data)) {
524      if (++(drive->image.sector)>=
423525         d64_sectors_per_track[(int)drive->track-1]) {
424         drive->d64.sector=0;
526         drive->image.sector=0;
425527      }
426      drive_sector_to_gcr((int)drive->track,drive->d64.sector);
427      drive->d64.pos=0;
528      drive_sector_to_gcr((int)drive->track,drive->image.sector);
529      drive->image.pos=0;
428530   }
429531   drive->head.ready=1;
430   if (drive->head.data[drive->d64.pos]==0xff) {
532   if (drive->head.data[drive->image.pos]==0xff) {
431533      drive->head.ffcount++;
432534      if (drive->head.ffcount==5) {
433535         drive->head.sync=1;
r3282r3283
567669
568670static READ8_HANDLER( vc1541_via1_read_porta )
569671{
570   int data=drive->head.data[drive->d64.pos];
672   int data=drive->head.data[drive->image.pos];
571673   DBG_LOG(2, "vc1541 drive",("port a read %.2x\n", data));
572674   return data;
573675}
r3282r3283
795897
796898/**************************************
797899
798   C1551
900   1570 / 1571 / 1571CR
799901
800902**************************************/
801903
904static ADDRESS_MAP_START( _1571_map, ADDRESS_SPACE_PROGRAM, 8 )
905   AM_RANGE(0x0000, 0x07ff) AM_RAM
906   AM_RANGE(0x1800, 0x180f) AM_READWRITE(via_2_r, via_2_w)  /* 0 and 1 used in vc20 */
907   AM_RANGE(0x1810, 0x189f) AM_READ(SMH_NOP) /* for debugger */
908   AM_RANGE(0x1c00, 0x1c0f) AM_READWRITE(via_3_r, via_3_w)
909   AM_RANGE(0x1c10, 0x1c9f) AM_READ(SMH_NOP) /* for debugger */
910//   AM_RANGE(0x2000, 0x2003) // WD17xx
911//   AM_RANGE(0x4000, 0x400f) // CIA
912   AM_RANGE(0xc000, 0xffff) AM_ROM
913ADDRESS_MAP_END
914
915
916/**************************************
917
918   1581
919
920**************************************/
921
922static ADDRESS_MAP_START( _1581_map, ADDRESS_SPACE_PROGRAM, 8 )
923//   AM_RANGE(0x4000, 0x400f) // CIA
924//   AM_RANGE(0x6000, 0x6003) // WD17xx
925ADDRESS_MAP_END
926
927
928/**************************************
929
930   2031 / 2040 / 3040 / 4040 /
931      1001 / 8050 / 8250
932
933**************************************/
934
935static ADDRESS_MAP_START( _2031_map, ADDRESS_SPACE_PROGRAM, 8 )
936//   AM_RANGE(0x0200, 0x021f) // RIOT1
937//   AM_RANGE(0x0280, 0x029f) // RIOT2
938ADDRESS_MAP_END
939
940
941/**************************************
942
943   1551
944
945**************************************/
946
802947/*
803948  c1551 irq line
804949  only timing related??? (60 hz?), delivered from c16?
r3282r3283
9241069
9251070static int c1551_port_b_r (void)
9261071{
927   int data=drive->head.data[drive->d64.pos];
1072   int data=drive->head.data[drive->image.pos];
9281073   DBG_LOG(2, "c1551 drive",("port a read %.2x\n", data));
9291074   return data;
9301075}
9311076
9321077
933static ADDRESS_MAP_START( c1551_map, ADDRESS_SPACE_PROGRAM, 8 )
1078static ADDRESS_MAP_START( _1551_map, ADDRESS_SPACE_PROGRAM, 8 )
9341079    AM_RANGE(0x0000, 0x0001) AM_READWRITE(c1551_port_r, c1551_port_w)
9351080   AM_RANGE(0x0002, 0x07ff) AM_RAM
9361081    AM_RANGE(0x4000, 0x4007) AM_READWRITE(tpi6525_0_port_r, tpi6525_0_port_w)
r3282r3283
10851230**************************************/
10861231
10871232MACHINE_DRIVER_START( cpu_vc1540 )
1088   MDRV_CPU_ADD("cpu_vc1540", M6502, 1000000)
1089   MDRV_CPU_PROGRAM_MAP(vc1541_map, 0)
1233   MDRV_CPU_ADD("cpu_vc1540", M6502, XTAL_16_MHz / 16)
1234   MDRV_CPU_PROGRAM_MAP(_1541_map, 0)
10901235MACHINE_DRIVER_END
10911236
10921237MACHINE_DRIVER_START( cpu_vc1541 )
r3282r3283
10981243MACHINE_DRIVER_END
10991244
11001245MACHINE_DRIVER_START( cpu_dolphin )
1101   MDRV_CPU_ADD("cpu_dolphin", M6502, 1000000)
1246   MDRV_CPU_ADD("cpu_dolphin", M6502, XTAL_16_MHz / 16)
11021247   MDRV_CPU_PROGRAM_MAP(dolphin_map, 0)
11031248MACHINE_DRIVER_END
11041249
11051250MACHINE_DRIVER_START( cpu_c1551 )
11061251   MDRV_CPU_ADD("cpu_c1551", M6510T, 2000000)
1107   MDRV_CPU_PROGRAM_MAP(c1551_map, 0)
1252   MDRV_CPU_PROGRAM_MAP(_1551_map, 0)
11081253MACHINE_DRIVER_END
11091254
11101255MACHINE_DRIVER_START( cpu_c1571 )
1111   MDRV_IMPORT_FROM(cpu_vc1541)
1256   MDRV_CPU_ADD("cpu_vc1540", M6502, XTAL_16_MHz / 16)
1257   MDRV_CPU_PROGRAM_MAP(_1571_map, 0)
11121258MACHINE_DRIVER_END
11131259
11141260/**************************************
r3282r3283
11191265
11201266DEVICE_IMAGE_LOAD(vc1541)
11211267{
1122   drive->d64.data = image_ptr(image);
1123   if (!drive->d64.data)
1268   offset_init (format_d64);
1269
1270   /* Fix me: we should load directly the GCR data */
1271   drive->image.data = image_ptr(image);
1272   if (!drive->image.data)
11241273      return INIT_FAIL;
11251274
11261275   logerror("floppy image %s loaded\n", image_filename(image));
r3282r3283
11311280DEVICE_IMAGE_UNLOAD(vc1541)
11321281{
11331282   /* writeback of image data */
1134   drive->d64.data = NULL;
1283   drive->image.data = NULL;
11351284}
11361285
11371286void vc1541_device_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team