some tty updates

Add a note about NO_TERMS to include/wintty.h for clarity.

Rename tty_startup and tty_shutdown to term_startup() and
term_shutdown(). They are found in termcap.c for !NO_TERMS
like most of the other term_ routines, as well as having
versions for several of the NO_TERMS platforms. They aren't
part of the tty_interface called from the core. The tty
implementation does call and rely on them.

Remove some conditional #ifdef's around term_shutdown()
(formerly tty_shutdown()) and just ensure that all the
tty platforms have an implementation that they can link
with, even if it is just a stub presently.

Put the protype for nethack_exit in extern.h to reduce
maintenance to a single spot, and remove it from other
locations. A warning in the msdos cross-compile led to
this change.
This commit is contained in:
nhmall
2025-01-04 19:01:34 -05:00
parent 7982c72e8b
commit 37758c7e48
18 changed files with 293 additions and 100 deletions

View File

@@ -2098,6 +2098,7 @@ extern void consoletty_open(int);
extern void consoletty_rubout(void);
extern int tgetch(void);
extern int console_poskey(coordxy *, coordxy *, int *);
void console_g_putch(int in_ch);
extern void set_output_mode(int);
extern void synch_cursor(void);
extern void nethack_enter_consoletty(void);
@@ -2302,7 +2303,14 @@ extern int getlock(void);
extern const char *get_portable_device(void);
#endif
/* ### pcsys.c ### */
/* ### pcsys.c, windsys.c ### */
#if defined(MICRO) || defined(WIN32)
ATTRNORETURN extern void nethack_exit(int) NORETURN;
#else
#define nethack_exit exit
#endif
/* ### pcsys.c ### */
#if defined(MICRO) || defined(WIN32)
extern void flushout(void);

View File

@@ -268,7 +268,6 @@ extern int alternative_palette(char *);
#endif
#define nethack_enter(argc, argv) nethack_enter_windows()
ATTRNORETURN extern void nethack_exit(int) NORETURN;
extern boolean file_exists(const char *);
extern boolean file_newer(const char *, const char *);
#ifndef SYSTEM_H

View File

@@ -129,6 +129,8 @@ struct tty_status_fields {
#endif
#define NHW_BASE (NHW_LAST_TYPE + 1)
/* external declarations */
extern struct window_procs tty_procs;
/* port specific variable declarations */
@@ -144,24 +146,53 @@ extern char defmorestr[]; /* default --more-- prompt */
/* port specific external function references */
/* ### getline.c ### */
extern void xwaitforspace(const char *);
/* ### termcap.c, video.c ### */
extern void tty_startup(int *, int *);
#ifndef NO_TERMS
extern void tty_shutdown(void);
#endif
extern int xputc(int);
extern void xputs(const char *);
#if defined(SCREEN_VGA) || defined(SCREEN_8514) || defined(SCREEN_VESA)
extern void xputg(const glyph_info *, const glyph_info *);
#endif
/*
* TERM or NO_TERMS
*
* The tty windowport interface relies on lower-level support routines
* to actually manipulate the terminal/display. Those are the right place
* for doing strange and arcane things such as outputting escape sequences
* to select a color or whatever. wintty.c should concern itself with WHERE
* to put stuff in a window.
* The TERM routines are found in:
*
* !NO_TERMS: termcap.c
*
* NO_TERMS:
* WINCON sys/windows/consoletty.c
* MSDOS sys/msdos/video.c
*
*/
extern void backsp(void);
extern void cl_end(void);
extern void term_clear_screen(void);
extern void cl_eos(void);
extern void graph_on(void);
extern void graph_off(void);
extern void home(void);
extern void standoutbeg(void);
extern void standoutend(void);
extern int term_attr_fixup(int);
extern void term_clear_screen(void);
extern void term_curs_set(int);
extern void term_end_attr(int attr);
extern void term_end_color(void);
extern void term_end_extracolor(void);
extern void term_end_raw_bold(void);
extern void term_start_attr(int attr);
extern void term_start_bgcolor(int color);
extern void term_start_color(int color);
extern void term_start_extracolor(uint32, uint16);
extern void term_start_raw_bold(void);
extern void term_startup(int *, int *);
extern void term_shutdown(void);
extern int xputc(int);
extern void xputs(const char *);
#if 0
extern void revbeg(void);
extern void boldbeg(void);
@@ -169,29 +200,9 @@ extern void blinkbeg(void);
extern void dimbeg(void);
extern void m_end(void);
#endif
extern void backsp(void);
extern void graph_on(void);
extern void graph_off(void);
extern void cl_eos(void);
/*
* termcap.c (or facsimiles in other ports) is the right place for doing
* strange and arcane things such as outputting escape sequences to select
* a color or whatever. wintty.c should concern itself with WHERE to put
* stuff in a window.
*/
extern int term_attr_fixup(int);
extern void term_start_attr(int attr);
extern void term_end_attr(int attr);
extern void term_start_raw_bold(void);
extern void term_end_raw_bold(void);
extern void term_end_color(void);
extern void term_start_color(int color);
extern void term_start_bgcolor(int color);
extern void term_start_extracolor(uint32, uint16);
extern void term_end_extracolor(void); /* termcap.c, consoletty.c */
extern void term_curs_set(int);
#if defined(SCREEN_VGA) || defined(SCREEN_8514) || defined(SCREEN_VESA)
extern void xputg(const glyph_info *, const glyph_info *);
#endif
/* ### topl.c ### */
@@ -203,6 +214,7 @@ extern void update_topl(const char *);
extern void putsyms(const char *);
/* ### wintty.c ### */
#ifdef CLIPPING
extern void setclipped(void);
#endif
@@ -217,7 +229,7 @@ extern void g_pututf8(uint8 *);
extern void erase_tty_screen(void);
extern void win_tty_init(int);
/* external declarations */
/* tty interface */
extern void tty_init_nhwindows(int *, char **);
extern void tty_preference_update(const char *);
extern void tty_player_selection(void);

View File

@@ -541,7 +541,7 @@ setftty(void)
}
void
tty_startup(int *width, int *height)
term_startup(int *width, int *height)
{
_mt_init_stuff();
*width = CO;

View File

@@ -36,12 +36,6 @@ staticfn void fixup_death(int);
staticfn int wordcount(char *);
staticfn void bel_copy1(char **, char *);
#if defined(__BEOS__) || defined(MICRO) || defined(OS2) || defined(WIN32)
ATTRNORETURN extern void nethack_exit(int) NORETURN;
#else
#define nethack_exit exit
#endif
#define done_stopprint program_state.stopprint
/*

View File

@@ -55,6 +55,7 @@
#endif
#define GETCURPOS 0x03 /* Get Cursor Position */
#define SETCURTYP 0x01 /* Set Cursor Type */
#define GETMODE 0x0f /* Get Video Mode */
#define SETMODE 0x00 /* Set Video Mode */
#define SETPAGE 0x05 /* Set Video Page */
@@ -248,6 +249,8 @@ extern void txt_nhbell(void);
extern void txt_startup(int *, int *);
extern void txt_xputs(const char *, int, int);
extern void txt_xputc(char, int);
extern void txt_hide_cursor(void);
extern void txt_show_cursor(void);
/* ### vidvga.c ### */
@@ -258,6 +261,8 @@ extern void vga_clear_screen(int);
extern void vga_cl_end(int, int);
extern void vga_cl_eos(int);
extern int vga_detect(void);
extern void vga_hide_cursor(void);
extern void vga_show_cursor(void);
#ifdef SIMULATE_CURSOR
extern void vga_DrawCursor(void);
#endif
@@ -273,7 +278,7 @@ extern void vga_HideCursor(void);
#endif
extern void vga_Init(void);
extern void vga_tty_end_screen(void);
extern void vga_tty_startup(int *, int *);
extern void vga_term_startup(int *, int *);
extern void vga_xputs(const char *, int, int);
extern void vga_xputc(char, int);
extern void vga_xputg(const glyph_info *, const glyph_info *);
@@ -288,6 +293,8 @@ extern void vesa_clear_screen(int);
extern void vesa_cl_end(int, int);
extern void vesa_cl_eos(int);
extern int vesa_detect(void);
extern void vesa_hide_cursor(void);
extern void vesa_show_cursor(void);
#ifdef SIMULATE_CURSOR
extern void vesa_DrawCursor(void);
#endif
@@ -302,7 +309,7 @@ extern void vesa_HideCursor(void);
#endif
extern void vesa_Init(void);
extern void vesa_tty_end_screen(void);
extern void vesa_tty_startup(int *, int *);
extern void vesa_term_startup(int *, int *);
extern void vesa_xputs(const char *, int, int);
extern void vesa_xputc(char, int);
extern void vesa_xputg(const glyph_info *, const glyph_info *);

View File

@@ -146,6 +146,61 @@ boolean traditional = FALSE; /* traditional TTY character mode */
boolean inmap = FALSE; /* in the map window */
char ttycolors[CLR_MAX]; /* also used/set in options.c */
/* for linkage from wintty.c */
void
term_shutdown(void)
{
}
#ifdef ASCIIGRAPH
void
graph_on(void)
{
}
void
graph_off(void)
{
}
#endif
void
term_curs_set(int visibility)
{
static int vis = -1;
if (vis == visibility)
return;
if (!visibility) {
if (!iflags.grmode) {
txt_hide_cursor();
#ifdef SCREEN_VGA
} else if (iflags.usevga) {
vga_hide_cursor();
#endif
#ifdef SCREEN_VESA
} else if (iflags.usevesa) {
vesa_hide_cursor();
}
#endif
} else if (visibility) {
if (!iflags.grmode) {
txt_show_cursor();
#ifdef SCREEN_VGA
} else if (iflags.usevga) {
vga_show_cursor();
#endif
#ifdef SCREEN_VESA
} else if (iflags.usevesa) {
vesa_show_cursor();
}
#endif
}
vis = visibility;
}
void
backsp(void)
{
@@ -447,7 +502,7 @@ tty_number_pad(int state)
}
void
tty_startup(int *wid, int *hgt)
term_startup(int *wid, int *hgt)
{
/* code to sense display adapter is required here - MJA */
@@ -461,12 +516,12 @@ tty_startup(int *wid, int *hgt)
#ifdef SCREEN_VGA
if (iflags.usevga) {
vga_tty_startup(wid, hgt);
vga_term_startup(wid, hgt);
} else
#endif
#ifdef SCREEN_VESA
if (iflags.usevesa) {
vesa_tty_startup(wid, hgt);
vesa_term_startup(wid, hgt);
} else
#endif
txt_startup(wid, hgt);

View File

@@ -38,6 +38,14 @@ extern int attrib_gr_normal; /* graphics mode normal attribute */
extern int attrib_text_intense; /* text mode intense attribute */
extern int attrib_gr_intense; /* graphics mode intense attribute */
#if defined(SCREEN_BIOS) && !defined(PC9800)
static unsigned char cursor_info = 0,
cursor_start_scanline = 6, cursor_end_scanline = 7;
static void get_cursinfo(unsigned char *start, unsigned char *end,
unsigned char *flg);
#endif
void
txt_get_scr_size(void)
{
@@ -80,6 +88,7 @@ txt_get_scr_size(void)
LI = regs.h.dl + 1;
CO = regs.h.ah;
#endif /* PC9800 */
}
@@ -260,6 +269,9 @@ txt_startup(int *wid, int *hgt)
attrib_gr_normal = attrib_text_normal;
attrib_gr_intense = attrib_text_intense;
g_attribute = attrib_text_normal; /* Give it a starting value */
get_cursinfo(&cursor_start_scanline,
&cursor_end_scanline,
&cursor_info);
}
/*
@@ -400,6 +412,61 @@ void txt_get_cursor(int *x, int *y)
(void) int86(VIDEO_BIOS, &regs, &regs); /* Get Cursor Position */
*x = regs.h.dl;
*y = regs.h.dh;
if (!cursor_info) {
cursor_start_scanline = regs.h.ch;
cursor_end_scanline = regs.h.cl;
cursor_info = 1;
}
}
void txt_hide_cursor(void)
{
union REGS regs;
regs.x.dx = 0;
regs.h.ah = SETCURTYP; /* set cursor type */
regs.h.ch = 0x3F; /* starting scanline */
regs.h.cl = 0; /* ending scanline */
regs.x.bx = 0;
(void) int86(VIDEO_BIOS, &regs, &regs);
}
void txt_show_cursor(void)
{
union REGS regs;
regs.x.dx = 0;
regs.h.ah = SETCURTYP; /* set cursor type */
if (cursor_info) {
regs.h.ch = cursor_start_scanline; /* starting scanline */
regs.h.cl = cursor_end_scanline; /* ending scanline */
} else {
regs.h.ch = 6; /* starting scanline */
regs.h.cl = 7; /* ending scanline */
}
regs.x.bx = 0;
(void) int86(VIDEO_BIOS, &regs, &regs);
}
static void
get_cursinfo(uchar *start, uchar *end, uchar *flg)
{
union REGS regs;
regs.x.dx = 0;
regs.h.ah = GETCURPOS; /* get cursor position */
regs.x.cx = 0;
regs.x.bx = 0;
(void) int86(VIDEO_BIOS, &regs, &regs); /* Get Cursor Position */
if (regs.h.ch != 0x3f) {
*start = regs.h.ch;
*end = regs.h.cl;
} else {
*start = 6;
*end = 7;
}
*flg = 1;
}
#endif /* SCREEN_BIOS && !PC9800 */

View File

@@ -603,7 +603,7 @@ vesa_tty_end_screen(void)
}
void
vesa_tty_startup(int *wid, int *hgt)
vesa_term_startup(int *wid, int *hgt)
{
/* code to sense display adapter is required here - MJA */
@@ -2042,6 +2042,16 @@ vesa_SetSoftPalette(const struct Pixel *palette)
return TRUE;
}
void
vesa_hide_cursor(void)
{
}
void
vesa_show_cursor(void)
{
}
#ifdef POSITIONBAR
#define PBAR_ROW (LI - 4)

View File

@@ -297,7 +297,7 @@ vga_tty_end_screen(void)
}
void
vga_tty_startup(int *wid, int *hgt)
vga_term_startup(int *wid, int *hgt)
{
/* code to sense display adapter is required here - MJA */
@@ -1159,6 +1159,16 @@ vga_SetPalette(const struct Pixel *p)
}
}
void
vga_hide_cursor(void)
{
}
void
vga_show_cursor(void)
{
}
/*static unsigned char colorbits[]={0x01,0x02,0x04,0x08}; */ /* wrong */
static unsigned char colorbits[] = { 0x08, 0x04, 0x02, 0x01 };

View File

@@ -22,12 +22,6 @@
#include <unistd.h> /* for getcwd() prototype */
#endif
#if defined(MICRO) || defined(OS2)
ATTRNORETURN void nethack_exit(int) NORETURN;
#else
#define nethack_exit exit
#endif
char *exepath(char *);
char orgdir[PATHLEN]; /* also used in pcsys.c, amidos.c */

View File

@@ -27,11 +27,6 @@
#define filesize filesize_nh
#endif
#if defined(MICRO) || defined(OS2)
ATTRNORETURN void nethack_exit(int) NORETURN;
#else
#define nethack_exit exit
#endif
static void msexit(void);
#ifdef MOVERLAY
@@ -276,6 +271,7 @@ msexit(void)
restore_colors();
#endif
wait_synch();
term_curs_set(1);
return;
}
#endif /* MICRO || OS2 */

View File

@@ -235,8 +235,8 @@ ifeq "$(WANT_DEBUG)" "1"
GDBEXE=$(dostargetexes)gdb.exe
GDBBAT=NHGDB.BAT
GDBCMDLINE=directory nhsrc/src nhsrc/include nhsrc/sys/msdos \
nhsrc/sys/share nhsrc/win/share nhsrc/win/curses \
nhsrc/win/tty nhsrc/util
nhsrc/sys/share nhsrc/win/curses \
nhsrc/win/tty
else
GDBEXE=
GDBBAT=

View File

@@ -1079,7 +1079,7 @@ setftty(void)
}
void
tty_startup(int *wid, int *hgt)
term_startup(int *wid, int *hgt)
{
*wid = console.width;
*hgt = console.height;
@@ -1092,6 +1092,36 @@ tty_number_pad(int state UNUSED)
// do nothing
}
/* stub tcap replacements for linkage from wintty.c */
void
term_shutdown(void)
{
consoletty_exit();
}
#ifdef ASCIIGRAPH
void
graph_on(void)
{
}
void
graph_off(void)
{
}
#endif
void
tty_end_screen(void)
{
term_clear_screen();
really_move_cursor();
buffer_fill_to_end(console.back_buffer, &clear_cell, 0, 0);
back_buffer_flip();
FlushConsoleInputBuffer(console.hConIn);
}
void
tty_start_screen(void)
{
@@ -1107,16 +1137,6 @@ tty_start_screen(void)
#endif /* VIRTUAL_TERMINAL_SEQUENCES */
}
void
tty_end_screen(void)
{
term_clear_screen();
really_move_cursor();
buffer_fill_to_end(console.back_buffer, &clear_cell, 0, 0);
back_buffer_flip();
FlushConsoleInputBuffer(console.hConIn);
}
static BOOL
CtrlHandler(DWORD ctrltype)
{
@@ -1251,6 +1271,7 @@ console_poskey(coordxy *x, coordxy *y, int *mod)
if (gc.Cmd.swap_yz)
numberpad |= 0x10;
#endif
term_curs_set(1);
ch = (program_state.done_hup)
? '\033'
: keyboard_handling.pCheckInput(
@@ -1262,6 +1283,7 @@ console_poskey(coordxy *x, coordxy *y, int *mod)
*x = cc.x;
*y = cc.y;
}
term_curs_set(0);
return ch;
}
@@ -1462,7 +1484,7 @@ xputc_core(int ch)
*/
#endif
void
g_putch(int in_ch)
console_g_putch(int in_ch)
{
unsigned char ch;
cell_t cell;
@@ -1644,6 +1666,25 @@ term_clear_screen(void)
home();
}
void
term_curs_set(int visibility)
{
static int vis = -1;
if (vis == visibility)
return;
static CONSOLE_CURSOR_INFO cursorinfo = { 0, 0 };
if (!cursorinfo.dwSize) {
GetConsoleCursorInfo(console.hConOut, &cursorinfo);
vis = cursorinfo.bVisible ? 1 : 0;
}
cursorinfo.bVisible = visibility ? (BOOL) TRUE : (BOOL) FALSE;
SetConsoleCursorInfo(console.hConOut, &cursorinfo);
vis = visibility;
}
void
home(void)
{

View File

@@ -25,7 +25,6 @@ char *translate_path_variables(const char *, char *);
char *exename(void);
boolean fakeconsole(void);
void freefakeconsole(void);
ATTRNORETURN extern void nethack_exit(int) NORETURN;
#if defined(MSWIN_GRAPHICS)
extern void mswin_destroy_reg(void);
#endif

View File

@@ -78,7 +78,7 @@ static char tgotobuf[20];
static char tty_standout_on[16], tty_standout_off[16];
void
tty_startup(int *wid, int *hgt)
term_startup(int *wid, int *hgt)
{
#ifdef TERMLIB
const char *term;
@@ -336,7 +336,7 @@ tty_startup(int *wid, int *hgt)
*/
/* deallocate resources prior to final termination */
void
tty_shutdown(void)
term_shutdown(void)
{
/* we only attempt to clean up a few individual termcap variables */
#if defined(TERMLIB) || defined(ANSI_DEFAULT)
@@ -1494,10 +1494,16 @@ term_start_bgcolor(int color)
void
term_curs_set(int visibility)
{
static int vis = -1;
if (vis == visibility)
return;
if (!visibility && nh_VI)
xputs(nh_VI);
else if (visibility && nh_VE)
xputs(nh_VE);
vis = visibility;
}
#ifdef CHANGE_COLOR

View File

@@ -197,7 +197,7 @@ static int clipy = 0, clipymax = 0;
extern void adjust_cursor_flags(struct WinDesc *);
#endif
#if defined(ASCIIGRAPH) && !defined(NO_TERMS)
#if defined(ASCIIGRAPH)
boolean GFlag = FALSE;
boolean HE_resets_AS; /* see termcap.c */
#endif
@@ -518,9 +518,9 @@ tty_init_nhwindows(int *argcp UNUSED, char **argv UNUSED)
/*
* Remember tty modes, to be restored on exit.
*
* gettty() must be called before tty_startup()
* gettty() must be called before term_startup()
* due to ordering of LI/CO settings
* tty_startup() must be called before initoptions()
* term_startup() must be called before initoptions()
* due to ordering of graphics settings
*/
#if defined(UNIX) || defined(VMS)
@@ -529,7 +529,7 @@ tty_init_nhwindows(int *argcp UNUSED, char **argv UNUSED)
gettty();
/* to port dependant tty setup */
tty_startup(&wid, &hgt);
term_startup(&wid, &hgt);
setftty(); /* calls start_screen */
term_curs_set(0);
@@ -840,12 +840,7 @@ tty_exit_nhwindows(const char *str)
ttyDisplay = (struct DisplayDesc *) 0;
#endif
#ifndef NO_TERMS /*(until this gets added to the window interface)*/
tty_shutdown(); /* cleanup termcap/terminfo/whatever */
#endif
#ifdef WIN32CON
consoletty_exit();
#endif
term_shutdown(); /* cleanup termcap/terminfo/whatever */
iflags.window_inited = 0;
}
@@ -3720,15 +3715,15 @@ end_glyphout(void)
}
}
#ifndef WIN32CON
void
g_putch(int in_ch)
{
char ch = (char) in_ch;
#ifndef WIN32CON
HUPSKIP();
#if defined(ASCIIGRAPH) && !defined(NO_TERMS)
#if defined(ASCIIGRAPH)
if (SYMHANDLING(H_UTF8)) {
(void) putchar(ch);
} else if (SYMHANDLING(H_IBM)
@@ -3762,14 +3757,16 @@ g_putch(int in_ch)
(void) putchar(ch);
}
#else
#else /* ?ASCIIGRAPH */
(void) putchar(ch);
#endif /* ASCIIGRAPH && !NO_TERMS */
#endif /* ASCIIGRAPH */
#else /* WIN32CON */
console_g_putch(in_ch);
nhUse(ch);
#endif /* WIN32CON */
return;
}
#endif /* !WIN32CON */
#if defined(UNIX) || defined(VMS)
#if defined(ENHANCED_SYMBOLS)
@@ -3867,9 +3864,9 @@ tty_print_glyph(
#ifndef NO_TERMS
if (ul_hack && ch == '_') { /* non-destructive underscore */
(void) putchar((char) ' ');
backsp();
}
(void) putchar((char) ' ');
backsp();
}
#endif
if (iflags.use_color) {
ttyDisplay->colorflags = NH_BASIC_COLOR;
@@ -3965,13 +3962,12 @@ term_start_bgcolor(int color)
{
/* placeholder for now */
}
#endif /* !MSDOS && !WIN32 */
void
term_curs_set(int visibility UNUSED)
{
/* nothing */
}
#endif
#ifdef CHANGE_COLOR
void

View File

@@ -53,7 +53,6 @@ Version _WIN_32IE Platform/IE
/*#define COMCTL_URL
* "http://www.microsoft.com/msdownload/ieplatform/ie/comctrlx86.asp"*/
ATTRNORETURN extern void nethack_exit(int) NORETURN;
static TCHAR *_get_cmd_arg(TCHAR *pCmdLine);
static HRESULT GetComCtlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor);
BOOL WINAPI