Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

std.c

00001 /*
00002  *      This program is free software; you can redistribute it and/or
00003  *      modify it under the terms of the GNU General Public License
00004  *      as published by the Free Software Foundation; either version
00005  *      2 of the License, or (at your option) any later version.
00006  *
00007  *  Copyright 1999 Michael Klein <michael(dot)klein(at)puffin(dot)lb(dot)shuttle(dot)de>
00008 */
00009 
00010 #ifdef SAVE_RCSID
00011 static char *rcsid =
00012     "@(#) $Id: std.c,v 1.6 2006/03/10 15:20:24 trikalio Exp $";
00013 #endif
00014 
00015 #include "opencbm.h"
00016 #include "d64copy_int.h"
00017 
00018 #include <stdio.h>
00019 #include <stdlib.h>
00020 
00021 static unsigned char drive = 0;
00022 static CBM_FILE fd_cbm = (CBM_FILE) -1;
00023 
00024 static int read_block(unsigned char tr, unsigned char se, unsigned char *block)
00025 {
00026     char cmd[48];
00027     int rv = 1;
00028 
00029     sprintf(cmd, "U1:2 0 %d %d", tr, se);
00030     if(cbm_exec_command(fd_cbm, drive, cmd, 0) == 0) {
00031         rv = cbm_device_status(fd_cbm, drive, cmd, sizeof(cmd));
00032         if(rv == 0) {
00033             if(cbm_exec_command(fd_cbm, drive, "B-P2 0", 0) == 0) {
00034                 if(cbm_talk(fd_cbm, drive, 2) == 0) {
00035                     rv = cbm_raw_read(fd_cbm, block, BLOCKSIZE) != BLOCKSIZE;
00036                     cbm_untalk(fd_cbm);
00037                 }
00038             }
00039         }
00040     }
00041     return rv;
00042 }
00043 
00044 static int write_block(unsigned char tr, unsigned char se, const unsigned char *blk, int size, int read_status)
00045 {
00046     char cmd[48];
00047     int  rv = 1;
00048 
00049     if(cbm_exec_command(fd_cbm, drive, "B-P2 0", 0) == 0)
00050     {
00051         if(cbm_listen(fd_cbm, drive, 2) == 0)
00052         {
00053             rv = cbm_raw_write(fd_cbm, blk, size) != size;
00054             cbm_unlisten(fd_cbm);
00055             if(rv == 0)
00056             {
00057                 sprintf(cmd ,"U2:2 0 %d %d", tr, se);
00058                 cbm_exec_command(fd_cbm, drive, cmd, 0);
00059                 rv = cbm_device_status(fd_cbm, drive, cmd, sizeof(cmd));
00060             }
00061         }
00062     }
00063     return rv;
00064 }
00065 
00066 static int open_disk(CBM_FILE fd, d64copy_settings *settings,
00067                      const void *arg, int for_writing,
00068                      turbo_start start, d64copy_message_cb message_cb)
00069 {
00070     char buf[48];
00071     int rv;
00072 
00073     if(settings->end_track > STD_TRACKS && !settings->two_sided)
00074     {
00075         message_cb(0, 
00076                    "standard transfer doesn't handle extended track images");
00077         return 99;
00078     }
00079 
00080     drive = (unsigned char)(ULONG_PTR)arg;
00081 
00082     fd_cbm = fd;
00083 
00084     cbm_open(fd_cbm, drive, 2, "#", 1);
00085 
00086     rv = cbm_device_status(fd_cbm, drive, buf, sizeof(buf));
00087     if(rv)
00088     {
00089         message_cb(0, "drive %02d: %s", drive, buf);
00090     }
00091     return rv;
00092 }
00093 
00094 static void close_disk(void)
00095 {
00096     cbm_close(fd_cbm, drive, 2);
00097 }
00098 
00099 DECLARE_TRANSFER_FUNCS(std_transfer, 1, 0);

Generated on Sun Apr 30 18:45:59 2006 for opencbm by  doxygen 1.4.2