Skip to content

Commit fd70e4d

Browse files
Merge pull request #121 from zohassadar/crunch_test
crunch test
2 parents 3e93562 + bd5f801 commit fd70e4d

File tree

2 files changed

+218
-1
lines changed

2 files changed

+218
-1
lines changed

tests/src/crunch.rs

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
use rusticnes_core::nes::NesState;
2+
3+
use crate::{util, labels, playfield};
4+
5+
const CRUNCH_F: &str = r##"### ###
6+
### ###
7+
### ###
8+
### ###
9+
### ###
10+
### ###
11+
### ###
12+
### ###
13+
### ###
14+
### ###
15+
### ###
16+
### ###
17+
### ###
18+
### ###
19+
### ###
20+
### ###
21+
### ###
22+
### ###
23+
### ###
24+
### ###"##;
25+
26+
const CRUNCH_D: &str = r##"### #
27+
### #
28+
### #
29+
### #
30+
### #
31+
### #
32+
### #
33+
### #
34+
### #
35+
### #
36+
### #
37+
### #
38+
### #
39+
### #
40+
### #
41+
### #
42+
### #
43+
### #
44+
### #
45+
### #"##;
46+
47+
const CRUNCH_7: &str = r##"# ###
48+
# ###
49+
# ###
50+
# ###
51+
# ###
52+
# ###
53+
# ###
54+
# ###
55+
# ###
56+
# ###
57+
# ###
58+
# ###
59+
# ###
60+
# ###
61+
# ###
62+
# ###
63+
# ###
64+
# ###
65+
# ###
66+
# ###"##;
67+
68+
const CRUNCH_5: &str = r##"# #
69+
# #
70+
# #
71+
# #
72+
# #
73+
# #
74+
# #
75+
# #
76+
# #
77+
# #
78+
# #
79+
# #
80+
# #
81+
# #
82+
# #
83+
# #
84+
# #
85+
# #
86+
# #
87+
# #"##;
88+
89+
const CRUNCH_4: &str = r##"#
90+
#
91+
#
92+
#
93+
#
94+
#
95+
#
96+
#
97+
#
98+
#
99+
#
100+
#
101+
#
102+
#
103+
#
104+
#
105+
#
106+
#
107+
#
108+
#"##;
109+
110+
const CRUNCH_1: &str = r##" #
111+
#
112+
#
113+
#
114+
#
115+
#
116+
#
117+
#
118+
#
119+
#
120+
#
121+
#
122+
#
123+
#
124+
#
125+
#
126+
#
127+
#
128+
#
129+
#"##;
130+
131+
const CRUNCH_0: &str = r##"
132+
133+
134+
135+
136+
137+
138+
139+
140+
141+
142+
143+
144+
145+
146+
147+
148+
149+
150+
"##;
151+
152+
153+
pub fn test() {
154+
let mut emu = util::emulator(None);
155+
test_crunch(&mut emu, CRUNCH_0, 0x0);
156+
test_crunch(&mut emu, CRUNCH_1, 0x1);
157+
test_crunch(&mut emu, CRUNCH_4, 0x4);
158+
test_crunch(&mut emu, CRUNCH_5, 0x5);
159+
test_crunch(&mut emu, CRUNCH_7, 0x7);
160+
test_crunch(&mut emu, CRUNCH_D, 0xD);
161+
test_crunch(&mut emu, CRUNCH_F, 0xF);
162+
}
163+
164+
165+
fn test_crunch(emu: &mut NesState, expected_playfield: &str, crunch_setting: u8) {
166+
emu.reset();
167+
168+
for _ in 0..3 { emu.run_until_vblank(); }
169+
170+
let game_mode = labels::get("gameMode") as usize;
171+
let main_loop = labels::get("mainLoop");
172+
let level_number = labels::get("levelNumber") as usize;
173+
let practise_type = labels::get("practiseType") as usize;
174+
let mode_crunch = labels::get("MODE_CRUNCH") as u8;
175+
let crunch_modifier = labels::get("crunchModifier") as usize;
176+
let allegro = labels::get("allegro") as usize;
177+
let lines = labels::get("lines") as usize;
178+
179+
emu.memory.iram_raw[practise_type] = mode_crunch;
180+
emu.memory.iram_raw[level_number] = 0; // intentionally slow
181+
emu.memory.iram_raw[game_mode] = 4;
182+
emu.memory.iram_raw[crunch_modifier] = crunch_setting;
183+
emu.memory.iram_raw[lines] = 0;
184+
emu.registers.pc = main_loop;
185+
playfield::clear(emu);
186+
for _ in 0..9 { emu.run_until_vblank(); }
187+
188+
189+
// validate initialized
190+
assert_eq!(expected_playfield, playfield::get_str(emu));
191+
192+
emu.memory.iram_raw[labels::get("currentPiece") as usize] = 0x12;
193+
emu.memory.iram_raw[labels::get("tetriminoX") as usize] = 0x5;
194+
emu.memory.iram_raw[labels::get("tetriminoY") as usize] = 0x12;
195+
emu.memory.iram_raw[labels::get("autorepeatY") as usize] = 0;
196+
emu.memory.iram_raw[labels::get("vramRow") as usize] = 0;
197+
198+
// skip lock tetrimino and setup a tetris to be cleared
199+
emu.memory.iram_raw[labels::get("playState") as usize] = 3;
200+
for block in 0x4a0..0x4c8 {
201+
emu.memory.iram_raw[block as usize] = 0x7b;
202+
};
203+
204+
// cycle through remainder of entry delay and animation
205+
for _ in 0..32 {
206+
emu.run_until_vblank();
207+
}
208+
209+
// validate tetris was scored and playfield looks the same
210+
assert_eq!(emu.memory.iram_raw[lines], 4);
211+
assert_eq!(expected_playfield, playfield::get_str(emu));
212+
213+
// validate allegro not set
214+
assert_eq!(emu.memory.iram_raw[allegro], 0);
215+
}

tests/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod video;
88
mod cycle_count;
99
mod crash;
1010

11+
mod crunch;
1112
mod drought;
1213
mod floor;
1314
mod garbage;
@@ -55,7 +56,7 @@ struct TestOptions {
5556
fn main() {
5657
let options = TestOptions::parse_args_default_or_exit();
5758

58-
let tests: [(&str, fn()); 15] = [
59+
let tests: [(&str, fn()); 16] = [
5960
("garbage4", garbage::test_garbage4_crash),
6061
("floor", floor::test),
6162
("tspins", tspins::test),
@@ -71,6 +72,7 @@ fn main() {
7172
("nmi", nmi::test),
7273
("constants", constants::test),
7374
("patch", patch::test),
75+
("crunch", crunch::test),
7476
];
7577

7678
// run tests

0 commit comments

Comments
 (0)