Let's compile Quake like it's 1997

Let’s compile Quake like it’s 1997

让我们像 1997 年那样编译《雷神之锤》(Quake)

The first batches of Quake executables, quake.exe and vquake.exe were programmed on HP 712-60 running NeXT and cross-compiled with DJGPP running on a DEC Alpha server 2100A. In June of 1996, having shipped their title but concerned with NeXT stagnation, id Software switched their development stack. “We moved to Intergraph hardware running Windows NT right after shipping Quake.” - John Carmack[1] 最初的一批《雷神之锤》可执行文件(quake.exe 和 vquake.exe)是在运行 NeXT 操作系统的 HP 712-60 工作站上编写的,并使用运行在 DEC Alpha 2100A 服务器上的 DJGPP 进行交叉编译。1996 年 6 月,在游戏发布后,由于担心 NeXT 平台的停滞不前,id Software 更换了他们的开发环境。“在《雷神之锤》发布后,我们立即转向了运行 Windows NT 的 Intergraph 硬件。”——约翰·卡马克 [1]

The next versions of Quake, winquake.exe, glquake.exe, and QuakeWorld (qwcl.exe and qwsv.exe) were all developed and compiled on Windows NT with Visual C++ 4.X. This article describes the steps to re-create the experience of building the win32 binaries of Quake as it happened in 1997. 随后的《雷神之锤》版本,包括 winquake.exe、glquake.exe 以及 QuakeWorld(qwcl.exe 和 qwsv.exe),都是在 Windows NT 上使用 Visual C++ 4.X 开发和编译的。本文将介绍如何重现 1997 年构建《雷神之锤》Win32 二进制文件的过程。

The purist’s corner

纯粹主义者的角落

Depending on the level of historical accuracy you want to reach, you can follow the steps with four environments. Find an Intergraph RealizM Dual P6-200MHz workstation (good luck). Find a dual Pentium Pro machine (good luck again but finding a W6-LI is doable). Use a regular late 90’s PC like the Quake PC. Download Oracle’s Virtualbox and create a VM. I tested these steps both on the Quake PC and in Virtualbox, running either Windows 98SE or Windows NT 4.0. 根据你想要达到的历史还原度,你可以通过四种环境来执行这些步骤:寻找一台 Intergraph RealizM 双 P6-200MHz 工作站(祝你好运);寻找一台双 Pentium Pro 机器(再次祝你好运,但找到 W6-LI 主板还是可行的);使用一台 90 年代末的普通 PC;或者下载 Oracle Virtualbox 创建一个虚拟机。我在 Quake PC 和 Virtualbox 上都测试了这些步骤,运行的系统均为 Windows 98SE 或 Windows NT 4.0。

Installing Windows NT 4

安装 Windows NT 4

Installing Windows NT 4 is pretty easy since the CD is bootable. Installation took 30 minutes. I love how minimalist Windows NT startup screen is. It proudly displayed how many CPUs are detected (Windows 95/98 only supports one CPU) and how much RAM is there. There is no silly animation. 安装 Windows NT 4 非常简单,因为光盘是可引导的。安装过程耗时 30 分钟。我非常喜欢 Windows NT 启动界面的极简风格。它会自豪地显示检测到的 CPU 数量(Windows 95/98 仅支持单 CPU)以及内存大小,没有任何花哨的动画。

Adding a second CPU to a system won’t be automatically detected by Windows NT. You need to re-install to get the HAL handling SMP systems. The same thing goes with dual CPU motherboard. On a W6-LI, one need not only to add another Pentium Pro but also a regulator! Windows NT 4 uses the same UI theme as Windows 9X. The first release, Windows NT 3 used the same UI elements as Windows 3.1. It looked awful. 在系统中添加第二个 CPU 不会被 Windows NT 自动检测到。你需要重新安装系统,以便让 HAL(硬件抽象层)处理 SMP(对称多处理)系统。双 CPU 主板也是如此。在 W6-LI 主板上,不仅需要添加另一个 Pentium Pro 处理器,还需要一个稳压器!Windows NT 4 使用与 Windows 9X 相同的 UI 主题。而最初的 Windows NT 3 使用的是与 Windows 3.1 相同的 UI 元素,看起来非常糟糕。

Installing Visual C++ 6

安装 Visual C++ 6

The Win32 version of Quake were coded on Visual C++ 4.X since it was the most recent version of Microsoft IDE available in mid-96. However, by 1999, the project had been migrated to Visual C++ 6. If you don’t have the CD handily available, you can likely find it on the Internet Archive or winworldpc.com. 《雷神之锤》的 Win32 版本是在 Visual C++ 4.X 上编写的,因为那是 96 年年中微软 IDE 的最新版本。然而,到了 1999 年,该项目已迁移至 Visual C++ 6。如果你手头没有光盘,很可能在 Internet Archive 或 winworldpc.com 上找到它。

In a time before “always on” Internet, most software had a product ID to fight piracy. The installation screen also brings up the next “Visual Studio”, combining many development environments. It would soon become THE Microsoft IDE to rule them all. The installation screen looks off. There is a lot of empty space and the progress bar is awkwardly placed. That is because Microsoft did not expect this to run at the crazy high resolution of 1280x1024 (which id developers likely used on their 21” monitors). It only looks as intended in 640x480 or 800x600. 在那个没有“全天候在线”互联网的时代,大多数软件都有产品 ID 来打击盗版。安装界面还展示了后续的“Visual Studio”,它整合了许多开发环境,并很快成为微软统治级的 IDE。安装界面看起来有些奇怪,有大量的空白区域,进度条的位置也很尴尬。这是因为微软没想到它会在 1280x1024 这种超高分辨率下运行(id 的开发者们可能在 21 英寸显示器上使用该分辨率)。它只有在 640x480 或 800x600 分辨率下看起来才正常。

With VC++6 installed, we now need to get the source code. DO NOT get it from github or transfer the files via FTP. This will mess up the workspace .dsw file. Then VC++6 will be unable to parse it. And it won’t even give you an error message, it will just open and show no file / project associated. And you will lose 1/2 a day trying to debug the problem. 安装好 VC++6 后,我们需要获取源代码。千万不要从 GitHub 获取或通过 FTP 传输文件,这会破坏工作区 .dsw 文件,导致 VC++6 无法解析。它甚至不会报错,只是打开后显示没有任何关联的文件或项目,你会浪费半天时间去调试这个问题。

Instead, you need to get q1source.zip. It used to be available on id Software’s FTP server but now you can get it from the awesome Quake Official Archive maintained by Jason Brownless[2]. With a VM you can transfer files via drag/drop. Alternatively you can use Quick ‘n Easy FTP Server which works on both 9X/NT. To decompress q1source.zip, you will need WinRar. The v2.50 still works well on 9X/NT. 相反,你需要获取 q1source.zip。它曾经在 id Software 的 FTP 服务器上提供,但现在你可以从 Jason Brownless 维护的优秀“Quake Official Archive”[2] 中获取。在虚拟机中,你可以通过拖放来传输文件。或者,你可以使用在 9X/NT 上都能运行的 Quick ‘n Easy FTP Server。要解压 q1source.zip,你需要 WinRar,v2.50 版本在 9X/NT 上运行良好。

Now launch VC++6. Select “Open Workspace” then pick “WinQuake.dsw”. Modern versions of Visual Studio use .sln (Solution) and .vcxproj but Visual C++ 6 uses .dsp and .dsw. The dsp contains a single project while the dsw is a workspace pointing to dsp projects. Start the build with “Rebuild All”. 现在启动 VC++6,选择“Open Workspace”,然后选择“WinQuake.dsw”。现代版本的 Visual Studio 使用 .sln(解决方案)和 .vcxproj,但 Visual C++ 6 使用 .dsp 和 .dsw。.dsp 包含单个项目,而 .dsw 是指向多个 .dsp 项目的工作区。使用“Rebuild All”开始构建。

The build will fail because VC6++ was unable to assemble all the .s files which contain the hand-optimized assembly by Michael Abrash. The .s file are built with “mycoolbuild” “Custom Build” step which relies on ml.exe assembler. It comes with VC++6 Processor Pack (vcpp5.exe). First install Visual Studio 6.0 Service Pack 5 (vc6sp5.exe). Of course, launching setupsp5.exe will fail. This is because you need to install MDAC 2.5. Don’t lose an hour trying to download MDAC from somewhere. You just need to run mdac_typ.exe which is in the same folder created when vs6spp5.exe decompressed itself. Go back and run setupsp5.exe. This time it will work. 构建会失败,因为 VC6++ 无法汇编所有包含 Michael Abrash 手工优化汇编代码的 .s 文件。.s 文件是通过依赖 ml.exe 汇编器的“mycoolbuild”自定义构建步骤来构建的,它包含在 VC++6 Processor Pack (vcpp5.exe) 中。首先安装 Visual Studio 6.0 Service Pack 5 (vc6sp5.exe)。当然,直接运行 setupsp5.exe 会失败,因为你需要先安装 MDAC 2.5。不要浪费一小时去别处下载 MDAC,只需运行 vs6spp5.exe 解压后所在文件夹中的 mdac_typ.exe 即可。然后再运行 setupsp5.exe,这次就能成功了。

By now it should feel like you are following the solution of Monkey Island. Nothing makes sense. We are definitely deeeep into the 90s. More awkwardly small progress bar but this is still progress. Install VC++6 Processor Pack (vcpp5.exe). Now you should see ml.exe next to cl.exe in VC++6 bin folder. Re-open the project with VC++6 and run “Rebuild All” again. This time it should work. Yup it built! You need to copy PmProXX.dll, WdirXX.dll, and id1 and the game should launch. You can even build/run QuakeWorld and it works with QSpy! 到了这一步,感觉就像是在玩《猴岛小英雄》(Monkey Island) 的解谜过程,一切都显得莫名其妙。我们确实深深地沉浸在 90 年代的氛围中。虽然进度条依然小得尴尬,但这确实是进展。安装 VC++6 Processor Pack (vcpp5.exe),现在你应该能在 VC++6 的 bin 文件夹中看到 ml.exe 和 cl.exe 并列了。用 VC++6 重新打开项目并再次运行“Rebuild All”。这次应该成功了。没错,构建完成了!你需要复制 PmProXX.dll、WdirXX.dll 和 id1 文件夹,游戏就能启动了。你甚至可以构建并运行 QuakeWorld,它还能与 QSpy 一起工作!

A darn good IDE

一个非常棒的 IDE

VC++6 is remarkably powerful for 1996. It has features such as “Go to definition”, breakpoints, stacktrace, and variable inspections (but no Intellisense auto-completion yet). I never used it but it must have felt like a dream at the time. 对于 1996 年来说,VC++6 的功能非常强大。它具备“转到定义”、断点、堆栈跟踪和变量检查等功能(尽管还没有 Intellisense 自动补全)。我以前从未使用过它,但在当时,这一定感觉像是一个梦想。

References 参考资料 [1] Conversation with John Carmack. [1] 与约翰·卡马克的对话。 [2] Quake Official Archive [2] 《雷神之锤》官方存档