Monday 9 October 2017

Javascript Port

Thinking about actually running it, I've decided to port the emulator to Javascript, well actually Typescript which I rather like despite its Microsoft origins.

Having been developing stuff with MS since Windows 3.0 one gets paranoid about embrace, extend, exterminate. Or just being dumped. Some of us remember when the web was all going to be ActiveX web apps written in Visual Basic. Or Silverlight. But this does appear to be genuinely open source.

Phaser will do the graphics and sound and so on.

I modified the COP444 code generator slightly to suit JS code generation as well as C, and got it generating a typescript file which is a superclass of an abstract processor class which is itself then subclassed to add useful and necessary stuff.  Each opcode becomes a function called opcode_207() or whatever and an array of these functions is returned by an accessor method. I'm unconvinced by javascripts case statement, perhaps unfairly. The one thing about GCC is you know it's going to optimise the case to a jump table.

Mostly these changes involved getting it to output things like this.a rather than A in code ; JS and C are near enough syntactically and the output code simple enough that it's pretty much all just replace().

It seems to be working even though there's no real hardware ; it is just a dummy class which implements IHardware and outputs what the CPUs doing to it, but running the "ROM image" it is certainly doing the first bits - figuring out the Game ID, displaying S1 on the LEDs and then scanning the keyboard.

The next time I write a framework emulator I'll probably think through a JS port in advance.

No comments:

Post a Comment