Skip to content

Commit 6cd0275

Browse files
committed
list all seeds
1 parent a331da1 commit 6cd0275

File tree

3 files changed

+67
-25
lines changed

3 files changed

+67
-25
lines changed

tests/src/main.rs

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mod block;
22
mod input;
33
mod labels;
44
mod pushdown;
5+
mod rng;
56
mod sps;
67
mod util;
78
mod video;
@@ -22,36 +23,14 @@ struct TestOptions {
2223
sps_seed: u32,
2324
#[options(help = "print SPS pieces")]
2425
sps_qty: u32,
26+
#[options(help = "list RNG seeds")]
27+
rng_seeds: bool,
2528
foo: bool,
2629
}
2730

2831
fn main() {
2932
let options = TestOptions::parse_args_default_or_exit();
3033

31-
if options.foo {
32-
let mut emu = util::emulator(None);
33-
let mut view = video::Video::new();
34-
35-
// spend a few frames bootstrapping
36-
for _ in 0..3 { emu.run_until_vblank(); }
37-
38-
emu.memory.iram_raw[labels::get("practiseType") as usize] = labels::get("MODE_TYPEB") as _;
39-
emu.memory.iram_raw[labels::get("gameMode") as usize] = 4;
40-
emu.memory.iram_raw[labels::get("levelNumber") as usize] = 18;
41-
emu.memory.iram_raw[labels::get("typeBModifier") as usize] = 5;
42-
let label = labels::get("mainLoop");
43-
rusticnes_core::opcodes::push(&mut emu, (label >> 8) as u8);
44-
rusticnes_core::opcodes::push(&mut emu, label as u8);
45-
46-
loop {
47-
emu.run_until_vblank();
48-
emu.ppu.render_ntsc(256);
49-
view.update(&emu.ppu.filtered_screen);
50-
}
51-
}
52-
53-
// TODO: cycle counts for modes
54-
5534
// run tests
5635
if options.test {
5736
sps::test();
@@ -75,4 +54,32 @@ fn main() {
7554
}
7655
println!("");
7756
}
57+
58+
// other stuff
59+
60+
if options.rng_seeds {
61+
println!("{:?}", rng::seeds());
62+
}
63+
64+
if options.foo {
65+
let mut emu = util::emulator(None);
66+
let mut view = video::Video::new();
67+
68+
// spend a few frames bootstrapping
69+
for _ in 0..3 { emu.run_until_vblank(); }
70+
71+
emu.memory.iram_raw[labels::get("practiseType") as usize] = labels::get("MODE_TYPEB") as _;
72+
emu.memory.iram_raw[labels::get("gameMode") as usize] = 4;
73+
emu.memory.iram_raw[labels::get("levelNumber") as usize] = 18;
74+
emu.memory.iram_raw[labels::get("typeBModifier") as usize] = 5;
75+
let label = labels::get("mainLoop");
76+
rusticnes_core::opcodes::push(&mut emu, (label >> 8) as u8);
77+
rusticnes_core::opcodes::push(&mut emu, label as u8);
78+
79+
for _ in 0..10 {
80+
emu.run_until_vblank();
81+
emu.ppu.render_ntsc(256);
82+
view.update(&emu.ppu.filtered_screen);
83+
}
84+
}
7885
}

tests/src/rng.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use crate::{util, labels};
2+
use std::collections::HashSet;
3+
4+
pub fn seeds() -> HashSet<u16> {
5+
let mut emu = util::emulator(None);
6+
let rng_seed = labels::get("rng_seed");
7+
let next_rng = labels::get("generateNextPseudorandomNumber");
8+
9+
let mut seeds: HashSet<u16> = HashSet::new();
10+
11+
let mut seed = 0x8988;
12+
13+
loop {
14+
seeds.insert(seed);
15+
16+
emu.memory.iram_raw[(rng_seed + 0) as usize] = (seed >> 8) as _;
17+
emu.memory.iram_raw[(rng_seed + 1) as usize] = seed as u8;
18+
19+
emu.registers.x = rng_seed as u8;
20+
emu.registers.y = 0x2;
21+
emu.registers.pc = next_rng;
22+
23+
util::run_to_return(&mut emu, false);
24+
25+
seed =
26+
((emu.memory.iram_raw[rng_seed as usize] as u16) << 8)
27+
+ emu.memory.iram_raw[(rng_seed + 1) as usize] as u16;
28+
29+
if seed == 0x8988 {
30+
break;
31+
}
32+
}
33+
34+
seeds
35+
}

tests/src/video.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use minifb::{Key, Window, WindowOptions};
1+
use minifb::{Window, WindowOptions};
22

33
const WIDTH: usize = 256;
44
const HEIGHT: usize = 240;

0 commit comments

Comments
 (0)