trunk/src/lib/formats/smx_dsk.c
| r19519 | r19520 | |
| 1 | | /********************************************************************* |
| 1 | /*************************************************************************** |
| 2 | 2 | |
| 3 | | formats/smx_dsk.c |
| 3 | Copyright Olivier Galibert |
| 4 | All rights reserved. |
| 4 | 5 | |
| 5 | | Specialist MX disk images |
| 6 | Redistribution and use in source and binary forms, with or without |
| 7 | modification, are permitted provided that the following conditions are |
| 8 | met: |
| 6 | 9 | |
| 7 | | *********************************************************************/ |
| 10 | * Redistributions of source code must retain the above copyright |
| 11 | notice, this list of conditions and the following disclaimer. |
| 12 | * Redistributions in binary form must reproduce the above copyright |
| 13 | notice, this list of conditions and the following disclaimer in |
| 14 | the documentation and/or other materials provided with the |
| 15 | distribution. |
| 16 | * Neither the name 'MAME' nor the names of its contributors may be |
| 17 | used to endorse or promote products derived from this software |
| 18 | without specific prior written permission. |
| 8 | 19 | |
| 9 | | #include <string.h> |
| 20 | THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR |
| 21 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 23 | DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, |
| 24 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 29 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 30 | POSSIBILITY OF SUCH DAMAGE. |
| 10 | 31 | |
| 11 | | #include "smx_dsk.h" |
| 12 | | #include "basicdsk.h" |
| 32 | ****************************************************************************/ |
| 13 | 33 | |
| 14 | | static FLOPPY_IDENTIFY(smx_dsk_identify) |
| 15 | | { |
| 16 | | *vote = (floppy_image_size(floppy) == 819200) ? 100 : 0; |
| 17 | | return FLOPPY_ERROR_SUCCESS; |
| 18 | | } |
| 34 | /********************************************************************* |
| 19 | 35 | |
| 20 | | static int smx_get_heads_per_disk(floppy_image_legacy *floppy) |
| 21 | | { |
| 22 | | return 2; |
| 23 | | } |
| 36 | formats/smx_dsk.c |
| 24 | 37 | |
| 25 | | static int smx_get_tracks_per_disk(floppy_image_legacy *floppy) |
| 26 | | { |
| 27 | | return 80; |
| 28 | | } |
| 38 | Specialist MX format |
| 29 | 39 | |
| 30 | | static UINT64 smx_translate_offset(floppy_image_legacy *floppy, |
| 31 | | int track, int head, int sector) |
| 32 | | { |
| 33 | | return (track * 1024 * 5 * 2) + (head * 1024 * 5) + 1024 * sector; |
| 34 | | } |
| 40 | *********************************************************************/ |
| 35 | 41 | |
| 36 | | static floperr_t get_offset(floppy_image_legacy *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) || (head >= 2) || (track < 0) || (track >= 80) |
| 46 | | || (sector < 0) || (sector >= 6)) |
| 47 | | return FLOPPY_ERROR_SEEKERROR; |
| 42 | #include "emu.h" |
| 43 | #include "formats/smx_dsk.h" |
| 48 | 44 | |
| 49 | | offs = smx_translate_offset(floppy, track, head, sector); |
| 50 | | if (offset) |
| 51 | | *offset = offs; |
| 52 | | return FLOPPY_ERROR_SUCCESS; |
| 53 | | } |
| 54 | | |
| 55 | | |
| 56 | | |
| 57 | | static floperr_t internal_smx_read_sector(floppy_image_legacy *floppy, int head, int track, int sector, int sector_is_index, void *buffer, size_t buflen) |
| 45 | smx_format::smx_format() : wd177x_format(formats) |
| 58 | 46 | { |
| 59 | | UINT64 offset; |
| 60 | | floperr_t err; |
| 61 | | err = get_offset(floppy, head, track, sector, sector_is_index, &offset); |
| 62 | | if (err) |
| 63 | | return err; |
| 64 | | |
| 65 | | floppy_image_read(floppy, buffer, offset, buflen); |
| 66 | | return FLOPPY_ERROR_SUCCESS; |
| 67 | 47 | } |
| 68 | 48 | |
| 69 | | |
| 70 | | |
| 71 | | static floperr_t internal_smx_write_sector(floppy_image_legacy *floppy, int head, int track, int sector, int sector_is_index, const void *buffer, size_t buflen, int ddam) |
| 49 | const char *smx_format::name() const |
| 72 | 50 | { |
| 73 | | UINT64 offset; |
| 74 | | floperr_t err; |
| 75 | | |
| 76 | | err = get_offset(floppy, head, track, sector, sector_is_index, &offset); |
| 77 | | if (err) |
| 78 | | return err; |
| 79 | | |
| 80 | | floppy_image_write(floppy, buffer, offset, buflen); |
| 81 | | return FLOPPY_ERROR_SUCCESS; |
| 51 | return "smx"; |
| 82 | 52 | } |
| 83 | 53 | |
| 84 | | |
| 85 | | |
| 86 | | static floperr_t smx_read_sector(floppy_image_legacy *floppy, int head, int track, int sector, void *buffer, size_t buflen) |
| 54 | const char *smx_format::description() const |
| 87 | 55 | { |
| 88 | | return internal_smx_read_sector(floppy, head, track, sector, FALSE, buffer, buflen); |
| 56 | return "Specialist MX disk image"; |
| 89 | 57 | } |
| 90 | 58 | |
| 91 | | static floperr_t smx_write_sector(floppy_image_legacy *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam) |
| 59 | const char *smx_format::extensions() const |
| 92 | 60 | { |
| 93 | | return internal_smx_write_sector(floppy, head, track, sector, FALSE, buffer, buflen, ddam); |
| 61 | return "odi"; |
| 94 | 62 | } |
| 95 | 63 | |
| 96 | | static floperr_t smx_read_indexed_sector(floppy_image_legacy *floppy, int head, int track, int sector, void *buffer, size_t buflen) |
| 64 | // Unverified gap sizes |
| 65 | const smx_format::format smx_format::formats[] = |
| 97 | 66 | { |
| 98 | | return internal_smx_read_sector(floppy, head, track, sector, TRUE, buffer, buflen); |
| 99 | | } |
| 67 | { // 720K 5.25 inch |
| 68 | floppy_image::FF_525, floppy_image::DSQD, |
| 69 | 2000, 5, 80, 2, 1024, {}, 1, {}, 100, 22, 20 |
| 70 | }, |
| 71 | {} |
| 72 | }; |
| 100 | 73 | |
| 101 | | static floperr_t smx_write_indexed_sector(floppy_image_legacy *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam) |
| 102 | | { |
| 103 | | return internal_smx_write_sector(floppy, head, track, sector, TRUE, buffer, buflen, ddam); |
| 104 | | } |
| 105 | | |
| 106 | | static floperr_t smx_get_sector_length(floppy_image_legacy *floppy, int head, int track, int sector, UINT32 *sector_length) |
| 107 | | { |
| 108 | | floperr_t err; |
| 109 | | err = get_offset(floppy, head, track, sector, FALSE, NULL); |
| 110 | | if (err) |
| 111 | | return err; |
| 112 | | |
| 113 | | if (sector_length) { |
| 114 | | *sector_length = 1024; |
| 115 | | } |
| 116 | | return FLOPPY_ERROR_SUCCESS; |
| 117 | | } |
| 118 | | |
| 119 | | |
| 120 | | |
| 121 | | static floperr_t smx_get_indexed_sector_info(floppy_image_legacy *floppy, int head, int track, int sector_index, int *cylinder, int *side, int *sector, UINT32 *sector_length, unsigned long *flags) |
| 122 | | { |
| 123 | | sector_index += 1; |
| 124 | | if (cylinder) |
| 125 | | *cylinder = track; |
| 126 | | if (side) |
| 127 | | *side = head; |
| 128 | | if (sector) |
| 129 | | *sector = sector_index; |
| 130 | | if (flags) |
| 131 | | /* TODO: read DAM or DDAM and determine flags */ |
| 132 | | *flags = 0; |
| 133 | | return smx_get_sector_length(floppy, head, track, sector_index, sector_length); |
| 134 | | } |
| 135 | | |
| 136 | | |
| 137 | | static FLOPPY_CONSTRUCT(smx_dsk_construct) |
| 138 | | { |
| 139 | | struct FloppyCallbacks *callbacks; |
| 140 | | callbacks = floppy_callbacks(floppy); |
| 141 | | callbacks->read_sector = smx_read_sector; |
| 142 | | callbacks->write_sector = smx_write_sector; |
| 143 | | callbacks->read_indexed_sector = smx_read_indexed_sector; |
| 144 | | callbacks->write_indexed_sector = smx_write_indexed_sector; |
| 145 | | callbacks->get_sector_length = smx_get_sector_length; |
| 146 | | callbacks->get_heads_per_disk = smx_get_heads_per_disk; |
| 147 | | callbacks->get_tracks_per_disk = smx_get_tracks_per_disk; |
| 148 | | callbacks->get_indexed_sector_info = smx_get_indexed_sector_info; |
| 149 | | |
| 150 | | return FLOPPY_ERROR_SUCCESS; |
| 151 | | } |
| 152 | | |
| 153 | | |
| 154 | | |
| 155 | | /* ----------------------------------------------------------------------- */ |
| 156 | | |
| 157 | | LEGACY_FLOPPY_OPTIONS_START( specimx ) |
| 158 | | LEGACY_FLOPPY_OPTION( smx_dsk, "odi", "Specialist MX floppy disk image", smx_dsk_identify, smx_dsk_construct, NULL, NULL) |
| 159 | | LEGACY_FLOPPY_OPTIONS_END |
| 74 | const floppy_format_type FLOPPY_SMX_FORMAT = &floppy_image_format_creator<smx_format>; |