From b048caf359c2e0308cac6b8c68da86654de03e73 Mon Sep 17 00:00:00 2001 From: kn0000 Date: Sat, 31 May 2025 23:14:37 +0100 Subject: [PATCH] Small additions, as well as changing mem to buf to use a vec for avoiding a stack overflow This marks the first fully functioning version of the project --- src/lib.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1bd997e13bb1ec18005d891d141300d0ac5c2178..2921be25fcfb6a13fa4f28941de1bfefe737002d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,7 +73,7 @@ impl Processor { self.pc += 1; stack.push(self.memory[self.pc] & 0x3FF); } - 1 => { + 1 => { //push pc let upper = self.pc & 0b11111111110000000000 >> 10; let lower = self.pc & 0b1111111111; stack.push(upper as u16); @@ -106,6 +106,9 @@ impl Processor { stack.push(a); stack.push(b); } + 8 => self.carry = false, //clear/set carry + 9 => self.carry = true, + 10 => _ = stack.pop(), //drop value 0x7F => return false, _ => () } @@ -129,12 +132,10 @@ fn calc(stack: &mut Stack, instruction: u16, carry_in: bool) -> bool { carry } -pub fn mem_to_buf(memory: &[u16]) -> [u32;SCREEN_WIDTH*SCREEN_HEIGHT] { - let mut result = [0u32;SCREEN_WIDTH*SCREEN_HEIGHT]; - let mut i = 0; +pub fn mem_to_buf(memory: &[u16]) -> Vec { + let mut result = Vec::new(); for byte in &memory[(MEMORY_SIZE-SCREEN_WIDTH*SCREEN_HEIGHT)..MEMORY_SIZE] { - result[i] = (((byte & 0b111000000) as u32) << 15) | (((byte & 0b111000) as u32) << 10) | (((byte & 0b111) as u32) << 5); //shifts 3 bits of each 10 bit value into the rgb channels of the buffer, from the last region of memory - i += 1; + result.push((((byte & 0b111000000) as u32) << 15) | (((byte & 0b111000) as u32) << 10) | (((byte & 0b111) as u32) << 5)); //shifts 3 bits of each 10 bit value into the rgb channels of the buffer, from the last region of memory } result }