ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/cwcbm/readcbm.c
(Generate patch)

Comparing cwcbm/readcbm.c (file contents):
Revision 1.1 by cebix, 2004-01-07T15:37:45Z vs.
Revision 1.2 by cebix, 2004-01-07T16:53:58Z

# Line 1 | Line 1
1   /*
2   *  readcbm.c - Read CBM disk to image file with the Catweasel controller
3   *
4 < *  Written in 2003 by Christian Bauer <Christian.Bauer@uni-mainz.de>
4 > *  Written in 2003-2004 by Christian Bauer <Christian.Bauer@uni-mainz.de>
5   */
6  
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <time.h>
11 #include <unistd.h>
12 #include <errno.h>
13 #include <sys/io.h>
14
7   #include "catweasel.h"
8   #include "common.h"
9  
# Line 263 | Line 255 | static int read_track(int drive, int tra
255   {
256          int i;
257  
258 <        // Set speed zone and tables
259 <        set_zone(track);
268 <
269 <        // Seek to track
270 <        catweasel_seek(c.drives + drive, (track - 1) * (double_step + 1));
271 <        msdelay(20);
258 >        // Seek to track, set speed zone
259 >        seek_to(drive, track);
260  
261          // Clear buffer
262          memset(track_buf, 0, num_sectors[track] * SECTOR_SIZE);
# Line 307 | Line 295 | static int read_track(int drive, int tra
295  
296   int main(int argc, char **argv)
297   {
298 <        int port, drive, track;
298 >        int track;
299          FILE *f;
300  
301          // Parse arguments
302 <        if (argc != 4) {
315 <                fprintf(stderr, "Usage: %s <port> <drive> <file>\n", argv[0]);
316 <                return 1;
317 <        }
318 <
319 <        port = strtol(argv[1], NULL, 16);
320 <        drive = atoi(argv[2]) & 1;
302 >        parse_args(argc, argv);
303  
304          // Open output file
305 <        f = fopen(argv[3], "wb");
305 >        f = fopen(file_name, "wb");
306          if (f == NULL) {
307 <                fprintf(stderr, "Can't open %s for writing: %s\n", argv[3], strerror(errno));
307 >                fprintf(stderr, "Can't open %s for writing: %s\n", file_name, strerror(errno));
308                  return 1;
309          }
310  
311          // Obtain access to I/O ports
312 <        if (ioperm(port, 8, 1) == -1) {
331 <                fprintf(stderr, "No access to I/O ports\n");
332 <                return 1;
333 <        }
334 <        setuid(getuid());
312 >        ioport_access();
313  
314          // Init Catweasel
337        memset(&c, 0, sizeof(c));
338        c.iobase = port;
339        c.msdelay = msdelay;
340        c.type = CATWEASEL_TYPE_MK1;
315          catweasel_init_controller(&c);
316  
317          // Start drive
318 <        catweasel_select(&c, drive == 0, drive == 1);
345 <        catweasel_set_motor(c.drives + drive, 1);
346 <        msdelay(500);
347 <        catweasel_seek(c.drives + drive, 0);
348 <        msdelay(20);
318 >        start_drive(drive_num);
319  
320          // Read all tracks
321          for (track = 1; track <= NUM_TRACKS; track++) {
322                  printf("Track %d...\n", track);
323 <                if (!read_track(drive, track))
323 >                if (!read_track(drive_num, track))
324                          break;
325                  fwrite(track_buf, 256, num_sectors[track], f);
326          }
327  
328          // Stop drive
329 <        catweasel_set_motor(c.drives + drive, 0);
330 <        catweasel_select(&c, 0, 0);
329 >        stop_drive(drive_num);
330 >
331 >        // Free Catweasel
332          catweasel_free_controller(&c);
333  
334          // Close output file

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines