links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
API Emulation
Last updated at 7:41 pm UTC on 29 November 2003
So, I was thinking about how much I hate the Windows look, and how much I wish that I could use some other operating system, or something like SqueakOS with a GUI, and I know that it is next to impossible.

This is because of my horrible Office addiction. If it weren't for Microsoft Office, I could save myself from the Windows OS. Sure, I could switch to StarOffice and Linux, but I just don't like those things as much as I like Office.

So, I got to thinking about the Wine project. They have come a long way, but not far enough by any means to do the Office thing. I think that what prevents a high rate of growth for Wine is the compile/debug cycle. They can't take a running office program, watch it break, tweak the APIs, and continue. Instead, they must do leap-of-faith development, hoping that the currently written API is close enough to the Real Thing in order for it to work. If it doesn't, fix it, compile Wine, run again.

So, how about coming up with a way of doing APIs in Squeak? If Squeak were able to load executables and map API calls to Squeak methods, then the API could be specified in Smalltalk. After it seems to be emulated correctly in ST, it could be translated either mechanically or by hand to some other language on some operating system. API specification without the agony!

I was thinking that all of this could be done in a few ways. One would be to make minor modifications to the VM that would have it load executables and insert stubs for calling ST methods. I'm not sure how easy this approach would be.

Another approach could be to integrate with the soon-to-be-available J3 to auto-generate stubs for Smalltalk APIs that are available. The Jitter would always do this, but it would not necessarily JIT the APIs themselves.

Still a third approach would be to provide a context-switching mechanism so that arbitrary amounts of code could be executed from ByteArrays and then at an API call an "interrupt" would occur, and the emulation code would figure out which API to call. It could be more intelligent than this.

I like the Jitter approach, but I haven't seen the Jitter yet. Still another thing that can be done is to provide JIT translation from one instruction code to another, so that a PPC or Alpha could execute X86 code and emulate Windows fully within Squeak. Or, whatever. Perhaps a Zaurus would be able to run Office.

The thing that I like would be the ease of specifying APIs. It could be used as a method of building API sets for the future. All that is needed is knowledge of the image format (COFF, etc) and you can start compiling programs to your API while Squeak handles the API servicing. Then, when you actually build the OS, you have a very nice prototype to work from.

Tell me what you think, and if you'd like to discuss/participate/burn my house.

Emulating Windows APIs is difficult. There are over 10,000 calls, growing regularly. Many are pooly documented. All by design, of course.

Better hooks between Windows and Squeak would be nice. OLE Automation client and server is the sensible way to go.

If you want to emluate Windows under Linux have a look at http://www.vmware.com/

They take an approach quite distinct from WINE: they emulate a complete PC Hardware. So you can run several virtual PC's (with different OSes).
I'm using it under Linux for more than half a year (running WinNT as virtual OS and MS Office) without any problems. Performance is REALLY good (you just don't recognize that you are working on a virtual PC).
Using this approach there is no need to struggle with Windows APIs...

You might also consider Bochs http://www.bochs.com which emulates a PC complete with Pentium, ROM BIOS and many popular peripherals, sells for $25 (vmware is closer to $300) and comes with source. It has been ported to a number of machines including the Mac, and has successfully run X86 Linux, DOS, Windows 3.1, 95 and 98 and all well-behaved applications.

I would also recommend against emulating Windows APIs unless you really have a lot of time to spend. Getting the bare-bones documented functionality running might be feasible, but I suspect that there are a lot of API functions that are not documented or where the documentation is wrong.
If you really must use Office, I also recommend VMware. I've not used it personally since I do not own a PC or any MS software, but I've heard from colleagues who use it that it's really nice and stable.

You might want to consider something like freeMWare which is a GPL'd program similare to VMWare. It's still in the alpha stages, but if I remember correctly the guy who wrote Bochs is working on it. So if you want the functionality without paying the money, you might want to wait for this program to come to term.

I deal with libraries and API's all the time, and I hate it. Plus, Office running on top of Squeak on a Zarus? That would be extremely slow if it's even possible.
Message sending and objects all the way! Down with API's! ;)
It's like "Here's this was of doing something new, now what are you gonna do?"
"I want to do the old way using the new way!"
Lets make a true squeak OS, then we'll never need to see another API ever again.... :D
Transmeta will release their new processor on Jan 19th, 2000. It's supposed to be specialized towards emulation of various ISA's. Since Smalltalk at the lowest level is an ISA, maybe we can finally give Squeak the speed it deserves...

Daniel Joyce