top | item 26450096

Experimental Nintendo Switch Emulator written in C#

333 points| chwolfe | 5 years ago |github.com

168 comments

order

molticrystal|5 years ago

This emulator currently has the most complete guest audio renderer implementations, as they just finished a project of doing an in depth reversing of that portion of the firmware. [0]

Getting it to work with the host os(windows usually) can have minor issues with output in rare circumstances, or when a game is still not running the proper speed, but they've ironed out the major ones.

-----------------------

    This is my requiem, I present to you Amadeus, a complete reimplementation of the Audio Renderer!
    This reimplementation is based on my reversing of every version of the audio system module that I carried for the past 10 months.
    This supports every revision (at the time of writing REV1 to REV8 included) and all features proposed by the Audio Renderer on real hardware.
[0] https://github.com/Ryujinx/Ryujinx/pull/1481

dt3ft|5 years ago

Awe inspiring. 10 months of work and 250 changed files! Respect!

edoceo|5 years ago

Why wouldn't one create and emulator for this using QEMU? Couldn't that be possible? Doesn't a bunch of hardware faking have to be rebuilt in C# that QEMU already does (well¿)? Or is it too hard to introduce custom hardware/firmware (like this audio stuff) into QEMU?

zapzupnz|5 years ago

For emulators that intend to run games at full speed, the sorts of shortcuts and tricks needed to achieve high level emulation (which can sometimes fall short of emulation in a strict sense) are often incompatible with writing a plugin or extension to an emulation framework that focuses on accuracy.

In the case of the Switch, it's not necessary to emulate the whole device or even processor, especially if the intention is to run Switch games on a computer. Rather, high level emulation is more than sufficient — anticipate what the software depends on the actual hardware to do and redirect it to do the same using what the computer has available.

IntelMiner|5 years ago

There is one emulator currently that does do that, the "XQEMU" emulator for the original Xbox https://xqemu.com/

It's in its infant stages at the moment according to the "Emulation General" wiki and focuses heavily on "accuracy" over performance

Other emulators such as CXBX-Reloaded have made larger strides, currently emulating roughly 10% of the software library

It's also worth stating, while the Xbox seems like an "easy" target, being based on an ia-32 (Pentium III) PC with an Nvidia GeForce chip (somewhere between a Geforce 2 and 3 at the time) it is an absolutely monstrous beast with minimal documentation about its hardware and numerous "gotchas"

It also has a very small library of 'exclusive' content which detracts from gaining many developers

orra|5 years ago

> Couldn't that be possible?

I mena, in principle, presumably.

> that QEMU already does

Potentially a couple devices. But for most of the hardware, probably not.

Regardless they might—I would—find QEMU harder to hack on, harder to extend, because it is written in C. C is of course the lowest level of all high level languages.

whoisthemachine|5 years ago

> The CPU emulator, ARMeilleure, emulates an ARMv8 CPU and currently has support for most 64-bit ARMv8 and some of the ARMv7 (and older) instructions, including partial 32-bit support. It translates the ARM code to a custom IR, performs a few optimizations, and turns that into x86 code.

Interesting... since .Net is cross-platform and can run on ARM, if it's running on an ARM processor does it just run the instructions directly?

grishka|5 years ago

> if it's running on an ARM processor does it just run the instructions directly?

You can't just run random instructions like that. That code is compiled with the assumption that there's the Switch's OS and hardware underneath, which means it will do all kinds of things, like calling directly into the kernel and assuming a particular address space layout, that would crash it under a different OS.

ARM has hardware virtualization. If the host OS supports it, you should be able to make use of it.

calaphos|5 years ago

The current ARMeilleure seems to emit x86 instructions directly and execute them, so never really using the intermediate representation of Jit compiler of the .Net runtime.

However the previous cpu emulator apparently emitted .Net byte code and used RyuJIT (the .Net jit) to emit the final native code.

> if it's running on an ARM processor does it just run the instructions directly?

So maybe? There are some passes in between but one would think it would at least result in very similar instructions.

brundolf|5 years ago

I have mixed feelings about emulating current-gen consoles. I think there's a very strong ethical case for emulating consoles whose games are no longer made (despite Nintendo's best efforts to shut that down too). But emulating something whose games can still be bought new would tend to encourage piracy, I expect.

Edit: "cracking" -> "piracy", for clarity

meibo|5 years ago

Unfortunately, Nintendo has not made any friends within the emulation/homebrew community especially as of late(or ever), so the common consensus seems to be "we don't care, as long as you don't do illegal things on our front porch".

This is purely an observation, however these things have tradition within the Nintendo hacking community and most members of the community are very passionate about their projects - the Wii is comparatively hard to emulate, which is why Dolphin is still struggling with certain things after a long time, while Switch emulators can run a lot of games nearly perfectly after less than half a decade.

Wowfunhappy|5 years ago

It sucks, doesn’t it? Developers deserve to get paid, but I’m glad I didn’t have to wait a decade to see Breath of the Wild in 4K.

I wish there was an easier way to run legitimately purchased cartridges. I don’t know how many people ever did it, but PCSX2, for instance, has always been able to run PS2 discs right off a standard PC optical drive.

If buying games can be made easier than piracy, lots of people will probably do that. But if piracy is way easier, then that’s what 99.9% of users will do.

matthewrobertso|5 years ago

Incidentally, around 20 years ago I purchased a copy of Bleem! at a Fry's electronics and some games to play on it (playstation was still a current-gen console at the time). I would not have purchased nor played the games if I had not purchased the emulator. This was probably not a typical thing to do but I don't see it as a fundamental thing that existence of emulators has to hurt software sales for a current-gen console.

I also think steam has proved that the way to beat piracy is to offer a better experience than piracy offers. I get headaches playing 3d content at 30 fps, I would pay double the cost per game to run first-party nintendo games on my PC at an unlocked resolution and frame rate.

foobar33333|5 years ago

These emulators are usually useless for piracy until after the console has reached its end of life. People start working on them as soon as possible but they don't work well for years. The switch is almost at the end now and there still isn't an emulator which works very well.

When the competition for emulators is buying a hackable switch and running dumped games natively with 0 bugs or slowdowns. I doubt switch emulators have prevented the sale of a single switch game.

ddevault|5 years ago

There are many reasons to use an emulator. You could play your own games on a new platform, or without having to pay for the hardware (a gaming PC which can run an current-gen emulator is expensive enough!). You could use it to play or develop homebrew software, or to research commercial software. You can use it to bypass region locks, which I would argue are quite unethical in their own right.

Even with all of that said, I support piracy. Information wants to be free, and games are made of information. No one has lost anything when a game is copied.

cdubzzz|5 years ago

> I think there's a very strong ethical case for emulating consoles whose games are no longer made (despite Nintendo's best efforts to shut that down too).

Do you differentiate between games being “made” and “sold”? If not, which consoles specifically are thinking of as ethical to emulate? Nintendo still sells NES, SNES, N64, etc. games via Virtual Console.

Cypher|5 years ago

We all have to make our own choices.

andy_ppp|5 years ago

If people who wouldn’t have bought a Switch end up playing those games on PC who has lost out here?

nix23|5 years ago

>But emulating something whose games can still be bought new would tend to encourage cracking, imo.

That would be truly terrible!! Making a copy of your owned games is a capital crime.

apatheticonion|5 years ago

I think consoles are great devices to make gaming accessible to the masses, requiring little to no effort to get up and running. Where I draw the line is console exclusives.

I will not purchase a console that forces me to buy hardware I do not need because they ban experiences from other platforms to try gain a competitive edge. I feel this is damaging to the industry as games with incredible experiences are blocked behind a paywall (and often restricted quality).

Consoles should compete on experience and features, not exclusive games that you can't play without buying into the ecosystem.

I only just got around to finishing Bloodborne (at 20-30 fps) and it's a game I have wanted to play since I saw the trailer back in 2013. It's so sad that they limit this game's IP to only PS4 owners. I would love to see the lore expanded upon in sequels (that run at an unlocked, variable frame rate), but if demon souls is anything to go by, we won't.

If it were available for PC, I would buy it. If it were available via emulation, I would buy it.

People who pirate games do so because they can't afford them, and there is nothing less affordable than having to buy an entire device to play a game.

Emulation does complicate this somewhat because piracy is a necessity to the experience, something that could be addressed by the hardware vendors themselves.

yc-kraln|5 years ago

The one thing I used to really enjoy about developing for Nintendo platforms once they've aged a bit is being able to have fast test-play cycles without hardware; for Gameboy Advance or Nintendo DS the emulators were very good and fully-featured (debuggers, memory inspection, etc.)

Unfortunately with Switch we're not there, and I don't think we ever will be. These emulators target, in order of priority, Cracked/Dumped Retail Games, then Homebrew games. I can't use them as part of my game development stack because they won't run binaries if they haven't been submitted to Nintendo to be signed (and subsequently cracked).

edflsafoiewq|5 years ago

What made C# a good choice for this?

tester756|5 years ago

Sometimes people just pick the languages they're most proficent in so they can move fast

maybe that's the case here

GlitchMr|5 years ago

Mostly, because it's easier to program in C# than in C++, and there is not much of a loss of performance (and worth noting that C# has `unsafe` keyword if necessary). In the past Ryujinx did use RyuJIT provided by .NET for JIT, albeit now it's using a custom JIT because RyuJIT was too slow for the way it was used by an emulator.

The_rationalist|5 years ago

C# is the fastest GCed language and emulators are not just about performance, a high level language increase both productivity and the number of contributors, hence the number/depth of optimizations + features and correctness. C# has C++ interop if ever needed.

aksss|5 years ago

I’m a big fan of c# but this question still fascinates me too. Would love to hear some input from the project devs on this.

nicetryguy|5 years ago

It's really coming along! It took Dolphin a few years to nail it but i'd imagine a near-perfectly emulated 4k switch in a couple years time.

caslon|5 years ago

Ryujinx isn't actually the only Switch emulator; between Ryujinx and Yuzu, you can emulate basically everything the Switch can do and play most of the games it can.

smaudet|5 years ago

Regarding all the positions that piracy is bad vs freedom of intellectual property, isn't this a bit a red herring?

I'm sure neither this nor Yuzu are 100% working - but if let's say work was done regarding allowing legal ripping, i.e. a license system whereby Nintendo grants sale or other rights to hobbyist runningthe express purpose of runnin their games on some emulator.

I think a lot of the people drawn to emulator, work, are drawn by the cool factor. Working on homebrew games is a way to learn and express passion about embedded platforms, game dev and coding.

They say 'piracy is stealing', but locking down platforms is also stealing. We should enforce universal IP monetary attribution - keep a low standard rate of mandatory fees which must be paid out while at the same time make it illegal for companies to entirely hide their designs.

huachimingo|5 years ago

Check out MelonDS, looks very promising and faster than Desmume. They managed to put a JIT for the emulation.

saagarjha|5 years ago

DeSmuME has a JIT backend.

royalghost|5 years ago

I am basically trying to learn c# after many years of working in JVM languages. This project looks like a good hack to learn C# and .NET.

azinman2|5 years ago

Considering this is emulating an ARM processor, I wonder how such software might perform if written specifically for the new M1 macs?

zapzupnz|5 years ago

I don't anticipate it would make much real difference. The trick with console emulators is usually making the graphics, audio, and game-specific quirks sing well on commodity hardware rather than the specialised hardware the console has. Getting ARM code to run on Intel isn't the hard bit — so getting ARM code to run on ARM may well be more performant than running it on Intel – but rather the trick is getting all the other precise console-specific hardware to sing with available cross-platform frameworks for audio and video.

andi999|5 years ago

Did GC lead to any problems?

Cyph0n|5 years ago

Impressive! Is this the first modern console emulator written in a GCed language, or even a language other than C++?

p1necone|5 years ago

The problems with GC'd languages are very exaggerated. I'm not surprised at all that this is performant in C#.

Orphis|5 years ago

I worked on Jpcsp a long time ago, PSP emulator in Java. It was the first emulator to manage to run a large amount of games. We had some crazy devs on it who even wrote a MIPS to Java bytecode JIT. It worked great... sometimes. We ended up running into lots of JIT issues as some patterns were unusual and not always properly handled by hotspot. Fun times!

monocasa|5 years ago

There were a slew of older JITing PSP emulators when it came out using C# that had modern architectures. It's a cute technique to bootstrap a JIT, using a JIT runime that people already can be expected to have.

pspplayer might have been the first? I could be wrong there

jb775|5 years ago

Is there a way to intercept data between the Switch and online Fortnite services?

I recently bought a Switch and have been playing Fortnite online...noticed more and more "online gamers" have been behaving like bots, so I'd like to take a look at the data if possible (to see if I'm playing against actual people)

emodendroket|5 years ago

Seems like you could intercept the traffic with your router.

177tcca|5 years ago

Wireshark and alternatives.

DC1350|5 years ago

This is great to see. It would be nice to play switch games on something at least as powerful as a modern phone

barbazoo|5 years ago

Are you implying that the Switch hardware isn't good enough for its games? I have yet to play a game that doesn't run well.

Maybe I should try Witcher 3.

miguelmurca|5 years ago

Starting a betting pool as to how long this makes it before being DMCAd

mappu|5 years ago

Emulators are legal (see Sony v Bleem).

Copyright infringement is a civil offense, but there's none here.

bri3d|5 years ago

Why would you see this emulator in particular getting DMCAed?

There's not really good precedent for this that I'm aware of - Nintendo did DMCA the repo for a GBA emulator a while ago, but it came with Nintendo game ROMs in the browser.

mdgrech23|5 years ago

what's that mean?

politelemon|5 years ago

I wanted to say dupe, but I can't really... my submission got no attention. Is it just matter of timing?

https://news.ycombinator.com/item?id=26445101

brundolf|5 years ago

Timing makes a huge difference in my experience

geswit2x|5 years ago

How is possible to post duplicate links in HN? I think when you do that, you get redirect to the duplicate one, and upvote the old post...