summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/formats/pc_dsk.c
diff options
context:
space:
mode:
author Olivier Galibert <galibert@pobox.com>2012-01-07 21:03:04 +0000
committer Olivier Galibert <galibert@pobox.com>2012-01-07 21:03:04 +0000
commitf659a7f5ff3831730fa60c6d95e08a11a1f32814 (patch)
tree076827f20f5014283b4b20a9c21896c1f20bcd31 /src/lib/formats/pc_dsk.c
parent517ae1369fbb4071e77a6f9efbf480134bcbbc6c (diff)
mess sync (nw)
Diffstat (limited to 'src/lib/formats/pc_dsk.c')
-rw-r--r--src/lib/formats/pc_dsk.c139
1 files changed, 139 insertions, 0 deletions
diff --git a/src/lib/formats/pc_dsk.c b/src/lib/formats/pc_dsk.c
index 237a2138749..2cd5be8aff1 100644
--- a/src/lib/formats/pc_dsk.c
+++ b/src/lib/formats/pc_dsk.c
@@ -135,3 +135,142 @@ LEGACY_FLOPPY_OPTIONS_START( pc )
TRACKS(40/[80])
SECTORS(8/[9]/10/15/18/36))
LEGACY_FLOPPY_OPTIONS_END
+
+
+const floppy_image_format_t::desc_e pc_format::pc_desc[] = {
+ { MFM, 0x4e, 80 },
+ { MFM, 0x00, 12 },
+ { RAW, 0x5224, 3 },
+ { MFM, 0xfc, 1 },
+ { MFM, 0x4e, 50 },
+ { MFM, 0x00, 12 },
+ { SECTOR_LOOP_START, 0, 17 },
+ { CRC_CCITT_START, 1 },
+ { RAW, 0x4489, 3 },
+ { MFM, 0xfe, 1 },
+ { TRACK_ID },
+ { HEAD_ID },
+ { SECTOR_ID },
+ { SIZE_ID },
+ { CRC_END, 1 },
+ { CRC, 1 },
+ { MFM, 0x4e, 22 },
+ { MFM, 0x00, 12 },
+ { CRC_CCITT_START, 2 },
+ { RAW, 0x4489, 3 },
+ { MFM, 0xfb, 1 },
+ { SECTOR_DATA, -1 },
+ { CRC_END, 2 },
+ { CRC, 2 },
+ { MFM, 0x4e, 84 },
+ { MFM, 0x00, 12 },
+ { SECTOR_LOOP_END },
+ { MFM, 0x4e, 498 },
+ { END }
+};
+
+pc_format::pc_format()
+{
+}
+
+const char *pc_format::name() const
+{
+ return "pc";
+}
+
+const char *pc_format::description() const
+{
+ return "PC floppy disk image";
+}
+
+const char *pc_format::extensions() const
+{
+ return "dsk,ima,img,ufi,360";
+}
+
+bool pc_format::supports_save() const
+{
+ return true;
+}
+
+void pc_format::find_size(io_generic *io, UINT32 form_factor, int &track_count, int &head_count, int &sector_count)
+{
+ int size = io_generic_size(io);
+ if(size == 512*18*2*80) {
+ track_count = 80;
+ head_count = 2;
+ sector_count = 18;
+ } else
+ track_count = head_count = sector_count = 0;
+}
+
+int pc_format::identify(io_generic *io, UINT32 form_factor)
+{
+ int track_count, head_count, sector_count;
+ find_size(io, form_factor, track_count, head_count, sector_count);
+
+ if(track_count)
+ return 50;
+ return 0;
+}
+
+bool pc_format::load(io_generic *io, UINT32 form_factor, floppy_image *image)
+{
+ int track_count, head_count, sector_count;
+ find_size(io, form_factor, track_count, head_count, sector_count);
+
+ UINT8 sectdata[36*512];
+ desc_s sectors[36];
+ for(int i=0; i<sector_count; i++) {
+ sectors[i].data = sectdata + 512*i;
+ sectors[i].size = 512;
+ sectors[i].sector_id = i + 1;
+ }
+
+ int track_size = sector_count*512;
+ for(int track=0; track < track_count; track++) {
+ for(int head=0; head < head_count; head++) {
+ io_generic_read(io, sectdata, (track*head_count + head)*track_size, track_size);
+ generate_track(pc_desc,
+ track, head, sectors, sector_count, 200000, image);
+ }
+ }
+
+ image->set_variant(floppy_image::DSHD);
+
+ return true;
+}
+
+bool pc_format::save(io_generic *io, floppy_image *image)
+{
+ int track_count, head_count, sector_count;
+ get_geometry_mfm_pc(image, 1000, track_count, head_count, sector_count);
+
+ if(track_count < 80)
+ track_count = 80;
+ else if(track_count > 82)
+ track_count = 82;
+
+ // Happens for a fully unformatted floppy
+ if(!head_count)
+ head_count = 1;
+
+ if(sector_count > 36)
+ sector_count = 36;
+ else if(sector_count < 9)
+ sector_count = 9;
+
+ UINT8 sectdata[36*512];
+ int track_size = sector_count*512;
+
+ for(int track=0; track < track_count; track++) {
+ for(int head=0; head < head_count; head++) {
+ get_track_data_mfm_pc(track, head, image, 1000, 512, sector_count, sectdata);
+ io_generic_write(io, sectdata, (track*head_count + head)*track_size, track_size);
+ }
+ }
+
+ return true;
+}
+
+const floppy_format_type FLOPPY_PC_FORMAT = &floppy_image_format_creator<pc_format>;