Skip to content
forked from shish/rosettaboy

A gameboy emulator in several different languages

License

Notifications You must be signed in to change notification settings

canh/rosettaboy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RosettaBoy

Trying to implement a gameboy emulator in a bunch of languages for my own amusement and education; also giving people an opportunity to compare the same code written in different languages, similar to Rosetta Code but with a non-trivial codebase :)

The main goals are:

  • Readability of the code
  • Consistency across langauges
  • Idiomatic use of language features
  • Basic playability

Notably, 100% accuracy is not a goal - if Tetris works perfectly then I'm happy, if other games require more obscure hardware features, then I'll weigh up whether or not the feature is worth the complexity.

Also yes, "consistent across languages" and "idiomatic" can be at odds - there are subjective compromises to be made, but for the most part that doesn't seem to be a huge problem. Rust uses Result, Python uses Exception, Go uses error - but so far it's always been pretty obvious that eg NewCart() in go and Cart.new() in rust are doing fundamentally the same thing in the same way.

So far all the implementations follow a fairly standard layout, with each module teaching me how to do a new thing. In fact they're all so similar, I wrote one copy of the documentation for all the implementations:

  • main: argument parsing
  • cpu: CPU emulation
  • gpu: graphical processing
  • apu: audio processing
  • buttons: user input
  • cart: binary file I/O and parsing
  • clock: timing / sleeping
  • consts: lists of constant values
  • ram: array access where some array values are special

Pull requests to translate into new languages, or fleshing out existing languages, are very welcome :)

Completeness

Feature Python C++ Rust Go
CPU
gblargh's test suite
interrupts
logging
Graphics
scaled output
scanline rendering
GPU interrupts
Audio
audio off-key glitchy
Inputs
keyboard input
gamepad input
turbo button
Memory
memory mapping
bank swapping

Benchmarks

Warning: These implementations aren't fully in-sync, so take numbers with a large grain of salt. For example: the Python implementation uses native code to blit whole 8x8 sprites in one go, while the other languages do one pixel at a time (which is more correct, and necessary for things like parallax effects), which means that the python version is unfairly fast.

Measurements are FPS, done with --turbo --profile 3600 opus5.gb (measuring how much physical time it takes to emulate 60 seconds of game time), on a Macbook Pro 2019 (2.4 GHz 8-Core Intel Core i9). If somebody knows how to measure CPU instructions instead of clock time, that seems fairer; especially if we can get the measurement included automatically via github actions. Pull requests welcome :)

Feature Python C++ Rust Go
release, silent, headless 5 700 700 60

About

A gameboy emulator in several different languages

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 48.2%
  • Rust 23.2%
  • Python 16.4%
  • Go 12.1%
  • Other 0.1%