Yet Another Gamecube’s Dev Diaryhttps://gxdev.wordpress.com
Sat, 19 Nov 2016 10:53:14 +0000enhourly1http://wordpress.com/https://s2.wp.com/i/buttonw-com.pngYet Another Gamecube’s Dev Diaryhttps://gxdev.wordpress.com
YM2612 reveals his secretshttps://gxdev.wordpress.com/2008/08/08/ym2612-reveals-his-secrets/
https://gxdev.wordpress.com/2008/08/08/ym2612-reveals-his-secrets/#commentsFri, 08 Aug 2008 14:45:24 +0000http://gxdev.wordpress.com/?p=96]]>In Sega Genesis emulation history, YM2612 sound chip has always been one of the hardest part to emulate and more over when you are going the accurate way, since no technical documentation really exists to describe how the FM synthesiser chip internally works.

During a long time, the only documentation we had was the official Sega Developers Sound Manual that describes the interface with the YM2612 OPN chip and his internal registers.

As a result, the number of available YM2612 core, written by emulator authors, is rather limited:

The “MAME” core, written by Tatsuyuki Satoh & Jarek Burczynski, courtesy of the M.A.M.E emulator. This is an open-source emulator with a rather high level of accuracy thanks to lot of low-level tests made on real Yamaha OPN chips from the same family.

The “GENS” core, written by Stéphane Dallongeville, author of the GENS emulator. This is also an open source emulator, inspirated by the MAME core regarding internal YM2612constants. It has beenseveral times updated to improve sound renderingin someSega Genesis games. For example, Stef added an interpolationmethod to emulate the YM2612 at his original frequency (quite but not completely similar as the KegaSuperHQ option). He also made many (but probably only at high level) tests on a real Sega Megadrive to adjust emulation parameters. The result is that his core is sometime considered as being more accurate than the MAME core regarding to some specific games.

Kega’s core, written by Steve Snake, one of the Sega Genesis emulation’s pioneer (author of Kgen & Kega). Not much is known about this core since it is closed-source but it is considered as the “most accurate” YM2612 emulator and Steve Snake admitted he spent MANY hours testing all possible features of the real chip. This even includes undocumented & unofficial features (see below) used by some games. The result is that, effectively, the accuracy level is quite HIGH and Kega was considered as the only emulator being able to render the sound of some games quite exactly as on real hardware. Sadly, Steve Snake always remained very discrete about his findings and, for whatever reasons, never publically shared them.

As you can now guess, excepted Kega, quite all (open-source or not) Sega Genesis/Megadrive emulators use the M.A.M.E core as a reference and, logically, share the same emulation flaws, resulting in some sound emulation inaccuracy.

Hopefully, a new document was recently discovered & translated, that covers the YM2608 FM chip. This chip is part of the same Yamaha OPN chip family as the YM2612 and obviously share a lot common internal behaviour. This document covers pretty everything about the chip registers & internal tables and even fixes some mistakes from the original Sega YM2612 document. However, it appeared quickly that the M.A.M.E core was already emulating all described features correctly so this document, even if being a great resource for emulator authors, could not help in fixing undocumented behaviour on his own.

But Nemesis, who is writing his own Sega Genesis emulator (not yet released) took this opportunity to start intensive tests on a real YM2612 chip, trying to fully understand how it internally works and most important, documenting it & sharing his notes.

Among other things (you can read the full thread here), he made priceless discoveries about two undocumented features that caused some games to sound incorrect before (one of this “bug” being discussed in a previous entry of this blog by the way, affecting some of the games using GEMS sound driver)

And now ?

I implemented these findings in the M.A.M.E ym612 core that I’m using for Genesis Plus and also, implemented sample interpolationto emulate the chip as it original frequency, which is required by some games to sound more correctly (the best example is known to be Sonic the Hedgehog’s end of level sign spinning). Finally, I fixed some inaccuracies regarding the Envelope Generator and Phase updates in CH3 special mode.

The result is a pretty accurate sound emulation, way better than before, and probably close (if not better) to Kega level of accuracy.

The modified source code is freely available on the Genesis Plus SVN repository (fm.c) for anyone interested. It seems that the M.A.M.E team, through Richard Belmont, got their hand on this and updated the original core: good stuff happen when people are sharing code & informations !

Obviously, Genesis Plus for Gamecube/Wii has been updated to reflect current modification, the last version can as usual be found on his thread on Tehskeen.

I didn’t post before but since a few months, thanks to the hard work of para (author of the wiiuse library) & shagkur (libogc main developper), we now got easy-to-use & stable support for wiimote and expansion controllers in Wii homebrew. Obviously, Genesis Plus GX takes full benefit of this and now even support up to 8 players.

I also worked on Sms Plus GX to add accurate Sega LightPhaser emulation and to use the Wiimote IR pointing ability for a full nostalgic experience. Sega Menacer & Konami Justifier emulation should come along soon for Genesis Plus, more to come in a later post.

]]>https://gxdev.wordpress.com/2008/08/08/ym2612-reveals-his-secrets/feed/7ekeekeReaching the limits…https://gxdev.wordpress.com/2008/03/02/how-to-reach-the-limits/
https://gxdev.wordpress.com/2008/03/02/how-to-reach-the-limits/#commentsSat, 01 Mar 2008 22:46:58 +0000http://gxdev.wordpress.com/?p=71]]>Here’s the time for another release of Genesis Plus. I have focused myself in fixing some bugs I introduced in the previous version, as well as emulating most of unlicensed “non-working” games (many thanks to Haze for his work).

I also made some progress about emulating an original YM2612 bug that made some games (Ariel, Shaq Fu, Comix Zone, Spiderman & Animated Series,…) sound correct on real hardware but wrong on emulators.

Finally, I added SVP emulation thanks to the great work of Tasco Deluxe and Notaz : as a result, Virtua Racing is now fully playable but don’t expect to run it full speed in gamecube mode. It needs to emulate a custom DSP running at 23Mhz which takes a lot of CPU time actually. You can still underclock the DSP but it will result in slower 3D rendering and effective framerate will still seem slower.

That’s why, to celebrate the last release of LibOGC which added Wii hardware support, I also release a special elf version that could be running in native Wii mode using the recent “Twilight hack“. Please note that this version remain completely UNTESTED as I personnaly don’t have any way to test it on Wii. SO, tell me if the above game is at least running faster

completely rewrote EEPROM emulation: now support all known EEPROM types (24C01-24C65) and mappers (Sega, Acclaim, EA, Codemasters) used in a few games (now use internal game database) as external RAM. This should at least fix save support in the following games:

added “Xshift” & “Yshift” settings to let you adjust display area position while keeping the original aspect ratio

added option to disable/enable SSG-EG support in FM cores: this special mode is indeed not properly emulated and some games might sound wrong when enabled

removed “CPU Type” option, you can also now force Region (JAP/EUR/USA) without reseting the game, choose USA or JAP for 60hz, EUR for 50hz, this can be useful to bypass game region protection at startup.

]]>https://gxdev.wordpress.com/2007/12/28/new-genesis-plus-release/feed/2ekeekeWork in progress: emulation accuracyhttps://gxdev.wordpress.com/2007/12/17/work-in-progress-emulation-accuracy/
https://gxdev.wordpress.com/2007/12/17/work-in-progress-emulation-accuracy/#commentsMon, 17 Dec 2007 16:06:28 +0000http://gxdev.wordpress.com/2007/12/17/work-in-progress-emulation-accuracy/]]>After a lot of beta testing, a new version of Genesis Plus for Gamecube/Wii is about to be released… Even if there are no really revolutionary features, I’m quite satisfied with this one since I’ve been working a lot on emulation accuracy, which is one of the most interesting challenge about writing an emulator, in my opinion.

Beside correcting some bugs and cleaning some parts of the source, my goal this time was mainly to:

1) Emulate Genesis timings as accurately as possible

Some games are very timing sensitive and expect some events (VDP writes, DMA, HV Interrupts, HBLANK and VBLANK) to happen at very precise times, or for a very specific period. I will not go deeply into details but one of the key to correctly emulate several CPU running in parallel and accessing shared memory resources, is to emulate also the latency of those devices.

For example, on real hardware, switching interrupts ON through VDP registers do not trigger an interrupt immediately, but, more probably, the CPU will have the time to run one single instruction before jumping to the interrupt routine. Not emulating this tiny timing latency could cause some bad programmed games to hang, which was indeed the case of Sesame’s Street Counting Cafe, not really the best game in the world, but a good challenge to test emulation accuracy.

In some way, I finally found timings that should work with any sensitive games, without need anymore for specific games “hacks” but also without disturbing any previous working game. The goal behind this is that the emulator now achieves a near perfect compatibility rate (I only found some unlicensed games not working properly, mostly due to some unemulated cartridge hardwares)

2) Get a “pixel accurate” aspect on screen

The first idea was to emulate the colored overscan area which indeed exists all around the active display (generally 320×224 pixels) . Emulating the full display height (243 lines for NTSC) and width (based on the VDP Pixel Clock and scanline period), gives an accurate screen aspect ratio, much more similar to what a real Genesis/Megadrive displays. Below is a screenshot example of the full overscan area, rendered on a line basis (when displayed on TV, this area is generally hidden with vertical borders being only visible when the system runs in PAL mode)

The second idea was to add support for original Genesis rendering modes. Indeed, as many old consoles, it originally uses a ~ 240 lines progressive mode, which means that in a regular NTSC screen (always ~480 lines), only the even lines were displayed, odd lines remaining black (this is sometime recreated as “scanline effect” in emulators).

Additionally, the “interlaced mode 2” support (double resolution interlaced mode used in Sonic 2 “vs-mode”) was also improved, with a better rendering quality using both 240i/480i TV modes.

Finally, I also add optional support for original PAL video modes which means that the Gamecube/Wii could automatically switch into a PAL video modes (287p, 287i or 574i)when the virtual Genesis is running in PAL mode…

The results, compared side-by-side with my old switched Megadrive II, is pretty accurate in term of rendering or aspect ratio, and I hope every fellow retrogamers would enjoy this nostalgic feeling as much as I do.

What should be next…

Next step would be to improve the sound emulation, especially FM core emulation. I already improved the samples rendering and FM timers accuracy which (I believe) produce some more accurate sound effects in some games but I still need to add support for original YM2612 samplerate/frequency and also investigate about some undocumented features (or bugs ?) of the original hardware which make some musics sound totally weird (Flashback, Spiderman, Comix Zone…) under emulators.

Anyway, I’m planning to release soon the new version of Genesis Plus (SMSPlus coming also along, with similar additions) since it’s always more enjoyable to share his work with other people and get some feedback…more to come at tehskeen.

]]>https://gxdev.wordpress.com/2007/12/17/work-in-progress-emulation-accuracy/feed/1ekeekesonic2000.gifSerial EEPROM emulationhttps://gxdev.wordpress.com/2007/09/06/serial-eeprom-emulation/
https://gxdev.wordpress.com/2007/09/06/serial-eeprom-emulation/#respondThu, 06 Sep 2007 10:21:49 +0000http://gxdev.wordpress.com/2007/09/06/serial-eeprom-emulation/]]>I have recently decided to rewrite completely the EEPROM emulation code used in Genesis Plus. The previous one was based on Notaz’s Picodrive sourcecode but was not compatible with some games (Rings of Power, College Slam, Micromachines’ serie, …) and, beside from preventing game backup to work properly, also make some games crashing.

Since not so many Genesis games use serial EEPROM as backup RAM, this feature is generally not supported by common emulators (so far I know, only Kega, Picodrive and Jenesis have some kind of eeprom support but none of them seem to have support for every existing EEPROM games), which make me think it could be interesting to code a complete support myself.

The emulation itself is not very difficult since EEPROM datasheets (24Cxx eeprom are generally used) are freely available and the communication protocol is quite easy to reproduce. The main difficulty was to determine which games indeed use serial EEPROM (instead of classic parallel SRAM) and also which type of EEPROM it is and which type of EEPROM mapper they are using.

After testing many games on the emulator, I finally get some results and a list of games using EEPROM and their characteristic. I compiled this in a document, which emulator authors may find useful or not. In this document, there is also a quick note about how EEPROM read/writes work, covering all 3 EPROM’s modes that are used in known Genesis cartridges. Interested people could also have a look at eeprom.c in the genesis plus SVN repositery.

added SVP faking: display 2D graphics in Virtua Racing (the game is however still unplayable)

added support for more internal IO registers: fixe some unlicensed games (Wisdom Tree games…)

added preliminary support for unmapped protection device: fix some unlicensed games with special built-in hardware (Squirell King, Lion King 2…)

added “Soft Reset” combo (in game, use L+Z triggers): this should be like pressing the RESET button on a real Genesis and this is required in some games to enable special features or even complete the game (ex: X-Men).

[NGC]

added separate configuration for PortA/PortB inputs (GAMEPAD, MULTITAP or NONE, see Joypad Config): this let you setting PORTB as unplugged, which is needed in some games to access special modes or enable cheat codes (Alien Storm, X-Men…)

Freezestate & SRAM files are now compressed (using zlib)

FreezeState & SRAM files can now be saved/loaded to/from SDCARD: located in /genplus/saves/ from the root of your SDCARD

changed initial ROMS directory for SDCARD user: now looking for /genplus/roms/ from the root of your SDCARD

added user-transparent SRAM autoload (detection order is MCARD then SDCARD, SLOTA then SLOTB)

“System reboot” is now used for console reboot or SD/PSO reload if detected

added new font: now use original IPL font, extracted from Bootrom

modified controls when going into the rom selection menu (DVD or SDCARD):

use B button to go up one directory

use Z button to quit the file selection menu

use L/R triggers to go down/up one full page

use Left/Right buttons or Analog stick to scroll the selected entry’s filename when it can’t be full displayed

various menu rearrangment, minor bugfixes & sourcecode cleanup

21/06/2007

added 4.7GB DVD support for WII drives (the maximal allowed size for Gamecube DVD is still 1.35GB)

you can now switch between FM cores without reseting the game. FM registers value are automatically restored when switching.

modified PAL framesync a little bit: the 20ms period is now applied between the start of 2 consecutive frames, no more between the end of the previous and the start of the next one, which seems more correct to me.

removed the previous VINT timings modification because it brokes some games (Rocket Knight, Thunderforce III,…)

added automatic Timing configuration (VDP latency, VINT timing & alternate Line Timing) at game loading, based upon specific romname detection. This means you can still modify some of these options afterwards but they are now automatically set/unset when loading a game which need special timing fixes. These fixes are also automatically desactivated when the current game doesn’t need them. For your information, games that are actually detected and need special timings to run properly are:

Legend of Galahad & Road Rash series (single line not rendered properly)

added DVD automount: automatically call libogc DVD_Mount function if ISO PVD reading failed (idea taken from softdev’s last neocdredux release). This may be useful for loading roms from a DVD after booting from SDLOAD or after stopping DVD motor.

added “DVD motor off” feature, like in others emulators

corrected Memory Card mounting function: EXI_ProbeReset() function was never called if the first mounting attempt failed. Should fix some of the “Unable to mount memory card” errors.

22/03/2007

added SDCARD subdirectory browsing and LFN (255 char. max) support

17/03/2007

remove some rendering unused code (only used by DOS version of genesis plus) for little speedup

added an option to enable alternate line rendering timing (fix single line error in Road Rash series and Legend of Galahad’s Intro)