24 #define DBG_PROGNAME "OPENCBM.DLL"
51 static __inline
void StoreInt8IntoBuffer(
unsigned char * Buffer,
unsigned int Value)
54 *Buffer = (
unsigned char) Value;
70 static __inline
void StoreInt16IntoBuffer(
unsigned char * Buffer,
unsigned int Value)
73 StoreInt8IntoBuffer(Buffer++, Value % 256);
74 StoreInt8IntoBuffer(Buffer, Value / 256);
94 static __inline
void StoreAddressAndCount(
unsigned char * Buffer,
unsigned int DriveMemAddress,
unsigned int ByteCount)
96 StoreInt16IntoBuffer(Buffer, DriveMemAddress);
97 StoreInt8IntoBuffer(Buffer + 2, ByteCount);
134 int DriveMemAddress,
const void *Program,
size_t Size)
136 const char *bufferToProgram = Program;
138 unsigned char command[] = {
'M',
'-',
'W',
' ',
' ',
' ' };
147 for(i = 0; i < Size; i += 32)
149 if (
cbm_listen(HandleDevice, DeviceAddress, 15) ) {
168 StoreAddressAndCount(&command[3], DriveMemAddress, c);
172 if (
cbm_raw_write(HandleDevice, command,
sizeof(command)) !=
sizeof command) {
180 if (
cbm_raw_write(HandleDevice, bufferToProgram, c) != c ) {
189 DriveMemAddress += c;
190 bufferToProgram += c;
240 enum { TRANSFER_SIZE_DOWNLOAD = 0x100u };
243 cbm_download(
CBM_FILE HandleDevice,
unsigned char DeviceAddress,
244 int DriveMemAddress,
void *
const Buffer,
size_t Size)
246 unsigned char command[] = {
'M',
'-',
'R',
' ',
' ',
'\0',
'\r' };
247 unsigned char *StoreBuffer = Buffer;
253 int page2workaround = 0;
259 for(i = 0; i < Size; i += c)
267 if (c > TRANSFER_SIZE_DOWNLOAD)
269 c = TRANSFER_SIZE_DOWNLOAD;
277 if (c + (DriveMemAddress & 0xFF) > 0x100) {
278 c = 0x100 - (DriveMemAddress & 0xFF);
285 StoreAddressAndCount(&command[3], DriveMemAddress, c);
288 if (
cbm_exec_command(HandleDevice, DeviceAddress, command,
sizeof(command)) ) {
294 if (
cbm_talk(HandleDevice, DeviceAddress, 15) ) {
306 DriveMemAddress += readbytes;
307 StoreBuffer += readbytes;
328 if ( ( (DriveMemAddress & 0xFF00) >> 8 == 2) && page2workaround == 0 ) {
int CBMAPIDECL cbm_talk(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Send a TALK on the IEC serial bus.
#define FUNC_LEAVE_INT(_xxx)
int CBMAPIDECL cbm_listen(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Send a LISTEN on the IEC serial bus.
Define makros for debugging purposes.
int CBMAPIDECL cbm_raw_write(CBM_FILE HandleDevice, const void *Buffer, size_t Count)
Write data to the IEC serial bus.
int CBMAPIDECL cbm_unlisten(CBM_FILE HandleDevice)
Send an UNLISTEN on the IEC serial bus.
int CBMAPIDECL cbm_raw_read(CBM_FILE HandleDevice, void *Buffer, size_t Count)
Read data from the IEC serial bus.
int CBMAPIDECL cbm_exec_command(CBM_FILE HandleDevice, unsigned char DeviceAddress, const void *Command, size_t Size)
Executes a command in the floppy drive.
DLL interface for accessing the driver.
int CBMAPIDECL cbm_untalk(CBM_FILE HandleDevice)
Send an UNTALK on the IEC serial bus.
int CBMAPIDECL cbm_upload(CBM_FILE HandleDevice, unsigned char DeviceAddress, int DriveMemAddress, const void *Program, size_t Size)
Upload a program into a floppy's drive memory.