OpenCBM
opencbm.h
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-2005 Michael Klein <michael(dot)klein(at)puffin(dot)lb(dot)shuttle(dot)de>
8  * Copyright 2001-2005,2008-2009 Spiro Trikaliotis
9  * Copyright 2006,2011 Wolfgang Moser (http://d81.de)
10  * Copyright 2009,2012 Arnd Menge
11  * Copyright 2011 Thomas Winkler
12  */
13 
26 #ifndef OPENCBM_H
27 #define OPENCBM_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <sys/types.h>
34 
35 #ifdef WIN32
36  /* we have windows */
37 
38 #include <windows.h>
39 
40 #ifdef DEFINE_ULONG_PTR
41 #define ULONG_PTR ULONG
42 #endif /* #ifdef DEFINE_ULONG_PTR */
43 
44 
45 # if defined DLL
46 # define EXTERN __declspec(dllexport)
47 # else
48 # define EXTERN __declspec(dllimport)
49 # endif
50 
51 
52 #define CBMAPIDECL __cdecl
53 # define CBM_FILE HANDLE
54 # define CBM_FILE_INVALID INVALID_HANDLE_VALUE
56 #elif defined(__MSDOS__)
57 
58  /* we have MS-DOS */
59 
60 #include <stdlib.h>
61 
62 # define EXTERN extern
63 # define CBMAPIDECL
64 # define WINAPI
65 # define CBM_FILE int
66 # define CBM_FILE_INVALID ((CBM_FILE)-1)
67 
68 extern int vdd_init(void);
69 extern void vdd_uninit(void);
70 extern int vdd_install_iohook(CBM_FILE f, int IoBaseAddress, int CableType);
71 extern int vdd_uninstall_iohook(CBM_FILE f);
72 extern void vdd_usleep(CBM_FILE f, unsigned int howlong);
73 #else
74 
75  /* we have linux or Mac */
76 
77 /*
78  * remove this include once the CBM_FILE intptr_t declaration
79  * below is changed back to int after the plugin/driver handle
80  * mapping was implemented
81  */
82 #include <stdint.h>
83 
84 # define EXTERN extern
85 # define CBMAPIDECL
86 # define WINAPI
87 # define CBM_FILE intptr_t
88 # define CBM_FILE_INVALID ((CBM_FILE)-1)
90 #ifndef UNREFERENCED_PARAMETER
91 #define UNREFERENCED_PARAMETER(x)
92 #endif
93 
94 #endif
95 
96 /* specifiers for the IEC bus lines */
97 #define IEC_DATA 0x01
98 #define IEC_CLOCK 0x02
99 #define IEC_ATN 0x04
100 #define IEC_RESET 0x08
101 #define IEC_SRQ 0x10
103 /* specifiers for the IEEE-488 bus lines */
104 #define IEE_NDAC 0x01
105 #define IEE_NRFD 0x02
106 #define IEE_ATN 0x04
107 #define IEE_IFC 0x08
108 #define IEE_DAV 0x10
109 #define IEE_EOI 0x20
110 #define IEE_REN 0x40
111 #define IEE_SRQ 0x80
114 enum cbm_device_type_e
115 {
129 };
130 
133 {
137 };
138 
140 EXTERN int CBMAPIDECL cbm_driver_open(CBM_FILE *f, int port);
141 EXTERN int CBMAPIDECL cbm_driver_open_ex(CBM_FILE *f, char * adapter);
145 
147 EXTERN const char * CBMAPIDECL cbm_get_driver_name(int port);
148 EXTERN const char * CBMAPIDECL cbm_get_driver_name_ex(char * adapter);
149 
150 EXTERN int CBMAPIDECL cbm_listen(CBM_FILE f, unsigned char dev, unsigned char secadr);
151 EXTERN int CBMAPIDECL cbm_talk(CBM_FILE f, unsigned char dev, unsigned char secadr);
152 
153 EXTERN int CBMAPIDECL cbm_open(CBM_FILE f, unsigned char dev, unsigned char secadr, const void *fname, size_t len);
154 EXTERN int CBMAPIDECL cbm_close(CBM_FILE f, unsigned char dev, unsigned char secadr);
155 
156 EXTERN int CBMAPIDECL cbm_raw_read(CBM_FILE f, void *buf, size_t size);
157 EXTERN int CBMAPIDECL cbm_raw_write(CBM_FILE f, const void *buf, size_t size);
158 
161 
164 
166 
167 EXTERN unsigned char CBMAPIDECL cbm_pp_read(CBM_FILE f);
168 EXTERN void CBMAPIDECL cbm_pp_write(CBM_FILE f, unsigned char c);
169 
171 EXTERN int CBMAPIDECL cbm_iec_get(CBM_FILE f, int line);
172 EXTERN void CBMAPIDECL cbm_iec_set(CBM_FILE f, int line);
173 EXTERN void CBMAPIDECL cbm_iec_release(CBM_FILE f, int line);
174 EXTERN void CBMAPIDECL cbm_iec_setrelease(CBM_FILE f, int set, int release);
175 EXTERN int CBMAPIDECL cbm_iec_wait(CBM_FILE f, int line, int state);
176 
177 EXTERN int CBMAPIDECL cbm_upload(CBM_FILE f, unsigned char dev, int adr, const void *prog, size_t size);
178 EXTERN int CBMAPIDECL cbm_download(CBM_FILE f, unsigned char dev, int adr, void *dbuf, size_t size);
179 
180 EXTERN int CBMAPIDECL cbm_device_status(CBM_FILE f, unsigned char dev, void *buf, size_t bufsize);
181 EXTERN int CBMAPIDECL cbm_exec_command(CBM_FILE f, unsigned char dev, const void *cmd, size_t len);
182 
183 EXTERN int CBMAPIDECL cbm_identify(CBM_FILE f, unsigned char drv,
184  enum cbm_device_type_e *t,
185  const char **type_str);
186 
188  unsigned char DeviceAddress,
189  enum cbm_device_type_e *CbmDeviceType,
190  enum cbm_cable_type_e *CableType);
191 
192 
193 EXTERN char CBMAPIDECL cbm_petscii2ascii_c(char character);
194 EXTERN char CBMAPIDECL cbm_ascii2petscii_c(char character);
195 EXTERN char * CBMAPIDECL cbm_petscii2ascii(char *str);
196 EXTERN char * CBMAPIDECL cbm_ascii2petscii(char *str);
197 
198 EXTERN int CBMAPIDECL gcr_5_to_4_decode(const unsigned char *source, unsigned char *dest,
199  size_t sourceLength, size_t destLength);
200 EXTERN int CBMAPIDECL gcr_4_to_5_encode(const unsigned char *source, unsigned char *dest,
201  size_t sourceLength, size_t destLength);
202 
203 
204 #if DBG
205 EXTERN int CBMAPIDECL cbm_get_debugging_buffer(CBM_FILE HandleDevice, char *buffer, size_t len);
206 #endif
207 
208 EXTERN int CBMAPIDECL cbm_iec_dbg_read (CBM_FILE HandleDevice);
209 EXTERN int CBMAPIDECL cbm_iec_dbg_write(CBM_FILE HandleDevice, unsigned char Value);
210 
211 /* functions specifically for parallel burst */
212 
214 EXTERN void CBMAPIDECL cbm_parallel_burst_write(CBM_FILE f, unsigned char c);
215 EXTERN int CBMAPIDECL cbm_parallel_burst_read_n(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length);
216 EXTERN int CBMAPIDECL cbm_parallel_burst_write_n(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length);
217 EXTERN int CBMAPIDECL cbm_parallel_burst_read_track(CBM_FILE f, unsigned char *buffer, unsigned int length);
218 EXTERN int CBMAPIDECL cbm_parallel_burst_read_track_var(CBM_FILE f, unsigned char *buffer, unsigned int length);
219 EXTERN int CBMAPIDECL cbm_parallel_burst_write_track(CBM_FILE f, unsigned char *buffer, unsigned int length);
220 
221 /* parallel burst functions end */
222 
223 /* functions specifically for srq nibbler */
224 
226 EXTERN void CBMAPIDECL cbm_srq_burst_write(CBM_FILE f, unsigned char c);
227 EXTERN int CBMAPIDECL cbm_srq_burst_read_n(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length);
228 EXTERN int CBMAPIDECL cbm_srq_burst_write_n(CBM_FILE HandleDevice, unsigned char *Buffer, unsigned int Length);
229 EXTERN int CBMAPIDECL cbm_srq_burst_read_track(CBM_FILE f, unsigned char *buffer, unsigned int length);
230 EXTERN int CBMAPIDECL cbm_srq_burst_write_track(CBM_FILE f, unsigned char *buffer, unsigned int length);
231 
232 /* srq nibbler functions end */
233 
234 /* functions specifically for CBM 153x tape drive */
235 
237 EXTERN int CBMAPIDECL cbm_tap_prepare_write(CBM_FILE f, int *Status);
238 EXTERN int CBMAPIDECL cbm_tap_get_sense(CBM_FILE f, int *Status);
241 EXTERN int CBMAPIDECL cbm_tap_start_capture(CBM_FILE f, unsigned char *Buffer, unsigned int Buffer_Length, int *Status, int *BytesRead);
242 EXTERN int CBMAPIDECL cbm_tap_start_write(CBM_FILE f, unsigned char *Buffer, unsigned int Length, int *Status, int *BytesWritten);
243 EXTERN int CBMAPIDECL cbm_tap_motor_on(CBM_FILE f, int *Status);
244 EXTERN int CBMAPIDECL cbm_tap_motor_off(CBM_FILE f, int *Status);
245 EXTERN int CBMAPIDECL cbm_tap_get_ver(CBM_FILE f, int *Status);
246 EXTERN int CBMAPIDECL cbm_tap_download_config(CBM_FILE f, unsigned char *Buffer, unsigned int Buffer_Length, int *Status, int *BytesRead);
247 EXTERN int CBMAPIDECL cbm_tap_upload_config(CBM_FILE f, unsigned char *Buffer, unsigned int Length, int *Status, int *BytesWritten);
248 EXTERN int CBMAPIDECL cbm_tap_break(CBM_FILE f);
249 
250 /* tape capture functions end */
251 
252 /* get function address of the plugin */
253 EXTERN void * CBMAPIDECL cbm_get_plugin_function_address(const char * Functionname);
254 
255 #ifdef __cplusplus
256 }
257 #endif
258 
259 #endif /* OPENCBM_H */
EXTERN int CBMAPIDECL cbm_iec_poll(CBM_FILE f)
Read status of all bus lines.
Definition: cbm.c:1314
EXTERN int CBMAPIDECL cbm_tap_prepare_write(CBM_FILE f, int *Status)
TAPE: Prepare write.
Definition: cbm.c:2055
EXTERN int CBMAPIDECL cbm_srq_burst_read_track(CBM_FILE f, unsigned char *buffer, unsigned int length)
PARBURST: Read a complete track.
Definition: cbm.c:1958
EXTERN void CBMAPIDECL cbm_srq_burst_write(CBM_FILE f, unsigned char c)
PARBURST: Write to the parallel port.
Definition: cbm.c:1877
EXTERN int CBMAPIDECL cbm_raw_read(CBM_FILE f, void *buf, size_t size)
Read data from the IEC serial bus.
Definition: cbm.c:906
EXTERN int CBMAPIDECL gcr_5_to_4_decode(const unsigned char *source, unsigned char *dest, size_t sourceLength, size_t destLength)
Decode GCR data.
Definition: gcr_4b5b.c:81
EXTERN int CBMAPIDECL cbm_tap_get_ver(CBM_FILE f, int *Status)
TAPE: Return tape firmware version.
Definition: cbm.c:2320
EXTERN int CBMAPIDECL gcr_4_to_5_encode(const unsigned char *source, unsigned char *dest, size_t sourceLength, size_t destLength)
Encode GCR data.
Definition: gcr_4b5b.c:206
EXTERN int CBMAPIDECL cbm_tap_start_capture(CBM_FILE f, unsigned char *Buffer, unsigned int Buffer_Length, int *Status, int *BytesRead)
TAPE: Start capture.
Definition: cbm.c:2247
EXTERN int CBMAPIDECL cbm_iec_get(CBM_FILE f, int line)
Get the (logical) state of a line on the IEC serial bus.
Definition: cbm.c:1477
EXTERN unsigned char CBMAPIDECL cbm_pp_read(CBM_FILE f)
Read a byte from a XP1541/XP1571 cable.
Definition: cbm.c:1244
#define CBMAPIDECL
Definition: opencbm.h:85
EXTERN int CBMAPIDECL cbm_untalk(CBM_FILE f)
Send an UNTALK on the IEC serial bus.
Definition: cbm.c:1128
EXTERN char *CBMAPIDECL cbm_petscii2ascii(char *str)
Convert an null-termined PETSCII string to ASCII.
Definition: petscii.c:136
EXTERN void CBMAPIDECL cbm_driver_close(CBM_FILE f)
Closes the driver.
Definition: cbm.c:768
EXTERN int CBMAPIDECL cbm_exec_command(CBM_FILE f, unsigned char dev, const void *cmd, size_t len)
Executes a command in the floppy drive.
Definition: cbm.c:1599
EXTERN int CBMAPIDECL cbm_driver_open_ex(CBM_FILE *f, char *adapter)
Opens the driver, extended version.
Definition: cbm.c:683
EXTERN int CBMAPIDECL cbm_identify_xp1541(CBM_FILE HandleDevice, unsigned char DeviceAddress, enum cbm_device_type_e *CbmDeviceType, enum cbm_cable_type_e *CableType)
Identify the cable connected to a specific floppy drive.
Definition: detectxp1541.c:187
EXTERN const char *CBMAPIDECL cbm_get_driver_name(int port)
Get the name of the driver for a specific parallel port.
Definition: cbm.c:650
EXTERN int CBMAPIDECL cbm_tap_upload_config(CBM_FILE f, unsigned char *Buffer, unsigned int Length, int *Status, int *BytesWritten)
TAPE: Upload configuration.
Definition: cbm.c:2419
EXTERN int CBMAPIDECL cbm_device_status(CBM_FILE f, unsigned char dev, void *buf, size_t bufsize)
Read the drive status from a floppy.
Definition: cbm.c:1525
EXTERN int CBMAPIDECL cbm_parallel_burst_read_track(CBM_FILE f, unsigned char *buffer, unsigned int length)
PARBURST: Read a complete track.
Definition: cbm.c:1746
EXTERN int CBMAPIDECL cbm_tap_wait_for_stop_sense(CBM_FILE f, int *Status)
TAPE: Wait for sense.
Definition: cbm.c:2115
EXTERN int CBMAPIDECL cbm_parallel_burst_read_track_var(CBM_FILE f, unsigned char *buffer, unsigned int length)
PARBURST: Read a variable length track.
Definition: cbm.c:1780
#define EXTERN
Definition: opencbm.h:84
EXTERN int CBMAPIDECL cbm_iec_dbg_read(CBM_FILE HandleDevice)
Read a byte from the parallel port input register.
Definition: cbm.c:2485
EXTERN void CBMAPIDECL cbm_pp_write(CBM_FILE f, unsigned char c)
Write a byte to a XP1541/XP1571 cable.
Definition: cbm.c:1282
EXTERN int CBMAPIDECL cbm_reset(CBM_FILE f)
RESET all devices.
Definition: cbm.c:1209
EXTERN int CBMAPIDECL cbm_get_eoi(CBM_FILE f)
Get EOI flag after bus read.
Definition: cbm.c:1157
EXTERN void *CBMAPIDECL cbm_get_plugin_function_address(const char *Functionname)
Get the function pointer for a function in a plugin.
Definition: cbm.c:2449
EXTERN int CBMAPIDECL cbm_tap_motor_on(CBM_FILE f, int *Status)
TAPE: Motor on.
Definition: cbm.c:2175
EXTERN char *CBMAPIDECL cbm_ascii2petscii(char *str)
Convert an null-termined ASCII string to PETSCII.
Definition: petscii.c:160
#define CBM_FILE
Definition: opencbm.h:87
EXTERN int CBMAPIDECL cbm_get_debugging_buffer(CBM_FILE HandleDevice, char *buffer, size_t len)
Output contents of the debugging buffer.
Definition: WINDOWS/iec.c:991
EXTERN int CBMAPIDECL cbm_tap_motor_off(CBM_FILE f, int *Status)
TAPE: Motor off.
Definition: cbm.c:2205
EXTERN const char *CBMAPIDECL cbm_get_driver_name_ex(char *adapter)
Get the name of the driver for a specific parallel port, extended version.
Definition: cbm.c:583
Definition: cbmctrl.c:1340
BOOLEAN vdd_usleep(VOID)
Sleep some microseconds.
Definition: execute.c:1447
EXTERN int CBMAPIDECL cbm_close(CBM_FILE f, unsigned char dev, unsigned char secadr)
Close a file on the IEC serial bus.
Definition: cbm.c:1072
EXTERN void CBMAPIDECL cbm_iec_setrelease(CBM_FILE f, int set, int release)
Activate and deactive a line on the IEC serial bus.
Definition: cbm.c:1412
EXTERN void CBMAPIDECL cbm_iec_set(CBM_FILE f, int line)
Activate a line on the IEC serial bus.
Definition: cbm.c:1341
EXTERN int CBMAPIDECL cbm_talk(CBM_FILE f, unsigned char dev, unsigned char secadr)
Send a TALK on the IEC serial bus.
Definition: cbm.c:976
EXTERN int CBMAPIDECL cbm_tap_prepare_capture(CBM_FILE f, int *Status)
TAPE: Prepare capture.
Definition: cbm.c:2025
EXTERN int CBMAPIDECL cbm_open(CBM_FILE f, unsigned char dev, unsigned char secadr, const void *fname, size_t len)
Open a file on the IEC serial bus.
Definition: cbm.c:1012
EXTERN int CBMAPIDECL cbm_identify(CBM_FILE f, unsigned char drv, enum cbm_device_type_e *t, const char **type_str)
Identify the connected floppy drive.
Definition: detect.c:66
EXTERN unsigned char CBMAPIDECL cbm_parallel_burst_read(CBM_FILE f)
PARBURST: Read from the parallel port.
Definition: cbm.c:1635
EXTERN int CBMAPIDECL cbm_listen(CBM_FILE f, unsigned char dev, unsigned char secadr)
Send a LISTEN on the IEC serial bus.
Definition: cbm.c:945
BOOLEAN vdd_uninstall_iohook(CBM_FILE HandleDevice)
Uninstall the I/O hook.
Definition: execute.c:1422
cbm_device_type_e
Definition: opencbm.h:114
EXTERN int CBMAPIDECL cbm_tap_download_config(CBM_FILE f, unsigned char *Buffer, unsigned int Buffer_Length, int *Status, int *BytesRead)
TAPE: Download configuration.
Definition: cbm.c:2377
EXTERN int CBMAPIDECL cbm_clear_eoi(CBM_FILE f)
Reset the EOI flag.
Definition: cbm.c:1180
cbm_cable_type_e
Definition: opencbm.h:132
EXTERN int CBMAPIDECL cbm_tap_wait_for_play_sense(CBM_FILE f, int *Status)
TAPE: Wait for sense.
Definition: cbm.c:2145
EXTERN char CBMAPIDECL cbm_petscii2ascii_c(char character)
Convert a PETSCII character to ASCII.
Definition: petscii.c:64
EXTERN int CBMAPIDECL cbm_unlisten(CBM_FILE f)
Send an UNLISTEN on the IEC serial bus.
Definition: cbm.c:1100
BOOLEAN vdd_install_iohook(CBM_FILE HandleDevice)
Install the I/O hook.
Definition: execute.c:1285
EXTERN int CBMAPIDECL cbm_parallel_burst_write_track(CBM_FILE f, unsigned char *buffer, unsigned int length)
PARBURST: Write a complete track.
Definition: cbm.c:1817
EXTERN int CBMAPIDECL cbm_tap_start_write(CBM_FILE f, unsigned char *Buffer, unsigned int Length, int *Status, int *BytesWritten)
TAPE: Start write.
Definition: cbm.c:2289
EXTERN unsigned char CBMAPIDECL cbm_srq_burst_read(CBM_FILE f)
PARBURST: Read from the parallel port.
Definition: cbm.c:1847
EXTERN void CBMAPIDECL cbm_parallel_burst_write(CBM_FILE f, unsigned char c)
PARBURST: Write to the parallel port.
Definition: cbm.c:1665
EXTERN int CBMAPIDECL cbm_iec_dbg_write(CBM_FILE HandleDevice, unsigned char Value)
Write a byte to the parallel port output register.
Definition: cbm.c:2528
EXTERN int CBMAPIDECL cbm_srq_burst_write_track(CBM_FILE f, unsigned char *buffer, unsigned int length)
PARBURST: Write a complete track.
Definition: cbm.c:1995
EXTERN void CBMAPIDECL cbm_iec_release(CBM_FILE f, int line)
Deactivate a line on the IEC serial bus.
Definition: cbm.c:1372
EXTERN int CBMAPIDECL cbm_tap_get_sense(CBM_FILE f, int *Status)
TAPE: Get tape sense.
Definition: cbm.c:2085
EXTERN int CBMAPIDECL cbm_upload(CBM_FILE f, unsigned char dev, int adr, const void *prog, size_t size)
Upload a program into a floppy's drive memory.
Definition: upload.c:133
EXTERN char CBMAPIDECL cbm_ascii2petscii_c(char character)
Convert an ASCII character to PETSCII.
Definition: petscii.c:105
EXTERN int CBMAPIDECL cbm_driver_open(CBM_FILE *f, int port)
Opens the driver.
Definition: cbm.c:740
EXTERN int CBMAPIDECL cbm_raw_write(CBM_FILE f, const void *buf, size_t size)
Write data to the IEC serial bus.
Definition: cbm.c:870
EXTERN void CBMAPIDECL cbm_unlock(CBM_FILE f)
Unlock the parallel port for the driver.
Definition: cbm.c:832
EXTERN void CBMAPIDECL cbm_lock(CBM_FILE f)
Lock the parallel port for the driver.
Definition: cbm.c:804
EXTERN int CBMAPIDECL cbm_iec_wait(CBM_FILE f, int line, int state)
Wait for a line to have a specific state.
Definition: cbm.c:1448