Live data from Hacker News

Smolnes: A NES emulator in less than 5000 significant bytes of C++

github.com

11–20 of 26 posts

Re: Smolnes: A NES emulator in less than 5000 significant bytes of C++

#11
A great resource for learning how to write an NES emulator is the Jakt NES monster video series [1] which covers writing the entire emulator where JT shows how to map specs of each instruction to code. The source code uses Jakt's modern syntax making it very readable [2].

[1] https://www.youtube.com/playlist?list=PLP2yfE2-FXdQBRpnZbcOb...

[2] https://github.com/jntrnr/jaktnesmonster

Re: Smolnes: A NES emulator in less than 5000 significant bytes of C++

#12
post #6

you got me, though using SDL doesn't seem quite as fair if you use that title :P nice work though. I have been writing a compile-eval NES emulator in multiple languages, C++, Rust and such, it was a lot of fun. Still haven't managed to get it working with Rust, I still have hope.

> you got me, though using SDL doesn't seem quite as fair if you use that title :P

The program would still be sitting on top of an OS, unless it was a booter, at which point it would be sitting on top of device firmware, which sits on top of specialized hardware. SDL is about as generic a library as it gets when it comes to game development. Compare all of the companies that get credit for making their own first-person shooters, when all they had to rely on was a first-person shooter engine and a bunch of licensed assets. Scrabbling in the very dirt and clay, they are.

Re: Smolnes: A NES emulator in less than 5000 significant bytes of C++

#14

Those who enjoy this might also enjoy "Creating a NES emulator in C++11" [0] [1] [2] while not short in bytes of code(space) there is a nice video series short in minutes(time). Bisqwit takes you on a 30 minute tool assisted coding journey of making an NES emulator and also provides a 15 minute followup Q&A video explaining different aspects. [0] https://www.youtube.com/watch?v=y71lli8MS8s [1] http://youtu.be/XZWw745…

Bisqwit's nesemu1 source is 940 lines at https://bisqwit.iki.fi/jutut/kuvat/programming_examples/nese... It also uses SDL.

NES emulation is a great low level programming project and the tradition will probably continue for some time.

Re: Smolnes: A NES emulator in less than 5000 significant bytes of C++

#15
post #13

I did something similar, but couldn’t figure out a clever enough way of resampling the audio from “native” rate down to something that Windows was happy with. What was your strategy?

I didn't handle audio for this emulator. But you can see how I handle resampling in my more fully-featured NES emulator here: https://github.com/binji/binjnes/blob/ca6977469168069a165176...

I'm not sure it's the right technique, but it seems to work pretty well!

Re: Smolnes: A NES emulator in less than 5000 significant bytes of C++

#17

IOCCC entry? Tiny emulators seem to appear there semi-regularly, e.g. this one was memorable years ago: https://news.ycombinator.com/item?id=18198374

This was brought up for the last one of these I made, but the code here is c++ so wouldn't be allowed. I don't use a lot of c++ features, but it might be hard to keep the code size small without them.

Re: Smolnes: A NES emulator in less than 5000 significant bytes of C++

#18
While reading the code I stumbled upon "case 1 ... 10:” or similar and asked myself how I could have missed this range feature for so many years. It turns out that this is a GCC extension and indeed not part of the language. A list of the C extensions (and C++ extensions) can be found here: https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/C-Extensions.ht...

Re: Smolnes: A NES emulator in less than 5000 significant bytes of C++

#19

Those who enjoy this might also enjoy "Creating a NES emulator in C++11" [0] [1] [2] while not short in bytes of code(space) there is a nice video series short in minutes(time). Bisqwit takes you on a 30 minute tool assisted coding journey of making an NES emulator and also provides a 15 minute followup Q&A video explaining different aspects. [0] https://www.youtube.com/watch?v=y71lli8MS8s [1] http://youtu.be/XZWw745…

To save you a click, the video is someone speed-typing the source code to an emulator, with no commentary or explanation. You'd probably be better off reading the final result yourself.

Re: Smolnes: A NES emulator in less than 5000 significant bytes of C++

#20
post #18

While reading the code I stumbled upon "case 1 ... 10:” or similar and asked myself how I could have missed this range feature for so many years. It turns out that this is a GCC extension and indeed not part of the language. A list of the C extensions (and C++ extensions) can be found here: https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/C-Extensions.ht...

That's true, I should have mentioned that I use this extension. It is supported by clang as well, however.
Post reply on HN