Developer Tutorial - Aronnax9000/WatchmakerSuite GitHub Wiki

Development on Blind Watchmaker falls into two categories. The first is active development of the original source code on the original Classical Macintosh platform, which can now be done using the Basilisk II software emulator. The second is the translation of the original programs into programming languages that can be used to produce versions of Blind Watchmaker which can run on modern computers: presently (2018) the preferred language is Java.

Classic Macintosh (m86k) Development

Richard Dawkins designed and wrote the original version of the Watchmaker Suite programs using one of the original m68k family of Apple Macintosh computers, introduced in 1984. The programs won't run on any later computer than the very last PowerPC-based Macintosh released in 2005, which was the last to feature a special legacy support mode for original Macintosh programs.

Emulation and Virtual Machines

Fortunately for fans of obsolete computer systems, there exist computer emulators. Emulators are pure software applications which simulate the behavior of the hardware of another computer. An emulator runs as an application on a computer which may have completely different hardware. The emulation is exact, right down to simulating the other computer's processor, memory, and firmware. To emulate devices which connect with the outside world, such as keyboards, disk drives, pointing devices, and displays, the emulator does the work of interfacing with the host computer's real-world hardware, its keyboard, disk drives, and so on.

The actual computer that the emulator runs on is called the host or hosting system, and the emulated system is sometimes termed a 'virtual machine'. The term 'virtual' highlights the fact that the emulated system has no real hardware of its own, but exists solely as a software process running on the host system.

Interestingly, there are emulators which run on the same kind of computer they emulate: one can host a virtual IBM PC running Windows on an actual IBM PC running Windows; host a virtual Macintosh on a real Macintosh of the same type, and so on. It is even possible for a virtual machine to run an emulator itself, so that the virtual machine becomes a host for another virtual machine. One is tempted to imagine recursing this process indefinitely, creating an infinitely nested "hall of mirrors" of virtual machines. In practice, there are practical limits to the degree of nested hosting of virtual machines within other virtual machines.

At the top of the hierarchy, there must, after all, be a real, physical computer, and any given computer system has finite limitations of speed and memory capacity. Hosting a virtual machine is expensive of both these resources, particularly in the case of emulating a different processor architecture than that of the host machine. In that case, the hardware processor of the virtual machine must be simulated by a set of data structures in memory, capable of representing the state of the emulated processor at a given moment.

In addition to the necessity of representing the hardware state of a virtual machine within the memory of the hosting system, there's another problem. The instructions contained within programs written for the virtual machine's hardware won't run on the host machine's processor, since it's of a different architecture. Because of this dissimilarity, the emulator must provide translation software to read the instructions to be executed on the virtual machine and manipulate the data structures representing the emulated processor's state. The manipulation changes the state of the data structures in just the same way that the state of a real, physical processor of the emulated design would change in response to the same instructions.

In contrast, if the virtual machine is of the same architecture as the hosting system, some economies are possible, such as running the virtual machine's instructions directly on the hosting system's actual processor, albeit in a special 'sandbox' mode which keeps the virtual machine's operations from 'leaking' into the hosted system's overall operation.

Nevertheless, whether or not the virtual machine is of the same architecture as the hosting system, there are computational costs associated with emulation, and nested emulation cannot in practice be carried past a particular degree, for any given actual, physical computer.

Basilisk II

Basilisk II is a free, open source emulator of the original m86k Macintosh computer architecture. Versions are available for Windows, Linux, and Mac System X. Basilisk II requires the user to find a copy of the image from a real, Apple-copyrighted, system ROM. The system ROM inside each original Macintosh contained instructions for operating the Macintosh hardware at the lowest level. Different ROM images are used to emulate different models of the original Macintosh. The present work was done using the ROM from the very last model of Macintosh to use the m68k architecture, the Quadra 900/950, and here we may pause to examine the architecture of the Quadra.

Macintosh Quadra

The pinnacle of the original Classic Macintosh line of computers was the Quadra line.

The last Classic Macintosh sold was the Quadra 950, which debuted March 18, 1992 and was discontinued October 14, 1995. The processor was a Motorola 68040, running at 33MHz, and the system had a maximum capacity of 256 MB of RAM. (When I told Richard that I was emulating one, and explained that at the time of its debut the computer cost $7,200, or about 4,200 GBP, he exclaimed, 'I remember coveting a Quadra when they came out.') Aside from a couple of short-lived high performance Macintosh computers with similar architectures, the Quadra 900 was the last computer on which the Blind Watchmaker programs would originally run which is also supported by Basilisk II, and it is the emulated platform chosen for continued development of Blind Watchmaker.

Mac OS

Mac OS 8.1 is the last release of the Macintosh operating system that will run on m68k based Macintosh computers.

THINK Pascal

THINK Pascal was the Pascal language, compiler and IDE (Integrated Development Environment) chosen by Richard Dawkins for the original development of the Blind Watchmaker programs. The last official release was version 4.0.2.

In his original development work, Richard Dawkins used the previous point release of THINK Pascal, version 4.0.1. His copy of THINK Pascal included the update installer required to bring his THINK Pascal installation to the latest official version, 4.0.2, but there is no evidence that Dawkins ever installed it. This update has been installed for continuing development of Blind Watchmaker in the Classic Macintosh environment.

Macintosh Toolbox

The Macintosh Toolbox consists of standard library routines (THINK Pascal procedures and functions) provided by the THINK Pascal compiler or the Macintosh operating system itself. Crucially for Blind Watchmaker development, this includes the QuickDraw libraries used to draw biomorphs on the display, together with routines to create and manipulate user interface items such as windows, menus, and other widgets. The toolbox is documented in the multi-volume series Inside Macintosh.

Free Pascal and Lazarus IDE

Free Pascal is an open source Pascal compiler for modern operating systems. It is capable of compiling THINK Pascal sources using its MACPAS mode if a few rules are followed. Since Free Pascal does not include the software libraries provided by the THINK Pascal environment or the Macintosh operating system itself, in order to successfully complete a compilation of the original sources on Free Pascal, the Blind Watchmaker project has produced "no operation" function and procedure stubs for all of the software library calls needed by Blind Watchmaker.

Lazarus IDE is an Integrated Development Environment for use with the Free Pascal compiler.

AppleScript

AppleScript is the native scripting language for Mac OS 8.1. The Blind Watchmaker project uses an AppleScript to ease the transfer of THINK Pascal source code modules from a host computer (where they may have been edited and compiled using Lazarus IDE and Free Pascal) to the Watchmaker(Watchmaker (volume)) volume in the emulator.

File Typer

File Typer 5.3 is a third-party program which can change the attributes of Macintosh files within HFS and HFS+ file systems of the type used by the Classic Macintosh. The Blind Watchmaker project uses a specialized utility, AlterAttributesForTP, generated by File Typer to set the attributes of THINK Pascal source code modules so that they conform to the expectations of the THINK Pascal compiler.

ResEdit

Classic Macintosh files have two "forks": a resource fork and a data fork. Resource forks are used by applications to store images, icons, menu selections, and window layouts for use in Macintosh applications. ResEdit is a graphical editor for such resource forks.

Stuffit

Stuffit is a third-party utility for creating compressed archives of Macintosh HFS file systems. The original version of Stuffit created archives with a .sit extension. Later versions of Stuffit created archives with a .sitx extension. These latter archives cannot be unpacked under Mac OS 8.1 and earlier. Richard Dawkins' final archive of the Blind Watchmaker program sources and executables was created with a .sitx extension. The only version of the Mac OS X operating system which can unpack .sitx files with their resource forks intact is Snow Leopard, version 10.6.8.

DropDMG

DropDMG is a third-party utility for creating .dmg (disk image) files from files stored on HFS file systems. In order to transfer resource files to an HFS file system under emulation, DropDMG 3.5 can be used on a machine running Snow Leopard, version 10.6.8, the version of OS X which can unpack .sitx files while preserving resource forks. This allows for the conversion of Dawkins' final Blind Watchmaker archive from .sitx to .img format. Filesystems in the .img format can be directly mounted as Basilisk II volumes.

Java Development

The WatchmakerSuite project has produced a reference implementation of the original Blind Watchmaker programs written in the Java programming language using the Eclipse Integrated Development Environment.

See WatchmakerSuite (Java) for an introductory discussion of the Java port of Blind Watchmaker.