OpenCBM
LINUX/iec.c
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-2005 Michael Klein <michael(dot)klein(at)puffin(dot)lb(dot)shuttle(dot)de>
8 */
9 
10 #include <fcntl.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <sys/ioctl.h>
14 #include <unistd.h>
15 
16 #include "opencbm.h"
17 #include "cbm_module.h"
18 
19 static char *cbm_dev_name = "/dev/cbm";
20 
21 const char *opencbm_plugin_get_driver_name(int port)
22 {
23  return cbm_dev_name;
24 }
25 
26 int opencbm_plugin_driver_open(CBM_FILE *f, int port)
27 {
28  *f = open(cbm_dev_name, O_RDWR);
29  return (*f < 0) ? -1 : 0; /* FIXME */
30 }
31 
33 {
34  if(f >= 0) {
35  close(f);
36  }
37 }
38 
63 void
65 {
66 }
67 
85 void
87 {
88 }
89 
90 int opencbm_plugin_raw_write(CBM_FILE f, const void *buf, size_t size)
91 {
92  return write(f, buf, size);
93 }
94 
95 int opencbm_plugin_raw_read(CBM_FILE f, void *buf, size_t size)
96 {
97  return read(f, buf, size);
98 }
99 
100 int opencbm_plugin_listen(CBM_FILE f, unsigned char dev, unsigned char secadr)
101 {
102  return ioctl(f, CBMCTRL_LISTEN, (dev<<8) | secadr);
103 }
104 
105 int opencbm_plugin_talk(CBM_FILE f, unsigned char dev, unsigned char secadr)
106 {
107  return ioctl(f, CBMCTRL_TALK, (dev<<8) | secadr);
108 }
109 
110 int opencbm_plugin_open(CBM_FILE f, unsigned char dev, unsigned char secadr)
111 {
112  int rv;
113 
114  rv = ioctl(f, CBMCTRL_OPEN, (dev<<8) | secadr);
115  return rv;
116 }
117 
118 int opencbm_plugin_close(CBM_FILE f, unsigned char dev, unsigned char secadr)
119 {
120  return ioctl(f, CBMCTRL_CLOSE, (dev<<8) | secadr);
121 }
122 
124 {
125  return ioctl(f, CBMCTRL_UNLISTEN);
126 }
127 
129 {
130  return ioctl(f, CBMCTRL_UNTALK);
131 }
132 
134 {
135  return ioctl(f, CBMCTRL_GET_EOI);
136 }
137 
139 {
140  return ioctl(f, CBMCTRL_CLEAR_EOI);
141 }
142 
144 {
145  return ioctl(f, CBMCTRL_RESET);
146 }
147 
148 unsigned char opencbm_plugin_pp_read(CBM_FILE f)
149 {
150  return ioctl(f, CBMCTRL_PP_READ);
151 }
152 
153 void opencbm_plugin_pp_write(CBM_FILE f, unsigned char c)
154 {
155  ioctl(f, CBMCTRL_PP_WRITE, c);
156 }
157 
159 {
160  return ioctl(f, CBMCTRL_IEC_POLL);
161 }
162 
163 int opencbm_plugin_iec_get(CBM_FILE f, int line)
164 {
165  return (ioctl(f, CBMCTRL_IEC_POLL) & line) != 0;
166 }
167 
168 void opencbm_plugin_iec_set(CBM_FILE f, int line)
169 {
170  ioctl(f, CBMCTRL_IEC_SET, line);
171 }
172 
173 void opencbm_plugin_iec_release(CBM_FILE f, int line)
174 {
175  ioctl(f, CBMCTRL_IEC_RELEASE, line);
176 }
177 
178 int opencbm_plugin_iec_wait(CBM_FILE f, int line, int state)
179 {
180  return ioctl(f, CBMCTRL_IEC_WAIT, (line<<8) | state);
181 }
182 
183 void opencbm_plugin_iec_setrelease(CBM_FILE f, int set, int release)
184 {
185  ioctl(f, CBMCTRL_IEC_SETRELEASE, (set<<8) | release);
186 }
void CBMAPIDECL opencbm_plugin_iec_release(CBM_FILE HandleDevice, int Line)
Deactivate a line on the IEC serial bus.
Definition: WINDOWS/iec.c:881
void CBMAPIDECL opencbm_plugin_driver_close(CBM_FILE HandleDevice)
Closes the driver.
Definition: i_opencbm.c:454
const char *CBMAPIDECL opencbm_plugin_get_driver_name(const char *const Port)
Get the name of the driver for a specific parallel port.
Definition: i_opencbm.c:347
int CBMAPIDECL opencbm_plugin_driver_open(CBM_FILE *HandleDevice, const char *const Port)
Opens the driver.
Definition: i_opencbm.c:405
int CBMAPIDECL opencbm_plugin_open(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Open a file on the IEC serial bus.
Definition: WINDOWS/iec.c:499
int CBMAPIDECL opencbm_plugin_close(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Close a file on the IEC serial bus.
Definition: WINDOWS/iec.c:543
void CBMAPIDECL opencbm_plugin_iec_set(CBM_FILE HandleDevice, int Line)
Activate a line on the IEC serial bus.
Definition: WINDOWS/iec.c:849
#define CBMCTRL_IEC_SET
IOCTL for setting an IEC line.
Definition: cbmioctl.h:289
#define CBMCTRL_LISTEN
IOCTL for sending a LISTEN command.
Definition: cbmioctl.h:266
int CBMAPIDECL opencbm_plugin_iec_poll(CBM_FILE HandleDevice)
Read status of all bus lines.
Definition: WINDOWS/iec.c:818
#define CBMCTRL_TALK
IOCTL for sending a TALK command.
Definition: cbmioctl.h:264
int CBMAPIDECL opencbm_plugin_unlisten(CBM_FILE HandleDevice)
Send an UNLISTEN on the IEC serial bus.
Definition: WINDOWS/iec.c:581
#define CBMCTRL_UNLISTEN
IOCTL for sending an UNLISTEN command.
Definition: cbmioctl.h:270
#define CBMCTRL_IEC_RELEASE
IOCTL for releasing an IEC line.
Definition: cbmioctl.h:291
#define CBMCTRL_IEC_SETRELEASE
IOCTL for setting and releasing IEC lines at once.
Definition: cbmioctl.h:304
int CBMAPIDECL opencbm_plugin_raw_write(CBM_FILE HandleDevice, const void *Buffer, size_t Count)
Write data to the IEC serial bus.
Definition: WINDOWS/iec.c:323
#define CBMCTRL_GET_EOI
IOCTL for getting the EOI state.
Definition: cbmioctl.h:278
int CBMAPIDECL opencbm_plugin_listen(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Send a LISTEN on the IEC serial bus.
Definition: WINDOWS/iec.c:421
#define CBMCTRL_PP_WRITE
IOCTL for setting the PP values.
Definition: cbmioctl.h:285
void CBMAPIDECL opencbm_plugin_unlock(CBM_FILE HandleDevice)
Unlock the parallel port for the driver.
Definition: WINDOWS/iec.c:289
#define CBM_FILE
Definition: opencbm.h:87
int CBMAPIDECL opencbm_plugin_reset(CBM_FILE HandleDevice)
RESET all devices.
Definition: WINDOWS/iec.c:706
unsigned char CBMAPIDECL opencbm_plugin_pp_read(CBM_FILE HandleDevice)
Read a byte from a XP1541/XP1571 cable.
Definition: WINDOWS/iec.c:748
void CBMAPIDECL opencbm_plugin_iec_setrelease(CBM_FILE HandleDevice, int Set, int Release)
Activate and deactive a line on the IEC serial bus.
Definition: WINDOWS/iec.c:922
int CBMAPIDECL opencbm_plugin_talk(CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress)
Send a TALK on the IEC serial bus.
Definition: WINDOWS/iec.c:461
#define CBMCTRL_UNTALK
IOCTL for sending an UNTALK command.
Definition: cbmioctl.h:268
int CBMAPIDECL opencbm_plugin_untalk(CBM_FILE HandleDevice)
Send an UNTALK on the IEC serial bus.
Definition: WINDOWS/iec.c:613
#define CBMCTRL_PP_READ
IOCTL for reading the PP values.
Definition: cbmioctl.h:283
#define CBMCTRL_RESET
IOCTL for sending a RESET.
Definition: cbmioctl.h:276
int CBMAPIDECL opencbm_plugin_clear_eoi(CBM_FILE HandleDevice)
Reset the EOI flag.
Definition: WINDOWS/iec.c:673
#define CBMCTRL_IEC_POLL
IOCTL for polling an IEC line.
Definition: cbmioctl.h:287
#define CBMCTRL_CLEAR_EOI
IOCTL for resetting the EOI state.
Definition: cbmioctl.h:280
DLL interface for accessing the driver.
int CBMAPIDECL opencbm_plugin_iec_wait(CBM_FILE HandleDevice, int Line, int State)
Wait for a line to have a specific state.
Definition: WINDOWS/iec.c:963
void CBMAPIDECL opencbm_plugin_lock(CBM_FILE HandleDevice)
Lock the parallel port for the driver.
Definition: WINDOWS/iec.c:262
#define CBMCTRL_IEC_WAIT
IOCTL for waiting for an IEC line.
Definition: cbmioctl.h:293
#define CBMCTRL_OPEN
IOCTL for sending an OPEN command.
Definition: cbmioctl.h:272
int CBMAPIDECL opencbm_plugin_get_eoi(CBM_FILE HandleDevice)
Get EOI flag after bus read.
Definition: WINDOWS/iec.c:646
int CBMAPIDECL opencbm_plugin_raw_read(CBM_FILE HandleDevice, void *Buffer, size_t Count)
Read data from the IEC serial bus.
Definition: WINDOWS/iec.c:370
#define CBMCTRL_CLOSE
IOCTL for sending a CLOSE command.
Definition: cbmioctl.h:274
void CBMAPIDECL opencbm_plugin_pp_write(CBM_FILE HandleDevice, unsigned char Byte)
Write a byte to a XP1541/XP1571 cable.
Definition: WINDOWS/iec.c:783