1 /* SCCS Id: @(#)os2.c 3.4 1996/02/29 */
2 /* Copyright (c) Timo Hakulinen, 1990, 1991, 1992, 1993, 1996. */
3 /* NetHack may be freely redistributed. See license for details. */
6 * OS/2 system functions.
16 /* OS/2 system definitions */
33 static char NDECL(DOSgetch);
34 static char NDECL(BIOSgetch);
41 /* BIOSgetch can use the numeric key pad on IBM compatibles. */
46 return ((ch == '\r') ? '\n' : ch);
50 * Keyboard translation tables.
55 #define PADKEYS (KEYPADHI - KEYPADLO + 1)
56 #define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI)
59 * Keypad keys are translated to the normal values below.
60 * When iflags.BIOS is active, shifted keypad keys are translated to the
63 static const struct pad {
64 char normal, shift, cntrl;
66 {'y', 'Y', C('y')}, /* 7 */
67 {'k', 'K', C('k')}, /* 8 */
68 {'u', 'U', C('u')}, /* 9 */
69 {'m', C('p'), C('p')}, /* - */
70 {'h', 'H', C('h')}, /* 4 */
71 {'g', 'g', 'g'}, /* 5 */
72 {'l', 'L', C('l')}, /* 6 */
73 {'p', 'P', C('p')}, /* + */
74 {'b', 'B', C('b')}, /* 1 */
75 {'j', 'J', C('j')}, /* 2 */
76 {'n', 'N', C('n')}, /* 3 */
77 {'i', 'I', C('i')}, /* Ins */
78 {'.', ':', ':'} /* Del */
79 }, numpad[PADKEYS] = {
80 {'7', M('7'), '7'}, /* 7 */
81 {'8', M('8'), '8'}, /* 8 */
82 {'9', M('9'), '9'}, /* 9 */
83 {'m', C('p'), C('p')}, /* - */
84 {'4', M('4'), '4'}, /* 4 */
85 {'g', 'G', 'g'}, /* 5 */
86 {'6', M('6'), '6'}, /* 6 */
87 {'p', 'P', C('p')}, /* + */
88 {'1', M('1'), '1'}, /* 1 */
89 {'2', M('2'), '2'}, /* 2 */
90 {'3', M('3'), '3'}, /* 3 */
91 {'i', 'I', C('i')}, /* Ins */
92 {'.', ':', ':'} /* Del */
96 * Unlike Ctrl-letter, the Alt-letter keystrokes have no specific ASCII
97 * meaning unless assigned one by a keyboard conversion table, so the
98 * keyboard BIOS normally does not return a character code when Alt-letter
99 * is pressed. So, to interpret unassigned Alt-letters, we must use a
100 * scan code table to translate the scan code into a letter, then set the
101 * "meta" bit for it. -3.
105 #define SCANKEYS (SCANHI - SCANLO + 1)
106 #define inmap(x) (SCANLO <= (x) && (x) <= SCANHI)
108 static const char scanmap[SCANKEYS] = { /* ... */
109 'q','w','e','r','t','y','u','i','o','p','[',']', '\n',
110 0, 'a','s','d','f','g','h','j','k','l',';','\'', '`',
111 0, '\\', 'z','x','c','v','b','N','m' /* ... */
115 * BIOSgetch emulates the MSDOS way of getting keys directly with a BIOS call.
117 #define SHIFT_KEY (0x1 | 0x2)
124 unsigned char scan, shift, ch;
125 const struct pad *kpad;
131 KbdCharIn(&CharData,IOWait,KbdHandle);
132 ch = CharData.chChar;
133 scan = CharData.chScan;
134 shift = CharData.fsState;
136 /* Translate keypad keys */
137 if (iskeypad(scan)) {
138 kpad = iflags.num_pad ? numpad : keypad;
139 if (shift & SHIFT_KEY)
140 ch = kpad[scan - KEYPADLO].shift;
141 else if (shift & CTRL_KEY)
142 ch = kpad[scan - KEYPADLO].cntrl;
144 ch = kpad[scan - KEYPADLO].normal;
146 /* Translate unassigned Alt-letters */
147 if ((shift & ALT_KEY) && !ch) {
149 ch = scanmap[scan - SCANLO];
150 return (isprint(ch) ? M(ch) : ch);
162 KbdCharIn(&CharData,IOWait,KbdHandle);
163 if (CharData.chChar == 0) { /* an extended code -- not yet supported */
164 KbdCharIn(&CharData,IOWait,KbdHandle); /* eat the next character */
165 CharData.chChar = 0; /* and return a 0 */
167 return (CharData.chChar);
182 KbdPeek(&CharData,KbdHandle);
183 return (CharData.fbStatus & (1 << 6));
190 FSALLOCATE FSInfoBuf;
196 DriveNumber, FSInfoLevel = 1, res;
198 if (path[0] && path[1] == ':')
199 DriveNumber = (toupper(path[0]) - 'A') + 1;
204 DosQueryFSInfo(DriveNumber,FSInfoLevel,(PVOID)&FSInfoBuf,(ULONG)sizeof(FSInfoBuf));
206 DosQFSInfo(DriveNumber,FSInfoLevel,(PBYTE)&FSInfoBuf,(USHORT)sizeof(FSInfoBuf));
209 return -1L; /* error */
211 return ((long) FSInfoBuf.cSectorUnit * FSInfoBuf.cUnitAvail *
216 * Functions to get filenames using wildcards
220 static FILEFINDBUF3 ResultBuf;
222 static FILEFINDBUF ResultBuf;
224 static HDIR DirHandle;
235 res, SearchCount = 1;
240 DosFindFirst((PSZ)path,&DirHandle,0L,(PVOID)&ResultBuf,(ULONG)sizeof(ResultBuf),&SearchCount,1L);
242 DosFindFirst((PSZ)path,&DirHandle,0,&ResultBuf,(USHORT)sizeof(ResultBuf),&SearchCount,0L);
255 res, SearchCount = 1;
259 DosFindNext(DirHandle,(PVOID)&ResultBuf,(ULONG)sizeof(ResultBuf),&SearchCount);
261 DosFindNext(DirHandle,&ResultBuf,(USHORT)sizeof(ResultBuf),&SearchCount);
269 return(ResultBuf.achName);
276 if (findfirst(file)) {
277 return (* (long *) (ResultBuf.cbFileAlloc));
283 * Chdrive() changes the default drive.
292 if ((ptr = index(str, ':')) != (char *)0) {
293 drive = toupper(*(ptr - 1));
295 DosSetDefaultDisk((ULONG)(drive - 'A' + 1));
297 DosSelectDisk((USHORT)(drive - 'A' + 1));
308 if (!iflags.rawio) return;
309 KbdInfo.cb = sizeof(KbdInfo);
310 KbdGetStatus(&KbdInfo,KbdHandle);
311 KbdInfo.fsMask &= 0xFFF7; /* ASCII off */
312 KbdInfo.fsMask |= 0x0004; /* BINARY on */
313 KbdSetStatus(&KbdInfo,KbdHandle);
322 if (!iflags.rawio) return;
323 KbdInfo.cb = sizeof(KbdInfo);
324 KbdGetStatus(&KbdInfo,KbdHandle);
325 KbdInfo.fsMask &= 0xFFFB; /* BINARY off */
326 KbdInfo.fsMask |= 0x0008; /* ASCII on */
327 KbdSetStatus(&KbdInfo,KbdHandle);
333 VIOMODEINFO ModeInfo;
334 HVIO VideoHandle = 0;
336 ModeInfo.cb = sizeof(ModeInfo);
338 (void) VioGetMode(&ModeInfo,VideoHandle);
348 HVIO VideoHandle = 0;
350 x--; y--; /* (0,0) is upper right corner */
352 (void) VioSetCurPos(x, y, VideoHandle);
356 char* get_username(lan_username_size)
357 int *lan_username_size;