OpenCBM
cbmfile.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 #include <windows.h>
19 
21 #define DBG_USERMODE
22 
24 #define DBG_PROGNAME "OPENCBMVDD.DLL"
25 
26 #include "debug.h"
27 
28 #include "vdd.h"
29 
30 #include <stdlib.h>
31 
32 
34 #define MAX_CBMFILE_VALUES 10
35 
36 static CBM_FILE CbmFile[MAX_CBMFILE_VALUES];
37 static BOOL CbmfileValuesInitialized = FALSE;
38 
39 static void
40 init_cbmfiles(void)
41 {
42  if (!CbmfileValuesInitialized)
43  {
44  int i;
45 
46  for (i = 0; i < MAX_CBMFILE_VALUES; i++)
47  {
48  CbmFile[i] = INVALID_HANDLE_VALUE;
49  }
50 
51  CbmfileValuesInitialized = TRUE;
52  }
53 }
54 
63 {
64  CBM_FILE ret;
65 
66  init_cbmfiles();
67 
68  if (a < MAX_CBMFILE_VALUES)
69  {
70  ret = CbmFile[a];
71  }
72  else
73  {
74  ret = INVALID_HANDLE_VALUE;
75  }
76 
77  return ret;
78 }
79 
86 WORD
88 {
89  WORD i;
90 
91  init_cbmfiles();
92 
93  i = 0;
94 
95  while (i < MAX_CBMFILE_VALUES && CbmFile[i] != INVALID_HANDLE_VALUE)
96  {
97  i++;
98  }
99 
100  if (i < MAX_CBMFILE_VALUES && CbmFile[i] == INVALID_HANDLE_VALUE)
101  {
102  CbmFile[i] = cbmfile;
103  }
104  else
105  {
106  i = -1;
107  }
108 
109  return i;
110 }
111 
118 CBM_FILE
120 {
121  CBM_FILE cbmfile;
122 
123  init_cbmfiles();
124 
125  cbmfile = INVALID_HANDLE_VALUE;
126 
127  if (a < MAX_CBMFILE_VALUES)
128  {
129  if (CbmFile[a] != INVALID_HANDLE_VALUE)
130  {
131  cbmfile = CbmFile[a];
132  CbmFile[a] = INVALID_HANDLE_VALUE;
133  }
134  }
135 
136  return cbmfile;
137 }
138 
142 VOID
144 {
145  int i;
146 
147  init_cbmfiles();
148 
149  for (i=0; i < MAX_CBMFILE_VALUES; i++)
150  {
151  cbm_driver_close(CbmFile[i]);
152  CbmFile[i] = INVALID_HANDLE_VALUE;
153  }
154 }
Define makros for debugging purposes.
VOID vdd_cbmfile_closeall(VOID)
@@@
Definition: cbmfile.c:143
WORD vdd_cbmfile_store(CBM_FILE cbmfile)
@@@
Definition: cbmfile.c:87
Function prototypes for the VDD.
void CBMAPIDECL cbm_driver_close(CBM_FILE HandleDevice)
Closes the driver.
Definition: cbm.c:768
#define CBM_FILE
Definition: opencbm.h:87
#define MAX_CBMFILE_VALUES
@@@
Definition: cbmfile.c:34
CBM_FILE vdd_cbmfile_delete(WORD a)
@@@
Definition: cbmfile.c:119
CBM_FILE vdd_cbmfile_get(WORD a)
@@@
Definition: cbmfile.c:62