# Porting a NES emulator from Go to Nim

DevFeed: [Porting a NES emulator from Go to Nim](<https://devfeed.tech/articles/porting-a-nes-emulator-from-go-to-nim-30832.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/porting-nes-go-nim/>)

Published: 2015-04-30T22:00:00Z

Content type: article

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Emulator](<https://devfeed.tech/topics/emulator.md>), [Nim](<https://devfeed.tech/topics/nim.md>), [Go Language](<https://devfeed.tech/topics/go-language.md>), [Programming language](<https://devfeed.tech/topics/programming-language.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [emulator](<https://devfeed.tech/tags/emulator.md>), [go](<https://devfeed.tech/tags/go.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [nim](<https://devfeed.tech/tags/nim.md>), [porting](<https://devfeed.tech/tags/porting.md>), [programming](<https://devfeed.tech/tags/programming.md>), [programming-language](<https://devfeed.tech/tags/programming-language.md>)

## AI overview

The article describes porting a NES emulator from Go to Nim, using SDL2 as the backend and comparing compilation, binary size, source size, CPU usage, and memory usage. It also explains compiling the Nim-generated C code to JavaScript with Emscripten.

## Source excerpt

Let me get this straight. We have an emulator for 1985 hardware that was written in a pretty new language (Go), ported to a language that isn't even 1.0 (Nim), compiled to C, then compiled to JavaScript? And the damn thing actually works? That's kind of amazing. -- Summary by haberman I spent the last weeks working on NimES, a NES emulator in the Nim programming language. As I really liked fogleman's NES emulator in Go I ended up mostly porting it to Nim. The source code is so clean that it's often easier to understand the internals of the NES by reading the source code than by reading documentation about it. The choice of backend fell on SDL2 for me, contrary to GLFW + PortAudio that the Go version used. This was mainly motivated by the great portability promised by SDL2. Later we will see how porting to JavaScript and Android worked. If you're impatient and want to play a game, there's a JS demo. Comparison of Go and Nim Most Go concepts are quite trivial to translate to Nim. This made the porting process simple. Let's compare some data that I found interesting: Metric Go Nim (clang backend) Compile command go build nimble build Fresh compile time 2.1 s¹ 1.7 s Recompile time 1.5 s 0.5 s Binary size 16 MB (static) 136 KB + 1MB SDL2 Source code size² 3260 lines, 74 KB 2145 lines, 60 KB CPU usage 71 % 53 % Memory usage 79 MB 73 MB ¹ Excluding go-glfw, go-gl and portaudio, which take 17 s to compile ² Emulation code only It's nice to see Nim doing well. Even the compile time is shorter than that of Go, which is well known for its short compile times. Now that the port seems to be doing fine and should be running on all Desktop platforms, let's look into some other interesting things we can do with Nim: JavaScript port via emscripten Nim has a JavaScript backend, but I don't trust it to be stable enough for this task yet. So I opted for emscripten instead, which can compile C code into JavaScript. Since Nim outputs C code, this sounds like a perfect fit. Luckily eeeee h