1 /* SCCS Id: @(#)vidtxt.c 3.4 1994/04/04 */
2 /* Copyright (c) NetHack PC Development Team 1993 */
3 /* NetHack may be freely redistributed. See license for details. */
6 * vidtxt.c - Textmode video hardware support (BIOS and DJGPPFAST)
9 * Initial Creation M. Allison 93/04/04
10 * Add djgpp support K. Smolkowski 93/04/26
11 * Add runtime monoadapter check M. Allison 93/05/09
25 #pragma warning(disable:4018) /* signed/unsigned mismatch */
26 #pragma warning(disable:4127) /* conditional expression is constant */
27 #pragma warning(disable:4131) /* old style declarator */
28 #pragma warning(disable:4305) /* prevents complaints with MK_FP */
29 #pragma warning(disable:4309) /* initializing */
30 #pragma warning(disable:4759) /* prevents complaints with MK_FP */
34 /* void FDECL(txt_xputc,(char, int)); */ /* write out character (and attribute) */
36 extern int attrib_text_normal; /* text mode normal attribute */
37 extern int attrib_gr_normal; /* graphics mode normal attribute */
38 extern int attrib_text_intense; /* text mode intense attribute */
39 extern int attrib_gr_intense; /* graphics mode intense attribute */
55 regs.h.ah = SENSEMODE;
56 (void) int86(CRT_BIOS, ®s, ®s);
58 CO = (regs.h.al & 0x02) ? 40 : 80;
59 LI = (regs.h.al & 0x01) ? 20 : 25;
62 regs.x.bx = 0; /* current ROM BIOS font */
63 regs.h.dl = 24; /* default row count */
64 /* in case no EGA/MCGA/VGA */
65 (void) int86(VIDEO_BIOS, ®s, ®s); /* Get Font Information */
67 /* MDA/CGA/PCjr ignore INT 10h, Function 11h, but since we
68 * cleverly loaded up DL with the default, everything's fine.
70 * Otherwise, DL now contains rows - 1. Also, CX contains the
71 * points (bytes per character) and ES:BP points to the font
76 (void) int86(VIDEO_BIOS, ®s, ®s); /* Get Video Mode */
78 /* This goes back all the way to the original PC. Completely
79 * safe. AH contains # of columns, AL contains display mode,
80 * and BH contains the active display page.
90 * --------------------------------------------------------------
91 * The rest of this file is only compiled if NO_TERMS is defined.
92 * --------------------------------------------------------------
96 /* #include "wintty.h" */
98 # ifdef SCREEN_DJGPPFAST
103 void FDECL(txt_gotoxy, (int,int));
105 # if defined(SCREEN_BIOS) && !defined(PC9800)
106 void FDECL(txt_get_cursor, (int *, int *));
109 # ifdef SCREEN_DJGPPFAST
110 #define txt_get_cursor(x,y) ScreenGetCursor(y,x)
113 extern int g_attribute; /* Current attribute to use */
114 extern int monoflag; /* 0 = not monochrome, else monochrome */
123 regs.h.dl = 0x01; /* one column */
124 regs.h.ah = CURSOR_LEFT;
125 regs.h.cl = DIRECT_CON_IO;
127 int86(DOS_EXT_FUNC, ®s, ®s);
132 txt_get_cursor(&col, &row);
133 if (col > 0) col = col-1;
143 if (flags.silent) return;
144 regs.h.dl = 0x07; /* bell */
145 regs.h.ah = 0x02; /* Character Output function */
146 (void) int86(DOSCALL, ®s, ®s);
153 /* djgpp provides ScreenClear(), but in version 1.09 it is broken
154 * so for now we just use the BIOS Routines
159 regs.h.dl = attr98[attrib_text_normal];
161 regs.h.cl = DIRECT_CON_IO;
163 (void) int86(DOS_EXT_FUNC, ®s, ®s);
165 regs.h.dl = 0x02; /* clear whole screen */
166 regs.h.ah = SCREEN_CLEAR;
167 regs.h.cl = DIRECT_CON_IO;
169 (void) int86(DOS_EXT_FUNC, ®s, ®s);
171 regs.h.dl = (char)(CO - 1); /* columns */
172 regs.h.dh = (char)(LI - 1); /* rows */
173 regs.x.cx = 0; /* CL,CH = x,y of upper left */
176 regs.h.bh = (char)attrib_text_normal;
177 regs.h.ah = (char)SCROLL;
178 /* DL,DH = x,y of lower rt */
179 (void) int86(VIDEO_BIOS, ®s, ®s); /* Scroll or init window */
185 txt_cl_end(col,row) /* clear to end of line */
194 regs.h.dl = attr98[attrib_text_normal];
196 regs.h.cl = DIRECT_CON_IO;
198 (void) int86(DOS_EXT_FUNC, ®s, ®s);
200 regs.h.dl = 0x00; /* clear to end of line */
201 regs.h.ah = LINE_CLEAR;
202 regs.h.cl = DIRECT_CON_IO;
204 (void) int86(DOS_EXT_FUNC, ®s, ®s);
208 regs.h.ah = PUTCHARATT; /* write attribute & character */
209 regs.h.al = ' '; /* character */
210 regs.h.bh = 0; /* display page */
212 regs.h.bl = (char)attrib_text_normal;
215 (void) int86(VIDEO_BIOS, ®s, ®s); /* write attribute
221 txt_cl_eos() /* clear to end of screen */
229 regs.h.dl = attr98[attrib_text_normal];
231 regs.h.cl = DIRECT_CON_IO;
233 (void) int86(DOS_EXT_FUNC, ®s, ®s);
235 regs.h.dl = 0x00; /* clear to end of screen */
236 regs.h.ah = SCREEN_CLEAR;
237 regs.h.cl = DIRECT_CON_IO;
239 (void) int86(DOS_EXT_FUNC, ®s, ®s);
241 txt_get_cursor(&col, &row);
242 txt_cl_end(col,row); /* clear to end of line */
243 txt_gotoxy(0,(row < (LI-1) ? row+1 : (LI-1)));
244 regs.h.dl = (char) (CO-1); /* X of lower right */
245 regs.h.dh = (char) (LI-1); /* Y of lower right */
246 regs.h.cl = 0; /* X of upper left */
247 /* Y (row) of upper left */
248 regs.h.ch = (char) (row < (LI-1) ? row+1 :(LI-1));
252 regs.h.bh = (char)attrib_text_normal;
254 (void) int86(VIDEO_BIOS, ®s, ®s); /* Scroll or initialize window */
261 txt_startup(wid, hgt)
268 attrib_gr_normal = attrib_text_normal;
269 attrib_gr_intense = attrib_text_intense;
270 g_attribute = attrib_text_normal; /* Give it a starting value */
275 * Screen output routines (these are heavily used).
277 * These are the 3 routines used to place information on the screen
278 * in the NO_TERMS PC tty port of NetHack. These are the routines
279 * that get called by routines in other NetHack source files (such
280 * as those in win/tty).
282 * txt_xputs - Writes a c null terminated string at the current location.
283 * Depending on compile options, this could just be a series
284 * of repeated calls to xputc() for each character.
285 * txt_xputc - Writes a single character at the current location. Since
286 * various places in the code assume that control characters
287 * can be used to control, we are forced to interpret some of
288 * the more common ones, in order to keep things looking correct.
291 * wintty.h uses macros to redefine common output functions
292 * such as puts, putc, putchar, so that they get steered into
293 * either xputs (for strings) or xputc (for single characters).
294 * References to puts, putc, and putchar in other source files
295 * (that include wintty.h) are actually using these routines.
306 if (s != (char *)0) {
310 txt_xputc(c,g_attribute);
311 if (col < (CO-1)) col++;
318 txt_xputc(ch,attr) /* write out character (and attribute) */
325 regs.h.dl = attr98[attr];
327 regs.h.cl = DIRECT_CON_IO;
329 (void) int86(DOS_EXT_FUNC, ®s, ®s);
334 regs.h.cl = DIRECT_CON_IO;
336 (void) int86(DOS_EXT_FUNC, ®s, ®s);
340 regs.h.cl = DIRECT_CON_IO;
342 (void) int86(DOS_EXT_FUNC, ®s, ®s);
349 txt_get_cursor(&col,&row);
358 # ifdef SCREEN_DJGPPFAST
359 ScreenPutChar((int)ch,attr,col,row);
362 regs.h.ah = PUTCHARATT; /* write att & character */
363 regs.h.al = ch; /* character */
364 regs.h.bh = 0; /* display page */
365 regs.h.bl = (char)attr; /* BL = attribute */
366 regs.x.cx = 1; /* one character */
367 (void) int86(VIDEO_BIOS, ®s, ®s);
369 if (col < (CO -1 )) ++col;
378 * This marks the end of the general screen output routines that are
379 * called from other places in NetHack.
380 * ---------------------------------------------------------------------
384 * Cursor location manipulation, and location information fetching
388 * txt_get_cursor(x,y) - Returns the current location of the cursor. In
389 * some implementations this is implemented as a
390 * function (BIOS), and in others it is a macro
393 * txt_gotoxy(x,y) - Moves the cursor on screen to the specified x and
394 * y location. This routine moves the location where
395 * screen writes will occur next, it does not change
396 * the location of the player on the NetHack level.
400 # if defined(SCREEN_BIOS) && !defined(PC9800)
402 * This is implemented as a macro under DJGPPFAST.
405 txt_get_cursor(x,y) /* get cursor position */
411 regs.h.ah = GETCURPOS; /* get cursor position */
414 (void) int86(VIDEO_BIOS, ®s, ®s); /* Get Cursor Position */
418 # endif /* SCREEN_BIOS && !PC9800 */
428 regs.h.dh = (char)y; /* row */
429 regs.h.dl = (char)x; /* column */
430 regs.h.ah = SETCURPOS;
431 regs.h.cl = DIRECT_CON_IO;
432 (void) int86(DOS_EXT_FUNC, ®s, ®s); /* Set Cursor Position */
434 regs.h.ah = SETCURPOS;
435 regs.h.bh = 0; /* display page */
436 regs.h.dh = (char)y; /* row */
437 regs.h.dl = (char)x; /* column */
438 (void) int86(VIDEO_BIOS, ®s, ®s); /* Set Cursor Position */
441 # if defined(SCREEN_DJGPPFAST)
442 ScreenSetCursor(y,x);
444 /* The above, too, goes back all the way to the original PC. If
445 * we ever get so fancy as to swap display pages (i doubt it),
446 * then we'll need to set BH appropriately. This function
447 * returns nothing. -3.
453 * This marks the end of the cursor manipulation/information routines.
454 * -------------------------------------------------------------------
459 int txt_monoadapt_check()
464 regs.h.ah = GETMODE; /* get video mode */
465 (void) int86(VIDEO_BIOS, ®s, ®s);
466 return (regs.h.al == 7) ? 1 : 0; /* 7 means monochrome mode */
468 # endif /* MONO_CHECK */
470 #endif /* NO_TERMS */