src/mess/formats/fm7_dsk.c
| r5801 | r5802 | |
| 1 | | /* |
| 2 | | * Fujitsu FM-7 series D77 disk images |
| 3 | | * |
| 4 | | * |
| 5 | | * Header (total size = 0x2b0 bytes): |
| 6 | | * 0x00 - Disk label |
| 7 | | * 0x1a - Write protect (bit 3) |
| 8 | | * 0x1b - 2D/2DD format (bit 3) |
| 9 | | * 0x1c-1f - image size (should match file size) |
| 10 | | * 0x20 - offsets for each track (max 164) |
| 11 | | * |
| 12 | | * Sectors (0x110 bytes each, typically) |
| 13 | | * 0x00 - Sector info |
| 14 | | * byte 0 - track number |
| 15 | | * byte 1 - side (0 or 1) |
| 16 | | * byte 2 - sector number |
| 17 | | * 0x10 - sector data |
| 18 | | * |
| 19 | | * Images can be concatenated together. |
| 20 | | * Sectors can be in any order. |
| 21 | | * Tracks are in the order: |
| 22 | | * Track 0 side 0 |
| 23 | | * Track 0 side 1 |
| 24 | | * Track 1 side 0 |
| 25 | | * ... |
| 26 | | * |
| 27 | | * |
| 28 | | */ |
| 29 | | |
| 30 | | #include "driver.h" |
| 31 | | #include "formats/fm7_dsk.h" |
| 32 | | |
| 33 | | #define D77_HEADER_LEN 0x2b0 |
| 34 | | |
| 35 | | struct d77_tag |
| 36 | | { |
| 37 | | UINT32 image_size; |
| 38 | | UINT32 trackoffset[164]; |
| 39 | | UINT8 write_protect; |
| 40 | | UINT8 disk_type; |
| 41 | | }; |
| 42 | | |
| 43 | | static struct d77_tag *get_d77_tag(floppy_image *floppy) |
| 44 | | { |
| 45 | | return floppy_tag(floppy, "d77tag"); |
| 46 | | } |
| 47 | | |
| 48 | | static int d77_get_sector_id(floppy_image *floppy, int head, int track, int sector_index) |
| 49 | | { |
| 50 | | struct d77_tag* tag = get_d77_tag(floppy); |
| 51 | | UINT32 offset; |
| 52 | | UINT8 sector_hdr[16]; |
| 53 | | int x; |
| 54 | | |
| 55 | | offset = tag->trackoffset[(track*2)+head]; |
| 56 | | |
| 57 | | if(offset == 0) |
| 58 | | return 0; |
| 59 | | |
| 60 | | floppy_image_read(floppy,sector_hdr,offset,16); |
| 61 | | |
| 62 | | // get to sector indexed |
| 63 | | x=0; |
| 64 | | while(x<sector_index) |
| 65 | | { |
| 66 | | offset += ((sector_hdr[15] << 8) | sector_hdr[14]); |
| 67 | | offset += 16; |
| 68 | | floppy_image_read(floppy,sector_hdr,offset,16); |
| 69 | | x++; |
| 70 | | } |
| 71 | | |
| 72 | | return sector_hdr[2]; |
| 73 | | } |
| 74 | | |
| 75 | | static int d77_get_tracks_per_disk(floppy_image *floppy) |
| 76 | | { |
| 77 | | return 82; // 82 tracks per side |
| 78 | | } |
| 79 | | |
| 80 | | static int d77_get_heads_per_disk(floppy_image *floppy) |
| 81 | | { |
| 82 | | return 2; // 2 heads |
| 83 | | } |
| 84 | | |
| 85 | | static int d77_get_sectors_per_track(floppy_image *floppy, int head, int track) |
| 86 | | { |
| 87 | | struct d77_tag* tag = get_d77_tag(floppy); |
| 88 | | UINT32 offset; |
| 89 | | UINT8 sector_hdr[16]; |
| 90 | | |
| 91 | | offset = tag->trackoffset[(track*2)+head]; |
| 92 | | |
| 93 | | floppy_image_read(floppy,sector_hdr,offset,16); |
| 94 | | |
| 95 | | return sector_hdr[4]; |
| 96 | | } |
| 97 | | |
| 98 | | static floperr_t d77_get_sector_length(floppy_image *floppy, int head, int track, int sector, UINT32 *sector_length) |
| 99 | | { |
| 100 | | struct d77_tag* tag = get_d77_tag(floppy); |
| 101 | | UINT32 offset; |
| 102 | | UINT8 sector_hdr[16]; |
| 103 | | UINT32 len; |
| 104 | | int count,secs; |
| 105 | | |
| 106 | | offset = tag->trackoffset[(track*2)+head]; |
| 107 | | |
| 108 | | floppy_image_read(floppy,sector_hdr,offset,16); |
| 109 | | secs = sector_hdr[4]; |
| 110 | | |
| 111 | | for(count=0;count<secs;count++) |
| 112 | | { |
| 113 | | floppy_image_read(floppy,sector_hdr,offset,16); |
| 114 | | if(sector == sector_hdr[2]) |
| 115 | | { |
| 116 | | if(sector_length) |
| 117 | | *sector_length = (sector_hdr[15] << 8) | sector_hdr[14]; |
| 118 | | return FLOPPY_ERROR_SUCCESS; |
| 119 | | } |
| 120 | | len = (sector_hdr[15] << 8) | sector_hdr[14]; |
| 121 | | len += 16; |
| 122 | | offset += len; |
| 123 | | } |
| 124 | | |
| 125 | | return FLOPPY_ERROR_SEEKERROR; |
| 126 | | } |
| 127 | | |
| 128 | | static floperr_t d77_read_track(floppy_image *floppy, int head, int track, UINT64 offset, void *buffer, size_t buflen) |
| 129 | | { |
| 130 | | // floperr_t err; |
| 131 | | |
| 132 | | return FLOPPY_ERROR_UNSUPPORTED; |
| 133 | | } |
| 134 | | |
| 135 | | static UINT32 d77_get_sector_offset(floppy_image* floppy, int head, int track, int sector) |
| 136 | | { |
| 137 | | struct d77_tag* tag = get_d77_tag(floppy); |
| 138 | | UINT32 offset = 0; |
| 139 | | UINT8 sector_hdr[16]; |
| 140 | | UINT32 len; |
| 141 | | UINT32 secs; |
| 142 | | int count; |
| 143 | | |
| 144 | | // get offset of the beginning of the track |
| 145 | | offset = tag->trackoffset[(track*2)+head]; |
| 146 | | |
| 147 | | floppy_image_read(floppy,sector_hdr,offset,16); |
| 148 | | secs = sector_hdr[4]; |
| 149 | | |
| 150 | | for(count=0;count<secs;count++) |
| 151 | | { |
| 152 | | floppy_image_read(floppy,sector_hdr,offset,16); |
| 153 | | if(sector == sector_hdr[2]) |
| 154 | | { |
| 155 | | logerror("d77_get_sector_offset - track %i, side %i, sector %02x, returns %08x\n",track,head,sector,offset+16); |
| 156 | | return offset + 16; |
| 157 | | } |
| 158 | | len = (sector_hdr[15] << 8) | sector_hdr[14]; |
| 159 | | len += 16; |
| 160 | | offset += len; |
| 161 | | } |
| 162 | | logerror("d77_get_sector_offset - track %i, side %i, sector %02x, not found\n",track,head,sector); |
| 163 | | return 0; |
| 164 | | } |
| 165 | | |
| 166 | | static floperr_t d77_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) |
| 167 | | { |
| 168 | | struct d77_tag* tag = get_d77_tag(floppy); |
| 169 | | UINT32 offset; |
| 170 | | UINT8 sector_hdr[16]; |
| 171 | | int x; |
| 172 | | |
| 173 | | offset = tag->trackoffset[(track*2)+head]; |
| 174 | | |
| 175 | | if(offset == 0) |
| 176 | | return FLOPPY_ERROR_SEEKERROR; |
| 177 | | |
| 178 | | |
| 179 | | floppy_image_read(floppy,sector_hdr,offset,16); |
| 180 | | |
| 181 | | if(sector_index >= sector_hdr[4]) |
| 182 | | return FLOPPY_ERROR_SEEKERROR; |
| 183 | | |
| 184 | | // get to sector indexed |
| 185 | | x=0; |
| 186 | | while(x<sector_index) |
| 187 | | { |
| 188 | | offset += ((sector_hdr[15] << 8) | sector_hdr[14]); |
| 189 | | offset += 16; |
| 190 | | floppy_image_read(floppy,sector_hdr,offset,16); |
| 191 | | x++; |
| 192 | | } |
| 193 | | |
| 194 | | if(offset > tag->image_size || offset == 0) |
| 195 | | return FLOPPY_ERROR_SEEKERROR; |
| 196 | | |
| 197 | | if(sector_length) |
| 198 | | *sector_length = (sector_hdr[15] << 8) | sector_hdr[14]; |
| 199 | | if(cylinder) |
| 200 | | *cylinder = sector_hdr[0]; |
| 201 | | if(side) |
| 202 | | *side = sector_hdr[1]; |
| 203 | | if(sector) |
| 204 | | *sector = sector_hdr[2]; |
| 205 | | if(flags) |
| 206 | | *flags = 0; |
| 207 | | |
| 208 | | return FLOPPY_ERROR_SUCCESS; |
| 209 | | } |
| 210 | | |
| 211 | | static floperr_t d77_read_sector(floppy_image *floppy, int head, int track, int sector, void *buffer, size_t buflen) |
| 212 | | { |
| 213 | | UINT64 offset; |
| 214 | | UINT32 sector_length; |
| 215 | | |
| 216 | | offset = d77_get_sector_offset(floppy,head,track,sector); |
| 217 | | |
| 218 | | if(d77_get_sector_length(floppy,head,track,sector,§or_length) != FLOPPY_ERROR_SUCCESS) |
| 219 | | return FLOPPY_ERROR_SEEKERROR; |
| 220 | | |
| 221 | | if(offset == 0) |
| 222 | | return FLOPPY_ERROR_SEEKERROR; |
| 223 | | |
| 224 | | if(buflen > sector_length) |
| 225 | | return FLOPPY_ERROR_INTERNAL; |
| 226 | | |
| 227 | | floppy_image_read(floppy,buffer,offset,sector_length); |
| 228 | | |
| 229 | | return FLOPPY_ERROR_SUCCESS; |
| 230 | | } |
| 231 | | |
| 232 | | static floperr_t d77_read_indexed_sector(floppy_image *floppy, int head, int track, int sector, void *buffer, size_t buffer_len) |
| 233 | | { |
| 234 | | int sec; |
| 235 | | |
| 236 | | sec = d77_get_sector_id(floppy,head,track,sector); |
| 237 | | return d77_read_sector(floppy,head,track,sec,buffer,buffer_len); |
| 238 | | } |
| 239 | | |
| 240 | | static void d77_get_header(floppy_image* floppy,UINT32* size, UINT8* prot, UINT8* type, UINT32* offsets) |
| 241 | | { |
| 242 | | UINT8 header[D77_HEADER_LEN]; |
| 243 | | int x,s; |
| 244 | | |
| 245 | | floppy_image_read(floppy,header,0,D77_HEADER_LEN); |
| 246 | | |
| 247 | | if(prot) |
| 248 | | *prot = header[0x1a]; |
| 249 | | if(type) |
| 250 | | *prot = header[0x1b]; |
| 251 | | if(size) |
| 252 | | { |
| 253 | | s = 0; |
| 254 | | s |= header[0x1f] << 24; |
| 255 | | s |= header[0x1e] << 16; |
| 256 | | s |= header[0x1d] << 8; |
| 257 | | s |= header[0x1c]; |
| 258 | | *size = s; |
| 259 | | } |
| 260 | | if(offsets) |
| 261 | | { |
| 262 | | for(x=0;x<164;x++) |
| 263 | | { |
| 264 | | s = 0; |
| 265 | | s |= header[0x23 + (x*4)] << 24; |
| 266 | | s |= header[0x22 + (x*4)] << 16; |
| 267 | | s |= header[0x21 + (x*4)] << 8; |
| 268 | | s |= header[0x20 + (x*4)]; |
| 269 | | *(offsets+x) = s; |
| 270 | | } |
| 271 | | } |
| 272 | | } |
| 273 | | |
| 274 | | FLOPPY_IDENTIFY(fm7_d77_identify) |
| 275 | | { |
| 276 | | UINT32 size; |
| 277 | | |
| 278 | | d77_get_header(floppy,&size,NULL,NULL,NULL); |
| 279 | | |
| 280 | | if(floppy_image_size(floppy) == size) |
| 281 | | { |
| 282 | | *vote = 100; |
| 283 | | return FLOPPY_ERROR_SUCCESS; |
| 284 | | } |
| 285 | | else |
| 286 | | { |
| 287 | | *vote = 0; |
| 288 | | return FLOPPY_ERROR_INVALIDIMAGE; |
| 289 | | } |
| 290 | | } |
| 291 | | |
| 292 | | FLOPPY_CONSTRUCT(fm7_d77_construct) |
| 293 | | { |
| 294 | | struct FloppyCallbacks *callbacks; |
| 295 | | struct d77_tag *tag; |
| 296 | | UINT32 size; |
| 297 | | UINT8 prot,type = 0; |
| 298 | | UINT32 offs[164]; |
| 299 | | int x; |
| 300 | | |
| 301 | | if(params) |
| 302 | | { |
| 303 | | // create |
| 304 | | return FLOPPY_ERROR_UNSUPPORTED; |
| 305 | | } |
| 306 | | else |
| 307 | | { |
| 308 | | // load |
| 309 | | d77_get_header(floppy,&size,&prot,&type,offs); |
| 310 | | } |
| 311 | | |
| 312 | | tag = floppy_create_tag(floppy,"d77tag",sizeof(struct d77_tag)); |
| 313 | | if (!tag) |
| 314 | | return FLOPPY_ERROR_OUTOFMEMORY; |
| 315 | | |
| 316 | | tag->write_protect = prot; |
| 317 | | tag->disk_type = type; |
| 318 | | tag->image_size = size; |
| 319 | | for(x=0;x<164;x++) |
| 320 | | tag->trackoffset[x] = offs[x]; |
| 321 | | |
| 322 | | callbacks = floppy_callbacks(floppy); |
| 323 | | callbacks->read_track = d77_read_track; |
| 324 | | callbacks->get_heads_per_disk = d77_get_heads_per_disk; |
| 325 | | callbacks->get_tracks_per_disk = d77_get_tracks_per_disk; |
| 326 | | callbacks->get_sector_length = d77_get_sector_length; |
| 327 | | callbacks->read_sector = d77_read_sector; |
| 328 | | callbacks->read_indexed_sector = d77_read_indexed_sector; |
| 329 | | callbacks->get_indexed_sector_info = d77_get_indexed_sector_info; |
| 330 | | callbacks->get_sectors_per_track = d77_get_sectors_per_track; |
| 331 | | |
| 332 | | |
| 333 | | return FLOPPY_ERROR_SUCCESS; |
| 334 | | } |
| 335 | | |
| 336 | | FLOPPY_OPTIONS_START( fm7 ) |
| 337 | | FLOPPY_OPTION( fm7_d77, "d77", "XM7 FM-7 Floppy Disk image", fm7_d77_identify, fm7_d77_construct, |
| 338 | | HEADS(1-[2]) |
| 339 | | TRACKS([82]) |
| 340 | | SECTORS(1-[17]) |
| 341 | | SECTOR_LENGTH(128/[256]) |
| 342 | | FIRST_SECTOR_ID(0-[1])) |
| 343 | | FLOPPY_OPTIONS_END |
| 344 | | |
| 345 | | |
src/mess/formats/d88_dsk.c
| r0 | r5802 | |
| 1 | /* |
| 2 | * D77 and D88 disk images |
| 3 | * |
| 4 | * |
| 5 | * Header (total size = 0x2b0 bytes): |
| 6 | * 0x00 - Disk label |
| 7 | * 0x1a - Write protect (bit 3) |
| 8 | * 0x1b - 2D/2DD format (bit 3) |
| 9 | * 0x1c-1f - image size (should match file size) |
| 10 | * 0x20 - offsets for each track (max 164) |
| 11 | * |
| 12 | * Sectors (0x110 bytes each, typically) |
| 13 | * 0x00 - Sector info |
| 14 | * byte 0 - track number |
| 15 | * byte 1 - side (0 or 1) |
| 16 | * byte 2 - sector number |
| 17 | * 0x10 - sector data |
| 18 | * |
| 19 | * Images can be concatenated together. |
| 20 | * Sectors can be in any order. |
| 21 | * Tracks are in the order: |
| 22 | * Track 0 side 0 |
| 23 | * Track 0 side 1 |
| 24 | * Track 1 side 0 |
| 25 | * ... |
| 26 | * |
| 27 | * |
| 28 | */ |
| 29 | |
| 30 | #include "driver.h" |
| 31 | #include "formats/flopimg.h" |
| 32 | #include "devices/flopdrv.h" |
| 33 | |
| 34 | #define D88_HEADER_LEN 0x2b0 |
| 35 | |
| 36 | struct d88_tag |
| 37 | { |
| 38 | UINT32 image_size; |
| 39 | UINT32 trackoffset[164]; |
| 40 | UINT8 write_protect; |
| 41 | UINT8 disk_type; |
| 42 | }; |
| 43 | |
| 44 | static struct d88_tag *get_d88_tag(floppy_image *floppy) |
| 45 | { |
| 46 | return floppy_tag(floppy, "d88tag"); |
| 47 | } |
| 48 | |
| 49 | static int d88_get_sector_id(floppy_image *floppy, int head, int track, int sector_index) |
| 50 | { |
| 51 | struct d88_tag* tag = get_d88_tag(floppy); |
| 52 | UINT32 offset; |
| 53 | UINT8 sector_hdr[16]; |
| 54 | int x; |
| 55 | |
| 56 | offset = tag->trackoffset[(track*2)+head]; |
| 57 | |
| 58 | if(offset == 0) |
| 59 | return 0; |
| 60 | |
| 61 | floppy_image_read(floppy,sector_hdr,offset,16); |
| 62 | |
| 63 | // get to sector indexed |
| 64 | x=0; |
| 65 | while(x<sector_index) |
| 66 | { |
| 67 | offset += ((sector_hdr[15] << 8) | sector_hdr[14]); |
| 68 | offset += 16; |
| 69 | floppy_image_read(floppy,sector_hdr,offset,16); |
| 70 | x++; |
| 71 | } |
| 72 | |
| 73 | return sector_hdr[2]; |
| 74 | } |
| 75 | |
| 76 | static int d88_get_tracks_per_disk(floppy_image *floppy) |
| 77 | { |
| 78 | return 82; // 82 tracks per side |
| 79 | } |
| 80 | |
| 81 | static int d88_get_heads_per_disk(floppy_image *floppy) |
| 82 | { |
| 83 | return 2; // 2 heads |
| 84 | } |
| 85 | |
| 86 | static int d88_get_sectors_per_track(floppy_image *floppy, int head, int track) |
| 87 | { |
| 88 | struct d88_tag* tag = get_d88_tag(floppy); |
| 89 | UINT32 offset; |
| 90 | UINT8 sector_hdr[16]; |
| 91 | |
| 92 | offset = tag->trackoffset[(track*2)+head]; |
| 93 | |
| 94 | floppy_image_read(floppy,sector_hdr,offset,16); |
| 95 | |
| 96 | return sector_hdr[4]; |
| 97 | } |
| 98 | |
| 99 | static floperr_t d88_get_sector_length(floppy_image *floppy, int head, int track, int sector, UINT32 *sector_length) |
| 100 | { |
| 101 | struct d88_tag* tag = get_d88_tag(floppy); |
| 102 | UINT32 offset; |
| 103 | UINT8 sector_hdr[16]; |
| 104 | UINT32 len; |
| 105 | int count,secs; |
| 106 | |
| 107 | offset = tag->trackoffset[(track*2)+head]; |
| 108 | |
| 109 | floppy_image_read(floppy,sector_hdr,offset,16); |
| 110 | secs = sector_hdr[4]; |
| 111 | |
| 112 | for(count=0;count<secs;count++) |
| 113 | { |
| 114 | floppy_image_read(floppy,sector_hdr,offset,16); |
| 115 | if(sector == sector_hdr[2]) |
| 116 | { |
| 117 | if(sector_length) |
| 118 | *sector_length = (sector_hdr[15] << 8) | sector_hdr[14]; |
| 119 | return FLOPPY_ERROR_SUCCESS; |
| 120 | } |
| 121 | len = (sector_hdr[15] << 8) | sector_hdr[14]; |
| 122 | len += 16; |
| 123 | offset += len; |
| 124 | } |
| 125 | |
| 126 | return FLOPPY_ERROR_SEEKERROR; |
| 127 | } |
| 128 | |
| 129 | static floperr_t d88_read_track(floppy_image *floppy, int head, int track, UINT64 offset, void *buffer, size_t buflen) |
| 130 | { |
| 131 | // floperr_t err; |
| 132 | |
| 133 | return FLOPPY_ERROR_UNSUPPORTED; |
| 134 | } |
| 135 | |
| 136 | static UINT32 d88_get_sector_offset(floppy_image* floppy, int head, int track, int sector) |
| 137 | { |
| 138 | struct d88_tag* tag = get_d88_tag(floppy); |
| 139 | UINT32 offset = 0; |
| 140 | UINT8 sector_hdr[16]; |
| 141 | UINT32 len; |
| 142 | UINT32 secs; |
| 143 | int count; |
| 144 | |
| 145 | // get offset of the beginning of the track |
| 146 | offset = tag->trackoffset[(track*2)+head]; |
| 147 | |
| 148 | floppy_image_read(floppy,sector_hdr,offset,16); |
| 149 | secs = sector_hdr[4]; |
| 150 | |
| 151 | for(count=0;count<secs;count++) |
| 152 | { |
| 153 | floppy_image_read(floppy,sector_hdr,offset,16); |
| 154 | if(sector == sector_hdr[2]) |
| 155 | { |
| 156 | logerror("d88_get_sector_offset - track %i, side %i, sector %02x, returns %08x\n",track,head,sector,offset+16); |
| 157 | return offset + 16; |
| 158 | } |
| 159 | len = (sector_hdr[15] << 8) | sector_hdr[14]; |
| 160 | len += 16; |
| 161 | offset += len; |
| 162 | } |
| 163 | logerror("d88_get_sector_offset - track %i, side %i, sector %02x, not found\n",track,head,sector); |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | static floperr_t d88_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) |
| 168 | { |
| 169 | struct d88_tag* tag = get_d88_tag(floppy); |
| 170 | UINT32 offset; |
| 171 | UINT8 sector_hdr[16]; |
| 172 | int x; |
| 173 | |
| 174 | offset = tag->trackoffset[(track*2)+head]; |
| 175 | |
| 176 | if(offset == 0) |
| 177 | return FLOPPY_ERROR_SEEKERROR; |
| 178 | |
| 179 | |
| 180 | floppy_image_read(floppy,sector_hdr,offset,16); |
| 181 | |
| 182 | if(sector_index >= sector_hdr[4]) |
| 183 | return FLOPPY_ERROR_SEEKERROR; |
| 184 | |
| 185 | // get to sector indexed |
| 186 | x=0; |
| 187 | while(x<sector_index) |
| 188 | { |
| 189 | offset += ((sector_hdr[15] << 8) | sector_hdr[14]); |
| 190 | offset += 16; |
| 191 | floppy_image_read(floppy,sector_hdr,offset,16); |
| 192 | x++; |
| 193 | } |
| 194 | |
| 195 | if(offset > tag->image_size || offset == 0) |
| 196 | return FLOPPY_ERROR_SEEKERROR; |
| 197 | |
| 198 | if(sector_length) |
| 199 | *sector_length = (sector_hdr[15] << 8) | sector_hdr[14]; |
| 200 | if(cylinder) |
| 201 | *cylinder = sector_hdr[0]; |
| 202 | if(side) |
| 203 | *side = sector_hdr[1]; |
| 204 | if(sector) |
| 205 | *sector = sector_hdr[2]; |
| 206 | if(flags) |
| 207 | *flags = 0; |
| 208 | |
| 209 | return FLOPPY_ERROR_SUCCESS; |
| 210 | } |
| 211 | |
| 212 | static floperr_t d88_read_sector(floppy_image *floppy, int head, int track, int sector, void *buffer, size_t buflen) |
| 213 | { |
| 214 | UINT64 offset; |
| 215 | UINT32 sector_length; |
| 216 | |
| 217 | offset = d88_get_sector_offset(floppy,head,track,sector); |
| 218 | |
| 219 | if(d88_get_sector_length(floppy,head,track,sector,§or_length) != FLOPPY_ERROR_SUCCESS) |
| 220 | return FLOPPY_ERROR_SEEKERROR; |
| 221 | |
| 222 | if(offset == 0) |
| 223 | return FLOPPY_ERROR_SEEKERROR; |
| 224 | |
| 225 | if(buflen > sector_length) |
| 226 | return FLOPPY_ERROR_INTERNAL; |
| 227 | |
| 228 | floppy_image_read(floppy,buffer,offset,sector_length); |
| 229 | |
| 230 | return FLOPPY_ERROR_SUCCESS; |
| 231 | } |
| 232 | |
| 233 | static floperr_t d88_read_indexed_sector(floppy_image *floppy, int head, int track, int sector, void *buffer, size_t buffer_len) |
| 234 | { |
| 235 | int sec; |
| 236 | |
| 237 | sec = d88_get_sector_id(floppy,head,track,sector); |
| 238 | return d88_read_sector(floppy,head,track,sec,buffer,buffer_len); |
| 239 | } |
| 240 | |
| 241 | static void d88_get_header(floppy_image* floppy,UINT32* size, UINT8* prot, UINT8* type, UINT32* offsets) |
| 242 | { |
| 243 | UINT8 header[D88_HEADER_LEN]; |
| 244 | int x,s; |
| 245 | |
| 246 | floppy_image_read(floppy,header,0,D88_HEADER_LEN); |
| 247 | |
| 248 | if(prot) |
| 249 | *prot = header[0x1a]; |
| 250 | if(type) |
| 251 | *prot = header[0x1b]; |
| 252 | if(size) |
| 253 | { |
| 254 | s = 0; |
| 255 | s |= header[0x1f] << 24; |
| 256 | s |= header[0x1e] << 16; |
| 257 | s |= header[0x1d] << 8; |
| 258 | s |= header[0x1c]; |
| 259 | *size = s; |
| 260 | } |
| 261 | if(offsets) |
| 262 | { |
| 263 | for(x=0;x<164;x++) |
| 264 | { |
| 265 | s = 0; |
| 266 | s |= header[0x23 + (x*4)] << 24; |
| 267 | s |= header[0x22 + (x*4)] << 16; |
| 268 | s |= header[0x21 + (x*4)] << 8; |
| 269 | s |= header[0x20 + (x*4)]; |
| 270 | *(offsets+x) = s; |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | FLOPPY_IDENTIFY(d88_dsk_identify) |
| 276 | { |
| 277 | UINT32 size; |
| 278 | |
| 279 | d88_get_header(floppy,&size,NULL,NULL,NULL); |
| 280 | |
| 281 | if(floppy_image_size(floppy) == size) |
| 282 | { |
| 283 | *vote = 100; |
| 284 | return FLOPPY_ERROR_SUCCESS; |
| 285 | } |
| 286 | else |
| 287 | { |
| 288 | *vote = 0; |
| 289 | return FLOPPY_ERROR_INVALIDIMAGE; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | FLOPPY_CONSTRUCT(d88_dsk_construct) |
| 294 | { |
| 295 | struct FloppyCallbacks *callbacks; |
| 296 | struct d88_tag *tag; |
| 297 | UINT32 size; |
| 298 | UINT8 prot,type = 0; |
| 299 | UINT32 offs[164]; |
| 300 | int x; |
| 301 | |
| 302 | if(params) |
| 303 | { |
| 304 | // create |
| 305 | return FLOPPY_ERROR_UNSUPPORTED; |
| 306 | } |
| 307 | else |
| 308 | { |
| 309 | // load |
| 310 | d88_get_header(floppy,&size,&prot,&type,offs); |
| 311 | } |
| 312 | |
| 313 | tag = floppy_create_tag(floppy,"d88tag",sizeof(struct d88_tag)); |
| 314 | if (!tag) |
| 315 | return FLOPPY_ERROR_OUTOFMEMORY; |
| 316 | |
| 317 | tag->write_protect = prot; |
| 318 | tag->disk_type = type; |
| 319 | tag->image_size = size; |
| 320 | for(x=0;x<164;x++) |
| 321 | tag->trackoffset[x] = offs[x]; |
| 322 | |
| 323 | callbacks = floppy_callbacks(floppy); |
| 324 | callbacks->read_track = d88_read_track; |
| 325 | callbacks->get_heads_per_disk = d88_get_heads_per_disk; |
| 326 | callbacks->get_tracks_per_disk = d88_get_tracks_per_disk; |
| 327 | callbacks->get_sector_length = d88_get_sector_length; |
| 328 | callbacks->read_sector = d88_read_sector; |
| 329 | callbacks->read_indexed_sector = d88_read_indexed_sector; |
| 330 | callbacks->get_indexed_sector_info = d88_get_indexed_sector_info; |
| 331 | callbacks->get_sectors_per_track = d88_get_sectors_per_track; |
| 332 | |
| 333 | |
| 334 | return FLOPPY_ERROR_SUCCESS; |
| 335 | } |
src/mess/formats/imd_dsk.c
| r0 | r5802 | |
| 1 | /********************************************************************* |
| 2 | |
| 3 | formats/imd_dsk.c |
| 4 | |
| 5 | IMD disk images |
| 6 | |
| 7 | *********************************************************************/ |
| 8 | |
| 9 | #include <string.h> |
| 10 | #include "driver.h" |
| 11 | #include "formats/flopimg.h" |
| 12 | #include "devices/flopdrv.h" |
| 13 | |
| 14 | #define IMD_DSK_TAG "imdtag" |
| 15 | |
| 16 | struct imddsk_tag |
| 17 | { |
| 18 | int heads; |
| 19 | int tracks; |
| 20 | int sector_size; |
| 21 | UINT64 track_offsets[84*2]; /* offset within data for each track */ |
| 22 | }; |
| 23 | |
| 24 | |
| 25 | static struct imddsk_tag *get_tag(floppy_image *floppy) |
| 26 | { |
| 27 | struct imddsk_tag *tag; |
| 28 | tag = floppy_tag(floppy, IMD_DSK_TAG); |
| 29 | return tag; |
| 30 | } |
| 31 | |
| 32 | |
| 33 | |
| 34 | FLOPPY_IDENTIFY( imd_dsk_identify ) |
| 35 | { |
| 36 | UINT8 header[3]; |
| 37 | |
| 38 | floppy_image_read(floppy, header, 0, 3); |
| 39 | if (header[0]=='I' && header[1]=='M' && header[1]=='D') { |
| 40 | *vote = 100; |
| 41 | } else { |
| 42 | *vote = 0; |
| 43 | } |
| 44 | return FLOPPY_ERROR_SUCCESS; |
| 45 | } |
| 46 | |
| 47 | static int imd_get_heads_per_disk(floppy_image *floppy) |
| 48 | { |
| 49 | return get_tag(floppy)->heads; |
| 50 | } |
| 51 | |
| 52 | static int imd_get_tracks_per_disk(floppy_image *floppy) |
| 53 | { |
| 54 | return get_tag(floppy)->tracks; |
| 55 | } |
| 56 | |
| 57 | /*static UINT64 imd_get_track_offset(floppy_image *floppy, int head, int track) |
| 58 | { |
| 59 | return get_tag(floppy)->track_offsets[(track<<1) + head]; |
| 60 | } |
| 61 | */ |
| 62 | static floperr_t get_offset(floppy_image *floppy, int head, int track, int sector, int sector_is_index, UINT64 *offset) |
| 63 | { |
| 64 | UINT64 offs; |
| 65 | UINT8 sectors_per_track = 0; |
| 66 | |
| 67 | if ((head < 0) || (head >= get_tag(floppy)->heads) || (track < 0) || (track >= get_tag(floppy)->tracks) |
| 68 | || (sector < 0) ) |
| 69 | return FLOPPY_ERROR_SEEKERROR; |
| 70 | |
| 71 | |
| 72 | if (!sector_is_index) { |
| 73 | // when taking ID's return seek error if number is over counter |
| 74 | if (sector > sectors_per_track) { |
| 75 | return FLOPPY_ERROR_SEEKERROR; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | if (offset) |
| 80 | *offset = offs; |
| 81 | return FLOPPY_ERROR_SUCCESS; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | |
| 86 | static floperr_t internal_imd_read_sector(floppy_image *floppy, int head, int track, int sector, int sector_is_index, void *buffer, size_t buflen) |
| 87 | { |
| 88 | UINT64 offset; |
| 89 | floperr_t err; |
| 90 | |
| 91 | // take sector offset |
| 92 | err = get_offset(floppy, head, track, sector, sector_is_index, &offset); |
| 93 | if (err) |
| 94 | return err; |
| 95 | |
| 96 | return FLOPPY_ERROR_SUCCESS; |
| 97 | } |
| 98 | |
| 99 | |
| 100 | static floperr_t imd_read_sector(floppy_image *floppy, int head, int track, int sector, void *buffer, size_t buflen) |
| 101 | { |
| 102 | return internal_imd_read_sector(floppy, head, track, sector, FALSE, buffer, buflen); |
| 103 | } |
| 104 | |
| 105 | static floperr_t imd_read_indexed_sector(floppy_image *floppy, int head, int track, int sector, void *buffer, size_t buflen) |
| 106 | { |
| 107 | return internal_imd_read_sector(floppy, head, track, sector, TRUE, buffer, buflen); |
| 108 | } |
| 109 | |
| 110 | static floperr_t imd_get_sector_length(floppy_image *floppy, int head, int track, int sector, UINT32 *sector_length) |
| 111 | { |
| 112 | floperr_t err; |
| 113 | err = get_offset(floppy, head, track, sector, FALSE, NULL); |
| 114 | if (err) |
| 115 | return err; |
| 116 | |
| 117 | if (sector_length) { |
| 118 | *sector_length = get_tag(floppy)->sector_size; |
| 119 | } |
| 120 | return FLOPPY_ERROR_SUCCESS; |
| 121 | } |
| 122 | |
| 123 | static floperr_t imd_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) |
| 124 | { |
| 125 | floperr_t retVal; |
| 126 | UINT64 offset; |
| 127 | |
| 128 | retVal = get_offset(floppy, head, track, sector_index, FALSE, &offset); |
| 129 | |
| 130 | if (cylinder) |
| 131 | *cylinder = 0; |
| 132 | if (side) |
| 133 | *side = 0; |
| 134 | if (sector) |
| 135 | *sector = 0; |
| 136 | if (sector_length) { |
| 137 | *sector_length = 0; |
| 138 | } |
| 139 | if (flags) |
| 140 | *flags = 0; |
| 141 | return retVal; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | FLOPPY_CONSTRUCT( imd_dsk_construct ) |
| 146 | { |
| 147 | struct FloppyCallbacks *callbacks; |
| 148 | |
| 149 | if(params) |
| 150 | { |
| 151 | // create |
| 152 | return FLOPPY_ERROR_UNSUPPORTED; |
| 153 | } |
| 154 | |
| 155 | callbacks = floppy_callbacks(floppy); |
| 156 | callbacks->read_sector = imd_read_sector; |
| 157 | callbacks->read_indexed_sector = imd_read_indexed_sector; |
| 158 | callbacks->get_sector_length = imd_get_sector_length; |
| 159 | callbacks->get_heads_per_disk = imd_get_heads_per_disk; |
| 160 | callbacks->get_tracks_per_disk = imd_get_tracks_per_disk; |
| 161 | callbacks->get_indexed_sector_info = imd_get_indexed_sector_info; |
| 162 | |
| 163 | return FLOPPY_ERROR_UNSUPPORTED; |
| 164 | } |
| 165 | |
src/mess/formats/dsk_dsk.c
| r5801 | r5802 | |
| 8 | 8 | |
| 9 | 9 | #include <string.h> |
| 10 | 10 | #include "driver.h" |
| 11 | | #include "formats/dsk_dsk.h" |
| 11 | #include "formats/flopimg.h" |
| 12 | 12 | #include "devices/flopdrv.h" |
| 13 | 13 | |
| 14 | 14 | #define MV_CPC "MV - CPC" |
| r5801 | r5802 | |
| 76 | 76 | int i; |
| 77 | 77 | /* translate the sector to a raw sector */ |
| 78 | 78 | |
| 79 | | if (!sector_is_index) |
| 80 | | { |
| 81 | | sector -= 1; |
| 82 | | } |
| 83 | | |
| 84 | 79 | /* check to see if we are out of range */ |
| 85 | 80 | if ((head < 0) || (head >= get_tag(floppy)->heads) || (track < 0) || (track >= get_tag(floppy)->tracks) |
| 86 | 81 | || (sector < 0) ) |
| r5801 | r5802 | |
| 91 | 86 | floppy_image_read(floppy, track_info, track_offset, 0x100); |
| 92 | 87 | |
| 93 | 88 | sectors_per_track = track_info[0x015]; |
| 94 | | if (sector >= sectors_per_track) { |
| 95 | | return FLOPPY_ERROR_SEEKERROR; |
| 89 | if (!sector_is_index) { |
| 90 | if (sector >= sectors_per_track) { |
| 91 | return FLOPPY_ERROR_SEEKERROR; |
| 92 | } |
| 96 | 93 | } |
| 97 | 94 | |
| 98 | 95 | if (get_tag(floppy)->disk_image_type==0) { |
| r5801 | r5802 | |
| 181 | 178 | UINT8 sector_info[0x100]; |
| 182 | 179 | int pos; |
| 183 | 180 | |
| 184 | | retVal = get_offset(floppy, head, track, sector_index+1, FALSE, NULL); |
| 181 | retVal = get_offset(floppy, head, track, sector_index, FALSE, NULL); |
| 185 | 182 | offset = dsk_get_track_offset(floppy,head,track); |
| 186 | 183 | pos = 0x18 + (sector_index << 3); |
| 187 | 184 | floppy_image_read(floppy, sector_info, offset, 0x100); |
| r5801 | r5802 | |
| 209 | 206 | int i; |
| 210 | 207 | int skip,cnt; |
| 211 | 208 | |
| 209 | if(params) |
| 210 | { |
| 211 | // create |
| 212 | return FLOPPY_ERROR_UNSUPPORTED; |
| 213 | } |
| 214 | |
| 212 | 215 | floppy_image_read(floppy, header, 0, 0x100); |
| 213 | 216 | |
| 214 | 217 | tag = (struct dskdsk_tag *) floppy_create_tag(floppy, dskDSK_TAG, sizeof(struct dskdsk_tag)); |
| r5801 | r5802 | |
| 254 | 257 | callbacks->get_indexed_sector_info = dsk_get_indexed_sector_info; |
| 255 | 258 | return FLOPPY_ERROR_SUCCESS; |
| 256 | 259 | } |
| 257 | | /* ----------------------------------------------------------------------- */ |
| 258 | | |
| 259 | | FLOPPY_OPTIONS_START(dsk ) |
| 260 | | FLOPPY_OPTION( dsk, "dsk", "DSK floppy disk image", dsk_dsk_identify, dsk_dsk_construct, NULL) |
| 261 | | FLOPPY_OPTIONS_END |