//! Show a tools/mosaic.py .cells file on the attract title screen: run the //! board to its title screen, clear the mosaic's rows, write the cells into //! tile RAM, render (stars off) and save the frame. Usage: //! galaga-mosaic-show CELLS TOP ROWS OUT.ppm use emu_galaga::galaga::roms::load_directory; use emu_galaga::galaga::video::Video; use emu_galaga::galaga::Machine; fn main() { let a: Vec = std::env::args().collect(); let cells: Vec<[usize; 4]> = std::fs::read_to_string(&a[1]) .unwrap() .lines() .map(|l| { let v: Vec = l.split_whitespace().map(|x| x.parse().unwrap()).collect(); [v[0], v[1], v[2], v[3]] }) .collect(); let (top, rows): (usize, usize) = (a[2].parse().unwrap(), a[3].parse().unwrap()); let roms = load_directory(std::path::Path::new("rom/galaga")).unwrap(); let mut m = Machine::new(&roms); for _ in 0..1350 { m.run_frame(); } { let mut s = m.shared.borrow_mut(); // Clear the mosaic's rows, then draw it. for row in top..top + rows { for col in 0..28 { let i = (row - 2) + 32 * (27 - col + 2); s.video_ram[i] = 0x24; } } for &[row, col, code, colour] in &cells { let i = (row - 2) + 32 * (27 - col + 2); s.video_ram[i] = code as u8; s.video_ram[0x400 + i] = colour as u8; } s.videolatch &= !0x20; // stars off, for the comparison } let mut v = Video::new(&roms); v.render(&m.shared.borrow(), m.videolatch_at_vblank_end & !0x20); let mut buf = vec![0u8; 224 * 288 * 4]; v.screen_rgba(&mut buf); let mut ppm = b"P6 224 288 255\n".to_vec(); for px in buf.chunks(4) { ppm.extend_from_slice(&px[..3]); } std::fs::write(&a[4], ppm).unwrap(); }