
An NES emulator written in Go - shurcooL
https://github.com/nwidger/nintengo
======
jmsdnns
The author blogged some of the experience too. \-
[http://nwidger.github.io/blog/post/writing-an-nes-
emulator-i...](http://nwidger.github.io/blog/post/writing-an-nes-emulator-in-
go-part-1/) \- [http://nwidger.github.io/blog/post/writing-an-nes-
emulator-i...](http://nwidger.github.io/blog/post/writing-an-nes-emulator-in-
go-part-2/) \- [http://nwidger.github.io/blog/post/writing-an-nes-
emulator-i...](http://nwidger.github.io/blog/post/writing-an-nes-emulator-in-
go-part-3/)

~~~
drbawb
This is so cool; what a great read. I'm working on a Gameboy emulator in Rust
at the moment and I'm in the same boat as the author: I know it has been done
before; _but I've never done it before!_

It's awesome how the Gameboy kept me entertained for hundreds and hundreds of
hours as a kid. -- Here I am over a decade later, and debugging my Gameboy
[emulator] has kept me up into the wee hours of the night. (On more than one
occasion, I might add.)

\---

Funny thing is I was actually going to write a NES emulator. On new-years day
I decided I really wanted to write an emulator that could play the original
MOTHER.

After a little bit of cursory research: the Gameboy hardware seemed a tad more
approachable. To be honest that's not terribly surprising: obviously to fit a
game console in such a small package (for the time) you had to make a lot of
sacrifices.

~~~
joshbaptiste
@drbawb and @bpowell , if you guys can blog (or take notes) about your
experiences building these emu's it would be a great.. It is a topic I would
definitely read/follow, I grew up on Nintendo/Gameboy and now reading how you
chaps are recreating my childhood addictions via emulation is just wonderful.

~~~
drbawb
I have been keeping notes as I learn new things. Though they are more of a
personal journal than anything.

I'll think about cleaning them up and publishing them once I get the source
up. I just get uneasy about publishing stuff like this. It just never feels
like my prose [or my code] is "good enough" for the world to see.

I want to keep it all tucked away: so no one will make fun of my primitive
debugger, or how I use hardtabs for indentation![1]

[1]: The Rust style guide dictates the opposite. They can pry the tab key from
my cold dead pinky!

------
scosman
I like to imagine the creator came up with the name first (nintenGO) and said,
well damn, now I need to write it.

------
studs_terkel
I wrote a mostly complete NES emulator in Go this past December.

[https://github.com/hkhalsa/helloworld](https://github.com/hkhalsa/helloworld)

I haven't added audio support yet, and it isn't very go-gettable (yet). But!
the code is reasonably well commented, and I have played through much of Super
Mario with it.

[http://web.textfiles.com/games/nestech.txt](http://web.textfiles.com/games/nestech.txt)
is probably the best overview about what's going on in the NES, though it's
inaccurate in some places.

[http://wiki.nesdev.com/w/index.php/Nesdev_Wiki](http://wiki.nesdev.com/w/index.php/Nesdev_Wiki)
is a great site with far more information about the NES than you'll need to
write an emulator.

------
recursivetheme
Impressive! How did they manage to build something some complex without
generics?

~~~
jamiltron
You do realize that significantly more complex software has been written for
decades without the use of generics, right?

~~~
lloeki
I think you missed the irony.

------
drbawb
Out of curiosity: can anyone w/ the relevant experience explain why older
consoles like the NES and the GB have "mirrors" in their memory map? I haven't
programmed embedded systems so I really don't understand what the advantage
might be.

I thought the Gameboy was odd enough with it's 'echo' of WRAM. (Which isn't
even a complete mirror; it stops partway through WRAM#1.)

Reading the NES memory map though it gets quite silly! There's a mirror
($2008-$3FFF) that repeats a set of 8 registers ($2000-2007) _every 8 bytes._

Was this simply a matter of having more address space than physical memory? Or
were these mirrors actually useful when programming these consoles?

\---

I thought it might have to do w/ different addressing modes; perhaps you could
save some bytes by just storing offsets or something. But that makes no sense
in the context of the Gameboy. Many of the z80's extended instructions are
gone; the only "interesting" addressing mode is a handful of instructions
which treat an 8-bit address as an offset from $FF00.

~~~
wk_end
Usually it's just a side-effect of how the system is wired.

Consider that GB WRAM mirror, where C000 = E000 all the way up to DDFF = FDFF.
Let's look at these numbers in binary:

    
    
      C000 = 1100 0000 0000 0000
      E000 = 1110 0000 0000 0000
    
      DDFF = 1101 1101 1111 1111
      FDFF = 1111 1101 1111 1111
    

If you notice, that third most significant bit is the only difference - and
this is true the entire way through the mirror. Because that address line
wasn't needed to access WRAM, it was probably never even wired to it - so on
access the value of it is simply ignored.

------
jzelinskie
There is also
[https://github.com/scottferg/Fergulator](https://github.com/scottferg/Fergulator)

~~~
pselbert
Came in here to make the same comment. I used to do some work with the author
around the time he was writing it. There was much talk about playing Battle
Toads in their break room.

~~~
ferg
Oh hey there ;)

3-player Bomberman 2 was also a big hit

------
anonbanker
Niels Widger, the author of this emulator, was the hardest working guy in the
emulation community, and single-handedly kept Zophar's Domain alive for years.
It's awesome that his love of emulation hasn't died more than a decade later.

Source: I've known the guy since he was thirteen.

------
bithush
If you liked this you might also enjoy these videos about writing a NES
emulator in C++11

[https://www.youtube.com/watch?v=y71lli8MS8s](https://www.youtube.com/watch?v=y71lli8MS8s)

------
danmanstx
cool project, better name! What advantages does Go add over other languages?

~~~
zerr
Coolness? I doubt "NES emulator in Java" would get any upvotes with the
nowadays userbase of HN... :)

~~~
kid0m4n
Yep, thats one of the main reasons of basing my startup on Go. For that
eventual HN post!

~~~
72deluxe
Is the language really that important to the end product? I know we like to
write in our favourite languages or the language we think in, but when you use
software daily, do you only use software written in C, for example? Do you
refuse to use anything written in C++?

~~~
27182818284
Not directly, but very possibly indirectly because of the people a new
language attracts: PG already touched on it:
[http://www.paulgraham.com/pypar.html](http://www.paulgraham.com/pypar.html)

------
Kurtz79
On cursory glance I haven´t found a single comment, still I think the code is
pretty readable, good job.

------
mrcactu5
I keep getting

    
    
      Failed to feed audio to OpenAL fast enough; resynching...

------
OedipusRex
Reminds me of NESticles

------
la6470
What use is this?

~~~
jimktrains2
What's the use of anything? Seriously, you're on HackerNews where all sorts of
one-off projects with no purpose except to exist get displayed and you're
asking what the use of an NES emulator is? Maybe the author wanted to learn
about emulation, or found it a challenge to do in Go. Does it matter? If you
don't enjoy it, move on.

