src/mess/formats/exidydsk.c
| r0 | r5954 | |
| 1 | /*********************************************************************
|
| 2 | |
| 3 | formats/exi_dsk.c
|
| 4 | |
| 5 | Exidy Sorcerer floppy-disk images
|
| 6 | |
| 7 | *********************************************************************/
|
| 8 | |
| 9 | #include <string.h>
|
| 10 | |
| 11 | #include "formats/exidydsk.h"
|
| 12 | #include "formats/basicdsk.h"
|
| 13 | #include "driver.h"
|
| 14 | |
| 15 | static FLOPPY_IDENTIFY(exi_dsk_identify)
|
| 16 | {
|
| 17 | *vote = (floppy_image_size(floppy) == 332640) ? 100 : 0;
|
| 18 | return FLOPPY_ERROR_SUCCESS;
|
| 19 | }
|
| 20 | |
| 21 | static int exi_get_heads_per_disk(floppy_image *floppy)
|
| 22 | {
|
| 23 | return 1;
|
| 24 | }
|
| 25 | |
| 26 | static int exi_get_tracks_per_disk(floppy_image *floppy)
|
| 27 | {
|
| 28 | return 77;
|
| 29 | }
|
| 30 | |
| 31 | static UINT64 exi_translate_offset(floppy_image *floppy, int track, int head, int sector)
|
| 32 | {
|
| 33 | return 13+270*(16*track+sector);
|
| 34 | }
|
| 35 | |
| 36 | static floperr_t get_offset(floppy_image *floppy, int head, int track, int sector, int sector_is_index, UINT64 *offset)
|
| 37 | {
|
| 38 | UINT64 offs;
|
| 39 | /* translate the sector to a raw sector */
|
| 40 | if (!sector_is_index)
|
| 41 | {
|
| 42 | sector -= 1;
|
| 43 | }
|
| 44 | /* check to see if we are out of range */
|
| 45 | if ((head != 0) || (track < 0) || (track >= 77) || (sector < 0) || (sector >= 16))
|
| 46 | return FLOPPY_ERROR_SEEKERROR;
|
| 47 | |
| 48 | offs = exi_translate_offset(floppy, track, head, sector);
|
| 49 | if (offset)
|
| 50 | *offset = offs;
|
| 51 | return FLOPPY_ERROR_SUCCESS;
|
| 52 | }
|
| 53 | |
| 54 | |
| 55 | |
| 56 | static floperr_t internal_exi_read_sector(floppy_image *floppy, int head, int track, int sector, int sector_is_index, void *buffer, size_t buflen)
|
| 57 | {
|
| 58 | UINT64 offset;
|
| 59 | floperr_t err;
|
| 60 | err = get_offset(floppy, head, track, sector, sector_is_index, &offset);
|
| 61 | if (err)
|
| 62 | return err;
|
| 63 | |
| 64 | floppy_image_read(floppy, buffer, offset, buflen);
|
| 65 | return FLOPPY_ERROR_SUCCESS;
|
| 66 | }
|
| 67 | |
| 68 | |
| 69 | |
| 70 | static floperr_t internal_exi_write_sector(floppy_image *floppy, int head, int track, int sector, int sector_is_index, const void *buffer, size_t buflen, int ddam)
|
| 71 | {
|
| 72 | UINT64 offset;
|
| 73 | floperr_t err;
|
| 74 | |
| 75 | err = get_offset(floppy, head, track, sector, sector_is_index, &offset);
|
| 76 | if (err)
|
| 77 | return err;
|
| 78 | |
| 79 | floppy_image_write(floppy, buffer, offset, buflen);
|
| 80 | return FLOPPY_ERROR_SUCCESS;
|
| 81 | }
|
| 82 | |
| 83 | |
| 84 | |
| 85 | static floperr_t exi_read_sector(floppy_image *floppy, int head, int track, int sector, void *buffer, size_t buflen)
|
| 86 | {
|
| 87 | return internal_exi_read_sector(floppy, head, track, sector, FALSE, buffer, buflen);
|
| 88 | }
|
| 89 | |
| 90 | static floperr_t exi_write_sector(floppy_image *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam)
|
| 91 | {
|
| 92 | return internal_exi_write_sector(floppy, head, track, sector, FALSE, buffer, buflen, ddam);
|
| 93 | }
|
| 94 | |
| 95 | static floperr_t exi_read_indexed_sector(floppy_image *floppy, int head, int track, int sector, void *buffer, size_t buflen)
|
| 96 | {
|
| 97 | return internal_exi_read_sector(floppy, head, track, sector, TRUE, buffer, buflen);
|
| 98 | }
|
| 99 | |
| 100 | static floperr_t exi_write_indexed_sector(floppy_image *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam)
|
| 101 | {
|
| 102 | return internal_exi_write_sector(floppy, head, track, sector, TRUE, buffer, buflen, ddam);
|
| 103 | }
|
| 104 | |
| 105 | static floperr_t exi_get_sector_length(floppy_image *floppy, int head, int track, int sector, UINT32 *sector_length)
|
| 106 | {
|
| 107 | floperr_t err;
|
| 108 | err = get_offset(floppy, head, track, sector, FALSE, NULL);
|
| 109 | if (err)
|
| 110 | return err;
|
| 111 | |
| 112 | if (sector_length) {
|
| 113 | *sector_length = 256;
|
| 114 | }
|
| 115 | return FLOPPY_ERROR_SUCCESS;
|
| 116 | }
|
| 117 | |
| 118 | |
| 119 | |
| 120 | static floperr_t exi_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)
|
| 121 | {
|
| 122 | sector_index += 1;
|
| 123 | if (cylinder)
|
| 124 | *cylinder = track;
|
| 125 | if (side)
|
| 126 | *side = head;
|
| 127 | if (sector)
|
| 128 | *sector = sector_index;
|
| 129 | if (flags)
|
| 130 | /* TODO: read DAM or DDAM and determine flags */
|
| 131 | *flags = 0;
|
| 132 | return exi_get_sector_length(floppy, head, track, sector_index, sector_length);
|
| 133 | }
|
| 134 | |
| 135 | |
| 136 | static FLOPPY_CONSTRUCT(exi_dsk_construct)
|
| 137 | {
|
| 138 | struct FloppyCallbacks *callbacks;
|
| 139 | callbacks = floppy_callbacks(floppy);
|
| 140 | callbacks->read_sector = exi_read_sector;
|
| 141 | callbacks->write_sector = exi_write_sector;
|
| 142 | callbacks->read_indexed_sector = exi_read_indexed_sector;
|
| 143 | callbacks->write_indexed_sector = exi_write_indexed_sector;
|
| 144 | callbacks->get_sector_length = exi_get_sector_length;
|
| 145 | callbacks->get_heads_per_disk = exi_get_heads_per_disk;
|
| 146 | callbacks->get_tracks_per_disk = exi_get_tracks_per_disk;
|
| 147 | callbacks->get_indexed_sector_info = exi_get_indexed_sector_info;
|
| 148 |
|
| 149 | return FLOPPY_ERROR_SUCCESS;
|
| 150 | }
|
| 151 | |
| 152 | |
| 153 | |
| 154 | /* ----------------------------------------------------------------------- */
|
| 155 | |
| 156 | FLOPPY_OPTIONS_START( exidy )
|
| 157 | FLOPPY_OPTION( exi_dsk, "dsk", "Exidy Sorcerer floppy disk image", exi_dsk_identify, exi_dsk_construct, NULL)
|
| 158 | FLOPPY_OPTIONS_END
|