| 1 |
/* File: main-ibm.c */ |
| 2 |
|
| 3 |
/* |
| 4 |
* Copyright (c) 1997 Ben Harrison, and others |
| 5 |
* |
| 6 |
* This software may be copied and distributed for educational, research, |
| 7 |
* and not for profit purposes provided that this copyright and statement |
| 8 |
* are included in all such copies. |
| 9 |
*/ |
| 10 |
|
| 11 |
/* Purpose: Visual Display Support for "z-term.c", for the IBM */ |
| 12 |
|
| 13 |
|
| 14 |
/* |
| 15 |
* Original code by "Billy Tanksley ([email protected])" |
| 16 |
* Use "Makefile.ibm" to compile Angband using this file. |
| 17 |
* |
| 18 |
* Support for DJGPP v2 by "Scott Egashira ([email protected])" |
| 19 |
* |
| 20 |
* Extensive modifications by "Ben Harrison ([email protected])", |
| 21 |
* including "collation" of the Watcom C/C++ and DOS-286 patches. |
| 22 |
* |
| 23 |
* Watcom C/C++ changes by "David Boeren ([email protected])" |
| 24 |
* Use "Makefile.wat" to compile this file with Watcom C/C++, and |
| 25 |
* be sure to define "USE_IBM" and "USE_WAT". |
| 26 |
* |
| 27 |
* DOS-286 (conio.h) changes by (Roland Jay Roberts ([email protected]) |
| 28 |
* Use "Makefile.286" (not ready) to compile this file for DOS-286, |
| 29 |
* and be sure to define "USE_IBM", "USE_WAT", and "USE_286". Also, |
| 30 |
* depending on your compiler, you may need to define "USE_CONIO". |
| 31 |
* |
| 32 |
* True color palette support by "Mike Marcelais ([email protected])", |
| 33 |
* with interface to the "color_table" array by Ben Harrison. |
| 34 |
* |
| 35 |
* Both "shift" keys are treated as "identical", and all the modifier keys |
| 36 |
* (control, shift, alt) are ignored when used with "normal" keys, unless |
| 37 |
* they modify the underlying "ascii" value of the key. You must use the |
| 38 |
* new "user pref files" to be able to interact with the keypad and such. |
| 39 |
* |
| 40 |
* The "lib/user/pref-ibm.prf" file contains keymap definitions and possible |
| 41 |
* alternative color set definitions. The "lib/user/font-ibm.prf" contains |
| 42 |
* attr/char mappings for walls and floors and such. |
| 43 |
* |
| 44 |
* Note the "Term_user_ibm()" function hook, which could allow the user |
| 45 |
* to interact with the "main-ibm.c" visual system. Currently this hook |
| 46 |
* is unused, but, for example, it could allow the user to toggle "sound" |
| 47 |
* or "graphics" modes, or to select the number of screen rows, with the |
| 48 |
* extra screen rows being used for the mirror window. |
| 49 |
*/ |
| 50 |
|
| 51 |
|
| 52 |
#include "angband.h" |
| 53 |
|
| 54 |
|
| 55 |
#ifdef USE_IBM |
| 56 |
|
| 57 |
#include "main.h" |
| 58 |
|
| 59 |
/* |
| 60 |
* Use a "virtual" screen to "buffer" screen writes. |
| 61 |
*/ |
| 62 |
#define USE_VIRTUAL |
| 63 |
|
| 64 |
|
| 65 |
#include <bios.h> |
| 66 |
#include <dos.h> |
| 67 |
|
| 68 |
#ifdef USE_WAT |
| 69 |
|
| 70 |
# include <conio.h> |
| 71 |
|
| 72 |
# ifdef USE_CONIO |
| 73 |
# else /* USE_CONIO */ |
| 74 |
|
| 75 |
# include <graph.h> |
| 76 |
|
| 77 |
# define bioskey(C) _bios_keybrd(C) |
| 78 |
|
| 79 |
# endif /* USE_CONIO */ |
| 80 |
|
| 81 |
# ifndef USE_286 |
| 82 |
# define int86(a,b,c) int386(a,b,c) |
| 83 |
# endif |
| 84 |
|
| 85 |
# define inportb(x) inp(x) |
| 86 |
# define outportb(x,y) outp(x,y) |
| 87 |
|
| 88 |
#else /* USE_WAT */ |
| 89 |
|
| 90 |
# if __DJGPP__ > 1 |
| 91 |
|
| 92 |
# include <pc.h> |
| 93 |
# include <osfcn.h> |
| 94 |
# include <libc/unconst.h> |
| 95 |
# include <wchar.h> |
| 96 |
# include <wctype.h> |
| 97 |
|
| 98 |
# else /* __DJGPP__ > 1 */ |
| 99 |
# ifdef __DJGPP__ |
| 100 |
# error "Upgrade to version 2.0 of DJGPP" |
| 101 |
# endif /* __DJGPP__ */ |
| 102 |
# endif /* __DJGPP__ > 1 */ |
| 103 |
|
| 104 |
#endif /* USE_WAT */ |
| 105 |
|
| 106 |
|
| 107 |
#ifdef USE_CONIO |
| 108 |
|
| 109 |
# include <conio.h> |
| 110 |
|
| 111 |
/* |
| 112 |
* Hack -- write directly to video card |
| 113 |
*/ |
| 114 |
extern int directvideo = 1; |
| 115 |
|
| 116 |
/* |
| 117 |
* Hack -- no virtual screen |
| 118 |
*/ |
| 119 |
# undef USE_VIRTUAL |
| 120 |
|
| 121 |
#endif /* USE_CONIO */ |
| 122 |
|
| 123 |
|
| 124 |
/* |
| 125 |
* Keypress input modifier flags (hard-coded by DOS) |
| 126 |
*/ |
| 127 |
#define K_RSHIFT 0 /* Right shift key down */ |
| 128 |
#define K_LSHIFT 1 /* Left shift key down */ |
| 129 |
#define K_CTRL 2 /* Ctrl key down */ |
| 130 |
#define K_ALT 3 /* Alt key down */ |
| 131 |
#define K_SCROLL 4 /* Scroll lock on */ |
| 132 |
#define K_NUM 5 /* Num lock on */ |
| 133 |
#define K_CAPS 6 /* Caps lock on */ |
| 134 |
#define K_INSERT 7 /* Insert on */ |
| 135 |
|
| 136 |
|
| 137 |
/* |
| 138 |
* Foreground color bits (hard-coded by DOS) |
| 139 |
*/ |
| 140 |
#define VID_BLACK 0x00 |
| 141 |
#define VID_BLUE 0x01 |
| 142 |
#define VID_GREEN 0x02 |
| 143 |
#define VID_CYAN 0x03 |
| 144 |
#define VID_RED 0x04 |
| 145 |
#define VID_MAGENTA 0x05 |
| 146 |
#define VID_YELLOW 0x06 |
| 147 |
#define VID_WHITE 0x07 |
| 148 |
|
| 149 |
/* |
| 150 |
* Bright text (hard-coded by DOS) |
| 151 |
*/ |
| 152 |
#define VID_BRIGHT 0x08 |
| 153 |
|
| 154 |
/* |
| 155 |
* Background color bits (hard-coded by DOS) |
| 156 |
*/ |
| 157 |
#define VUD_BLACK 0x00 |
| 158 |
#define VUD_BLUE 0x10 |
| 159 |
#define VUD_GREEN 0x20 |
| 160 |
#define VUD_CYAN 0x30 |
| 161 |
#define VUD_RED 0x40 |
| 162 |
#define VUD_MAGENTA 0x50 |
| 163 |
#define VUD_YELLOW 0x60 |
| 164 |
#define VUD_WHITE 0x70 |
| 165 |
|
| 166 |
/* |
| 167 |
* Blinking text (hard-coded by DOS) |
| 168 |
*/ |
| 169 |
#define VUD_BRIGHT 0x80 |
| 170 |
|
| 171 |
|
| 172 |
/* |
| 173 |
* Screen Size |
| 174 |
*/ |
| 175 |
static int rows = 25; |
| 176 |
static int cols = 80; |
| 177 |
|
| 178 |
|
| 179 |
/* |
| 180 |
* Physical Screen |
| 181 |
*/ |
| 182 |
#ifdef USE_286 |
| 183 |
# define PhysicalScreen ((uint8_t *)MK_FP(0xB800,0x0000)) |
| 184 |
#else |
| 185 |
# define PhysicalScreen ((uint8_t *)(0xB800 << 4)) |
| 186 |
#endif |
| 187 |
|
| 188 |
|
| 189 |
#ifdef USE_VIRTUAL |
| 190 |
|
| 191 |
/* |
| 192 |
* Virtual Screen Contents |
| 193 |
*/ |
| 194 |
static uint8_t *VirtualScreen; |
| 195 |
|
| 196 |
#else |
| 197 |
|
| 198 |
/* |
| 199 |
* Physical screen access |
| 200 |
*/ |
| 201 |
#define VirtualScreen PhysicalScreen |
| 202 |
|
| 203 |
#endif |
| 204 |
|
| 205 |
|
| 206 |
/* |
| 207 |
* Hack -- the cursor "visibility" |
| 208 |
*/ |
| 209 |
static int saved_cur_v; |
| 210 |
static int saved_cur_high; |
| 211 |
static int saved_cur_low; |
| 212 |
|
| 213 |
|
| 214 |
#ifdef USE_CONIO |
| 215 |
#else /* USE_CONIO */ |
| 216 |
|
| 217 |
/* |
| 218 |
* This array is used for "wiping" the screen |
| 219 |
*/ |
| 220 |
static uint8_t wiper[160]; |
| 221 |
|
| 222 |
#endif /* USE_CONIO */ |
| 223 |
|
| 224 |
|
| 225 |
/* |
| 226 |
* The main screen (currently the only screen) |
| 227 |
*/ |
| 228 |
static term term_screen_body; |
| 229 |
|
| 230 |
|
| 231 |
/* |
| 232 |
* Choose between the "complex" and "simple" color methods |
| 233 |
*/ |
| 234 |
static uint8_t use_color_complex = false; |
| 235 |
|
| 236 |
|
| 237 |
/* |
| 238 |
* The "complex" color set |
| 239 |
*/ |
| 240 |
static long ibm_color_complex[16]; |
| 241 |
|
| 242 |
|
| 243 |
/* |
| 244 |
* The "simple" color set |
| 245 |
* |
| 246 |
* This table is used by the "color" code to instantiate the "approximate" |
| 247 |
* Angband colors using the only colors available on crappy monitors. |
| 248 |
* |
| 249 |
* The entries below are taken from the "color bits" defined above. |
| 250 |
* |
| 251 |
* Note that values from 16 to 255 are extremely ugly. |
| 252 |
* |
| 253 |
* The values below came from various sources, if you do not like them, |
| 254 |
* get a better monitor, or edit "pref-ibm.prf" to use different codes. |
| 255 |
* |
| 256 |
* Note that many of the choices below suck, but so do crappy monitors. |
| 257 |
*/ |
| 258 |
static uint8_t ibm_color_simple[16] = |
| 259 |
{ |
| 260 |
VID_BLACK, /* Dark */ |
| 261 |
VID_WHITE, /* White */ |
| 262 |
VID_CYAN, /* Slate XXX */ |
| 263 |
VID_RED | VID_BRIGHT, /* Orange XXX */ |
| 264 |
VID_RED, /* Red */ |
| 265 |
VID_GREEN, /* Green */ |
| 266 |
VID_BLUE, /* Blue */ |
| 267 |
VID_YELLOW, /* Umber XXX */ |
| 268 |
VID_BLACK | VID_BRIGHT, /* Light Dark */ |
| 269 |
VID_CYAN | VID_BRIGHT, /* Light Slate XXX */ |
| 270 |
VID_MAGENTA, /* Violet */ |
| 271 |
VID_YELLOW | VID_BRIGHT, /* Yellow */ |
| 272 |
VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */ |
| 273 |
VID_GREEN | VID_BRIGHT, /* Light Green */ |
| 274 |
VID_BLUE | VID_BRIGHT, /* Light Blue */ |
| 275 |
VID_YELLOW /* Light Umber XXX */ |
| 276 |
}; |
| 277 |
|
| 278 |
|
| 279 |
static uint8_t ext_color_map[32] = { |
| 280 |
0, |
| 281 |
1, |
| 282 |
2, |
| 283 |
3, |
| 284 |
4, |
| 285 |
5, |
| 286 |
6, |
| 287 |
7, |
| 288 |
8, |
| 289 |
9, |
| 290 |
10, |
| 291 |
11, |
| 292 |
12, |
| 293 |
13, |
| 294 |
14, |
| 295 |
15, |
| 296 |
10, /* Purple -> Violet */ |
| 297 |
10, /* Violet -> Violet */ |
| 298 |
14, /* Teal -> Light Blue */ |
| 299 |
7, /* Mud -> Umber */ |
| 300 |
15, /* Light Yellow -> Light Umber */ |
| 301 |
10, /* Magenta -> Violet */ |
| 302 |
14, /* Light Teal -> Light Blue */ |
| 303 |
10, /* Light Violet -> Violet */ |
| 304 |
12, /* Light Pink -> Light Red */ |
| 305 |
7, /* Mustard -> Yellow */ |
| 306 |
6, /* Blue Slate -> Blue */ |
| 307 |
14, /* Deep Light Blue -> Light Blue */ |
| 308 |
8 /* Shade -> Light Dark */ |
| 309 |
}; |
| 310 |
|
| 311 |
/* |
| 312 |
* Activate the "ibm_color_complex" palette information. |
| 313 |
* |
| 314 |
* Code by Mike Marcelais, with help from "The programmer's guide |
| 315 |
* to the EGA and VGA video cards" [Farraro]. |
| 316 |
* |
| 317 |
* On VGA cards, colors go through a double-indirection when looking |
| 318 |
* up the `real' color when in 16 color mode. The color value in the |
| 319 |
* attribute is looked up in the EGA color registers. Then that value |
| 320 |
* is looked up in the VGA color registers. Then the color is displayed. |
| 321 |
* This is done for compatability. However, the EGA registers are |
| 322 |
* initialized by default to 0..5, 14, 7, 38..3F and not 0..F which means |
| 323 |
* that unless these are reset, the VGA setpalette function will not |
| 324 |
* update the correct palette register! |
| 325 |
* |
| 326 |
* DJGPP's GrSetColor() does _not_ set the EGA palette list, only the |
| 327 |
* VGA color list. |
| 328 |
* |
| 329 |
* Note that the "traditional" method, using "int86(0x10)", is very slow |
| 330 |
* when called in protected mode, so we use a faster method using video |
| 331 |
* ports instead. |
| 332 |
* |
| 333 |
* On Watcom machines, we could simply use the special "_remapallpalette()" |
| 334 |
* function, which not only sets both palette lists (see below) but also |
| 335 |
* checks for legality of the monitor mode, but, if we are doing bitmapped |
| 336 |
* graphics, that function forgets to set the EGA registers for some reason. |
| 337 |
*/ |
| 338 |
static void activate_color_complex(void) |
| 339 |
{ |
| 340 |
int i; |
| 341 |
printf("%c%c%c%c",8,8,8,8); |
| 342 |
|
| 343 |
#if 1 |
| 344 |
|
| 345 |
/* Edit the EGA palette */ |
| 346 |
inportb(0x3da); |
| 347 |
|
| 348 |
/* Edit the colors */ |
| 349 |
for (i = 0; i < 16; i++) |
| 350 |
{ |
| 351 |
/* Set color "i" */ |
| 352 |
outportb(0x3c0, i); |
| 353 |
|
| 354 |
/* To value "i" */ |
| 355 |
outportb(0x3c0, i); |
| 356 |
}; |
| 357 |
|
| 358 |
/* Use that EGA palette */ |
| 359 |
outportb(0x3c0, 0x20); |
| 360 |
|
| 361 |
/* Edit VGA palette, starting at color zero */ |
| 362 |
outportb(0x3c8, 0); |
| 363 |
|
| 364 |
/* Send the colors */ |
| 365 |
for (i = 0; i < 16; i++) |
| 366 |
{ |
| 367 |
/* Send the red, green, blue components */ |
| 368 |
outportb(0x3c9, ((ibm_color_complex[i]) & 0xFF)); |
| 369 |
outportb(0x3c9, ((ibm_color_complex[i] >> 8) & 0xFF)); |
| 370 |
outportb(0x3c9, ((ibm_color_complex[i] >> 16) & 0xFF)); |
| 371 |
} |
| 372 |
|
| 373 |
#else /* 1 */ |
| 374 |
|
| 375 |
/* Set the colors */ |
| 376 |
for (i = 0; i < 16; i++) |
| 377 |
{ |
| 378 |
union REGS r; |
| 379 |
|
| 380 |
/* Set EGA color */ |
| 381 |
r.h.ah = 0x10; |
| 382 |
r.h.al = 0x00; |
| 383 |
|
| 384 |
/* Set color "i" */ |
| 385 |
r.h.bl = i; |
| 386 |
|
| 387 |
/* To value "i" */ |
| 388 |
r.h.bh = i; |
| 389 |
|
| 390 |
/* Do it */ |
| 391 |
int86(0x10, &r, &r); |
| 392 |
|
| 393 |
/* Set VGA color */ |
| 394 |
r.h.ah = 0x10; |
| 395 |
r.h.al = 0x10; |
| 396 |
|
| 397 |
/* Set color "i" */ |
| 398 |
r.h.bh = 0x00; |
| 399 |
r.h.bl = i; |
| 400 |
|
| 401 |
/* Use this "green" value */ |
| 402 |
r.h.ch = ((ibm_color_complex[i] >> 8) & 0xFF); |
| 403 |
|
| 404 |
/* Use this "blue" value */ |
| 405 |
r.h.cl = ((ibm_color_complex[i] >> 16) & 0xFF); |
| 406 |
|
| 407 |
/* Use this "red" value */ |
| 408 |
r.h.dh = ((ibm_color_complex[i]) & 0xFF); |
| 409 |
|
| 410 |
/* Do it */ |
| 411 |
int86(0x10, &r, &r); |
| 412 |
} |
| 413 |
|
| 414 |
#endif /* 1 */ |
| 415 |
|
| 416 |
} |
| 417 |
|
| 418 |
static int get_ext_color(int a) |
| 419 |
{ |
| 420 |
int retval; |
| 421 |
if (a > -1 && a < 29) { |
| 422 |
retval = ext_color_map[a]; |
| 423 |
} else { |
| 424 |
retval = a & 0x0F; |
| 425 |
} |
| 426 |
return retval; |
| 427 |
} |
| 428 |
|
| 429 |
/* |
| 430 |
* Note the use of "(x >> 2)" to convert an 8 bit value to a 6 bit value |
| 431 |
* without losing much precision. |
| 432 |
*/ |
| 433 |
static int Term_xtra_ibm_react(void) |
| 434 |
{ |
| 435 |
int i; |
| 436 |
|
| 437 |
/* Complex method */ |
| 438 |
if (use_color_complex) |
| 439 |
{ |
| 440 |
long rv, gv, bv, code; |
| 441 |
|
| 442 |
bool change = false; |
| 443 |
|
| 444 |
/* Save the default colors */ |
| 445 |
for (i = 0; i < 16; i++) |
| 446 |
{ |
| 447 |
/* Extract desired values */ |
| 448 |
rv = angband_color_table[i][1] >> 2; |
| 449 |
gv = angband_color_table[i][2] >> 2; |
| 450 |
bv = angband_color_table[i][3] >> 2; |
| 451 |
|
| 452 |
/* Extract a full color code */ |
| 453 |
code = ((rv) | (gv << 8) | (bv << 16)); |
| 454 |
|
| 455 |
/* Activate changes */ |
| 456 |
if (ibm_color_complex[i] != code) |
| 457 |
{ |
| 458 |
/* Note the change */ |
| 459 |
change = true; |
| 460 |
|
| 461 |
/* Apply the desired color */ |
| 462 |
ibm_color_complex[i] = code; |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
/* Activate the palette if needed */ |
| 467 |
if (change) activate_color_complex(); |
| 468 |
} |
| 469 |
|
| 470 |
/* Simple method */ |
| 471 |
else |
| 472 |
{ |
| 473 |
/* Save the default colors */ |
| 474 |
for (i = 0; i < 16; i++) |
| 475 |
{ |
| 476 |
/* Simply accept the desired colors */ |
| 477 |
ibm_color_simple[i] = angband_color_table[i][0]; |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
/* Success */ |
| 482 |
return (0); |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
/* |
| 488 |
* Hack -- set the cursor "visibility" |
| 489 |
*/ |
| 490 |
static void curs_set(int v) |
| 491 |
{ |
| 492 |
/* If needed */ |
| 493 |
if (saved_cur_v != v) |
| 494 |
{ |
| 495 |
union REGS r; |
| 496 |
|
| 497 |
/* Set cursor */ |
| 498 |
r.h.ah = 1; |
| 499 |
|
| 500 |
/* Visible */ |
| 501 |
if (v) |
| 502 |
{ |
| 503 |
/* Use the saved values */ |
| 504 |
r.h.ch = saved_cur_high; |
| 505 |
r.h.cl = saved_cur_low; |
| 506 |
} |
| 507 |
|
| 508 |
/* Invisible */ |
| 509 |
else |
| 510 |
{ |
| 511 |
/* Make it invisible */ |
| 512 |
r.h.ch = 0x20; |
| 513 |
r.h.cl = 0x00; |
| 514 |
} |
| 515 |
|
| 516 |
/* Make the call */ |
| 517 |
int86(0x10, &r, &r); |
| 518 |
|
| 519 |
/* Save the cursor state */ |
| 520 |
saved_cur_v = v; |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
/* |
| 527 |
* Process an event (check for a keypress) |
| 528 |
* |
| 529 |
* The keypress processing code is often the most system dependant part |
| 530 |
* of Angband, since sometimes even the choice of compiler is important. |
| 531 |
* |
| 532 |
* For the IBM, we divide all keypresses into two catagories, first, the |
| 533 |
* "normal" keys, including all keys required to play Angband, and second, |
| 534 |
* the "special" keys, such as keypad keys, function keys, and various keys |
| 535 |
* used in combination with various modifier keys. |
| 536 |
* |
| 537 |
* To simplify this file, we use Angband's "keymap" ability, in |
| 538 |
* combination with a specialized "pref-ibm.prf" file, to handle most of the |
| 539 |
* "special" keys, instead of attempting to fully analyze them here. This |
| 540 |
* file only has to determine when a "special" key has been pressed, and |
| 541 |
* translate it into a simple string which signals the use of a "special" |
| 542 |
* key, the set of modifiers used, if any, and the hardware scan code of |
| 543 |
* the actual key which was pressed. To simplify life for the user, we |
| 544 |
* treat both "shift" keys as identical modifiers. |
| 545 |
* |
| 546 |
* The final encoding is "^_MMMxSS\r", where "MMM" encodes the modifiers |
| 547 |
* ("C" for control, "S" for shift, "A" for alt, or any ordered combination), |
| 548 |
* and "SS" encodes the keypress (as the two "digit" hexidecimal encoding of |
| 549 |
* the scan code of the key that was pressed), and the "^_" and "x" and "\r" |
| 550 |
* delimit the encoding for recognition by the keymap code. |
| 551 |
* |
| 552 |
* Some important facts about scan codes follow. All "normal" keys use |
| 553 |
* scan codes from 1-58. The "function" keys use 59-68 (and 133-134). |
| 554 |
* The "keypad" keys use 69-83. Escape uses 1. Enter uses 28. Control |
| 555 |
* uses 29. Left Shift uses 42. Right Shift uses 54. PrtScrn uses 55. |
| 556 |
* Alt uses 56. Space uses 57. CapsLock uses 58. NumLock uses 69. |
| 557 |
* ScrollLock uses 70. The "keypad" keys which use scan codes 71-83 |
| 558 |
* are ordered KP7,KP8,KP9,KP-,KP4,KP5,KP6,KP+,KP1,KP2,KP3,INS,DEL. |
| 559 |
* |
| 560 |
* Using "bioskey(0x10)" instead of "bioskey(0)" apparently provides more |
| 561 |
* information, including better access to the keypad keys in combination |
| 562 |
* with various modifiers, but only works on "PC's after 6/1/86", and there |
| 563 |
* is no way to determine if the function is provided on a machine. I have |
| 564 |
* been told that without it you cannot detect, for example, control-left. |
| 565 |
* The basic scan code + ascii value pairs returned by the keypad follow, |
| 566 |
* with values in parentheses only available to "bioskey(0x10)". |
| 567 |
* |
| 568 |
* / * - + 1 2 3 4 |
| 569 |
* Norm: 352f 372a 4a2d 4e2b 4f00 5000 5100 4b00 |
| 570 |
* Shft: 352f 372a 4a2d 4e2b 4f31 5032 5133 4b34 |
| 571 |
* Ctrl: (9500) (9600) (8e00) (9000) 7500 (9100) 7600 7300 |
| 572 |
* |
| 573 |
* 5 6 7 8 9 0 . Enter |
| 574 |
* Norm: (4c00) 4d00 4700 4800 4900 5200 5300 (e00d) |
| 575 |
* Shft: 4c35 4d36 4737 4838 4939 5230 532e (e00d) |
| 576 |
* Ctrl: (8f00) 7400 7700 (8d00) 8400 (9200) (9300) (e00a) |
| 577 |
* |
| 578 |
* See "pref-ibm.prf" for the "standard" keymaps for various keys. |
| 579 |
* |
| 580 |
* Certain "bizarre" keypad keys (such as "enter") return a "scan code" |
| 581 |
* of "0xE0", and a "usable" ascii value. These keys should be treated |
| 582 |
* like the normal keys, see below. XXX XXX XXX Note that these "special" |
| 583 |
* keys could be prefixed with an optional "ctrl-^" which would allow them |
| 584 |
* to be used in keymaps without hurting their use in normal situations. |
| 585 |
*/ |
| 586 |
static errr Term_xtra_ibm_event(int v) |
| 587 |
{ |
| 588 |
int i, k, s; |
| 589 |
int ch = 0; |
| 590 |
|
| 591 |
bool mc = false; |
| 592 |
bool ms = false; |
| 593 |
bool ma = false; |
| 594 |
bool kp = false; |
| 595 |
|
| 596 |
uint8_t mods = 0; |
| 597 |
|
| 598 |
/* Hack -- Check for a keypress */ |
| 599 |
if (!v && !bioskey(1)) return (1); |
| 600 |
|
| 601 |
/* Wait for a keypress */ |
| 602 |
k = bioskey(0x10); |
| 603 |
|
| 604 |
/* Access the "modifiers" */ |
| 605 |
i = bioskey(2); |
| 606 |
|
| 607 |
/* Extract the "scan code" */ |
| 608 |
s = ((k >> 8) & 0xFF); |
| 609 |
|
| 610 |
/* Extract the "ascii value" */ |
| 611 |
k = (k & 0xFF); |
| 612 |
|
| 613 |
/* Process "normal" keys */ |
| 614 |
if ((s <= 58) || (s == 0xE0)) |
| 615 |
{ |
| 616 |
/* Enqueue it */ |
| 617 |
if (k) Term_keypress(k, 0); |
| 618 |
|
| 619 |
/* Success */ |
| 620 |
return (0); |
| 621 |
} |
| 622 |
|
| 623 |
/* Extract the modifier flags */ |
| 624 |
if (i & (1 << K_CTRL)) mc = true; |
| 625 |
if (i & (1 << K_LSHIFT)) ms = true; |
| 626 |
if (i & (1 << K_RSHIFT)) ms = true; |
| 627 |
if (i & (1 << K_ALT)) ma = true; |
| 628 |
|
| 629 |
switch (s) { |
| 630 |
case 0x56: |
| 631 |
/* Hack -- Some foreign keyboards have a special key on the |
| 632 |
* keyboard, which is used to generate the "<", ">", and |
| 633 |
* "|" keys (alone, shifted, alt-ed). |
| 634 |
*/ |
| 635 |
if (ms) { |
| 636 |
ch = '>'; |
| 637 |
} else if (ma) { |
| 638 |
ch = '|'; |
| 639 |
} else { |
| 640 |
ch = '<'; |
| 641 |
} |
| 642 |
break; |
| 643 |
case 0x35: kp = true; ch = '/'; break; |
| 644 |
case 0x37: kp = true; ch = '*'; break; |
| 645 |
case 0x47: kp = true; ch = '7'; break; |
| 646 |
case 0x48: kp = true; ch = '8'; break; |
| 647 |
case 0x49: kp = true; ch = '9'; break; |
| 648 |
case 0x4A: kp = true; ch = '-'; break; |
| 649 |
case 0x4B: kp = true; ch = '4'; break; |
| 650 |
case 0x4C: kp = true; ch = '5'; break; |
| 651 |
case 0x4D: kp = true; ch = '6'; break; |
| 652 |
case 0x4E: kp = true; ch = '+'; break; |
| 653 |
case 0x4F: kp = true; ch = '1'; break; |
| 654 |
case 0x50: kp = true; ch = '2'; break; |
| 655 |
case 0x51: kp = true; ch = '3'; break; |
| 656 |
case 0x52: kp = true; ch = '0'; break; |
| 657 |
case 0x53: kp = true; ch = '.'; break; |
| 658 |
case 0x95: |
| 659 |
if (mc) { |
| 660 |
kp = true; |
| 661 |
ch = '/'; |
| 662 |
} |
| 663 |
break; |
| 664 |
case 0x96: |
| 665 |
if (mc) { |
| 666 |
kp = true; |
| 667 |
ch = '*'; |
| 668 |
} |
| 669 |
break; |
| 670 |
case 0x77: |
| 671 |
if (mc) { |
| 672 |
kp = true; |
| 673 |
ch = '7'; |
| 674 |
} |
| 675 |
break; |
| 676 |
case 0x8D: |
| 677 |
if (mc) { |
| 678 |
kp = true; |
| 679 |
ch = '8'; |
| 680 |
} |
| 681 |
break; |
| 682 |
case 0x84: |
| 683 |
if (mc) { |
| 684 |
kp = true; |
| 685 |
ch = '9'; |
| 686 |
} |
| 687 |
break; |
| 688 |
case 0x8E: |
| 689 |
if (mc) { |
| 690 |
kp = true; |
| 691 |
ch = '-'; |
| 692 |
} |
| 693 |
break; |
| 694 |
case 0x73: |
| 695 |
if (mc) { |
| 696 |
kp = true; |
| 697 |
ch = '4'; |
| 698 |
} |
| 699 |
break; |
| 700 |
case 0x8F: |
| 701 |
if (mc) { |
| 702 |
kp = true; |
| 703 |
ch = '5'; |
| 704 |
} |
| 705 |
break; |
| 706 |
case 0x74: |
| 707 |
if (mc) { |
| 708 |
kp = true; |
| 709 |
ch = '6'; |
| 710 |
} |
| 711 |
break; |
| 712 |
case 0x90: |
| 713 |
if (mc) { |
| 714 |
kp = true; |
| 715 |
ch = '+'; |
| 716 |
} |
| 717 |
break; |
| 718 |
case 0x75: |
| 719 |
if (mc) { |
| 720 |
kp = true; |
| 721 |
ch = '1'; |
| 722 |
} |
| 723 |
break; |
| 724 |
case 0x91: |
| 725 |
if (mc) { |
| 726 |
kp = true; |
| 727 |
ch = '2'; |
| 728 |
} |
| 729 |
break; |
| 730 |
case 0x76: |
| 731 |
if (mc) { |
| 732 |
kp = true; |
| 733 |
ch = '3'; |
| 734 |
} |
| 735 |
break; |
| 736 |
case 0x92: |
| 737 |
if (mc) { |
| 738 |
kp = true; |
| 739 |
ch = '0'; |
| 740 |
} |
| 741 |
break; |
| 742 |
case 0x93: |
| 743 |
if (mc) { |
| 744 |
kp = true; |
| 745 |
ch = '.'; |
| 746 |
} |
| 747 |
break; |
| 748 |
default: break; |
| 749 |
} |
| 750 |
|
| 751 |
if (ch) { |
| 752 |
if (kp) mods |= KC_MOD_KEYPAD; |
| 753 |
if (ma) mods |= KC_MOD_ALT; |
| 754 |
if (ms) mods |= KC_MOD_SHIFT; |
| 755 |
Term_keypress(ch, mods); |
| 756 |
} |
| 757 |
|
| 758 |
/* Success */ |
| 759 |
return (0); |
| 760 |
} |
| 761 |
|
| 762 |
|
| 763 |
/* |
| 764 |
* Handle a "special request" |
| 765 |
* |
| 766 |
* The given parameters are "valid". |
| 767 |
*/ |
| 768 |
static errr Term_xtra_ibm(int n, int v) |
| 769 |
{ |
| 770 |
int i; |
| 771 |
|
| 772 |
/* Analyze the request */ |
| 773 |
switch (n) |
| 774 |
{ |
| 775 |
/* Make a "bell" noise */ |
| 776 |
case TERM_XTRA_NOISE: |
| 777 |
{ |
| 778 |
/* Make a bell noise */ |
| 779 |
(void)write(1, "\007", 1); |
| 780 |
|
| 781 |
/* Success */ |
| 782 |
return (0); |
| 783 |
} |
| 784 |
|
| 785 |
/* Set the cursor shape */ |
| 786 |
case TERM_XTRA_SHAPE: |
| 787 |
{ |
| 788 |
/* Set cursor shape */ |
| 789 |
curs_set(v); |
| 790 |
|
| 791 |
/* Success */ |
| 792 |
return (0); |
| 793 |
} |
| 794 |
|
| 795 |
/* Flush one line of output */ |
| 796 |
case TERM_XTRA_FROSH: |
| 797 |
{ |
| 798 |
|
| 799 |
#ifdef USE_VIRTUAL |
| 800 |
|
| 801 |
# ifdef USE_WAT |
| 802 |
|
| 803 |
/* Copy the virtual screen to the physical screen */ |
| 804 |
memcpy(PhysicalScreen + (v*160), VirtualScreen + (v*160), 160); |
| 805 |
|
| 806 |
# else /* USE_WAT */ |
| 807 |
|
| 808 |
/* Apply the virtual screen to the physical screen */ |
| 809 |
ScreenUpdateLine(VirtualScreen + ((v*cols) << 1), v); |
| 810 |
|
| 811 |
# endif /* USE_WAT */ |
| 812 |
|
| 813 |
#endif /* USE_VIRTUAL */ |
| 814 |
|
| 815 |
/* Success */ |
| 816 |
return (0); |
| 817 |
} |
| 818 |
|
| 819 |
/* Clear the screen */ |
| 820 |
case TERM_XTRA_CLEAR: |
| 821 |
{ |
| 822 |
|
| 823 |
#ifdef USE_CONIO |
| 824 |
|
| 825 |
/* Clear the screen */ |
| 826 |
clrscr(); |
| 827 |
|
| 828 |
#else /* USE_CONIO */ |
| 829 |
|
| 830 |
/* Clear each line (virtual or physical) */ |
| 831 |
for (i = 0; i < rows; i++) |
| 832 |
{ |
| 833 |
/* Clear the line */ |
| 834 |
memcpy((VirtualScreen + ((i*cols) << 1)), wiper, (cols << 1)); |
| 835 |
} |
| 836 |
|
| 837 |
# ifdef USE_VIRTUAL |
| 838 |
|
| 839 |
# ifdef USE_WAT |
| 840 |
|
| 841 |
/* Copy the virtual screen to the physical screen */ |
| 842 |
memcpy(PhysicalScreen, VirtualScreen, 25*80*2); |
| 843 |
|
| 844 |
# else /* USE_WAT */ |
| 845 |
|
| 846 |
/* Erase the physical screen */ |
| 847 |
ScreenClear(); |
| 848 |
|
| 849 |
# endif /* USE_WAT */ |
| 850 |
|
| 851 |
# endif /* USE_VIRTUAL */ |
| 852 |
|
| 853 |
#endif /* USE_CONIO */ |
| 854 |
|
| 855 |
/* Success */ |
| 856 |
return (0); |
| 857 |
} |
| 858 |
|
| 859 |
/* Process events */ |
| 860 |
case TERM_XTRA_EVENT: |
| 861 |
{ |
| 862 |
/* Process one event */ |
| 863 |
return (Term_xtra_ibm_event(v)); |
| 864 |
} |
| 865 |
|
| 866 |
/* Flush events */ |
| 867 |
case TERM_XTRA_FLUSH: |
| 868 |
{ |
| 869 |
/* Strip events */ |
| 870 |
while (!Term_xtra_ibm_event(false)) /* loop */; |
| 871 |
|
| 872 |
/* Success */ |
| 873 |
return (0); |
| 874 |
} |
| 875 |
|
| 876 |
/* React to global changes */ |
| 877 |
case TERM_XTRA_REACT: |
| 878 |
{ |
| 879 |
/* React to "color_table" changes */ |
| 880 |
return (Term_xtra_ibm_react()); |
| 881 |
} |
| 882 |
|
| 883 |
/* Delay for some milliseconds */ |
| 884 |
case TERM_XTRA_DELAY: |
| 885 |
{ |
| 886 |
/* Delay if needed */ |
| 887 |
if (v > 0) delay(v); |
| 888 |
|
| 889 |
/* Success */ |
| 890 |
return (0); |
| 891 |
} |
| 892 |
} |
| 893 |
|
| 894 |
/* Unknown request */ |
| 895 |
return (1); |
| 896 |
} |
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
/* |
| 901 |
* Move the cursor |
| 902 |
* |
| 903 |
* The given parameters are "valid". |
| 904 |
*/ |
| 905 |
static errr Term_curs_ibm(int x, int y) |
| 906 |
{ |
| 907 |
|
| 908 |
#ifdef USE_WAT |
| 909 |
|
| 910 |
# ifdef USE_CONIO |
| 911 |
|
| 912 |
/* Place the cursor */ |
| 913 |
gotoxy(x+1, y+1); |
| 914 |
|
| 915 |
# else /* USE_CONIO */ |
| 916 |
|
| 917 |
union REGS r; |
| 918 |
|
| 919 |
r.h.ah = 2; |
| 920 |
r.h.bh = 0; |
| 921 |
r.h.dl = x; |
| 922 |
r.h.dh = y; |
| 923 |
|
| 924 |
/* Place the cursor */ |
| 925 |
int86(0x10, &r, &r); |
| 926 |
|
| 927 |
# endif /* USE_CONIO */ |
| 928 |
|
| 929 |
#else /* USE_WAT */ |
| 930 |
|
| 931 |
/* Move the cursor */ |
| 932 |
ScreenSetCursor(y, x); |
| 933 |
|
| 934 |
#endif /* USE_WAT */ |
| 935 |
|
| 936 |
/* Success */ |
| 937 |
return (0); |
| 938 |
} |
| 939 |
|
| 940 |
|
| 941 |
/* |
| 942 |
* Erase a block of the screen |
| 943 |
* |
| 944 |
* The given parameters are "valid". |
| 945 |
*/ |
| 946 |
static errr Term_wipe_ibm(int x, int y, int n) |
| 947 |
{ |
| 948 |
|
| 949 |
#ifdef USE_CONIO |
| 950 |
|
| 951 |
/* Wipe the region */ |
| 952 |
window(x+1, y+1, x+n, y+1); |
| 953 |
clrscr(); |
| 954 |
window(1, 1, cols, rows); |
| 955 |
|
| 956 |
#else /* USE_CONIO */ |
| 957 |
|
| 958 |
/* Wipe part of the virtual (or physical) screen */ |
| 959 |
memcpy(VirtualScreen + ((cols*y + x)<<1), wiper, n<<1); |
| 960 |
|
| 961 |
#endif /* USE_CONIO */ |
| 962 |
|
| 963 |
/* Success */ |
| 964 |
return (0); |
| 965 |
} |
| 966 |
|
| 967 |
|
| 968 |
/* |
| 969 |
* Place some text on the screen using an attribute |
| 970 |
* |
| 971 |
* The given parameters are "valid". Be careful with "a". |
| 972 |
* |
| 973 |
* The string "cp" has length "n" and is NOT null-terminated. |
| 974 |
*/ |
| 975 |
static errr Term_text_ibm(int x, int y, int n, int a, const wchar_t *cp) |
| 976 |
{ |
| 977 |
register int i; |
| 978 |
register uint8_t attr; |
| 979 |
register uint8_t *dest; |
| 980 |
|
| 981 |
/* Handle "complex" color */ |
| 982 |
if (use_color_complex) |
| 983 |
{ |
| 984 |
/* Extract a color index */ |
| 985 |
attr = (uint8_t)(get_ext_color(a)); |
| 986 |
} |
| 987 |
|
| 988 |
/* Handle "simple" color */ |
| 989 |
else |
| 990 |
{ |
| 991 |
/* Extract a color value */ |
| 992 |
attr = ibm_color_simple[get_ext_color(a)]; |
| 993 |
} |
| 994 |
|
| 995 |
#ifdef USE_CONIO |
| 996 |
|
| 997 |
/* Place the cursor */ |
| 998 |
gotoxy(x+1, y+1); |
| 999 |
|
| 1000 |
/* Set the attribute */ |
| 1001 |
textattr(attr); |
| 1002 |
|
| 1003 |
/* Dump the text */ |
| 1004 |
for (i = 0; i < n; i++) { |
| 1005 |
if (cp[i] < 0x100) { |
| 1006 |
putch(cp[i]); |
| 1007 |
} |
| 1008 |
} |
| 1009 |
|
| 1010 |
#else /* USE_CONIO */ |
| 1011 |
|
| 1012 |
/* Access the virtual (or physical) screen */ |
| 1013 |
dest = VirtualScreen + (((cols * y) + x) << 1); |
| 1014 |
|
| 1015 |
/* Save the data */ |
| 1016 |
for (i = 0; i < n; i++) |
| 1017 |
{ |
| 1018 |
/* Apply */ |
| 1019 |
*dest++ = cp[i]; |
| 1020 |
*dest++ = attr; |
| 1021 |
} |
| 1022 |
|
| 1023 |
#endif /* USE_CONIO */ |
| 1024 |
|
| 1025 |
/* Success */ |
| 1026 |
return (0); |
| 1027 |
} |
| 1028 |
|
| 1029 |
|
| 1030 |
/* |
| 1031 |
* Place some attr/char pairs on the screen |
| 1032 |
* |
| 1033 |
* The given parameters are "valid". |
| 1034 |
*/ |
| 1035 |
static errr Term_pict_ibm(int x, int y, int n, const int *ap, |
| 1036 |
const wchar_t *cp, const int *tap, const wchar_t *tcp) |
| 1037 |
{ |
| 1038 |
register int i; |
| 1039 |
register uint8_t attr; |
| 1040 |
register uint8_t *dest; |
| 1041 |
|
| 1042 |
/* Unused parameters */ |
| 1043 |
(void)tap; |
| 1044 |
(void)tcp; |
| 1045 |
|
| 1046 |
#ifdef USE_CONIO |
| 1047 |
|
| 1048 |
/* Place the cursor */ |
| 1049 |
gotoxy(x+1, y+1); |
| 1050 |
|
| 1051 |
/* Dump the text */ |
| 1052 |
for (i = 0; i < n; i++) |
| 1053 |
{ |
| 1054 |
/* Handle "complex" color */ |
| 1055 |
if (use_color_complex) |
| 1056 |
{ |
| 1057 |
/* Extract a color index */ |
| 1058 |
attr = (uint8_t)(get_ext_color(ap[i])); |
| 1059 |
} |
| 1060 |
|
| 1061 |
/* Handle "simple" color */ |
| 1062 |
else |
| 1063 |
{ |
| 1064 |
/* Extract a color value */ |
| 1065 |
attr = ibm_color_simple[get_ext_color(ap[i])]; |
| 1066 |
} |
| 1067 |
|
| 1068 |
/* Set the attribute */ |
| 1069 |
textattr(attr); |
| 1070 |
|
| 1071 |
/* Dump the char */ |
| 1072 |
if (cp[i] < 0x100) { |
| 1073 |
putch(cp[i]); |
| 1074 |
} |
| 1075 |
} |
| 1076 |
|
| 1077 |
#else /* USE_CONIO */ |
| 1078 |
|
| 1079 |
/* Access the virtual (or physical) screen */ |
| 1080 |
dest = VirtualScreen + (((cols * y) + x) << 1); |
| 1081 |
|
| 1082 |
/* Save the data */ |
| 1083 |
for (i = 0; i < n; i++) |
| 1084 |
{ |
| 1085 |
/* Handle "complex" color */ |
| 1086 |
if (use_color_complex) |
| 1087 |
{ |
| 1088 |
/* Extract a color index */ |
| 1089 |
attr = (uint8_t)(get_ext_color(ap[i])); |
| 1090 |
} |
| 1091 |
|
| 1092 |
/* Handle "simple" color */ |
| 1093 |
else |
| 1094 |
{ |
| 1095 |
/* Extract a color value */ |
| 1096 |
attr = ibm_color_simple[get_ext_color(ap[i])]; |
| 1097 |
} |
| 1098 |
|
| 1099 |
/* Apply */ |
| 1100 |
*dest++ = cp[i]; |
| 1101 |
*dest++ = attr; |
| 1102 |
} |
| 1103 |
|
| 1104 |
#endif /* USE_CONIO */ |
| 1105 |
|
| 1106 |
/* Success */ |
| 1107 |
return (0); |
| 1108 |
} |
| 1109 |
|
| 1110 |
|
| 1111 |
/* |
| 1112 |
* Init a Term |
| 1113 |
*/ |
| 1114 |
static void Term_init_ibm(term *t) |
| 1115 |
{ |
| 1116 |
/* Unused parameter */ |
| 1117 |
(void)t; |
| 1118 |
|
| 1119 |
/* XXX Nothing */ |
| 1120 |
} |
| 1121 |
|
| 1122 |
|
| 1123 |
/* |
| 1124 |
* Nuke a Term |
| 1125 |
*/ |
| 1126 |
static void Term_nuke_ibm(term *t) |
| 1127 |
{ |
| 1128 |
#ifdef USE_WAT |
| 1129 |
|
| 1130 |
/* Nothing */ |
| 1131 |
|
| 1132 |
#else /* USE_WAT */ |
| 1133 |
|
| 1134 |
union REGS r; |
| 1135 |
|
| 1136 |
#endif /* USE_WAT */ |
| 1137 |
|
| 1138 |
/* Unused parameter */ |
| 1139 |
(void)t; |
| 1140 |
|
| 1141 |
/* Move the cursor to the bottom of the screen */ |
| 1142 |
Term_curs_ibm(0, rows-1); |
| 1143 |
|
| 1144 |
#ifdef USE_WAT |
| 1145 |
|
| 1146 |
/* Restore the original video mode */ |
| 1147 |
_setvideomode(_DEFAULTMODE); |
| 1148 |
|
| 1149 |
#else /* USE_WAT */ |
| 1150 |
|
| 1151 |
/* Restore the original video mode */ |
| 1152 |
r.h.ah = 0x00; |
| 1153 |
r.h.al = 0x03; |
| 1154 |
int86(0x10, &r, &r); |
| 1155 |
|
| 1156 |
#endif /* USE_WAT */ |
| 1157 |
|
| 1158 |
/* Make the cursor visible */ |
| 1159 |
curs_set(1); |
| 1160 |
} |
| 1161 |
|
| 1162 |
int Term_iswprint_ibm(wint_t wc) |
| 1163 |
{ |
| 1164 |
int retval; |
| 1165 |
retval = (wc < 0x100); |
| 1166 |
return retval; |
| 1167 |
} |
| 1168 |
|
| 1169 |
wchar_t *Term_wcschr_ibm(const wchar_t *s, wchar_t c) { |
| 1170 |
wchar_t cc = c; |
| 1171 |
|
| 1172 |
while (*s) { |
| 1173 |
if (*s == cc) { |
| 1174 |
return unconst(s, wchar_t *); |
| 1175 |
} |
| 1176 |
s++; |
| 1177 |
} |
| 1178 |
|
| 1179 |
if (cc == 0) { |
| 1180 |
return unconst(s, wchar_t *); |
| 1181 |
} |
| 1182 |
|
| 1183 |
return 0; |
| 1184 |
} |
| 1185 |
|
| 1186 |
size_t Term_wcslen_ibm(const wchar_t *s) { |
| 1187 |
const wchar_t *p; |
| 1188 |
|
| 1189 |
if (s == 0) { |
| 1190 |
return 0; |
| 1191 |
} |
| 1192 |
|
| 1193 |
for (p = s; *p; ++p); |
| 1194 |
|
| 1195 |
return p - s; |
| 1196 |
} |
| 1197 |
|
| 1198 |
#ifdef USE_GRAPHICS |
| 1199 |
|
| 1200 |
#ifdef USE_286 |
| 1201 |
|
| 1202 |
/* |
| 1203 |
* In 286 mode we don't need to worry about translating from a 32bit |
| 1204 |
* pointer to a 16 bit pointer so we just call the interrupt function |
| 1205 |
* |
| 1206 |
* Note the use of "intr()" instead of "int86()" so we can pass |
| 1207 |
* segment registers. |
| 1208 |
*/ |
| 1209 |
void enable_graphic_font(void *font) |
| 1210 |
{ |
| 1211 |
union REGPACK regs = |
| 1212 |
{0}; |
| 1213 |
|
| 1214 |
regs.h.ah = 0x11; /* Text font function */ |
| 1215 |
regs.h.bh = 0x10; /* Size of a character -- 16 bytes */ |
| 1216 |
regs.h.cl = 0xFF; /* Last character in font */ |
| 1217 |
regs.x.es = FP_SEG(font); /* Pointer to font */ |
| 1218 |
regs.x.bp = FP_OFF(font); |
| 1219 |
intr(0x10, ®s); |
| 1220 |
}; |
| 1221 |
|
| 1222 |
#else /* USE_286 */ |
| 1223 |
|
| 1224 |
#ifdef USE_WAT |
| 1225 |
|
| 1226 |
/* |
| 1227 |
* This structure is used by the DMPI function to hold registers when |
| 1228 |
* doing a real mode interrupt call. (Stolen from the DJGPP <dpmi.h> |
| 1229 |
* header file). |
| 1230 |
*/ |
| 1231 |
|
| 1232 |
typedef union |
| 1233 |
{ |
| 1234 |
struct |
| 1235 |
{ |
| 1236 |
unsigned long edi; |
| 1237 |
unsigned long esi; |
| 1238 |
unsigned long ebp; |
| 1239 |
unsigned long res; |
| 1240 |
unsigned long ebx; |
| 1241 |
unsigned long edx; |
| 1242 |
unsigned long ecx; |
| 1243 |
unsigned long eax; |
| 1244 |
} d; |
| 1245 |
struct |
| 1246 |
{ |
| 1247 |
unsigned short di, di_hi; |
| 1248 |
unsigned short si, si_hi; |
| 1249 |
unsigned short bp, bp_hi; |
| 1250 |
unsigned short res, res_hi; |
| 1251 |
unsigned short bx, bx_hi; |
| 1252 |
unsigned short dx, dx_hi; |
| 1253 |
unsigned short cx, cx_hi; |
| 1254 |
unsigned short ax, ax_hi; |
| 1255 |
unsigned short flags; |
| 1256 |
unsigned short es; |
| 1257 |
unsigned short ds; |
| 1258 |
unsigned short fs; |
| 1259 |
unsigned short gs; |
| 1260 |
unsigned short ip; |
| 1261 |
unsigned short cs; |
| 1262 |
unsigned short sp; |
| 1263 |
unsigned short ss; |
| 1264 |
} x; |
| 1265 |
struct |
| 1266 |
{ |
| 1267 |
unsigned char edi[4]; |
| 1268 |
unsigned char esi[4]; |
| 1269 |
unsigned char ebp[4]; |
| 1270 |
unsigned char res[4]; |
| 1271 |
unsigned char bl, bh, ebx_b2, ebx_b3; |
| 1272 |
unsigned char dl, dh, edx_b2, edx_b3; |
| 1273 |
unsigned char cl, ch, ecx_b2, ecx_b3; |
| 1274 |
unsigned char al, ah, eax_b2, eax_b3; |
| 1275 |
} h; |
| 1276 |
} __dpmi_regs; |
| 1277 |
|
| 1278 |
unsigned __dpmi_allocate_dos_memory(int size, unsigned *selector) |
| 1279 |
{ |
| 1280 |
union REGPACK regs = |
| 1281 |
{0}; |
| 1282 |
|
| 1283 |
regs.w.ax = 0x100; /* DPMI function -- allocate low memory */ |
| 1284 |
regs.w.bx = size; /* Number of Paragraphs to allocate */ |
| 1285 |
intr(0x31, ®s); /* DPMI interface */ |
| 1286 |
|
| 1287 |
*selector = regs.w.dx; |
| 1288 |
return (regs.w.ax); |
| 1289 |
}; |
| 1290 |
|
| 1291 |
void __dpmi_free_dos_memory(unsigned sel) |
| 1292 |
{ |
| 1293 |
union REGPACK regs = |
| 1294 |
{0}; |
| 1295 |
|
| 1296 |
regs.w.ax = 0x101; /* DPMI function -- free low memory */ |
| 1297 |
regs.x.edx = sel; /* PM selector for memory block */ |
| 1298 |
intr(0x31, ®s); /* DPMI interface */ |
| 1299 |
}; |
| 1300 |
|
| 1301 |
void __dpmi_int(int intno, __dpmi_regs *dblock) |
| 1302 |
{ |
| 1303 |
union REGPACK regs = |
| 1304 |
{0}; |
| 1305 |
|
| 1306 |
regs.w.ax = 0x300; /* DPMI function -- real mode interrupt */ |
| 1307 |
regs.h.bl = intno; /* interrupt 0x10 */ |
| 1308 |
regs.x.edi = FP_OFF(dblock); /* Pointer to dblock (offset and segment) */ |
| 1309 |
regs.x.es = FP_SEG(dblock); |
| 1310 |
intr(0x31, ®s); /* DPMI interface */ |
| 1311 |
}; |
| 1312 |
|
| 1313 |
unsigned short __dpmi_sel = 0x0000; |
| 1314 |
#define _farsetsel(x) __dpmi_sel=(x) |
| 1315 |
extern void _farnspokeb(unsigned long offset, unsigned char value); |
| 1316 |
#pragma aux _farnspokeb = \ |
| 1317 |
"push fs" \ |
| 1318 |
"mov fs,__dpmi_sel" \ |
| 1319 |
"mov fs:[eax],bl" \ |
| 1320 |
"pop fs" \ |
| 1321 |
parm [eax] [bl]; |
| 1322 |
|
| 1323 |
#else /* USE_WAT */ |
| 1324 |
|
| 1325 |
#include <dpmi.h> |
| 1326 |
#include <go32.h> |
| 1327 |
#include <sys/farptr.h> |
| 1328 |
|
| 1329 |
#endif /* USE_WAT */ |
| 1330 |
|
| 1331 |
|
| 1332 |
/* |
| 1333 |
* Since you cannot send 32bit pointers to a 16bit interrupt handler |
| 1334 |
* and the video BIOS wants a (16bit) pointer to the font, we have |
| 1335 |
* to allocate a block of dos memory, copy the font into it, then |
| 1336 |
* translate a 32bit pointer into a 16bit pointer to that block. |
| 1337 |
* |
| 1338 |
* DPMI - Dos Protected Mode Interface provides functions that let |
| 1339 |
* us do that. |
| 1340 |
*/ |
| 1341 |
void enable_graphic_font(const char *font) |
| 1342 |
{ |
| 1343 |
__dpmi_regs dblock = {{0}}; |
| 1344 |
|
| 1345 |
unsigned int seg, i; |
| 1346 |
int sel; |
| 1347 |
|
| 1348 |
/* |
| 1349 |
* Allocate a block of memory 4096 bytes big in `low memory' so a real |
| 1350 |
* mode interrupt can access it. Real mode pointer is returned as seg:0 |
| 1351 |
* Protected mode pointer is sel:0. |
| 1352 |
*/ |
| 1353 |
seg = __dpmi_allocate_dos_memory(256, &sel); |
| 1354 |
|
| 1355 |
/* Copy the information into low memory buffer, by copying one byte at |
| 1356 |
* a time. According to the info in <sys/farptr.h>, the functions |
| 1357 |
* _farsetsel() and _farnspokeb() will optimise away completely |
| 1358 |
*/ |
| 1359 |
_farsetsel(sel); /* Set the selector to write to */ |
| 1360 |
for (i = 0; i<4096; i++) |
| 1361 |
{ |
| 1362 |
_farnspokeb(i, *font++); /* Copy 1 byte into low (far) memory */ |
| 1363 |
} |
| 1364 |
|
| 1365 |
/* |
| 1366 |
* Now we use DPMI as a jumper to call the real mode interrupt. This |
| 1367 |
* is needed because loading `es' while in protected mode with a real |
| 1368 |
* mode pointer will cause an Protection Fault and calling the interrupt |
| 1369 |
* directly using the protected mode pointer will result in garbage |
| 1370 |
* being received by the interrupt routine |
| 1371 |
*/ |
| 1372 |
dblock.d.eax = 0x1100; /* BIOS function -- set font */ |
| 1373 |
dblock.d.ebx = 0x1000; /* bh = size of a letter; bl = 0 (reserved) */ |
| 1374 |
dblock.d.ecx = 0x00FF; /* Last character in font */ |
| 1375 |
dblock.x.es = seg; /* Pointer to font segment */ |
| 1376 |
dblock.d.ebp = 0x0000; /* Pointer to font offset */ |
| 1377 |
|
| 1378 |
__dpmi_int(0x10, &dblock); |
| 1379 |
|
| 1380 |
/* We're done with the low memory, free it */ |
| 1381 |
__dpmi_free_dos_memory(sel); |
| 1382 |
} |
| 1383 |
|
| 1384 |
#endif /* USE_286 */ |
| 1385 |
|
| 1386 |
#endif /* ALLOW_GRAPH */ |
| 1387 |
|
| 1388 |
|
| 1389 |
const char help_ibm[] = "IBM Visual Display Support"; |
| 1390 |
|
| 1391 |
|
| 1392 |
/* |
| 1393 |
* Initialize the IBM "visual module" |
| 1394 |
* |
| 1395 |
* Hack -- we assume that "blank space" should be "white space" |
| 1396 |
* (and not "black space" which might make more sense). |
| 1397 |
* |
| 1398 |
* Note the use of "((x << 2) | (x >> 4))" to "expand" a 6 bit value |
| 1399 |
* into an 8 bit value, without losing much precision, by using the 2 |
| 1400 |
* most significant bits as the least significant bits in the new value. |
| 1401 |
*/ |
| 1402 |
errr init_ibm(int argc, char **argv) |
| 1403 |
{ |
| 1404 |
int i; |
| 1405 |
int mode; |
| 1406 |
|
| 1407 |
term *t = &term_screen_body; |
| 1408 |
|
| 1409 |
union REGS r; |
| 1410 |
|
| 1411 |
/* Unused parameters */ |
| 1412 |
(void)argc; |
| 1413 |
(void)argv; |
| 1414 |
|
| 1415 |
/* Check for "Windows" */ |
| 1416 |
if (getenv("windir")) |
| 1417 |
{ |
| 1418 |
r.h.ah = 0x16; /* Windows API Call -- Set device focus */ |
| 1419 |
r.h.al = 0x8B; /* Causes Dos boxes to become fullscreen */ |
| 1420 |
r.h.bh = r.h.bl = 0x00; /* 0x0000 = current Dos box */ |
| 1421 |
int86(0x2F, &r, &r); /* Call the Windows API */ |
| 1422 |
}; |
| 1423 |
|
| 1424 |
/* Initialize "color_table" */ |
| 1425 |
for (i = 0; i < 16; i++) |
| 1426 |
{ |
| 1427 |
long rv, gv, bv; |
| 1428 |
|
| 1429 |
/* Extract desired values */ |
| 1430 |
rv = angband_color_table[i][1] >> 2; |
| 1431 |
gv = angband_color_table[i][2] >> 2; |
| 1432 |
bv = angband_color_table[i][3] >> 2; |
| 1433 |
|
| 1434 |
/* Extract the "complex" codes */ |
| 1435 |
ibm_color_complex[i] = ((rv) | (gv << 8) | (bv << 16)); |
| 1436 |
|
| 1437 |
/* Save the "simple" codes */ |
| 1438 |
angband_color_table[i][0] = ibm_color_simple[i]; |
| 1439 |
} |
| 1440 |
|
| 1441 |
#ifdef USE_WAT |
| 1442 |
|
| 1443 |
/* Set the video mode */ |
| 1444 |
if (_setvideomode(_VRES16COLOR)) |
| 1445 |
{ |
| 1446 |
mode = 0x13; |
| 1447 |
} |
| 1448 |
|
| 1449 |
/* Wimpy monitor */ |
| 1450 |
else |
| 1451 |
{ |
| 1452 |
mode = 0x03; |
| 1453 |
} |
| 1454 |
|
| 1455 |
/* Force 25 line mode */ |
| 1456 |
_setvideomode(_TEXTC80); |
| 1457 |
_settextrows(25); |
| 1458 |
|
| 1459 |
#else /* USE_WAT */ |
| 1460 |
|
| 1461 |
/* Set video mode */ |
| 1462 |
r.h.ah = 0x00; |
| 1463 |
r.h.al = 0x13; /* VGA only mode */ |
| 1464 |
int86(0x10, &r, &r); |
| 1465 |
|
| 1466 |
/* Get video mode */ |
| 1467 |
r.h.ah = 0x0F; |
| 1468 |
int86(0x10, &r, &r); |
| 1469 |
mode = r.h.al; |
| 1470 |
|
| 1471 |
/* Set video mode */ |
| 1472 |
r.h.ah = 0x00; |
| 1473 |
r.h.al = 0x03; /* Color text mode */ |
| 1474 |
int86(0x10, &r, &r); |
| 1475 |
|
| 1476 |
#endif /* USE_WAT */ |
| 1477 |
|
| 1478 |
/* Check video mode */ |
| 1479 |
if (mode == 0x13) |
| 1480 |
{ |
| 1481 |
/* Remember the mode */ |
| 1482 |
use_color_complex = true; |
| 1483 |
|
| 1484 |
/* Instantiate the color set */ |
| 1485 |
activate_color_complex(); |
| 1486 |
} |
| 1487 |
|
| 1488 |
#ifdef USE_GRAPHICS |
| 1489 |
|
| 1490 |
/* Try to activate bitmap graphics */ |
| 1491 |
if (arg_graphics && use_color_complex) |
| 1492 |
{ |
| 1493 |
FILE *f; |
| 1494 |
|
| 1495 |
char buf[4096]; |
| 1496 |
|
| 1497 |
/* Build the filename */ |
| 1498 |
path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA, "angband.fnt"); |
| 1499 |
|
| 1500 |
/* Open the file */ |
| 1501 |
f = fopen(buf, "rb"); |
| 1502 |
|
| 1503 |
/* Okay */ |
| 1504 |
if (f) |
| 1505 |
{ |
| 1506 |
/* Load the bitmap data */ |
| 1507 |
if (fread(buf, 1, sizeof(buf), f) != 4096) |
| 1508 |
{ |
| 1509 |
quit("Corrupt 'angband.fnt' file"); |
| 1510 |
} |
| 1511 |
|
| 1512 |
/* Close the file */ |
| 1513 |
fclose(f); |
| 1514 |
|
| 1515 |
/* Enable graphics */ |
| 1516 |
enable_graphic_font(buf); |
| 1517 |
|
| 1518 |
/* Enable colors (again) */ |
| 1519 |
activate_color_complex(); |
| 1520 |
|
| 1521 |
/* Use graphics */ |
| 1522 |
use_graphics = GRAPHICS_ORIGINAL; |
| 1523 |
} |
| 1524 |
} |
| 1525 |
|
| 1526 |
#endif |
| 1527 |
|
| 1528 |
#ifdef USE_CONIO |
| 1529 |
#else /* USE_CONIO */ |
| 1530 |
|
| 1531 |
/* Build a "wiper line" */ |
| 1532 |
for (i = 0; i < 80; i++) |
| 1533 |
{ |
| 1534 |
/* Space */ |
| 1535 |
wiper[2*i] = ' '; |
| 1536 |
|
| 1537 |
/* Black */ |
| 1538 |
wiper[2*i+1] = COLOUR_WHITE; |
| 1539 |
} |
| 1540 |
|
| 1541 |
#endif /* USE_CONIO */ |
| 1542 |
|
| 1543 |
|
| 1544 |
#ifdef USE_VIRTUAL |
| 1545 |
|
| 1546 |
/* Make the virtual screen */ |
| 1547 |
VirtualScreen = mem_zalloc(rows * cols * 2 * sizeof(uint8_t)); |
| 1548 |
|
| 1549 |
#endif /* USE_VIRTUAL */ |
| 1550 |
|
| 1551 |
|
| 1552 |
/* Erase the screen */ |
| 1553 |
Term_xtra_ibm(TERM_XTRA_CLEAR, 0); |
| 1554 |
|
| 1555 |
|
| 1556 |
/* Place the cursor */ |
| 1557 |
Term_curs_ibm(0, 0); |
| 1558 |
|
| 1559 |
|
| 1560 |
/* Access the "default" cursor info */ |
| 1561 |
r.h.ah = 3; |
| 1562 |
r.h.bh = 0; |
| 1563 |
|
| 1564 |
/* Make the call */ |
| 1565 |
int86(0x10, &r, &r); |
| 1566 |
|
| 1567 |
/* Extract the standard cursor info */ |
| 1568 |
saved_cur_v = 1; |
| 1569 |
saved_cur_high = r.h.ch; |
| 1570 |
saved_cur_low = r.h.cl; |
| 1571 |
|
| 1572 |
|
| 1573 |
/* Initialize the term */ |
| 1574 |
term_init(t, 80, 24, 256); |
| 1575 |
|
| 1576 |
#ifdef USE_CONIO |
| 1577 |
#else /* USE_CONIO */ |
| 1578 |
|
| 1579 |
/* Always use "Term_pict()" */ |
| 1580 |
t->always_pict = true; |
| 1581 |
|
| 1582 |
#endif /* USE_CONIO */ |
| 1583 |
|
| 1584 |
/* Prepare the init/nuke hooks */ |
| 1585 |
t->init_hook = Term_init_ibm; |
| 1586 |
t->nuke_hook = Term_nuke_ibm; |
| 1587 |
|
| 1588 |
/* Connect the hooks */ |
| 1589 |
t->xtra_hook = Term_xtra_ibm; |
| 1590 |
t->curs_hook = Term_curs_ibm; |
| 1591 |
t->wipe_hook = Term_wipe_ibm; |
| 1592 |
t->text_hook = Term_text_ibm; |
| 1593 |
t->pict_hook = Term_pict_ibm; |
| 1594 |
text_iswprint_hook = Term_iswprint_ibm; |
| 1595 |
text_wcschr_hook = Term_wcschr_ibm; |
| 1596 |
text_wcslen_hook = Term_wcslen_ibm; |
| 1597 |
|
| 1598 |
/* Save it */ |
| 1599 |
term_screen = t; |
| 1600 |
|
| 1601 |
/* Activate it */ |
| 1602 |
Term_activate(term_screen); |
| 1603 |
|
| 1604 |
/* Success */ |
| 1605 |
return 0; |
| 1606 |
} |
| 1607 |
|
| 1608 |
|
| 1609 |
#endif /* USE_IBM */ |
| 1610 |
|