Live data from Hacker News

I built a Game Boy emulator in F#

nickkossolapov.github.io

41–50 of 84 posts

Re: I built a Game Boy emulator in F#

#41
post #32

Earlier quoted context omitted.

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.

I haven't used Fable much, but apparently it maps .NET arrays to js TypedArray. Presumably you could keep the registers in 8-element array and fable will properly produce a Uint8Array. I'd like to benchmark that.

Re: I built a Game Boy emulator in F#

#42
post #5

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!

Yes, CHIP-8 is kind of the standard "I want to get into emulators" first project. In my latest book Computer Science from Scratch we go CHIP-8 -> NES in chapters 5 to 6. GBA is quite a step up from CHIP-8. I would suggest doing NES or GameBoy next, but of course with today's LLM help GBA is very reasonable if you are going that route.

Re: I built a Game Boy emulator in F#

#44

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…

It's actually discussed in the article in the part where he ports it to fable (he also tried blazor)

Re: I built a Game Boy emulator in F#

#46
post #5

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!

Yes, CHIP-8 is kind of the standard "I want to get into emulators" first project. In my latest book Computer Science from Scratch we go CHIP-8 -> NES in chapters 5 to 6. GBA is quite a step up from CHIP-8. I would suggest doing NES or GameBoy next, but of course with today's LLM help GBA is very reasonable if you are going that route.

Got it

Re: I built a Game Boy emulator in F#

#48
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.

Re: I built a Game Boy emulator in F#

#49

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?

What do you mean? It has to mirror the behavior of the hardware pretty closely otherwise... well... the games don't run.
Post reply on HN