-/* SCCS Id: @(#)nttty.c 3.4 $Date$ */
+ /* SCCS Id: @(#)nttty.c 3.4 $Date$ */
/* Copyright (c) NetHack PC Development Team 1993 */
/* NetHack may be freely redistributed. See license for details. */
int GUILaunched;
static BOOL FDECL(CtrlHandler, (DWORD));
+#ifdef PORT_DEBUG
+static boolean display_cursor_info = TRUE;
+#endif
+
extern boolean getreturn_enabled; /* from sys/share/pcsys.c */
/* dynamic keystroke handling .DLL support */
tty_end_screen()
{
clear_screen();
+ really_move_cursor();
if (GetConsoleScreenBufferInfo(hConOut,&csbi))
{
DWORD ccnt;
static void
really_move_cursor()
{
+#if defined(PORT_DEBUG) && defined(WIZARD)
+ char oldtitle[BUFSZ], newtitle[BUFSZ];
+ if (display_cursor_info && wizard) {
+ oldtitle[0] = '\0';
+ if (GetConsoleTitle(oldtitle, BUFSZ)) {
+ oldtitle[39] = '\0';
+ }
+ Sprintf(newtitle, "%-55s tty=(%02d,%02d) nttty=(%02d,%02d)",
+ oldtitle, ttyDisplay->curx, ttyDisplay->cury,
+ cursor.X, cursor.Y);
+ (void)SetConsoleTitle(newtitle);
+ }
+#endif
+ if (ttyDisplay) {
+ cursor.X = ttyDisplay->curx;
+ cursor.Y = ttyDisplay->cury;
+ }
SetConsoleCursorPosition(hConOut, cursor);
}
cmov(x, y)
register int x, y;
{
+ ttyDisplay->cury = y;
+ ttyDisplay->curx = x;
cursor.X = x;
cursor.Y = y;
- ttyDisplay->curx = x;
- ttyDisplay->cury = y;
}
void
nocmov(x, y)
int x,y;
{
- cursor.Y = y;
cursor.X = x;
+ cursor.Y = y;
ttyDisplay->curx = x;
ttyDisplay->cury = y;
}
void
-xputc(ch)
+xputc_core(ch)
char ch;
{
switch(ch) {
cursor.Y++;
/* fall through */
case '\r':
- cursor.X = 0;
- cmov(cursor.X, cursor.Y);
- return;
+ cursor.X = 1;
+ break;
+ case '\b':
+ cursor.X--;
+ ch = ' ';
+ WriteConsoleOutputAttribute(hConOut,&attr,1,
+ cursor,&acount);
+ WriteConsoleOutputCharacter(hConOut,&ch,1,
+ cursor,&ccount);
+ break;
+ default:
+ WriteConsoleOutputAttribute(hConOut,&attr,1,
+ cursor,&acount);
+ WriteConsoleOutputCharacter(hConOut,&ch,1,
+ cursor,&ccount);
+ cursor.X++;
}
- WriteConsoleOutputAttribute(hConOut,&attr,1,cursor,&acount);
- WriteConsoleOutputCharacter(hConOut,&ch,1,cursor,&ccount);
- cursor.X++;
- cmov(cursor.X, cursor.Y);
+}
+
+void
+xputc(ch)
+char ch;
+{
+ cursor.X = ttyDisplay->curx;
+ cursor.Y = ttyDisplay->cury;
+ xputc_core(ch);
}
void
xputs(s)
const char *s;
{
- int k, slen = strlen(s);
- if (s)
+ int k;
+ int slen = strlen(s);
+
+ if (ttyDisplay) {
+ cursor.X = ttyDisplay->curx;
+ cursor.Y = ttyDisplay->cury;
+ }
+
+ if (s) {
for (k=0; k < slen && s[k]; ++k)
- xputc(s[k]);
+ xputc_core(s[k]);
+ }
}
/*
- * Overrides winntty.c function of the same name
+ * Overrides wintty.c function of the same name
* for win32. It is used for glyphs only, not text.
*/
void
cl_end()
{
int cx;
+ cursor.X = ttyDisplay->curx;
+ cursor.Y = ttyDisplay->cury;
cx = CO - cursor.X;
FillConsoleOutputAttribute(hConOut, DEFTEXTCOLOR, cx, cursor, &acount);
FillConsoleOutputCharacter(hConOut,' ', cx, cursor,&ccount);
void
backsp()
{
- cursor.X--;
- xputc(' ');
- cursor.X--;
+ cursor.X = ttyDisplay->curx;
+ cursor.Y = ttyDisplay->cury;
+ xputc_core('\b');
}
void
cl_eos()
{
- register int cy = ttyDisplay->cury+1;
+ int cy = ttyDisplay->cury+1;
if (GetConsoleScreenBufferInfo(hConOut,&csbi)) {
DWORD ccnt;
COORD newcoord;
- newcoord.X = 0;
+ newcoord.X = ttyDisplay->curx;
newcoord.Y = ttyDisplay->cury;
FillConsoleOutputAttribute(hConOut,
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
csbi.dwSize.X * csbi.dwSize.Y - cy,
newcoord, &ccnt);
- newcoord.X = 0;
- newcoord.Y = ttyDisplay->cury;
FillConsoleOutputCharacter(hConOut,' ',
csbi.dwSize.X * csbi.dwSize.Y - cy,
newcoord, &ccnt);
(void)doredraw();
}
}
+
+void win32con_toggle_cursor_info()
+{
+ display_cursor_info = !display_cursor_info;
+}
#endif
void
}
}
-/* this is used when window system isn't initialized yet */
+/* this is used as a printf() replacement when the window
+ * system isn't initialized yet
+ */
void
msmsg VA_DECL(const char *, fmt)
char buf[ROWNO * COLNO]; /* worst case scenario */
-
VA_START(fmt);
VA_INIT(fmt, const char *);
Vsprintf(buf, fmt, VA_ARGS);
VA_END();
-
xputs(buf);
- really_move_cursor();
+ curs(BASE_WINDOW, cursor.X+1, cursor.Y);
return;
}
+/* fatal error */
+/*VARARGS1*/
+void
+error VA_DECL(const char *,s)
+ char buf[BUFSZ];
+ VA_START(s);
+ VA_INIT(s, const char *);
+ /* error() may get called before tty is initialized */
+ if (iflags.window_inited) end_screen();
+ buf[0] = '\n';
+ (void) vsprintf(&buf[1], s, VA_ARGS);
+ VA_END();
+ msmsg(buf);
+ really_move_cursor();
+ exit(EXIT_FAILURE);
+}
+
+void
+synch_cursor()
+{
+ really_move_cursor();
+}
#endif /* WIN32CON */
#endif
#include <ctype.h>
#include "win32api.h"
-
+#ifdef WIN32CON
+#include "wintty.h"
+#endif
#ifdef WIN32
}
# endif
-
+#ifndef WIN32CON
/* fatal error */
/*VARARGS1*/
void
error VA_DECL(const char *,s)
+ char buf[BUFSZ];
VA_START(s);
VA_INIT(s, const char *);
/* error() may get called before tty is initialized */
if (iflags.window_inited) end_screen();
if (!strncmpi(windowprocs.name, "tty", 3)) {
- putchar('\n');
- Vprintf(s,VA_ARGS);
- putchar('\n');
+ buf[0] = '\n';
+ (void) vsprintf(&buf[1], s, VA_ARGS);
+ Strcat(buf, "\n");
+ msmsg(buf);
} else {
- char buf[BUFSZ];
(void) vsprintf(buf, s, VA_ARGS);
Strcat(buf, "\n");
raw_printf(buf);
VA_END();
exit(EXIT_FAILURE);
}
+#endif
+
void Delay(int ms)
{
(void)Sleep(ms);
strstri(datadir, "TEMP") ||
(tempdir && strstri(datadir, tempdir))) {
(void)strncpy(interjection_buf[INTERJECT_PANIC],
- "\nThe nature of the error seems to indicate that you may\n"
- "be attempting to execute the game by double-clicking on \n"
- "it from within the download distribution zip file.\n\n"
+ "\nOne common cause of this error is attempting to execute\n"
+ "the game by double-clicking on it while it is displayed\n"
+ "inside an unzip utility.\n\n"
"You have to unzip the contents of the zip file into a\n"
"folder on your system, and then run \"NetHack.exe\" or \n"
"\"NetHackW.exe\" from there.\n\n"