Monday, April 23, 2007

#64 - Commodore 64 emulator on Mono

With the recent success of running Pong on Mono.Xna, on the mono runtime, I decided to try my port of #64.  I was pleasantly surprised to see it run without recompilation or any issues on the mono runtime.

My first observation was the not insignificant increase in CPU usage over running on the Microsoft JIT. 

I haven't had a chance to dig into things yet, and it may not be for a while, some areas I will look at are:

  • switch statements
    • Like many emulators, #64 has a number of large switch statements to emulate the various CPUs (6502, 6510, 6581, 6569, etc), and these are perhaps not as well optimized as the MS JIT.
  • inlining
    • Whilst I inlined some code, the other possibility is that the mono JIT may not be as aggressive when inlining code.
  • floating point
    • The sound emulation does use a significant amount of floating point code.
  • memory allocation
    • I am pretty sure the memory allocation is minimal, and suspect the mono memory allocator is just a pointer being incremented, much like the MS implementation 

It will be an interesting journey into the inners of the code generation and optimizations, since I'm not familiar with all the optimization techniques.  I'll blog about my experiences when the time comes.

1 comment:

Rob Loach said...

Hey,

Here's what we use to have for the Gamepad: Gamepad.cs.

It supported everything on the Xbox 360 controller, except the throttle buttons (Axis3) because they were being reported as one number. If you take a look at the source, you'll also see it supported vibration in Windows using a Win32 call to XInput.

It's difficult to create NUnit tests for this kind of thing though, as it's all based on what the user sees and does with the controller.

Any thoughts?

Thanks a lot,

Rob