太空探索 II 主盘错误
The Space Quest II Master Disk Blunder

原始链接: https://lanceewing.github.io/blog/sierra/agi/sq2/2024/05/22/do-you-own-this-space-quest-2-disk.html

本文描述了在旧的塞拉利昂在线冒险游戏磁盘上发现的不寻常内容的有趣发现。 具体来说,据报道,某些版本的 Space Quest II 软盘(特别是 2.0D 和 2.0F)包含此类游戏中通常找不到的独特数据。 尽管在初步检查时看起来很正常,但这些磁盘中保存着一些意想不到的东西——来自 Sierra On-Line 的 AGI 解释器源代码的一部分。 作者解释说,这些目录并没有揭示任何违规行为; 相反,它们看起来很像普通的 Sierra 游戏光盘。 然而,经过进一步调查,使用十六进制编辑器,发现了这些额外数据的证据。 研究结果表明,这些特定版本的 Space Quest II 的母盘很可能在转化为最终产品之前从另一个项目中重新调整用途。 不使用行话解释文本: 一张旧的 Sierra On-Line 冒险游戏光盘,特别是 2.0D 或 2.0F Space Quest II,包含一个惊喜:Sierra On-Line 的 AGI 解释器源代码的残余部分。 尽管磁盘本身看起来很普通,但它隐藏的数据却讲述了一个不同的故事。 经过仔细检查,我们发现了部分解释器的编程,暗示着前世是另一个项目的组成部分。 使用更简单的术语: 一张 80 年代的冒险游戏光盘,属于 Space Quest II(版本 2.0D 或 2.0F),拥有一个秘密:AGI 解释器的源代码片段。 乍一看,它看似平淡无奇,但在表面之下却隐藏着一段迷人的历史。 在特殊工具的帮助下,数据的真实性质显现出来——揭示了口译员以前作为另一个项目的关键要素存在的痕迹。

本文讨论了从旧电子存储介质(特别是磁盘和磁带)读取和重新创建数据的各种方法。 作者区分了在驱动器的模数转换器处理后从磁盘读取数字数据的传统方法,以及直接读取和处理原始磁通量反转的更先进的技术,类似于记录到磁带上 甲板。 这种设备的一个例子是 Domesday Duplicator,它使用软件定义的采样模拟信号操作,而不是像那个时代常见的那样依赖复杂的 FPGA 技术和高速数字信号处理。 另一个名为 Applesauce 的当代项目似乎实现了相同的目标——从驱动器而不是驱动器的 ADC 输出采样模拟信号。 作者分享了个人对经典电子游戏(尤其是《Space Quest》)的怀旧之情,回顾了由于资源有限和技术限制,他们在没有外部指导的情况下试图取得进步所面临的困境。 最终,这些经历使他们掌握了自学和解决问题的技能,这些技能至今仍在为他们服务。
相关文章

原文

There is nothing unusual about the outside of these disks, but there is something unique about the data that is stored on them, something that Sierra On-Line would have been totally unaware of and certainly wouldn’t have wanted them to include.

If you happen to have one of these 720KB floppy disks lurking somewhere in your Sierra adventure game collection, then chances are you are not alone. Versions 2.0D and 2.0F of Space Quest II were not exactly uncommon.

A simple directory listing

Listing the files on the disk doesn’t reveal anything unusual:

The listing shown is from version 2.0D. There are no mysterious additional files, in fact it looks like any other Sierra game disk. Nothing is out of place.

The timestamps show that the game’s main data files, i.e. PICDIR, LOGDIR, VIEWDIR, SNDDIR, VOL.0 and VOL.1, were built on the 14th March 1988. The .OVL files are dated the 15th March 1988, and the AGI interpreter code itself is dated the 18th March 1988. These file timestamps capture a week of activity during which someone in the Sierra office was focused on preparing the 2.0D version of Space Quest II.

One thing that is a little curious about the directory listing above is that the “free” space on the disk is greater than the used space. 302,918 bytes are used and 402,432 bytes are supposedly free.

Using a hex editor

To take a closer look at what is on the disk, and to peek into that supposedly unused part, we need a tool called a hex editor. Back in the 1980s, a commonly used tool for this came with Norton Utilities. These days a great modern equivalent is the excellent HxD Hex Editor written by Maël Hörz.

For a freshly formatted DOS floppy disk, we’d expect all of the unused sectors to be filled with the 0xF6 byte value (i.e. DOS’s default format ‘filler’ byte), which is indeed the case for Disk 2 of Space Quest II version 2.0D, as shown below:

There isn’t, however, a single unused sector on Disk 1 that is filled with the 0xF6 byte, in fact the longest string of consecutive 0xF6 bytes on Disk 1 is only two. Given that over half the disk is “free” space, then clearly the disk had not been formatted prior to being prepared as a SQ2 master disk. The following shows an example of a section of the SQ2 Disk 1 disk that is marked as unused:

Rather than being filled with the 0xF6 byte, it is instead filled with something that looks like C source code. This strongly suggests that the master disk was used for some other purpose prior to being the SQ2 Disk 1 master disk. The files were then deleted, but the disk was not properly formatted afterwards. Due to the way the DOS FAT file system works, deleting a file does not actually remove the data. Instead it simply marks the sectors as no longer being in use, so that in the future they could be used for a new file. If those sectors are never used again for a new file, then they will keep what they previously had stored on them, and so it was important that people fully formatted a floppy disk after storing sensitive files on them.

AGI interpreter source code

It is difficult to see exactly what the above data looks like when viewed in a hex editor, but it clearly looks like text, so let’s copy and paste the ASCII text on the right hand side into a text editor to see what we have:

As we can see, it certainly does look like C source code. There are two functions defined, one called DisplayStatusLine and another called StatusLineOn. In the case of DisplayStatusLine, it appears to be displaying a line of text that includes the current score and whether the sound is on or off. Does this look familiar? You bet it does. Take a look at the top of the Space Quest II screen shot below:

That particular piece of C source code is responsible for displaying the white status bar at the top of the game screen, with the black text that shows the user what their current score is. This source code is a part of the AGI interpreter itself!

This is just one small example. Scrolling through more of the unused sectors in the hex editor reveals that there is a large amount of such source code. Not only that but the code is stored over consecutive sectors, i.e. it is not fragmented as you might expect, so it is relatively easy to extract this data from the disk and then split it up into separate C source files. The split points are easy to determine, since each file has a comment at the top saying what the name of the source file is. Splitting into the separate files gives us 93 files in total, made up of 75 C source files, 16 assembly language source files, and 2 DOS BAT files:

In total, there are over 15000 lines of code and most of these files are complete.

It turns out that this Space Quest 2 game disk contains about 70% of the source code of Sierra On-Line’s AGI interpreter, complete with comments and change history. We will look at how that 70% figure was calculated later in the article.

When we say “the AGI interpreter”, what we are referring to is the file named “AGI” in the directory listing that was shown earlier, along with the the .OVL files. The “AGI” file is the executable that performs the actual interpretation of the game data contained in the LOGDIR, PICDIR, VIEWDIR, SNDDIR, OBJECT, WORDS.TOK and VOL files.

Source file change history

Some of the source files contain a change history within the header comment at the top. The following is an example from the ANIMATE.C source file:

The header comment starts by stating the name of the source file. It then gives a short description of what it does, in this case to “Handle one cycle of animation in an adventure game”. Next we have a line that says “compile: MWC”. This appears to state the name of the C compiler that was used to compile the C source. MWC was a C compiler from the Mark Williams company that was very popular in those days. After that, the header has a “Change History” section and this makes for very interesting reading. It mentions the date, time, initials of the person making the change, and a description of the change.

The programmers have identied themselves using their initials, including their middle name initial. JAS is none other than Jeff Stephenson, the main programmer who was working on the AGI interpreter code, and DCI is Chris Iden. If you look at the game credits for the AGI games from 1985-89, you will see that Jeff and Chris were always credited with working on the game development system.

Robert Heitman is also listed, but his focus was mainly on the graphics tools (i.e. the Picture Editor (PE) and View Editor (VE)), whereas Jeff and Chris worked primarily on the interpreter code. So it isn’t surprising to see their initials in the change history for the C source code of the AGI interpreter.

AGI.EXE memory map

In addition to the 93 AGI interpreter source code files, the SQ2 2.0D 720KB Disk 1 disk also contains over 2000 lines of a Memory Map of the AGI.EXE executable. For production releases of AGI games, the interpreter executable is called simply AGI, and is not directly executable, but during the development of the games, Sierra On-Line used a version of the interpreter that had the .EXE extension and could be run directly. Someone at Sierra generated a memory map of the AGI.EXE executable, i.e. the AGI interpreter, on the 7th October 1987. A small section of it is shown below:

This gives a potential date to the collection of source code files. It ties in with the most recent change history comment in the code, which is from September 1987.

The memory map also gives us a fairly complete list of the modules and source files that make up the AGI interpreter. Each module specifies the file that it is defined in. If we count the number of distinct source files mentioned, it comes to 98. The number of those source files that are present in full on the SQ2 disk is 71. This is where we get the figure of roughly 70% for the amount of AGI interpreter source code that is on the SQ2 disk. For some of the modules, only the C header file is included, and so those modules are not included in this calculation.

Sierra’s intellectual property

In 1984, Sierra On-Line was lucky to survive as a business. Some time around the release of King’s Quest, in May/June of that year, Ken Williams had to lay off around 100 of his employees, reducing the head count from approximately 130 down to about 30. Although it was a struggle, part of what turned their fortunes around was the success of the AGI adventure game system and the games that were built using it. By the end of 1984, King’s Quest had entered the top 20 on the software sales charts for computer games. It would stay there for the next half year, right up until the release of King’s Quest II, and it wasn’t long until King’s Quest II was also in the charts. This was helped a lot by the deal that Sierra made with Tandy Radio Shack to sell Tandy versions of the games in the Radio Shack stores.

The AGI games continued to be best sellers from 1985 to 1988. Over those years, the AGI interpreter was Sierra On-Line’s primary means of making money and therefore a core part of their intellectual property. They not only invented the 3D animated graphic adventure game genre but also had a head start on their competitors that lasted several years. It is safe to say that the source code for the AGI interpreter is something that Sierra would have preferred didn’t fall into the hands of their competitors.

For 70% of the source code to end up being copied en masse and sent out to tens, if not hundreds of thousands of their customers, was a big blunder.

How did this happen?

When a new release version of a game was prepared by Sierra, it involved creating a “production copy” master disk to be used by the FormMaster disk duplication machine. This machine did not simply copy files from the the master disk to each copy but instead copied every byte of every sector of the disk, regardless of whether the sectors were currently being used or not. What this meant in the case of the version 2.0D and 2.0F SQ2 Disk 1 disks is that it also copied the supposedly unused 402,432 bytes, despite there being no reason to. This is why the preparation of a master disk involved ensuring that it started out fully formatted before the game was copied on to it, and for the most part, Sierra On-Line got this step right. Most original Sierra game disks were formatted before use. It would seem that someone forgot to do this for the Space Quest II version 2.0D Disk 1 disk, and the same disk was then also used for version 2.0F of SQ2.

This meant that potentially hundreds of thousands of SQ2 disks sent to customers and retail stores had a copy of 70% of the AGI interpreter source code hidden on them.

Dodged a bullet

It was almost certainly an unintentional mistake. Surprisingly, no one appeared to have noticed that this happened, not Sierra, not their competitors or their customers, and it was only discovered decades later, the first known discovery of it by online user NewRisingSun in October 2016.

It is also fortuitous that this happened at the end of the AGI era. In March 1988, Sierra had already developed their SCI adventure game system and were about to release the first game using it, which would be King’s Quest IV. So accidentally leaking the AGI interpreter source code into the public, should someone have noticed it, may not have been the issue it could have been only a year or two before that.

It makes for an interesting digital archeaology story though, and it allows us, 36 years later, to see how our heros at Sierra On-Line wrote their AGI interpreter.


For those who are interested, I have uploaded the extracted AGI interpreter source code into a github repo: https://github.com/lanceewing/agi

Check out AGILE, the web based AGI interpreter, whose implementation was guided in part by the original AGI source code.


联系我们 contact @ memedata.com