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

upload.c

Go to the documentation of this file.
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-2005 Michael Klein <michael(dot)klein(at)puffin(dot)lb(dot)shuttle(dot)de>
00008  *  Copyright 2001-2005 Spiro Trikaliotis
00009  *
00010 */
00011 
00022 #define DBG_USERMODE
00023 
00025 #define DBG_PROGNAME "OPENCBM.DLL"
00026 
00027 #include "debug.h"
00028 
00029 #include <stdlib.h>
00030 
00032 #define DLL
00033 #include "opencbm.h"
00034 #include "archlib.h"
00035 
00036 
00037 /*-------------------------------------------------------------------*/
00038 /*--------- HELPER FUNCTIONS ----------------------------------------*/
00039 
00040 
00072 int CBMAPIDECL
00073 cbm_upload(CBM_FILE HandleDevice, __u_char DeviceAddress, 
00074            int DriveMemAddress, const void *Program, size_t Size)
00075 {
00076     const char *bufferToProgram = Program;
00077 
00078     unsigned char command[] = { 'M', '-', 'W', ' ', ' ', ' ' };
00079     size_t i;
00080     int rv = 0;
00081     int c;
00082 
00083     FUNC_ENTER();
00084 
00085     DBG_ASSERT(sizeof(command) == 6);
00086 
00087     for(i = 0; i < Size; i += 32)
00088     {
00089         cbmarch_listen(HandleDevice, DeviceAddress, 15);
00090 
00091         // Calculate how much bytes are left
00092 
00093         c = Size - i;
00094 
00095         // Do we have more than 32? Than, restrict to 32
00096 
00097         if (c > 32)
00098         {
00099             c = 32;
00100         }
00101 
00102         // The command M-W consists of:
00103         // M-W <lowaddress> <highaddress> <count>
00104         // build that command:
00105 
00106         command[3] = (unsigned char) (DriveMemAddress % 256);
00107         command[4] = (unsigned char) (DriveMemAddress / 256);
00108         command[5] = (unsigned char) c; 
00109 
00110         // Write the M-W command to the drive...
00111 
00112         cbmarch_raw_write(HandleDevice, command, sizeof(command));
00113 
00114         // ... as well as the (up to 32) data bytes
00115 
00116         cbmarch_raw_write(HandleDevice, bufferToProgram, c);
00117 
00118         // Now, advance the pointer into drive memory
00119         // as well to the program in PC's memory in case we
00120         // might need to use it again for another M-W command
00121 
00122         DriveMemAddress += c;
00123         bufferToProgram += c;
00124 
00125         // Advance the return value of send bytes, too.
00126 
00127         rv += c;
00128 
00129         // The UNLISTEN is the signal for the drive 
00130         // to start execution of the command
00131 
00132         cbmarch_unlisten(HandleDevice);
00133     }
00134 
00135     FUNC_LEAVE_INT(rv);
00136 }

Generated on Sun Apr 30 18:46:00 2006 for opencbm by  doxygen 1.4.2