Age of Empires developer confirms the game is mostly written in low-level Assembly code because ‘we could scroll the screen and fill it with sprites as fast or faster’ than competitors like Starcraft ‘even though we had twice as many pixels’

Some of the greatest stories about games are simply about how developers made the thing work. Ask any developer for their favourite workarounds and you’ll get a full evening’s worth of entertainment about how a giant tram is actually an NPC with a hat on, or how rabbits are actually what makes Azeroth work, and so on.

This isn’t quite on those lines, but a redditor recently noted that Chris Sawyer wrote Rollercoaster Tycoon 1 and 2 in Assembly language, and apparently Age of Empires was the same: “AoE is written in Assembly: is this actually TRUE?!” It’s important to note that this wasn’t uncommon back in the day, though it would still be pretty remarkable if an entire game was hard-coded this way. Assembly language, to be as brief as possible, is any low-level coding language that communicates more directly with a computer’s architecture than high-level languages like C++.

The question about whether Age of Empires was coded in Assembly language hit gold in the replies thanks to Matt Pritchard, one of the founding members of Ensemble Studios, who’s been the coding lead on the series from the very start.

“I guess I can clarify this, since I wrote all the assembly code used in Age of Empires and Age of Kings, along with many other parts of those games,” says Pritchard. “There were about ~13,000 lines of x86 32-bit assembly code written in total.”

Pritchard goes on to explain that the vast majority of this was in the “drawing core”, which was compiled by Microsoft Macro Assembler 6.1 into a .obj file and in other cases Visual C++. In plain English, this was an extremely efficient way for the game to draw sprites, with Pritchard estimating it was around 10 times faster than standard C++ implementations.

“AoE’s drawing core was notably faster than competitors like StarCraft, which is why the default resolution ‘out of the box’ for AoE was 800 by 600, when nearly all our competition was 640 x 480 resolution,” says Pritchard. “We could scroll the screen and fill it with sprites as fast or faster even though we had twice as many pixels-ish in the game world area.”

The Assembly code remained in use even by the time of Age of Kings: HD edition (a 32-bit game), but Pritchard “re-wrote the assembly functions into C++ for both Definitive Editions, as they are 64-bit programs and inline assembly was never supported by the 64-bit C++ compiler, and the vastly improved register sets and compiler optimizations made it unnecessary. Additionally, sprite drawing in the definitive editions is multi-threaded, and will use up to 4 cores for that task alone.”

Part of why such a workaround was required is that both games were being developed at a time when standalone 3D cards were uncommon: “cutting edge was 2D with a separate 3D card like the Voodoo 1 & 2” says Pritchard. He goes into some detail on the technical restrictions of the time, noting that the Pentium 166 CPU in the machines most Ensemble developers were using “had 16K of cache… TOTAL.” Or to put it in plainer terms, “You are probably working right now on a PC with more on-CPU Cache Memory than the PC I developed AoE on had in TOTAL.” 

Pritchard’s had quite the career but clearly has real affinity for Age of Empires, and mentions how the HD edition (not to be confused with the Definitive Edition) came about. “The HD edition came about after I had been knocking on doors at Microsoft for a few years trying to get someone interested, and the contract with Hidden Path (where I was at the time, working on CS:GO for my previous employer Valve) was rather small,” says Pritchard.

“Microsoft did not think there was much interest in an all digital download version of a 2D game from the 1990s (the CD-ROM version of the original game was still on store shelves just a year or two prior). HD was done by a great team at HPE on a tiny budget (~5 people, ~ little less than a year), so changes were kept to the realm of ‘absolutely necessary’ rather than the more aspirational Definitive Editions.”

There’s also some amusing detail on the various console ports of the games. “Ensemble had nothing to do with the PS2 port,” says Pritchard. “Microsoft negotiated the deal by themselves and gave them a code and asset drop on CD and said ‘have at it’. Almost the same for the Dreamcast port, though for that one I did spend an hour drawing on a whiteboard and trying to explain graphics details to a Konami engineer who spoke no English while I spoke no Japanese.”

Pritchard finishes up by saying, “I am very fortunate to have gotten to play an outsized role in those games from the very beginning and creation in 1996 to being the driving force behind the revival in 2010-11 to modern day, finishing my own journey with it once DE was released in 2019.

“I am both very fortunate to have been part of its creation and humbled to this day at all the enjoyment and more that it has brought to people. I would never have had the great career in game development that I had without all of the fans and supporters of those games.”

Leave a Reply

Your email address will not be published.

Previous post New Models MolMIM and DiffDock Power Molecule Generation and Molecular Docking in NVIDIA BioNeMo
Next post Nearly 10 years after it came out, Obsidian’s isometric RPG Pillars of Eternity gets a surprise update