Live data from Hacker News

I built a Game Boy emulator in F#

nickkossolapov.github.io

31–40 of 84 posts

Re: I built a Game Boy emulator in F#

#31
post #4

That's so cool! I love F#, but I wrote a little Smalltalk interpreter in it and I can confirm it isn't exactly a speed demon for that kind of thing if you use it as intended lol

Out of curiosity when did you write that interpreter? The entire dotnet ecosystem has seen massive speed improvements over the years, particularly for anyone who last tried them during the Framework era. Hell they even put work in to improving tail calls which the c# compiler doesn't even take advantage of (also either in the dotnet 9 or 10 timeframe f# added an attribute to make it so a recursive call that isn't a t…

It's .NET 10 lol. It's not so slow you can't write stuff for it, I have implementations of Conway's game of life, Huffman compression, and a minimal TUI. The main problem is doing almost anything in it involves a method lookup. And there are almost certainly places I could have done things more smartly.

One thing I do want to try out is publishing it with native AOT. I had a lot of luck with that on one of my other F# projects, I got like a 75% speedup out of it. I understand the JIT is supposed to outperform native AOT in the long term but I haven't seen it reach that speed.

Re: I built a Game Boy emulator in F#

#32

Cool to see F# here! Emulators are a great way to learn a language. On first sight you chose well between more or less idiomatic F# for each job. Some low hanging fruit to reduce allocations: the discriminated unions in Instructions.fs could be [ ], reusing field names to reuse internal fields. Also, minor nitpick but I'm confused about some of the registers. They are already of type byte, the setters with `a &&& 0xF…

The Register source has this comment:

    // Registers can't be a record type because the values need to be truncated to 8 bits when writing, so setters are needed
    // This is for the web renderer as Fable transpiles uint8 to Number (more than 8 bits) in JS and doesn't apply any truncation
    // Known non-standard behaviour in Fable (https://fable.io/docs/javascript/compatibility.html#numeric-types)
So, I think, it's just conservatively cleaning the data due to Fable's widening via js Number on the web target.

Re: I built a Game Boy emulator in F#

#33

Finally someone putting in actual human effort to learn something, and not a LLM helped me build X in Y minutes. There is some hope for humanity after all I suppose.

As a longtime F# developer and longtime recipient of STEM academic bullying[1] I refuse to use LLMs in large part because ChatGPT-3.5 was so ridiculously bad and obvious about copy-pasting from F# GitHub repos. I never felt the AGI, I just saw a plagiarism machine whose decorations had fallen off.

Eventually I am sure someone at Microsoft noticed and rang the RLHF alarm, so GPT improved substantially. It seems pretty usable for F#. I am sure some unprincipled F#er is crushing it with agents these days. But I didn't think "oh boy they solved the plagiarism problem, let's go generate some slop!" I thought "oh great, now it's no longer going to be blatantly obvious when ChatGPT plagiarizes." I really don't want to roll a d100, or even a d1000, to completely compromise a core value of mine in in exchange for a productivity benefit. I'll just be slow and jobless, thanks. This is serious: I am getting into solar installations and junk hauling.

[1] The "students don't want to think" problem is much older than LLMs. In 2007 I took a senior-level PDEs class, and almost everyone copied my homework because I was actually motivated to study PDEs, and too psychologically weak to resist those mean lazy math majors. Then it happened again in math grad school! Actually unbelievable. Why are you even in the program?

Re: I built a Game Boy emulator in F#

#34
post #21
post #17

Earlier quoted context omitted.

It's always going to exist. People still build things with hand tools in the year 2026. Let's call it Artisanal Coding.

Even if you use AI, there's a certain point where it's not clear that an AI would make you faster. F# is my favorite language, and I've been programming in it so long (since 2012) that I feel like I think in F#. Asking an AI for something can be faster if I can state my requirements informally; but if I need to specify many things precisely to an AI... why not just write the code in F#? Part of the beauty of good fun…

> I probably spent over 20 hours debugging, scanning the emu-dev Discord, creating tests, and even throwing the issue at earlier AI models. Nothing worked. But then after a few weeks away from the emulator I tried Claude Opus, and it found the issue in just a few minutes.

Even if you want to write all the code yourself (which is a fine decision), the only reason in 2026 to bang your head against a problem like this for 20 hours is if you really enjoy doing so.

(I'm surprised that "earlier AI models" didn't work for the author. For me, free-tier Gemini gets stuff like this correct all the time.)

Re: I built a Game Boy emulator in F#

#35
post #23

mildy related but wasn't there an emulator (maybe not GB but NES or SNES?) which had a visual panel showing each CPU cycle step by step? afaik it was very slow but the 1000% accuracy was the goal not playability.

My guess is you're thinking of no$gmb, a very early Game Boy emulator: https://gbatemp.net/threads/no-gmb-2-5-dos-full-version.6039... I've got fond memories of using this to get a preview of Pokemon Gold before it was released in NA!

Found it

MetalNES, transistor level NES emulation https://github.com/iaddis/metalnes

While searching I also found a new one, VisualNES https://kaiokendev.github.io/nes/about

There is also one for GB https://github.com/aappleby/MetroBoy

Re: I built a Game Boy emulator in F#

#36

mildy related but wasn't there an emulator (maybe not GB but NES or SNES?) which had a visual panel showing each CPU cycle step by step? afaik it was very slow but the 1000% accuracy was the goal not playability.

I'm not sure if this is the one you are talking about but I remember seeing this a little while ago. https://mtmc.cs.montana.edu/

Found it

MetalNES, transistor level NES emulation https://github.com/iaddis/metalnes

While searching I also found a new one, VisualNES https://kaiokendev.github.io/nes/about

There is also one for GB https://github.com/aappleby/MetroBoy

Re: I built a Game Boy emulator in F#

#37
post #31

Earlier quoted context omitted.

Out of curiosity when did you write that interpreter? The entire dotnet ecosystem has seen massive speed improvements over the years, particularly for anyone who last tried them during the Framework era. Hell they even put work in to improving tail calls which the c# compiler doesn't even take advantage of (also either in the dotnet 9 or 10 timeframe f# added an attribute to make it so a recursive call that isn't a t…

It's .NET 10 lol. It's not so slow you can't write stuff for it, I have implementations of Conway's game of life, Huffman compression, and a minimal TUI. The main problem is doing almost anything in it involves a method lookup. And there are almost certainly places I could have done things more smartly. One thing I do want to try out is publishing it with native AOT. I had a lot of luck with that on one of my other F…

AOT vs JIT is always interesting since JIT depends on the runtime actually deciding to bother running the later passes to get more optimized code.

And sorry for the paranoia, I find a lot of people tried f# or even c# back in 4.x Framework era and think it hasn't changed.

Re: I built a Game Boy emulator in F#

#38
post #32

Cool to see F# here! Emulators are a great way to learn a language. On first sight you chose well between more or less idiomatic F# for each job. Some low hanging fruit to reduce allocations: the discriminated unions in Instructions.fs could be [ ], reusing field names to reuse internal fields. Also, minor nitpick but I'm confused about some of the registers. They are already of type byte, the setters with `a &&& 0xF…

The Register source has this comment: // Registers can't be a record type because the values need to be truncated to 8 bits when writing, so setters are needed // This is for the web renderer as Fable transpiles uint8 to Number (more than 8 bits) in JS and doesn't apply any truncation // Known non-standard behaviour in Fable (https://fable.io/docs/javascript/compatibility.html#numeric-types) So, I think, it's just co…

Oof, thanks for pointing that out, I hadn't noticed and I've only ever used F# on .NET.

That's terrible on Fable's part, the least they could do is truncate. I wasn't aware Fable's translation is so naive.

Re: I built a Game Boy emulator in F#

#39
post #17

Finally someone putting in actual human effort to learn something, and not a LLM helped me build X in Y minutes. There is some hope for humanity after all I suppose.

It's always going to exist. People still build things with hand tools in the year 2026. Let's call it Artisanal Coding.

trad coding

Re: I built a Game Boy emulator in F#

#40
Building emulators is cool but everyone does it, and the end result is more or less the same. Is there some things that could be done during the process to perhaps make an emulator a little more unique instead of a perfect replica?
Post reply on HN