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

Comparing cwcbm/writecbm.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   *  writecbm.c - Write CBM disk from 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 175 | Line 167 | static int write_track(int drive, int tr
167   {
168          int i;
169  
170 <        // Set speed zone and tables
171 <        set_zone(track);
180 <
181 <        // Seek to track
182 <        catweasel_seek(c.drives + drive, (track - 1) * (double_step + 1));
183 <        msdelay(20);
170 >        // Seek to track, set speed zone
171 >        seek_to(drive, track);
172  
173          // Write empty track
174          inb(c.iobase + 1);
# Line 211 | Line 199 | static int write_track(int drive, int tr
199  
200   int main(int argc, char **argv)
201   {
202 <        int port, drive, track, ret = 0;
202 >        int track, ret = 0;
203          FILE *f;
204  
205          // Parse arguments
206 <        if (argc != 4) {
219 <                fprintf(stderr, "Usage: %s <port> <drive> <file>\n", argv[0]);
220 <                return 1;
221 <        }
222 <
223 <        port = strtol(argv[1], NULL, 16);
224 <        drive = atoi(argv[2]) & 1;
206 >        parse_args(argc, argv);
207  
208          // Open input file
209 <        f = fopen(argv[3], "rb");
209 >        f = fopen(file_name, "rb");
210          if (f == NULL) {
211 <                fprintf(stderr, "Can't open %s for reading: %s\n", argv[3], strerror(errno));
211 >                fprintf(stderr, "Can't open %s for reading: %s\n", file_name, strerror(errno));
212                  return 1;
213          }
214  
215          // Obtain access to I/O ports
216 <        if (ioperm(port, 8, 1) == -1) {
235 <                fprintf(stderr, "No access to I/O ports\n");
236 <                return 1;
237 <        }
238 <        setuid(getuid());
216 >        ioport_access();
217  
218          // Init Catweasel
241        memset(&c, 0, sizeof(c));
242        c.iobase = port;
243        c.msdelay = msdelay;
244        c.type = CATWEASEL_TYPE_MK1;
219          catweasel_init_controller(&c);
220  
221          // Start drive
222 <        catweasel_select(&c, drive == 0, drive == 1);
249 <        catweasel_set_motor(c.drives + drive, 1);
250 <        msdelay(500);
251 <        catweasel_seek(c.drives + drive, 0);
252 <        msdelay(20);
222 >        start_drive(drive_num);
223  
224          // Disk write protected?
225 <        if (!catweasel_write_protected(c.drives + drive)) {
225 >        if (!catweasel_write_protected(c.drives + drive_num)) {
226  
227                  // No, write all tracks
228                  for (track = 1; track <= NUM_TRACKS; track++) {
# Line 261 | Line 231 | int main(int argc, char **argv)
231                                  fprintf(stderr, "Error reading input file\n");
232                                  break;
233                          }
234 <                        if (!write_track(drive, track))
234 >                        if (!write_track(drive_num, track))
235                                  break;
236                  }
237  
# Line 272 | Line 242 | int main(int argc, char **argv)
242          }
243  
244          // Stop drive
245 <        catweasel_set_motor(c.drives + drive, 0);
246 <        catweasel_select(&c, 0, 0);
245 >        stop_drive(drive_num);
246 >
247 >        // Free Catweasel
248          catweasel_free_controller(&c);
249  
250          // Close input file

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines