Live data from Hacker News

Statically Recompiling NES Games into Native Executables with LLVM and Go

andrewkelley.me

21–30 of 103 posts

Re: Statically Recompiling NES Games into Native Executables with LLVM and Go

#21
post #20

Earlier quoted context omitted.

That thought occurred to me as well, although I did not actually try it.

Seems like a good followup post. I'd read that. I mean essentially it would make NES games running natively in the browser with no emulator right?

It's not quite as sunshine and rainbows as that. For one, I had to embed an interpreter runtime in the generated code to handle some dirty assembly tricks that programmers can do. Further, the Picture Processing Unit and Audio Processing Unit must be emulated. Even worse, there are some things that fool the disassembler that many games do. And finally, this project never even attempted to support mappers, which means that there are only about 8 or 9 notable games that this could even potentially support.

As is, it supports Super Mario Bros. 1 only.

Re: Statically Recompiling NES Games into Native Executables with LLVM and Go

#22
post #14

This is interesting. If this project can output LLVM byte code, then you could also codegen to javascript with emscripten and make a web based version of a NES game.

Or, you could just use an emulator written by hand in javascript: http://fir.sh/projects/jsnes

Re: Statically Recompiling NES Games into Native Executables with LLVM and Go

#23
post #11

I won't even pretend that I understand half of this but from a quick browse this looks pretty interesting. It seems very well written, too. Filed away into my magic "ZOMG INTERESTING PROJECT IDEA" folder :D

Oh, man! I know that folder! I don't have one, but 20. I've switched from bookmarks to actually writing it down on a piece of physical paper. And not just the url. I write down a small explanation for my future self. I haven't been bored in months :D

Re: Statically Recompiling NES Games into Native Executables with LLVM and Go

#26
post #9

Earlier quoted context omitted.

Emulating accurately takes much more power than you'd think: http://arstechnica.com/gaming/2011/08/accuracy-takes-power-o... ;

Oh, I know, but that's usually really tiny edge-case things. NES emulation was "good-enough" speed and accuracy-wise a decade ago. These days even an older-model smartphone can emulate NES games solidly well.

Unless you get into speedrunning games where accuracy matters a lot and some emulators are "banned" because they are lacking in it. Banned in this case of course only meaning that you will not get recognition from most of the communities for performing speedruns on such emulators.

Re: Statically Recompiling NES Games into Native Executables with LLVM and Go

#27
This is one of the best technical articles I've seen in a long long time congratulations. I won't go and pretend I understand what is really going on but the writing style is excellent, to the point and the general flow and formatting are a pleasure.

Props dude.

Re: Statically Recompiling NES Games into Native Executables with LLVM and Go

#28

There is some research on this http://www.pagetable.com/docs/libcpu/26C3-libcpu.pdf It's a very interesting topic. It may be our best chance at preserving software.

It's really unfortunate that libcpu didn't take off. Last I checked, they got nowhere with no contributors, and now their site 503s. It was an interesting project.

Re: Statically Recompiling NES Games into Native Executables with LLVM and Go

#29
post #9

Earlier quoted context omitted.

Emulating accurately takes much more power than you'd think: http://arstechnica.com/gaming/2011/08/accuracy-takes-power-o... ;

Oh, I know, but that's usually really tiny edge-case things. NES emulation was "good-enough" speed and accuracy-wise a decade ago. These days even an older-model smartphone can emulate NES games solidly well.

You're right in that emulating the NES "good-enough" for most games is no big feat, in terms of power, but you are wrong in saying that it's because the platform is "old". There are old systems that are much trickier to emulate simply because software takes advantage of every corner case in the hardware design, using cycle perfect timing to exploit unexpected behavior in the chipset. The C64 is the perfect example, still having a pretty vibrant demoscene, coming up with new tricks that break emulators every year. Then, to get a reasonable level of accuracy, you need to emulate everything per cycle, complete with a bunch of analog hardware (simply emulating the SID sound chip is quite a heavy task) and registers bound to pins simply left floating.

Re: Statically Recompiling NES Games into Native Executables with LLVM and Go

#30
post #20

Earlier quoted context omitted.

Seems like a good followup post. I'd read that. I mean essentially it would make NES games running natively in the browser with no emulator right?

It's not quite as sunshine and rainbows as that. For one, I had to embed an interpreter runtime in the generated code to handle some dirty assembly tricks that programmers can do. Further, the Picture Processing Unit and Audio Processing Unit must be emulated. Even worse, there are some things that fool the disassembler that many games do. And finally, this project never even attempted to support mappers, which means…

There was a NES emulator for the Game Boy Advance that performed with a surprising level of accuracy at full frame rate. I guess the CPU emulator was a simple state machine, but the interesting thing in this context is how it did the graphics and sound. Having a pretty advanced "PPU" of its own, with the same basic types of features (sprites, tile indexing background layers), it translated the PPU register writes (with appropriate scaling, I guess) to native register writes. I'm not sure how things like collision interrupts were handled, but presumably the GBA has similar functionality. For a javascript emulator or static recompilation, similar methods could be used to set up a bunch of shaders dealing with the basic functionality of the PPU (sprites, tile layers etc). Certainly less accurate and probably missing a bunch of corner cases, but it would definitely be the fastest approach to dealing with graphics emulation.
Post reply on HN