Previous 15994 Revisions Next

r5626 Monday 7th September, 2009 at 11:04:03 UTC by Miodrag Milanović
[X68K] Floppy cleanup
[src/mess]mess.mak
[src/mess/devices]mflopimg.c mflopimg.h
[src/mess/drivers]x68k.c
[src/mess/formats]dim_dsk.c* dim_dsk.h*

src/mess/mess.mak
r5625r5626
12101210   $(MESS_MACHINE)/mz700.o      \
12111211   $(MESS_DRIVERS)/x68k.o      \
12121212   $(MESS_VIDEO)/x68k.o      \
1213   $(MESS_FORMATS)/dim_dsk.o   \
12131214   $(MESS_MACHINE)/x68k_hdc.o   \
12141215   $(MESS_DRIVERS)/mz80.o      \
12151216   $(MESS_VIDEO)/mz80.o      \
src/mess/devices/mflopimg.c
r5625r5626
3131{
3232   floppy_image *floppy;
3333   int track;
34   void (*load_proc)(const device_config *image);
3435   void (*unload_proc)(const device_config *image);
3536   int (*tracktranslate_proc)(const device_config *image, floppy_image *floppy, int physical_track);
3637};
r5625r5626
334335
335336static DEVICE_IMAGE_LOAD( floppy )
336337{
337   return internal_floppy_device_load(image, -1, NULL);
338   mess_flopimg *flopimg;
339   int retVal = internal_floppy_device_load(image, -1, NULL);
340   flopimg = image_lookuptag(image, FLOPPY_TAG);
341   if (retVal==INIT_PASS) {
342      /* if we have one of our hacky unload procs, call it */
343      if (flopimg->load_proc)
344         flopimg->load_proc(image);
345   }
346   return retVal;
338347}
339348
340349
341350
342351static DEVICE_IMAGE_CREATE( floppy )
343352{
344   return internal_floppy_device_load(image, create_format, create_args);
353   return internal_floppy_device_load(image, create_format, create_args);   
345354}
346355
347356
r5625r5626
367376 *
368377 *************************************/
369378
379void floppy_install_load_proc(const device_config *image, void (*proc)(const device_config *image))
380{
381   mess_flopimg *flopimg;
382   flopimg = image_lookuptag(image, FLOPPY_TAG);
383   flopimg->load_proc = proc;
384}
385
370386void floppy_install_unload_proc(const device_config *image, void (*proc)(const device_config *image))
371387{
372388   mess_flopimg *flopimg;
src/mess/devices/mflopimg.h
r5625r5626
2828/* hack for apple II; replace this when we think of something better */
2929void floppy_install_unload_proc(const device_config *image, void (*proc)(const device_config *image));
3030
31void floppy_install_load_proc(const device_config *image, void (*proc)(const device_config *image));
32
3133/* hack for TI99; replace this when we think of something better */
3234void floppy_install_tracktranslate_proc(const device_config *image, int (*proc)(const device_config *image, floppy_image *floppy, int physical_track));
3335
src/mess/formats/dim_dsk.c
r0r5626
1/*********************************************************************
2
3   formats/dim_dsk.c
4
5   DIM disk images
6
7*********************************************************************/
8
9#include <string.h>
10
11#include "formats/dim_dsk.h"
12#include "formats/basicdsk.h"
13#include "driver.h"
14
15FLOPPY_IDENTIFY(dim_dsk_identify)
16{
17   *vote = 100;
18   return FLOPPY_ERROR_SUCCESS;
19}
20
21FLOPPY_CONSTRUCT(dim_dsk_construct)
22{
23   struct basicdsk_geometry geometry;
24   // DIM disk image header, most of this is guesswork
25   int tracks = 77;
26   int heads = 2;
27   int sectors = 8;  // per track
28   int sectorlen = 1024;
29   int firstsector = 0x01;
30   UINT8 format_tmp;
31   int x;
32   UINT16 temp;
33   
34   if(params)
35   {
36      // create
37      return FLOPPY_ERROR_UNSUPPORTED;
38   }
39
40   // Offset + 0 : disk format type (1 byte):
41    //  0 = 2HD / 2HDA (8 sector/track, 1024 bytes/sector, GAP#3 = 0x74)
42    //  1 = 2HS        (9 sector/track, 1024 bytes/sector, GAP#3 = 0x39)
43    //  2 = 2HC        (15 sector/track, 512 bytes/sector, GAP#3 = 0x54)
44    //  3 = 2HDE(68)   (9 sector/track, 1024 bytes/sector, GAP#3 = 0x39)
45    //  9 = 2HQ        (18 sector/track, 512 bytes/sector, GAP#3 = 0x54)
46    //  17 = N88-BASIC (26 sector/track, 256 bytes/sector, GAP#3 = 0x33)
47    //              or (26 sector/track, 128 bytes/sector, GAP#3 = 0x1a)
48    //
49   floppy_image_read(floppy, &format_tmp,0,1);
50
51   switch(format_tmp)
52   {
53   case 0x00:
54      sectors = 8;
55      sectorlen = 1024;
56      break;
57   case 0x01:
58   case 0x03:
59      sectors = 9;
60      sectorlen = 1024;
61      break;
62   case 0x02:
63      sectors = 15;
64      sectorlen = 512;
65      break;
66   case 0x09:
67      sectors = 18;
68      sectorlen = 512;
69      break;
70   case 0x11:
71      sectors = 26;
72      sectorlen = 256;
73      break;
74   }
75   tracks = 0;
76   for (x=0;x<86;x++)
77   {
78      floppy_image_read(floppy,&temp,(x*2)+1,2);
79      if(temp == 0x0101)
80         tracks++;
81   }
82   // TODO: expand on this basic implementation
83
84   logerror("FDD: DIM image loaded - type %i, %i tracks, %i sectors per track, %i bytes per sector\n", format_tmp,tracks, sectors,sectorlen);
85   
86   memset(&geometry, 0, sizeof(geometry));
87   geometry.heads = heads;
88   geometry.first_sector_id = firstsector;
89   geometry.sector_length = sectorlen;
90   geometry.tracks = tracks+1;
91   geometry.sectors = sectors;
92   geometry.offset = 0x100;
93   return basicdsk_construct(floppy, &geometry);   
94}
95
src/mess/formats/dim_dsk.h
r0r5626
1/*********************************************************************
2
3   formats/dim_dsk.h
4
5   DIM disk images
6
7*********************************************************************/
8
9#ifndef DIM_DSK_H
10#define DIM_DSK_H
11
12#include "formats/flopimg.h"
13
14/**************************************************************************/
15
16FLOPPY_IDENTIFY(dim_dsk_identify);
17FLOPPY_CONSTRUCT(dim_dsk_construct);
18
19#endif /* DIM_DSK_H */
src/mess/drivers/x68k.c
r5625r5626
128128#include "machine/8530scc.h"
129129#include "machine/hd63450.h"
130130#include "machine/rp5c15.h"
131#include "devices/basicdsk.h"
131#include "devices/mflopimg.h"
132#include "formats/basicdsk.h"
133#include "formats/dim_dsk.h"
132134#include "devices/harddriv.h"
133135#include "machine/x68k_hdc.h"
134136#include "includes/x68k.h"
r5625r5626
22272229
22282230INPUT_PORTS_END
22292231
2230static void dimdsk_set_geometry(const device_config* image)
2231{
2232   // DIM disk image header, most of this is guesswork
2233   int tracks = 77;
2234   int heads = 2;
2235   int sectors = 8;  // per track
2236   int sectorlen = 1024;
2237   int firstsector = 0x01;
2238   unsigned char format;
2239   int x;
2240   unsigned short temp;
2241
2242   /* Offset + 0 : disk format type (1 byte):
2243     * 0 = 2HD / 2HDA (8 sector/track, 1024 bytes/sector, GAP#3 = 0x74)
2244     * 1 = 2HS        (9 sector/track, 1024 bytes/sector, GAP#3 = 0x39)
2245     * 2 = 2HC        (15 sector/track, 512 bytes/sector, GAP#3 = 0x54)
2246     * 3 = 2HDE(68)   (9 sector/track, 1024 bytes/sector, GAP#3 = 0x39)
2247     * 9 = 2HQ        (18 sector/track, 512 bytes/sector, GAP#3 = 0x54)
2248     * 17 = N88-BASIC (26 sector/track, 256 bytes/sector, GAP#3 = 0x33)
2249     *             or (26 sector/track, 128 bytes/sector, GAP#3 = 0x1a)
2250     */
2251   image_fread(image,&format,1);
2252
2253   switch(format)
2232static void x68k_load_proc(const device_config *image)
2233{   
2234   if(x68k_sys.ioc.irqstatus & 0x02)
22542235   {
2255   case 0x00:
2256      sectors = 8;
2257      sectorlen = 1024;
2258      break;
2259   case 0x01:
2260   case 0x03:
2261      sectors = 9;
2262      sectorlen = 1024;
2263      break;
2264   case 0x02:
2265      sectors = 15;
2266      sectorlen = 512;
2267      break;
2268   case 0x09:
2269      sectors = 18;
2270      sectorlen = 512;
2271      break;
2272   case 0x11:
2273      sectors = 26;
2274      sectorlen = 256;
2275      break;
2236      current_vector[1] = 0x61;
2237      x68k_sys.ioc.irqstatus |= 0x40;
2238      current_irq_line = 1;
2239      cputag_set_input_line_and_vector(image->machine, "maincpu",1,ASSERT_LINE,current_vector[1]);  // Disk insert/eject interrupt
2240      logerror("IOC: Disk image inserted\n");
22762241   }
2277   tracks = 0;
2278   for (x=0;x<86;x++)
2279   {
2280      image_fread(image,&temp,2);
2281      if(temp == 0x0101)
2282         tracks++;
2283   }
2284   // TODO: expand on this basic implementation
2285
2286   logerror("FDD: DIM image loaded - type %i, %i tracks, %i sectors per track, %i bytes per sector\n", format,tracks, sectors,sectorlen);
2287   basicdsk_set_geometry(image, tracks+1, heads, sectors, sectorlen, firstsector, 0x100, FALSE);
2242   x68k_sys.fdc.disk_inserted[image_index_in_device(image)] = 1;
22882243}
22892244
2290static DEVICE_IMAGE_LOAD( x68k_floppy )
2245static void x68k_unload_proc(const device_config *image)
22912246{
2292   if (device_load_basicdsk_floppy(image)==INIT_PASS)
2293   {
2294      /* sector id's 01-08 */
2295      /* drive, tracks, heads, sectors per track, sector length, first sector id */
2296      if(strcmp(image_filetype(image),"dim") == 0)
2297         dimdsk_set_geometry(image);
2298      else
2299         basicdsk_set_geometry(image, 77, 2, 8, 1024, 0x01, 0, FALSE);
2300      if(x68k_sys.ioc.irqstatus & 0x02)
2301      {
2302         current_vector[1] = 0x61;
2303         x68k_sys.ioc.irqstatus |= 0x40;
2304         current_irq_line = 1;
2305         cputag_set_input_line_and_vector(image->machine, "maincpu",1,ASSERT_LINE,current_vector[1]);  // Disk insert/eject interrupt
2306         logerror("IOC: Disk image inserted\n");
2307      }
2308      x68k_sys.fdc.disk_inserted[image_index_in_device(image)] = 1;
2309      return INIT_PASS;
2310   }
2311
2312   return INIT_FAIL;
2313}
2314
2315static DEVICE_IMAGE_UNLOAD( x68k_floppy )
2316{
23172247   if(x68k_sys.ioc.irqstatus & 0x02)
23182248   {
23192249      current_vector[1] = 0x61;
r5625r5626
23242254   x68k_sys.fdc.disk_inserted[image_index_in_device(image)] = 0;
23252255}
23262256
2257FLOPPY_OPTIONS_START( x68k )
2258   FLOPPY_OPTION( dim, "dim",      "DIM floppy disk image",   dim_dsk_identify, dim_dsk_construct, NULL)
2259   FLOPPY_OPTION( img2d, "xdf,hdm,2hd", "XDF disk image", basicdsk_identify_default, basicdsk_construct_default,
2260      HEADS([2])
2261      TRACKS([77])
2262      SECTORS([8])
2263      SECTOR_LENGTH([1024])
2264      FIRST_SECTOR_ID([1]))
2265FLOPPY_OPTIONS_END
2266
2267
23272268static void x68k_floppy_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
23282269{
2270   /* floppy */
23292271   switch(state)
23302272   {
2331   case MESS_DEVINFO_INT_READABLE:
2332      info->i = 1;
2333      break;
2334   case MESS_DEVINFO_INT_WRITEABLE:
2335      info->i = 1;
2336      break;
2337   case MESS_DEVINFO_INT_CREATABLE:
2338      info->i = 0;
2339      break;
2340   case MESS_DEVINFO_INT_COUNT:
2341      info->i = 4;
2342      break;
2343   case MESS_DEVINFO_PTR_LOAD:
2344      info->load = DEVICE_IMAGE_LOAD_NAME(x68k_floppy);
2345      break;
2346   case MESS_DEVINFO_PTR_UNLOAD:
2347      info->unload = DEVICE_IMAGE_UNLOAD_NAME(x68k_floppy);
2348      break;
2349   case MESS_DEVINFO_STR_FILE_EXTENSIONS:
2350      strcpy(info->s = device_temp_str(), "xdf,hdm,2hd,dim");
2351      break;
2352   default:
2353      legacybasicdsk_device_getinfo(devclass, state, info);
2354      break;
2273      /* --- the following bits of info are returned as 64-bit signed integers --- */
2274      case MESS_DEVINFO_INT_COUNT:                     info->i = 4; break;
2275
2276      /* --- the following bits of info are returned as pointers to data or functions --- */
2277      case MESS_DEVINFO_PTR_FLOPPY_OPTIONS:            info->p = (void *) floppyoptions_x68k; break;
2278
2279      default:                              floppy_device_getinfo(devclass, state, info); break;
23552280   }
23562281}
23572282
r5625r5626
24192344      output_set_indexed_value("eject_drv",drive,1);
24202345      output_set_indexed_value("ctrl_drv",drive,1);
24212346      output_set_indexed_value("access_drv",drive,1);
2347      floppy_install_unload_proc(image_from_devtype_and_index(machine, IO_FLOPPY, drive), x68k_unload_proc);
2348      floppy_install_load_proc(image_from_devtype_and_index(machine, IO_FLOPPY, drive), x68k_load_proc);
24222349   }
24232350   
24242351   // reset CPU

Previous 15994 Revisions Next


© 1998-2018 The MESS Team