Hacker News new | comments | show | ask | jobs | submit login
Finding the Lost Vikings – Reversing a Virtual Machine (ryiron.wordpress.com)
165 points by jsnell 211 days ago | hide | past | web | 27 comments | favorite

Fun fact: The Lost Vikings was created by Silicon Synapse. They were later renamed "Blizzard Entertainment" and went on to make Warcraft/Starcraft. The Vikings are now featured in Blizzard's game Heroes of the Storm: http://us.battle.net/heroes/en/heroes/the-lost-vikings/

And you can download the original for free, along with a couple of other Blizzard classics: https://us.battle.net/account/download/?show=classic

Whoa, this is awesome!

"The Lost Viking" also appears as a game-in-a-game. It's an arcade console in the bar on the Hyperion. It is a playable 2D scrolling shooter that features a Viking (the SC2 unit) shooting through waves of pattern based enemies.

It's really kind of cool how many of these old games were built on top of their own custom vms.

Of course there is the Infocom Z-machine, going way back, that made porting between all the different microcomputers of that era somewhat easier. Another interesting writeup of this kind of an architecture is for Another World [1]. Along those lines, I wonder in the case of The Lost Vikings, how much of the game code was able to be reused between the different platforms it was released on (SNES, Genesis, PC, maybe Mac, I don't remember?)

[1] http://fabiensanglard.net/anotherWorld_code_review/index.php

I suspect the mix of CPUs in use back then had an impact.

After all, you had the 6502, Z80, 68000, and various x86 generation all bouncing around (the 486 was introduced in 1989, this game was released in 1993).

The Sega Genesis/Mega Drive for example had both a 68000 and a Z80 inside it, while the SNES used a 6502 clone.

The Mega Drive's Z80 was essentially just powerful enough to play music and sounds - it couldn't really be used for much else, leaving the 68k to focus on gameplay and manipulating the sprite-based Video Display Processor.

Only relatively speaking. The MD runs the games of the previous generation (Master System) natively on the Z80. The hardware of the MD, including the VDP and audio, is basically a superset of that of the MS.

While true, people expected better audio out of the Genesis than the Master System, which involved more processing power.

> while the SNES used a 6502 clone

The NES used a 6502 clone, with a few minor changes (no BCD mode, I think some changes to interrupts, addition of sound-generation hardware).

The SNES used a 65c816 clone, from the same family of chips.

Why did they write their own VM?

Was it sort of a write-once, run everywhere thing? So they can reuse the game code on various platforms?

Having written games back in that time, I can at least tell you why I wrote my own VM: You get a custom language/compiler, which makes iteration time significantly faster than recompiling your game yet again, for yet another tiny tweak.

Or, worse, writing every bit of your game in assembly. (Worse in the sense of time consumed. In the sense of fun had, the VM approach takes some of that away ;)

This is the impression I get from reversing it: the virtual machine mostly assists quickly porting to other platforms.

I previously reversed another game engine called Comprehend (for 1980s text/graphical adventure games) which also had a VM. I ended up talking with one of the original developers, who said that portability was a major reason. Their company wrote the original Apple 2 implementation, and then contracted development for the other platforms out, so they just provided specs for the VM. The Lost Vikings development may have been similar.

In the Lost Vikings the VM implementation was almost certainly written in assembler. There are various tricks used in the binary which I don't think compilers of the day were capable of. The other parts of the game also appear to have probably been written in assembler, which I think is interesting since it was developed quite late in the DOS era.

In these kinds of games, the programs tend to be very small and you only need a very small set of functions which can be made opcodes rather than explicit function calls. You can often write the VM in 2k or so and have programs of only a few dozen bytes, while a standard vm would be ten or a hundred times the size.

For Lost Vikings it was most likely for easy porting.

Wikipedia mentions is was available on the following platforms: Amiga, Amiga CD32, Game Boy Advance, MS-DOS, Mega Drive/Genesis, Super NES, PlayStation

Variations on that theme seem pretty common. Ultima Underworld's conversation system uses a stack-based VM. The original Jedi Knight game has a programming API and a compiler. Game assets are compiled from a C-like language at load-time. Various adventure games (both graphical and text-based) were written as bytecode programs that run in a VM.

Bytecode programs can be more compact and built-in coroutines are useful for games.

Yup, coroutines are a really nice fit for game logic which is partly why you see Lua used so often in games(along with being super-compact and fast).

another world used a similar technique.

Cool article and great game! Here is a video of someone doing a speedrun using two controllers at once: https://www.youtube.com/watch?v=5LkoTGv2z6E

Looks like Joel Spolsky in the second row behind the gamer (after he moves).

I spent most of a Sydney-Vancouver flight rediscovering this game on the seatback IFE (AirCanada used to have a SNES emulator of some sort in their setup).

This kind of closes the loop on an interview I read a long time ago in a magazine.

When Blizzard went to make the Mac (System 7) port of Warcraft 1, the guys that were interviewed about it mentioned that the port was relatively easy because the game code was relatively insulated from the OS and all they had to do was update the OS-side code and keep the game logic running in "a thread." (their words)

Probably this virtual machine model was continued at least to Warcraft 1, which makes a lot of sense for a shop that was used to doing console ports of their PC titles at the time.

Thanks to whoever posted this, and glad that people are enjoying a little bit of DOS games nostalgia. The tools I've developed (also linked in the blog post) are all public domain if anybody wants to play around with them: https://github.com/RyanMallon/TheLostVikingsTools

So many hours wasted playing this game! :)

Thanks for the article.

Great writeup!

Applications are open for YC Winter 2018

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact