Giter Club home page Giter Club logo

rosettaboy's Introduction

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: exception handling
  • args: 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
  • errors: standard errors / exceptions / etc
  • ram: array access where some array values are special

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

Dev Guide

I want to keep the build processes as simple as possible - it should be possible to cd into the directory for any implementation and then ./run.sh should build (if necessary) and run the code. Ideally the run script should also fetch-if-needed any dependencies, the only assumption I want to make is that the user has the standard language dev kits installed (eg we assume anyone who wants to work on the Rust version will have Cargo installed; anyone who wants to work on Python will have virtualenv + pip; etc)

If you have a shell with docker installed, you can run ./utils/shell.sh to create and run a docker container with all the necessary dev tools pre-installed -- ./run.sh --headless --silent should be able to pass tests for all languages.

Benchmarks

Warning: These implementations aren't 100% in-sync, so take numbers with a large grain of salt. For example, as of this writing, the PHP version is using a stub SDL mock instead of calling the real C library, because I couldn't find an SDL library that worked.

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 :)

Running on an M1 Macbook Pro, using (to my knowledge) the latest version of each compiler, with standard "release mode" flags (see each language's run.sh for exactly which flags are used):

$ ./utils/bench.py
  zig / release: Emulated 28799 frames in 10.00s (2880fps)
   rs / lto    : Emulated 20371 frames in 10.00s (2037fps)
   rs / release: Emulated 16950 frames in 10.00s (1695fps)
  cpp / release: Emulated 15397 frames in 10.00s (1540fps)
  nim / speed  : Emulated 14241 frames in 10.00s (1424fps)
  nim / release: Emulated 14193 frames in 10.00s (1419fps)
   go / release: Emulated  5973 frames in 10.00s (597fps)
  php / release: Emulated   497 frames in 10.01s (50fps)
  zig / safe   : Emulated   228 frames in 10.00s (23fps)
   py / release: Emulated   181 frames in 10.00s (18fps)
   py / mypyc  : Emulated   179 frames in 10.01s (18fps)

Also if you spot some bit of code that is weirdly slow and making your favourite language look bad, pull requests to fix that might be welcome too, but "simplicity and consistency" are going to take priority (eg an "add an inline flag to this function" would be great but "replace python's CPU interpreter with a JIT compiler written as a C extension module" would probably be rejected[0])

[0] That said if somebody wanted to come up with a separate "python but all the slow parts are replaced with C modules like they would be in a real app" implementation, that could be interesting...

rosettaboy's People

Contributors

8bit-pixies avatar andrewrk avatar n5m avatar shish avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.