MS-DOS/Compiling NetHack 3.4.3 in real mode

From NetHackWiki
Jump to navigation Jump to search

This post to rec.games.roguelike.nethack describes a successful build of NetHack 3.4.3 for real mode MS-DOS.

The complete thread can be found in the Wayback Machine's archive of Google Groups. Google Groups itself only sporadically allows reading of direct links to posts. This post contains a patch, and Google Groups' mangling of whitespace is a problem. The text below is recovered from the Internet Archive.

The post as recovered had tabs converted to spaces. These are converted back to tabs, to give a patch that applies cleanly.

Path: number1.nntp.ams.giganews.com!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.glorb.com!sn-xit-04!sn-xit-06!sn-post-01!supernews.com!corp.supernews.com!not-for-mail
From: Ray Chason <long-defunct email address redacted>
Newsgroups: rec.games.roguelike.nethack
Subject: Support for real-mode MS-DOS:  still worthwhile?
Date: Tue, 08 Feb 2005 20:36:30 -0500
Organization: Not Bloody Likely
Message-ID: <110iq1nmc55t93b@corp.supernews.com>
User-Agent: KNode/0.7.7
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7Bit
X-Windows-95: Where do you want to go today?
X-Windows-XP: All your base are belong to us.
X-Complaints-To: abuse@supernews.com
Lines: 283
Xref: number1.nntp.dca.giganews.com rec.games.roguelike.nethack:279037

Just to see if it could still be done, or if maybe it was time to drop
support for it, I tried to make a 16-bit MS-DOS build of NetHack.  I was
indeed able to get it to run, although it doesn't exactly dance.

The necessary tweaks to the code were surprisingly few:

    * In eat.c, the function "maybe_finished_meal" is defined in OVL1,
      but references the static variable "victual" in OVLB.  The easiest
      thing to do was to move the function to OVLB.

    * In invent.c, the function "display_pickinv" is declared static,
      but referenced from another overlay.  It is redeclared with the
      STATIC_DCL and STATIC_OVL macros.

    * In objnam.c, the function "nextobuf" is likewise declared static,
      but referenced from another overlay.  It is redeclared with the
      STATIC_DCL and STATIC_OVL macros.

It was also necessary to add mapglyph.o to the schema files, schema1.BC
and schema2.BC, and to modify the makefile to fix some syntax that this
particular version of Make didn't understand.  I imagine that the file
schema3.MSC also needs to be modified, but I leave the build on the
Microsoft compiler as an exercise for the reader.

With this done, and schema 2 selected, the program compiled...but was too
big to run, asking for about 43,800 bytes more memory.  This is on a
Windows XP box on which the MEM command reports:

    655360 bytes total conventional memory
    655360 bytes available to MS-DOS
    598480 largest executable program size

   1048576 bytes total contiguous extended memory
         0 bytes available contiguous extended memory
    941056 bytes available XMS memory
           MS-DOS resident in High Memory Area

Borland's compilers have tended to generate larger code with each new
version, and perhaps using 3.1, as the makefile comment suggests, might
get this build under size.

As it was, I used 4.52.  Linking in NOEHL.LIB was helpful, cutting the
memory requirement by about 20K.  (The libraries use some C++ exception
handlers internally, which are quite large; NOEHx.LIB replaces them
with smaller stubs.)  Cutting out tile support also helped, and got the
program to run.

I played a short game as a Tourist, and rather quickly got myself killed.

The program felt quite sluggish, taking a slight but noticeable moment to
respond to the keyboard.  This was on a 2.4 GHz Celeron.  I shudder to
think how it might have responded on an original IBM PC.

Back to the memory requirement.  Even with schema 2, which is set up to
place everything possible in the overlays, Nethack needed practically the
whole lower 640K to run.  In particular, it needed, as MEM reported,
MS-DOS resident in the High Memory Area.

But if you even *have* a High Memory Area, then you have at least a 286.
Even if using an earlier compiler might further shrink the requirement,
Nethack is already close to demanding more than an 8088-based PC can give.
There is, it seems, already a minimum requirement of a 286; and if there
is not, there likely will be in some future version.

Maybe it's time to drop support for the real-mode build.  If it is still
desirable to support Nethack on a 286, it may be possible to find, or
write, a suitable 16-bit DOS extender, leaving no need to put up with
overlays.  Cutting out overlays would remove some of the clutter from
the code without impairing the builds for more modern hardware.

Here is a patch that makes the necessary changes, and creates the exact
makefile that I used to build a real mode Nethack.

--CUT HERE--CUT HERE--CUT HERE--CUT HERE--CUT HERE--CUT HERE--CUT HERE--
diff -U 3 -r nethack-3.4.3/src/eat.c nethack-3.4.3-msdos16/src/eat.c
--- nethack-3.4.3/src/eat.c	Sun Dec 07 18:39:13 2003
+++ nethack-3.4.3-msdos16/src/eat.c	Mon Feb 07 22:56:49 2005
@@ -2563,9 +2563,6 @@
     }
 }
 
-#endif /* OVLB */
-#ifdef OVL1
-
 /* called when eatfood occupation has been interrupted,
    or in the case of theft, is about to be interrupted */
 boolean
@@ -2581,6 +2578,6 @@
 	return FALSE;
 }
 
-#endif /* OVL1 */
+#endif /* OVLB */
 
 /*eat.c*/
diff -U 3 -r nethack-3.4.3/src/invent.c nethack-3.4.3-msdos16/src/invent.c
--- nethack-3.4.3/src/invent.c	Sun Dec 07 18:39:13 2003
+++ nethack-3.4.3-msdos16/src/invent.c	Mon Feb 07 22:57:21 2005
@@ -19,7 +19,7 @@
 STATIC_DCL boolean FDECL(putting_on, (const char *));
 STATIC_PTR int FDECL(ckunpaid,(struct obj *));
 STATIC_PTR int FDECL(ckvalidcat,(struct obj *));
-static char FDECL(display_pickinv, (const char *,BOOLEAN_P, long *));
+STATIC_DCL char FDECL(display_pickinv, (const char *,BOOLEAN_P, long *));
 #ifdef OVLB
 STATIC_DCL boolean FDECL(this_type_only, (struct obj *));
 STATIC_DCL void NDECL(dounpaid);
@@ -1689,7 +1689,7 @@
  * inventory and return a count as well as a letter. If out_cnt is not null,
  * any count returned from the menu selection is placed here.
  */
-static char
+STATIC_OVL char
 display_pickinv(lets, want_reply, out_cnt)
 register const char *lets;
 boolean want_reply;
diff -U 3 -r nethack-3.4.3/src/objnam.c nethack-3.4.3-msdos16/src/objnam.c
--- nethack-3.4.3/src/objnam.c	Sun Dec 07 18:39:13 2003
+++ nethack-3.4.3-msdos16/src/objnam.c	Mon Feb 07 22:56:11 2005
@@ -13,7 +13,7 @@
 #ifdef OVLB
 static boolean FDECL(wishymatch, (const char *,const char *,BOOLEAN_P));
 #endif
-static char *NDECL(nextobuf);
+STATIC_DCL char *NDECL(nextobuf);
 static void FDECL(add_erosion_words, (struct obj *, char *));
 
 struct Jitem {
@@ -77,7 +77,7 @@
 #ifdef OVLB
 
 /* manage a pool of BUFSZ buffers, so callers don't have to */
-static char *
+STATIC_OVL char *
 nextobuf()
 {
 	static char NEARDATA bufs[NUMOBUF][BUFSZ];
diff -U 3 -r nethack-3.4.3/sys/msdos/Makefile.BC nethack-3.4.3-msdos16/sys/msdos/Makefile.BC
--- nethack-3.4.3/sys/msdos/Makefile.BC	Sun Dec 07 18:39:13 2003
+++ nethack-3.4.3-msdos16/sys/msdos/Makefile.BC	Tue Feb 08 00:34:56 2005
@@ -54,7 +54,7 @@
 UUDECODE = uudecode	# Unix style uudecoder
 
 #BCTOP	 = c:\borlandc	# main Borland C++ directory
-BCTOP	 = c:\bc31
+BCTOP	 = c:\bc45
 
 #
 # Yacc/Lex ... if you got 'em.
@@ -164,7 +164,7 @@
 #	"video".
 #
 
-TILESUPPORT = Y
+TILESUPPORT = N
 
 #
 #  C COMPILER AND LINKER SETTINGS
@@ -329,9 +329,10 @@
 #
 
 LWCASE	= /c			# treat case as significant
-LMAP	= /m			# create map file
+LMAP	= /s			# create map file
 LINIT	= $(BCLIB)\C0$(MODEL)	# initialization object file
 LOVL	= /oOVLY		# overlay all needed segments
+LEXC    = $(BCLIB)\NOEH$(MODEL).LIB
 
 #
 # Stack Sizes
@@ -481,7 +482,7 @@
 
 LFLAGSU	= $(LDFLAGSU) $(LUSTACK) $(LINIT)
 LFLAGSN	= $(LDFLAGSN) $(LNSTACK) $(LWCASE) $(LMAXSEG) $(INTOVL) $(LMAXALL) \
-	  $(LINFO) $(LINIT) $(LOVL)
+	  $(LMAP) $(LINFO) $(LINIT) $(LEXC) $(LOVL)
 
 #
 # Make Roolz dude.
@@ -1001,21 +1002,21 @@
 
 #
 #  Inline files :
-#			Specifying the "<<" means to start an inline file.
-#                 	Another "<<" at the start of a line closes the
+#			Specifying the "&&!" means to start an inline file.
+#                 	Another "!" at the start of a line closes the
 #                 	inline file.
 #
-#  DO NOT INDENT THE << below!
+#  DO NOT INDENT THE ! below!
 #
 
 $(GAMEFILE) :  $(ALLOBJ)
 	@echo Linking....
-	$(LINK) $(LFLAGSN) @<<$(GAME).lnk
+	$(LINK) $(LFLAGSN) @&&!
 		$(ALLOBJ)
 		$(GAMEFILE)
 		$(GAME)
 		$(TERMLIB) $(MOVETR) $(CLIB) $(BCOVL) $(BCMDL)
-<<
+!
 	@if exist $(GAMEDIR)\$(GAME).bak del $(GAMEDIR)\$(GAME).bak
 
 #
@@ -1273,28 +1274,28 @@
 #
 
 $(U)gif2txt.exe: $(GIFREADERS) $(TEXT_IO)
-	@$(LINK) $(LFLAGSU) << $(@B).lnk
+	@$(LINK) $(LFLAGSU) &&!
 		$(GIFREADERS) $(TEXT_IO)
 		$@,,$(CLIB) $(BCMDL)
-<<
+!
 
 $(U)txt2ppm.exe: $(PPMWRITERS) $(TEXT_IO)
-	@$(LINK) $(LFLAGSU) << $(@B).lnk
+	@$(LINK) $(LFLAGSU) &&!
 		$(PPMWRITERS) $(TEXT_IO)
 		$@,,$(CLIB) $(BCMDL);
-<<
+!
 
 $(U)gif2txt2.exe: $(GIFREAD2) $(TEXT_IO2)
-	@$(LINK) $(LFLAGSU) << $(@B).lnk
+	@$(LINK) $(LFLAGSU) &&!
 		$(GIFREAD2) $(TEXT_IO2)
 		$@,,$(CLIB) $(BCMDL);
-<<
+!
 
 $(U)txt2ppm2.exe: $(PPMWRIT2) $(TEXT_IO2)
-	@$(LINK) $(LFLAGSU) << $(@B).lnk
+	@$(LINK) $(LFLAGSU) &&!
 		$(PPMWRIT2) $(TEXT_IO2)
 		$@,,$(CLIB) $(BCMDL);
-<<
+!
 
 #
 #  Required for tile support
@@ -1376,7 +1377,7 @@
 	@echo dungeon >>dlb.lst
 	@echo license >>dlb.lst
 	@echo msdoshlp.txt >>dlb.lst
-	@for %%N in (*.lev) do echo %%N >>dlb.lst
+	@for %N in (*.lev) do echo %N >>dlb.lst
 	$(U)dlb_main cvIf dlb.lst $(SRC)\nhdat
 	@cd $(SRC)
 
diff -U 3 -r nethack-3.4.3/sys/msdos/schema1.BC nethack-3.4.3-msdos16/sys/msdos/schema1.BC
--- nethack-3.4.3/sys/msdos/schema1.BC	Sun Dec 07 18:39:13 2003
+++ nethack-3.4.3-msdos16/sys/msdos/schema1.BC	Mon Feb 07 22:54:12 2005
@@ -101,6 +101,7 @@
 -zCmakemon_1 -zAOVLY -zCOVL71
 -zCmakemon_2 -zAOVLY -zCOVL72
 -zCmakemon_b -zAOVLY -zCOVL73
+-zCmapglyph_o
 -zCmcastu_0 -zAOVLY -zCOVL74
 -zCmcastu_b -zAOVLY -zCOVL75
 -zCmhitm_0 -zAOVLY -zCOVL76
diff -U 3 -r nethack-3.4.3/sys/msdos/schema2.BC nethack-3.4.3-msdos16/sys/msdos/schema2.BC
--- nethack-3.4.3/sys/msdos/schema2.BC	Sun Dec 07 18:39:13 2003
+++ nethack-3.4.3-msdos16/sys/msdos/schema2.BC	Mon Feb 07 22:54:25 2005
@@ -97,6 +97,7 @@
 -zCmakemon_1 -zAOVLY -zCOVL85
 -zCmakemon_2 -zAOVLY -zCOVL86
 -zCmakemon_b -zAOVLY -zCOVL87
+-zCmapglyph_o
 -zCmcastu_0 -zAOVLY -zCOVL88
 -zCmcastu_b -zAOVLY -zCOVL89
 -zCmhitm_0 -zAOVLY -zCOVL90
--CUT HERE--CUT HERE--CUT HERE--CUT HERE--CUT HERE--CUT HERE--CUT HERE--

-- 
 --------------===============<[ Ray Chason ]>===============--------------
                  The War on Terra is not meant to be won.
                    Delendae sunt RIAA, MPAA et Windoze