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