prep to add savestates

This commit is contained in:
2024-11-02 08:10:20 -04:00
parent 4e52b5b05a
commit 5663123f81
5 changed files with 565 additions and 541 deletions
+175 -81
View File
@@ -1,5 +1,3 @@
use log::debug;
use rand::random;
use gemma::chip8::computer::Chip8Computer;
use gemma::chip8::cpu_states::Chip8CpuStates::WaitingForInstruction;
use gemma::chip8::delay_timer::DelayTimer;
@@ -14,12 +12,13 @@ use gemma::chip8::system_memory::Chip8SystemMemory;
use gemma::chip8::util::InstructionUtil;
use gemma::chip8::video::{Chip8Video, Chip8VideoModes};
use gemma::constants::*;
use log::debug;
use rand::random;
const TEST_OUTPUT_SAMPLE_DIR: &str = "../resources/test/";
fn read_test_result(suffix: &str) -> String {
std::fs::read_to_string(TEST_OUTPUT_SAMPLE_DIR.to_owned() + suffix)
.unwrap()
std::fs::read_to_string(TEST_OUTPUT_SAMPLE_DIR.to_owned() + suffix).unwrap()
}
#[test]
@@ -27,18 +26,19 @@ fn smoke() {
assert!(true)
}
#[test]
fn decoder_test_invalid_instructions() {
let invalid_to_encode = [
0x5ab1, 0x5abf, 0x8ab8, 0x8abd, 0x8abf,
0x9ab1, 0x9abf, 0xea9d, 0xea9f, 0xeaa0,
0xeaa2, 0xf006, 0xf008
0x5ab1, 0x5abf, 0x8ab8, 0x8abd, 0x8abf, 0x9ab1, 0x9abf, 0xea9d, 0xea9f, 0xeaa0, 0xeaa2,
0xf006, 0xf008,
];
for i in invalid_to_encode {
assert_eq!(Chip8CpuInstructions::decode(i, &Chip8).encode(), 0xffff);
assert!(matches!(Chip8CpuInstructions::decode(i, &Chip8), Chip8CpuInstructions::XXXXERRORINSTRUCTION));
assert!(matches!(
Chip8CpuInstructions::decode(i, &Chip8),
Chip8CpuInstructions::XXXXERRORINSTRUCTION
));
}
}
@@ -109,7 +109,7 @@ fn instruction_tests() {
let mut x = Chip8Computer::new();
x.registers.poke(0x01, 0x01);
x.registers.poke(0x02, 0x02);
Chip8CpuInstructions::LDR_Y(0x01, 0x02).execute(&mut x);
Chip8CpuInstructions::LDRY(0x01, 0x02).execute(&mut x);
assert_eq!(x.registers.peek(1), 0x02);
// 0x8xy1 Set Vx = Vx OR Vy
@@ -172,7 +172,7 @@ fn instruction_tests() {
x.registers.poke(0x0f, 0x00);
x.registers.poke(0x01, 0b00001000);
x.registers.poke(0x02, 0b00000000);
Chip8CpuInstructions::SHR(0x1, 0x2).execute(&mut x); // 0b0000 0010 (0x02) (Not Set)
Chip8CpuInstructions::SHR(0x1, 0x2).execute(&mut x); // 0b0000 0010 (0x02) (Not Set)
assert_eq!(x.registers.peek(1), 0b00000100);
assert_eq!(x.registers.peek(0xf), 0);
@@ -520,8 +520,8 @@ fn draw_nibble_vx_vy_n_test_sd() {
for row_in_sprite in 0..5 {
let row_data = CHIP8FONT_2[row_in_sprite];
for bit_in_byte in 0..8 {
let data_offset = (x_offset
as u16 + row_in_sprite as u16) * 64 + (bit_in_byte + y_offset) as u16;
let data_offset =
(x_offset as u16 + row_in_sprite as u16) * 64 + (bit_in_byte + y_offset) as u16;
let real_bit_in_byte = 7 - bit_in_byte;
let shifted_one = 0x01 << real_bit_in_byte;
let one_shift_set = (shifted_one & row_data) > 0;
@@ -561,14 +561,16 @@ fn sub_test() {
assert_eq!(x.stack.depth(), 0);
}
#[test]
fn ldvxk_test() {
// SETUP
let mut x = Chip8Computer::new();
x.registers.poke(0x01, 0x01);
Chip8CpuInstructions::LDRK(0x1).execute(&mut x);
assert!(matches!(x.state, gemma::chip8::cpu_states::Chip8CpuStates::WaitingForKey));
assert!(matches!(
x.state,
gemma::chip8::cpu_states::Chip8CpuStates::WaitingForKey
));
}
#[test]
@@ -577,7 +579,6 @@ fn series8xy4_corex_tests() {
/// Set Vx = Vx + Vy
/// Set VF=1 if Carry
///
// 1 + 1
let mut x = Chip8Computer::new();
x.registers.poke(0x01, 0x01);
@@ -637,8 +638,14 @@ fn series8xy4_corex_tests() {
fn random_produces_different_numbers() {
let mut x = Chip8Computer::new();
x.registers.poke(0x01, 0x00);
let first_number = Chip8CpuInstructions::RND(0x01, 0xff).execute(&mut x).registers.peek(0x01);
let second_number = Chip8CpuInstructions::RND(0x01, 0xff).execute(&mut x).registers.peek(0x01);
let first_number = Chip8CpuInstructions::RND(0x01, 0xff)
.execute(&mut x)
.registers
.peek(0x01);
let second_number = Chip8CpuInstructions::RND(0x01, 0xff)
.execute(&mut x)
.registers
.peek(0x01);
assert_ne!(first_number, second_number);
}
@@ -679,13 +686,14 @@ fn keypad_keys_check() {
assert!(k.released(1));
}
#[test]
fn keypad_string_format_test() {
let k = Keypad::new();
assert_eq!(k.format_as_string(), read_test_result("gemma_keypad_string_result.asc"));
assert_eq!(
k.format_as_string(),
read_test_result("gemma_keypad_string_result.asc")
);
}
#[test]
@@ -786,10 +794,10 @@ fn stack_underflow_test() {
#[test]
fn stack_lots_of_subs() {
let mut x = Chip8Stack::new();
let stack_contents = [0x123, 0x321, 0xabc, 0xdef,
0xbad, 0xbef, 0xfed, 0xcab,
0xbed, 0xcad, 0xfeb, 0xcab,
0xfff, 0x000, 0x001];
let stack_contents = [
0x123, 0x321, 0xabc, 0xdef, 0xbad, 0xbef, 0xfed, 0xcab, 0xbed, 0xcad, 0xfeb, 0xcab, 0xfff,
0x000, 0x001,
];
for i in stack_contents {
x.push(&i);
}
@@ -814,7 +822,6 @@ fn stack_lots_of_subs() {
}
}
#[test]
fn video_split_bytes() {
// from 0xABCD we should have AB high, CD low
@@ -851,17 +858,40 @@ fn instruction_ubln() {
#[test]
fn instruction_byte_to_bool_changes() {
assert_eq!(InstructionUtil::byte_to_bools(0b00000000), [false, false, false, false, false, false, false, false]);
assert_eq!(InstructionUtil::byte_to_bools(0b11111111), [true, true, true, true, true, true, true, true]);
assert_eq!(InstructionUtil::byte_to_bools(0b11001100), [false, false, true, true, false, false, true, true]);
assert_eq!(InstructionUtil::byte_to_bools(0b11110000), [false, false, false, false, true, true, true, true]);
assert_eq!(InstructionUtil::bools_to_byte([false, false, false, false, false, false, false, false]), 0b00000000);
assert_eq!(InstructionUtil::bools_to_byte([true, true, true, true, true, true, true, true]), 0b11111111);
assert_eq!(InstructionUtil::bools_to_byte([false, false, true, true, false, false, true, true]), 0b11001100);
assert_eq!(InstructionUtil::bools_to_byte([false, false, false, false, true, true, true, true]), 0b11110000);
assert_eq!(
InstructionUtil::byte_to_bools(0b00000000),
[false, false, false, false, false, false, false, false]
);
assert_eq!(
InstructionUtil::byte_to_bools(0b11111111),
[true, true, true, true, true, true, true, true]
);
assert_eq!(
InstructionUtil::byte_to_bools(0b11001100),
[false, false, true, true, false, false, true, true]
);
assert_eq!(
InstructionUtil::byte_to_bools(0b11110000),
[false, false, false, false, true, true, true, true]
);
assert_eq!(
InstructionUtil::bools_to_byte([false, false, false, false, false, false, false, false]),
0b00000000
);
assert_eq!(
InstructionUtil::bools_to_byte([true, true, true, true, true, true, true, true]),
0b11111111
);
assert_eq!(
InstructionUtil::bools_to_byte([false, false, true, true, false, false, true, true]),
0b11001100
);
assert_eq!(
InstructionUtil::bools_to_byte([false, false, false, false, true, true, true, true]),
0b11110000
);
}
fn real_build_checkboard(in_hd: bool) -> Chip8Video {
let mut r = Chip8Video::default();
let (width, height) = if in_hd {
@@ -943,10 +973,7 @@ fn video_poke_byte_test() {
#[test]
fn video_poke_2byte_test() {
let to_poke: [u8; 2] = [
0b11001111,
0b00111100
];
let to_poke: [u8; 2] = [0b11001111, 0b00111100];
let mut x = Chip8Video::default();
x.poke_2byte(0x00, to_poke);
@@ -1002,12 +1029,7 @@ fn video_poke_byte_test_2() {
#[test]
fn video_poke_multi_line_test() {
let mut v = Chip8Video::default();
let to_poke = [
0b00000000,
0b11111111,
0b10101010,
0b01010101
];
let to_poke = [0b00000000, 0b11111111, 0b10101010, 0b01010101];
for (byte_in_set, byte_to_poke) in to_poke.iter().enumerate() {
let base_offset = byte_in_set * 64;
@@ -1040,17 +1062,11 @@ fn video_poke_multi_line_test() {
#[test]
fn video_moved_poke_test() {
let mut v = Chip8Video::default();
let to_poke = [
0b00000000,
0b11111111,
0b10101010,
0b01010101
];
let to_poke = [0b00000000, 0b11111111, 0b10101010, 0b01010101];
let x_offset = 20;
let y_offset = 5;
for (byte_in_set, byte_to_poke) in to_poke.iter().enumerate() {
let base_offset = (x_offset + byte_in_set) * 64 + y_offset;
v.poke_byte(base_offset as u16, *byte_to_poke);
@@ -1091,7 +1107,10 @@ fn video_verify_change_registered() {
#[test]
fn video_write_checkboard() {
let v = build_checkerboard();
assert_eq!(v.clone().format_as_string(), read_test_result("test_video_write_checkerboard.asc"));
assert_eq!(
v.clone().format_as_string(),
read_test_result("test_video_write_checkerboard.asc")
);
}
#[test]
@@ -1102,14 +1121,26 @@ fn video_zero_test() {
x.poke_byte(data_offset as u16, CHIP8FONT_0[byte_index]);
}
assert_eq!(read_test_result("test_video_zero.asc"), x.format_as_string());
assert_eq!(
read_test_result("test_video_zero.asc"),
x.format_as_string()
);
}
#[test]
fn video_multi_sprite_test() {
let mut x = Chip8Video::default();
// draw a row of digits 01234567
let to_draw = [CHIP8FONT_0, CHIP8FONT_1, CHIP8FONT_2, CHIP8FONT_3, CHIP8FONT_4, CHIP8FONT_5, CHIP8FONT_6, CHIP8FONT_7];
let to_draw = [
CHIP8FONT_0,
CHIP8FONT_1,
CHIP8FONT_2,
CHIP8FONT_3,
CHIP8FONT_4,
CHIP8FONT_5,
CHIP8FONT_6,
CHIP8FONT_7,
];
for (index, sprite) in to_draw.iter().enumerate() {
let data_base_offset = index * 0x8;
for (index, offset) in (0..=0x100).step_by(0x40).enumerate() {
@@ -1117,14 +1148,20 @@ fn video_multi_sprite_test() {
}
}
assert_eq!(read_test_result("test_multi_sprite.asc"), x.format_as_string());
assert_eq!(
read_test_result("test_multi_sprite.asc"),
x.format_as_string()
);
}
#[test]
fn video_reset_test() {
let mut x = build_checkerboard();
x.reset();
assert_eq!(x.format_as_string(), read_test_result("test_reset_clears_video.asc"));
assert_eq!(
x.format_as_string(),
read_test_result("test_reset_clears_video.asc")
);
}
#[test]
@@ -1157,6 +1194,15 @@ fn video_collision_test2() {
assert!(x.has_frame_changed);
}
#[test]
fn video_collision_test3() {
// draw a couple sprites that do not overlap.
// goal being drawing without triggering the collision
// detection.
let mut x = Chip8Video::default();
x.poke_byte(0x00, 0b11110000);
}
#[test]
fn video_peek_out_of_bounds_doesnt_panic() {
let x = Chip8Video::default();
@@ -1172,21 +1218,30 @@ fn video_peek_out_of_bounds_doesnt_panic() {
fn video_scroll_down_1_row_test() {
let mut x = build_checkerboard();
x.scroll_down(1);
assert_eq!(read_test_result("test_video_scroll_down_1.asc"), x.format_as_string());
assert_eq!(
read_test_result("test_video_scroll_down_1.asc"),
x.format_as_string()
);
}
#[test]
fn video_scroll_down_10_row_test() {
let mut x = build_checkerboard();
x.scroll_down(10);
assert_eq!(read_test_result("test_video_scroll_down_10.asc"), x.format_as_string());
assert_eq!(
read_test_result("test_video_scroll_down_10.asc"),
x.format_as_string()
);
}
#[test]
fn video_high_res_has_right_resolution() {
let x = build_checkboard_hd();
println!("[{}]", x.format_as_string());
assert_eq!(read_test_result("test_video_highdef.asc"), x.format_as_string());
assert_eq!(
read_test_result("test_video_highdef.asc"),
x.format_as_string()
);
}
#[test]
@@ -1197,45 +1252,62 @@ fn video_scroll_down_1_row_test_schip() {
println!("[{}]", x.format_as_string());
println!("[{}]", read_test_result("test_scroll_down_1_hd.asc"));
assert_eq!(read_test_result("test_scroll_down_1_hd.asc"), x.format_as_string());
assert_eq!(
read_test_result("test_scroll_down_1_hd.asc"),
x.format_as_string()
);
}
#[test]
fn video_scroll_down_10_row_test_schip() {
let mut x = build_checkboard_hd();
x.scroll_down(10);
assert_eq!(read_test_result("test_scroll_down_10_hd.asc"), x.format_as_string());
assert_eq!(
read_test_result("test_scroll_down_10_hd.asc"),
x.format_as_string()
);
}
#[test]
fn video_scroll_left_4_row_test_std_def() {
let mut x = build_checkerboard();
x.scroll_left();
assert_eq!(read_test_result("test_scroll_left_4.asc"), x.format_as_string());
assert_eq!(
read_test_result("test_scroll_left_4.asc"),
x.format_as_string()
);
}
#[test]
fn video_scroll_left_4_row_test_high_def() {
let mut x = build_checkboard_hd();
x.scroll_left();
assert_eq!(read_test_result("test_scroll_left_4_hd.asc"), x.format_as_string());
assert_eq!(
read_test_result("test_scroll_left_4_hd.asc"),
x.format_as_string()
);
}
#[test]
fn video_scroll_right_4_row_test_std_def() {
let mut x = build_checkerboard();
x.scroll_right();
assert_eq!(read_test_result("test_scroll_right_4.asc"), x.format_as_string());
assert_eq!(
read_test_result("test_scroll_right_4.asc"),
x.format_as_string()
);
}
#[test]
fn video_scroll_right_4_row_test_high_def() {
let mut x = build_checkboard_hd();
x.scroll_right();
assert_eq!(read_test_result("test_scroll_right_4_hd.asc"), x.format_as_string());
assert_eq!(
read_test_result("test_scroll_right_4_hd.asc"),
x.format_as_string()
);
}
#[test]
fn instructions_operands_tests() {
assert_eq!(Chip8CpuInstructions::SYS(0x000).operands(), "0x0000");
@@ -1267,26 +1339,38 @@ fn instruction_test_scrolling_lowres() {
x.video_memory = build_checkerboard();
x.quirk_mode = quirk.clone();
Chip8CpuInstructions::SCR.execute(&mut x);
assert_eq!(read_test_result("test_scroll_right_4.asc"), x.dump_video_to_string());
assert_eq!(
read_test_result("test_scroll_right_4.asc"),
x.dump_video_to_string()
);
x = Chip8Computer::new();
x.video_memory = build_checkerboard();
x.quirk_mode = quirk.clone();
Chip8CpuInstructions::SCL.execute(&mut x);
assert_eq!(read_test_result("test_scroll_left_4.asc"), x.dump_video_to_string());
assert_eq!(
read_test_result("test_scroll_left_4.asc"),
x.dump_video_to_string()
);
x = Chip8Computer::new();
x.video_memory = build_checkerboard();
x.quirk_mode = quirk.clone();
Chip8CpuInstructions::SCD(0x01).execute(&mut x);
assert_eq!(read_test_result("test_video_scroll_down_1.asc"), x.dump_video_to_string());
assert_eq!(
read_test_result("test_video_scroll_down_1.asc"),
x.dump_video_to_string()
);
x = Chip8Computer::new();
x.video_memory = build_checkerboard();
x.quirk_mode = quirk.clone();
Chip8CpuInstructions::SCD(0xA).execute(&mut x);
assert_eq!(read_test_result("test_video_scroll_down_10.asc"), x.dump_video_to_string());
assert_eq!(
read_test_result("test_video_scroll_down_10.asc"),
x.dump_video_to_string()
);
}
}
@@ -1295,17 +1379,18 @@ fn computer_dump_keypad_to_string() {
let mut x = Chip8Computer::new();
x.keypad.push_key(0x1);
x.keypad.push_key(0x2);
assert_eq!(read_test_result("test_keypad_to_string.asc"), x.dump_keypad_to_string());
assert_eq!(
read_test_result("test_keypad_to_string.asc"),
x.dump_keypad_to_string()
);
}
#[test]
fn computer_dump_registers_to_string() {
let mut x = Chip8Computer::new();
let values_to_set = [0x0b, 0xad, 0xbe, 0xef,
0xca, 0xb0,
0x7a, 0xc0, 0xca, 0x70,
0xba, 0xdb, 0xed, 0x00,
0x00, 0x00
let values_to_set = [
0x0b, 0xad, 0xbe, 0xef, 0xca, 0xb0, 0x7a, 0xc0, 0xca, 0x70, 0xba, 0xdb, 0xed, 0x00, 0x00,
0x00,
];
let expected_value = "Vx: 0x0b 0xad 0xbe 0xef 0xca 0xb0 0x7a 0xc0\n 0xca 0x70 0xba 0xdb 0xed 0x00 0x00 0x00\nI: 0x0000\tPC: 0x0200";
@@ -1322,7 +1407,10 @@ fn video_scroll_up_tests_sd() {
let mut x = build_checkerboard();
let distance = 1u8;
x.scroll_up(&distance);
assert_eq!(read_test_result("test_video_scroll_up_test_sd.asc"), x.format_as_string());
assert_eq!(
read_test_result("test_video_scroll_up_test_sd.asc"),
x.format_as_string()
);
}
#[test]
@@ -1330,7 +1418,10 @@ fn video_scroll_up_tests_hd() {
let mut x = build_checkboard_hd();
let distance = 1u8;
x.scroll_up(&distance);
assert_eq!(read_test_result("test_video_scroll_up_test_hd.asc"), x.format_as_string());
assert_eq!(
read_test_result("test_video_scroll_up_test_hd.asc"),
x.format_as_string()
);
}
#[test]
@@ -1339,7 +1430,10 @@ fn video_resolution_changing() {
x.set_highres();
assert_eq!(x.get_resolution(), (SCHIP_VIDEO_WIDTH, SCHIP_VIDEO_HEIGHT));
assert!(matches!(x.get_screen_resolution(), Chip8VideoModes::HighRes));
assert!(matches!(
x.get_screen_resolution(),
Chip8VideoModes::HighRes
));
x.set_lowres();
assert_eq!(x.get_resolution(), (CHIP8_VIDEO_WIDTH, CHIP8_VIDEO_HEIGHT));
assert!(matches!(x.get_screen_resolution(), Chip8VideoModes::LowRes));
@@ -1402,4 +1496,4 @@ fn sound_timer_default() {
fn system_memory_new() {
let x = Chip8SystemMemory::new();
assert!(true);
}
}
+72 -63
View File
@@ -33,7 +33,7 @@ fn instructions_encode_decode_tests_with_quirks() {
chip8: SYS(0x123),
schip: XXXXERRORINSTRUCTION,
xochip: XXXXERRORINSTRUCTION,
}
},
},
InstructionTest {
name: INST_CLS.to_string(),
@@ -44,8 +44,8 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: CLS,
schip: CLS,
xochip: CLS
}
xochip: CLS,
},
},
InstructionTest {
name: INST_RET.to_string(),
@@ -56,8 +56,8 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: RET,
schip: RET,
xochip: RET
}
xochip: RET,
},
},
InstructionTest {
name: INST_JPX.to_string(),
@@ -81,7 +81,7 @@ fn instructions_encode_decode_tests_with_quirks() {
chip8: CALL(0x123),
schip: CALL(0x123),
xochip: CALL(0x123),
}
},
},
InstructionTest {
name: INST_DRW.to_string(),
@@ -92,8 +92,8 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: DRW(0x1, 0x2, 0x3),
schip: DRW(0x1, 0x2, 0x3),
xochip: DRW(0x1, 0x2, 0x3)
}
xochip: DRW(0x1, 0x2, 0x3),
},
},
InstructionTest {
name: INST_JPI.to_string(),
@@ -104,8 +104,8 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: JPI(0x321),
schip: XXXXERRORINSTRUCTION,
xochip: JPI(0x321)
}
xochip: JPI(0x321),
},
},
InstructionTest {
name: INST_SCD.to_string(),
@@ -116,8 +116,8 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: XXXXERRORINSTRUCTION,
schip: SCD(0x1),
xochip: SCD(0x1)
}
xochip: SCD(0x1),
},
},
InstructionTest {
name: INST_SCR.to_string(),
@@ -128,8 +128,8 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: XXXXERRORINSTRUCTION,
schip: SCR,
xochip: SCR
}
xochip: SCR,
},
},
InstructionTest {
name: INST_SCL.to_string(),
@@ -140,8 +140,8 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: XXXXERRORINSTRUCTION,
schip: SCL,
xochip: SCL
}
xochip: SCL,
},
},
InstructionTest {
name: INST_EXIT.to_string(),
@@ -152,8 +152,8 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: XXXXERRORINSTRUCTION,
schip: EXIT,
xochip: EXIT
}
xochip: EXIT,
},
},
InstructionTest {
name: INST_LOW.to_string(),
@@ -165,7 +165,7 @@ fn instructions_encode_decode_tests_with_quirks() {
chip8: XXXXERRORINSTRUCTION,
schip: LOW,
xochip: LOW,
}
},
},
InstructionTest {
name: INST_HIGH.to_string(),
@@ -176,8 +176,8 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: XXXXERRORINSTRUCTION,
schip: HIGH,
xochip: HIGH
}
xochip: HIGH,
},
},
InstructionTest {
name: INST_SEX.to_string(),
@@ -188,7 +188,7 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: Chip8CpuInstructions::SEX(0x1, 0xfa),
schip: Chip8CpuInstructions::SEX(0x1, 0xfa),
xochip: Chip8CpuInstructions::SEX(0x1, 0xfa)
xochip: Chip8CpuInstructions::SEX(0x1, 0xfa),
},
},
InstructionTest {
@@ -212,8 +212,8 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: SEY(0x1, 0x2),
schip: SEY(0x1, 0x2),
xochip: SEY(0x1, 0x2)
}
xochip: SEY(0x1, 0x2),
},
},
InstructionTest {
name: INST_LDR.to_string(),
@@ -224,7 +224,7 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: LDR(0xa, 0xbe),
schip: LDR(0xa, 0xbe),
xochip: LDR(0xa, 0xbe)
xochip: LDR(0xa, 0xbe),
},
},
InstructionTest {
@@ -284,7 +284,7 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: XXXXERRORINSTRUCTION,
schip: XXXXERRORINSTRUCTION,
xochip: SCU(0x04)
xochip: SCU(0x04),
},
},
InstructionTest {
@@ -297,7 +297,7 @@ fn instructions_encode_decode_tests_with_quirks() {
chip8: ADDR(0x01, 0x02),
schip: ADDR(0x01, 0x02),
xochip: ADDR(0x01, 0x02),
}
},
},
InstructionTest {
name: INST_AND.to_string(),
@@ -333,8 +333,8 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: BCD(0xcd),
schip: BCD(0xcd),
xochip: BCD(0xcd)
}
xochip: BCD(0xcd),
},
},
InstructionTest {
name: INST_LDD.to_string(),
@@ -346,7 +346,7 @@ fn instructions_encode_decode_tests_with_quirks() {
chip8: LDD(0xfc),
schip: LDD(0xfc),
xochip: LDD(0xfc),
}
},
},
InstructionTest {
name: INST_ORY.to_string(),
@@ -417,9 +417,10 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: SHR(0x04, 0x4),
schip: SHR(0x04, 0x4),
xochip: SHR(0x04, 0x4)
}
}, InstructionTest {
xochip: SHR(0x04, 0x4),
},
},
InstructionTest {
name: INST_SHL.to_string(),
instruction: SHL(0x04, 0x4),
operands: "0x4, 0x4".to_string(),
@@ -428,8 +429,8 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: SHL(0x04, 0x4),
schip: SHL(0x04, 0x4),
xochip: SHL(0x04, 0x4)
}
xochip: SHL(0x04, 0x4),
},
},
InstructionTest {
name: INST_RND.to_string(),
@@ -441,19 +442,19 @@ fn instructions_encode_decode_tests_with_quirks() {
chip8: RND(0x01, 0xff),
schip: RND(0x01, 0xff),
xochip: RND(0x01, 0xff),
}
},
},
InstructionTest {
name: INST_LDRY.to_string(),
instruction: LDR_Y(0x01, 0x02),
instruction: LDRY(0x01, 0x02),
operands: "0x1, 0x2".to_string(),
asm: "LDRY 0x1, 0x2".to_string(),
encoded: 0x8120,
quirks: InstructionTestQuirks {
chip8: LDR_Y(0x01, 0x02),
schip: LDR_Y(0x01, 0x02),
xochip: LDR_Y(0x01, 0x02)
}
chip8: LDRY(0x01, 0x02),
schip: LDRY(0x01, 0x02),
xochip: LDRY(0x01, 0x02),
},
},
InstructionTest {
name: INST_LDIS.to_string(),
@@ -465,7 +466,7 @@ fn instructions_encode_decode_tests_with_quirks() {
chip8: LDIS(0x01),
schip: LDIS(0x01),
xochip: LDIS(0x01),
}
},
},
InstructionTest {
name: INST_LIDR.to_string(),
@@ -477,7 +478,7 @@ fn instructions_encode_decode_tests_with_quirks() {
chip8: XXXXERRORINSTRUCTION,
schip: LIDR(0x01),
xochip: LIDR(0x01),
}
},
},
InstructionTest {
name: INST_LDF2.to_string(),
@@ -488,8 +489,8 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: XXXXERRORINSTRUCTION,
schip: LDF2(0x01),
xochip: LDF2(0x01)
}
xochip: LDF2(0x01),
},
},
InstructionTest {
name: INST_LDF.to_string(),
@@ -500,8 +501,8 @@ fn instructions_encode_decode_tests_with_quirks() {
quirks: InstructionTestQuirks {
chip8: LDFX(0x01),
schip: LDFX(0x01),
xochip: LDFX(0x01)
}
xochip: LDFX(0x01),
},
},
InstructionTest {
name: INST_LDIA.to_string(),
@@ -513,7 +514,7 @@ fn instructions_encode_decode_tests_with_quirks() {
chip8: LDIA(0x01),
schip: LDIA(0x01),
xochip: LDIA(0x01),
}
},
},
InstructionTest {
name: INST_LDIX.to_string(),
@@ -525,7 +526,7 @@ fn instructions_encode_decode_tests_with_quirks() {
chip8: LDIX(0x01),
schip: LDIX(0x01),
xochip: LDIX(0x01),
}
},
},
InstructionTest {
name: INST_LDRD.to_string(),
@@ -558,10 +559,10 @@ fn instructions_encode_decode_tests_with_quirks() {
asm: "SKP 0x01".to_string(),
encoded: 0xe19e,
quirks: InstructionTestQuirks {
chip8: SKP(0x01),
schip: SKP(0x01),
xochip: SKP(0x01),
}
chip8: SKP(0x01),
schip: SKP(0x01),
xochip: SKP(0x01),
},
},
InstructionTest {
name: INST_SNEY.to_string(),
@@ -570,10 +571,10 @@ fn instructions_encode_decode_tests_with_quirks() {
asm: "SNEY 0x1, 0x1".to_string(),
encoded: 0x9110,
quirks: InstructionTestQuirks {
chip8: SNEY(0x01, 0x1),
schip: SNEY(0x01, 0x1),
xochip: SNEY(0x01, 0x1),
}
chip8: SNEY(0x01, 0x1),
schip: SNEY(0x01, 0x1),
xochip: SNEY(0x01, 0x1),
},
},
InstructionTest {
name: INST_SKNP.to_string(),
@@ -582,10 +583,10 @@ fn instructions_encode_decode_tests_with_quirks() {
asm: "SKNP 0x01".to_string(),
encoded: 0xe1a1,
quirks: InstructionTestQuirks {
chip8: SKNP(0x01),
schip: SKNP(0x01),
xochip: SKNP(0x01),
}
chip8: SKNP(0x01),
schip: SKNP(0x01),
xochip: SKNP(0x01),
},
},
];
@@ -601,9 +602,17 @@ fn instructions_encode_decode_tests_with_quirks() {
// ** CONVERSION **
// -> Integer to Instruction
assert!(matches!(Chip8CpuInstructions::decode(current.encoded, &Chip8), i));
assert!(matches!(
Chip8CpuInstructions::decode(current.encoded, &Chip8),
i
));
// -> Instruction to Integer
println!("TESTING INSTRUCTION TO INTEGER FOR {:?} / {:04x} {:04x}", current.instruction, current.encoded, instruction.encode());
println!(
"TESTING INSTRUCTION TO INTEGER FOR {:?} / {:04x} {:04x}",
current.instruction,
current.encoded,
instruction.encode()
);
assert_eq!(current.encoded, instruction.encode());
// -> Instruction to String
assert_eq!(instruction.to_string(), current.asm);