Skip to content

Commit

Permalink
feat: desktop works, not key input
Browse files Browse the repository at this point in the history
  • Loading branch information
rkdud007 committed Nov 11, 2024
1 parent 117adc8 commit a3b1eb8
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 5,364 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ out/
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/
broadcast

# Docs
docs/

# Dotenv file
.env

target
target
2 changes: 1 addition & 1 deletion desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ cargo run -r
anvil

```
anvil -b 1 --no-request-size-limit --disable-block-gas-limit --disable-code-size-limit --disable-min-priority-fee
anvil -b 0.2 --no-request-size-limit --disable-block-gas-limit --disable-code-size-limit --disable-min-priority-fee --slots-in-an-epoch 1 --order fifo
```
71 changes: 42 additions & 29 deletions desktop/src/main.rs

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ libs = ["lib"]
fs_permissions = [{ access = "read", path = "./c8games" }]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
[rpc_endpoints]
sepolia = "${RPC_URL}"

[etherscan]
sepolia = { key = "${ETHERSCAN_API_KEY}" }
24 changes: 9 additions & 15 deletions script/Emu.s.sol
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;

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

contract EmulatorScript is Script {
Emu public emulator;

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

emulator = new Emu();
}

function run() public {
bytes memory bytecode = vm.readFileBinary("./c8games/PONG");
console.logBytes(bytecode);
uint8[] memory converted_bytes = new uint8[](bytecode.length);
for (uint256 i = 0; i < bytecode.length;) {
converted_bytes[i] = uint8(bytecode[i]);
unchecked {
++i;
}
}
emulator.load(converted_bytes);
emulator.run();
console2.log("emulator deployed at: ", address(emulator));

vm.stopBroadcast();
}
}
17 changes: 17 additions & 0 deletions test/Emu.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ contract EmuTest is Test {
// Instruction tests
// -------------------------------------------------------------------------

// Test 1: NOP instruction (0x0000)
function testExecuteNOP() public {
// 0x0000: Nothing

uint8[] memory program = new uint8[](4);
program[0] = 0x00;
program[1] = 0x00;
program[2] = 0x00;
program[3] = 0x00;

emulator.load(program);
emulator.tick();
emulator.tick();

assertEq(emulator.getPC(), 0x204, "PC should be advanced by 2 after NOP instruction");
}

// Test 2: CLS instruction (0x00E0)
function testExecuteCLS() public {
// 0x00E0: Clear the display
Expand Down
Loading

0 comments on commit a3b1eb8

Please sign in to comment.