
Show HN: An NES emulator written in Rust - pcwalton
https://github.com/pcwalton/sprocketnes
======
kibwen
Note that this project includes a makefile, though Rust will be moving away
from make and friends entirely once the new rustpkg tool is merged:

<https://github.com/mozilla/rust/pull/4610>

Independence from external build tools is one of the coolest features of Go,
so I'm really excited about seeing more languages take this route.

~~~
gnuvince
Oh, that's really cool, I didn't know they had this project in the pipe. I
agree that bundling tools with the compiler is such a great idea; a build tool
built specifically for the language can assume so much more and do so much
more, it's a net win.

------
apaprocki
It was fun watching @pcwalton get it working in such a short time.. from the
first signs of life[1] to something we all recognize[2].

    
    
      [1]: https://twitter.com/pcwalton/status/298134945531035648
      [2]: https://twitter.com/pcwalton/status/299401519890042880

------
sixbrx
LOVE seeing stuff about Rust.

I'm at a junction where I've been using Scala happily, but it falls down for
numerical work because it can't call C libraries using large arrays without
copying, because of the different memory layout used by the JVM vs. C, which
really hurts for large data.

~~~
dysoco
I'm also a Scala fan looking fowards to Rust. Have you tried Go? I really like
it too.

~~~
sixbrx
I haven't tried it, but I've heard good things about the experience and the
performance. It didn't seem very functional though when I first looked at it
which is what I was interested in at the time.

There's something to be said though for being able to write programs that will
already be doing real work before the pinky finger has released the return key
that launched them, I like the _feel_ of that and I've missed that with the
JVM.

------
thristian
So... how much of the NES does this emulate? As I understand it, it's pretty
easy to get a basic 6502 core and a scanline renderer together enough to
handle, say, Super Mario Bros. but if you support all the timing corner-cases
and memory-map chips and such, it gets to be pretty frustratingly complicated.

EDIT: I should have looked more closely; looking into 'mapper.rs' reveals that
it currently supports only the vanilla NES memory-map.

~~~
pcwalton
It's very early. You're right that it supports only the very basic
functionality.

------
zura
@pcwalton

Thanks! quite interesting use case for Rust.

May I ask you - was it your side project or did you actually work on this at
the office?

~~~
pcwalton
It's a side project.

~~~
gnuvince
Next step, rewrite Firefox in 6502 assembly, and run it in your NES emulator!

------
zobzu
Looks pretty clean and concise, yet reasonably readable. Cool to see this
kinds of language demos.

~~~
kibwen
Concise indeed, only around 2,000 lines for the whole thing. Though I'm not
sure if it's possible to quantify the accuracy of the emulation.

------
aidenn0
This is cool and all, but...

Since when does an NES take "decent processing power" to emulate? I emulated
NES games on a 386DX40 and SNES games on a 486DX266. Certainly the emulation
wasn't as accurate as what you get today, but neither is this tech-demo
example.

~~~
gnuvince
I guess it depends on how closely you want to emulate the platform. For
example, there was a great article [1] about a SNES emulator that required an
extremely powerful machine, because it aimed to be a 100% accurate emulator. I
guess if pcwalton decides to go for a very accurate NES emulator, the CPU
usage would be non-negligable.

[1] [http://arstechnica.com/gaming/2011/08/accuracy-takes-
power-o...](http://arstechnica.com/gaming/2011/08/accuracy-takes-power-one-
mans-3ghz-quest-to-build-a-perfect-snes-emulator/)

~~~
jthomp
Nice, I was about to link the same thing.

------
jmgrosen
How would you recommend I get started learning Rust? It looks really
interesting, but I haven't found any reasonably good tutorials.

~~~
grayrest
I thought the official tutorial was good enough to start reading the library
code. That's probably about as good as it'll get until the language
stabilizes.

* Note: Rust is my language for the year. I can read Rust, follow program flow and I understand the major ideas but I've only put together toy programs.

------
saosebastiao
Is there a timeline set for Rust 1.0?

~~~
pcwalton
We're shooting for the end of the year. No guarantees of course.

------
fzzzy
Love it :-) I'm really looking forward to reading the code.

------
drivebyacct2
I think it's neat that this doesn't used any managed pointers and avoids the
Garbage collector. The fact that you can simply grep a codebase for '@' to
find cases of managed memory is great in my opinion. I've been learning the
Rust syntax a bit but am currently stuck trying to find a problem to solve
with it that doesn't require me writing a bunch of libs from scratch or
writing C interfaces. The Std/Core libraries are still rather lacking compared
to say, the Go std lib.

I'm sure that will change, but for now it seems unfortunate. For example,
there's an HTTP lib as part of Servo but according to some people in the IRC,
it's not even very good.

~~~
kibwen
Yes, the net lib was originally just intended to showcase preliminary libuv
integration rather than as any sort of production library. Work is ongoing on
a brand new approach to integrating libuv that will be both more efficient and
more flexible. Once that's done I expect a proper, well-designed net library
to emerge.

~~~
drivebyacct2
Fantastic to hear, I'm excited to watch Rust progress this year both in terms
of libraries, language polish and tooling that has been hinted at in this
thread. Some folks in the IRC gave me some pointers on another avenue
involving HTTP so I've got something to play around with for a while when I
get bored of writing Go :)

