Accuracy takes power: one man's 3GHz quest to build a perfect SNES emulator

How can it take 3GHz to emulate a Super Nintendo? The man behind a major SNES emulator explores the difficulty of true hardware emulation—and what users get from such efforts.

<a href='http://meincmagazine.com/gaming/news/2011/08/accuracy-takes-power-one-mans-3ghz-quest-to-build-a-perfect-snes-emulator.ars'>Read the whole story</a>
 

Hurda

Ars Scholae Palatinae
1,427
Nibbling Hell Goat":39xprb16 said:
Very interesting article - I downloaded bSNES immediately after reading.

Then I launched it and pointed it at my ROMs folder, then spent ten minutes extracting stuff and trying to figure out why it wasn't showing anything up, finally reading on the site that even if I extract all my .zips, it's not going to support the .smc files inside.

I like the idea of building a reference emulation that is truly accurate but I can't see many people using it in practice if it's this much of a pain in the arse to try it out.
bsnes comes with snespurify, which removes the unnecessary headers of ROMs like .smc, .swc etc.
 
Upvote
0 (0 / 0)

Markm49uk

Smack-Fu Master, in training
94
Seriously the level of knowledge and skill on display here is simply outstanding. I have programmed realtime interfaces between Allen Bradley logic controllers on 3 axis labelling machines for some of the worlds largest mobile phone companies but seriously this article makes me feel like I am a mere beginner.

Kudos.
 
Upvote
1 (1 / 0)

nharding

Seniorius Lurkius
2
Christopher Blue":2duo61dn said:
nharding":2duo61dn said:
I was writing a game for the Sega Master System. You could write to the video memory during the vblank, and it took 16 cycles per byte, or it would take 29 cycles whilst it was drawing the screen. You had 64 8x8 sprites (maximum of 8 per scanline), so by counting the z80 instructions I could get another 16 sprites by rewriting the position registers (for a rear view mirror), and I downloaded extra data whilst rendering the screen, changing palette color for the side of the road, and horizontal scroll register on each line, and I think I could get another 4 bytes downloaded as well. If you were emulating something like this, you would get visual tearing if cycle times were not emulated correctly.
That sounds really cool nharding, do you happen to have a website with more information on your project?

No, this was 15 years ago, it was Rad Mobile for the Sega Master System. During development of that I actually found a hardware bug that doubled the size of sprites (they became chunky, but appeared as 16x16 pixels on screen). I used that on the Sega Game Gear, and used the LCD persistence on it as well, to get semi transparency, plus an extra overlay character map, so I had character explosions, and huge sprites (diagonally shifting the position every frame, and using a 15 frame walk cycle instead of a traditional 4 frame, to hide the blockyness). It looked more like a SNES game then a Game Gear game, but that would need an emulator that would merge the frames into a frame buffer to emulate the LCD persistence.

Emulation is hard to do correctly. I used a high level emulation on the Sega Saturn for Sonic 3D Blast, which was converted from the Genesis. We changed the graphics, to use 256 colors for Sprites instead of 16, and the maps had 4096 characters rather than 256 for extra details (plus layer effects, like rain, snow, etc). It was good enough emulation, that the demo sequences which were stored as left <30 frames>, a, up <20 frames>, a, etc, worked the same on the Saturn and PC as they did on the Genesis. There was a data table, in the code, which was not terminated, but since it was in the middle of the code on the Genesis, the instruction that followed happened to be negative, so there was no bug, but since I was converting the data and code separately I had a bug that took a while to track down.
 
Upvote
2 (2 / 0)

RevEng

Seniorius Lurkius
2
It's great to see that people are trying to make perfect emulations of old hardware, but I wonder, why do it in software on a general-purpose CPU? FPGAs are plentiful and you can generate much of this old hardware quite easily in relatively inexpensive FPGAs. Yes, I understand that they will never be as cheap and accessible as desktop PCs, but if you are worried about preserving the details of an ancient platform, it's easier to make functionally identical versions of the original chips and reproduce them that way that it is to emulate the entire thing in software. As a plus, the hardware descriptive languages are already designed for describing the operation of hardware; no need to make a slew of custom classes to describe and emulate the functions of these in your favorite high-level language.
 
Upvote
1 (1 / 0)
Thanks for writing this excellent article!

I have an appreciation for this type of article, I've written the software-based 16550AFN UART emulator for Linux DOSEMU back in 1994. (Google "rejhon DOSEMU" to find it)

It was a high-level emulator of the serial-port UART chip running at register level behavior, but it actually passed a 16550 tester better than many 16550 clone chips at the time, supporting a few quirks, back in the old 386-SX days when the accessible timer interrupts ran at only around 18Hz, and I had to simulate things like the transmit queue empty interrupt, that occurs delayed far less than 1/18th sec later, that was really hard...
 
Upvote
2 (2 / 0)

ringobob

Ars Praefectus
4,784
Subscriptor
Awesome article. It strikes me (and someone may have addressed this in the comments already) that it may be possible to write a best-of-both-worlds emulator. If running it faster and less accurately is just a matter of reducing the synchronization schedule (and other such localized changes), perhaps bsnes could implement a performance slider that ramps down the accuracy in controlled amounts and ramps up the speed accordingly. When you run into a game that doesn't work with those settings, ramp up the accuracy bit by bit until you get what you're looking for, perhaps even have a warning for games that present with a known bug at lower accuracy settings.

I know things are rarely that simple, and it may be very complex and not worth it to incorporate that into bsnes, but it would help to solve the issue of losing users to a faster and more currently usable emulator while we wait for 3ghz to be as common as 800mhz is today.
 
Upvote
1 (1 / 0)

michealPW

Seniorius Lurkius
1
Exelius":1sa7ry7r said:
Accuracy is great, but so is portability. Your hyper-accurate SNES emulator works great on a modern desktop machine, but what about an iPhone or Android Tablet? There are often times when you don't want to use all your available power

If you desire to emulate nes/snes on your iPhone or Android tablet, then the speed-oriented emulators such as zsnes are what you're looking for.

If you're at home and you want to take advantage of your powerful desktop PC then you can use Byuu's accuracy-oriented bsnes emulator.

It's important to remember that this is not a zero-sum game. In order for Byuu to make a high-accuracy bsnes, zsnes does not have to go away. There's no reason why Byuu can't work on the extremely-accurate bsnes while the zsnes team continues to work on their emulator.
 
Upvote
0 (0 / 0)

revlimit

Seniorius Lurkius
1
I programmed several games on the SNES and I can well believe it needs so much power to emulate. It was by far the most difficult machine I ever worked on, because it never felt 'solid'. It didn't even seem to be deterministic - you could write code to do the same thing in two different ways; one would work, the other wouldn't. There was something weird going on with the timing that destroyed the flexibility you assumed you had. You could mess around with the hardware on an old 8-bit machine, but the SNES would bite you back if you tried. So yes I'm not surprised a completely accurate emulation is next to impossible - I'm not even sure anyone knows 100% how the thing worked.
 
Upvote
2 (2 / 0)

CrankyRealist

Wise, Aged Ars Veteran
127
If software emulation is too expensive why not reverse engineer the hardware?
Make a hardware replica of the snes console, same components or functionally equivalent ones.

Only difference is that you can plug it in to a usb port.

I've always wondered why software emulation have been the only solution. Why not ask the makers of the consoles and the games for the specs and source code?
This is preservation of history after all.

Now fast-forward to 2014. When will developers begin emulating old game copy protections so we can play those games on new hardware?

I've tried as recently as last year to play Bioshock 1 and 2 on windows 7 x64. The copy protection made it nearly impossible to play my own bought games !
How did i solve it?
I downloaded a game crack from a piracy site because the game company refused to offer me a game update to remove the copy protection or update the copy protection to work with my modern computer.

"We offer no technical support or software update patches of such old products"

Now ask me: Why should copy protections (and patents) be made illegal?

Funny: I can still play Doom and Quake on all new hardware i buy because it doesn't have copy protection afaik and if problems arise I can download the source code and patch the problem myself.

This is why I love, support and appreciate the work John Carmack have done.
All game companies should follow his example. Publish the source code! Preserve the history through sharing.

Many games, movies and music have been lost because the owners didn't care about preserving their own "property".
Only reason this doesn't happen to human kids is because there are laws against it.
Should we make laws to force content creators to preserve their creations?
 
Upvote
1 (1 / 0)
[url=http://meincmagazine.com/civis/viewtopic.php?p=26037191#p26037191:2rma3hrp said:
CrankyRealist[/url]":2rma3hrp]If software emulation is too expensive why not reverse engineer the hardware?
Make a hardware replica of the snes console, same components or functionally equivalent ones.

Only difference is that you can plug it in to a usb port.

There are plenty of hardware SNES clones out there, actually, and IIRC, some will even take SD cards as input. The problem is that, even though most of the patents surrounding the SNES are expired, some of the details are still secret, so even those are not 100% accurate.
 
Upvote
1 (1 / 0)

Abresh

Well-known member
2,344
With all due respect, there is no reason why an 'accurate' emulator should have to take all this power unless it is poorly written.

As to the "Speedy Gonzales" case, the best way to fix that is with game by game 'special' fixes for those specific games in those specific levels, that does not require the thing to be hyper-accurate. Actually, in many cases where those 'special' calls are made, they are a rudimentary form of DRM that is supposed to keep 'pirates' from playing the game through totally and those special 'calls' should not have been used in the first place.

I understand about 'accuracy' but many times extreme accuracy is not necessary in the real world of emulators. I'd also prefer that old game manufacturers had to release after about 10 years or whenever the console in question is not sold by first party's anymore the specifications for EVERYTHING including custom chips so that people can properly emulate them by simply 'rip the chips memory' like they did with PS1 emulation up until recently.

Even more preferable to the above? The game manufacturers release re-releases of their old games for the newer consoles. They don't even have to 'prettyfy' the game, just make it so that the old game runs on an emulator for the new console or just runs on the new console outright without an emulator, like many older NES and SNES-era games on the Wii U do now.
 
Upvote
-6 (0 / -6)
"As soon as Windows drops 32-bit backwards compatibility, just as it has already done with 16-bit backwards compatibility, these fan translations and hacks will be lost forever. "

Actually no, they won't be lost forever. By the time that's an issue, the host will be powerful enough to run said emulator inside another emulator like DosBox.
 
Upvote
0 (1 / -1)
[url=http://meincmagazine.com/civis/viewtopic.php?p=21935687#p21935687:2qvcxpnr said:
zibeb[/url]":2qvcxpnr]I wonder if virtualization technology could be applied to emulators.
Virtualization mimics "compactible hardware or environment" for OS/software, so target software can run and execute tasks with acceptable issues, but emulation mimics both hardware and OS/software so target software can run and execute tasks that produce the exact result like it was run on original hardware.
 
Upvote
0 (0 / 0)

mickoz

Seniorius Lurkius
1
It makes me think, and it might not be as simple as reading the example explanations in this article, that the author could allow the person running his emulator to tweak some options. Heck, since the game database is pretty limited and known, some optimisation, which keep the playing accuracy (or not) could be applied. You don't know the game in the database? You apply fully accurate mode to be on the safe side.

For example when BYUU said this "When it comes to video, 99 percent of games do not try modifying the display registers while the screen is drawing. This allows entire scanlines to be drawn at once, requiring 262 scanlines * 60 frames per second of synchronization. But run a game like Air Strike Patrol, which writes to the display brightness register multiple times per scanline, and you must synchronize after every clock cycle if you want full accuracy."

Based on this, 99 percent of the games could apply some optimisation which could hopefully keep all as accurate to the original playing experience without doing useless computation for the "user" of the emulator. While if it runs an exception, like "Air Strike Patrol", it could default to the most accurate mode.

I think like an user here. Without knowing the in and out of how the emulator works, I don't know if it can easily be controlled with a couple of options that we can turn on and off. But if it could be done, then the accurate emulators could appeal to both the user who search a speed emulator and the most accurate in the world emulator.
 
Upvote
0 (0 / 0)

lolAtU

Seniorius Lurkius
3
Aye, the hilarity of classic troll articles like this and people claiming to be programmers being impressed by it. The poster has no understanding of performance per clock, and gained reputation as a programmer despite saying nothing about programming and demonstrating knowledge equivalent of that of a superficial read of a Wikipedia page. Honestly, the internet attracts some really dumb people.
 
Upvote
-7 (0 / -7)

lolAtU

Seniorius Lurkius
3
Honestly, the internet attracts some really dumb people.
oh mighty necro poster, i dont think anyone is going to disagree with this portion and your example of this.

So the megahertz myth is not a myth because you think I'm dumb and I'm the only one that necroed this post? Although maybe I could've used a word other than dumb, more and more people are reading this and getting misled. The last post was from April 2017. That's the point, not whatever it is you're thinking.
 
Upvote
-4 (0 / -4)

Dark Empath

Ars Tribunus Angusticlavius
8,778
So the megahertz myth is not a myth because you think I'm dumb and I'm the only one that necroed this post?
No, you're dumb because you necroposted a 7 year old article for no other reason but to tell everyone how much smarter than them you are.

Good use of a first post, BTW.

The last post was from April 2017.
So your necropost was only 20 months old, so it doesn't count? Riiight.

That's the point, not whatever it is you're thinking.
I'm glad you're here to explain to us what the point is. We were lost without you.
 
Upvote
-2 (1 / -3)

Dark Empath

Ars Tribunus Angusticlavius
8,778
Upvote
-2 (0 / -2)
For those who enjoyed reading this featured article by byuu should also read the following ones I linked below:
http://www.tested.com/tech/gaming/44376 ... servation/
http://filthypants.blogspot.com/2011/05 ... dated.html
Necroman, Necroman, does whatever a mancer can,
Spins a post, any size,
Trolling readers just like flies
Look out, here comes the Necroman.

Dude, what is your problem? If you don't like my post, you could've easily ignored it. Different strokes for different folks.
 
Upvote
-2 (0 / -2)
Dude, what is your problem?
Zombies. Everywhere I look, zombies. The dead walk, and they post in eight year old threads.

Beware the double-tap, dude. Beware.
Dude, get a life. You've been spreading that same regurgitated hogwash in your 'cryptic' creep-infested nursery rhymes for years.
 
Upvote
-1 (0 / -1)

lolAtU

Seniorius Lurkius
3
So the megahertz myth is not a myth because you think I'm dumb and I'm the only one that necroed this post?
No, you're dumb because you necroposted a 7 year old article for no other reason but to tell everyone how much smarter than them you are.

Good use of a first post, BTW.

The last post was from April 2017.
So your necropost was only 20 months old, so it doesn't count? Riiight.

That's the point, not whatever it is you're thinking.
I'm glad you're here to explain to us what the point is. We were lost without you.

First off, this isn't a forum as far as I know. The necroposting rule is to prevent people from bumping old, no-longer-relevant threads to the top of the list. This is a news article with a comment section. Second, that it's from 2011 doesn't mean the ars technica staff stopped believing these things. That they don't remove it is testament to that. It was wrong then, it's wrong now. Even Wikipedia has an article dedicated to this sort of misconception. https://en.wikipedia.org/wiki/Megahertz_myth. There's an entire thread ridiculing this idea on dosbox's forum https://www.vogons.org/viewtopic.php?f=25&t=60444. AMD's infamous FX rebrand from 2013 is the GREATEST example of this, with them being the first to launch 5 Ghz CPU while Intel could afford to sleep on their laurels and just kept rehashing their old sandy bridge architecture to no penalty up until the 7000 series. AMD really deserved their lawsuit, although it wasn't because of the hertz at all to my understanding.
https://cpu.userbenchmark.com/Compare/I ... 3647vs1985 The 7700k, despite being clocked .7 Ghz higher, being a whopping 5 years newer, and having access to DDR4 memory bandwidth, only performed, on average, 38% faster than their 2700k.

To finish pouring salt on your (and your downvoting sockpuppets' still fresh) wounds, mGBA was designed for something as low end as embedded systems, yet emulated (don't know if it's still the case these days) at the time of release things no other emulator did. It's so accurate, it's Bizhawk's default GBA core.

On the off chance this is actually mirrored on a separate forum, this isn't something that was shown to me when commenting. Also, I don't care about the damage this may have inflicted upon you and your consistently odd-numbered sockpuppets. My apologies goes only to the staff if it bothers them.
 
Upvote
-3 (1 / -4)

Z1ggy

Ars Legatus Legionis
15,440
source.gif
 
Upvote
-1 (0 / -1)

Dark Empath

Ars Tribunus Angusticlavius
8,778
First off, this isn't a forum as far as I know.
o_O
It literally says "Arstechnica openforum" and "Ars Technica > Forums" at the top of the page. But, as far as you know, this isn't a forum. Okie dokie.

The necroposting rule is to blah blah blah Wikipedia has an article dedicated to blah blah blah while Intel could afford to sleep on their laurels blah blah blah it wasn't because of the hertz at all blah blah blah
Nobody cares. You're responding to a post I wrote in fucking January. That's so long ago I've forgotten what you're waffling on about.

To finish pouring salt on your (and your downvoting sockpuppets' still fresh) wounds
I have no idea what wound you're talking about. The world has moved on while you stewed over it for more than 10 months. That's some serious incel shit right there. Stewing and brooding over some random person on the internet mocking your bullshit posts for almost a year.

On the off chance this is actually mirrored on a separate forum
A separate forum? Separate from the forum you're posting in that you don't think is a forum?

Also, I don't care about the damage this may have inflicted upon you and your consistently odd-numbered sockpuppets.
I'm SO damaged. Damaged beyond repair. I don't think I'll ever be undamaged again. Your artfully crafted blah blah blah has inflicted damage I couldn't previously comprehend.

Thankfully I have no sock puppets for you to inflict damage upon, though I am curious which accounts you think were mine. Or why they're "consistently odd-numbered". That's some serious paranoia. Or perhaps you're just a professional victim.

You wouldn't happen to be orange, would you?
 
Upvote
-3 (0 / -3)