fixes reset from exection completion

adds 'default.oc8'
adds control window size to state for load/save of settings maybe?
moves TestCompressionTool code into InstructionUtil
remove gemmautil and moves into gemma
This commit is contained in:
2024-11-08 09:42:28 -05:00
parent 67ca71ccb7
commit cddbe0c46e
41 changed files with 464 additions and 310 deletions
View File
+18 -20
View File
@@ -1,26 +1,24 @@
use std::fs::File;
use flate2::write::{GzDecoder, GzEncoder};
use flate2::Compression;
use gemma::chip8::computer::Chip8Computer;
use gemma::chip8::util::InstructionUtil;
use std::io;
use std::io::prelude::*;
fn load_result(to_load: &str) -> String {
let full_path = format!("resources/test/state/{}", to_load);
let full_path = format!("../resources/test/state/{}", to_load);
println!("Loading state => (([{}]))", full_path);
std::fs::read_to_string(full_path).unwrap()
}
fn load_compressed_result(file_path: &str) -> io::Result<String> {
// Load the compressed file contents
let compressed_data = fs::read(file_path)?;
// Create a GzDecoder to uncompress the data
let mut decoder = GzDecoder::new(&compressed_data[..]);
let mut decompressed_data = String::new();
// Read the decompressed data directly into a String
decoder.read_to_string(&mut decompressed_data)?;
Ok(decompressed_data)
let full_path = format!("../resources/test/state/{}", file_path);
println!(
"ATTEMPTING TO LOAD {} AS A COMPRESSED TEST RESULT.",
full_path
);
InstructionUtil::decompress_file_to_string(full_path)
}
fn load_rom(to_load: &str) -> Vec<u8> {
@@ -33,21 +31,21 @@ fn test_serialization_round_trip() {
let expected_json = load_result("smoke_001_round_trip_serialize_deserialize.json");
// Serialize the Chip8Computer instance
let serialized = serde_json::to_string(&original_computer).expect("Serialization failed");
let serialized = Chip8Computer::serialize(&original_computer);
let deserialized = Chip8Computer::deserialize(expected_json.clone());
// Compare the serialized output to the expected JSON
println!("Serialized Output: [{}]", serialized);
assert_eq!(
serialized.trim(),
expected_json.trim(),
expected_json.clone().trim(),
"Serialized output does not match expected JSON"
);
// Deserialize back to Chip8Computer and assert equality
let deserialized_computer: Chip8Computer =
serde_json::from_str(&serialized).expect("Deserialization failed");
assert_eq!(
deserialized_computer, original_computer,
deserialized, original_computer,
"Deserialized instance does not match the original"
);
}
@@ -55,9 +53,9 @@ fn test_serialization_round_trip() {
#[test]
fn computer_001_system_zero_state() {
let x = Chip8Computer::new();
let expected_string = load_compressed_result("smoke_002_round_trip_serialize_deserialize.tflt");
let serialized = serde_json::to_string(&x).unwrap();
let expected_string = load_compressed_result("computer_001_system_zero_state.tct")
.expect("Unable to read result");
let serialized = x.serialize();
assert_eq!(serialized, expected_string);
}
}
@@ -35,11 +35,13 @@ fn decoder_test_invalid_instructions() {
];
for i in invalid_to_encode {
assert_eq!(Chip8CpuInstructions::decode(i, &Chip8).encode(), 0xffff);
println!("TESTING 0x{i:04x}");
println!("DECOODED TO {:?}", Chip8CpuInstructions::decode(i, &Chip8));
assert!(matches!(
Chip8CpuInstructions::decode(i, &Chip8),
Chip8CpuInstructions::XXXXERRORINSTRUCTION
));
Chip8CpuInstructions::DW(i)
) ||
matches!(Chip8CpuInstructions::decode(i, &Chip8), Chip8CpuInstructions::XXXXERRORINSTRUCTION));
}
}