OpenCBM
plugin/xum1541/archlib.c
Go to the documentation of this file.
1 /*
2  * xum1541 plugin interface, derived from the xu1541 file of the same name
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version
7  * 2 of the License, or (at your option) any later version.
8  *
9  * Copyright 2009-2010 Nate Lawson
10  * Copyright 1999-2001 Michael Klein <michael(dot)klein(at)puffin(dot)lb(dot)shuttle(dot)de>
11  * Copyright 2001-2005, 2007, 2010-2011 Spiro Trikaliotis
12  * Copyright 2010 Wolfgang Moser
13  *
14 */
15 
24 #ifdef WIN32
25 #include <windows.h>
26 #include <windowsx.h>
27 
29 #define DBG_USERMODE
30 
32 // #define DBG_DLL
33 
35 #define DBG_PROGNAME "OPENCBM-XUM1541.DLL"
36 
38 // #define DBG_IS_DEBUG_C
39 
40 #include "debug.h"
41 #endif
42 
43 #include <stdlib.h>
44 
46 #define OPENCBM_PLUGIN
47 #include "archlib_ex.h"
48 
49 #include "xum1541.h"
50 
51 
52 /*-------------------------------------------------------------------*/
53 /*--------- OPENCBM ARCH FUNCTIONS ----------------------------------*/
54 
71 const char * CBMAPIDECL
72 opencbm_plugin_get_driver_name(const char * const Port)
73 {
74  int portNumber = 0;
75 
76  if(Port != NULL) {
77  portNumber = strtoul(Port, NULL, 10);
78  }
79 
80  return xum1541_device_path(portNumber);
81 }
82 
103 int CBMAPIDECL
104 opencbm_plugin_driver_open(CBM_FILE *HandleDevice, const char * const Port)
105 {
106  int portNumber = 0;
107 
108  if(Port != NULL) {
109  portNumber = strtoul(Port, NULL, 10);
110  }
111 
112  return xum1541_init((usb_dev_handle **)HandleDevice, portNumber);
113 }
114 
129 void CBMAPIDECL
131 {
132  xum1541_close((usb_dev_handle *)HandleDevice);
133 }
134 
135 
160 void CBMAPIDECL
162 {
163 }
164 
182 void CBMAPIDECL
184 {
185 }
186 
211 int CBMAPIDECL
212 opencbm_plugin_raw_write(CBM_FILE HandleDevice, const void *Buffer, size_t Count)
213 {
214  return xum1541_write((usb_dev_handle *)HandleDevice, XUM1541_CBM, Buffer, Count);
215 }
216 
240 int CBMAPIDECL
241 opencbm_plugin_raw_read(CBM_FILE HandleDevice, void *Buffer, size_t Count)
242 {
243  return xum1541_read((usb_dev_handle *)HandleDevice, XUM1541_CBM, Buffer, Count);
244 }
245 
246 
247 
271 int CBMAPIDECL
272 opencbm_plugin_listen(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
273 {
274  unsigned char proto, dataBuf[2];
275 
276  proto = XUM1541_CBM | XUM_WRITE_ATN;
277  dataBuf[0] = 0x20 | DeviceAddress;
278  dataBuf[1] = 0x60 | SecondaryAddress;
279  return !xum1541_write((usb_dev_handle *)HandleDevice, proto, dataBuf, sizeof(dataBuf));
280 }
281 
305 int CBMAPIDECL
306 opencbm_plugin_talk(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
307 {
308  unsigned char proto, dataBuf[2];
309 
310  proto = XUM1541_CBM | XUM_WRITE_ATN | XUM_WRITE_TALK;
311  dataBuf[0] = 0x40 | DeviceAddress;
312  dataBuf[1] = 0x60 | SecondaryAddress;
313  return !xum1541_write((usb_dev_handle *)HandleDevice, proto, dataBuf, sizeof(dataBuf));
314 }
315 
337 int CBMAPIDECL
338 opencbm_plugin_open(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
339 {
340  unsigned char proto, dataBuf[2];
341 
342  proto = XUM1541_CBM | XUM_WRITE_ATN;
343  dataBuf[0] = 0x20 | DeviceAddress;
344  dataBuf[1] = 0xf0 | SecondaryAddress;
345  return !xum1541_write((usb_dev_handle *)HandleDevice, proto, dataBuf, sizeof(dataBuf));
346 }
347 
369 int CBMAPIDECL
370 opencbm_plugin_close(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
371 {
372  unsigned char proto, dataBuf[2];
373 
374  proto = XUM1541_CBM | XUM_WRITE_ATN;
375  dataBuf[0] = 0x20 | DeviceAddress;
376  dataBuf[1] = 0xe0 | SecondaryAddress;
377  return !xum1541_write((usb_dev_handle *)HandleDevice, proto, dataBuf, sizeof(dataBuf));
378 }
379 
400 int CBMAPIDECL
402 {
403  unsigned char proto, dataBuf[1];
404 
405  proto = XUM1541_CBM | XUM_WRITE_ATN;
406  dataBuf[0] = 0x3f;
407  return !xum1541_write((usb_dev_handle *)HandleDevice, proto, dataBuf, sizeof(dataBuf));
408 }
409 
430 int CBMAPIDECL
432 {
433  unsigned char proto, dataBuf[1];
434 
435  proto = XUM1541_CBM | XUM_WRITE_ATN;
436  dataBuf[0] = 0x5f;
437  return !xum1541_write((usb_dev_handle *)HandleDevice, proto, dataBuf, sizeof(dataBuf));
438 }
439 
440 
461 int CBMAPIDECL
463 {
464  return xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_GET_EOI, 0, 0);
465 }
466 
482 int CBMAPIDECL
484 {
485  return xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_CLEAR_EOI, 0, 0);
486 }
487 
509 int CBMAPIDECL
511 {
512  return xum1541_control_msg((usb_dev_handle *)HandleDevice, XUM1541_RESET);
513 }
514 
515 
516 /*-------------------------------------------------------------------*/
517 /*--------- LOW-LEVEL PORT ACCESS -----------------------------------*/
518 
540 unsigned char CBMAPIDECL
542 {
543  return (unsigned char) xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_PP_READ, 0, 0);
544 }
545 
569 void CBMAPIDECL
570 opencbm_plugin_pp_write(CBM_FILE HandleDevice, unsigned char Byte)
571 {
572  xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_PP_WRITE, Byte, 0);
573 }
574 
596 int CBMAPIDECL
598 {
599  return xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_IEC_POLL, 0, 0);
600 }
601 
602 
621 void CBMAPIDECL
622 opencbm_plugin_iec_set(CBM_FILE HandleDevice, int Line)
623 {
624  xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_IEC_SETRELEASE, Line, 0);
625 }
626 
645 void CBMAPIDECL
646 opencbm_plugin_iec_release(CBM_FILE HandleDevice, int Line)
647 {
648  xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_IEC_SETRELEASE, 0, Line);
649 }
650 
678 void CBMAPIDECL
679 opencbm_plugin_iec_setrelease(CBM_FILE HandleDevice, int Set, int Release)
680 {
681  xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_IEC_SETRELEASE, Set, Release);
682 }
683 
710 int CBMAPIDECL
711 opencbm_plugin_iec_wait(CBM_FILE HandleDevice, int Line, int State)
712 {
713  return xum1541_ioctl((usb_dev_handle *)HandleDevice, XUM1541_IEC_WAIT, Line, State);
714 }
715 
730 int CBMAPIDECL
731 xum1541_plugin_control_msg(CBM_FILE HandleDevice, unsigned int cmd)
732 {
733  return xum1541_control_msg((usb_dev_handle *)HandleDevice, cmd);
734 }
void CBMAPIDECL opencbm_plugin_pp_write(CBM_FILE HandleDevice, unsigned char Byte)
Write a byte to a XP1541/XP1571 cable.
const char * xum1541_device_path(int PortNumber)
Query unique identifier for the xum1541 device This function tries to find an unique identifier for t...
Definition: xum1541.c:287
void CBMAPIDECL opencbm_plugin_driver_close(CBM_FILE HandleDevice)
Closes the driver.
void xum1541_close(usb_dev_handle *HandleXum1541)
close the xum1541 device
Definition: xum1541.c:466
int CBMAPIDECL opencbm_plugin_raw_read(CBM_FILE HandleDevice, void *Buffer, size_t Count)
Read data from the IEC serial bus.
Define makros for debugging purposes.
int CBMAPIDECL opencbm_plugin_reset(CBM_FILE HandleDevice)
RESET all devices.
#define CBMAPIDECL
Definition: opencbm.h:85
void CBMAPIDECL opencbm_plugin_unlock(CBM_FILE HandleDevice)
Unlock the parallel port for the driver.
int CBMAPIDECL xum1541_plugin_control_msg(CBM_FILE HandleDevice, unsigned int cmd)
Sends a command to the xum1541 device.
const char *CBMAPIDECL opencbm_plugin_get_driver_name(const char *const Port)
Get the name of the driver for a specific parallel port.
int CBMAPIDECL opencbm_plugin_unlisten(CBM_FILE HandleDevice)
Send an UNLISTEN on the IEC serial bus.
int CBMAPIDECL opencbm_plugin_raw_write(CBM_FILE HandleDevice, const void *Buffer, size_t Count)
Write data to the IEC serial bus.
int CBMAPIDECL opencbm_plugin_clear_eoi(CBM_FILE HandleDevice)
Reset the EOI flag.
#define CBM_FILE
Definition: opencbm.h:87
int CBMAPIDECL opencbm_plugin_iec_wait(CBM_FILE HandleDevice, int Line, int State)
Wait for a line to have a specific state.
int xum1541_write(usb_dev_handle *HandleXum1541, unsigned char modeFlags, const unsigned char *data, size_t size)
Write data to the xum1541 device.
Definition: xum1541.c:686
int CBMAPIDECL opencbm_plugin_driver_open(CBM_FILE *HandleDevice, const char *const Port)
Opens the driver.
void CBMAPIDECL opencbm_plugin_iec_release(CBM_FILE HandleDevice, int Line)
Deactivate a line on the IEC serial bus.
int CBMAPIDECL opencbm_plugin_open(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Open a file on the IEC serial bus.
void CBMAPIDECL opencbm_plugin_iec_setrelease(CBM_FILE HandleDevice, int Set, int Release)
Activate and deactive a line on the IEC serial bus.
void CBMAPIDECL opencbm_plugin_lock(CBM_FILE HandleDevice)
Lock the parallel port for the driver.
unsigned char CBMAPIDECL opencbm_plugin_pp_read(CBM_FILE HandleDevice)
Read a byte from a XP1541/XP1571 cable.
int CBMAPIDECL opencbm_plugin_talk(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Send a TALK on the IEC serial bus.
int xum1541_init(usb_dev_handle **HandleXum1541, int PortNumber)
Initialize the xum1541 device This function tries to find and identify the xum1541 device...
Definition: xum1541.c:374
int CBMAPIDECL opencbm_plugin_listen(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Send a LISTEN on the IEC serial bus.
int xum1541_ioctl(usb_dev_handle *HandleXum1541, unsigned int cmd, unsigned int addr, unsigned int secaddr)
Perform an ioctl on the xum1541, which is any command other than read/write or special device managem...
Definition: xum1541.c:616
int xum1541_control_msg(usb_dev_handle *HandleXum1541, unsigned int cmd)
Handle synchronous USB control messages, e.g. for RESET. xum1541_ioctl() is used for bulk messages...
Definition: xum1541.c:499
int CBMAPIDECL opencbm_plugin_untalk(CBM_FILE HandleDevice)
Send an UNTALK on the IEC serial bus.
int xum1541_read(usb_dev_handle *HandleXum1541, unsigned char mode, unsigned char *data, size_t size)
Read data from the xum1541 device.
Definition: xum1541.c:833
void CBMAPIDECL opencbm_plugin_iec_set(CBM_FILE HandleDevice, int Line)
Activate a line on the IEC serial bus.
int CBMAPIDECL opencbm_plugin_iec_poll(CBM_FILE HandleDevice)
Read status of all bus lines.
int CBMAPIDECL opencbm_plugin_get_eoi(CBM_FILE HandleDevice)
Get EOI flag after bus read.
int CBMAPIDECL opencbm_plugin_close(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Close a file on the IEC serial bus.