home | java maze | legacy ibm pc emulator

shinelife

tasty links

tasty downloads

legacy ibm pc emulator - introduction

Emulators of other computers - they're one of those things (along with operating systems) that always mystified and fascinated me. I could see how one might put together a game, or a word processor, or a windowing system. But emulators seemed somehow magic. This was more or less what got me started, at some point in 2001, on the development of the "Legacy" IBM PC Emulator.

I started out on this journey with very little knowledge of how I was planning to go about getting old MS-DOS CGA games from the early 1980's running within a GUI window on my modern Linux laptop. I'd done a fair bit of assembly language and mode 13h stuff during my Turbo Pascal days in the mid 1990's - this gave me a reasonable (if shallow) understanding of the 8086 instruction set and the mode 13h memory map. I was therefore only missing about 90% of the information I needed to know - timers, interrupts, DMA, disk interfaces and various other things I was yet to discover were beyond the current reach of my understanding.

Pitstop 2

Pitstop 2

Space Strike

Space Strike

Marble Madness

Marble Madness

One particularly challenging aspect of writing an emulator under these circumstances is that you don't know how well you're doing, or even if you're on the right track, until you've written a lot of code. I probably spent about a month on my first attempt at writing code to emulate the 8086 CPU, 1Mb memory and 80x25 textmode, during which there was little feedback available to help assess the correctness of my approach.

Once the time came to feed some 8086 code through my "emulator", I found it useful to start off small. I had a CD full of small DOS .COM executables (BBS ads, small textmode games etc) that came in handy. I could load these directly into the emulated memory, set CS:IP (the program counter) to the correct starting location, and watch instructions executing through a crudely written "debugger" until something strange happened. Normally this would involve the instruction pointer jumping to some bizarre location such as the start of memory (home of the interrupt vector table), or one or more of the registers taking on and maintaining strange values that didn't seem right.

I'd have to look back through the dump of emulated instructions (often running to text files of several megabytes in size) and attempt to isolated what went wrong, and where it went wrong. Sometimes it would be a badly emulated instruction not setting the flags correctly, sometimes an interrupt that I'd ignored or not emulated correctly. Every once in a while, I'd get stuck and have to resort to the Internet as a source of inspiration - unfortunately this involved going downstairs, plugging the laptop into the phone line and logging onto AOL. Until somebody else needed to use the phone.

I was somewhat elated when some of these .COM executables actually started doing something meaningful - even being able to see a sentence of legible text written on the emulated screen was encouraging. However, computers aren't designed to display static text and pictures - the real breakthrough was when I managed to persuade the emulator to correctly run a colour textmode BBS advert, complete with a large yellow scroller several lines high at the top of the screen, and some kind of text shading effect at the bottom. It's not entirely surprising how satisfying these moments are when you think about how much work has gone into reaching them.

Graphics and disk emulation >>