Skip to content

Commit

Permalink
Performance, Docs (#4)
Browse files Browse the repository at this point in the history
added some optimization around display, key.
some inline documentation
faster state transition by script

* chore: rm fontset

* perf: display optimization

* perf: key transition optimization

* perf: speed up

* docs, key perf

* docs
  • Loading branch information
rkdud007 authored Nov 15, 2024
1 parent afa50f0 commit 3382502
Show file tree
Hide file tree
Showing 11 changed files with 584 additions and 724 deletions.
37 changes: 37 additions & 0 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Solchip8Test:testExecuteADD_I_VX() (gas: 114316)
Solchip8Test:testExecuteADD_VX_NN() (gas: 89953)
Solchip8Test:testExecuteADD_VX_VY() (gas: 94455)
Solchip8Test:testExecuteAND_VX_VY() (gas: 91732)
Solchip8Test:testExecuteCALL_ADDR() (gas: 114499)
Solchip8Test:testExecuteCLS() (gas: 88378)
Solchip8Test:testExecuteDRW_VX_VY_N() (gas: 344654)
Solchip8Test:testExecuteJP_ADDR() (gas: 66234)
Solchip8Test:testExecuteJP_V0_ADDR() (gas: 90378)
Solchip8Test:testExecuteLD_B_VX() (gas: 141807)
Solchip8Test:testExecuteLD_DT_VX() (gas: 111518)
Solchip8Test:testExecuteLD_F_VX() (gas: 113199)
Solchip8Test:testExecuteLD_I_ADDR() (gas: 88791)
Solchip8Test:testExecuteLD_I_VX() (gas: 186348)
Solchip8Test:testExecuteLD_ST_VX() (gas: 111602)
Solchip8Test:testExecuteLD_VX_DT() (gas: 111159)
Solchip8Test:testExecuteLD_VX_I() (gas: 185766)
Solchip8Test:testExecuteLD_VX_K() (gas: 123385)
Solchip8Test:testExecuteLD_VX_NN() (gas: 88611)
Solchip8Test:testExecuteLD_VX_VY() (gas: 90258)
Solchip8Test:testExecuteNOP() (gas: 50299)
Solchip8Test:testExecuteOR_VX_VY() (gas: 91838)
Solchip8Test:testExecuteRET() (gas: 97593)
Solchip8Test:testExecuteRND_VX_NN() (gas: 89812)
Solchip8Test:testExecuteSE_VX_NN() (gas: 91727)
Solchip8Test:testExecuteSE_VX_VY() (gas: 93398)
Solchip8Test:testExecuteSHL_VX_VY() (gas: 93145)
Solchip8Test:testExecuteSHR_VX_VY() (gas: 92912)
Solchip8Test:testExecuteSKNP_VX() (gas: 92890)
Solchip8Test:testExecuteSKP_VX() (gas: 113798)
Solchip8Test:testExecuteSNE_VX_NN() (gas: 91800)
Solchip8Test:testExecuteSNE_VX_VY() (gas: 93984)
Solchip8Test:testExecuteSUBN_VX_VY() (gas: 95119)
Solchip8Test:testExecuteSUB_VX_VY() (gas: 94713)
Solchip8Test:testExecuteUnknownOpcode() (gas: 64249)
Solchip8Test:testExecuteXOR_VX_VY() (gas: 91779)
Solchip8Test:testReset() (gas: 121981)
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/solady"]
path = lib/solady
url = https://github.com/vectorized/solady
203 changes: 0 additions & 203 deletions Emuabi.json

This file was deleted.

24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
# SolChip8

[Chip8](https://en.wikipedia.org/wiki/CHIP-8) Emulator written in Solidity.
`SolChip8` is the first 100% on-chain [Chip8](https://en.wikipedia.org/wiki/CHIP-8) emulator smart contract where you can run chip8 games on EVM environment. CHIP-8 is an interpreted programming language, initially used on the 8-bit microcomputers made in the mid-1970s.

[![Video Label](http://img.youtube.com/vi/e5J1xQcg4wU/0.jpg)](https://youtu.be/e5J1xQcg4wU?t=0s)


### Installation

```
forge install rkdud007/solchip8
```

### Deployment
| Chain | Contract Address |
|-------|-----------------|
| Ethereum Sepolia | [0x6Cf84915E775d47e685D84359526878b38170809](https://sepolia.etherscan.io/address/0x6cf84915e775d47e685d84359526878b38170809) |

Got helped alot from [An Introduction to Chip-8 Emulation using the Rust Programming Language](https://aquova.net/chip8/chip8.pdf).

### Features

- A 64x32 monochrome display
- Sixteen 8-bit general purpose registers
- 4096 bytes of RAM
- Example [ROM games](./c8games/) from [Chip-8 Games Pack](https://www.zophar.net/pdroms/chip8/chip-8-games-pack.html)
- Demo [![Video Label](http://img.youtube.com/vi/4cni9DNQ0wA/0.jpg)](https://youtu.be/4cni9DNQ0wA?t=0s)
- Run demo with [desktop](./desktop/)



### **Supported CHIP-8 Opcodes**

Fully tested on [here](./test/Emu.t.sol)
Tested [here](./test/Emu.t.sol)

| Opcode | Mnemonic | Description |
| ------ | ----------------- | ------------------------------------------------------------------- |
Expand Down Expand Up @@ -57,3 +72,4 @@ Fully tested on [here](./test/Emu.t.sol)
### Resources

- [chip8](http://devernay.free.fr/hacks/chip8/C8TECH10.HTM#8xy3)
- [An Introduction to Chip-8 Emulation using the Rust Programming Language](https://aquova.net/chip8/chip8.pdf)
1 change: 1 addition & 0 deletions desktop/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bitvec = "1.0.1"
sdl2 = "^0.34.3"
alloy = { version = "=0.5.4", features = [
"full",
Expand Down
334 changes: 208 additions & 126 deletions desktop/src/main.rs

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion lib/solady
Submodule solady deleted from 4ac044
10 changes: 5 additions & 5 deletions script/Emu.s.sol → script/Solchip8.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ pragma solidity ^0.8.21;

import {Script} from "forge-std/Script.sol";
import {console2} from "forge-std/console2.sol";
import {Emu} from "../src/Emu.sol";
import {Solchip8} from "../src/Solchip8.sol";

contract EmulatorScript is Script {
Emu public emulator;
contract Solchip8Script is Script {
Solchip8 public solchip8;

function run() public {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);

emulator = new Emu();
solchip8 = new Solchip8();

console2.log("emulator deployed at: ", address(emulator));
console2.log("solchip8 deployed at: ", address(solchip8));

vm.stopBroadcast();
}
Expand Down
Loading

0 comments on commit 3382502

Please sign in to comment.