00001
00002
00003
00004
00005
00006
00007
00008
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
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
00092
00093 c = Size - i;
00094
00095
00096
00097 if (c > 32)
00098 {
00099 c = 32;
00100 }
00101
00102
00103
00104
00105
00106 command[3] = (unsigned char) (DriveMemAddress % 256);
00107 command[4] = (unsigned char) (DriveMemAddress / 256);
00108 command[5] = (unsigned char) c;
00109
00110
00111
00112 cbmarch_raw_write(HandleDevice, command, sizeof(command));
00113
00114
00115
00116 cbmarch_raw_write(HandleDevice, bufferToProgram, c);
00117
00118
00119
00120
00121
00122 DriveMemAddress += c;
00123 bufferToProgram += c;
00124
00125
00126
00127 rv += c;
00128
00129
00130
00131
00132 cbmarch_unlisten(HandleDevice);
00133 }
00134
00135 FUNC_LEAVE_INT(rv);
00136 }