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