From b6747f89ca4d0c1a3da1fecf01808aec59182ab2 Mon Sep 17 00:00:00 2001 From: Ingo Paschke Date: Sun, 3 May 2026 17:48:30 +0200 Subject: [PATCH] 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));