Merge branch 'windows-makefile' into NetHack-3.7

This commit is contained in:
nhmall
2022-12-05 13:27:25 -05:00
13 changed files with 1345 additions and 934 deletions

View File

@@ -254,7 +254,7 @@ typedef uchar nhsym;
#endif
#if defined(X11_GRAPHICS) || defined(QT_GRAPHICS) || defined(GNOME_GRAPHICS) \
|| defined(WIN32)
|| defined(MSWIN_GRAPHICS)
#ifndef NO_TILE_C
#ifndef USE_TILES
#define USE_TILES /* glyphmap[] with prefilled tile mappings will be available */

View File

@@ -561,7 +561,7 @@ static int optfn_##a(int, int, boolean, char *, char *);
#endif
NHOPTC(statuslines, Status, 20, opt_in, set_in_game,
No, Yes, No, No, NoAlias, "2 or 3 lines for status display")
#ifdef WIN32
#ifdef WIN32CON
NHOPTC(subkeyvalue, Advanced, 7, opt_in, set_in_config,
No, Yes, Yes, No, NoAlias, "override keystroke value")
#endif

View File

@@ -29,7 +29,7 @@
#define DUMPLOG_MSG_COUNT 50
#define USER_SOUNDS
#define TTY_SOUND_ESCCODES
/* #define TTY_SOUND_ESCCODES */
/*#define CHANGE_COLOR*/ /* allow palette changes */

6
src/.gitignore vendored
View File

@@ -12,6 +12,7 @@ Systos
SysBe
nethack
*.o
*.tag
tiles.bmp
*.moc
*.lnk
@@ -21,4 +22,9 @@ o
nhdat*
date.nmk
tilemappings.lst
objgui/*
objtty/*
objutil/*
objlua/*
objpdc/*

View File

@@ -426,7 +426,7 @@ moveloop_core(void)
gc.context.move = 1;
if (gm.multi >= 0 && go.occupation) {
#if defined(MICRO) || defined(WIN32)
#if defined(MICRO) || defined(WIN32CON)
mvl_abort_lev = 0;
if (kbhit()) {
char ch;

View File

@@ -715,7 +715,7 @@ optfn_altkeyhandling(
if (req == do_set) {
/* altkeyhandling:string */
#if defined(WIN32) && defined(TTY_GRAPHICS)
#if defined(WIN32CON) && defined(TTY_GRAPHICS)
if (op == empty_optstr || negated)
return optn_err;
set_altkeyhandling(op);
@@ -739,7 +739,7 @@ optfn_altkeyhandling(
#endif
return optn_ok;
}
#ifdef WIN32
#ifdef WIN32CON
if (req == do_handler) {
return set_keyhandling_via_option();
}
@@ -3399,7 +3399,7 @@ optfn_statuslines(int optidx, int req, boolean negated, char *opts, char *op)
return optn_ok;
}
#ifdef WIN32
#ifdef WIN32CON
static int
optfn_subkeyvalue(int optidx UNUSED, int req, boolean negated UNUSED,
char *opts, char *op UNUSED)
@@ -3423,7 +3423,7 @@ optfn_subkeyvalue(int optidx UNUSED, int req, boolean negated UNUSED,
}
return optn_ok;
}
#endif /* WIN32 */
#endif /* WIN32CON */
static int
optfn_suppress_alert(int optidx, int req, boolean negated,

File diff suppressed because it is too large Load Diff

View File

@@ -1,228 +0,0 @@
/* NetHack 3.7 stubs.c $NHDT-Date: 1596498317 2020/08/03 23:45:17 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.31 $ */
/* Copyright (c) 2015 by Michael Allison */
/* NetHack may be freely redistributed. See license for details. */
#include "win32api.h"
#include "hack.h"
#ifdef GUISTUB
#ifdef TTYSTUB
#error You cannot compile this with both GUISTUB and TTYSTUB defined.
#endif
struct window_procs mswin_procs = { WPIDMINUS(guistubs) };
#ifdef QT_GRAPHICS
struct window_procs Qt_procs = { WPIDMINUS(guistubs) };
int qt_tilewidth, qt_tileheight, qt_fontsize, qt_compact_mode;
#endif
void
mswin_destroy_reg(void)
{
return;
}
void
mswin_raw_print_flush(void)
{
}
void
mswin_raw_print(const char *str)
{
}
/* MINGW32 has trouble with both a main() and WinMain()
* so we move main for the MINGW tty version into this stub
* so that it is out of sight for the gui linkage.
*/
#ifdef __MINGW32__
extern char default_window_sys[];
extern int mingw_main(int argc, char **argv);
int
main(int argc, char *argv[])
{
boolean resuming;
resuming = mingw_main(argc, argv);
nethack_exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
}
#endif
#endif /* GUISTUB */
/* =============================================== */
#ifdef TTYSTUB
HANDLE hConIn;
HANDLE hConOut;
struct window_procs tty_procs = { WPIDMINUS(ttystubs) };
#ifdef CURSES_GRAPHICS
char erase_char, kill_char;
#endif
void
win_tty_init(int dir)
{
return;
}
void
consoletty_open(int mode)
{
return;
}
int
xputc(int ch)
{
return 0;
}
void
xputs(const char *s)
{
return;
}
void
raw_clear_screen(void)
{
return;
}
void
clear_screen(void)
{
return;
}
void
backsp(void)
{
return;
}
#ifndef NO_MOUSE_ALLOWED
void
toggle_mouse_support(void)
{
return;
}
#endif
#ifdef PORT_DEBUG
void
win32con_debug_keystrokes(void)
{
return;
}
void
win32con_handler_info(void)
{
return;
}
#endif
void
map_subkeyvalue(char *op)
{
return;
}
/* this is used as a printf() replacement when the window
* system isn't initialized yet
*/
void msmsg
VA_DECL(const char *, fmt)
{
VA_START(fmt);
VA_INIT(fmt, const char *);
VA_END();
return;
}
/*VARARGS1*/
void consoletty_error
VA_DECL(const char *, s)
{
VA_START(s);
VA_INIT(s, const char *);
VA_END();
return;
}
#ifdef TTY_GRAPHICS
void
synch_cursor(void)
{
return;
}
#ifdef TTY_PERM_INVENT
boolean in_tty_perm_invent_toggled = FALSE;
void
tty_perm_invent_toggled(boolean negated)
{
}
#endif /* TTY_PERM_INVENT */
#endif /* TTY_GRAPHICS */
void
more(void)
{
return;
}
void
nethack_enter_consoletty(void)
{
return;
}
void
set_altkeyhandler(const char *inName)
{
return;
}
#if defined(USER_SOUNDS) && defined(TTY_SOUND_ESCCODES)
void
play_usersound_via_idx(int idx, int volume)
{
}
#endif /* USER_SOUNDS && TTY_SOUND_ESCCODES */
void
set_altkeyhandling(const char *inName)
{
}
int
set_keyhandling_via_option(void)
{
return 1;
}
#ifdef CURSES_GRAPHICS
struct window_procs curses_procs = {WPIDMINUS(curses)};
int curses_read_attrs(const char *attrs)
{
return 0;
}
char *
curses_fmt_attrs(char *outbuf)
{
int attr = iflags.wc2_petattr;
outbuf[0] = '\0';
Sprintf(outbuf, "+unknown [%d]", attr);
return &outbuf[1];
}
#endif
#endif /* TTYSTUBS */

View File

@@ -35,7 +35,7 @@
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<AdditionalIncludeDirectories>$(WinWin32Dir);$(IncDir);$(SysWindDir);$(SysShareDir);$(WinShareDir);$(LuaDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32CON;NO_TILE_C;DLB;MSWIN_GRAPHICS;SAFEPROCS;_LIB;HAS_STDINT_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32CON;NO_TILE_C;DLB;SAFEPROCS;_LIB;HAS_STDINT_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;winmm.lib;Winmm.lib;bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -171,9 +171,6 @@
<ClCompile Include="$(SysShareDir)random.c" />
<ClCompile Include="$(SysWindDir)ntsound.c" />
<ClCompile Include="$(SysWindDir)consoletty.c" />
<ClCompile Include="$(SysWindDir)stubs.c">
<PreprocessorDefinitions>GUISTUB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="$(SysWindDir)windmain.c" />
<ClCompile Include="$(SysWindDir)windsys.c" />
<ClCompile Include="$(WinShareDir)safeproc.c" />

View File

@@ -15,6 +15,12 @@
<PropertyGroup>
<OutDir>$(BinDir)</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/Gs /Oi- /w44774 %(AdditionalOptions)</AdditionalOptions>
@@ -167,9 +173,6 @@
<ClCompile Include="$(SysShareDir)cppregex.cpp" />
<ClCompile Include="$(SysShareDir)random.c" />
<ClCompile Include="$(SysWindDir)ntsound.c" />
<ClCompile Include="$(SysWindDir)stubs.c">
<PreprocessorDefinitions>TTYSTUB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="$(SysWindDir)windmain.c" />
<ClCompile Include="$(SysWindDir)windsys.c" />
<ClCompile Include="$(SysWindDir)win10.c" />
@@ -311,4 +314,4 @@
<Target Name="AfterRebuild">
<MSBuild Projects="$(vsDir)NetHack\afternethack.proj" Targets="Build" Properties="Configuration=$(Configuration)" />
</Target>
</Project>
</Project>

View File

@@ -32,8 +32,10 @@ extern void nethack_exit(int) NORETURN;
extern void mswin_destroy_reg(void);
#endif
#ifdef TTY_GRAPHICS
#ifdef WIN32CON
extern void backsp(void);
#endif
#endif
extern void clear_screen(void);
#ifdef update_file
@@ -49,12 +51,14 @@ extern void (*cursesgraphics_mode_callback)(void);
extern void (*utf8graphics_mode_callback)(void);
#endif
#ifdef WIN32CON
#ifdef _MSC_VER
#ifdef kbhit
#undef kbhit
#endif
#include <conio.h.>
#endif
#endif
#ifdef PC_LOCKING
static int eraseoldlocks(void);
@@ -65,9 +69,13 @@ int windows_nh_poskey(int *, int *, int *);
void windows_raw_print(const char *);
char windows_yn_function(const char *, const char *, char);
static void windows_getlin(const char *, char *);
#ifdef WIN32CON
extern int windows_console_custom_nhgetch(void);
void safe_routines(void);
int tty_self_recover_prompt(void);
#endif
int other_self_recover_prompt(void);
char orgdir[PATHLEN];
@@ -78,8 +86,11 @@ int windows_startup_state = 0; /* we flag whether to continue with this */
extern int redirect_stdout; /* from sys/share/pcsys.c */
extern int GUILaunched;
HANDLE hStdOut;
char default_window_sys[] =
#if defined(MSWIN_GRAPHICS)
char default_window_sys[] = "mswin";
"mswin";
#elif defined(TTY_GRAPHICS)
"tty";
#endif
#ifdef WANT_GETHDATE
static struct stat hbuf;
@@ -437,11 +448,14 @@ mingw_main(int argc, char *argv[])
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
#ifdef WIN32CON
/*
* Get a set of valid safe windowport function
* pointers during early startup initialization.
*/
safe_routines();
#endif /* WIN32CON */
early_init();
#ifdef _MSC_VER
#ifdef DEBUG
@@ -556,13 +570,17 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
iflags.use_background_glyph = FALSE;
if (WINDOWPORT(mswin))
iflags.use_background_glyph = TRUE;
#ifdef WIN32CON
if (WINDOWPORT(tty))
consoletty_open(1);
#endif
init_nhwindows(&argc, argv);
#ifdef WIN32CON
if (WINDOWPORT(tty))
toggle_mouse_support();
#endif
if (gs.symset[PRIMARYSET].handling
&& !symset_is_compatible(gs.symset[PRIMARYSET].handling,
@@ -760,12 +778,14 @@ process_options(int argc, char * argv[])
nethack_exit(EXIT_SUCCESS);
}
#ifdef MSWIN_GRAPHICS
if (GUILaunched) {
if (!strncmpi(argv[1], "-clearreg", 6)) { /* clear registry */
mswin_destroy_reg();
nethack_exit(EXIT_SUCCESS);
}
}
#endif
/* Don't initialize the full window system just to print usage */
if (!strncmp(argv[1], "-?", 2) || !strncmp(argv[1], "/?", 2)) {
nhusage();
@@ -902,6 +922,7 @@ nhusage(void)
#undef ADD_USAGE
}
#ifdef WIN32CON
void
safe_routines(void)
{
@@ -914,6 +935,7 @@ safe_routines(void)
if (!GUILaunched)
windowprocs.win_nhgetch = windows_console_custom_nhgetch;
}
#endif
#ifdef PORT_HELP
void
@@ -937,8 +959,8 @@ authorize_wizard_mode(void)
#if defined(WIN32) && !defined(WIN32CON)
static char exenamebuf[PATHLEN];
extern HANDLE hConIn;
extern HANDLE hConOut;
HANDLE hConIn;
HANDLE hConOut;
boolean has_fakeconsole;
char *
@@ -1166,7 +1188,9 @@ getlock(void)
const char *fq_lock;
#define OOPS_BUFSZ 512
char oops[OOPS_BUFSZ];
#ifdef WIN32CON
boolean istty = WINDOWPORT(tty);
#endif
/* we ignore QUIT and INT at this point */
if (!lock_file(HLOCK, LOCKPREFIX, 10)) {
@@ -1197,9 +1221,11 @@ getlock(void)
(void) nhclose(fd);
#ifdef WIN32CON
if (WINDOWPORT(tty))
prompt_result = tty_self_recover_prompt();
else
#endif
prompt_result = other_self_recover_prompt();
/*
* prompt_result == 1 means recover old game.
@@ -1212,8 +1238,10 @@ getlock(void)
: (prompt_result == 1)
? "recover the old game"
: "not start a new game");
#ifdef WIN32CON
if (istty)
clear_screen();
#endif
raw_printf("%s", oops);
if (prompt_result == 1) { /* recover */
if (recover_savefile()) {
@@ -1231,8 +1259,10 @@ getlock(void)
}
} else if (prompt_result < 0) { /* destroy old game */
if (eraseoldlocks()) {
#ifdef WIN32CON
if (istty)
clear_screen(); /* display gets fouled up otherwise */
#endif
goto gotlock;
} else {
unlock_file(HLOCK);
@@ -1320,6 +1350,7 @@ file_newer(const char* a_path, const char* b_path)
return FALSE;
}
#ifdef WIN32CON
/*
* returns:
* 1 if game should be recovered
@@ -1391,6 +1422,7 @@ tty_self_recover_prompt(void)
}
return retval;
}
#endif
int
other_self_recover_prompt(void)

View File

@@ -48,6 +48,7 @@ extern int GUILaunched;
extern boolean getreturn_enabled;
int redirect_stdout;
#ifdef WIN32CON
typedef HWND(WINAPI *GETCONSOLEWINDOW)();
static HWND GetConsoleHandle(void);
static HWND GetConsoleHwnd(void);
@@ -66,6 +67,21 @@ extern void safe_routines(void);
int def_kbhit(void);
int (*nt_kbhit)() = def_kbhit;
#endif /* WIN32CON */
#ifndef WIN32CON
/* this is used as a printf() replacement when the window
* system isn't initialized yet
*/
void msmsg
VA_DECL(const char *, fmt)
{
VA_START(fmt);
VA_INIT(fmt, const char *);
VA_END();
return;
}
#endif
char
switchar(void)
@@ -187,8 +203,10 @@ return &szFullPath[0];
}
#endif
#ifdef MSWIN_GRAPHICS
extern void mswin_raw_print_flush(void);
extern void mswin_raw_print(const char *);
#endif
/* fatal error */
/*VARARGS1*/
@@ -211,8 +229,10 @@ VA_DECL(const char *, s)
Strcat(buf, "\n");
raw_printf(buf);
}
#ifdef MSWIN_GRAPHICS
if (windowprocs.win_raw_print == mswin_raw_print)
mswin_raw_print_flush();
#endif
VA_END();
exit(EXIT_FAILURE);
}
@@ -233,8 +253,10 @@ win32_abort(void)
exit_nhwindows((char *) 0);
iflags.window_inited = FALSE;
}
#ifdef WIN32CON
if (!WINDOWPORT(mswin) && !WINDOWPORT(safestartup))
safe_routines();
#endif
if (wizard) {
raw_print("Execute debug breakpoint wizard?");
if ((c = nhgetch()) == 'y' || c == 'Y')
@@ -368,6 +390,7 @@ void port_insert_pastebuf(char *buf)
return;
}
#ifdef WIN32CON
static HWND
GetConsoleHandle(void)
{
@@ -405,7 +428,7 @@ GetConsoleHwnd(void)
/* printf("%d iterations\n", iterations); */
return hwndFound;
}
#endif /* WIN32CON */
#endif
#ifdef RUNTIME_PORT_ID
@@ -447,12 +470,14 @@ nethack_exit(int code)
*/
#ifdef WIN32CON
if (!GUILaunched) {
windowprocs = *get_safe_procs(1);
/* use our custom version which works
a little cleaner than the stdio one */
windowprocs.win_nhgetch = windows_console_custom_nhgetch;
}
#endif
if (getreturn_enabled) {
raw_print("\n");
wait_synch();
@@ -460,6 +485,7 @@ nethack_exit(int code)
exit(code);
}
#ifdef WIN32CON
#undef kbhit
#include <conio.h>
@@ -488,13 +514,16 @@ getreturn(const char *str)
in_getreturn = FALSE;
return;
}
#endif
/* nethack_enter_windows() is called from main immediately after
initializing the window port */
void nethack_enter_windows(void)
{
#ifdef WIN32CON
if (WINDOWPORT(tty))
nethack_enter_consoletty();
#endif
}
/* CP437 to Unicode mapping according to the Unicode Consortium */

View File

@@ -106,7 +106,7 @@ struct window_procs tty_procs = {
#ifdef MSDOS
| WC_TILED_MAP | WC_ASCII_MAP
#endif
#if defined(WIN32)
#if defined(WIN32CON)
| WC_MOUSE_SUPPORT
#endif
| WC_COLOR | WC_HILITE_PET | WC_INVERSE | WC_EIGHT_BIT_IN),
@@ -120,7 +120,7 @@ struct window_procs tty_procs = {
#endif
| WC2_DARKGRAY | WC2_SUPPRESS_HIST | WC2_URGENT_MESG | WC2_STATUSLINES
| WC2_U_UTF8STR
#if !defined(NO_TERMS) || defined(WIN32)
#if !defined(NO_TERMS) || defined(WIN32CON)
| WC2_U_24BITCOLOR
#endif
),
@@ -555,7 +555,7 @@ tty_preference_update(const char *pref)
new_status_window();
}
#if defined(WIN32)
#if defined(WIN32CON)
consoletty_preference_update(pref);
#else
genl_preference_update(pref);
@@ -1531,7 +1531,7 @@ tty_exit_nhwindows(const char *str)
#ifndef NO_TERMS /*(until this gets added to the window interface)*/
tty_shutdown(); /* cleanup termcap/terminfo/whatever */
#endif
#ifdef WIN32
#ifdef WIN32CON
consoletty_exit();
#endif
iflags.window_inited = 0;
@@ -4085,7 +4085,7 @@ end_glyphout(void)
#endif
}
#ifndef WIN32
#ifndef WIN32CON
void
g_putch(int in_ch)
{
@@ -4125,7 +4125,7 @@ g_putch(int in_ch)
return;
}
#endif /* !WIN32 */
#endif /* !WIN32CON */
#if defined(ENHANCED_SYMBOLS) && defined(UNIX)
void