forked from troglobit/MicroEMACS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhp150.c
338 lines (262 loc) · 6.71 KB
/
hp150.c
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
/*
* The routines in this file provide support for HP150 screens
* and routines to access the Keyboard through KEYCODE mode.
* It compiles into nothing if not an HP150 screen device.
* added by Daniel Lawrence
*/
#define termdef 1 /* don't define "term" external */
#include <stdio.h>
#include "estruct.h"
#include "edef.h"
#if HP150
#include <dos.h>
#define NROW 24 /* Screen size. */
#define NCOL 80 /* Edit if you want to. */
#define MARGIN 8 /* size of minimim margin and */
#define SCRSIZ 64 /* scroll size for extended lines */
#define BEL 0x07 /* BEL character. */
#define ESC 0x1B /* ESC character. */
extern int openhp(); /* Forward references. */
extern int ttgetc();
extern int ttputc();
extern int ttflush();
extern int closehp();
extern int hp15move();
extern int hp15eeol();
extern int hp15eeop();
extern int hp15beep();
extern int gethpkey();
extern int hp15rev();
/* weird to ascii translation table */
char trans[][2] = {
0x24, 9, /* tab */
0x25, 13, /* ret */
0x27, 8, /* backspace */
0x30, 48, /* zero */
0x31, 49, /* one */
0x32, 50, /* two */
0x33, 51, /* three */
0x34, 52, /* four */
0x35, 53, /* five */
0x36, 54, /* six */
0x37, 55, /* seven */
0x38, 56, /* eight */
0x39, 57, /* nine */
0x50, 13, /* enter */
0x54, 27, /* break -> ESC */
0x55, 27, /* esc */
0x58, 24, /* stop -> ^X */
0x70, 45, /* N-minus */
0x71, 42, /* N-asterisk */
0x72, 43, /* N-plus */
0x73, 47, /* N-slash */
0x74, 44, /* N-comma */
0x75, 13, /* N-enter */
0x76, 9, /* N-tab */
0x77, 46 /* N-period */
};
#define NTRANS sizeof(trans) / 2
union REGS r; /* register set for bios and dos (AGIOS) calls */
int capslock = 0; /* caps lock flag */
/*
* Standard terminal interface dispatch table. Most of the fields point into
* "termio" code.
*/
TERM term = {
NROW-1,
NCOL,
MARGIN,
SCRSIZ,
openhp,
closehp,
gethpkey,
ttputc,
ttflush,
hp15move,
hp15eeol,
hp15eeop,
hp15beep,
hp15rev
};
hp15move(row, col)
{
ttputc(ESC);
ttputc('&');
ttputc('a');
hp15parm(col);
ttputc('c');
hp15parm(row);
ttputc('R');
}
hp15eeol()
{
ttputc(ESC);
ttputc('K');
}
hp15eeop()
{
ttputc(ESC);
ttputc('J');
}
hp15rev(status) /* change the reverse video status */
int status; /* TRUE = on, FALSE = off */
{
ttputc(ESC);
ttputc('&');
ttputc('d');
ttputc(status ? 'B': '@');
}
hp15beep()
{
ttputc(BEL);
ttflush();
}
hp15parm(n)
register int n;
{
register int q;
q = n/10;
if (q != 0)
hp15parm(q);
ttputc((n%10) + '0');
}
gethpkey() /* get a key from the HP keyboard while in keycode mode */
{
static int keepflag = 0; /* kept ahead char flag */
static int keepchar = 0; /* kept ehead flag */
int c;
int devid; /* device ID */
int ctype; /* type of character gotten */
int shiftb; /* state of shift keys */
int i;
/* if we are in an extended char sequence, finish it */
if (keepflag != 0) {
keepflag = 0;
return(keepchar);
}
/* grab the next 4 char sequence */
next: shiftb = ttgetc();
devid = ttgetc();
c = ttgetc();
ttgetc(); /* skip null byte */
/* make sure we are from the keyboard */
if (devid != 192)
goto next;
/* if normal ascii, return it */
if ((shiftb & 0x80) == 0) {
if (capslock && c >= 'a' && c <= 'z')
c -= 32;
return(c);
}
/* check specifically for the caps lock key */
if (c == 0x56) {
capslock = ~capslock;
goto next;
}
/* check to see if it needs translation */
for (i=0; i < NTRANS; i++)
if (trans[i][0] == c)
return((int)trans[i][1]);
/* other wise, shove it in the keep char and return the leadin code */
keepchar = c;
keepflag = 1;
return(0);
}
openhp() /* open the HP150 keyboard for input */
{
revexist = TRUE;
/* define key charectoristics with AGIOS call (0, 40) */
defkey();
/* Turn on RAW mode with MSDOS call 44h */
rawon();
/* Turn off Control-C checking MS-DOS 33h */
ckeyoff();
/* Turn on keycode mode with AGIOS call (0,43) */
keycon();
}
closehp() /* close the HP150 keyboard for input */
{
/* define key charectoristics with AGIOS call (0, 40) */
undefkey();
/* Turn off RAW mode with MSDOS call 44h */
rawoff();
/* Turn on Control-C checking MS-DOS 33h */
ckeyon();
/* Turn off keycode mode with AGIOS call (0,43) */
keycoff();
}
rawon() /* put the HP150 keyboard into RAW mode */
{
/* get the IO control info */
r.x.ax = 0x4400; /* IO ctrl get device information */
r.x.bx = 0x0001; /* File handle; 1 for console */
intdos(&r, &r); /* go fer it */
r.h.dh = 0; /* clear high byte for put */
r.h.dl |= 0x20; /* set raw bit */
/* and put it back */
r.x.ax = 0x4401; /* IO ctrl put device information */
r.x.bx = 0x0001; /* File handle; 1 for console */
intdos(&r, &r); /* go fer it */
}
rawoff() /* put the HP150 keyboard into COOKED mode */
{
/* get the IO control info */
r.x.ax = 0x4400; /* IO ctrl get device information */
r.x.bx = 0x0001; /* File handle; 1 for console */
intdos(&r, &r); /* go fer it */
r.h.dh = 0; /* clear high byte for put */
r.h.dl &= 0xdf; /* set raw bit */
/* and put it back */
r.x.ax = 0x4401; /* IO ctrl put device information */
r.x.bx = 0x0001; /* File handle; 1 for console */
intdos(&r, &r); /* go fer it */
}
ckeyoff() /* turn control-C trapping off */
{
r.h.ah = 0x33; /* ctrl-break check */
r.h.al = 1; /* set the state of the ctrl-break check */
r.h.dl = 0; /* turn it off */
intdos(&r, &r);
}
ckeyon() /* turn control-C trapping on */
{
r.h.ah = 0x33; /* ctrl-break check */
r.h.al = 1; /* set the state of the ctrl-break check */
r.h.dl = 1; /* turn it on */
intdos(&r, &r);
}
agios(buf, len) /* perform an AGIOS call */
char *buf; /* sequence of bytes in command */
int len; /* length of command in bytes */
{
r.x.ax = 0x4403; /* I/O ctrl write */
r.x.bx = 1; /* console handle */
r.x.cx = len; /* buffer length */
r.x.dx = (unsigned)buf; /* buffer address */
return(intdos(&r, &r)); /* do it */
}
keycon() /* turn keycode mode on */
{
static char cmd[] = {43, 0, 1};
return(agios(&cmd[0], 3));
}
keycoff() /* turn keycode mode off */
{
static char cmd[] = {43, 0, 0};
return(agios(&cmd[0], 3));
}
defkey() /* change all special keys to intercept mode */
{
static char cmd[] = {40, 0, 2, 0, 0xfe, 0};
return(agios(&cmd[0], 6));
}
undefkey() /* change all special keys to intercept mode */
{
static char cmd[] = {40, 0, 0, 0, 0xfe, 0};
return(agios(&cmd[0], 6));
}
#else
h15hello()
{
}
#endif