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
|
/* SCCS Id: @(#)os2.c 3.4 1996/02/29 */
/* Copyright (c) Timo Hakulinen, 1990, 1991, 1992, 1993, 1996. */
/* NetHack may be freely redistributed. See license for details. */
/*
* OS/2 system functions.
*/
#define NEED_VARARGS
#include "hack.h"
#ifdef OS2
#include "tcap.h"
/* OS/2 system definitions */
#ifdef __EMX__
#undef CLR_BLACK
#undef CLR_WHITE
#undef CLR_BLUE
#undef CLR_RED
#undef CLR_GREEN
#undef CLR_CYAN
#undef CLR_YELLOW
#undef CLR_BROWN
#endif
#include "def_os2.h"
#include <ctype.h>
static char NDECL(DOSgetch);
static char NDECL(BIOSgetch);
int
tgetch()
{
char ch;
/* BIOSgetch can use the numeric key pad on IBM compatibles. */
if (iflags.BIOS)
ch = BIOSgetch();
else
ch = DOSgetch();
return ((ch == '\r') ? '\n' : ch);
}
/*
* Keyboard translation tables.
*/
#define KEYPADLO 0x47
#define KEYPADHI 0x53
#define PADKEYS (KEYPADHI - KEYPADLO + 1)
#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI)
/*
* Keypad keys are translated to the normal values below.
* When iflags.BIOS is active, shifted keypad keys are translated to the
* shift values below.
*/
static const struct pad {
char normal, shift, cntrl;
} keypad[PADKEYS] = {
{'y', 'Y', C('y')}, /* 7 */
{'k', 'K', C('k')}, /* 8 */
{'u', 'U', C('u')}, /* 9 */
{'m', C('p'), C('p')}, /* - */
{'h', 'H', C('h')}, /* 4 */
{'g', 'g', 'g'}, /* 5 */
{'l', 'L', C('l')}, /* 6 */
{'p', 'P', C('p')}, /* + */
{'b', 'B', C('b')}, /* 1 */
{'j', 'J', C('j')}, /* 2 */
{'n', 'N', C('n')}, /* 3 */
{'i', 'I', C('i')}, /* Ins */
{'.', ':', ':'} /* Del */
}, numpad[PADKEYS] = {
{'7', M('7'), '7'}, /* 7 */
{'8', M('8'), '8'}, /* 8 */
{'9', M('9'), '9'}, /* 9 */
{'m', C('p'), C('p')}, /* - */
{'4', M('4'), '4'}, /* 4 */
{'g', 'G', 'g'}, /* 5 */
{'6', M('6'), '6'}, /* 6 */
{'p', 'P', C('p')}, /* + */
{'1', M('1'), '1'}, /* 1 */
{'2', M('2'), '2'}, /* 2 */
{'3', M('3'), '3'}, /* 3 */
{'i', 'I', C('i')}, /* Ins */
{'.', ':', ':'} /* Del */
};
/*
* Unlike Ctrl-letter, the Alt-letter keystrokes have no specific ASCII
* meaning unless assigned one by a keyboard conversion table, so the
* keyboard BIOS normally does not return a character code when Alt-letter
* is pressed. So, to interpret unassigned Alt-letters, we must use a
* scan code table to translate the scan code into a letter, then set the
* "meta" bit for it. -3.
*/
#define SCANLO 0x10
#define SCANHI 0x32
#define SCANKEYS (SCANHI - SCANLO + 1)
#define inmap(x) (SCANLO <= (x) && (x) <= SCANHI)
static const char scanmap[SCANKEYS] = { /* ... */
'q','w','e','r','t','y','u','i','o','p','[',']', '\n',
0, 'a','s','d','f','g','h','j','k','l',';','\'', '`',
0, '\\', 'z','x','c','v','b','N','m' /* ... */
};
/*
* BIOSgetch emulates the MSDOS way of getting keys directly with a BIOS call.
*/
#define SHIFT_KEY (0x1 | 0x2)
#define CTRL_KEY 0x4
#define ALT_KEY 0x8
static char
BIOSgetch()
{
unsigned char scan, shift, ch;
const struct pad *kpad;
KBDKEYINFO CharData;
USHORT IOWait = 0;
HKBD KbdHandle = 0;
KbdCharIn(&CharData,IOWait,KbdHandle);
ch = CharData.chChar;
scan = CharData.chScan;
shift = CharData.fsState;
/* Translate keypad keys */
if (iskeypad(scan)) {
kpad = iflags.num_pad ? numpad : keypad;
if (shift & SHIFT_KEY)
ch = kpad[scan - KEYPADLO].shift;
else if (shift & CTRL_KEY)
ch = kpad[scan - KEYPADLO].cntrl;
else
ch = kpad[scan - KEYPADLO].normal;
}
/* Translate unassigned Alt-letters */
if ((shift & ALT_KEY) && !ch) {
if (inmap(scan))
ch = scanmap[scan - SCANLO];
return (isprint(ch) ? M(ch) : ch);
}
return ch;
}
static char
DOSgetch()
{
KBDKEYINFO CharData;
USHORT IOWait = 0;
HKBD KbdHandle = 0;
KbdCharIn(&CharData,IOWait,KbdHandle);
if (CharData.chChar == 0) { /* an extended code -- not yet supported */
KbdCharIn(&CharData,IOWait,KbdHandle); /* eat the next character */
CharData.chChar = 0; /* and return a 0 */
}
return (CharData.chChar);
}
char
switchar()
{
return '/';
}
int
kbhit()
{
KBDKEYINFO CharData;
HKBD KbdHandle = 0;
KbdPeek(&CharData,KbdHandle);
return (CharData.fbStatus & (1 << 6));
}
long
freediskspace(path)
char *path;
{
FSALLOCATE FSInfoBuf;
#ifdef OS2_32BITAPI
ULONG
#else
USHORT
#endif
DriveNumber, FSInfoLevel = 1, res;
if (path[0] && path[1] == ':')
DriveNumber = (toupper(path[0]) - 'A') + 1;
else
DriveNumber = 0;
res =
#ifdef OS2_32BITAPI
DosQueryFSInfo(DriveNumber,FSInfoLevel,(PVOID)&FSInfoBuf,(ULONG)sizeof(FSInfoBuf));
#else
DosQFSInfo(DriveNumber,FSInfoLevel,(PBYTE)&FSInfoBuf,(USHORT)sizeof(FSInfoBuf));
#endif
if (res)
return -1L; /* error */
else
return ((long) FSInfoBuf.cSectorUnit * FSInfoBuf.cUnitAvail *
FSInfoBuf.cbSector);
}
/*
* Functions to get filenames using wildcards
*/
#ifdef OS2_32BITAPI
static FILEFINDBUF3 ResultBuf;
#else
static FILEFINDBUF ResultBuf;
#endif
static HDIR DirHandle;
int
findfirst(path)
char *path;
{
#ifdef OS2_32BITAPI
ULONG
#else
USHORT
#endif
res, SearchCount = 1;
DirHandle = 1;
res =
#ifdef OS2_32BITAPI
DosFindFirst((PSZ)path,&DirHandle,0L,(PVOID)&ResultBuf,(ULONG)sizeof(ResultBuf),&SearchCount,1L);
#else
DosFindFirst((PSZ)path,&DirHandle,0,&ResultBuf,(USHORT)sizeof(ResultBuf),&SearchCount,0L);
#endif
return(!res);
}
int
findnext()
{
#ifdef OS2_32BITAPI
ULONG
#else
USHORT
#endif
res, SearchCount = 1;
res =
#ifdef OS2_32BITAPI
DosFindNext(DirHandle,(PVOID)&ResultBuf,(ULONG)sizeof(ResultBuf),&SearchCount);
#else
DosFindNext(DirHandle,&ResultBuf,(USHORT)sizeof(ResultBuf),&SearchCount);
#endif
return(!res);
}
char *
foundfile_buffer()
{
return(ResultBuf.achName);
}
long
filesize(file)
char *file;
{
if (findfirst(file)) {
return (* (long *) (ResultBuf.cbFileAlloc));
} else
return -1L;
}
/*
* Chdrive() changes the default drive.
*/
void
chdrive(str)
char *str;
{
char *ptr;
char drive;
if ((ptr = index(str, ':')) != (char *)0) {
drive = toupper(*(ptr - 1));
#ifdef OS2_32BITAPI
DosSetDefaultDisk((ULONG)(drive - 'A' + 1));
#else
DosSelectDisk((USHORT)(drive - 'A' + 1));
#endif
}
}
void
disable_ctrlP()
{
KBDINFO KbdInfo;
HKBD KbdHandle = 0;
if (!iflags.rawio) return;
KbdInfo.cb = sizeof(KbdInfo);
KbdGetStatus(&KbdInfo,KbdHandle);
KbdInfo.fsMask &= 0xFFF7; /* ASCII off */
KbdInfo.fsMask |= 0x0004; /* BINARY on */
KbdSetStatus(&KbdInfo,KbdHandle);
}
void
enable_ctrlP()
{
KBDINFO KbdInfo;
HKBD KbdHandle = 0;
if (!iflags.rawio) return;
KbdInfo.cb = sizeof(KbdInfo);
KbdGetStatus(&KbdInfo,KbdHandle);
KbdInfo.fsMask &= 0xFFFB; /* BINARY off */
KbdInfo.fsMask |= 0x0008; /* ASCII on */
KbdSetStatus(&KbdInfo,KbdHandle);
}
void
get_scr_size()
{
VIOMODEINFO ModeInfo;
HVIO VideoHandle = 0;
ModeInfo.cb = sizeof(ModeInfo);
(void) VioGetMode(&ModeInfo,VideoHandle);
CO = ModeInfo.col;
LI = ModeInfo.row;
}
void
gotoxy(x,y)
int x,y;
{
HVIO VideoHandle = 0;
x--; y--; /* (0,0) is upper right corner */
(void) VioSetCurPos(x, y, VideoHandle);
}
char* get_username(lan_username_size)
int *lan_username_size;
{
return (char*)0;
}
#ifdef X11_GRAPHICS
int errno;
#endif
#endif /* OS2 */
|