--- cwcbm/readcbm.c 2004/01/07 15:37:45 1.1 +++ cwcbm/readcbm.c 2004/01/07 16:53:58 1.2 @@ -1,17 +1,9 @@ /* * readcbm.c - Read CBM disk to 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" @@ -263,12 +255,8 @@ static int read_track(int drive, int tra { 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); // Clear buffer memset(track_buf, 0, num_sectors[track] * SECTOR_SIZE); @@ -307,57 +295,40 @@ static int read_track(int drive, int tra int main(int argc, char **argv) { - int port, drive, track; + int track; 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 output file - f = fopen(argv[3], "wb"); + f = fopen(file_name, "wb"); if (f == NULL) { - fprintf(stderr, "Can't open %s for writing: %s\n", argv[3], strerror(errno)); + fprintf(stderr, "Can't open %s for writing: %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); // Read all tracks for (track = 1; track <= NUM_TRACKS; track++) { printf("Track %d...\n", track); - if (!read_track(drive, track)) + if (!read_track(drive_num, track)) break; fwrite(track_buf, 256, num_sectors[track], f); } // 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 output file