mod screen; pub mod system; use std::{ops::DerefMut, sync::Arc}; pub(crate) use screen::Screen; pub(crate) use system::{Ppu, SystemHandle}; pub use system::{CtlMsg, GfxMsg, Handle, System}; use crate::screen::greay32; fn main() { let (mut sys, handle) = System::new(); sys.initialize_screen(); let main = std::thread::spawn(|| mainloop(handle)); sys.run(); main.join().unwrap(); } fn mainloop(handle: Handle) { let mut frames = 0; { let ppu = handle.ppu(); let mut background_palette = ppu.palette(0); let mut background_tilemap = ppu.tilemap(0); for (idx, tile) in background_tilemap.deref_mut().iter_mut().enumerate() { println!("Tile {idx}"); background_palette.deref_mut()[idx % 256] = greay32((idx % 256) as u8); tile.fill(idx as u8); } ppu.background().as_mut()[25] = 25; } loop { print!("LOOP "); for back in handle.ppu().background().iter().take(8) { print!("{back:02X} "); } println!(""); handle.wait_vblank(); println!("Frame {frames} PPU={:?}", Arc::as_ptr(&handle.ppu())); let background_len = handle.ppu().background().len(); handle.ppu().background().as_mut()[frames % background_len] = (frames % 256) as u8; println!( "background[{}] is {} (prev is {})", frames % background_len, handle.ppu().background()[frames % background_len], handle.ppu().background()[(frames.saturating_sub(1)) % background_len] ); handle.ppu().print_background(); frames += 1; } }