paint-brush
Why I’m writing a Windows 3 Emulatorby@CantabileApp
15,354 reads
15,354 reads

Why I’m writing a Windows 3 Emulator

by Brad @ CantabileSeptember 18th, 2016
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

I’ve decided to write a 16-bit Windows <a href="https://hackernoon.com/tagged/emulator" target="_blank">emulator</a>. It’s a bit of crazy idea, but hear me out…

People Mentioned

Mention Thumbnail

Companies Mentioned

Mention Thumbnail
Mention Thumbnail

Coin Mentioned

Mention Thumbnail
featured image - Why I’m writing a Windows 3 Emulator
Brad @ Cantabile HackerNoon profile picture

I’ve decided to write a 16-bit Windows emulator. It’s a bit of crazy idea, but hear me out…

A couple of weeks ago I upgraded my partner Jen’s PC to 64-bit Windows. It all was going well until she went to play some Windows 3 card games that she enjoys when we realized that 16-bit programs don’t work on Windows x64.

Right. I’m sure that software publisher from 1992 is still around.

So I installed a copy of 32-bit Windows on a VM and that works, but it got me thinking…

What would it take to write an emulator with just enough support to run these old games?

I’ve written a couple of emulators before and while they’re a ton of work, they’re also a great learning experience and the kind of challenge I really enjoy.

I particularly like the idea of this project because:

  • it’s different enough that I’ll learn something new,
  • it’s got some really tricky challenges,
  • it’s not been done before (that I’m aware of) (and don’t care if it has) and
  • there’s a slim chance it might actually be useful — even if only for Jen.

Besides, who doesn’t love a fairly pointless super geeky side project?

How would it work?

The basic idea is to write a program that can read a 16-bit Windows executable file, run it on an emulated CPU and map any 16-bit API calls that it makes onto the x64 equivalents.

  • It’s like DosBox in that it’s emulating the CPU — but unlike DosBox in that it’s not emulating other low level hardware.
  • It’s like Wine in that it’s emulating the Windows API — but unlike Wine in that the CPU is emulated instead of running on a physical processor (remember Wine stands for “Wine Is Not an Emulator”).
  • It’s not like VirtualBox or VMWare or other virtualization software as it’s not emulating or virtualizing low level hardware.

In other words, even though it’ll include an emulated CPU to execute the 16-bit code this is more about emulating the operating system than the hardware.

The nice thing about this approach is that the 16-bit program will appear just like a regular Windows program — it’ll get its own entry in the task bar and you’ll be able to Alt-Tab to/from it just like any other program. It won’t be constrained to the walls of a virtual machine.

The down side is that the Windows API is massive (but I should only need to implement a subset of it).

Proof Of Concept

So far I’ve managed to get a proof of concept working that can run two really simple 16-bit programs. The first simply displays a message box and exits.

The second is essentially the “HELLOWIN.C” program from Chapter 1 of Charles Petzold’s classic book Programming Windows. It creates a window with a title, draws some text, can be resized, maximized, minimized and shuts down cleanly when closed.

Here’s how it looks on Windows 3:

Very retro!

And here’s the exact same .exe file running under the emulator on Windows 10 x64 with emulated CPU instructions being logged in the background.

Code Segment 0013?

That doesn’t look like much but there’s a fair bit going on there — enough for me to realize that this might actually work.

Follow Along!

I’m still a fair way from getting those old games up and running, but I thought a series of articles about it would be interesting. If you remember the joys of segment arithmetic, MakeProcInstance and LocalLock you’ll especially appreciate this project.

What do you think: have I lost my mind or is this something worth pursuing?

Hi, I’m Brad Robinson — an independent software developer living in Sydney Australia. I write software for musicians and as an indie developer I rely on word of mouth.

If you enjoyed this article please consider sharing it by hitting the “recommend heart” below or by sharing on Facebook/Twitter. It’s a small gesture but makes a real difference.

Also, if your feed is lacking in hex dumps, disassembly listings and screen shots of old Windows 3 games you might like to follow me on Twitter.

Continue reading… Part 2 — Initial Design Thoughts