I built a Game Boy emulator in F#

291 points - yesterday at 5:14 PM

Source

Comments

DavyJone today at 12:12 PM
F# is my coding love language that I never get to use (outside of personal projects) :(
debugnik yesterday at 6:13 PM
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 [<Struct>], 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 &&& 0xFFuy` don't add anything over `member val A = 0uy with get, set`. I'm guessing this changed over time.

cermicelli yesterday at 5:44 PM
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.

redrobein yesterday at 11:29 PM
F# is a good language, but I feel like it's forever stuck in C#'s shadow. A lot of the library code is C# and .NET handmedowns. Not interfaces or libraries crafted with F# in mind, often having no explicit documentation for use with F# either.
hurril today at 6:56 AM
Ah F#, my greatest love. How I wish the C# guys and girls would see this instead of further bastardizing (don't hate me) C# into being everything but poorly.

Don't you see that if you would use F# instead, creating projects with C# and F#, that you would get what is being added to C# but actually working and ergonomically? Interop is great!

z500 yesterday at 5:58 PM
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
yoyohello13 yesterday at 6:10 PM
I always find emulators written in functional languages impressive. It tends to be much easier to map hardware to an imperative language. I enjoy seeing the functional abstractions people come up with.
tehnub today at 5:58 AM
Interesting, enjoyable post. Like the bit about data modeling. I've been dabbling in some OCaml and that kind of modeling is the best part. Also interesting to learn of CAMLBOY. Feedback to the author: Skip the AI edit step. I'd have preferred grammar errors or inelegance to what we have here, which is a bit stale.
hmokiguess yesterday at 5:46 PM
F# is super fun, awesome work!
CSMastermind yesterday at 6:43 PM
Insanely cool. I've had it in the back of my mind to write a Rust compiler for the game boy for a long time and everytime I see something like this I think about brushing off that project.
BadBadJellyBean yesterday at 11:10 PM
When I read F# I always have to think of the song with the same name by Tim Minchin and it starts playing in my head.
mannycalavera42 today at 8:19 AM
dsyme nodding proudly meme here
thrownawaysz yesterday at 6:53 PM
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.
hallegbg today at 10:15 AM
Really Cool!
sirjaz today at 12:04 AM
This is awesome. Love seeing projects like this.
mkw5053 yesterday at 7:37 PM
Very cool. Makes me want to build something with F*
MattCruikshank yesterday at 6:06 PM
Sorry for the tangent - does anyone have some really zoomed in views of GB, GBColor, GBA screens in operation? I'd love for retro shaders to be able to more faithfully reproduce.

I mean, ideally, we'd run different color test patterns through, in different lighting conditions, to build a really detailed model, right?

deadbabe yesterday at 9:28 PM
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?
__loam yesterday at 6:01 PM
I'm actually starting a new project to create a gba emulator in zig, and also starting with chip8. I'm going to skip nand to tetris because I played Turing complete. Cool to see I'm on the right track!
DeathArrow today at 4:22 AM
Now I would like to see the other way around, F# running on Game Boy.
dmitrygr yesterday at 7:46 PM
> No code is free from the influence of AI these days, even learning projects

Speak for yourself

makeryi411 today at 8:25 AM
[flagged]
abricq yesterday at 7:23 PM
[dead]
surajguptayc today at 4:32 AM
[dead]
Ginop yesterday at 6:21 PM
I misread Fem-Boy and I was not understanding the context anymore lol