RosettaBoy
==========
[![C](https://github.com/shish/rosettaboy/actions/workflows/c.yml/badge.svg)](https://github.com/shish/rosettaboy/actions/workflows/c.yml)
[![C++](https://github.com/shish/rosettaboy/actions/workflows/cpp.yml/badge.svg)](https://github.com/shish/rosettaboy/actions/workflows/cpp.yml)
[![Go](https://github.com/shish/rosettaboy/actions/workflows/go.yml/badge.svg)](https://github.com/shish/rosettaboy/actions/workflows/go.yml)
[![Nim](https://github.com/shish/rosettaboy/actions/workflows/nim.yml/badge.svg)](https://github.com/shish/rosettaboy/actions/workflows/nim.yml)
[![PHP](https://github.com/shish/rosettaboy/actions/workflows/php.yml/badge.svg)](https://github.com/shish/rosettaboy/actions/workflows/php.yml)
[![Python](https://github.com/shish/rosettaboy/actions/workflows/py.yml/badge.svg)](https://github.com/shish/rosettaboy/actions/workflows/py.yml)
[![Rust](https://github.com/shish/rosettaboy/actions/workflows/rs.yml/badge.svg)](https://github.com/shish/rosettaboy/actions/workflows/rs.yml)
[![Zig](https://github.com/shish/rosettaboy/actions/workflows/zig.yml/badge.svg)](https://github.com/shish/rosettaboy/actions/workflows/zig.yml)
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](https://www.rosettacode.org) 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](docs/main.md): exception handling
- [args](docs/args.md): argument parsing
- [cpu](docs/cpu.md): CPU emulation
- [gpu](docs/gpu.md): graphical processing
- [apu](docs/apu.md): audio processing
- [buttons](docs/buttons.md): user input
- [cart](docs/cart.md): binary file I/O and parsing
- [clock](docs/clock.md): timing / sleeping
- [consts](docs/consts.md): lists of constant values
- [errors](docs/errors.md): standard errors / exceptions / etc
- [ram](docs/ram.md): 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:
- `cd` into the directory for any implementation
- `./build.sh` to build the standard version with release-mode compiler flags
- `./rosettaboy-release [...]` to run games
Ideally the build 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 either Nix or Docker available, you can run `./utils/shell.sh` to create and run an environment with all necessary dev tools pre-installed. — `./build.sh && ./rosettaboy-release --headless --silent` should be able to pass tests for all languages.
If you prefer Docker, you can use `./utils/shell-docker.sh` instead.
If you prefer Nix, you can manually run `nix develop` or `nix-shell` instead. When run with an implementation as an argument, e.g. `nix develop .#py`, it will only provide what is needed for that language, and when run in the project root it will provide everything needed for all languages. Alternatively, there is also an integration with [nix-direnv](https://github.com/nix-community/nix-direnv).
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
`build.sh` for exactly which flags are used):
```
$ ./all.py bench | ./utils/sort.py
nim / lto : Emulated 16438 frames in 10.00s (1643fps)
rs / lto : Emulated 16029 frames in 10.00s (1603fps)
cpp / lto : Emulated 15064 frames in 10.00s (1506fps)
c / lto : Emulated 15054 frames in 10.00s (1505fps)
rs / release: Emulated 13904 frames in 10.00s (1390fps)
c / release: Emulated 13368 frames in 10.00s (1337fps)
cpp / release: Emulated 12967 frames in 10.00s (1297fps)
nim / release: Emulated 11860 frames in 10.00s (1185fps)
zig / release: Emulated 8844 frames in 10.00s (884fps)
zig / safe : Emulated 7206 frames in 10.00s (721fps)
c / debug : Emulated 5914 frames in 10.00s (591fps)
cpp / debug : Emulated 5663 frames in 10.00s (566fps)
go / release: Emulated 5029 frames in 10.00s (503fps)
pxd / release: Emulated 3610 frames in 10.00s (361fps)
nim / debug : Emulated 2587 frames in 10.00s (258fps)
rs / debug : Emulated 1808 frames in 10.01s (181fps)
py / mypyc : Emulated 789 frames in 10.01s (79fps)
php / opcache: Emulated 655 frames in 10.00s (65fps)
php / release: Emulated 257 frames in 10.02s (26fps)
py / release: Emulated 165 frames in 10.02s (16fps)
```
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...
没有合适的资源?快使用搜索试试~ 我知道了~
几种不同语言的gameboy模拟器.zip
共282个文件
sh:36个
py:30个
nix:24个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 43 浏览量
2023-03-23
21:30:10
上传
评论
收藏 319KB ZIP 举报
温馨提示
几种不同语言的gameboy模拟器
资源推荐
资源详情
资源评论
收起资源包目录
几种不同语言的gameboy模拟器.zip (282个子文件)
cpu.c 35KB
apu.c 16KB
gpu.c 14KB
buttons.c 4KB
cart.c 4KB
args.c 3KB
ram.c 2KB
clock.c 1KB
gameboy.c 1KB
main.c 381B
.clang-format 5KB
.clang-format 266B
cpu.cpp 23KB
gpu.cpp 12KB
apu.cpp 12KB
cart.cpp 3KB
buttons.cpp 3KB
args.cpp 2KB
ram.cpp 1KB
clock.cpp 1024B
gameboy.cpp 899B
main.cpp 737B
Dockerfile 2KB
.envrc 34B
.envrc 15B
.envrc 15B
.envrc 15B
.envrc 15B
.envrc 15B
.envrc 15B
.envrc 15B
.envrc 15B
.envrc 15B
.envrc 10B
.gitignore 142B
.gitignore 137B
.gitignore 123B
.gitignore 122B
.gitignore 115B
.gitignore 36B
.gitignore 31B
.gitignore 26B
.gitignore 18B
.gitignore 14B
.gitmodules 282B
cpu.go 27KB
gpu.go 11KB
apu.go 10KB
ram.go 6KB
buttons.go 3KB
cart.go 2KB
consts.go 1KB
gameboy.go 1KB
clock.go 1KB
errors.go 1KB
args.go 1KB
main.go 559B
_args.h 139KB
cpu.h 12KB
ram.h 7KB
ram.h 6KB
apu.h 4KB
consts.h 3KB
errors.h 3KB
errors.h 2KB
consts.h 2KB
gpu.h 2KB
cpu.h 1KB
cart.h 1KB
cart.h 1KB
buttons.h 885B
apu.h 875B
gpu.h 638B
gameboy.h 572B
buttons.h 500B
clock.h 492B
gameboy.h 472B
clock.h 427B
args.h 386B
args.h 370B
.mypy.ini 51B
composer.json 575B
composer.lock 73KB
Cargo.lock 14KB
flake.lock 7KB
README.md 7KB
README.md 5KB
README.md 3KB
README.md 1KB
README.md 924B
errors.md 863B
buttons.md 843B
README.md 683B
ram.md 628B
README.md 607B
args.md 593B
cpu.md 585B
gpu.md 584B
README.md 505B
gameboy.md 320B
共 282 条
- 1
- 2
- 3
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功