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

libcbmcopy/s2.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: s2.c,v 1.13 2006/04/09 10:30:20 trikalio Exp $";
00013 #endif
00014 
00015 #include "opencbm.h"
00016 #include "cbmcopy_int.h"
00017 
00018 #include <stdlib.h>
00019 
00020 #include "arch.h"
00021 
00022 
00023 static const unsigned char s2r15x1[] = {
00024 #include "s2r.inc"
00025 };
00026 
00027 static const unsigned char s2w15x1[] = {
00028 #include "s2w.inc"
00029 };
00030 
00031 static const unsigned char s2r1581[] = {
00032 #include "s2r-1581.inc"
00033 };
00034 
00035 static const unsigned char s2w1581[] = {
00036 #include "s2w-1581.inc"
00037 };
00038 
00039 static struct drive_prog
00040 {
00041     const unsigned char *prog;
00042     size_t size;
00043 } drive_progs[] =
00044 {
00045     { s2r15x1, sizeof(s2r15x1) },
00046     { s2w15x1, sizeof(s2w15x1) },
00047     { s2r1581, sizeof(s2r1581) },
00048     { s2w1581, sizeof(s2w1581) }
00049 };
00050 
00051 static int write_byte(CBM_FILE fd, unsigned char c)
00052 {
00053     int i;
00054     for(i=4; i>0; i--) {
00055         c & 1 ? cbm_iec_set(fd, IEC_DATA) : cbm_iec_release(fd, IEC_DATA);
00056         c >>= 1;
00057         cbm_iec_release(fd, IEC_ATN);
00058 #ifndef USE_CBM_IEC_WAIT
00059         while(cbm_iec_get(fd, IEC_CLOCK));
00060 #else
00061         cbm_iec_wait(fd, IEC_CLOCK, 0);
00062 #endif
00063         c & 1 ? cbm_iec_set(fd, IEC_DATA) : cbm_iec_release(fd, IEC_DATA);
00064         c >>= 1;
00065         cbm_iec_set(fd, IEC_ATN);
00066 #ifndef USE_CBM_IEC_WAIT
00067         while(!cbm_iec_get(fd, IEC_CLOCK));
00068 #else
00069         cbm_iec_wait(fd, IEC_CLOCK, 1);
00070 #endif
00071     }
00072     cbm_iec_release(fd, IEC_DATA);
00073     return 0;
00074 }
00075 
00076 static unsigned char read_byte(CBM_FILE fd)
00077 {
00078     int i;
00079     unsigned char c;
00080     c = 0;
00081     for(i=4; i>0; i--) {
00082 #ifndef USE_CBM_IEC_WAIT
00083         while(cbm_iec_get(fd, IEC_CLOCK));
00084         c = (c>>1) | (cbm_iec_get(fd, IEC_DATA) ? 0x80 : 0);
00085 #else
00086         c = (c>>1) | ((cbm_iec_wait(fd, IEC_CLOCK, 0) & IEC_DATA) ? 0x80 : 0 );
00087 #endif
00088         cbm_iec_release(fd, IEC_ATN);
00089 #ifndef USE_CBM_IEC_WAIT
00090         while(!cbm_iec_get(fd,IEC_CLOCK));
00091         c = (c>>1) | (cbm_iec_get(fd, IEC_DATA) ? 0x80 : 0);
00092 #else   
00093         c = (c>>1) | ((cbm_iec_wait(fd, IEC_CLOCK, 1) & IEC_DATA) ? 0x80 : 0 );    
00094 #endif  
00095         cbm_iec_set(fd, IEC_ATN);
00096     }   
00097 
00098     return c;
00099 }
00100 
00101 static int check_error(CBM_FILE fd, int write)
00102 {
00103     int error;
00104 
00105     cbm_iec_release(fd, IEC_ATN);
00106     cbm_iec_wait(fd, IEC_CLOCK, 0);
00107     error = cbm_iec_get(fd, IEC_DATA) == 0;
00108     if(!error)
00109     {
00110         cbm_iec_set(fd, IEC_DATA);
00111         cbm_iec_set(fd, IEC_ATN);
00112         cbm_iec_wait(fd, IEC_CLOCK, 1);
00113         if(!write)
00114         {
00115             cbm_iec_release(fd, IEC_DATA);
00116         }
00117     }
00118 
00119     return error;
00120 }
00121 
00122 static int upload_turbo(CBM_FILE fd, unsigned char drive,
00123                         enum cbm_device_type_e drive_type, int write)
00124 {
00125     const struct drive_prog *p;
00126     int dt;
00127 
00128     dt = (drive_type == cbm_dt_cbm1581);
00129     p = &drive_progs[dt * 2 + (write != 0)];
00130 
00131     cbm_upload(fd, drive, 0x680, p->prog, p->size);
00132     return 0;
00133 }
00134 
00135 static int start_turbo(CBM_FILE fd, int write)
00136 {
00137     cbm_iec_release(fd, IEC_CLOCK);
00138     cbm_iec_wait(fd, IEC_CLOCK, 1);
00139     cbm_iec_set(fd, IEC_ATN);
00140     arch_usleep(20000);
00141     return 0;
00142 }
00143 
00144 static void exit_turbo(CBM_FILE fd, int write)
00145 {
00146     cbm_iec_release(fd, IEC_ATN);
00147     cbm_iec_release(fd, IEC_DATA);
00148     cbm_iec_set(fd, IEC_CLOCK);
00149     arch_usleep(20000);
00150 //    cbm_iec_wait(fd, IEC_DATA, 0);
00151 }
00152 
00153 DECLARE_TRANSFER_FUNCS(s2_transfer);

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