From d9da3196227902ec4c57415ed828b8e68ba25621 Mon Sep 17 00:00:00 2001 From: Ingo Paschke Date: Sun, 3 May 2026 17:48:15 +0200 Subject: [PATCH 1/3] Amiga: honor __stack under libnix Reference __stkinit so the linker pulls swapstack.o from libnix.a; without it the program runs on the inherited shell stack and crashes inside Lua / level-gen. --- sys/amiga/amistack.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sys/amiga/amistack.c b/sys/amiga/amistack.c index 2d38b552a..84ae496e1 100644 --- a/sys/amiga/amistack.c +++ b/sys/amiga/amistack.c @@ -22,6 +22,10 @@ #ifdef __SASC_60 long __stack = 256 * 1024; #else -/* For GCC with -noixemul (libnix), __stack is also recognized */ +/* libnix needs __stkinit referenced to pull swapstack.o from libnix.a */ unsigned long __stack = 256 * 1024; +#ifdef CROSS_TO_AMIGA +extern void __stkinit(void); +void *__nh_force_stkinit = __stkinit; +#endif #endif From 2a59726f1851120d406171618615acfce16c2d28 Mon Sep 17 00:00:00 2001 From: Ingo Paschke Date: Sun, 3 May 2026 17:48:22 +0200 Subject: [PATCH 2/3] Amiga: disable SYSCF, drop sysconf from package SYSCF is for multi-user system-admin lockdown; single-user Amigas don't need it, and assure_syscf_file() killing the binary when run outside NetHack: was breaking normal launches. --- include/amiconf.h | 3 +++ sys/unix/hints/include/cross-post.500 | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/amiconf.h b/include/amiconf.h index 17b03c2eb..a362c94f8 100644 --- a/include/amiconf.h +++ b/include/amiconf.h @@ -212,4 +212,7 @@ struct ami_sysflags { }; extern struct ami_sysflags sysflags; +#undef SYSCF +#undef SYSCF_FILE + #endif /* AMICONF_H */ diff --git a/sys/unix/hints/include/cross-post.500 b/sys/unix/hints/include/cross-post.500 index f4f236e2f..8e67cfa4f 100644 --- a/sys/unix/hints/include/cross-post.500 +++ b/sys/unix/hints/include/cross-post.500 @@ -318,7 +318,6 @@ amigapkg: $(AMITILES) ../util/uudecode cp $(TARGETPFX)tiles16.iff $(TARGETPFX)pkg/tiles/tiles16.iff cp $(TARGETPFX)tiles32.iff $(TARGETPFX)pkg/tiles/tiles32.iff cp $(TARGETPFX)tomb.iff $(TARGETPFX)pkg/tomb.iff - cp ../sys/msdos/sysconf $(TARGETPFX)pkg/sysconf cp ../doc/nethack.txt $(TARGETPFX)pkg/nethack.txt ( cd $(TARGETPFX)pkg && ../../../util/uudecode ../../../sys/amiga/amifont8.uu && mv 8 hack/8 ) ( cd $(TARGETPFX)pkg && ../../../util/uudecode ../../../sys/amiga/amifont.uu ) From b6747f89ca4d0c1a3da1fecf01808aec59182ab2 Mon Sep 17 00:00:00 2001 From: Ingo Paschke Date: Sun, 3 May 2026 17:48:30 +0200 Subject: [PATCH 3/3] Amiga: fall back to text mode when tile mode is not viable Detect Workbench depth, display-database MaxDepth, and free chip RAM; if any signals AMIV can't run (e.g. A1000 with 4-colour WB), swap windowprocs to amii_procs before opening any screens. --- sys/amiga/nethack.cnf | 5 ++++- sys/amiga/winfuncs.c | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/sys/amiga/nethack.cnf b/sys/amiga/nethack.cnf index 84dd3d60b..b594c3d99 100644 --- a/sys/amiga/nethack.cnf +++ b/sys/amiga/nethack.cnf @@ -5,7 +5,10 @@ # *** DISPLAY MODE *** # -# Tile mode (graphical tiles, recommended): +# Tile mode (graphical tiles, recommended). Needs >=384 KB free chip +# RAM and a display mode that can open at 4 bitplanes (16 colours); on +# machines that can't, NetHack will automatically fall back to text +# mode at startup. OPTIONS=windowtype:amiv # # Text mode (uses hack.font line-drawing characters): diff --git a/sys/amiga/winfuncs.c b/sys/amiga/winfuncs.c index 7d451a665..e39af4a5d 100644 --- a/sys/amiga/winfuncs.c +++ b/sys/amiga/winfuncs.c @@ -886,6 +886,49 @@ int return 0; } +/* Fall back from AMIV (tile) to AMII (text) if this machine can't + * run tile mode. Probes in order of reliability. */ +static void +amii_fall_back(const char *why1, const char *why2) +{ + extern struct window_procs amii_procs; + + raw_print(why1); + raw_print(why2); + raw_print("Falling back to text mode. Set windowtype:amiv in"); + raw_print("nethack.cnf to override."); + windowprocs = amii_procs; + ami_wininit_data(WININIT); +} + +static void +amii_maybe_fall_back_to_text(void) +{ + if (!WINVERS_AMIV) + return; + + if (IntuitionBase->LibNode.lib_Version >= 37) { + struct Screen *wbscr; + int wb_depth = -1; + + if ((wbscr = LockPubScreen("Workbench")) != NULL) { + wb_depth = wbscr->BitMap.Depth; + UnlockPubScreen(NULL, wbscr); + } + if (wb_depth >= 0 && wb_depth < 4) { + amii_fall_back("Workbench screen is shallower than 16 colours", + "(tile mode requires depth >= 4)."); + return; + } + } + + if (AvailMem(MEMF_CHIP) < 384L * 1024L) { + amii_fall_back("Not enough chip RAM available for tile mode", + "(< 384 KB free)."); + return; + } +} + /* Initialize the windowing environment */ void @@ -951,6 +994,8 @@ amii_init_nhwindows(int *argcp, char **argv) Abort(AG_OpenLib); } + amii_maybe_fall_back_to_text(); + amiIDisplay = (struct amii_DisplayDesc *) alloc(sizeof(struct amii_DisplayDesc)); memset(amiIDisplay, 0, sizeof(struct amii_DisplayDesc));