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