OpenCBM
vdd.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 2004 Spiro Trikaliotis
8 */
9 
18 // #define UNICODE 1
19 
20 #include <windows.h>
21 #include <vddsvc.h>
22 
23 #include <opencbm.h>
24 
26 #define DBG_USERMODE
27 
29 #define DBG_DLL
30 
32 #define DBG_PROGNAME "OPENCBMVDD.DLL"
33 
35 #define DBG_IS_DEBUG_C
36 
37 #include "debug.h"
38 
39 #include "vdd.h"
40 
41 #include <stdlib.h>
42 
43 
45 #undef EXTERN
46 #define EXTERN __declspec(dllexport)
47 
48 EXTERN BOOL VDDInitialize(IN HANDLE Module, IN DWORD Reason, IN LPVOID Reserved);
49 EXTERN VOID VDDRegisterInit(VOID);
50 EXTERN VOID VDDDispatch(VOID);
51 
52 
54 HANDLE vdd_handle;
55 
63 static VOID
64 VDDBlockHandler(VOID)
65 {
66  FUNC_ENTER();
67 
69 
70  FUNC_LEAVE();
71 }
72 
93 BOOL
94 VDDInitialize(IN HANDLE Module, IN DWORD Reason, IN LPVOID Reserved)
95 {
96  FUNC_ENTER();
97 
98  DBG_PRINT((DBG_PREFIX "OpencbmVDD.Entry: " __DATE__ " " __TIME__));
99 
100  switch (Reason)
101  {
102  case DLL_PROCESS_ATTACH:
103  vdd_handle = Module;
104  VDDInstallUserHook(vdd_handle, NULL, NULL, VDDBlockHandler, NULL);
105  break;
106 
107  case DLL_PROCESS_DETACH:
108  DBG_ASSERT(vdd_handle == Module);
110  VDDDeInstallUserHook(Module);
111 
112  // make sure all CBM_FILE handles are closed
113  // whenever this VDD is unloaded
115  break;
116 
117  default:
118  break;
119 
120  }
121 
122  FUNC_LEAVE_BOOL(TRUE);
123 }
124 
131 VOID
133 {
134  FUNC_ENTER();
135 
136  setCF(0);
137 
138  FUNC_LEAVE();
139 }
140 
147 VOID
149 {
150  FUNCTIONCODE functioncode;
151  CBM_FILE cbmfile;
152  BOOLEAN error;
153 
154  FUNC_ENTER();
155 
156  functioncode = getDL();
157 
158  error = FALSE;
159 
160  // convert to BX value into a CBM_FILE
161  switch (functioncode)
162  {
163  case FC_VDD_USLEEP:
164  case FC_DRIVER_OPEN:
165  case FC_GET_DRIVER_NAME:
166  // FC_VDD_USLEEP, FC_DRIVER_OPEN and FC_GET_DRIVER_NAME are special,
167  // they do not have a BX input.
168  break;
169 
170  default:
171  cbmfile = vdd_cbmfile_get(getBX());
172 
173  if (cbmfile == INVALID_HANDLE_VALUE)
174  {
175  DBG_ERROR((DBG_PREFIX "invalid BX given: %04x", getBX()));
176  error = TRUE;
177  }
178  break;
179  }
180 
181  if (!error)
182  {
183  switch (functioncode)
184  {
185  case FC_DRIVER_OPEN: error = vdd_driver_open(); break;
186  case FC_DRIVER_CLOSE: error = vdd_driver_close(cbmfile); break;
187  case FC_LISTEN: error = vdd_listen(cbmfile); break;
188  case FC_TALK: error = vdd_talk(cbmfile); break;
189  case FC_OPEN: error = vdd_open(cbmfile); break;
190  case FC_CLOSE: error = vdd_close(cbmfile); break;
191  case FC_RAW_READ: error = vdd_raw_read(cbmfile); break;
192  case FC_RAW_WRITE: error = vdd_raw_write(cbmfile); break;
193  case FC_UNLISTEN: error = vdd_unlisten(cbmfile); break;
194  case FC_UNTALK: error = vdd_untalk(cbmfile); break;
195  case FC_GET_EOI: error = vdd_get_eoi(cbmfile); break;
196  case FC_CLEAR_EOI: error = vdd_clear_eoi(cbmfile); break;
197  case FC_RESET: error = vdd_reset(cbmfile); break;
198  case FC_PP_READ: error = vdd_pp_read(cbmfile); break;
199  case FC_PP_WRITE: error = vdd_pp_write(cbmfile); break;
200  case FC_IEC_POLL: error = vdd_iec_poll(cbmfile); break;
201  case FC_IEC_GET: error = vdd_iec_get(cbmfile); break;
202  case FC_IEC_SET: error = vdd_iec_set(cbmfile); break;
203  case FC_IEC_RELEASE: error = vdd_iec_release(cbmfile); break;
204  case FC_IEC_SETRELEASE: error = vdd_iec_setrelease(cbmfile); break;
205  case FC_IEC_WAIT: error = vdd_iec_wait(cbmfile); break;
206  case FC_UPLOAD: error = vdd_upload(cbmfile); break;
207  case FC_DEVICE_STATUS: error = vdd_device_status(cbmfile); break;
208  case FC_EXEC_COMMAND: error = vdd_exec_command(cbmfile); break;
209  case FC_IDENTIFY: error = vdd_identify(cbmfile); break;
210  case FC_IDENTIFY_XP1541: error = vdd_identify_xp1541(cbmfile); break;
211  case FC_GET_DRIVER_NAME: error = vdd_get_driver_name(); break;
212 
213  case FC_VDD_USLEEP: error = vdd_usleep(); break;
214 
215  case FC_VDD_INSTALL_IOHOOK: error = vdd_install_iohook(cbmfile); break;
216  case FC_VDD_UNINSTALL_IOHOOK: error = vdd_uninstall_iohook(cbmfile); break;
217 
218  default:
219  // this function is not implemented:
220  DBG_ERROR((DBG_PREFIX "unknown function code in DL: %02x", functioncode));
221  error = TRUE;
222  break;
223  }
224  }
225 
226  setCF(error ? 1 : 0);
227 
228  FUNC_LEAVE();
229 }
BOOLEAN vdd_listen(CBM_FILE HandleDevice)
Send a LISTEN on the IEC serial bus.
Definition: execute.c:329
#define EXTERN
Definition: vdd.c:46
Definition: vdd.h:47
BOOLEAN vdd_device_status(CBM_FILE HandleDevice)
Read the drive status from a floppy.
Definition: execute.c:924
BOOLEAN vdd_get_driver_name(VOID)
Get the name of the driver for a specific parallel port.
Definition: execute.c:220
Define makros for debugging purposes.
BOOLEAN vdd_identify(CBM_FILE HandleDevice)
Identify the connected floppy drive.
Definition: execute.c:995
Definition: vdd.h:29
VOID vdd_cbmfile_closeall(VOID)
@@@
Definition: cbmfile.c:143
BOOLEAN vdd_pp_write(CBM_FILE HandleDevice)
Write a byte to a XP1541/XP1571 cable.
Definition: execute.c:643
Definition: vdd.h:36
BOOLEAN vdd_iec_wait(CBM_FILE HandleDevice)
Wait for a line to have a specific state.
Definition: execute.c:804
EXTERN VOID VDDDispatch(VOID)
RegisterModule processing.
Definition: vdd.c:148
BOOLEAN vdd_iec_get(CBM_FILE HandleDevice)
Get the (logical) state of a line on the IEC serial bus.
Definition: execute.c:835
BOOLEAN vdd_iec_poll(CBM_FILE HandleDevice)
Read status of all bus lines.
Definition: execute.c:674
BOOLEAN vdd_iec_set(CBM_FILE HandleDevice)
Activate a line on the IEC serial bus.
Definition: execute.c:703
Function prototypes for the VDD.
BOOLEAN vdd_clear_eoi(CBM_FILE HandleDevice)
Reset the EOI flag.
Definition: execute.c:545
Definition: vdd.h:39
#define FUNC_LEAVE()
Definition: debug.h:349
BOOLEAN vdd_iec_release(CBM_FILE HandleDevice)
Deactivate a line on the IEC serial bus.
Definition: execute.c:731
BOOLEAN vdd_open(CBM_FILE HandleDevice)
Open a file on the IEC serial bus.
Definition: execute.c:400
Definition: vdd.h:43
EXTERN BOOL VDDInitialize(IN HANDLE Module, IN DWORD Reason, IN LPVOID Reserved)
VDD initialization und unloading.
Definition: vdd.c:94
#define CBM_FILE
Definition: opencbm.h:87
#define DBG_ASSERT(_xxx)
Definition: debug.h:401
#define FUNC_LEAVE_BOOL(_xxx)
Definition: debug.h:354
BOOLEAN vdd_close(CBM_FILE HandleDevice)
Close a file on the IEC serial bus.
Definition: execute.c:429
BOOLEAN vdd_exec_command(CBM_FILE HandleDevice)
Executes a command in the floppy drive.
Definition: execute.c:957
#define DBG_ERROR(_xxx)
Definition: debug.h:397
BOOLEAN vdd_raw_write(CBM_FILE HandleDevice)
Write data to the IEC serial bus.
Definition: execute.c:266
Definition: vdd.h:32
BOOLEAN vdd_usleep(VOID)
Sleep some microseconds.
Definition: execute.c:1447
BOOLEAN vdd_upload(CBM_FILE HandleDevice)
Upload a program into a floppy's drive memory.
Definition: execute.c:881
BOOLEAN vdd_talk(CBM_FILE HandleDevice)
Send a TALK on the IEC serial bus.
Definition: execute.c:362
Definition: vdd.h:30
BOOLEAN vdd_get_eoi(CBM_FILE HandleDevice)
Get EOI flag after bus read.
Definition: execute.c:520
Definition: vdd.h:37
Definition: vdd.h:44
BOOLEAN vdd_iec_setrelease(CBM_FILE HandleDevice)
Activate and deactive a line on the IEC serial bus.
Definition: execute.c:768
BOOLEAN vdd_raw_read(CBM_FILE HandleDevice)
Read data from the IEC serial bus.
Definition: execute.c:298
#define FUNC_ENTER()
Definition: debug.h:347
EXTERN VOID VDDRegisterInit(VOID)
RegisterModule processing.
Definition: vdd.c:132
BOOLEAN vdd_uninstall_iohook(CBM_FILE HandleDevice)
Uninstall the I/O hook.
Definition: execute.c:1422
Definition: vdd.h:40
USHORT vdd_uninstall_iohook_internal(VOID)
Uninstall the I/O hook.
Definition: execute.c:1383
#define DBG_PREFIX
Definition: debug.h:320
DLL interface for accessing the driver.
BOOLEAN vdd_driver_close(CBM_FILE HandleDevice)
Closes the driver.
Definition: execute.c:186
BOOLEAN vdd_identify_xp1541(CBM_FILE HandleDevice)
Identify the cable connected to a specific floppy drive.
Definition: execute.c:1041
BOOLEAN vdd_pp_read(CBM_FILE HandleDevice)
Read a byte from a XP1541/XP1571 cable.
Definition: execute.c:612
BOOLEAN vdd_install_iohook(CBM_FILE HandleDevice)
Install the I/O hook.
Definition: execute.c:1285
BOOLEAN vdd_unlisten(CBM_FILE HandleDevice)
Send an UNLISTEN on the IEC serial bus.
Definition: execute.c:459
BOOLEAN vdd_untalk(CBM_FILE HandleDevice)
Send an UNTALK on the IEC serial bus.
Definition: execute.c:489
Definition: vdd.h:31
CBM_FILE vdd_cbmfile_get(WORD a)
@@@
Definition: cbmfile.c:62
BOOLEAN vdd_reset(CBM_FILE HandleDevice)
RESET all devices.
Definition: execute.c:576
HANDLE vdd_handle
Definition: vdd.c:54
BOOLEAN vdd_driver_open(VOID)
Opens the driver.
Definition: execute.c:141
#define DBG_PRINT(_xxx)
Definition: debug.h:403
FUNCTIONCODE
Definition: vdd.h:24