···11+/*****************************************************************************
22+ * pce *
33+ *****************************************************************************/
44+55+/*****************************************************************************
66+ * File name: src/utils/pfdc/main.h *
77+ * Created: 2010-08-13 by Hampa Hug <hampa@hampa.ch> *
88+ * Copyright: (C) 2010 Hampa Hug <hampa@hampa.ch> *
99+ *****************************************************************************/
1010+1111+/*****************************************************************************
1212+ * This program is free software. You can redistribute it and / or modify it *
1313+ * under the terms of the GNU General Public License version 2 as published *
1414+ * by the Free Software Foundation. *
1515+ * *
1616+ * This program is distributed in the hope that it will be useful, but *
1717+ * WITHOUT ANY WARRANTY, without even the implied warranty of *
1818+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
1919+ * Public License for more details. *
2020+ *****************************************************************************/
2121+2222+2323+#ifndef PFDC_MAIN_H
2424+#define PFDC_MAIN_H 1
2525+2626+2727+#endif
+221
src/utils/pfdc/pfdc-img-io.c
···11+/*****************************************************************************
22+ * pce *
33+ *****************************************************************************/
44+55+/*****************************************************************************
66+ * File name: src/utils/pfdc/pfdc-img-io.c *
77+ * Created: 2010-08-21 by Hampa Hug <hampa@hampa.ch> *
88+ * Copyright: (C) 2010 Hampa Hug <hampa@hampa.ch> *
99+ *****************************************************************************/
1010+1111+/*****************************************************************************
1212+ * This program is free software. You can redistribute it and / or modify it *
1313+ * under the terms of the GNU General Public License version 2 as published *
1414+ * by the Free Software Foundation. *
1515+ * *
1616+ * This program is distributed in the hope that it will be useful, but *
1717+ * WITHOUT ANY WARRANTY, without even the implied warranty of *
1818+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
1919+ * Public License for more details. *
2020+ *****************************************************************************/
2121+2222+2323+#include <stdlib.h>
2424+#include <stdio.h>
2525+#include <string.h>
2626+2727+#include <devices/block/pfdc-img-ana.h>
2828+#include <devices/block/pfdc-img-imd.h>
2929+#include <devices/block/pfdc-img-pfdc.h>
3030+#include <devices/block/pfdc-img-raw.h>
3131+#include <devices/block/pfdc-img-td0.h>
3232+3333+#include "pfdc-img-io.h"
3434+3535+3636+static
3737+int pfdc_get_file_size (const char *fname, unsigned long *size)
3838+{
3939+ FILE *fp;
4040+4141+ fp = fopen (fname, "rb");
4242+4343+ if (fp == NULL) {
4444+ return (1);
4545+ }
4646+4747+ if (fseek (fp, 0, SEEK_END) != 0) {
4848+ fclose (fp);
4949+ return (1);
5050+ }
5151+5252+ *size = ftell (fp);
5353+5454+ fclose (fp);
5555+5656+ return (0);
5757+}
5858+5959+static
6060+int pfdc_is_raw (const char *fname)
6161+{
6262+ unsigned long size;
6363+ unsigned c, h, s;
6464+6565+ if (pfdc_get_file_size (fname, &size)) {
6666+ return (0);
6767+ }
6868+6969+ if (pfdc_get_geometry_from_size (size, &c, &h, &s)) {
7070+ return (0);
7171+ }
7272+7373+ return (1);
7474+}
7575+7676+static
7777+unsigned pfdc_get_type (unsigned type, const char *fname)
7878+{
7979+ unsigned i;
8080+ const char *ext;
8181+8282+ if (type != PFDC_FORMAT_NONE) {
8383+ return (type);
8484+ }
8585+8686+ ext = "";
8787+8888+ i = 0;
8989+ while (fname[i] != 0) {
9090+ if (fname[i] == '.') {
9191+ ext = fname + i;
9292+ }
9393+9494+ i += 1;
9595+ }
9696+9797+ if (strcasecmp (ext, ".ana") == 0) {
9898+ return (PFDC_FORMAT_ANA);
9999+ }
100100+ else if (strcasecmp (ext, ".ima") == 0) {
101101+ return (PFDC_FORMAT_RAW);
102102+ }
103103+ else if (strcasecmp (ext, ".imd") == 0) {
104104+ return (PFDC_FORMAT_IMD);
105105+ }
106106+ else if (strcasecmp (ext, ".raw") == 0) {
107107+ return (PFDC_FORMAT_RAW);
108108+ }
109109+ else if (strcasecmp (ext, ".td0") == 0) {
110110+ return (PFDC_FORMAT_TD0);
111111+ }
112112+113113+ if (strcasecmp (ext, ".img") == 0) {
114114+ if (pfdc_is_raw (fname)) {
115115+ return (PFDC_FORMAT_RAW);
116116+ }
117117+ }
118118+119119+ return (PFDC_FORMAT_PFDC);
120120+}
121121+122122+pfdc_img_t *pfdc_img_load_fp (FILE *fp, unsigned type)
123123+{
124124+ pfdc_img_t *img;
125125+126126+ img = NULL;
127127+128128+ switch (type) {
129129+ case PFDC_FORMAT_PFDC0:
130130+ case PFDC_FORMAT_PFDC1:
131131+ case PFDC_FORMAT_PFDC:
132132+ img = pfdc_load_pfdc (fp);
133133+ break;
134134+135135+ case PFDC_FORMAT_ANA:
136136+ img = pfdc_load_anadisk (fp);
137137+ break;
138138+139139+ case PFDC_FORMAT_IMD:
140140+ img = pfdc_load_imd (fp);
141141+ break;
142142+143143+ case PFDC_FORMAT_RAW:
144144+ img = pfdc_load_raw (fp);
145145+ break;
146146+147147+ case PFDC_FORMAT_TD0:
148148+ img = pfdc_load_td0 (fp);
149149+ break;
150150+ }
151151+152152+ return (img);
153153+}
154154+155155+pfdc_img_t *pfdc_img_load (const char *fname, unsigned type)
156156+{
157157+ FILE *fp;
158158+ pfdc_img_t *img;
159159+160160+ type = pfdc_get_type (type, fname);
161161+162162+ fp = fopen (fname, "rb");
163163+164164+ if (fp == NULL) {
165165+ return (NULL);
166166+ }
167167+168168+ img = pfdc_img_load_fp (fp, type);
169169+170170+ fclose (fp);
171171+172172+ return (img);
173173+}
174174+175175+int pfdc_img_save_fp (FILE *fp, const pfdc_img_t *img, unsigned type)
176176+{
177177+ switch (type) {
178178+ case PFDC_FORMAT_PFDC0:
179179+ return (pfdc_save_pfdc (fp, img, 0));
180180+181181+ case PFDC_FORMAT_PFDC1:
182182+ return (pfdc_save_pfdc (fp, img, 1));
183183+184184+ case PFDC_FORMAT_PFDC:
185185+ return (pfdc_save_pfdc (fp, img, 2));
186186+187187+ case PFDC_FORMAT_ANA:
188188+ return (pfdc_save_anadisk (fp, img));
189189+190190+ case PFDC_FORMAT_IMD:
191191+ return (pfdc_save_imd (fp, img));
192192+193193+ case PFDC_FORMAT_RAW:
194194+ return (pfdc_save_raw (fp, img));
195195+196196+ case PFDC_FORMAT_TD0:
197197+ return (pfdc_save_td0 (fp, img));
198198+ }
199199+200200+ return (1);
201201+}
202202+203203+int pfdc_img_save (const char *fname, const pfdc_img_t *img, unsigned type)
204204+{
205205+ int r;
206206+ FILE *fp;
207207+208208+ type = pfdc_get_type (type, fname);
209209+210210+ fp = fopen (fname, "wb");
211211+212212+ if (fp == NULL) {
213213+ return (1);
214214+ }
215215+216216+ r = pfdc_img_save_fp (fp, img, type);
217217+218218+ fclose (fp);
219219+220220+ return (r);
221221+}
+49
src/utils/pfdc/pfdc-img-io.h
···11+/*****************************************************************************
22+ * pce *
33+ *****************************************************************************/
44+55+/*****************************************************************************
66+ * File name: src/utils/pfdc/pfdc-img-io.h *
77+ * Created: 2010-08-21 by Hampa Hug <hampa@hampa.ch> *
88+ * Copyright: (C) 2010 Hampa Hug <hampa@hampa.ch> *
99+ *****************************************************************************/
1010+1111+/*****************************************************************************
1212+ * This program is free software. You can redistribute it and / or modify it *
1313+ * under the terms of the GNU General Public License version 2 as published *
1414+ * by the Free Software Foundation. *
1515+ * *
1616+ * This program is distributed in the hope that it will be useful, but *
1717+ * WITHOUT ANY WARRANTY, without even the implied warranty of *
1818+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
1919+ * Public License for more details. *
2020+ *****************************************************************************/
2121+2222+2323+#ifndef PFDC_IMG_IO_H
2424+#define PFDC_IMG_IO_H 1
2525+2626+2727+#include <devices/block/pfdc.h>
2828+2929+3030+#define PFDC_FORMAT_NONE 0
3131+#define PFDC_FORMAT_PFDC 1
3232+#define PFDC_FORMAT_PFDC0 2
3333+#define PFDC_FORMAT_PFDC1 3
3434+#define PFDC_FORMAT_ANA 4
3535+#define PFDC_FORMAT_IMD 5
3636+#define PFDC_FORMAT_RAW 6
3737+#define PFDC_FORMAT_TD0 7
3838+3939+4040+pfdc_img_t *pfdc_img_load_fp (FILE *fp, unsigned type);
4141+4242+pfdc_img_t *pfdc_img_load (const char *fname, unsigned type);
4343+4444+int pfdc_img_save_fp (FILE *fp, const pfdc_img_t *img, unsigned type);
4545+4646+int pfdc_img_save (const char *fname, const pfdc_img_t *img, unsigned type);
4747+4848+4949+#endif
+230
src/utils/pfdc/pfdc.1
···11+.TH PFDC 1 "2010-08-22" "HH" "pce"
22+\
33+.SH NAME
44+pfdc \- convert and modify PFDC floppy disk image files
55+66+.SH SYNOPSIS
77+.BI pfdc " [options] [input-file] [options] [output-file]"
88+99+.SH DESCRIPTION
1010+\fBpfdc\fR(1) is used to modify and convert PFDC floppy disk images
1111+files.
1212+1313+.SH OPTIONS
1414+.TP
1515+.BI "-a, --alternate " "alt1[-alt2]"
1616+Select a range of alternate sectors.
1717+\
1818+.TP
1919+.BI "-c, --cylinder " "cyl1[-cyl2]"
2020+Select a range of cylinders.
2121+\
2222+.TP
2323+.BI "-e, --edit " "what val"
2424+For all selected sectors, set sector attribute \fIwhat\fR to \fIval\fR.
2525+For boolean attributes, a value of 0 disables the attribute and any other
2626+value enables it.
2727+Recognized attributes are:
2828+.RS
2929+.TP
3030+.B crc-id
3131+The ID field contains a CRC error.
3232+.TP
3333+.B crc-data
3434+The data field contains a CRC error.
3535+.TP
3636+.B del-dam
3737+The sector has a deleted data address mark.
3838+.TP
3939+.B data-rate
4040+The data rate in bits per second.
4141+.TP
4242+.B fm
4343+The sector uses FM encoding.
4444+.TP
4545+.B mfm
4646+The sector uses MFM encoding.
4747+.TP
4848+.B size
4949+The sector size in bytes.
5050+.TP
5151+.B c
5252+The cylinder number in the sector ID.
5353+.TP
5454+.B h
5555+The head number in the sector ID.
5656+.TP
5757+.B s
5858+The sector number in the sector ID.
5959+.RE
6060+\
6161+.TP
6262+.B "-f, --info"
6363+Print information about the current image or the next image loaded.
6464+\
6565+.TP
6666+.BI "-F, --filler " val
6767+Set the fill byte to \fIval\fR. The fill byte is used when sectors
6868+are created or enlarged.
6969+\
7070+.TP
7171+.BI "-h, --head " "head1[-head2]"
7272+Select a range of heads.
7373+\
7474+.TP
7575+.BI "-i, --input " filename
7676+Load an image from \fIfilename\fR.
7777+\
7878+.TP
7979+.BI "-I, --input-format " format
8080+Set the input file format to \fIformat\fR.
8181+Valid formats are:
8282+.RS
8383+.TP
8484+.B pfdc
8585+The native PFDC file format.
8686+.TP
8787+.B ana
8888+The anadisk dump format.
8989+.TP
9090+.B imd
9191+The ImageDisk file format.
9292+.TP
9393+.B raw
9494+A raw sector dump.
9595+.TP
9696+.B td0
9797+The teledisk file format. Only files that don't use advanced compression
9898+are supported.
9999+.RE
100100+\
101101+.TP
102102+.B "-l, --list-tracks"
103103+List all tracks in the current image or in the next image loaded.
104104+\
105105+.TP
106106+.B "-L, --list-sectors"
107107+List all sectors in the current image or in the next image loaded.
108108+\
109109+.TP
110110+.BI "-m, --merge " filename
111111+Load an image from \fIfilename\fR and merge it with the current
112112+image. Sectors that are identical are discarded. Sectors that
113113+exist in only one image are retained. Sectors that exist in both
114114+images, but differ, are added as alternate sectors.
115115+\
116116+.TP
117117+.BI "-n, --new " size
118118+Create a new image of size \fIsize\fR KiB.
119119+\
120120+.TP
121121+.BI "-o, --output " filename
122122+Set the output file name. Before exiting, the current image will
123123+be written to this file.
124124+\
125125+.TP
126126+.BI "-O, --output-format " format
127127+Set the output file format to \fIformat\fR. See the \fI-I\fR option
128128+for a list of valid formats.
129129+\
130130+.TP
131131+.BI "-p, --operation " "name [arg...]"
132132+Perform an operation on the current image. Valid operations are:
133133+.RS
134134+.TP
135135+.BI "comment-add " text
136136+Add \fItext\fR to the image comment.
137137+.TP
138138+.BI "comment-load " filename
139139+Load the image comment from file \fIfilename\fR.
140140+.TP
141141+.B comment-print
142142+Print the current image comment.
143143+.TP
144144+.BI "comment-save " filename
145145+Save the current image comment to \fIfilename\fR.
146146+.TP
147147+.BI "comment-set " text
148148+Set the image comment to \fItext\fR.
149149+.TP
150150+.B delete
151151+Delete all selected sectors.
152152+.TP
153153+.B info
154154+Print information about the current image (same as \fB-f\fR).
155155+.TP
156156+.BI "load "filename"
157157+Load the contents of all selected sectors from \fIfilename\fR. The
158158+contents of the sectors are read sequentially from the file.
159159+.TP
160160+.B new
161161+Create all selected sectors, if they do not already exist.
162162+.TP
163163+.BI "reorder " "s1,s2,s3,..."
164164+Reorder the sectors on all selected tracks. Sectors that are not
165165+mentioned in the parameter are moved to the end of the track.
166166+.TP
167167+.BI "rotate " first
168168+Rotate the sectors on all selected tracks such that \fIfirst\fR is
169169+the first sector on the track. If \fIfirst\fR does not exist on
170170+a track, the next higher sector will be rotated to the start of
171171+the track.
172172+.TP
173173+.BI "save " filename
174174+Save all selected sectors to \fIfilename\fR. The contents of the
175175+sectors are written sequentially to the file.
176176+.RE
177177+\
178178+.TP
179179+.BI "-r, --record " "cyl1[-cyl2] head1[-head2] sect1[-sect2]"
180180+Select sectors. This is the same as using the \fB-c\fR, \fB-h\fR
181181+and \fB-s\fR options seperately.
182182+\
183183+.TP
184184+.BI "-s, --sector " "sect1[-sect2]"
185185+Select a range of logical sectors.
186186+\
187187+.TP
188188+.BI "-S, --real-sectors " "sect1[-sect2]"
189189+Select a range of physical sectors.
190190+\
191191+.TP
192192+.B "-v, --verbose"
193193+Enable verbose operation.
194194+\
195195+.TP
196196+.B --help
197197+Print usage information.
198198+\
199199+.TP
200200+.B --version
201201+Print version information.
202202+203203+.SH EXAMPLES
204204+Convert an ImageDisk file to a PFDC file:
205205+.IP ""
206206+$ pfdc source.imd dest.pfdc
207207+.PP
208208+Get image information:
209209+.IP
210210+$ pfdc -f image.pfdc
211211+.PP
212212+Add sectors 10 and 11 to all tracks on side 0:
213213+.IP
214214+$ pfdc -i source.pfdc -r all 0 10-11 -p new -o dest.pfdc
215215+.PP
216216+Mark the first sector in the image as having a bad data CRC:
217217+.IP
218218+$ pfdc -i source.pfdc -r 0 0 1 -e crc-data 1 -o dest.pfdc
219219+.PP
220220+Set the image comment:
221221+.IP
222222+$ pfdc -i source.pfdc -p comment-set "Test image" -o dest.pfdc
223223+224224+.SH SEE ALSO
225225+.BR pce-ibmpc "(1),"
226226+.BR pce-macplus "(1),"
227227+.BR pce-img "(1)"
228228+229229+.SH AUTHOR
230230+Hampa Hug <hampa@hampa.ch>