1 #include "../api/api.h" 2 3 #include "apilib.h" 4 5 int 6 api_sup_errno = 0, /* Supervisor error number */ 7 api_sup_fcn_id = 0, /* Supervisor function id (0x12) */ 8 api_fcn_errno = 0, /* Function error number */ 9 api_fcn_fcn_id = 0; /* Function ID (0x6b, etc.) */ 10 11 static int 12 gate_sessmgr = 0, 13 gate_keyboard = 0, 14 gate_copy = 0, 15 gate_oiam = 0; 16 17 /* 18 * Issue an API request, with reg structures supplied by the caller. 19 * 20 * Only certain routines need this (supervisor services come to mind). 21 */ 22 23 static int 24 api_issue_regs(ah, al, bh, bl, cx, dx, parms, length, regs, sregs) 25 int ah, al, bh, bl, cx, dx; 26 char *parms; 27 int length; 28 union REGS *regs; 29 struct SREGS *sregs; 30 { 31 char far *ourseg = parms; 32 33 regs->h.ah = ah; 34 regs->h.al = al; 35 regs->h.bh = bh; 36 regs->h.bl = bl; 37 regs->x.cx = cx; 38 regs->x.dx = dx; 39 sregs->es = (int) FP_SEG(ourseg); 40 regs->x.di = (int) FP_OFF(ourseg); 41 42 #if defined(MSDOS) 43 int86x(API_INTERRUPT_NUMBER, regs, regs, sregs); 44 #endif /* defined(MSDOS) */ 45 #if defined(unix) 46 api_exch_api(regs, sregs, parms, length); 47 #endif /* defined(unix) */ 48 49 if (regs->h.cl != 0) { 50 api_sup_errno = regs->h.cl; 51 return -1; 52 } else { 53 return 0; 54 } 55 } 56 57 58 /* 59 * Issue an API request without requiring caller to supply 60 * registers. Most routines use this. 61 */ 62 63 static int 64 api_issue(ah, al, bh, bl, cx, dx, parms, length) 65 int 66 ah, 67 al, 68 bh, 69 bl, 70 cx, 71 dx; 72 char *parms; 73 int length; /* Length of parms */ 74 { 75 union REGS regs; 76 struct SREGS sregs; 77 78 return api_issue_regs(ah, al, bh, bl, cx, dx, parms, length, ®s, &sregs); 79 } 80 81 /* 82 * Supervisor Services 83 */ 84 85 int 86 api_name_resolve(name) 87 char *name; 88 { 89 NameResolveParms parms; 90 int i; 91 union REGS regs; 92 struct SREGS sregs; 93 94 for (i = 0; i < sizeof parms.gate_name; i++) { 95 if (*name) { 96 parms.gate_name[i] = *name++; 97 } else { 98 parms.gate_name[i] = ' '; 99 } 100 } 101 102 if (api_issue_regs(NAME_RESOLUTION, 0, 0, 0, 0, 0, &parms, sizeof parms, ®s, &sregs) 103 == -1) { 104 return -1; 105 } else { 106 return regs.x.dx; 107 } 108 } 109 110 /* 111 * Session Information Services 112 */ 113 114 api_query_session_id(parms) 115 QuerySessionIdParms *parms; 116 { 117 if (api_issue(0x09, QUERY_SESSION_ID, 0x80, 0x20, 0, 118 gate_sessmgr, (char *)parms, sizeof *parms) == -1) { 119 api_fcn_errno = 0; 120 api_fcn_fcn_id = 0; 121 return -1; 122 } else if (parms->rc == 0) { 123 return 0; 124 } else { 125 api_fcn_errno = parms->rc; 126 api_fcn_fcn_id = parms->function_id; 127 return -1; 128 } 129 } 130 131 132 api_query_session_parameters(parms) 133 QuerySessionParametersParms *parms; 134 { 135 if (api_issue(0x09, QUERY_SESSION_PARAMETERS, 0x80, 0x20, 0, 136 gate_sessmgr, (char *)parms, sizeof *parms) == -1) { 137 api_fcn_errno = 0; 138 api_fcn_fcn_id = 0; 139 return -1; 140 } else if (parms->rc == 0) { 141 return 0; 142 } else { 143 api_fcn_errno = parms->rc; 144 api_fcn_fcn_id = parms->function_id; 145 return -1; 146 } 147 } 148 149 api_query_session_cursor(parms) 150 QuerySessionCursorParms *parms; 151 { 152 if (api_issue(0x09, QUERY_SESSION_CURSOR, 0x80, 0x20, 0xff, 153 gate_sessmgr, (char *)parms, sizeof *parms) == -1) { 154 api_fcn_errno = 0; 155 api_fcn_fcn_id = 0; 156 return -1; 157 } else if (parms->rc == 0) { 158 return 0; 159 } else { 160 api_fcn_errno = parms->rc; 161 api_fcn_fcn_id = parms->function_id; 162 return -1; 163 } 164 } 165 166 /* 167 * Keyboard Services 168 */ 169 170 api_connect_to_keyboard(parms) 171 ConnectToKeyboardParms *parms; 172 { 173 if (api_issue(0x09, CONNECT_TO_KEYBOARD, 0x80, 0x20, 0, 174 gate_keyboard, (char *)parms, sizeof *parms) == -1) { 175 api_fcn_errno = 0; 176 api_fcn_fcn_id = 0; 177 return -1; 178 } else if (parms->rc == 0) { 179 return 0; 180 } else { 181 api_fcn_errno = parms->rc; 182 api_fcn_fcn_id = parms->function_id; 183 return -1; 184 } 185 } 186 187 188 api_disconnect_from_keyboard(parms) 189 DisconnectFromKeyboardParms *parms; 190 { 191 if (api_issue(0x09, DISCONNECT_FROM_KEYBOARD, 0x80, 0x20, 0, 192 gate_keyboard, (char *)parms, sizeof *parms) == -1) { 193 api_fcn_errno = 0; 194 api_fcn_fcn_id = 0; 195 return -1; 196 } else if (parms->rc == 0) { 197 return 0; 198 } else { 199 api_fcn_errno = parms->rc; 200 api_fcn_fcn_id = parms->function_id; 201 return -1; 202 } 203 } 204 205 206 api_write_keystroke(parms) 207 WriteKeystrokeParms *parms; 208 { 209 if (api_issue(0x09, WRITE_KEYSTROKE, 0x80, 0x20, 0, 210 gate_keyboard, (char *)parms, sizeof *parms) == -1) { 211 api_fcn_errno = 0; 212 api_fcn_fcn_id = 0; 213 return -1; 214 } else if (parms->rc == 0) { 215 return 0; 216 } else { 217 api_fcn_errno = parms->rc; 218 api_fcn_fcn_id = parms->function_id; 219 return -1; 220 } 221 } 222 223 224 api_disable_input(parms) 225 DisableInputParms *parms; 226 { 227 if (api_issue(0x09, DISABLE_INPUT, 0x80, 0x20, 0, 228 gate_keyboard, (char *)parms, sizeof *parms) == -1) { 229 api_fcn_errno = 0; 230 api_fcn_fcn_id = 0; 231 return -1; 232 } else if (parms->rc == 0) { 233 return 0; 234 } else { 235 api_fcn_errno = parms->rc; 236 api_fcn_fcn_id = parms->function_id; 237 return -1; 238 } 239 } 240 241 api_enable_input(parms) 242 EnableInputParms *parms; 243 { 244 if (api_issue(0x09, ENABLE_INPUT, 0x80, 0x20, 0, 245 gate_keyboard, (char *)parms, sizeof *parms) == -1) { 246 api_fcn_errno = 0; 247 api_fcn_fcn_id = 0; 248 return -1; 249 } else if (parms->rc == 0) { 250 return 0; 251 } else { 252 api_fcn_errno = parms->rc; 253 api_fcn_fcn_id = parms->function_id; 254 return -1; 255 } 256 } 257 258 /* 259 * Copy Services 260 */ 261 262 api_copy_string(parms) 263 CopyStringParms *parms; 264 { 265 if (api_issue(0x09, COPY_STRING, 0x80, 0x20, 0xff, 266 gate_copy, (char *)parms, sizeof *parms) == -1) { 267 api_fcn_errno = 0; 268 api_fcn_fcn_id = 0; 269 return -1; 270 } else if (parms->rc == 0) { 271 return 0; 272 } else { 273 api_fcn_errno = parms->rc; 274 api_fcn_fcn_id = parms->function_id; 275 return -1; 276 } 277 } 278 279 /* 280 * Operator Information Area Services 281 */ 282 283 api_read_oia_group(parms) 284 ReadOiaGroupParms *parms; 285 { 286 if (api_issue(0x09, READ_OIA_GROUP, 0x80, 0x20, 0xff, 287 gate_oiam, (char *)parms, sizeof *parms) == -1) { 288 api_fcn_errno = 0; 289 api_fcn_fcn_id = 0; 290 return -1; 291 } else if (parms->rc == 0) { 292 return 0; 293 } else { 294 api_fcn_errno = parms->rc; 295 api_fcn_fcn_id = parms->function_id; 296 return -1; 297 } 298 } 299 300 /* 301 * The "we are done" routine. This gets called last. 302 */ 303 304 api_finish() 305 { 306 #if defined(unix) 307 if (api_close_api() == -1) { 308 return -1; 309 } else { 310 return 0; 311 } 312 #endif /* defined(unix) */ 313 } 314 315 316 /* 317 * The initialization routine. Be sure to call this first. 318 */ 319 320 api_init() 321 { 322 union REGS regs; 323 struct SREGS sregs; 324 325 #if defined(MSDOS) 326 regs.h.ah = 0x35; 327 regs.h.al = API_INTERRUPT_NUMBER; 328 intdosx(®s, ®s, &sregs); 329 330 if ((regs.x.bx == 0) && (sregs.es == 0)) { 331 return 0; /* Interrupt not being handled */ 332 } 333 #endif defined(MSDOS) 334 #if defined(unix) 335 if (api_open_api(0) == -1) { 336 return 0; 337 } 338 #endif /* defined(unix) */ 339 340 gate_sessmgr = api_name_resolve("SESSMGR"); 341 gate_keyboard = api_name_resolve("KEYBOARD"); 342 gate_copy = api_name_resolve("COPY"); 343 gate_oiam = api_name_resolve("OIAM"); 344 345 if ((gate_sessmgr == gate_keyboard) || 346 (gate_sessmgr == gate_copy) || 347 (gate_sessmgr == gate_oiam) || 348 (gate_keyboard == gate_copy) || 349 (gate_keyboard == gate_oiam) || 350 (gate_copy == gate_oiam)) { 351 return 0; /* Interrupt doesn't seem correct */ 352 } 353 return 1; 354 } 355