[Coco] creatdsk.c source

Bob Devries bdevries at gil.com.au
Sat Dec 24 03:45:02 EST 2005


Here's a QAD C code file I just threw together to make a dsk file from a 
floppy. Hehe, this works on the MESS emulator.... making a .dsk file from a 
.dsk file for the emu, in the emu.

/* Creatdsk.c - A util to create a .dsk file to be used by */
/* the JV or MESS emulators under OS9                      */
/*                                                         */
/* Syntax:                                                 */
/*          creatdsk /dx [filename]                        */
/*                                                         */
/* the drivespec '/dx (/d0, /d1...) must be an RBF disk    */
/* filename is optional, and if not used, data is written  */
/* to stdout                                               */
/*                                                         */
/* Copyright (c) 2005 by Bob Devries                       */

#include <stdio.h>
#include <errno.h>

int main(argc, argv)
int argc;
char *argv[];
{
        FILE *fopen(), *infile, *outfile;
        char sector[256];
        char diskname[32];
        int bytesread;

        if (argc < 2 || argc > 3) {
                usage(argv[0]);
                exit(0);
        }

        strcpy (diskname, argv[1]);
        if (index(diskname,'@') == NULL) {
                strcat(diskname, "@");
        }

        if (argc == 3) {
                if (access(argv[2],0) == 0) {
                        exit(E_CEF);
                } else {
                        if ((outfile = fopen(argv[2],"w")) == NULL) {
                                exit(errno);
                        }
                }
        }

        if (argc == 2) {
                outfile = stdout;
        }

        if ((infile = fopen(diskname,"r")) == NULL) {
                exit(errno);
        }

        while (bytesread = fread (sector, sizeof(sector), 1, infile) == 1) {
                if (bytesread = fwrite (sector, sizeof(sector), 1, outfile) 
!= 1) {
                        exit (errno);
                }
        }

        if (argc > 2) {
                fclose(outfile);
        }
        fclose(infile);
}

usage(progname)
char *progname;
{
        fprintf(stderr,"Usage: %s /dx [filename]\n", progname);
        fprintf(stderr,"/dx must be a valid RBF device.\n");
        fprintf(stderr,"filename is optional; if not given, stdout is 
used\n");
}

/* EOF creatdsk.c */

--
Regards, Bob Devries, Dalby, Queensland, Australia

Isaiah 50:4 The sovereign Lord has given me
the capacity to be his spokesman,
so that I know how to help the weary.

website: http://www.home.gil.com.au/~bdevasl
my blog: http://bdevries.invigorated.org/




More information about the Coco mailing list