How Dolphin lastly cracked the code on Star Wars: Clone Wars, now emulates each GameCube title
Emulating consoles on fashionable PCs is an advanced enterprise. There are important low-level variations between the structure of a console and that of a PC. Whereas a few of these points could be brute-forced by uncooked computational horsepower, others closely resist this sort of answer. Dolphin, the favored emulator for GameCube and Wii titles, lately launched a significant replace to its personal supply code that lastly allows emulation on the final title standing: Star Wars: The Clone Wars.
The staff revealed a weblog publish detailing the way it achieved this process. It’s an attention-grabbing instance of how the unique developer’s choice to reap the benefits of some rarely-used GameCube capabilities prevented their sport from being emulated for over a decade. On this case, the issue boiled right down to the GC’s reminiscence administration unit, or MMU.
The MMU contained in the GameCube gives video games with digital reminiscence addresses that it maps internally to bodily reminiscence areas. The MMU is able to offering both a Block Deal with Translation (BAT), which remaps a big chunk of reminiscence, or with finer-grained web page tables for small quantities of reminiscence. The GameCube used an MMU within the first place as a result of it allowed the CPU to cache reminiscence accesses, and since there’s solely 24MB of RAM within the system, regardless of having a 4GB most addressable area. The diagram beneath exhibits how MMUs work, usually phrases.
Dolphin was already able to emulating the GameCube’s MMU in a number of methods. Most video games simply use the default BAT mappings supplied by Nintendo. Help for this mode is hard-coded into Dolphin. The emulated console doesn’t “know” that its knowledge requests are being stuffed from a really totally different reminiscence subsystem than the one the GameCube shipped with. On this mode, the MMU isn’t truly doing any handle translation — it is aware of the place the GameCube expects to search out reminiscence based mostly on the handle handed to it, and it retrieves the corresponding block of knowledge from the PC’s RAM.
The second type of emulation that Dolphin helps is predictable invalid reminiscence requests. The GameCube included 16MB of RAM that was mapped to the audio DSP, however many video games use this pool for extra reminiscence. Offered they achieve this in predictable vogue, Dolphin can seize these addresses (though they’re invalid) and hand the sport the info its requesting — supplied it all the time requests info from the identical set of invalid reminiscence addresses.
However what occurs when the addresses are each invalid and unpredictable? Prior to now, this killed sport efficiency. Really emulating the MMU takes 1000’s of CPU cycles, and the tempo of enchancment in CPU clock pace has all however stopped. The GameCube CPU might need solely run at 485MHz, however our fashionable chips are simply 10x quicker when it comes to uncooked clock pace — and there are features that merely can’t be emulated successfully when doing so prices 1000’s of CPU cycles.
From the Dolphin staff’s weblog publish:
Dealing with reminiscence checks (memchecks) is slower as a result of it harms the efficiency optimization “fastmem”. Fastmem maps the GameCube/Wii handle area to host reminiscence after which marks the entire emulated invalid reminiscence as allotted for the host PC. This permits Dolphin to make use of the host CPU’s exception handler to do the soiled work when catching exceptions. When it does catch an exception, Dolphin has to fallback from fastmem to slowmem with a view to deal with the handle, which generally is a big efficiency dilemma.
Memchecks are the core of what Allow MMU does, and it’s the important thing motive why MMU Enabled titles have been so sluggish in Dolphin. There are instances that require falling again to the interpreter, it doesn’t work with fastmem, they usually’re even slower than regular reminiscence accesses on console!
Latest code contributions by Fiora boosted efficiency in a single MMU title (Star Wars: Rogue Squadron) by 10x and in most others by a mean of 100%, however that wasn’t sufficient to unravel the issue of Star Wars: The Clone Wars. This specific title truly outlined its personal BAT — the one sport recognized to exist that did so. As a result of Dolphin essentially relied on the concept of a hardcoded BAT, there was no method to handle this edge case with out rewriting all the reminiscence emulator subsystem, and probably not with out ruining efficiency in an awesome many different video games within the course of.
One of many Dolphin contributors, magumagu, evidently got here up with a method to rewrite Dolphin to help The Clone Wars’ customized BAT mapping with out compromising efficiency in another title. Based on the Dolphin staff, earlier makes an attempt to help the sport had the aspect impact of decreasing efficiency in different video games by as much as 30%. Whereas the staff has taken an 8-15% hit in different MMU titles, it believes it may possibly get well this loss by means of additional tweaks and enhancements. Different video games ought to truly see improved efficiency and fewer bugs on account of the rewrite, so the good points ought to be effectively value it in the long run.
Console emulation has truly moved a bit extra mainstream as of late, due to excessive profile efforts from Microsoft to emulate the Xbox 360 on the Xbox One. Even Sony has dipped its toe within the waters with PS2 emulation on the PlayStation 4. Nintendo’s upcoming console, the NX, reportedly gained’t be backwards-compatible — which might spur curiosity in emulating that platform as effectively.