JEmu2Droid wip

I’ve just made a first attempt in bringing JEmu2 to Android.
It’s not the complete JEmu2, but just the ‘demo’ Space Invaders driver, but I at least I got something working now :slight_smile:
(see attached screenshot)

On my Legend running on Android 2.1 it works reasonably well (hopefully it’ll run better on 2.2), although not really at full speed (I think it’s about 50% real time) and I haven’t implemented the controls yet.
I’ll post a working version when I got around to implementing controls.

[attachment deleted by admin]

Hi!

Does it work on Android 1.5?

At this point it probably still works on 1.5, but I plan to target 2.2 and up for 2 reasons:

  • It’s too slow on anything lower than 2.2. Even on 2.2 it’s not that fast, so I’ll even recommend at least a 1GHz CPU.
  • I need multi-touch for the controls

(another screenshot attached :))

[attachment deleted by admin]

Maybe you could keep the compatibility with Android 1.5 and use multi touch, I posted a piece of code about it a few months ago.

Thanks, goussej I’ll look into that. Still, I think performance might be very poor on pre-2.2 devices.
I have a Legend (which has only a 600MHz cpu) running on 2.2 now (just upgraded it), and there it also doesn’t run fast. I image running all interpreted will be very slow. But anyway, it’s worth a shot.
Do you know what kind of CPU your android phone has?

Anyway, here is a test version with Donkey Kong: http://www.gagaplay.com/jemu2/JEmu2Droid.apk

The joystick is implemented as a ‘swipe’ kind of thing: Put your finger on the lower left side, and there will be the centre of the stick. Swipe to the right to go right, etc. The stick will center again if you either release your finger, or move back to the spot where you first touched the screen. There’s still room for improvement of the implementation, but I think it already works quite well (…for touchscreen controls…).

This what I’m doing with the controls in my minecraft renderer. It certainly beats having the stick at a fixed position, but I’m not sure how much better touchscreen controls can be made. They need some kind of feedback to let the user know how far/in what direction the stick is pressed. Auditory or visual would probably be overly distracting, but the phone’s vibrator could be a way to go for digital controls - a tiny wee jolt whenever you transition between up/down/left/right/center zones might be interesting.

I’m showing sort of a compass when the stick is ‘active’, which works reasonably well.
Good idea about the using the vibrator!

I just uploaded an update: http://www.gagaplay.com/jemu2/JEmu2Droid.apk

It’s now really a lot faster and now runs close to full speed on a 600MHz CPU (on the Android 2.2 JIT runtime).

Now also with sound: http://www.gagaplay.com/jemu2/JEmu2Droid.apk

I have the oldest Android phone :slight_smile: HTC Dream G1. I’m giving it a try…

Edit.: sorry, it crashes immediately.

Ah yes, I forgot to tell it currently targets 2.2. (sorry about that)

Great start! Works fine but still just a tad slow on a Droid 1 OC’d to 800 MHz.

Aww… I’m on a Sony Erricson x8. That means a 600 Ghz processor, 2.1 version Android and not multitouch :-\

I’ll try speeding up emulation more tonight, but I’ll need to be able to gain lots of performance before I can start thinking of supporting pre-2.2 phones.
This Donkey Kong emulation driver uses a lot of generic components that are easy to use but not necessarily the fastest solution, so I think there’s still something to gain.

A small update:
I’ve now ‘hard wired’ the memory map to get rid of some indirections. This gave me a small (but noticeable) performance gain of about 10% (this version is not online yet).

To speed up things more, I’ll see if it helps to get rid of the generic graphics decoding & blitting code and replace that part with a custom optimised version. There’s already a simple ‘dirty rectangles’ algorithm in place, so I’m not sure how much I can gain there since Donkey Kong’s graphics are quite static.

After that, I guess there’s realistically not much more performance to squeeze out of this without reverting to things like recompilation. I already down-clocked the CPU emulation (which is of course a gross cheat :)), so even busy loop removal won’t help that much, and I even reverted to 30FPS rendering…

To be honest, I’m a bit disappointed with the performance of the new android JIT runtime. I think that got me at most 2x the performance.
Donkey Run ran fine on J2SE 1.4 on a 266MHz Pentium II laptop, 60 fps with sound and all, without all those ugly hacks…
I know a laptop is not the same as a phone, but still, hopefully Google will improve things there. After all, my phone’s clock speed is still more than 2 times higher than the old laptop where I did most of JEmu2’s development.

If it doesn’t work on a phone with a 600 GHz processor, it won’t run anywhere! :stuck_out_tongue:

I finally got it running at 60fps on my 600Mhz phone.
It only renders at 30fps, but that’s not really noticeable in this game. It turned out that drawing the backbuffer is actually slower than running the emulator (even when it internally still renders everything at 60fps), so simply drawing the backbuffer at only 30fps gave me a massive 33% performance gain!

I just uploaded the new version: http://www.gagaplay.com/jemu2/JEmu2Droid.apk