diff --git a/frontends/sdl/res/test/blargg/instr_timing/instr_timing.png b/frontends/sdl/res/test/blargg/instr_timing/instr_timing.png new file mode 100644 index 0000000000000000000000000000000000000000..2f56cb91ba13f74eaee3010fa3f7fda7945276f0 Binary files /dev/null and b/frontends/sdl/res/test/blargg/instr_timing/instr_timing.png differ diff --git a/frontends/sdl/src/test.rs b/frontends/sdl/src/test.rs index 7fa014f81ad9c1f2ce1eb6f7407d0bd5848157a4..4d02cbc2be18e3eeedd808449bf6f4380a99c67f 100644 --- a/frontends/sdl/src/test.rs +++ b/frontends/sdl/src/test.rs @@ -1,4 +1,4 @@ -use image::io::Reader as ImageReader; +use image::{io::Reader as ImageReader, ImageBuffer, Rgb}; pub fn compare_images(source_pixels: &[u8], target_path: &str) -> bool { let image_buffer = ImageReader::open(target_path) @@ -23,6 +23,19 @@ pub fn compare_images(source_pixels: &[u8], target_path: &str) -> bool { true } +pub fn save_image(pixels: &[u8], width: u32, height: u32, file_path: &str) { + let mut image_buffer: ImageBuffer<Rgb<u8>, Vec<u8>> = ImageBuffer::new(width, height); + + for (x, y, pixel) in image_buffer.enumerate_pixels_mut() { + let base = ((y * width + x) * 3) as usize; + *pixel = Rgb([pixels[base], pixels[base + 1], pixels[base + 2]]); + } + + image_buffer + .save_with_format(file_path, image::ImageFormat::Png) + .unwrap(); +} + #[cfg(test)] mod tests { use boytacean::{ @@ -31,7 +44,7 @@ mod tests { test::{run_image_test, TestOptions}, }; - use super::compare_images; + use super::{compare_images, save_image}; #[test] fn test_blargg_cpu_instrs() { @@ -44,6 +57,18 @@ mod tests { assert_eq!(image_result, true); } + #[test] + fn test_blargg_instr_timing() { + let result: [u8; FRAME_BUFFER_SIZE] = run_image_test( + "../../res/roms/test/blargg/instr_timing/instr_timing.gb", + Some(50000000), + TestOptions::default(), + ); + compare_images(&result, "res/test/blargg/instr_timing/instr_timing.png"); + let image_result = compare_images(&result, "res/test/blargg/instr_timing/instr_timing.png"); + assert_eq!(image_result, true); + } + #[test] fn test_dmg_acid2() { let result: [u8; FRAME_BUFFER_SIZE] = run_image_test(