This commit is contained in:
2024-03-03 14:12:54 +05:30
parent 1e8997d324
commit 049748b243
2 changed files with 27 additions and 27 deletions

View File

@@ -64,6 +64,7 @@ impl Device {
let instruction = Instruction::decode_instruction(instr_slice);
self.execute_instruction(instruction);
}
pub fn get_framebuffer_index(x:usize,y:usize)->usize{
y*Self::FRAME_BUFFER_WIDTH + x
@@ -80,9 +81,10 @@ impl Device {
for pixel in frame_buffer.iter_mut(){
*pixel = 0;
}
log::info!("ClearScreen")
log::trace!("ClearScreen")
}
Instruction::JumpTo(new_pc) => {
// hint that we're jumping back to self
self.registers.pc = new_pc;
}
Instruction::SetRegister(reg_location, value) => {
@@ -92,7 +94,6 @@ impl Device {
self.registers.v[reg_location] += value;
}
Instruction::SetIndex(value) => {
log::info!("Setting index to {}",value);
self.registers.i = value;
}
Instruction::Draw(regx,regy, n) => {
@@ -116,8 +117,7 @@ impl Device {
}
}
// TODO fix carry bit
log::info!("Drawing at ({},{}) for {} pixels from {}",x,y,n,self.registers.i);
log::warn!("Draw call unimplemented");
log::warn!("Draw call incomplete");
}
};
}

View File

@@ -31,8 +31,7 @@ fn main() {
let (sender, receiver) = std::sync::mpsc::channel();
let compute_handle = thread::spawn(move ||{
let compute_handle = thread::Builder::new().name("Compute".to_string()).spawn(move || {
let mut device = Device::new(timer, frame_buffer);
device.set_default_font();
{
@@ -48,8 +47,10 @@ fn main() {
panic!("Disconnected");
}
device.cycle();
// Put a bit of delay to slow down execution
thread::sleep(Duration::from_nanos(500))
}
});
}).expect("Failed to launch thread");
let (mut canvas, mut event_pump) = initiate_sdl(8f32);
let mut fb_sdl = vec![0; 3 * Device::FRAME_BUFFER_SIZE];
@@ -94,7 +95,6 @@ fn main() {
compute_handle.join().unwrap();
}
fn draw_screen(frame_buffer: MutexGuard<Box<[u8; 2048]>>, window_canvas: &mut WindowCanvas, x1: &mut Vec<u8>) {
@@ -118,12 +118,12 @@ fn get_frame_buffer() -> Arc<Mutex<Box<[u8; 2048]>>> {
}
const ROM_SIZE: usize = 4096 - 0x200;
fn load_rom() -> [u8; ROM_SIZE] {
let mut rom_slice = [0u8; ROM_SIZE];
let mut file = File::open("roms/ibm_logo.ch8").expect("could not open");
file.read(&mut rom_slice).expect("Unwrap");
rom_slice
}
fn initiate_sdl(draw_scale: f32) -> (WindowCanvas, EventPump) {