1 /* SCCS Id: @(#)tos.c 3.1 90/14/08
2 /* NetHack may be freely redistributed. See license for details. */
5 * TOS system functions.
14 /* To avoid error for tos.c; will be removed later */
15 static char *nh_HE="\033q";
22 # define WORD short /* 16 bits -- redefine if necessary */
27 static char NDECL(DOSgetch);
28 static char NDECL(BIOSgetch);
29 static void NDECL(init_aline);
30 char *_a_line; /* for Line A variables */
32 boolean colors_changed = FALSE;
40 /* BIOSgetch can use the numeric key pad on IBM compatibles. */
45 return ((ch == '\r') ? '\n' : ch);
49 * Keyboard translation tables.
54 #define PADKEYS (KEYPADHI - KEYPADLO + 1)
55 #define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI)
58 * Keypad keys are translated to the normal values below.
59 * When iflags.BIOS is active, shifted keypad keys are translated to the
62 static const struct pad {
63 char normal, shift, cntrl;
65 {C('['), 'Q', C('[')}, /* UNDO */
66 {'?', '/', '?'}, /* HELP */
67 {'(', 'a', '('}, /* ( */
68 {')', 'w', ')'}, /* ) */
69 {'/', '/', '/'}, /* / */
70 {C('p'), '$', C('p')}, /* * */
71 {'y', 'Y', C('y')}, /* 7 */
72 {'k', 'K', C('k')}, /* 8 */
73 {'u', 'U', C('u')}, /* 9 */
74 {'h', 'H', C('h')}, /* 4 */
76 {'l', 'L', C('l')}, /* 6 */
77 {'b', 'B', C('b')}, /* 1 */
78 {'j', 'J', C('j')}, /* 2 */
79 {'n', 'N', C('n')}, /* 3 */
80 {'i', 'I', C('i')}, /* Ins */
81 {'.', ':', ':'} /* Del */
82 }, numpad[PADKEYS] = {
83 {C('['), 'Q', C('[')} , /* UNDO */
84 {'?', '/', '?'}, /* HELP */
85 {'(', 'a', '('}, /* ( */
86 {')', 'w', ')'}, /* ) */
87 {'/', '/', '/'}, /* / */
88 {C('p'), '$', C('p')}, /* * */
89 {'7', M('7'), '7'}, /* 7 */
90 {'8', M('8'), '8'}, /* 8 */
91 {'9', M('9'), '9'}, /* 9 */
92 {'4', M('4'), '4'}, /* 4 */
93 {'.', '.', '.'}, /* 5 */
94 {'6', M('6'), '6'}, /* 6 */
95 {'1', M('1'), '1'}, /* 1 */
96 {'2', M('2'), '2'}, /* 2 */
97 {'3', M('3'), '3'}, /* 3 */
98 {'i', 'I', C('i')}, /* Ins */
99 {'.', ':', ':'} /* Del */
103 * Unlike Ctrl-letter, the Alt-letter keystrokes have no specific ASCII
104 * meaning unless assigned one by a keyboard conversion table, so the
105 * keyboard BIOS normally does not return a character code when Alt-letter
106 * is pressed. So, to interpret unassigned Alt-letters, we must use a
107 * scan code table to translate the scan code into a letter, then set the
108 * "meta" bit for it. -3.
112 static const char scanmap[] = { /* ... */
113 'q','w','e','r','t','y','u','i','o','p','[',']', '\n',
114 0, 'a','s','d','f','g','h','j','k','l',';','\'', '`',
115 0, '\\', 'z','x','c','v','b','N','m',',','.','?' /* ... */
118 #define inmap(x) (SCANLO <= (x) && (x) < SCANLO + SIZE(scanmap))
121 * BIOSgetch gets keys directly with a BIOS call.
123 #define SHIFT (0x1 | 0x2)
130 unsigned char scan, shift, ch;
131 const struct pad *kpad;
139 scan = (x & 0x00ff0000L) >> 16;
144 /* Translate keypad keys */
145 if (iskeypad(scan)) {
146 kpad = iflags.num_pad ? numpad : keypad;
148 ch = kpad[scan - KEYPADLO].shift;
149 else if (shift & CTRL)
150 ch = kpad[scan - KEYPADLO].cntrl;
152 ch = kpad[scan - KEYPADLO].normal;
154 /* Translate unassigned Alt-letters */
155 if ((shift & ALT) && !ch) {
157 ch = scanmap[scan - SCANLO];
158 return (isprint(ch) ? M(ch) : ch);
166 return (Crawcin() & 0x007f);
176 long freal; /*free allocation units*/
177 long total; /*total number of allocation units*/
178 long bps; /*bytes per sector*/
179 long pspal; /*physical sectors per allocation unit*/
181 if (path[0] && path[1] == ':')
182 drive = (toupper(path[0]) - 'A') + 1;
183 if (Dfree(&freespace,drive)<0) return -1;
184 return freespace.freal*freespace.bps*freespace.pspal;
188 * Functions to get filenames using wildcards
194 return (Fsfirst(path, 0) == 0);
200 return (Fsnext() == 0);
206 return (char *)Fgetdta() + 30;
214 return (* (long *) ((char *)Fgetdta() + 26));
220 * Chdrive() changes the default drive.
229 if ((ptr = index(str, ':')) != (char *)0) {
230 drive = toupper(*(ptr - 1));
231 (void)Dsetdrv(drive - 'A');
245 if((tmp=nh_getenv("LINES")))
247 else if((tmp=nh_getenv("ROWS")))
249 if(tmp && (tmp=nh_getenv("COLUMNS")))
252 ioctl(0,TIOCGWINSZ, &win);
258 LI = (*((WORD *)(_a_line + -42L))) + 1;
259 CO = (*((WORD *)(_a_line + -44L))) + 1;
272 if ((fromfd = open(from, O_RDONLY|O_BINARY, 0)) < 0)
274 if ((tofd = open(to, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, FCMASK)) < 0)
276 buf = (char *)alloc((size_t)BIGBUF);
277 while ( (r = read(fromfd, buf, BIGBUF)) > 0)
282 return 0; /* successful */
294 /* line A calls nuke registers d0-d2,a0-a2; not all compilers regard these
295 as scratch registers, though, so we save them
297 asm(" moveml d0-d2/a0-a2, sp@-");
298 asm(" .word 0xa000; movel d0, __a_line");
299 asm(" moveml sp@+, d0-d2/a0-a2");
301 asm(" movem.l d0-d2/a0-a2, -(sp)");
302 asm(" .dc.w 0xa000"); /* tweak as necessary for your compiler */
303 asm(" move.l d0, __a_line");
304 asm(" movem.l (sp)+, d0-d2/a0-a2");
309 /* used in termcap.c to decide how to set up the hilites */
310 unsigned long tos_numcolors = 2;
315 static char colorHE[] = "\033q\033b0";
320 tos_numcolors = 1 << (((unsigned char *) _a_line)[1]);
321 if (tos_numcolors <= 2) { /* mono */
322 iflags.use_color = FALSE;
325 colors_changed = TRUE;
333 static char plainHE[] = "\033q";
337 colors_changed = FALSE;
339 # endif /* TEXTCOLOR */
355 pline("Sorry, it seems we have no SIGTSTP here. Try ! or S.");
358 else if(signal(SIGTSTP, SIG_IGN) == SIG_DFL) {
359 suspend_nhwindows((char *)0);
360 (void) signal(SIGTSTP, SIG_DFL);
361 (void) kill(0, SIGTSTP);
365 pline("I don't think your shell has job control.");
370 # endif /* SUSPEND */