Porting FC64 to Android via Adobe AIR

| No Comments | No TrackBacks
A long, long time ago on an Internet far, far away, Claus Wahlers and I collaborated to create FC64, a low level Commodore 64 emulator written in ActionScript 3.  I remember first talking about FC64 at FITC, and I first blogged about it back in May of 2006.

FC64 is a side project of ours that, like the cobbler's kids who never get shoes, never seems to get the attention it deserves.  The TODO list hasn't been chipped away at in a long time, and there are still some glaring omissions (the most obvious being sound emulation).  There's a nagging decimal mode bug in the CPU that still needs to be fixed.  The code has been lost, found, moved around a few places, survived a hard drive failure, but eventually made it's way to http://github.com/claus/fc64 where it's been dormant for, well... a long time.

However, all of that changed this weekend when my Nexus One arrived.

So far I've been doing all of my Android development with the native Java SDK testing on a Motorola Droid, but the Nexus One gave me a chance to install Android 2.2 and the AIR runtime.  This provided me an opportunity to take a deep, hands-on dive with with the AIR for Android beta.

Naturally, the very first thing I did with it was to try and get FC64 running on the device.  I tweeted about it quickly on Saturday and included a very poor screenshot, and Scott Janousek picked up on it and relayed the news around on his weblog.  I was a little embarrassed that not only did I have a typo in the tweet that was going around (as an aside, Twitter as a stream-of-thought medium for me tends to be much more raw than an article/post/entry), but that the screenshot was such poor quality.  It literally was the very first build though, and I was excited to at least get that far.

Since then I've had the chance to bring FC64 to a point where I would officially call it "working" on Android 2.2 via AIR.  Here are a few screenshots that illustrate the current progress of version 0.0.1 (click images for larger versions):

These two images show FC64 loaded in portrait mode using the native on-screen keyboard to enter commands. This shows the result of running a simple POKE command.

FC64 in landscape mode playing a game.
Here we have a game running in landscape mode with the virtual keyboard hidden.

For the most part it was straightforward and easy to port our 4-year-old ActionScript project to Android via AIR.  Here is the short list of things that needed to be done:

  • Installing the AIR runtime on my Nexus One
  • Creation of a separate AIR project in FlashBuilder with a device-specific main runner class
  • Addition of code to handle screen orientation changes
  • Refactoring of code to handle keyboard input
  • Added support for trackball to act as a joystick
  • Creation of a build script to compile, package, and install the application on my phone
Everything else worked out of the box without modification.  I did make a few minor changes to the base code in order to improve performance just a little.  For example, we were originally dispatching a lot of events for tracking frames per second, but new Event() at short intervals has a lot of overhead on mobile and was slowing down the emulation.  This will probably be refactored again into a conditional compilation directive.

I also took some time to wire up the Nexus One trackball so that it can be used as a joystick.  In Galaga, for example, scrolling the trackpad will move your ship left and right, and pressing the button down will fire.  It's a nice addition and fun for games.

There is still a lot that needs to be done, both for the Android application and for FC64 in general, but I was pleasantly surprised at how quickly I was able to get an initial port of the code base running on my device.

A short Android-specific TODO list for FC64:

  • Load ROMs from SD card.  Currently I've hard-coded the public domain game Galaga into the application.  Pressing the Android "back" button will load the ROM and start it automatically, or, if the ROM has already been loaded, it will reset the CPU.
  • Further optimizations such as using Joa's TDSI and Memory class to improve performance (both for mobile and in general).
  • Update the visual display.  Currently we're scaling the renderer to match the width or height, but it degrades the C64 text.  We might remove the scale and just center the renderer for a crisper display.
  • Proper key mapping.  This wasn't so apparent on the desktop version, but the virtual keyboard on mobile doesn't allow you to press "shift + 2" which is required for entering the " symbol (the original C64 keyboard had " as shift + 2) so BASIC commands are hard to enter.
I plan on pushing the source for this into my GitHub repository at http://github.com/darronschall/fc64 in the next day or so, and I'll propagate the changes upstream to the master repository.


No TrackBacks

TrackBack URL: http://www.darronschall.com/mt/mt-tb.cgi/169

Leave a comment

About this Entry

This page contains a single entry by darron published on July 19, 2010 7:21 PM.

Flash Camp Philadelphia 2009 FlexUnit 4 slides and examples was the previous entry in this blog.

Find recent content on the main index or look in the archives to find all content.


OpenID accepted here Learn more about OpenID
Powered by Movable Type 5.02