1 #include "../ctlr/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 #if defined(unix) 111 /* 112 * Block until the oia or ps is modified. 113 */ 114 115 int 116 api_ps_or_oia_modified() 117 { 118 union REGS regs; 119 struct SREGS sregs; 120 121 if (api_issue_regs(PS_OR_OIA_MODIFIED, 0, 0, 0, 0, 0, 0, 0, ®s, &sregs) 122 == -1) { 123 return -1; 124 } else { 125 return 0; 126 } 127 } 128 #endif /* defined(unix) */ 129 130 /* 131 * Session Information Services 132 */ 133 134 api_query_session_id(parms) 135 QuerySessionIdParms *parms; 136 { 137 if (api_issue(0x09, QUERY_SESSION_ID, 0x80, 0x20, 0, 138 gate_sessmgr, (char *)parms, sizeof *parms) == -1) { 139 api_fcn_errno = 0; 140 api_fcn_fcn_id = 0; 141 return -1; 142 } else if (parms->rc == 0) { 143 return 0; 144 } else { 145 api_fcn_errno = parms->rc; 146 api_fcn_fcn_id = parms->function_id; 147 return -1; 148 } 149 } 150 151 152 api_query_session_parameters(parms) 153 QuerySessionParametersParms *parms; 154 { 155 if (api_issue(0x09, QUERY_SESSION_PARAMETERS, 0x80, 0x20, 0, 156 gate_sessmgr, (char *)parms, sizeof *parms) == -1) { 157 api_fcn_errno = 0; 158 api_fcn_fcn_id = 0; 159 return -1; 160 } else if (parms->rc == 0) { 161 return 0; 162 } else { 163 api_fcn_errno = parms->rc; 164 api_fcn_fcn_id = parms->function_id; 165 return -1; 166 } 167 } 168 169 api_query_session_cursor(parms) 170 QuerySessionCursorParms *parms; 171 { 172 if (api_issue(0x09, QUERY_SESSION_CURSOR, 0x80, 0x20, 0xff, 173 gate_sessmgr, (char *)parms, sizeof *parms) == -1) { 174 api_fcn_errno = 0; 175 api_fcn_fcn_id = 0; 176 return -1; 177 } else if (parms->rc == 0) { 178 return 0; 179 } else { 180 api_fcn_errno = parms->rc; 181 api_fcn_fcn_id = parms->function_id; 182 return -1; 183 } 184 } 185 186 /* 187 * Keyboard Services 188 */ 189 190 api_connect_to_keyboard(parms) 191 ConnectToKeyboardParms *parms; 192 { 193 if (api_issue(0x09, CONNECT_TO_KEYBOARD, 0x80, 0x20, 0, 194 gate_keyboard, (char *)parms, sizeof *parms) == -1) { 195 api_fcn_errno = 0; 196 api_fcn_fcn_id = 0; 197 return -1; 198 } else if (parms->rc == 0) { 199 return 0; 200 } else { 201 api_fcn_errno = parms->rc; 202 api_fcn_fcn_id = parms->function_id; 203 return -1; 204 } 205 } 206 207 208 api_disconnect_from_keyboard(parms) 209 DisconnectFromKeyboardParms *parms; 210 { 211 if (api_issue(0x09, DISCONNECT_FROM_KEYBOARD, 0x80, 0x20, 0, 212 gate_keyboard, (char *)parms, sizeof *parms) == -1) { 213 api_fcn_errno = 0; 214 api_fcn_fcn_id = 0; 215 return -1; 216 } else if (parms->rc == 0) { 217 return 0; 218 } else { 219 api_fcn_errno = parms->rc; 220 api_fcn_fcn_id = parms->function_id; 221 return -1; 222 } 223 } 224 225 226 api_write_keystroke(parms) 227 WriteKeystrokeParms *parms; 228 { 229 if (api_issue(0x09, WRITE_KEYSTROKE, 0x80, 0x20, 0, 230 gate_keyboard, (char *)parms, sizeof *parms) == -1) { 231 api_fcn_errno = 0; 232 api_fcn_fcn_id = 0; 233 return -1; 234 } else if (parms->rc == 0) { 235 return 0; 236 } else { 237 api_fcn_errno = parms->rc; 238 api_fcn_fcn_id = parms->function_id; 239 return -1; 240 } 241 } 242 243 244 api_disable_input(parms) 245 DisableInputParms *parms; 246 { 247 if (api_issue(0x09, DISABLE_INPUT, 0x80, 0x20, 0, 248 gate_keyboard, (char *)parms, sizeof *parms) == -1) { 249 api_fcn_errno = 0; 250 api_fcn_fcn_id = 0; 251 return -1; 252 } else if (parms->rc == 0) { 253 return 0; 254 } else { 255 api_fcn_errno = parms->rc; 256 api_fcn_fcn_id = parms->function_id; 257 return -1; 258 } 259 } 260 261 api_enable_input(parms) 262 EnableInputParms *parms; 263 { 264 if (api_issue(0x09, ENABLE_INPUT, 0x80, 0x20, 0, 265 gate_keyboard, (char *)parms, sizeof *parms) == -1) { 266 api_fcn_errno = 0; 267 api_fcn_fcn_id = 0; 268 return -1; 269 } else if (parms->rc == 0) { 270 return 0; 271 } else { 272 api_fcn_errno = parms->rc; 273 api_fcn_fcn_id = parms->function_id; 274 return -1; 275 } 276 } 277 278 /* 279 * Copy Services 280 */ 281 282 api_copy_string(parms) 283 CopyStringParms *parms; 284 { 285 if (api_issue(0x09, COPY_STRING, 0x80, 0x20, 0xff, 286 gate_copy, (char *)parms, sizeof *parms) == -1) { 287 api_fcn_errno = 0; 288 api_fcn_fcn_id = 0; 289 return -1; 290 } else if (parms->rc == 0) { 291 return 0; 292 } else { 293 api_fcn_errno = parms->rc; 294 api_fcn_fcn_id = parms->function_id; 295 return -1; 296 } 297 } 298 299 /* 300 * Operator Information Area Services 301 */ 302 303 api_read_oia_group(parms) 304 ReadOiaGroupParms *parms; 305 { 306 if (api_issue(0x09, READ_OIA_GROUP, 0x80, 0x20, 0xff, 307 gate_oiam, (char *)parms, sizeof *parms) == -1) { 308 api_fcn_errno = 0; 309 api_fcn_fcn_id = 0; 310 return -1; 311 } else if (parms->rc == 0) { 312 return 0; 313 } else { 314 api_fcn_errno = parms->rc; 315 api_fcn_fcn_id = parms->function_id; 316 return -1; 317 } 318 } 319 320 /* 321 * The "we are done" routine. This gets called last. 322 */ 323 324 api_finish() 325 { 326 #if defined(unix) 327 if (api_close_api() == -1) { 328 return -1; 329 } else { 330 return 0; 331 } 332 #endif /* defined(unix) */ 333 } 334 335 336 /* 337 * The initialization routine. Be sure to call this first. 338 */ 339 340 api_init() 341 { 342 union REGS regs; 343 struct SREGS sregs; 344 345 #if defined(MSDOS) 346 regs.h.ah = 0x35; 347 regs.h.al = API_INTERRUPT_NUMBER; 348 intdosx(®s, ®s, &sregs); 349 350 if ((regs.x.bx == 0) && (sregs.es == 0)) { 351 return 0; /* Interrupt not being handled */ 352 } 353 #endif /* defined(MSDOS) */ 354 #if defined(unix) 355 if (api_open_api(0) == -1) { 356 return 0; 357 } 358 #endif /* defined(unix) */ 359 360 gate_sessmgr = api_name_resolve("SESSMGR"); 361 gate_keyboard = api_name_resolve("KEYBOARD"); 362 gate_copy = api_name_resolve("COPY"); 363 gate_oiam = api_name_resolve("OIAM"); 364 365 if ((gate_sessmgr == gate_keyboard) || 366 (gate_sessmgr == gate_copy) || 367 (gate_sessmgr == gate_oiam) || 368 (gate_keyboard == gate_copy) || 369 (gate_keyboard == gate_oiam) || 370 (gate_copy == gate_oiam)) { 371 return 0; /* Interrupt doesn't seem correct */ 372 } 373 return 1; 374 } 375