OpenCBM
plugin/xu1541/archlib.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version
5  * 2 of the License, or (at your option) any later version.
6  *
7  * Copyright 1999-2001 Michael Klein <michael(dot)klein(at)puffin(dot)lb(dot)shuttle(dot)de>
8  * Copyright 2001-2005, 2007, 2009, 2011 Spiro Trikaliotis
9  *
10 */
11 
20 #ifdef WIN32
21 #include <windows.h>
22 #include <windowsx.h>
23 
25 #define DBG_USERMODE
26 
28 // #define DBG_DLL
29 
31 #define DBG_PROGNAME "OPENCBM-XU1541.DLL"
32 
34 // #define DBG_IS_DEBUG_C
35 
36 #include "debug.h"
37 #endif
38 
39 #include <stdlib.h>
40 
42 #define OPENCBM_PLUGIN
43 #include "archlib.h"
44 
45 #include "xu1541.h"
46 
47 
48 /*-------------------------------------------------------------------*/
49 /*--------- OPENCBM ARCH FUNCTIONS ----------------------------------*/
50 
67 const char * CBMAPIDECL
68 opencbm_plugin_get_driver_name(const char * const Port)
69 {
70  UNREFERENCED_PARAMETER(Port);
71 
72  return "libusb/xu1541";
73 }
74 
95 int CBMAPIDECL
96 opencbm_plugin_driver_open(CBM_FILE *HandleDevice, const char * const Port)
97 {
98  UNREFERENCED_PARAMETER(Port);
99 
100  return xu1541_init();
101 }
102 
117 void CBMAPIDECL
119 {
120  xu1541_close();
121 }
122 
123 
148 void CBMAPIDECL
150 {
151 }
152 
170 void CBMAPIDECL
172 {
173 }
174 
199 int CBMAPIDECL
200 opencbm_plugin_raw_write(CBM_FILE HandleDevice, const void *Buffer, size_t Count)
201 {
202  return xu1541_write(Buffer, Count);
203 }
204 
228 int CBMAPIDECL
229 opencbm_plugin_raw_read(CBM_FILE HandleDevice, void *Buffer, size_t Count)
230 {
231  return xu1541_read(Buffer, Count);
232 }
233 
234 
235 
259 int CBMAPIDECL
260 opencbm_plugin_listen(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
261 {
262  return xu1541_ioctl(XU1541_LISTEN, DeviceAddress, SecondaryAddress);
263 }
264 
288 int CBMAPIDECL
289 opencbm_plugin_talk(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
290 {
291  return xu1541_ioctl(XU1541_TALK, DeviceAddress, SecondaryAddress);
292 }
293 
315 int CBMAPIDECL
316 opencbm_plugin_open(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
317 {
318  return xu1541_ioctl(XU1541_OPEN, DeviceAddress, SecondaryAddress);
319 }
320 
342 int CBMAPIDECL
343 opencbm_plugin_close(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
344 {
345  return xu1541_ioctl(XU1541_CLOSE, DeviceAddress, SecondaryAddress);
346 }
347 
368 int CBMAPIDECL
370 {
371  return xu1541_ioctl(XU1541_UNLISTEN, 0, 0);
372 }
373 
394 int CBMAPIDECL
396 {
397  return xu1541_ioctl(XU1541_UNTALK, 0, 0);
398 }
399 
400 
421 int CBMAPIDECL
423 {
424  return xu1541_ioctl(XU1541_GET_EOI, 0, 0);
425 }
426 
442 int CBMAPIDECL
444 {
445  return xu1541_ioctl(XU1541_CLEAR_EOI, 0, 0);
446 }
447 
469 int CBMAPIDECL
471 {
472  return xu1541_ioctl(XU1541_RESET, 0, 0);
473 }
474 
475 
476 /*-------------------------------------------------------------------*/
477 /*--------- LOW-LEVEL PORT ACCESS -----------------------------------*/
478 
500 unsigned char CBMAPIDECL
502 {
503  return (unsigned char) xu1541_ioctl(XU1541_PP_READ, 0, 0);
504 }
505 
529 void CBMAPIDECL
530 opencbm_plugin_pp_write(CBM_FILE HandleDevice, unsigned char Byte)
531 {
532  xu1541_ioctl(XU1541_PP_WRITE, Byte, 0);
533 }
534 
556 int CBMAPIDECL
558 {
559  return xu1541_ioctl(XU1541_IEC_POLL, 0, 0);
560 }
561 
562 
581 void CBMAPIDECL
582 opencbm_plugin_iec_set(CBM_FILE HandleDevice, int Line)
583 {
584  xu1541_ioctl(XU1541_IEC_SETRELEASE, Line, 0);
585 }
586 
605 void CBMAPIDECL
606 opencbm_plugin_iec_release(CBM_FILE HandleDevice, int Line)
607 {
608  xu1541_ioctl(XU1541_IEC_SETRELEASE, 0, Line);
609 }
610 
638 void CBMAPIDECL
639 opencbm_plugin_iec_setrelease(CBM_FILE HandleDevice, int Set, int Release)
640 {
641  xu1541_ioctl(XU1541_IEC_SETRELEASE, Set, Release);
642 }
643 
670 int CBMAPIDECL
671 opencbm_plugin_iec_wait(CBM_FILE HandleDevice, int Line, int State)
672 {
673  return xu1541_ioctl(XU1541_IEC_WAIT, Line, State);
674 }
675 
int CBMAPIDECL opencbm_plugin_raw_read(CBM_FILE HandleDevice, void *Buffer, size_t Count)
Read data from 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_driver_close(CBM_FILE HandleDevice)
Closes the driver.
Define makros for debugging purposes.
void CBMAPIDECL opencbm_plugin_iec_set(CBM_FILE HandleDevice, int Line)
Activate a line on the IEC serial bus.
int CBMAPIDECL opencbm_plugin_reset(CBM_FILE HandleDevice)
RESET all devices.
#define CBMAPIDECL
Definition: opencbm.h:85
void xu1541_close(void)
close the xu1541 device
Definition: xu1541.c:243
void CBMAPIDECL opencbm_plugin_lock(CBM_FILE HandleDevice)
Lock the parallel port for the driver.
int CBMAPIDECL opencbm_plugin_iec_wait(CBM_FILE HandleDevice, int Line, int State)
Wait for a line to have a specific state.
#define CBM_FILE
Definition: opencbm.h:87
int xu1541_ioctl(unsigned int cmd, unsigned int addr, unsigned int secaddr)
perform an ioctl on the xu1541
Definition: xu1541.c:270
int CBMAPIDECL opencbm_plugin_iec_poll(CBM_FILE HandleDevice)
Read status of all bus lines.
int xu1541_init(void)
initialise the xu1541 device
Definition: xu1541.c:132
int CBMAPIDECL opencbm_plugin_driver_open(CBM_FILE *HandleDevice, const char *const Port)
Opens the driver.
int xu1541_read(unsigned char *data, size_t len)
read data from the xu1541 device
Definition: xu1541.c:461
int CBMAPIDECL opencbm_plugin_raw_write(CBM_FILE HandleDevice, const void *Buffer, size_t Count)
Write data to the IEC serial bus.
void CBMAPIDECL opencbm_plugin_unlock(CBM_FILE HandleDevice)
Unlock the parallel port for the driver.
int CBMAPIDECL opencbm_plugin_talk(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Send a TALK on the IEC serial bus.
int CBMAPIDECL opencbm_plugin_close(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Close a file on the IEC serial bus.
int CBMAPIDECL opencbm_plugin_get_eoi(CBM_FILE HandleDevice)
Get EOI flag after bus read.
const char *CBMAPIDECL opencbm_plugin_get_driver_name(const char *const Port)
Get the name of the driver for a specific parallel port.
unsigned char CBMAPIDECL opencbm_plugin_pp_read(CBM_FILE HandleDevice)
Read a byte from a XP1541/XP1571 cable.
int CBMAPIDECL opencbm_plugin_untalk(CBM_FILE HandleDevice)
Send an UNTALK on the IEC serial bus.
void CBMAPIDECL opencbm_plugin_pp_write(CBM_FILE HandleDevice, unsigned char Byte)
Write a byte to a XP1541/XP1571 cable.
void CBMAPIDECL opencbm_plugin_iec_release(CBM_FILE HandleDevice, int Line)
Deactivate a line on the IEC serial bus.
int CBMAPIDECL opencbm_plugin_unlisten(CBM_FILE HandleDevice)
Send an UNLISTEN on the IEC serial bus.
int CBMAPIDECL opencbm_plugin_listen(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Send a LISTEN on the IEC serial bus.
int CBMAPIDECL opencbm_plugin_clear_eoi(CBM_FILE HandleDevice)
Reset the EOI flag.
void CBMAPIDECL opencbm_plugin_iec_setrelease(CBM_FILE HandleDevice, int Set, int Release)
Activate and deactive a line on the IEC serial bus.
int xu1541_write(const unsigned char *data, size_t len)
write data to the xu1541 device
Definition: xu1541.c:379