1 /* NetHack 3.6 os2.c $NHDT-Date: 1432512793 2015/05/25 00:13:13 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */
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
;
67 { 'y', 'Y', C('y') }, /* 7 */
68 { 'k', 'K', C('k') }, /* 8 */
69 { 'u', 'U', C('u') }, /* 9 */
70 { 'm', C('p'), C('p') }, /* - */
71 { 'h', 'H', C('h') }, /* 4 */
72 { 'g', 'g', 'g' }, /* 5 */
73 { 'l', 'L', C('l') }, /* 6 */
74 { 'p', 'P', C('p') }, /* + */
75 { 'b', 'B', C('b') }, /* 1 */
76 { 'j', 'J', C('j') }, /* 2 */
77 { 'n', 'N', C('n') }, /* 3 */
78 { 'i', 'I', C('i') }, /* Ins */
79 { '.', ':', ':' } /* Del */
82 { '7', M('7'), '7' }, /* 7 */
83 { '8', M('8'), '8' }, /* 8 */
84 { '9', M('9'), '9' }, /* 9 */
85 { 'm', C('p'), C('p') }, /* - */
86 { '4', M('4'), '4' }, /* 4 */
87 { 'g', 'G', 'g' }, /* 5 */
88 { '6', M('6'), '6' }, /* 6 */
89 { 'p', 'P', C('p') }, /* + */
90 { '1', M('1'), '1' }, /* 1 */
91 { '2', M('2'), '2' }, /* 2 */
92 { '3', M('3'), '3' }, /* 3 */
93 { 'i', 'I', C('i') }, /* Ins */
94 { '.', ':', ':' } /* Del */
98 * Unlike Ctrl-letter, the Alt-letter keystrokes have no specific ASCII
99 * meaning unless assigned one by a keyboard conversion table, so the
100 * keyboard BIOS normally does not return a character code when Alt-letter
101 * is pressed. So, to interpret unassigned Alt-letters, we must use a
102 * scan code table to translate the scan code into a letter, then set the
103 * "meta" bit for it. -3.
107 #define SCANKEYS (SCANHI - SCANLO + 1)
108 #define inmap(x) (SCANLO <= (x) && (x) <= SCANHI)
110 static const char scanmap
[SCANKEYS
] = {
112 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', 0, 'a',
113 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\', 'z', 'x',
114 'c', 'v', 'b', 'N', 'm' /* ... */
118 * BIOSgetch emulates the MSDOS way of getting keys directly with a BIOS call.
120 #define SHIFT_KEY (0x1 | 0x2)
127 unsigned char scan
, shift
, ch
;
128 const struct pad
*kpad
;
134 KbdCharIn(&CharData
, IOWait
, KbdHandle
);
135 ch
= CharData
.chChar
;
136 scan
= CharData
.chScan
;
137 shift
= CharData
.fsState
;
139 /* Translate keypad keys */
140 if (iskeypad(scan
)) {
141 kpad
= iflags
.num_pad
? numpad
: keypad
;
142 if (shift
& SHIFT_KEY
)
143 ch
= kpad
[scan
- KEYPADLO
].shift
;
144 else if (shift
& CTRL_KEY
)
145 ch
= kpad
[scan
- KEYPADLO
].cntrl
;
147 ch
= kpad
[scan
- KEYPADLO
].normal
;
149 /* Translate unassigned Alt-letters */
150 if ((shift
& ALT_KEY
) && !ch
) {
152 ch
= scanmap
[scan
- SCANLO
];
153 return (isprint(ch
) ? M(ch
) : ch
);
165 KbdCharIn(&CharData
, IOWait
, KbdHandle
);
166 if (CharData
.chChar
== 0) { /* an extended code -- not yet supported */
167 KbdCharIn(&CharData
, IOWait
, KbdHandle
); /* eat the next character */
168 CharData
.chChar
= 0; /* and return a 0 */
170 return (CharData
.chChar
);
185 KbdPeek(&CharData
, KbdHandle
);
186 return (CharData
.fbStatus
& (1 << 6));
193 FSALLOCATE FSInfoBuf
;
199 DriveNumber
, FSInfoLevel
= 1, res
;
201 if (path
[0] && path
[1] == ':')
202 DriveNumber
= (toupper(path
[0]) - 'A') + 1;
207 DosQueryFSInfo(DriveNumber
, FSInfoLevel
, (PVOID
) &FSInfoBuf
,
208 (ULONG
) sizeof(FSInfoBuf
));
210 DosQFSInfo(DriveNumber
, FSInfoLevel
, (PBYTE
) &FSInfoBuf
,
211 (USHORT
) sizeof(FSInfoBuf
));
214 return -1L; /* error */
216 return ((long) FSInfoBuf
.cSectorUnit
* FSInfoBuf
.cUnitAvail
217 * FSInfoBuf
.cbSector
);
221 * Functions to get filenames using wildcards
225 static FILEFINDBUF3 ResultBuf
;
227 static FILEFINDBUF ResultBuf
;
229 static HDIR DirHandle
;
240 res
, SearchCount
= 1;
245 DosFindFirst((PSZ
) path
, &DirHandle
, 0L, (PVOID
) &ResultBuf
,
246 (ULONG
) sizeof(ResultBuf
), &SearchCount
, 1L);
248 DosFindFirst((PSZ
) path
, &DirHandle
, 0, &ResultBuf
,
249 (USHORT
) sizeof(ResultBuf
), &SearchCount
, 0L);
262 res
, SearchCount
= 1;
266 DosFindNext(DirHandle
, (PVOID
) &ResultBuf
, (ULONG
) sizeof(ResultBuf
),
269 DosFindNext(DirHandle
, &ResultBuf
, (USHORT
) sizeof(ResultBuf
),
278 return (ResultBuf
.achName
);
285 if (findfirst(file
)) {
286 return (*(long *) (ResultBuf
.cbFileAlloc
));
292 * Chdrive() changes the default drive.
301 if ((ptr
= index(str
, ':')) != (char *) 0) {
302 drive
= toupper(*(ptr
- 1));
304 DosSetDefaultDisk((ULONG
)(drive
- 'A' + 1));
306 DosSelectDisk((USHORT
)(drive
- 'A' + 1));
319 KbdInfo
.cb
= sizeof(KbdInfo
);
320 KbdGetStatus(&KbdInfo
, KbdHandle
);
321 KbdInfo
.fsMask
&= 0xFFF7; /* ASCII off */
322 KbdInfo
.fsMask
|= 0x0004; /* BINARY on */
323 KbdSetStatus(&KbdInfo
, KbdHandle
);
334 KbdInfo
.cb
= sizeof(KbdInfo
);
335 KbdGetStatus(&KbdInfo
, KbdHandle
);
336 KbdInfo
.fsMask
&= 0xFFFB; /* BINARY off */
337 KbdInfo
.fsMask
|= 0x0008; /* ASCII on */
338 KbdSetStatus(&KbdInfo
, KbdHandle
);
344 VIOMODEINFO ModeInfo
;
345 HVIO VideoHandle
= 0;
347 ModeInfo
.cb
= sizeof(ModeInfo
);
349 (void) VioGetMode(&ModeInfo
, VideoHandle
);
359 HVIO VideoHandle
= 0;
362 y
--; /* (0,0) is upper right corner */
364 (void) VioSetCurPos(x
, y
, VideoHandle
);
368 get_username(lan_username_size
)
369 int *lan_username_size
;