summaryrefslogtreecommitdiff
path: root/reference/C/CONTRIB/SNIP/x00api.c
blob: 927ed0470bd3d8191746f81af643f8a456b4b24b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/*
 *   X00API.C: X00 FOSSIL driver
 *   
 *   Created by R.F. Pels.
 *   modified by Bob Stout
 *   Placed in the public domain by R.F. Pels.
 */

#include "x00api.h"
#include <dos.h>

static union  REGS  x00regs;
static struct SREGS x00sregs;
int                 x00error = 0;

#if __cplusplus
 extern "C" {
#endif

#ifdef __TURBOC__
 #define PEEK(s,o) peek(s,o)
#else /* MSC or ZTC */
 #define PEEK(s,o) *((unsigned _far *)(MK_FP((s),(o))))
#endif

#ifndef MK_FP
 #define MK_FP(seg,offset) \
        ((void _far *)(((unsigned long)(seg)<<16) | (unsigned)(offset)))
#endif

unsigned int  x00_detect(void)
{
        unsigned int segofx00;
        unsigned int ofsofx00;
        
        /* Peek in interrupt vector table for start of FOSSIL */

        ofsofx00 = PEEK(0, X00_VECTOR * 4);
        segofx00 = PEEK(0, (X00_VECTOR * 4) + 2);
        
        /* Peek in start of FOSSIL + X00_IDOFFSET */

        return (PEEK(segofx00, ofsofx00 + X00_IDOFFSET));
}

FOSSILSTATUS  x00_set(unsigned char set, PORT port)
{
        FOSSILSTATUS retval;
        
        x00regs.x.ax = SET_BAUDRATE | set;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
        retval.statusword = x00regs.x.ax;
        return retval;
}

FOSSILSTATUS  x00_tx_char(unsigned char c, PORT port)
{
        FOSSILSTATUS retval;
        
        x00regs.x.ax = TX_CHAR | c;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
        retval.statusword = x00regs.x.ax;
        return retval;
}

unsigned char  x00_rx_char(PORT port)
{
        x00regs.x.ax = RX_CHAR;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
        return (unsigned char)(x00regs.x.ax & 0xff);
}

FOSSILSTATUS  x00_status(PORT port)
{
        FOSSILSTATUS retval;
        
        x00regs.x.ax = STATUS;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
        retval.statusword = x00regs.x.ax;
        return retval;
}

FOSSILINIT    x00_init(PORT port, unsigned char far *ctlc_flagbyte)
{
        FOSSILINIT retval;
        
        x00regs.x.ax = INITIALIZE;
        if (ctlc_flagbyte != (unsigned char far *)0)
        {
                x00regs.x.dx = 0x00ff;
                x00regs.x.bx = 0x4F50;
                segread(&x00sregs);
                x00sregs.es  = FP_SEG(ctlc_flagbyte);
                x00regs.x.cx = FP_OFF(ctlc_flagbyte);
        }
        else
        {
                x00regs.x.bx = 0x0000; /* in any case _NOT_ 0x4f50 */
                x00regs.x.dx = port;
        }
        int86x(X00_VECTOR, &x00regs, &x00regs, &x00sregs);
        retval.result       = x00regs.x.ax;
        retval.max_function = (unsigned char)(x00regs.x.bx & 0xff);
        retval.revision     = (unsigned char)(x00regs.x.bx >> 8);
        return retval;
}

void          x00_deinit(PORT port)
{
        x00regs.x.ax = DEINITIALIZE;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
}

unsigned int  x00_raise_dtr(PORT port)
{
        unsigned int retval;
        
        x00regs.x.ax = RAISE_DTR;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
        if ((x00regs.x.ax & 0x0001) == 1)
        {
                retval = X00_DTR_HIGH;
        }
        else    retval = X00_DTR_LOW;
        return retval;
}

unsigned int  x00_lower_dtr(PORT port)
{
        unsigned int retval;
        
        x00regs.x.ax = LOWER_DTR;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
        if ((x00regs.x.ax & 0x0001) == 1)
        {
                retval = X00_DTR_HIGH;
        }
        else    retval = X00_DTR_LOW;
        return retval;
}

FOSSILSYSINFO x00_sysinfo(void)
{
        FOSSILSYSINFO retval;
        
        x00regs.x.ax = GET_SYS_INFO;
        int86(X00_VECTOR, &x00regs, &x00regs);
        retval.tick_number        = (unsigned char)(x00regs.x.ax & 0xff);
        retval.ticks_per_second   = (unsigned char)(x00regs.x.ax >> 8);
        retval.approx_ms_per_tick = x00regs.x.dx;
        return retval;
}

void          x00_flush_output(PORT port)
{
        x00regs.x.ax = FLUSH_OUTPUT;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
}

void          x00_purge_output(PORT port)
{
        x00regs.x.ax = PURGE_OUTPUT;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
}

void          x00_purge_input(PORT port)
{
        x00regs.x.ax = PURGE_INPUT;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
}

unsigned int  x00_tx_char_nowait(unsigned char c, PORT port)
{
        unsigned int retval;
        
        x00regs.x.ax = TX_CHAR_NOWAIT | c;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
        if ((x00regs.x.ax & 0x0001) == 1)
        {
                retval = X00_OK;
        }
        else    retval = X00_CHAR_NOT_SENT;
        return retval;
}

unsigned int  x00_peek_ahead_input(PORT port)
{
        x00regs.x.ax = PEEK_AHEAD_INPUT;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
        return x00regs.x.ax;
}

unsigned int   x00_peek_ahead_kbd(void)
{
        x00regs.x.ax = PEEK_AHEAD_KBD;
        int86(X00_VECTOR, &x00regs, &x00regs);
        return x00regs.x.ax;
}

unsigned int  x00_read_kbd(void)
{
        x00regs.x.ax = READ_KBD;
        int86(X00_VECTOR, &x00regs, &x00regs);
        return x00regs.x.ax;
}

void          x00_flow_control(FOSSILFLOWCTRL f, PORT port)
{
        x00regs.x.ax = FLOW_CONTROL | 0xf0 | f.flowword;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
}

unsigned int  x00_ctlc_ctlk_check(FOSSILCTLCCTLK c, PORT port)
{
        x00regs.x.ax = CTLC_CTLK_CHECK | c.checkword;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
        return x00regs.x.ax;
}

void          x00_set_cup(unsigned char row, unsigned char col)
{
        x00regs.x.ax = SET_CUP;
        x00regs.x.dx = (row << 8) | col;
        int86(X00_VECTOR, &x00regs, &x00regs);
}

void          x00_get_cup(unsigned char *row, unsigned char *col)
{
        x00regs.x.ax = GET_CUP;
        int86(X00_VECTOR, &x00regs, &x00regs);
        *col = (unsigned char)(x00regs.x.dx & 0xff);
        *row = (unsigned char)(x00regs.x.dx >> 8);
}

void          x00_write_ANSI_char(unsigned char c)
{
        x00regs.x.ax = WRITE_ANSI_CHAR | c;
        int86(X00_VECTOR, &x00regs, &x00regs);
}

void          x00_enable_watchdog(PORT port)
{
        x00regs.x.ax = ENABLE_WATCHDOG;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
}

void          x00_disable_watchdog(PORT port)
{
        x00regs.x.ax = DISABLE_WATCHDOG;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
}

void          x00_write_BIOS_char(unsigned char c)
{
        x00regs.x.ax = WRITE_BIOS_CHAR | c;
        int86(X00_VECTOR, &x00regs, &x00regs);
}

unsigned int  x00_insert_tick_func(void (far *tickfunc)())
{
        unsigned int retval;
        
        x00regs.x.ax = INSERT_TICK_FUNC;
        x00regs.x.dx = FP_OFF(tickfunc);
        segread(&x00sregs);
        x00sregs.es  = FP_SEG(tickfunc);
        int86x(X00_VECTOR, &x00regs, &x00regs, &x00sregs);
        if (x00regs.x.ax == 0x0000)
        {
                retval = X00_OK;
        }
        else    retval = X00_INS_TICK;
        return retval;
}

unsigned int  x00_delete_tick_func(void (far *tickfunc)())
{
        unsigned int retval;
        
        x00regs.x.ax = DELETE_TICK_FUNC;
        x00regs.x.dx = FP_OFF(tickfunc);
        segread(&x00sregs);
        x00sregs.es  = FP_SEG(tickfunc);
        int86x(X00_VECTOR, &x00regs, &x00regs, &x00sregs);
        if (x00regs.x.ax == 0x0000)
        {
                retval = X00_OK;
        }
        else    retval = X00_DEL_TICK;
        return retval;
}

void          x00_boot_machine(unsigned int boottype)
{
        x00regs.x.ax = BOOT_MACHINE | (boottype & 0x0001);
        int86(X00_VECTOR, &x00regs, &x00regs);
}

unsigned int  x00_read_block(unsigned int count, void far *buf, PORT port)
{
        x00regs.x.ax = READ_BLOCK;
        x00regs.x.cx = count;
        x00regs.x.dx = port;
        segread(&x00sregs);
        x00sregs.es  = FP_SEG(buf);
        x00regs.x.di = FP_OFF(buf);
        int86x(X00_VECTOR, &x00regs, &x00regs, &x00sregs);
        return x00regs.x.ax;
}

unsigned int  x00_write_block(unsigned int count, void far *buf, PORT port)
{
        x00regs.x.ax = WRITE_BLOCK;
        x00regs.x.cx = count;
        x00regs.x.dx = port;
        segread(&x00sregs);
        x00sregs.es  = FP_SEG(buf);
        x00regs.x.di = FP_OFF(buf);
        int86x(X00_VECTOR, &x00regs, &x00regs, &x00sregs);
        return x00regs.x.ax;
}

void          x00_start_break_signal(PORT port)
{
        x00regs.x.ax = START_BREAK_SIGNAL;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
}

void          x00_stop_break_signal(PORT port)
{
        x00regs.x.ax = STOP_BREAK_SIGNAL;
        x00regs.x.dx = port;
        int86(X00_VECTOR, &x00regs, &x00regs);
}

unsigned int  x00_get_driverinfo(void far *buf, PORT port)
{
        x00regs.x.ax = GET_DRIVER_INFO;
        x00regs.x.cx = sizeof(FOSSILINFO);
        segread(&x00sregs);
        x00sregs.es  = FP_SEG(buf);
        x00regs.x.di = FP_OFF(buf);
        x00regs.x.dx = port;
        int86x(X00_VECTOR, &x00regs, &x00regs, &x00sregs);
        return x00regs.x.ax;
}

unsigned int  x00_install_appendage(unsigned char appcode,
                                              void (far *appfunc)())
{
        unsigned int retval;
        
        x00regs.x.ax = INSTALL_APPENDAGE | appcode;
        segread(&x00sregs);
        x00sregs.es  = FP_SEG(appfunc);
        x00regs.x.dx = FP_OFF(appfunc);
        int86x(X00_VECTOR, &x00regs, &x00regs, &x00sregs);
        if (x00regs.x.ax == X00_PRESENT)
        {
                if ((x00regs.x.bx & 0xff00) == 1)
                {
                        retval = X00_OK;
                }
                else    retval = X00_INS_APP;
        }
        else    retval = X00_NOT_HERE;
        return retval;
}

unsigned int  x00_remove_appendage(unsigned char appcode,
                                             void (far *appfunc)())
{
        unsigned int retval;
        
        x00regs.x.ax = REMOVE_APPENDAGE | appcode;
        segread(&x00sregs);
        x00sregs.es  = FP_SEG(appfunc);
        x00regs.x.dx = FP_OFF(appfunc);
        int86x(X00_VECTOR, &x00regs, &x00regs, &x00sregs);
        if (x00regs.x.ax == X00_PRESENT)
        {
                if ((x00regs.x.bx & 0xff00) == 1)
                {
                        retval = X00_OK;
                }
                else    retval = X00_REM_APP;
        }
        else    retval = X00_NOT_HERE;
        return retval;
}

#if __cplusplus
 }
#endif