more win32tty clean-up

This brings things much closer to correct operation (I hope).
- The shift to only moving the cursor on input (<Someone>'s
changes) had a lot of complications, among them was
that sometimes, there is no more input. When the program was
exiting, or bombing the cursor synch never got done, so the
final messages could end up strewn any place the cursor
happened to be dwelling.

- There were two competing output systems in use: the
wintty stuff for the game, and the msmsg and error stuff
used by the sys/share/pcsys, sys/share/pctty, and
sys/share/pcunix routines.  Those were meant to mimic
output to stdout, where stuff just got sent to a sequential
display.  Over time, there were calls mixed in that depended
on the cursor tracked stuff from the core game, so you
really couldn't be sure where things were going to display.
It wasn't as much of an issue before, because the cursor
really did get moved around as expected. Everything
now ends up in the same output system.

- I even found a use of the real putchar() because
sys/share/pcunix didn't #include wintty.h the same
as the other files, and the macro never got defined.
Who knows where that character was being put -
the game certainly couldn't track it.

While everything I knew to be wrong yesterday is
now working, there may be some other glitches
lurking that I haven't discovered yet.

Please: test, test, test.
This commit is contained in:
nethack.allison
2003-10-26 15:56:50 +00:00
parent ca476c0eb2
commit 211666434c
6 changed files with 123 additions and 50 deletions
+1
View File
@@ -1338,6 +1338,7 @@ E void NDECL(nttty_rubout);
E int NDECL(tgetch); E int NDECL(tgetch);
E int FDECL(ntposkey,(int *, int *, int *)); E int FDECL(ntposkey,(int *, int *, int *));
E void FDECL(set_output_mode, (int)); E void FDECL(set_output_mode, (int));
E void NDECL(synch_cursor);
#endif #endif
/* ### o_init.c ### */ /* ### o_init.c ### */
+2 -5
View File
@@ -490,10 +490,6 @@ void nethack_exit(code)
int code; int code;
{ {
msexit(); msexit();
#ifdef MTHREAD_VIEW
if (iflags.mthreaded) nh_thread_exit(code); /* no return from this */
else
#endif
exit(code); exit(code);
} }
@@ -536,8 +532,9 @@ static void msexit()
* not vanish instantly after being created. * not vanish instantly after being created.
* GUILaunched is defined and set in nttty.c. * GUILaunched is defined and set in nttty.c.
*/ */
synch_cursor();
if (GUILaunched) getreturn("to end"); if (GUILaunched) getreturn("to end");
synch_cursor();
#endif #endif
return; return;
} }
+1 -6
View File
@@ -5,6 +5,7 @@
/* This file collects some Unix dependencies; pager.c contains some more */ /* This file collects some Unix dependencies; pager.c contains some more */
#include "hack.h" #include "hack.h"
#include "wintty.h"
#include <sys/stat.h> #include <sys/stat.h>
#if defined(WIN32) || defined(MSDOS) #if defined(WIN32) || defined(MSDOS)
@@ -174,13 +175,7 @@ getlock()
# endif # endif
while ((ci=nhgetch()) != '\n') { while ((ci=nhgetch()) != '\n') {
if (ct > 0) { if (ct > 0) {
# if defined(WIN32CON)
backsp(); /* \b is visible on NT */
(void) putchar(' ');
backsp();
# else
msmsg("\b \b"); msmsg("\b \b");
# endif
ct = 0; ct = 0;
c = 'n'; c = 'n';
} }
+102 -27
View File
@@ -1,4 +1,4 @@
/* SCCS Id: @(#)nttty.c 3.4 $Date$ */ /* SCCS Id: @(#)nttty.c 3.4 $Date$ */
/* Copyright (c) NetHack PC Development Team 1993 */ /* Copyright (c) NetHack PC Development Team 1993 */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -58,6 +58,10 @@ INPUT_RECORD ir;
int GUILaunched; int GUILaunched;
static BOOL FDECL(CtrlHandler, (DWORD)); static BOOL FDECL(CtrlHandler, (DWORD));
#ifdef PORT_DEBUG
static boolean display_cursor_info = TRUE;
#endif
extern boolean getreturn_enabled; /* from sys/share/pcsys.c */ extern boolean getreturn_enabled; /* from sys/share/pcsys.c */
/* dynamic keystroke handling .DLL support */ /* dynamic keystroke handling .DLL support */
@@ -192,6 +196,7 @@ void
tty_end_screen() tty_end_screen()
{ {
clear_screen(); clear_screen();
really_move_cursor();
if (GetConsoleScreenBufferInfo(hConOut,&csbi)) if (GetConsoleScreenBufferInfo(hConOut,&csbi))
{ {
DWORD ccnt; DWORD ccnt;
@@ -371,6 +376,23 @@ int *x, *y, *mod;
static void static void
really_move_cursor() 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); SetConsoleCursorPosition(hConOut, cursor);
} }
@@ -378,24 +400,24 @@ void
cmov(x, y) cmov(x, y)
register int x, y; register int x, y;
{ {
ttyDisplay->cury = y;
ttyDisplay->curx = x;
cursor.X = x; cursor.X = x;
cursor.Y = y; cursor.Y = y;
ttyDisplay->curx = x;
ttyDisplay->cury = y;
} }
void void
nocmov(x, y) nocmov(x, y)
int x,y; int x,y;
{ {
cursor.Y = y;
cursor.X = x; cursor.X = x;
cursor.Y = y;
ttyDisplay->curx = x; ttyDisplay->curx = x;
ttyDisplay->cury = y; ttyDisplay->cury = y;
} }
void void
xputc(ch) xputc_core(ch)
char ch; char ch;
{ {
switch(ch) { switch(ch) {
@@ -403,29 +425,55 @@ char ch;
cursor.Y++; cursor.Y++;
/* fall through */ /* fall through */
case '\r': case '\r':
cursor.X = 0; cursor.X = 1;
cmov(cursor.X, cursor.Y); break;
return; 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++; void
cmov(cursor.X, cursor.Y); xputc(ch)
char ch;
{
cursor.X = ttyDisplay->curx;
cursor.Y = ttyDisplay->cury;
xputc_core(ch);
} }
void void
xputs(s) xputs(s)
const char *s; const char *s;
{ {
int k, slen = strlen(s); int k;
if (s) int slen = strlen(s);
if (ttyDisplay) {
cursor.X = ttyDisplay->curx;
cursor.Y = ttyDisplay->cury;
}
if (s) {
for (k=0; k < slen && s[k]; ++k) 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. * for win32. It is used for glyphs only, not text.
*/ */
void void
@@ -444,6 +492,8 @@ void
cl_end() cl_end()
{ {
int cx; int cx;
cursor.X = ttyDisplay->curx;
cursor.Y = ttyDisplay->cury;
cx = CO - cursor.X; cx = CO - cursor.X;
FillConsoleOutputAttribute(hConOut, DEFTEXTCOLOR, cx, cursor, &acount); FillConsoleOutputAttribute(hConOut, DEFTEXTCOLOR, cx, cursor, &acount);
FillConsoleOutputCharacter(hConOut,' ', cx, cursor,&ccount); FillConsoleOutputCharacter(hConOut,' ', cx, cursor,&ccount);
@@ -484,27 +534,25 @@ home()
void void
backsp() backsp()
{ {
cursor.X--; cursor.X = ttyDisplay->curx;
xputc(' '); cursor.Y = ttyDisplay->cury;
cursor.X--; xputc_core('\b');
} }
void void
cl_eos() cl_eos()
{ {
register int cy = ttyDisplay->cury+1; int cy = ttyDisplay->cury+1;
if (GetConsoleScreenBufferInfo(hConOut,&csbi)) { if (GetConsoleScreenBufferInfo(hConOut,&csbi)) {
DWORD ccnt; DWORD ccnt;
COORD newcoord; COORD newcoord;
newcoord.X = 0; newcoord.X = ttyDisplay->curx;
newcoord.Y = ttyDisplay->cury; newcoord.Y = ttyDisplay->cury;
FillConsoleOutputAttribute(hConOut, FillConsoleOutputAttribute(hConOut,
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
csbi.dwSize.X * csbi.dwSize.Y - cy, csbi.dwSize.X * csbi.dwSize.Y - cy,
newcoord, &ccnt); newcoord, &ccnt);
newcoord.X = 0;
newcoord.Y = ttyDisplay->cury;
FillConsoleOutputCharacter(hConOut,' ', FillConsoleOutputCharacter(hConOut,' ',
csbi.dwSize.X * csbi.dwSize.Y - cy, csbi.dwSize.X * csbi.dwSize.Y - cy,
newcoord, &ccnt); newcoord, &ccnt);
@@ -762,6 +810,11 @@ win32con_handler_info()
(void)doredraw(); (void)doredraw();
} }
} }
void win32con_toggle_cursor_info()
{
display_cursor_info = !display_cursor_info;
}
#endif #endif
void void
@@ -877,19 +930,41 @@ load_keyboard_handler()
} }
} }
/* 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 void
msmsg VA_DECL(const char *, fmt) msmsg VA_DECL(const char *, fmt)
char buf[ROWNO * COLNO]; /* worst case scenario */ char buf[ROWNO * COLNO]; /* worst case scenario */
VA_START(fmt); VA_START(fmt);
VA_INIT(fmt, const char *); VA_INIT(fmt, const char *);
Vsprintf(buf, fmt, VA_ARGS); Vsprintf(buf, fmt, VA_ARGS);
VA_END(); VA_END();
xputs(buf); xputs(buf);
really_move_cursor(); curs(BASE_WINDOW, cursor.X+1, cursor.Y);
return; 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 /* WIN32CON */
+14 -9
View File
@@ -17,7 +17,9 @@
#endif #endif
#include <ctype.h> #include <ctype.h>
#include "win32api.h" #include "win32api.h"
#ifdef WIN32CON
#include "wintty.h"
#endif
#ifdef WIN32 #ifdef WIN32
@@ -195,21 +197,22 @@ return &szFullPath[0];
} }
# endif # endif
#ifndef WIN32CON
/* fatal error */ /* fatal error */
/*VARARGS1*/ /*VARARGS1*/
void void
error VA_DECL(const char *,s) error VA_DECL(const char *,s)
char buf[BUFSZ];
VA_START(s); VA_START(s);
VA_INIT(s, const char *); VA_INIT(s, const char *);
/* error() may get called before tty is initialized */ /* error() may get called before tty is initialized */
if (iflags.window_inited) end_screen(); if (iflags.window_inited) end_screen();
if (!strncmpi(windowprocs.name, "tty", 3)) { if (!strncmpi(windowprocs.name, "tty", 3)) {
putchar('\n'); buf[0] = '\n';
Vprintf(s,VA_ARGS); (void) vsprintf(&buf[1], s, VA_ARGS);
putchar('\n'); Strcat(buf, "\n");
msmsg(buf);
} else { } else {
char buf[BUFSZ];
(void) vsprintf(buf, s, VA_ARGS); (void) vsprintf(buf, s, VA_ARGS);
Strcat(buf, "\n"); Strcat(buf, "\n");
raw_printf(buf); raw_printf(buf);
@@ -217,6 +220,8 @@ error VA_DECL(const char *,s)
VA_END(); VA_END();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#endif
void Delay(int ms) void Delay(int ms)
{ {
(void)Sleep(ms); (void)Sleep(ms);
@@ -292,9 +297,9 @@ genericptr_t ptr2;
strstri(datadir, "TEMP") || strstri(datadir, "TEMP") ||
(tempdir && strstri(datadir, tempdir))) { (tempdir && strstri(datadir, tempdir))) {
(void)strncpy(interjection_buf[INTERJECT_PANIC], (void)strncpy(interjection_buf[INTERJECT_PANIC],
"\nThe nature of the error seems to indicate that you may\n" "\nOne common cause of this error is attempting to execute\n"
"be attempting to execute the game by double-clicking on \n" "the game by double-clicking on it while it is displayed\n"
"it from within the download distribution zip file.\n\n" "inside an unzip utility.\n\n"
"You have to unzip the contents of the zip file into a\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" "folder on your system, and then run \"NetHack.exe\" or \n"
"\"NetHackW.exe\" from there.\n\n" "\"NetHackW.exe\" from there.\n\n"
+3 -3
View File
@@ -147,8 +147,8 @@ boolean GFlag = FALSE;
boolean HE_resets_AS; /* see termcap.c */ boolean HE_resets_AS; /* see termcap.c */
#endif #endif
#ifdef MICRO #if defined(MICRO) || defined(WIN32CON)
static char to_continue[] = "to continue"; static const char to_continue[] = "to continue";
#define getret() getreturn(to_continue) #define getret() getreturn(to_continue)
#else #else
STATIC_DCL void NDECL(getret); STATIC_DCL void NDECL(getret);
@@ -741,7 +741,7 @@ tty_get_nh_event()
return; return;
} }
#ifndef MICRO #if !defined(MICRO) && !defined(WIN32CON)
STATIC_OVL void STATIC_OVL void
getret() getret()
{ {