Skip to content

Commit d49df68

Browse files
committed
initial test framework
1 parent f7d2235 commit d49df68

File tree

6 files changed

+62
-0
lines changed

6 files changed

+62
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ tetris.lbl
99
tetris.map
1010
tetris.dbg
1111
release/*
12+
target

tests/Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "gym-tests"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
rusticnes-core = { git = "https://github.com/zeta0134/rusticnes-core.git", version = "0.2.0" }

tests/src/labels.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use std::collections::HashMap;
2+
use std::sync::OnceLock;
3+
4+
fn labels() -> &'static HashMap<String, u16> {
5+
static LABELS: OnceLock<HashMap<String, u16>> = OnceLock::new();
6+
LABELS.get_or_init(|| {
7+
let text = include_str!("../../tetris.lbl");
8+
let mut labels: HashMap<String, u16> = HashMap::new();
9+
10+
for line in text.lines() {
11+
let parts: Vec<&str> = line.split_whitespace().collect();
12+
if parts.len() >= 2 {
13+
if let Ok(hex_value) = u16::from_str_radix(parts[1], 16) {
14+
labels.insert(parts[2].to_string(), hex_value);
15+
}
16+
}
17+
}
18+
19+
labels
20+
})
21+
}
22+
23+
pub fn get(label: &str) -> u16 {
24+
*labels().get(label).expect(&format!("label {} not found", label))
25+
}

tests/src/main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use rusticnes_core::nes::NesState;
2+
use rusticnes_core::cartridge;
3+
4+
mod labels;
5+
6+
fn main() {
7+
let rom = include_bytes!("../../tetris.nes");
8+
let mut emu = NesState::new(Box::new(cartridge::mapper_from_file(rom)).unwrap());
9+
10+
emu.registers.pc = labels::get(".addPushDownPoints");
11+
12+
// set pc
13+
// set stackpointer to something absurd
14+
}

tests/src/pushdown.rs

Whitespace-only changes.

0 commit comments

Comments
 (0)