8 ms·
Fergulator - NES emulator, written in Go
- kodablah 13y agoThe juxtaposition between this and https://github.com/pcwalton/sprocketnes https://github.com/pcwalton/sprocketnes is neat. E.g. https://github.com/pcwalton/sprocketnes/blob/master/audio.rs https://github.com/pcwalton/sprocketnes/blob/master/audio.rs compared to https://github.com/scottferg/Fergulator/blob/master/audio.go https://github.com/scottferg/Fergulator/blob/master/audio.go or https://github.com/pcwalton/sprocketnes/blob/master/disasm.rs https://github.com/pcwalton/sprocketnes/blob/master/disasm.r... compared to https://github.com/scottferg/Fergulator/blob/master/disassembler.go https://github.com/scottferg/Fergulator/blob/master/disassem...
- voidlogic 13y agoIt is interesting to read and compare both, but I would avoid a simple LOC comparison as the Go versions have a lot of extra lines (newlines, unneeded selects, redundant case statements) that could easily be eliminated.
- pcwalton 13y agoEw, my audio code. :( I hacked the SDL audio bindings together with no regard to proper Rust idioms; hence the unsafe everywhere. The Go code reads far better. The disassembler is nicer though—it demonstrates macros and traits well. The macros and AddressingMode trait help avoid duplicating the instruction decode logic between the CPU interpreter and disassembler, with no overhead at runtime.
- ferg 13y agoThe audio bindings are due to the excellent Go-SDL package. Nevermind my own fork, that was just to remove some unneeded stuff to fix compilation on OSX.
- GhotiFish 13y agoHe should consider making the emulator able to read .fcm input logs from a TAS. These runs usually serve as good tests of an emulators compliance. Particularly the runs that were verified on the actual console. though... there are some cartridges that have random (read: not psudo-random) behavior, and can't actually be tested. (or tased at all)
- tptacek 13y agoI found Go to be really productive for expressing machine emulators; the language is deliberately amenable to working with ints at bit level, the packaging system is effective and mostly stays out of the way, it has a flexible "switch", there's just enough abstraction so that it's easy to swap different components (memories, etc) in and out, and, of course, once you start running the things, goroutines make it easy to step machines as coroutines.
- laumars 13y agoWith regards to the switch statement, I've read on stackoverflow[1] that function tables actually outperform switch statements when there's several cases. So I tend to avoid switches for performance critical routines. It will be interesting to see how 1.1 performs in relation to this. [1] http://stackoverflow.com/questions/9928221/table-of-functions-vs-switch-in-golang http://stackoverflow.com/questions/9928221/table-of-function...
- m0th87 13y agoThis is pretty strange if it's true; shouldn't a switch (especially one that simple) compile into a jump table? Otherwise what's the point? Does Go just linearly search through case conditions in a switch? EDIT: Missed the link: https://groups.google.com/forum/#!msg/golang-nuts/IURR4Z2SY7M/R7ORD_yDix4J https://groups.google.com/forum/#!msg/golang-nuts/IURR4Z2SY7... Seems like a reasonable argument, but then again I don't see why they even bothered adding a switch given those constraints.
- tptacek 13y agoThere is a general form to switch statements in Go that really is syntactic sugar over if/else chains. I get that serious emulators invest effort in making dispatch fast, and that a naive for/switch loop is not the fastest way to dispatch instructions, but it's nice for getting the emulator working. :)
- daeken 13y ago
- xyproto 13y agoBest part is that if you've installed Go and set up the GOPATH already, downloading and compiling fergulator is just a go get github.com/scottferg/Fergulator away.
- mseepgood 13y agoHowever, sdl, SDL_image and glew must be installed with header files.
- eruditely 13y agoWhere does one go to learn how to create an emulator? I'm interested in picking up C/Go (probably the latter nowadays) while trying to make an emulator. Is there a process people adhere by or do they seriously just figure it out?
- ferg 13y agoIt's mostly the steep curve of learning the platform you're trying to emulate. Start here: http://emu-docs.org/ http://emu-docs.org/ and read everything you can get your hands on. Begin with the CPU and start emulating that. Then just start adding hardware bit by bit. It makes a lot more sense as you get into it. For NES emulation, the community at nesdev.com is amazing for assistance if you get stumped.
- fiatpandas 13y agoI'm just beginning with emulators and I wrote my first one to emulate CHIP8 a few months ago. I'm now working on a gameboy emulator. Anyways, having no experience with assembly, processor instructions, bitwise operations, etc, I started with this tutorial: http://www.multigesture.net/articles/how-to-write-an-emulator-chip-8-interpreter/ http://www.multigesture.net/articles/how-to-write-an-emulato... Also, good reference: http://en.wikipedia.org/wiki/CHIP-8 http://en.wikipedia.org/wiki/CHIP-8 I think that tutorial quite good and I emerged with a solid understanding of what exactly emulators/interpreters do, and what it means to emulate a certain device. CHIP8 is very simple, so moving to gameboy is actually a very big leap. The gameboy's instruction set (you'll know why that is a crucial piece of information after completing the CHIP8 tutorial) is much larger, so it requires a lot more work and understanding. Let me know if you have any questions
- jimmaswell 13y agoI have a 90%-working chip-8 emulator in JS. I never got around to fixing an instruction that waits for user input, though. http://luna.thehorseplace.us/pr/chip8.html http://luna.thehorseplace.us/pr/chip8.html
- awy 13y agoI wrote a post about creating a Chip-8 emulator in JavaScript, if JS is your thing. http://blog.alexanderdickson.com/javascript-chip-eight-emulator http://blog.alexanderdickson.com/javascript-chip-eight-emula...