don't click here

Cycle accurate emulation: Exodus 2.0 + Open Source Release

Discussion in 'General Sega Discussion' started by Nemesis, Apr 27, 2015.

  1. Nemesis

    Nemesis

    Tech Member
    You may or may not have heard about Exodus. Exodus is a generic and extensible emulation platform I have been developing for almost 9 years now, which aims to support cycle-level accuracy in emulation, combined with powerful debugging and development tools. Unlike other emulators which are statically compiled to support a particular set of systems, Exodus is open an extensible, with every emulation core supplied through plugins. The platform itself constructs systems from an XML definition of the connections between individual components in the system. This design allows the emulator itself to focus on managing the timing and interaction between the components, and allows the emulation cores to be totally modular and reusable in other systems that share the same components. A lot more information about this is available on the website.

    On the 30th of April 2013 I released Exodus 1.0, with support for the Sega Mega Drive. The plugin SDK wasn't ready for use at that stage though, so I held off on the open source release until I could get it up to scratch. Since then I've had delays and setbacks in getting the next release out the door, but the long process is now complete. I'm pleased to announce that Exodus 2.0 will be released both as binaries, and an open source repository, on the 30th of April 2015. Developer documentation will also be published detailing the API. The code will be licensed under MS-RL, and the repository will be hosted on Bitbucket. Refer to the website for more information on how to build Exodus from the source, and how to contribute ideas or code changes to the project.

    In terms of Mega Drive emulation, the main differences in Exodus 2.0 are as follows:
    -Major speed improvements (average 90% on dual-core systems, 30%-40% on quad-core systems)
    -Around 40% reduction in memory usage
    -Completely redesigned user interface, with a very powerful docking system for window management.
    -Gamepad/joystick support
    -Lots of bugs fixed and new debugging features

    [​IMG]
    The release will be made available on the official website at http://www.exodusemulator.com, so head over there for download links and more information about this project. I hope this emulator of use to some people out there, and I hope other people will be interested in contributing to this project, and helping me to expand it into other platforms.

    Edit:
    Exodus 2.0.0 has now been released! You can download the new version on the release page at http://www.exodusemulator.com/index.php/downloads/current-release
     
  2. Aerosol

    Aerosol

    Not here. Moderator
    11,163
    573
    93
    Not where I want to be.
    Sonic (?): Coming summer of 2055...?
    Amazing. I'm so excited my hands are shaking.
     
  3. winterhell

    winterhell

    Member
    1,165
    7
    18
    Awesome! With the new changes in this version I might actually move to playing emulated games on this platform.
     
  4. LoneDevil

    LoneDevil

    Eternal Underdog Member
    Will definitely keep in eye on this one for future rom hacking projects. *cough* Ristar? & etc.
     
  5. Meat Miracle

    Meat Miracle

    Researcher
    1,664
    5
    18
    Question, does your license only allow open source extensions/plugins to be made, from a legal standpoint, or does it also allow someone to publish a plugin (only a plugin as a separate download) without releasing the source code of it?

    edit: another question, does the ym2612 core emulate that strange hardware noise that no emulator does? Compare these:
    https://www.youtube.com/watch?v=tRkHqw58PPk
    https://www.youtube.com/watch?v=lkGs3MjEigo
    I don't know if that's just some noise due to poor filtering/audio circuitry, or if it an actual hardware thing in the ym2612...
     
  6. Chibisteven

    Chibisteven

    Member
    1,365
    39
    28
    US

    It's due to the YM2612 itself. The ASIC and GOAC YM3438 variants don't output that kind of noise. I've been able to somewhat simulate it by quantizing the audio a bit. -24 dB and save as an 8 bit wave and then mix the result with the original, can't remember if I did cancellation or not. There is a lot of stereo cross-talk and frequency dependent stuff that I haven't been able to figure out.

    The discrete YM2612 has crappy audio quality compared to the ASIC / GOAC YM3438 variants, but games can sound quite off on the later and sound correctly on the former frequently enough to have anyone preferring the YM2612 over the ASIC / GOAC YM3438 versions.

    I'm glad the Saturn and Dreamcast don't have these kind of problems and can be modified for digital audio. SEGA dropped the ball on their late model 1 VA7 and earlier model 2 (VA0, VA1, VA1.8, VA2, VA2.3) systems on how much you can mess up the mixing and amp circuit. Fortunately it's fixable. The earliest model 1's (VA0, VA1, VA2) have a screw up on the pre-amp part of the circuit making it more prone to clipping when games get loud.
     
  7. Nemesis

    Nemesis

    Tech Member
    The license does allow releasing a closed-source plugin. To follow the license to the letter, you wouldn't be able to use the standard base classes, and you'd have to tread carefully around what's a pure virtual method or data structure (legal to use) and what's an inlined method (technically not legal), but it wouldn't be very much work at all to stick within the bounds of the license and have closed source plugin. I haven't tried to prevent this in the license terms. Of course, a closed source plugin couldn't be based off anything already in Exodus, and wouldn't be eligible to become part of the official project.

    [quote='Meat Miracle"]edit: another question, does the ym2612 core emulate that strange hardware noise that no emulator does? Compare these:
    ....
    I don't know if that's just some noise due to poor filtering/audio circuitry, or if it an actual hardware thing in the ym2612... [/quote]
    The audio output quirks of the YM2612 are faithfully emulated to my knowledge, with just one or two almost certainly inaudible things to correct. Filtering can introduce a whole range of strange audio artifacts however, and Exodus currently does not attempt to emulate distortion of the analog waveform from the filtering process. I've seen it happen on the hardware too where the filtering effect on a high-frequency audio signal (way too high frequency to hear) which is changing in amplitude, after filtering causes the high frequency signal to be decimated, and instead it effectively becomes a carrier wave for an audible waveform constructed from the amplitude changes. The PSG for example has this effect, and After Burner II is a game that actually relies on it for the machine gun sound. As a result, you virtually won't hear this sound on the emulator, because the signal is too "clean", while on the real hardware it's quite loud. Emulating these kind of artifacts will require a much more complex audio filter, just like a graphics filter is used to emulate visual blurring and bleeding artifacts from RF or composite NTSC and PAL signals. Exodus will support plugins for audio and graphics filters in the future, but the current version does not. Right now a simple linear interpolation method is used for audio resampling.
     
  8. Overlord

    Overlord

    Now playable in Smash Bros Ultimate Moderator
    19,239
    972
    93
    Long-term happiness
    Fantastic to see the source release happening, a high-quality Mega Drive emulator with available base code can only be good thing for the long term emulation community and hobbyists of the system. Thanks Nemesis, I hope that others pick up and integrate with your work!
     
  9. LocalH

    LocalH

    roxoring your soxors Tech Member
    Any chance of an iOS port? I'd love to screw around with it on my iPad Air, especially with the performance improvements. I doubt it, but I don't guess it would hurt to ask. I am not an HLL programmer, so I wouldn't know where to begin.
     
  10. Nemesis

    Nemesis

    Tech Member
    Exodus 2.0.0 has now been released! You can download the new version on the release page at http://www.exodusemulator.com/index.php/downloads/current-release
    I'm dedicating this release to my beautiful wife Judi, and my two boisterous little boys Justin and Aiden.

    As promised, Exodus is now also open source. Check out the website at http://www.exodusemulator.com for instructions on how to obtain and compile the source, and information on how you can contribute code changes to the project.

    Note that you won't see a massive improvement in Mega Drive game compatibility with this version, as the focus has been on other areas, like performance, user interface, and the plugin API. There are still a number of games I know of that will greet you with a black screen for example when you try and load. This is due to the fact that although Exodus aims for cycle-level accuracy, it's not actually there yet, and there's a number of games that use a kind of wait loop against flags on the VDP that technically requires at the very least sub-opcode level timing emulation to pass. No other emulators have sub-opcode level timing emulation for their CPU cores, but they use incorrect timing on the VDP as well in order to make the tests pass.

    The biggest thing that needs to be done for Exodus at this stage in order to improve Mega Drive compatibility is write Z80 and M68000 cores that emulate individual bus cycles, rather than emulating at an "opcode" level. For the M68000 at least, nobody seems to have ever done this, and a lot of information needs to be gathered on the hardware in order to determine the correct timing and order for each bus access within instructions. Emulating it properly will also require a major change to the bus system, which I currently have in the works. I was originally planning to have this bus change in Exodus 2.0, but I didn't want to delay the release any further. The bus system redesign, along with cycle-exact M68000 and Z80 cores, will now be my primary focus of development for the next major release. After this is complete, Exodus will have CPU emulation which is truly cycle-exact.

    Despite the lack of perfection with the CPU cores at this stage though, Exodus is already much more accurate than other emulators at Mega Drive support for graphics and sound. Exodus has the most advanced YM2612 core ever written, as it was written entirely from scratch during my detailed reverse engineering of the YM2612 back in 2008.

    In terms of the VDP, Exodus is the only Mega Drive emulator that has a cycle-exact VDP core, which allows it to emulate many quirks and tricks of the real hardware that other emulators can't, like Direct Color DMA. Aside from rendering accuracy, the VDP core is also fundamentally more accurate in handling basic communication from the CPU. Try this test ROM for example, which tests VDP port access:
    [​IMG]
    http://nemesis.exodusemulator.com/MegaDrive/Tests/VDPFIFOTesting/VDPFIFOTesting.zip
    (Detailed discussion: http://gendev.spritesmind.net/forum/viewtopic.php?p=20975#20975)

    This test ROM isn't perfect, a couple of the tests fail intermittently on the real hardware, but it's pretty stable, and it's very thorough and brutal. Even Exodus doesn't get a perfect score here yet, it gets 121 out of 122. Most other Mega Drive emulators will only score around 20 or so. I'm hoping with Exodus now open source, other Mega Drive emulators which are still being maintained can use Exodus as a reference, and improve their accuracy on these kind of tests too.


    Anyway, I hope some other people can make use of this. It's been a very long road to get to this point. Exodus was around 200,000 lines of code at the last count, and most areas of the code have gone through numerous revisions to get to where they are now. I daren't even estimate the number of hours that have gone into this project. I hope you find it interesting and useful.

    EDIT: I forgot to say, if you want to check out the debugging features, you'll be best off using one of the pre-made workspaces. Select "File -> Load Workspace" from the main menu and select "Mega Drive Debugger.xml". That'll give you a pretty good debug environment ready to go.
     
  11. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    One thing I have been thinking in this regard for the 68k was implementing it using micro-opcode information from the patent/die shots: write one forced-inline function for each micro-opcode, then code each opcode as a sequence of micro-opcodes, with one forced-inline template function per opcode (with parameters being the opcode parameters, such as addressing mode, etc). Then use these to generate a huge switch table for hih speed emulation. All these functions would probably work better as member functions of a 68k class that stores CPU context information, to allow reuse for the SCD CPU.

    Anyways, downloading source now; will look into making a Linux GUI when I time the time.
     
  12. Spanner

    Spanner

    The Tool Member
    Seem to be having problems getting keys to work. The default configuration is a keyboard but it's not taking any responses from it.
     
  13. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    Clicking in the image generally seems to fix that.

    A quick review of Exodus:

    Good news: it works on Wine after manually adding two native DLLs.

    Bad news: seems to hang on a critical section after some time; this message starts popping up:
    [codeerr:ntdll:RtlpWaitForCriticalSection section 0x13ba560 "waveform.c: WINMM_Device.lock" wait timed out in thread 0048, blocked by 0016, retrying (60 sec)[/code]
    After this, the image freezes, and if I try to close Exodus, it will hang on close. Could be a Wine issue on how it implements critical sections, or it could be a race condition on Exodus; I am thinking it may be a race condition due to the way Wine implements these things.

    Frame rate is better than previous version, and CRAM dots seem to go to the right spots (so S3&K water line in AIZ looks correct).

    Am I correct in assuming that the SRAM bankswitcher is still not implemented?
     
  14. rata

    rata

    Member
    690
    73
    28
    Argentina
    Trying to be useful somehow.
    I downloaded it ready to try it, but it seems that I can't since Im a 32-bit dirty peasant. Oh, well, maybe soem day I will be able to.

    In the meantime, thank you for making this and conratulations for actually do it! I know it will be amazing even I can't try it.
     
  15. Sappharad

    Sappharad

    Oldbie
    1,414
    70
    28
    I seem to have issues accessing the site. The main page says "THIS ACCOUNT IS NOW ACTIVE!" with a large green background. The link to the download page is a 404.

    Is anyone else running into that? I've tried Chrome, Firefox, and Safari, all have the same result.
     
  16. Nemesis

    Nemesis

    Tech Member
    I'm pretty happy with the release of Exodus 2.0 overall, but as expected with only me testing the build prior to release, there were a few bugs in some areas I hadn't tested for awhile. There have been enough issues fixed to justify a patch release, so Exodus 2.0.1 is now available for download! Considering it was 2 years between the first two releases, I think 18 hours between these last two is a bit of an improvement. :)/>

    Get it now from the current releases page at http://www.exodusemulator.com/index.php/downloads/current-release

    Enhancements:
    EX-291 - Improved default workspace loading to restore the main window size and maximized state before the main window appears, removed the maximized state as the default state, and changed the "Mega Drive Clean" workspace to not be maximized.

    Bug fixes:
    EX-289 - Fixed an error in the Mega Drive ROM loader which prevented games that used SRAM from loading
    EX-290 - Fixed a bug in the way embedded ROM file selection was saved which prevented saved systems with an embedded ROM specified from loading
    EX-292 - Fixed a race condition in the ViewManager which intermittently caused two "Image" windows to appear on startup
    EX-293 - Fixed several issues with device key mapping which prevented new key assignments being made
     
  17. Nemesis

    Nemesis

    Tech Member
    That would be the ideal, and microcode-level emulation with the correct internal registers and update steps would be essential in order to accurately emulate the exception stack frame information on the M68010 and higher. I actually took a serious look at beginning work on this for Exodus, but I found there was simply not enough information currently known to make a proper start of it, and it's a long road to gather all the information. I'm hoping we'll get there someday. I'm going to focus on something simpler to start with though, which is breaking down opcodes into discrete states based on their external bus cycles, so that an M68000 core can be written which will present with the correct timing externally, which is really the main goal here. Full microcode-level emulation is only required when the internal processor state beyond the bus access level is exposed externally, such as for exception stacks on the M68010 and higher.

    That'll be in the AudioStream support library, and my money is on a Wine bug. The WinMM API takes a hammering in that library order to achieve the low-latency gapless audio playback Exodus needs, without clicks and pops when emulation lags. It looks like the lock is internal to their WinMM implementation. My side of the code is stable and well tested, and I'd be surprised if there was a race condition. An API usage bug is possible though, which the Win32 API might silently ignore. The API documentation is terrible here, so I wouldn't be surprised if either Wine or Exodus is making a mistake.

    The CRAM dots will be more accurate, but still not 100% correct due to a lack of sub-opcode timing in the M68000 core. The VDP has perfect timing though, the M68000 just needs to use the correct timing on its access.

    Correct. Should be an easy task for anyone who might want to give it a go, otherwise I might get to it sometime soon.

    Someone else reported having trouble accessing the site too. Not sure what's up with it, seems to only be either very short-lived or only affect a few people. I've never seen problems myself. Try a full refresh of the page (ctrl+F5 in Chrome), otherwise no idea what's going wrong.

    I won't be working on ports myself, but other people are free to try. I've worked hard to keep the code as platform independent as possible, and isolate any necessary platform-specific code.
     
  18. Covarr

    Covarr

    Sentient Cash Register Member
    4,233
    3
    18
    Trapped in my own thoughts.
    Two stageplays, a screenplay, and an album
    For some reason, it seems to hover around 61-62fps when I have throttling enabled, instead of 60. Is this on purpose?
     
  19. MarkeyJester

    MarkeyJester

    Original, No substitute Resident Jester
    2,202
    432
    63
    Japan
    Gave both 2.0.0 and 2.0.1 a go. The improved speed is definately there (albeit minor), interestingly, the audio seems responsible for the majority of the slowdown, specifically DAC/PCM (I assume this is due to the YM2612 being constantly sent data at a frequent rate? Correct me if I'm wrong). At any rate, it's definately improved.

    The plane viewer is much cooler than I was expecting, the green boxes than bend and reshape based on the scroll positions is a genius idea! Though it seems to crash when selecting sprites while the sprite table is being changed/altered mid-screen multiple times.
     
  20. winterhell

    winterhell

    Member
    1,165
    7
    18
    Things to make the emulator great :

    - .smd format support(this would include autodetection which is the actual format since some .bin files are actually renamed .smd and vice versa)

    - while maximizing the emulator window changes backbuffer size, it should also change the actual viewport's size, and not it remaining in the bottom left corner with the same number of pixels.

    - needs a better UI. The File menu is a good start, you would want to take couple of hints from the likes of Kega Fusion for setting the Input.

    - while it did detect I have 6-button controller, I cant seem to be able to use it for playing. I'm with the 'USB Genesis RetroPort ' . Apart from it not being configured, in the configuration it doesnt detect A,B,C and Start. This is likely due to the way the controller works and some APIs have trouble with that as well, or cloning the input for A/X, B/Y, C/Z, Start/Mode.
    All this being said, I cant seem to be able to control a game with neither the keyboard or the controller(mapped one of the buttons to Start and it still doesn't work)

    - I assume you are rendering to a 640x448 pixel buffer. If you copy that to a texture and then have the option for aspect scaling with no filtering(nearest neighbor) it would make many people happy.

    Disclaimer: I understand this emulator is primarily for research and development purposes, not so much for the consumers. That being said, having all of those points would make for a several times better user experience. If they are already possible, then they are either not set as the default setting, and I'm having a hard time finding the way to set any of them. And I've been programming for 15 years now.
    I can also tell those would take minor effort or time compared to the whole endeavor that is the whole emulator.

    Its up to you if you need/want those features. I can assist with testing and OpenGL rendering.

    Cheers.