OpenCBM
|
Shared library / DLL for accessing the driver, windows specific code. More...
#include <windows.h>
#include <windowsx.h>
#include <mmsystem.h>
#include "debug.h"
#include <winioctl.h>
#include "cbmioctl.h"
#include <stdlib.h>
#include "i_opencbm.h"
#include "archlib.h"
Go to the source code of this file.
Macros | |
#define | DBG_USERMODE |
#define | DBG_DLL |
#define | DBG_PROGNAME "OPENCBM.DLL" |
#define | DBG_IS_DEBUG_C |
#define | DLL |
mark: We are building the DLL */ | |
#define | OPENCBM_PLUGIN |
mark: We are building the DLL */ | |
Functions | |
BOOL WINAPI | DllMain (IN HANDLE Module, IN DWORD Reason, IN LPVOID Reserved) |
DLL initialization und unloading. More... | |
void CBMAPIDECL | opencbm_plugin_lock (CBM_FILE HandleDevice) |
Lock the parallel port for the driver. More... | |
void CBMAPIDECL | opencbm_plugin_unlock (CBM_FILE HandleDevice) |
Unlock the parallel port for the driver. More... | |
int CBMAPIDECL | opencbm_plugin_raw_write (CBM_FILE HandleDevice, const void *Buffer, size_t Count) |
Write data to the IEC serial bus. More... | |
int CBMAPIDECL | opencbm_plugin_raw_read (CBM_FILE HandleDevice, void *Buffer, size_t Count) |
Read data from the IEC serial bus. More... | |
int CBMAPIDECL | opencbm_plugin_listen (CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress) |
Send a LISTEN on the IEC serial bus. More... | |
int CBMAPIDECL | opencbm_plugin_talk (CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress) |
Send a TALK on the IEC serial bus. More... | |
int CBMAPIDECL | opencbm_plugin_open (CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress) |
Open a file on the IEC serial bus. More... | |
int CBMAPIDECL | opencbm_plugin_close (CBM_FILE HandleDevice, unsigned char DeviceAddress, unsigned char SecondaryAddress) |
Close a file on the IEC serial bus. More... | |
int CBMAPIDECL | opencbm_plugin_unlisten (CBM_FILE HandleDevice) |
Send an UNLISTEN on the IEC serial bus. More... | |
int CBMAPIDECL | opencbm_plugin_untalk (CBM_FILE HandleDevice) |
Send an UNTALK on the IEC serial bus. More... | |
int CBMAPIDECL | opencbm_plugin_get_eoi (CBM_FILE HandleDevice) |
Get EOI flag after bus read. More... | |
int CBMAPIDECL | opencbm_plugin_clear_eoi (CBM_FILE HandleDevice) |
Reset the EOI flag. More... | |
int CBMAPIDECL | opencbm_plugin_reset (CBM_FILE HandleDevice) |
RESET all devices. More... | |
unsigned char CBMAPIDECL | opencbm_plugin_pp_read (CBM_FILE HandleDevice) |
Read a byte from a XP1541/XP1571 cable. More... | |
void CBMAPIDECL | opencbm_plugin_pp_write (CBM_FILE HandleDevice, unsigned char Byte) |
Write a byte to a XP1541/XP1571 cable. More... | |
int CBMAPIDECL | opencbm_plugin_iec_poll (CBM_FILE HandleDevice) |
Read status of all bus lines. More... | |
void CBMAPIDECL | opencbm_plugin_iec_set (CBM_FILE HandleDevice, int Line) |
Activate a line on the IEC serial bus. More... | |
void CBMAPIDECL | opencbm_plugin_iec_release (CBM_FILE HandleDevice, int Line) |
Deactivate a line on the IEC serial bus. More... | |
void CBMAPIDECL | opencbm_plugin_iec_setrelease (CBM_FILE HandleDevice, int Set, int Release) |
Activate and deactive a line on the IEC serial bus. More... | |
int CBMAPIDECL | opencbm_plugin_iec_wait (CBM_FILE HandleDevice, int Line, int State) |
Wait for a line to have a specific state. More... | |
int CBMAPIDECL | cbm_get_debugging_buffer (CBM_FILE HandleDevice, char *buffer, size_t len) |
Output contents of the debugging buffer. More... | |
int CBMAPIDECL | opencbm_plugin_iec_dbg_read (CBM_FILE HandleDevice) |
Read a byte from the parallel port input register. More... | |
int CBMAPIDECL | opencbm_plugin_iec_dbg_write (CBM_FILE HandleDevice, unsigned char Value) |
Write a byte to the parallel port output register. More... | |
Shared library / DLL for accessing the driver, windows specific code.
Definition in file WINDOWS/iec.c.
#define DBG_DLL |
Mark: We are building the DLL
Definition at line 29 of file WINDOWS/iec.c.
#define DBG_IS_DEBUG_C |
This file is "like" debug.c, that is, define some variables
Definition at line 35 of file WINDOWS/iec.c.
#define DBG_PROGNAME "OPENCBM.DLL" |
The name of the executable
Definition at line 32 of file WINDOWS/iec.c.
#define DBG_USERMODE |
Mark: We are in user-space (for debug.h)
Definition at line 26 of file WINDOWS/iec.c.
int CBMAPIDECL cbm_get_debugging_buffer | ( | CBM_FILE | HandleDevice, |
char * | buffer, | ||
size_t | len | ||
) |
Output contents of the debugging buffer.
This function outputs the contents of the kernel-mode debugging buffer to the screen.
This function is for use of the installation routines only!
Definition at line 991 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, and FUNC_LEAVE_INT.
BOOL WINAPI DllMain | ( | IN HANDLE | Module, |
IN DWORD | Reason, | ||
IN LPVOID | Reserved | ||
) |
DLL initialization und unloading.
This function is called whenever the DLL is loaded or unloaded. It ensures that the driver is loaded to be able to call its functions.
Module | Handle of the module; this is not used. |
Reason | DLL_PROCESS_ATTACH if the DLL is loaded, DLL_PROCESS_DETACH if it is unloaded. |
Reserved | Not used. |
If this function returns FALSE, windows reports that loading the DLL was not successful. If the DLL is linked statically, the executable refuses to load with STATUS_DLL_INIT_FAILED (0xC0000142)
Definition at line 131 of file WINDOWS/iec.c.
References cbm_driver_start(), cbm_driver_stop(), cbm_get_debugging_flags(), DBG_ASSERT, DBG_ERROR, DBG_PREFIX, FUNC_ENTER, FUNC_LEAVE_BOOL, IEC_ATN, IEC_CLOCK, IEC_DATA, IEC_LINE_ATN, IEC_LINE_CLOCK, IEC_LINE_DATA, IEC_LINE_RESET, IEC_RESET, IsDriverStartedAutomatically(), WaitForIoCompletionDeinit(), and WaitForIoCompletionInit().
int CBMAPIDECL opencbm_plugin_clear_eoi | ( | CBM_FILE | HandleDevice | ) |
Reset the EOI flag.
This function resets the EOI ("End of Information") flag which might be still set after reading the IEC serial bus.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 673 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, and FUNC_LEAVE_INT.
int CBMAPIDECL opencbm_plugin_close | ( | CBM_FILE | HandleDevice, |
unsigned char | DeviceAddress, | ||
unsigned char | SecondaryAddress | ||
) |
Close a file on the IEC serial bus.
This function closes a file on the IEC serial bus.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
DeviceAddress | The address of the device on the IEC serial bus. This is known as primary address, too. |
SecondaryAddress | The secondary address for the device on the IEC serial bus. |
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 543 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, FUNC_LEAVE_INT, CBMT_IECADDRESS::PrimaryAddress, and CBMT_IECADDRESS::SecondaryAddress.
int CBMAPIDECL opencbm_plugin_get_eoi | ( | CBM_FILE | HandleDevice | ) |
Get EOI flag after bus read.
This function gets the EOI ("End of Information") flag after reading the IEC serial bus.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
If a previous read returned less than the specified number of bytes, there are two possible reasons: Either an error occurred on the IEC serial bus, or an EOI was signalled. To find out the cause, check with this function.
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 646 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, CBMT_BOOLEAN::Decision, FUNC_ENTER, and FUNC_LEAVE_INT.
int CBMAPIDECL opencbm_plugin_iec_dbg_read | ( | CBM_FILE | HandleDevice | ) |
Read a byte from the parallel port input register.
This function reads a byte from the parallel port input register. (STATUS_PORT). It is a helper function for debugging the cable (i.e., for the XCDETECT tool) only!
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
If the routine fails, the return value is -1.
This functions masks some bits off. The bits that are not masked off are defined in PARALLEL_STATUS_PORT_MASK_VALUES.
Definition at line 1026 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, FUNC_LEAVE_INT, and CBMT_IEC_DBG_VALUE::Value.
int CBMAPIDECL opencbm_plugin_iec_dbg_write | ( | CBM_FILE | HandleDevice, |
unsigned char | Value | ||
) |
Write a byte to the parallel port output register.
This function writes a byte to the parallel port output register. (CONTROL_PORT). It is a helper function for debugging the cable (i.e., for the XCDETECT tool) only!
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
Value | The value to set the control port to |
If the routine fails, it returns -1.
After this function has been called, it is NOT safe to use the parallel port again unless you close the driver (cbm_driver_close()) and open it again (cbm_driver_open())!
This functions masks some bits off. That is, the bits not in the mask are not changed at all. The bits that are not masked off are defined in PARALLEL_CONTROL_PORT_MASK_VALUES.
Definition at line 1070 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, FUNC_LEAVE_INT, and CBMT_IEC_DBG_VALUE::Value.
int CBMAPIDECL opencbm_plugin_iec_poll | ( | CBM_FILE | HandleDevice | ) |
Read status of all bus lines.
This function reads the state of all lines on the IEC serial bus.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
This function just reads the port. No handshaking is performed at all.
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 818 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, FUNC_LEAVE_INT, and CBMT_LINE::Line.
void CBMAPIDECL opencbm_plugin_iec_release | ( | CBM_FILE | HandleDevice, |
int | Line | ||
) |
Deactivate a line on the IEC serial bus.
This function deactivates (sets to 5V) a line on the IEC serial bus.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
Line | The line to be deactivated. This must be exactly one of IEC_DATA, IEC_CLOCK, IEC_ATN, or IEC_RESET. |
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 881 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, FUNC_LEAVE, and CBMT_LINE::Line.
void CBMAPIDECL opencbm_plugin_iec_set | ( | CBM_FILE | HandleDevice, |
int | Line | ||
) |
Activate a line on the IEC serial bus.
This function activates (sets to 0V) a line on the IEC serial bus.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
Line | The line to be activated. This must be exactly one of IEC_DATA, IEC_CLOCK, IEC_ATN, or IEC_RESET. |
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 849 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, FUNC_LEAVE, and CBMT_LINE::Line.
void CBMAPIDECL opencbm_plugin_iec_setrelease | ( | CBM_FILE | HandleDevice, |
int | Set, | ||
int | Release | ||
) |
Activate and deactive a line on the IEC serial bus.
This function activates (sets to 0V, L) and deactivates (set to 5V, H) lines on the IEC serial bus.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
Set | The mask of which lines should be set. This has to be a bitwise OR between the constants IEC_DATA, IEC_CLOCK, IEC_ATN, and IEC_RESET |
Release | The mask of which lines should be released. This has to be a bitwise OR between the constants IEC_DATA, IEC_CLOCK, IEC_ATN, and IEC_RESET |
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 922 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, FUNC_LEAVE, CBMT_LINESTATE::Line, and CBMT_LINESTATE::State.
int CBMAPIDECL opencbm_plugin_iec_wait | ( | CBM_FILE | HandleDevice, |
int | Line, | ||
int | State | ||
) |
Wait for a line to have a specific state.
This function waits for a line to enter a specific state on the IEC serial bus.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
Line | The line to be deactivated. This must be exactly one of IEC_DATA, IEC_CLOCK, IEC_ATN, and IEC_RESET. |
State | If zero, then wait for this line to be deactivated. If not zero, then wait for this line to be activated. |
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 963 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, FUNC_LEAVE_INT, CBMT_LINE::Line, CBMT_LINESTATE::Line, and CBMT_LINESTATE::State.
int CBMAPIDECL opencbm_plugin_listen | ( | CBM_FILE | HandleDevice, |
unsigned char | DeviceAddress, | ||
unsigned char | SecondaryAddress | ||
) |
Send a LISTEN on the IEC serial bus.
This function sends a LISTEN on the IEC serial bus. This prepares a LISTENer, so that it will wait for our bytes we will write in the future.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
DeviceAddress | The address of the device on the IEC serial bus. This is known as primary address, too. |
SecondaryAddress | The secondary address for the device on the IEC serial bus. |
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 421 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, FUNC_LEAVE_INT, CBMT_IECADDRESS::PrimaryAddress, and CBMT_IECADDRESS::SecondaryAddress.
void CBMAPIDECL opencbm_plugin_lock | ( | CBM_FILE | HandleDevice | ) |
Lock the parallel port for the driver.
This function locks the driver onto the parallel port. This way, no other program or driver can allocate the parallel port and interfere with the communication.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
If cbm_driver_open() did not succeed, it is illegal to call cbm_driver_close().
Note that it is not necessary to call this function (or cbm_unlock()) when all communication is done with the handle to opencbm open (that is, between cbm_driver_open() and cbm_driver_close(). You only need this function to pin the driver to the port even when cbm_driver_close() is to be executed (for example, because the program terminates).
Definition at line 262 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, and FUNC_LEAVE.
int CBMAPIDECL opencbm_plugin_open | ( | CBM_FILE | HandleDevice, |
unsigned char | DeviceAddress, | ||
unsigned char | SecondaryAddress | ||
) |
Open a file on the IEC serial bus.
This function opens a file on the IEC serial bus.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
DeviceAddress | The address of the device on the IEC serial bus. This is known as primary address, too. |
SecondaryAddress | The secondary address for the device on the IEC serial bus. |
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 499 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, FUNC_LEAVE_INT, CBMT_IECADDRESS::PrimaryAddress, and CBMT_IECADDRESS::SecondaryAddress.
unsigned char CBMAPIDECL opencbm_plugin_pp_read | ( | CBM_FILE | HandleDevice | ) |
Read a byte from a XP1541/XP1571 cable.
This function reads a single byte from the parallel portion of an XP1541/1571 cable.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
This function reads the current state of the port. No handshaking is performed at all.
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 748 of file WINDOWS/iec.c.
References CBMT_SINGLEBYTE::Byte, cbm_ioctl(), CBMCTRL, FUNC_ENTER, and FUNC_LEAVE_UCHAR.
void CBMAPIDECL opencbm_plugin_pp_write | ( | CBM_FILE | HandleDevice, |
unsigned char | Byte | ||
) |
Write a byte to a XP1541/XP1571 cable.
This function writes a single byte to the parallel portion of a XP1541/1571 cable.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
Byte | the byte to be output on the parallel port |
This function just writes on the port. No handshaking is performed at all.
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 783 of file WINDOWS/iec.c.
References CBMT_SINGLEBYTE::Byte, cbm_ioctl(), CBMCTRL, FUNC_ENTER, and FUNC_LEAVE.
int CBMAPIDECL opencbm_plugin_raw_read | ( | CBM_FILE | HandleDevice, |
void * | Buffer, | ||
size_t | Count | ||
) |
Read data from the IEC serial bus.
This function retrieves data after a cbm_talk().
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
Buffer | Pointer to a buffer which will hold the bytes read. |
Count | Number of bytes to be read at most. |
At most Count bytes are read.
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 370 of file WINDOWS/iec.c.
References FUNC_ENTER, FUNC_LEAVE_INT, WaitForIoCompletion(), and WaitForIoCompletionConstruct().
int CBMAPIDECL opencbm_plugin_raw_write | ( | CBM_FILE | HandleDevice, |
const void * | Buffer, | ||
size_t | Count | ||
) |
Write data to the IEC serial bus.
This function sends data after a cbm_listen().
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
Buffer | Pointer to a buffer which hold the bytes to write to the bus. |
Count | Number of bytes to be written. |
This function tries to write Count bytes. Anyway, if an error occurs, this function can stop prematurely.
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 323 of file WINDOWS/iec.c.
References FUNC_ENTER, FUNC_LEAVE_INT, WaitForIoCompletion(), and WaitForIoCompletionConstruct().
int CBMAPIDECL opencbm_plugin_reset | ( | CBM_FILE | HandleDevice | ) |
RESET all devices.
This function performs a hardware RESET of all devices on the IEC serial bus.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
Don't overuse this function! Normally, an initial RESET should be enough.
Control is returned after a delay which ensures that all devices are ready again.
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 706 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, FUNC_LEAVE_INT, and WaitForIoCompletionCancelAll().
int CBMAPIDECL opencbm_plugin_talk | ( | CBM_FILE | HandleDevice, |
unsigned char | DeviceAddress, | ||
unsigned char | SecondaryAddress | ||
) |
Send a TALK on the IEC serial bus.
This function sends a TALK on the IEC serial bus. This prepares a TALKer, so that it will prepare to send us some bytes in the future.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
DeviceAddress | The address of the device on the IEC serial bus. This is known as primary address, too. |
SecondaryAddress | The secondary address for the device on the IEC serial bus. |
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 461 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, FUNC_LEAVE_INT, CBMT_IECADDRESS::PrimaryAddress, and CBMT_IECADDRESS::SecondaryAddress.
int CBMAPIDECL opencbm_plugin_unlisten | ( | CBM_FILE | HandleDevice | ) |
Send an UNLISTEN on the IEC serial bus.
This function sends an UNLISTEN on the IEC serial bus. Other than LISTEN and TALK, an UNLISTEN is not directed to just one device, but to all devices on that IEC serial bus.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
At least on a 1541 floppy drive, an UNLISTEN also undoes a previous TALK.
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 581 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, and FUNC_LEAVE_INT.
void CBMAPIDECL opencbm_plugin_unlock | ( | CBM_FILE | HandleDevice | ) |
Unlock the parallel port for the driver.
This function unlocks the driver from the parallel port. This way, other programs and drivers can allocate the parallel port and do their own communication with whatever device they use.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
If cbm_driver_open() did not succeed, it is illegal to call cbm_driver_close().
Definition at line 289 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, and FUNC_LEAVE.
int CBMAPIDECL opencbm_plugin_untalk | ( | CBM_FILE | HandleDevice | ) |
Send an UNTALK on the IEC serial bus.
This function sends an UNTALK on the IEC serial bus. Other than LISTEN and TALK, an UNTALK is not directed to just one device, but to all devices on that IEC serial bus.
HandleDevice | A CBM_FILE which contains the file handle of the driver. |
At least on a 1541 floppy drive, an UNTALK also undoes a previous LISTEN.
If cbm_driver_open() did not succeed, it is illegal to call this function.
Definition at line 613 of file WINDOWS/iec.c.
References cbm_ioctl(), CBMCTRL, FUNC_ENTER, and FUNC_LEAVE_INT.