2023-04-23 16:58:57 +00:00
|
|
|
// (c) 2023 John A. Breaux
|
|
|
|
// This code is licensed under MIT license (see LICENSE for details)
|
|
|
|
// When compiled, the resulting binary is licensed under version 3 of the GNU General Public License (see chip8-test-suite/LICENSE for details)
|
|
|
|
|
2023-03-28 02:31:54 +00:00
|
|
|
//! These are a series of interpreter tests using Timendus's incredible test suite
|
|
|
|
|
2023-04-01 07:31:06 +00:00
|
|
|
pub use chirp::*;
|
2023-03-28 02:31:54 +00:00
|
|
|
|
|
|
|
fn setup_environment() -> (CPU, Bus) {
|
|
|
|
let mut cpu = CPU::default();
|
2023-04-15 02:25:41 +00:00
|
|
|
cpu.flags = Flags {
|
2023-03-28 02:31:54 +00:00
|
|
|
debug: true,
|
|
|
|
pause: false,
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
(
|
|
|
|
cpu,
|
|
|
|
bus! {
|
|
|
|
// Load the charset into ROM
|
|
|
|
Charset [0x0050..0x00A0] = include_bytes!("../src/mem/charset.bin"),
|
|
|
|
// Load the ROM file into RAM
|
2023-04-17 10:04:23 +00:00
|
|
|
Program [0x0200..0x1000],
|
|
|
|
// Create a screen, and fill it with garbage
|
2023-04-17 10:26:49 +00:00
|
|
|
Screen [0x0F00..0x1000] = b"jsuadhgufywegrwsdyfogbbg4owgbrt",
|
2023-03-28 02:31:54 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SuiteTest {
|
2023-04-17 10:04:23 +00:00
|
|
|
test: u8,
|
|
|
|
data: &'static [u8],
|
2023-03-28 02:31:54 +00:00
|
|
|
screen: &'static [u8],
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run_screentest(test: SuiteTest, mut cpu: CPU, mut bus: Bus) {
|
2023-04-02 19:46:39 +00:00
|
|
|
// Set the test to run
|
2023-04-17 10:04:23 +00:00
|
|
|
bus.write(0x1ffu16, test.test);
|
2023-04-23 17:10:02 +00:00
|
|
|
cpu.load_program_bytes(test.data).unwrap();
|
2023-03-28 02:31:54 +00:00
|
|
|
// The test suite always initiates a keypause on test completion
|
2023-04-23 17:10:02 +00:00
|
|
|
while !(cpu.flags.is_paused()) {
|
|
|
|
cpu.multistep(&mut bus, 10).unwrap();
|
2023-03-28 02:31:54 +00:00
|
|
|
}
|
|
|
|
// Compare the screen to the reference screen buffer
|
|
|
|
bus.print_screen().unwrap();
|
2023-04-17 10:04:23 +00:00
|
|
|
bus! {crate::cpu::bus::Region::Screen [0..256] = test.screen}
|
2023-03-28 02:31:54 +00:00
|
|
|
.print_screen()
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(bus.get_region(Screen).unwrap(), test.screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn splash_screen() {
|
2023-04-02 19:45:32 +00:00
|
|
|
let (cpu, bus) = setup_environment();
|
2023-03-28 02:31:54 +00:00
|
|
|
run_screentest(
|
|
|
|
SuiteTest {
|
2023-04-02 19:46:39 +00:00
|
|
|
test: 0,
|
2023-04-17 10:04:23 +00:00
|
|
|
data: include_bytes!("../chip8-test-suite/bin/1-chip8-logo.ch8"),
|
2023-03-28 02:31:54 +00:00
|
|
|
screen: include_bytes!("screens/chip8-test-suite/splash.bin"),
|
|
|
|
},
|
2023-04-02 19:45:32 +00:00
|
|
|
cpu,
|
|
|
|
bus,
|
2023-03-28 02:31:54 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ibm_logo() {
|
2023-04-02 19:46:39 +00:00
|
|
|
let (cpu, bus) = setup_environment();
|
2023-03-28 02:31:54 +00:00
|
|
|
run_screentest(
|
|
|
|
SuiteTest {
|
2023-04-17 10:04:23 +00:00
|
|
|
test: 0x00,
|
|
|
|
data: include_bytes!("../chip8-test-suite/bin/2-ibm-logo.ch8"),
|
2023-03-28 02:31:54 +00:00
|
|
|
screen: include_bytes!("screens/chip8-test-suite/IBM.bin"),
|
|
|
|
},
|
2023-04-01 05:15:40 +00:00
|
|
|
cpu,
|
|
|
|
bus,
|
2023-03-28 02:31:54 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-04-17 10:04:23 +00:00
|
|
|
#[test]
|
|
|
|
fn corax_test() {
|
|
|
|
let (cpu, bus) = setup_environment();
|
|
|
|
run_screentest(
|
|
|
|
SuiteTest {
|
|
|
|
test: 0x00,
|
|
|
|
data: include_bytes!("../chip8-test-suite/bin/3-corax+.ch8"),
|
|
|
|
screen: include_bytes!("screens/chip8-test-suite/corax+.bin"),
|
|
|
|
},
|
|
|
|
cpu,
|
|
|
|
bus,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-03-28 02:31:54 +00:00
|
|
|
#[test]
|
|
|
|
fn flags_test() {
|
2023-04-02 19:46:39 +00:00
|
|
|
let (cpu, bus) = setup_environment();
|
2023-03-28 02:31:54 +00:00
|
|
|
run_screentest(
|
|
|
|
SuiteTest {
|
2023-04-17 10:04:23 +00:00
|
|
|
test: 0x00,
|
|
|
|
data: include_bytes!("../chip8-test-suite/bin/4-flags.ch8"),
|
2023-03-28 02:31:54 +00:00
|
|
|
screen: include_bytes!("screens/chip8-test-suite/flags.bin"),
|
|
|
|
},
|
2023-04-01 05:15:40 +00:00
|
|
|
cpu,
|
|
|
|
bus,
|
2023-03-28 02:31:54 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn quirks_test() {
|
2023-04-02 19:46:39 +00:00
|
|
|
let (cpu, bus) = setup_environment();
|
2023-03-28 02:31:54 +00:00
|
|
|
run_screentest(
|
|
|
|
SuiteTest {
|
2023-04-17 10:04:23 +00:00
|
|
|
test: 0x01,
|
|
|
|
data: include_bytes!("../chip8-test-suite/bin/5-quirks.ch8"),
|
2023-03-28 02:31:54 +00:00
|
|
|
screen: include_bytes!("screens/chip8-test-suite/quirks.bin"),
|
|
|
|
},
|
2023-04-01 05:15:40 +00:00
|
|
|
cpu,
|
|
|
|
bus,
|
2023-03-28 02:31:54 +00:00
|
|
|
)
|
|
|
|
}
|