--- cwcbm/writecbm.c 2004/01/07 15:37:45 1.1 +++ cwcbm/writecbm.c 2004/01/07 16:53:58 1.2 @@ -1,17 +1,9 @@ /* * writecbm.c - Write CBM disk from image file with the Catweasel controller * - * Written in 2003 by Christian Bauer + * Written in 2003-2004 by Christian Bauer */ -#include -#include -#include -#include -#include -#include -#include - #include "catweasel.h" #include "common.h" @@ -175,12 +167,8 @@ static int write_track(int drive, int tr { int i; - // Set speed zone and tables - set_zone(track); - - // Seek to track - catweasel_seek(c.drives + drive, (track - 1) * (double_step + 1)); - msdelay(20); + // Seek to track, set speed zone + seek_to(drive, track); // Write empty track inb(c.iobase + 1); @@ -211,48 +199,30 @@ static int write_track(int drive, int tr int main(int argc, char **argv) { - int port, drive, track, ret = 0; + int track, ret = 0; FILE *f; // Parse arguments - if (argc != 4) { - fprintf(stderr, "Usage: %s \n", argv[0]); - return 1; - } - - port = strtol(argv[1], NULL, 16); - drive = atoi(argv[2]) & 1; + parse_args(argc, argv); // Open input file - f = fopen(argv[3], "rb"); + f = fopen(file_name, "rb"); if (f == NULL) { - fprintf(stderr, "Can't open %s for reading: %s\n", argv[3], strerror(errno)); + fprintf(stderr, "Can't open %s for reading: %s\n", file_name, strerror(errno)); return 1; } // Obtain access to I/O ports - if (ioperm(port, 8, 1) == -1) { - fprintf(stderr, "No access to I/O ports\n"); - return 1; - } - setuid(getuid()); + ioport_access(); // Init Catweasel - memset(&c, 0, sizeof(c)); - c.iobase = port; - c.msdelay = msdelay; - c.type = CATWEASEL_TYPE_MK1; catweasel_init_controller(&c); // Start drive - catweasel_select(&c, drive == 0, drive == 1); - catweasel_set_motor(c.drives + drive, 1); - msdelay(500); - catweasel_seek(c.drives + drive, 0); - msdelay(20); + start_drive(drive_num); // Disk write protected? - if (!catweasel_write_protected(c.drives + drive)) { + if (!catweasel_write_protected(c.drives + drive_num)) { // No, write all tracks for (track = 1; track <= NUM_TRACKS; track++) { @@ -261,7 +231,7 @@ int main(int argc, char **argv) fprintf(stderr, "Error reading input file\n"); break; } - if (!write_track(drive, track)) + if (!write_track(drive_num, track)) break; } @@ -272,8 +242,9 @@ int main(int argc, char **argv) } // Stop drive - catweasel_set_motor(c.drives + drive, 0); - catweasel_select(&c, 0, 0); + stop_drive(drive_num); + + // Free Catweasel catweasel_free_controller(&c); // Close input file