PDA

View Full Version : Sega MegaDrive/Genesis



Lordus
December 11th, 2005, 00:06
Beside being one of my favorite systems, its also a very nice one to emulate.
To anyone looking for a new challenge i can just recommend it ;)
After Chip8 and GameBoy i started 7weeks ago with a Genesis Emu in Java,
and here are my first public results.
Everything was written from scratch and i am quite statisfied with the results
so far. Sound emulation is still missing and there are CPU bugs preventing many
games from being playable, but i am currently working on them :whistling

I am also happy with the performance, and this is to all Java sceptics here.
It is not optimized yet, everything except sound emulation is there and it
runs up to 350FPS on a 3 GHz machine and
130FPS on a 1.8GHz AthlonXP. (Screenshots were taken @1.4GHz)

Comments are welcome and i'd be glad to help, if anyone wants to develop a Genesis/MegaDrive Emulator.

If someone has too much time and wanted to make a nice Icon for it, id be happy too :saint:

http://www.workingdesign.de/projects/jenesis_24.pnghttp://www.workingdesign.de/projects/jenesis_11.pnghttp://www.workingdesign.de/projects/jenesis_18.png

More Screenshots here:
http://www.workingdesign.de/projects/index.php

smcd
December 11th, 2005, 00:10
Nice job man :)

Dark Stalker
December 11th, 2005, 00:39
wow, that's so neat. Does it run on any system with a decent jre? With gcj improving steadily and all, maybe I should look into this java thing :P

Lordus
December 11th, 2005, 00:53
wow, that's so neat. Does it run on any system with a decent jre? With gcj improving steadily and all, maybe I should look into this java thing :P

Thanks.
It should. I tested it on WinXP & Linux so far without any problems (of course). Its all standard Java, nothing OS specific, so it should run on any jre (from 1.4 i think). When it runs good enough ill make an applet version of it, so it could
theoretically run on a website then. I dont know about releasing it yet though.
When, if and how... i will see

ShizZy
December 11th, 2005, 01:17
Awesome job there. How is Genesis? Is it difficult to emulate?

Lordus
December 11th, 2005, 01:31
Awesome job there. How is Genesis? Is it difficult to emulate?

I dont know :P
I just implemented everything as it was in the docs and suddenly it worked :whistling

It went rather smoothly so far, i wouldnt say it is so difficult. The sprite & background layer
priority handling and vertical and horizontal scrolling has to be
thought about a bit, but other than that its ok.

Its surely easier if you do it in C/C++ and use one of the existing M68k cores.
A lot less headaches...

bcrew1375
December 11th, 2005, 02:47
Wow, looks nice :).

Sagon
December 11th, 2005, 11:40
Great job, Lordus! Can you post docs that you used? I'm thinking of creation of Sega Genesis emu, it's my favorite, too =)

hap
December 11th, 2005, 12:35
looking good! keep us updated here

The thing keeping me away from such a project is the complex cpu, but I'm sure it would be very interesting to undertake.

Lordus
December 11th, 2005, 14:57
For the M68000 this was very useful :
http://oldwww.nvg.ntnu.no/amiga/MC680x0_Sections/index.HTML
For the rest there is a lot of info on Charles MacDonald's page:
http://cgfm2.emuviews.com/gen.php
Another very helpful resource is this:
http://www.antime.org/sega/md.html

retroK
December 11th, 2005, 15:26
Looks really nice. Keep it up!

Sagon
December 11th, 2005, 15:46
Wow great docs, thanks.

Lordus
December 12th, 2005, 00:53
Little update.
I think i finally nailed down the sprite and bg layer priority handling.
The first shot is a demo, where the priorities are set in a way, to force the
background to shine through, wherever the Sega sprite is overlapping the
foreground column sprites... does it make sense? :saint:

now just the interlace2 mode and shadow/highlite mode is missing and i guess
i have to change my whole rendering code to implement that :party:

http://www.workingdesign.de/projects/jenesis_47.pnghttp://www.workingdesign.de/projects/jenesis_45.png

bcrew1375
December 12th, 2005, 02:36
Geez, you're making my mouth water :drool:. Unfortunately, I don't think I'd have the will power to keep going on it. There's just not enough games I like for the Genesis :(.

ShizZy
December 12th, 2005, 03:01
My thoughts exactly bcrew. I'd kill to do a snes emu, but it's probably beyond my skill level. (then again, so was gb when I started :P Makes more sense now though almost a year later)

Lordus
December 24th, 2005, 01:28
A little update. I am sure all of you have something better to do, but anyway.
Its still very early in development, exactly 2 months before today
i started working on this, but i decided, to release a little XMAS version ;)

All comments are welcome, and id also like some reports on how it works
(read the readme.txt for details, if you want to)


30257

hap
December 24th, 2005, 14:13
Overall, very nice..

The non-emulation part is working ok; no lockups or crashes when changing display modes or loading games. I'm using Sun's Java.

games (I haven't tried many):
- Mortal Kombat: won't boot
- Mickey Mania: won't boot
- Puyo Puyo 2: won't boot
- James Pond 3: won't boot
- Contra Hard Corps: problem with scrolling, many screen effects look ok though
- Gunstar Heroes: ok
- Alien Soldier: ok
- Skitchin: ok, shadow/highlight mode too
- Strider: mostly ok, when you press start in the 'hahahahaha' intro, the screen should turn off
- Sonic: ok
- Sonic 2: ok
- Streets of Rage: ok
- Streets of Rage 2: ok
- Golden Axe: ok

Athlon XP 2ghz speed (Sonic 2):
- 1x: 134fps
- 2x: 92fps
- 3x: 60fps
(filters are slow, eg. hq2x gives 20fps)
Full screen mode (320x240, 75hz) is fast.


Have fun emulating sound :p

Lordus
December 24th, 2005, 14:56
Thanks for the feedback. I know many games wont work and its not a release meant to work perfectly, just wanted to see if and how it works all in all on other systems.
I think many games, like the MortalKombat ones wont boot due to missing sound emulation or improper faking of it and/or flag bugs that are still in the cpu core.
There still has to be one major bug, that i am currently tracing, which hopefully
will make a lot of the games that dont work now boot, as most of them
have the same problem according to my debugging output.
Well, i just started on it and the next version i release will surely be more compatible.

And Yeah sound scares me a lot.. ;)

smcd
December 24th, 2005, 16:49
It runs quite nicely (hq2x really kills it though) on my machine - sometimes it seems to randomly speed up (going to 100+ fps) but quickly goes back down to 56 - 62 fps (tried using auto frameskip and 0 frameskip). My machine is an AMD 2500+, 1GB DDR400, ATI 9600 Pro and I'm using XP Pro SP2 with the latest Java VM 1.5.0_4 I think it is. The game that I tried was Sonic & Knuckles.

EDIT: OK so update 4 isn't the latest, update 6 is... I might give it another go in a while and see if anything changes.

blueshogun96
December 27th, 2005, 17:35
Thanks lorus. Keep up the good work :)

Pixman
December 31st, 2005, 01:05
Good job, Lordus.

Did you comemnt it a lot? If yes, is the source open too?
i'd love to read it up a bit.
And also the sources for the GB emulator maybe.
I'd like to have it.
I'm planning to code a GB emulator on my own but I'm a bit stuck.. I started on the core, don't find it TOO hard yet, but it's till tough to me :)

Greets,
Pix

Lordus
March 20th, 2006, 22:32
Didnt have so much time, but started working on it again last week.
Implemented both V-Scrolling modes now, fixed some bugs, which
raised compatibility a lot.
There is also almost complete sound support now, and i am quite happy about that ...

The only thing that is really annoying is the throtteling. It seems almost impossible in Java,
to provide a constant framerate for everyone. It works on my machine, but
might not on others.
Depending on the VM the Java timing has an incredible resolution of up to 16ms and i just couldnt come up with a method yet, that works everywhere and is native Java.
If anyone has an idea about that, please share it with me ...

Also, if anyone is interested, i can release my current version.

http://www.workingdesign.de/projects/gynoug.png

smcd
March 21st, 2006, 01:00
I'd be interested in having the latest edition posted just because it's fun to play with up-and-coming emulators :)

Lordus
March 21st, 2006, 01:56
Here it is, feedback is welcome of course ;)

jEnesis 0.0.3.zip (http://www.workingdesign.de/projects/jEnesis%200.0.3.zip)

smcd
March 21st, 2006, 04:00
Works pretty nicely. The sound's a bit crackly sometimes but hey, it's working! I am using java 1.5u6 and played Sonic & Knuckles just fine.

hap
March 21st, 2006, 10:54
Sounds and works well over here. I've noticed some crackling too sometimes, I think due to the PSG, eg. in the Sonic "Sega" intro voice.

NecroRomancist
March 21st, 2006, 17:18
Hi.I ran your emu on my linux box and i 'm staggered. Really fast and compatible..only some problems with the sound and fullscreen but that maybe due to the jvm rather than your code.
One question- what are you using to draw the image? BufferedImages and setRGB? do you use a double buffering technique?
One suggestion - could you add a plugin structure..it would be really could if we could used lwjgl if available :)
Congrats on your work..

Lordus
March 21st, 2006, 18:06
Thanks. I think most of the sound problems are related to timing issues. I dont have crackling sound or anything like that here, except when the framerate drops for a second.
I am thinking of using lwjgl myself, for rendering and it also provides more acurate timing. I also thought about plugins and i am consideing it.
I was experimenting with the JNI and actually wrote a native rendering and sound "plugin" for windows. Maybe i will do something into that direction and also use lwjgl.

Currently i am not using BufferedImage. I tried, but it was slower for me. I am using double buffering with a fast ImageProducer class and setPixels.

smcd
March 22nd, 2006, 00:49
There's also java bindings for sdl which might be a possible route? Just thought I'd share.

NecroRomancist
March 22nd, 2006, 01:16
About the timing issues.There is a opensource java master system emu (http://www.javagear.co.uk) that has a nice throtteling code.On bindings it would be really cool to have bindings for something like libcdio to make it possible to emulate the mega cd as it provides iso and cd reading :) I've gotta take a look into that :)

Lordus
March 23rd, 2006, 00:00
Thanks, but the throtteling of JavaGear doesnt help much. Its not so different from mine, its just a general problem using the System.currentTimeMillis() and Thread.sleep() to throttle this way. It works mostly, just not for everyone.
There is another way since the 1.5 VM that i am currently experimenting with, that provides a solid 60fps.

I am also currently working with LWJGL and its so neat. The speed increase is
huge due to OpenGL rendering. I achieved 130fps in 3x resolution that way.
With the Java rendering i just get like 25 fps on my machine in 3x.
So i will provide both methods in the end i guess.

NecroRomancist
March 23rd, 2006, 01:35
Good to hear :D.Yeah System.nanotimer() would have been my next advice :).Looking forward to a next release :)

Fabricio_EX
March 23rd, 2006, 19:55
Way to go, Lordus! A great work using this language that everyone say it's slow. Soon I'll be programming in Java too (I'm still learning the basics), and I want to make an emulator using this language (although I don't know the platform yet). I think it's nice to create those programs to increase your abilities... and have fun!

Lordus
May 7th, 2006, 17:01
Here is a new version of jEnesis: jEnesis 0.0.4.zip (http://www.workingdesign.de/projects/jEnesis%200.0.4.zip)
For the complete changelog look here (http://www.workingdesign.de/projects/index.php)

There are many fixes, it has .7z support now and uses an alternate timing method, which i hope works better.
If not, feel free to tell me. Eventually i will get that right i guess.

Sound is still buggy, but i will work on that for the next release.

I forgot to mention it in the readme.txt (which nobody reads anyway), but you can disable LWJGL and switch to native Java rendering, by setting
LWJGL=false
in the config file (if its all too fast for you).
And also switch back to the old timing method by specifiying:
UseHighPrecissionTimer=false

As always, feedback is welcome of course.

Miretank
May 7th, 2006, 17:17
I forgot to mention it in the readme.txt (which nobody reads anyway)
I am weird, I read readme texts. :)
It looks nice, I'll give it try. ^_^

Lordus
May 14th, 2006, 22:12
The amount of feedback is overwhelming :D . I updated the LWJGL part a bit, as many people seem to have problems with that.
jEnesis 0.0.5 (http://www.workingdesign.de/projects/jEnesis%200.0.5.zip)
If anyone has problems with LWJGL rendering, like blank screens, fullscreen mode not working, or crashes, please send me your system specs and tell me about the exact problem.
It would be really helpful to have some beta testers :P Its just hard to debug something that i cant reproduce here...

NecroRomancist
June 7th, 2006, 13:25
On a linux system with both the DRI drivers and the ATI official ones i get this

Xlib: unexpected async reply (sequence 0x4801)!

when using LWJGL.

PS :- Sorry if haven't said anything about the libcdio bindings but life is really busy atm :)

Lordus
June 11th, 2006, 21:09
No problem, i was working on something else anyway. Ill try to fix that LWJGL problems, its just hard without any more info on what is going wrong.
But anyway here is a little update. I wrote a SH2 core now and somwhat the 32X already works as you can see below.
Its still a bit slow, but i am sure it can be optimized a lot. I am also working on converting the core to a dynarec one atm. Those 2 SH2 cores are just damn fast and take about 80-85% of the whole processing power.

http://www.workingdesign.de/projects/32x_doom.png http://www.workingdesign.de/projects/32x_sh.png http://www.workingdesign.de/projects/32x_tempo.png

smcd
June 11th, 2006, 21:39
Nice :)

hap
June 12th, 2006, 10:44
As Rocky would say to Apollo Creed: you're great :P

NecroRomancist
June 13th, 2006, 01:09
Wow great news...
I am going to try and find out more about what is happening with lwjgl on my machine.
It seems that a new lwjgl release is out :)

Lordus
June 14th, 2006, 19:22
As Rocky would say to Apollo Creed: you're great :P

Hehe, uhm ... how should i interpret that :apollo:

Anyway, i've updated my site (http://www.workingdesign.de/projects/index.php) with some more screens. Compatibility was raised a bit and its taking shape. Just have to work on the speed a bit ;)

NecroRomancist
June 16th, 2006, 13:56
No problem, i was working on something else anyway. Ill try to fix that LWJGL problems, its just hard without any more info on what is going wrong.

I've also tried to run it in my laptop but the same thing happened.. :( On my home pc i forgot to mention that when i close the prog my monitor goes to 1280x1024@60hz.Hope that helps a bit more :)

Lordus
June 26th, 2006, 13:16
I made some nice progress with 32X emulation speed, some games even run fullspeed now, due to idle loop detection. You can see some screens here:
http://jenesis-emu.blogspot.com/

NecroRomancist
June 26th, 2006, 23:56
Great work :D.
Being a java programmer, most of the time, its nice to see those games running smoothly under java :)