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