NetHack now part of the Software Collection at MOMA

Asset 199863

It’s over online display here:

Jean-Christophe Collet made mention of it over on linked in of all places. Link to the article is here. Since I do not have a linked-in account (I was forced to open one at a prior employer, they were an early investor, back when absolutely *nobody* used the thing, before Microsoft had bought them), so I was unable to read the article. But before I had created a smurf account, I found that just switching to incognito mode got me the article in question.

It’s almost crazy to put it in perspective after all these years, but when NetHack became a thing in 1987, the GPL didn’t exist yet, instead opting for the BISON license. There was no NetBSD, nor was there a Net/1 release of BSD, meaning there was no wide-scale free Unix to the Masses.

I’ve tried numerous times to get into it, even playing it a fair bit when I got it running for the x68000. But I never got far, as I’m clearly out of my league. Which is a shame I’m clearly missing out on quite a bit.

Since it’s all news to me, there indeed is a software category over at MOMA. When I did live in New York, I was a member. I did all that artsy stuff, although I’m clearly not the artiste.

NetHack in your browser via Moxie CPU

I saw this many years ago, but for some reason never finished writing about this. Moxie was a virtual CPU designed to be as simple as possible for the GNU toolchain to target.

Perhaps one of the more interesting things was a port of RTEMS to the Moxie CPU, and a port of Nethack to that architecture. And of course, there was a javascript simulator environment allowing me to easily embed it into this post.

Terminal uses canvas

So yes, it’s a virtual CPU, OS & Game, running in java-script and on the page.

Spent some more time messing with NetHack 1.3d revived

1.3d revived and reloaded

1.3d revived and reloaded

And now it runs on Windows 10 (probably lots of Windows NT as well) thanks to EMX+RSXNT.

I put a Windows binary build on sourceforge, with the needed termcap and rsxnt.dll to run.  It works best if installed into the root of a drive, but it doesn’t matter which drive letter (I suppose you could even use subst).  I was patching around the stock NetHack 1.3d, but considering the weird issues I was having with it ‘mostly’ working, it was easier to just lean on the NetHack 1.3d revived project.  I should also say this is what I also used to get NetHack 1.3d running on the x68000.

I’ve been able to save, restore and go up, down and even die without it crashing so it seems OK to me.

It’s kind of cool to build it with GCC 1.40 on Windows 10, and get a native executable.  Maybe pointless in the golden age of emulation / virtualization as you could just as easily build stock 1.3d on a 4.2 BSD VAX, or even 386BSD 0.1 system.

Maybe I’ll finish the work to see if I can get it running on OS/2 or MS-DOS via EMX, but for now the project stuff is on sourceforge.net

GCC 1.40 on Windows

I know with all the talk of GCC 6.1.0 for MS-DOS, and other platforms, you must be thinking that all this talk of progress, and high versions numbers just isn’t right!  I’ve just started to migrate code to GCC 5.1, and now you are telling me there is a GCC 6!

Where can I turn away from all this so called progress!  I don’t like my C compilers to be C++ programs that require massive HOURS to compile.  Can’t we just go back to the good old days?

And the answer is YES, you can!

While looking for some libraries on another project, I came across this old defunct project called RSXNT. And it’s a port of EMX to Win32 platforms!  Well isn’t that fantastic!

So, considering I was able to build GCC 1.40 and cross compile to Linux 0.11 from Windows, can we do something with this?

Well ancient versions of EMX are very difficult to track down.  Somehow I did mange to find this hybrid of 0.8B & 0.8C.  The EMX runtime & binaries are from 0.8C, but the source code is from 0.8B.  And the best thing is that the 0.8B is based around GCC 1.40!  So with a little bit of tweaking the files, and messing around I got the assembler, linker, and C compiler to build with MinGW!  Sadly the source code to EMXBIND, wasn’t included in the zips that I have, but the aformentioned RSXNT packages included a version of EMXBIND that will run on Windows!  So I managed to mash them together, and for the fun of it, I’m using the old InfoTaskForce interpreter from 1987 to complete the vintage feel.

Compiling & Binding

Compiling & Binding

Now with my executable, I can run it on MS-DOS & OS/2!

MS-DOS via DOSBox

MS-DOS via DOSBox

and OS/2 2.0!

OS/2 (on Qemu)

OS/2 (on Qemu)

Well isn’t that fantastic!

However when running RSXNT’s bind, NTBIND I got this error:

D:\emx_w32\infocom>..\bin\ntbind info2
No relocations in file:
you have not linked the NT library

Great.  Some more digging around, and if you want to make Windows programs, you need to use the RSXNT includes & libraries.  So I shifted the libraries around, and patched gcc to call the linker the same way RSXNT’s gcc driver calls it, and first go this error:

io.o: Undefined symbol __streams referenced from text segment

And looking at the stdio.h there is this:

extern struct _stdio _streams[];

No doubt, the headers & libraries are tied together.  So now making both of the RSXNT versions, I can link the executable. (YES I did try declaring the structure anyways, and I get stdout, but stdin doesn’t work).

Running on Windows 10

Running on Windows 10

Just like EMX before it, RSXNT, requires you to have the RSXNT.DLL file in your path, or in the same directory.  I suppose it’s a fair trade off.  Not that I expect there to be a surge of people cross compiling from Windows to OS/2, or even MS-DOS these days.  GCC 1.40 is ancient, 1991 vintage, but even Linus Torvalds loved it!

For comparison, GCC 5.10 produces a 55,906 byte interpreter, while GCC 1.40 produces a 88,576 byte interpreter.

For an attempt at porting some code, I choose Nethack 1.3d, and used the MS-DOS based makefiles.  It didn’t work so well, but I was able to patch in enough of the unix based termios logic, and thanks to EMX/RSXNT’s built in termios capabilities I was able to get a working version!

Nethack 1.3d on Windows 10 x64

Nethack 1.3d on Windows 10 x64

I don’t know if there really was any advantage to compiling with GCC 1.40, but it was great to see that this 1991 compiler could handily compile the 1987 based code.

How about some speed comparisons?  I dug out the ancient dhrystone.c, and gave it a shot.  I had to define 500,000,000 passes, as my computer is fast.  GCC 1.40 only offers -O for optimization, while GCC 5.1 offers many more levels, but for this quick experiment they really aren’t needed.

D:\emx\demo\dhry>gcc140.exe
Dhrystone(1.1) time for 500000000 passes = 57
This machine benchmarks at 8771929 dhrystones/second

D:\emx\demo\dhry>gcc140_O.exe
Dhrystone(1.1) time for 500000000 passes = 40
This machine benchmarks at 12500000 dhrystones/second

D:\emx\demo\dhry>gcc510.exe
Dhrystone(1.1) time for 500000000 passes = 43
This machine benchmarks at 11627906 dhrystones/second

D:\emx\demo\dhry>gcc510_O.exe
Dhrystone(1.1) time for 500000000 passes = 16
This machine benchmarks at 31250000 dhrystones/second

D:\emx\demo\dhry>gcc510_O2.exe
Dhrystone(1.1) time for 500000000 passes = 14
This machine benchmarks at 35714285 dhrystones/second

D:\emx\demo\dhry>gcc510_Ofast.exe
Dhrystone(1.1) time for 500000000 passes = 11
This machine benchmarks at 45454545 dhrystones/second

As you can see, GCC 1.40 produces the slowest code.  While it’s optimized code did beat out GCC 5.10 with no optimizations, turning on optimizations did blow it away.  And again GCC 5.1 beat out the older 1.40 for executable sizes.

29,960 gcc510_O.exe
29,996 gcc510_O2.exe
30,472 gcc510.exe
70,656 gcc140_O.exe
74,752 gcc140.exe

And this time by over a 2x lead!  It is fair to say that the new versions of GCC, despite being significantly larger do indeed produce smaller and faster code.

For anyone who’s read this far, I guess you want to take it out for a test drive?  Remember it is still EMX based, which means is wants to live on the ROOT of your hard disk.  I’m using the ‘D’ drive for myself, so if you are using C or whatever you’ll need to alter the environment vars.

You can download the exe’s and combined source here: gcc-1.40_EMX-OS2_RSXNT.7z

NetHack 1.3d on the x68000

Ok, I know… why? But it’s more of a why not!

NetHack

NetHack

So I figured since I’ve had major issues trying to get DOOM to run, I’d try something bigger, like NetHack.  I figured its a good fit, it’s all ASCII based anyways, so how complicated can it be?

Actually it turned out to not be that complicated.  Thankfully having both run68’s source and NetHack source I was able to adapt enough of the system stuff to get it running. I decided to use this build of NetHack 1.3d that has been updated to compile with modern compilers, since the cross tools use GCC 4.6.2.  NetHack 1.3d synchronized PC hack, and UNIX based NetHack enough that I could start to build under MS-DOS, and then re-target it, as Human68k and MS-DOS share a lot of features (although Human68k has support for tasks, and shared memory.  It’s more like OS/2 although no memory protection… ).

I’ve gotten it to the point where you can save, load and quit.  Oddly enough the ANSI support in Human68k isn’t as good as ansicon so it actually runs better on run68.

So my next step will be to figure out more of the console controls on Human68k, and remove the ANSI support.

Ideally I’d love to figure out how to talk to the sound drivers on the x68000.  Add some music. Maybe sound effects, and graphics?

So for anyone who cares, my source directory, binaries and a xm6 disk image is all here. I’ve seen in the cvs tree on sourceforge that run68 has some support for BSD.  That’d be another interesting thing to add, common exe’s between windows/linux.  But console access first!

While hunting for Hack 1.0 in usenet

I came across this PDP-11 version.  I saved it to the side while I was looking for my main target.

Now I’ve tried to compile it on contemporary UNIX of the time, namely Unix v7, 2.9 BSD and 2.10 BSD and they fail at the same point:

hack.monst.c:99: Too many initializers: mon
*** Error code 1

Stop.

What is more weird is I didn’t see anyone having any reports of it working, just requests for the code.  Although I have been able to compile and run it on 4.2BSD/VAX.  So it must be a cc/pcc thing, or some other C compiler they are using on the PDP-11 in Amsterdam circa 1985.  And then I found this interesting bit:

Date-Received: Mon, 22-Apr-85 06:57:56 EST
References: <[email protected]>
Reply-To: [email protected] (Andries Brouwer)
Distribution: net
Organization: CWI, Amsterdam
Lines: 11

In article <[email protected]> [email protected] (Chuck McManis) writes:
>… about the PDP-11 version of hack …
>All in all it doesn’t seem to do 90% of the things that make it different
>from rogue.

The PDP-11 version of hack is a slightly improved (by people at the VU,
Amsterdam) version of some code that was stolen from my directory
some three years ago; it was being worked on, and certainly not in a
shape fit for distribution. Thus, as you noted, it doesnt have half
of the features present in hack, and, what is worse, it is very buggy.
I am sorry it was distributed.

Which to me is kind of interesting as this recently happened on September 21st:

The NetHack Development Team feels it is necessary to publicly address an issue that has surfaced in the last week.

Recently a NetHack source distribution has appeared, claiming to be NetHack 3.5 or 3.5.0 or 3.4.4.

This claim is partially correct. This is our code. However it was not released by us or with our authorization. This code is not ready for release: it is unfinished, unpolished, and almost certainly very buggy. It has not been play-tested for balance or functionality. It is best considered a partial and unfinished rough draft. We will not be supporting this code, nor will we be releasing binaries or bugfixes for it. It will not be available through our website.

Due to this incident and to prevent confusion, we will not now nor in the future release anything with a version number of 3.4.4, 3.5, or 3.5.0.

We thank those of you who play and develop both NetHack and its many variants for your support and encouragement at this time and over the many years NetHack and its progeny have and continue to evolve.

So yeah it seems there is a long history of hacking hack, why even the Fortran port of Zork was born that way:

Zork (was) only as encrypted files that were runnable in an MDL environment but were not readable (and modifiable) as source code. They even went so far as to patch their famously insecure ITS development system, adding security to just the directory that stored the source. Hackers, however, won’t be denied, and soon one from DEC itself had penetrated the veil. From Infocom’s own official “History of Zork“:

[The security] was finally beaten by a system hacker from Digital: using some archaic ITS documentation (there’s never been any other kind), he was able to figure out how to modify the running operating system. Being clever, he was also able to figure out how our patch to protect the source directory worked. Then it was just a matter of decrypting the sources, but that was soon reduced to figuring out the key we’d used. Ted had no trouble getting machine time; he just found a new TOPS-20 machine that was undergoing final testing, and started a program that tried every key until it got something that looked like text. After less than a day of crunching, he had a readable copy of the source. We had to concede that anyone who’d go to that much trouble deserved it. This led to some other things later on.

Indeed,hackers won’t be denied.

Hack 1.0 preliminary version

The source code to Hack was posted onto usenet back in December of 1984:

From: [email protected] (funhouse)
Newsgroups: net.games,net.sources
Subject: Hack sources posted
Message-ID: <[email protected]>
Date: Mon, 17-Dec-84 09:11:48 EST
Article-I.D.: mcvax.6238
Posted: Mon Dec 17 09:11:48 1984
Date-Received: Tue, 18-Dec-84 07:04:44 EST
Organization: CWI, Amsterdam
Lines: 20
Xref: watmath net.games:1303 net.sources:2185

I will post the sources for Hack to net.sources.
They come in 10 parts; the total source is slightly over 400kbyte.

Hack is a game resembling rogue (but much richer than the versions
of rogue I have had access to).

The game runs on all machines with sufficient address space:
$ ls -l /usr/games/HACK
-rws--x--x  1 play       159744 Nov 10 19:09 /usr/games/HACK
$ size /usr/games/HACK
text	data	bss	dec	hex
106496	34816	29264	170576	29a50
but if you are unfortunate enough to have a backward C compiler
(without structure assignments or bitfields or functions returning
structures or with only 6 significant chars to an identifier)
then you'll have to work to get this running.

I am happy with mail, but will be abroad the next four weeks.

Good Luck & Happy Hacking !

Oddly enough the full source code to Hack had been lost.  Even the Nethack Wiki didn’t have the full source code, although thanks to the UTZOO archives by Henry Spencer, I was able to look through enough of the tapes since I had the date and subject in hand, and I was able to pull out the entire thing.

hack 1.0 preliminary version

hack 1.0 preliminary version

I’ve added a package tape for SIMH, as it builds and runs on 4.2 BSD out of the box.

It’s really cool to have saved this from the digital dumpster, although it was there all along.  And thanks to others for at least pointing out that part of it was missing or I’d never even look.

Nethack for Windows CE (x86)

So after struggling like CRAZY on trying to build nethack for Windows CE, it came down to two posts out there….

Thanks to some people in Russia, and Google translate, I found some explicit instructions on building Nethack…

Which spelt out that you need Visual C++ 6.0 to create the dependancies, then use embedded Visual C++ 3.0 to build, which the snag there, is that I was foolishly using 4.0 service packed to level 4, which stripped out support for the SH4 cpu…!

Thankfully, the site hpcfactor, maintains a download for embedded VC 3.0, and I was able to churn out an exe for the emulator. Then tearing it appart, I was able to replicate the build using Platform Builder 2.11 to create a native x86 executable.

So after all that work, here it is!

NetHack for WindowsCE x86

NetHack for WindowsCE x86

 

For those people on x86 machines, or using the CEPC platform, here is the exe, datafile, and finally the source code.

This is what I’m hoping I can manipulate for SIMH…

Nethack on CE text

Nethack on CE text

Textmode in graphics…