Previous 15994 Revisions Next

r7231 Monday 1st February, 2010 at 16:53:59 UTC by Dirk Best
[APRICOT] Added basic APRIDISK image format support, not doing much because the i8089 still needs to emulated
[src/mess]mess.mak
[src/mess/drivers]apricot.c
[src/mess/formats]apridisk.c* apridisk.h*

src/mess/formats/apridisk.c
r0r7231
1/***************************************************************************
2 
3    APRIDISK disk image format
4 
5***************************************************************************/
6 
7#include "apridisk.h"
8 
9 
10/***************************************************************************
11    CONSTANTS
12***************************************************************************/
13 
14#define APR_HEADER_SIZE      128
15 
16/* sector types */
17#define APR_DELETED      0xe31d0000
18#define APR_MAGIC      0xe31d0001
19#define APR_COMMENT      0xe31d0002
20#define APR_CREATOR      0xe31d0003
21 
22/* compression type */
23#define APR_UNCOMPRESSED   0x9e90
24#define APR_COMPRESSED      0x3e5a
25 
26static const char *apr_magic = "ACT Apricot disk image\x1a\x04";
27 
28 
29/***************************************************************************
30    TYPE DEFINITIONS
31***************************************************************************/
32 
33struct apr_sector
34{
35   int head;
36   int track;
37   int sector;
38   UINT8 data[512];
39};
40 
41struct apr_tag
42{
43   int heads;
44   int tracks;
45   int sectors_per_track;
46   struct apr_sector sectors[2880];
47   char *comment;
48};
49 
50 
51/***************************************************************************
52    IMPLEMENTATION
53***************************************************************************/
54 
55/* sector format:
56 *
57 * 00-03: sector type
58 * 04-05: compression type
59 * 06-07: header size
60 * 08-11: data size
61 * 12-13: track
62 *    14: head
63 *    15: sector
64 */
65 
66static floperr_t apr_read_sector(floppy_image *floppy, int head, int track, int sector, void *buffer, size_t buflen)
67{
68   struct apr_tag *tag = (apr_tag *)floppy_tag(floppy);
69//   printf("apr_read_sector %d %d %d\n", head, track, sector);
70   memcpy(buffer, tag->sectors[head * track * sector].data, buflen);
71   return FLOPPY_ERROR_SUCCESS;
72}
73 
74static floperr_t apr_read_indexed_sector(floppy_image *floppy, int head, int track, int sector, void *buffer, size_t buflen)
75{
76   struct apr_tag *tag = (apr_tag *)floppy_tag(floppy);
77//   printf("apr_read_indexed_sector %d %d %d\n", head, track, sector);
78   memcpy(buffer, tag->sectors[head * track * sector].data, buflen);
79   return FLOPPY_ERROR_SUCCESS;
80}
81 
82/* sector length is always 512 byte */
83static floperr_t apr_get_sector_length(floppy_image *floppy, int head, int track, int sector, UINT32 *sector_length)
84{
85   *sector_length = 512;
86   return FLOPPY_ERROR_SUCCESS;
87}
88 
89static int apr_get_heads_per_disk(floppy_image *floppy)
90{
91   struct apr_tag *tag = (apr_tag *)floppy_tag(floppy);
92   return tag->heads;
93}
94 
95static int apr_get_tracks_per_disk(floppy_image *floppy)
96{
97   struct apr_tag *tag = (apr_tag *)floppy_tag(floppy);
98   return tag->tracks;
99}
100 
101static floperr_t apr_get_indexed_sector_info(floppy_image *floppy, int head, int track, int sector_index, int *cylinder, int *side, int *sector, UINT32 *sector_length, unsigned long *flags)
102{
103   struct apr_tag *tag = (apr_tag *)floppy_tag(floppy);
104 
105//   printf("apr_get_indexed_sector_info %d %d %d\n", head, track, sector_index);
106 
107   /* sanity checks */
108   if (head         < 0 || head         > (tag->heads - 1))             return FLOPPY_ERROR_SEEKERROR;
109   if (track        < 0 || track        > (tag->tracks - 1))            return FLOPPY_ERROR_SEEKERROR;
110   if (sector_index < 0 || sector_index > (tag->sectors_per_track - 1)) return FLOPPY_ERROR_SEEKERROR;
111 
112   if (cylinder)      *cylinder = tag->sectors[head * track * sector_index].track;
113   if (side)          *side = tag->sectors[head * track * sector_index].head;
114   if (sector)        *sector = tag->sectors[head * track * sector_index].sector;
115   if (sector_length) *sector_length = 512;
116 
117   return FLOPPY_ERROR_SUCCESS;
118}
119 
120FLOPPY_IDENTIFY( apridisk_identify )
121{
122   UINT8 header[APR_HEADER_SIZE];
123 
124   /* get header */
125   floppy_image_read(floppy, &header, 0, sizeof(header));
126 
127   /* look for the magic string */
128   if (memcmp(header, apr_magic, sizeof(apr_magic)) == 0)
129      *vote = 100;
130   else
131      *vote = 0;
132 
133   return FLOPPY_ERROR_SUCCESS;
134}
135 
136FLOPPY_CONSTRUCT( apridisk_construct )
137{
138   struct FloppyCallbacks *callbacks;
139   struct apr_tag *tag;
140 
141   int cur_sector = 0;
142   UINT8 sector_header[16];
143   UINT64 pos = 128;
144   UINT32 type;
145 
146   tag = (apr_tag *)floppy_create_tag(floppy, sizeof(struct apr_tag));
147 
148   if (!tag)
149      return FLOPPY_ERROR_OUTOFMEMORY;
150 
151   tag->heads = 0;
152   tag->tracks = 0;
153   tag->sectors_per_track = 0;
154 
155   floppy_image_read(floppy, &sector_header, pos, 16);
156   type = pick_integer_le(&sector_header, 0, 4);
157 
158   while (type == APR_DELETED || type == APR_MAGIC || type == APR_COMMENT || type == APR_CREATOR)
159   {
160      UINT16 compression = pick_integer_le(&sector_header, 4, 2);
161      UINT16 header_size = pick_integer_le(&sector_header, 6, 2);
162      UINT32 data_size = pick_integer_le(&sector_header, 8, 4);
163 
164      tag->sectors[cur_sector].head = pick_integer_le(&sector_header, 12, 1);
165      tag->sectors[cur_sector].sector = pick_integer_le(&sector_header, 13, 1);
166      tag->sectors[cur_sector].track = pick_integer_le(&sector_header, 14, 1);
167 
168      pos += header_size;
169 
170      if (type == APR_MAGIC)
171      {
172         if (compression == APR_UNCOMPRESSED)
173         {
174            floppy_image_read(floppy, &tag->sectors[cur_sector].data, pos, data_size);
175 
176         }
177         else if (compression == APR_COMPRESSED)
178         {
179            UINT8 buffer[data_size];
180            UINT16 length;
181            UINT8 value;
182 
183            floppy_image_read(floppy, &buffer, pos, data_size);
184 
185            length = pick_integer_le(buffer, 0, 2);
186            value = pick_integer_le(buffer, 2, 1);
187 
188            /* not sure if this is possible */
189            if (length != 512)
190               fatalerror("Compression unsupported\n");
191 
192            memset(&tag->sectors[cur_sector].data, value, length);
193         }
194         else
195            return FLOPPY_ERROR_INVALIDIMAGE;
196 
197         tag->heads = MAX(tag->sectors[cur_sector].head, tag->heads);
198         tag->tracks = MAX(tag->sectors[cur_sector].track, tag->tracks);
199         tag->sectors_per_track = MAX(tag->sectors[cur_sector].sector, tag->sectors_per_track);
200      }
201 
202      /* seek to next sector */
203      pos += data_size;
204      cur_sector++;
205 
206      floppy_image_read(floppy, &sector_header, pos, 16);
207      type = pick_integer_le(&sector_header, 0, 4);
208   }
209 
210   tag->heads++;
211   tag->tracks++;
212 
213   callbacks = floppy_callbacks(floppy);
214   callbacks->read_sector = apr_read_sector;
215   callbacks->read_indexed_sector = apr_read_indexed_sector;
216   callbacks->get_sector_length = apr_get_sector_length;
217   callbacks->get_heads_per_disk = apr_get_heads_per_disk;
218   callbacks->get_tracks_per_disk = apr_get_tracks_per_disk;
219   callbacks->get_indexed_sector_info = apr_get_indexed_sector_info;
220 
221   return FLOPPY_ERROR_SUCCESS;
222}
src/mess/formats/apridisk.h
r0r7231
1/***************************************************************************
2 
3    APRIDISK disk image format
4 
5***************************************************************************/
6 
7#ifndef __APRIDISK_H__
8#define __APRIDISK_H__
9 
10#include "flopimg.h"
11 
12FLOPPY_IDENTIFY( apridisk_identify );
13FLOPPY_CONSTRUCT( apridisk_construct );
14 
15#endif /* __APRIDISK_H__ */
src/mess/mess.mak
r7230r7231
544544$(MESSOBJ)/act.a:            \
545545   $(MESS_DRIVERS)/apricot.o   \
546546   $(MESS_DRIVERS)/apricotf.o   \
547   $(MESS_FORMATS)/apridisk.o   \
547548
548549$(MESSOBJ)/amiga.a:            \
549550   $(MAME_VIDEO)/amiga.o      \
src/mess/drivers/apricot.c
r7230r7231
1818#include "video/mc6845.h"
1919#include "devices/messram.h"
2020#include "devices/flopdrv.h"
21#include "formats/apridisk.h"
2122
2223
2324/***************************************************************************
r7230r7231
277278
278279   cpu_set_irq_callback(maincpu, apricot_irq_ack);
279280
280   apricot->pic8259 = devtag_get_device(machine, "pic8259");
281   apricot->wd2793 = devtag_get_device(machine, "wd2793");
282   apricot->mc6845 = devtag_get_device(machine, "mc6845");
281   apricot->pic8259 = devtag_get_device(machine, "ic31");
282   apricot->wd2793 = devtag_get_device(machine, "ic68");
283   apricot->mc6845 = devtag_get_device(machine, "ic30");
283284
284285   apricot->video_mode = 0;
285286   apricot->display_on = 1;
r7230r7231
298299ADDRESS_MAP_END
299300
300301static ADDRESS_MAP_START( apricot_io, ADDRESS_SPACE_IO, 16 )
301   AM_RANGE(0x00, 0x03) AM_DEVREADWRITE8("pic8259", pic8259_r, pic8259_w, 0x00ff)
302   AM_RANGE(0x40, 0x47) AM_DEVREADWRITE8("wd2793", wd17xx_r, wd17xx_w, 0x00ff)
303   AM_RANGE(0x48, 0x4f) AM_DEVREADWRITE8("i8255a", i8255a_r, i8255a_w, 0x00ff)
304   AM_RANGE(0x50, 0x51) AM_DEVWRITE8("sn76489", sn76496_w, 0x00ff)
305   AM_RANGE(0x58, 0x5f) AM_DEVREADWRITE8("pit8253", pit8253_r, pit8253_w, 0x00ff)
306   AM_RANGE(0x60, 0x67) AM_DEVREADWRITE8("z80sio", apricot_sio_r, apricot_sio_w, 0x00ff)
307   AM_RANGE(0x68, 0x69) AM_DEVWRITE8("mc6845", mc6845_address_w, 0x00ff)
308   AM_RANGE(0x6a, 0x6b) AM_DEVREADWRITE8("mc6845", mc6845_register_r, mc6845_register_w, 0x00ff)
309//   AM_RANGE(0x70, 0x73) 8089
302   AM_RANGE(0x00, 0x03) AM_DEVREADWRITE8("ic31", pic8259_r, pic8259_w, 0x00ff)
303   AM_RANGE(0x40, 0x47) AM_DEVREADWRITE8("ic68", wd17xx_r, wd17xx_w, 0x00ff)
304   AM_RANGE(0x48, 0x4f) AM_DEVREADWRITE8("ic17", i8255a_r, i8255a_w, 0x00ff)
305   AM_RANGE(0x50, 0x51) AM_MIRROR(0x06) AM_DEVWRITE8("ic7", sn76496_w, 0x00ff)
306   AM_RANGE(0x58, 0x5f) AM_DEVREADWRITE8("ic16", pit8253_r, pit8253_w, 0x00ff)
307   AM_RANGE(0x60, 0x67) AM_DEVREADWRITE8("ic15", apricot_sio_r, apricot_sio_w, 0x00ff)
308   AM_RANGE(0x68, 0x69) AM_MIRROR(0x04) AM_DEVWRITE8("ic30", mc6845_address_w, 0x00ff)
309   AM_RANGE(0x6a, 0x6b) AM_MIRROR(0x04) AM_DEVREADWRITE8("ic30", mc6845_register_r, mc6845_register_w, 0x00ff)
310//   AM_RANGE(0x70, 0x71) AM_MIRROR(0x04) 8089 channel attention 1
311//   AM_RANGE(0x72, 0x73) AM_MIRROR(0x04) 8089 channel attention 2
312   AM_RANGE(0x78, 0x7f) AM_NOP /* unavailable */
310313ADDRESS_MAP_END
311314
312315
r7230r7231
334337    MACHINE DRIVERS
335338***************************************************************************/
336339
340static FLOPPY_OPTIONS_START( apricot )
341   FLOPPY_OPTION
342   (
343      apridisk, "dsk", "ACT Apricot disk image", apridisk_identify, apridisk_construct,
344      HEADS(1-[2])
345      TRACKS(70/[80])
346      SECTORS([9]/18)
347      SECTOR_LENGTH([512])
348      FIRST_SECTOR_ID([1])
349   )
350FLOPPY_OPTIONS_END
351
337352static const floppy_config apricot_floppy_config =
338353{
339354   DEVCB_NULL,
r7230r7231
342357   DEVCB_NULL,
343358   DEVCB_NULL,
344359   FLOPPY_DRIVE_SS_40,
345   FLOPPY_OPTIONS_NAME(default),
360   FLOPPY_OPTIONS_NAME(apricot),
346361   DO_NOT_KEEP_GEOMETRY
347362};
348363
r7230r7231
354369   MDRV_CPU_PROGRAM_MAP(apricot_mem)
355370   MDRV_CPU_IO_MAP(apricot_io)
356371
372//   MDRV_CPU_ADD("ic71", I8089, XTAL_15MHz / 3)
373
357374   /* video hardware */
358375   MDRV_SCREEN_ADD("screen", RASTER)
359376   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
r7230r7231
366383
367384   MDRV_VIDEO_UPDATE(apricot)
368385
369   MDRV_MC6845_ADD("mc6845", MC6845, XTAL_15MHz / 10, apricot_mc6845_intf)
386   MDRV_MC6845_ADD("ic30", MC6845, XTAL_15MHz / 10, apricot_mc6845_intf)
370387
371388   /* sound hardware */
372389   MDRV_SPEAKER_STANDARD_MONO("mono")
373   MDRV_SOUND_ADD("sn76489", SN76489, XTAL_4MHz / 2)
390   MDRV_SOUND_ADD("ic7", SN76489, XTAL_4MHz / 2)
374391   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
375392
376393   /* internal ram */
r7230r7231
378395   MDRV_RAM_DEFAULT_SIZE("256k")
379396   MDRV_RAM_EXTRA_OPTIONS("384k,512k") /* with 1 or 2 128k expansion boards */
380397
381   MDRV_I8255A_ADD("i8255a", apricot_i8255a_intf)
382   MDRV_PIC8259_ADD("pic8259", apricot_pic8259_intf)
383   MDRV_PIT8253_ADD("pit8253", apricot_pit8253_intf)
384   MDRV_Z80SIO_ADD("z80sio", 0, apricot_z80sio_intf)
398   MDRV_I8255A_ADD("ic17", apricot_i8255a_intf)
399   MDRV_PIC8259_ADD("ic31", apricot_pic8259_intf)
400   MDRV_PIT8253_ADD("ic16", apricot_pit8253_intf)
401   MDRV_Z80SIO_ADD("ic15", 0, apricot_z80sio_intf)
385402
386403   /* floppy */
387   MDRV_WD2793_ADD("wd2793", apricot_wd17xx_intf)
404   MDRV_WD2793_ADD("ic68", apricot_wd17xx_intf)
388405   MDRV_FLOPPY_2_DRIVES_ADD(apricot_floppy_config)
389406MACHINE_DRIVER_END
390407

Previous 15994 Revisions Next


© 1998-2018 The MESS Team