~maddie/STT-implementation

bd62c0375bbf0397295668f165bcf7c25c190360 — kn0000 20 days ago 465460b master
Implement the run loop and display, untested for now
2 files changed, 28 insertions(+), 8 deletions(-)

M src/lib.rs
M src/main.rs
M src/lib.rs => src/lib.rs +8 -6
@@ 1,13 1,13 @@
struct Processor {
    stack_a: Vec<u16>,
    stack_b: Vec<u16>,
pub struct Processor {
    pub stack_a: Vec<u16>,
    pub stack_b: Vec<u16>,
    pub memory: [u16;0xFFFFF],
    carry: bool,
    pub carry: bool,
    pub pc: u16 //program counter
}

impl Processor {
    pub fn run(&mut self) {
    pub fn run(&mut self) -> bool {
        let instruction = self.memory[self.pc as usize];
        let mut is_jump = false;
        match instruction & 0x300 {


@@ 77,6 77,7 @@ impl Processor {
                        6 => { //set/clear carry
                            self.carry = toggle;
                        }
                        0x3F => return false,
                        _ => ()
                    }
                }


@@ 84,6 85,7 @@ impl Processor {
            _ => unreachable!()
        }
        if !is_jump {self.pc += 1};
        true
    }
}



@@ 102,7 104,7 @@ fn calc(stack: &mut Vec::<u16>, instruction: u16, carry_in: bool) -> bool {
    carry
}

fn mem_to_buf(memory: &[u16]) -> [u32;(2<<14)-1] {
pub fn mem_to_buf(memory: &[u16]) -> [u32;(2<<14)-1] {
    let mut result = [0u32;(2<<14)-1];
    let mut i = 0;
    for byte in &memory[(2<<20)-(2<<14)..(2<<20)-1] {

M src/main.rs => src/main.rs +20 -2
@@ 1,11 1,13 @@
use std::{fs,io};
use minifb;
use std::{fs, io};
use minifb::{Window, WindowOptions};
use implementation::*;

fn main() {
    let mut filename = String::new();
    print!("Enter filename of the program to load into memory");
    io::stdin().read_line(&mut filename).unwrap();
    let program = fs::read_to_string(filename).unwrap();

    let mut i = 0;
    let mut memory = [0u16;0xFFFFF];
    for line in program.lines() {


@@ 29,4 31,20 @@ fn main() {
        memory[i] = byte;
        i += 1;
    }
    
    let mut processor = Processor {
        stack_a: Vec::new(),
        stack_b: Vec::new(),
        memory,
        carry: false,
        pc: 0
    };
    
    let mut window = Window::new("STT Display", 128, 128, WindowOptions::default()).unwrap();
    while window.is_open() && processor.run() {
        if processor.memory[(2<<20)-(2<<14)-1] != 0 {
            processor.memory[(2<<20)-(2<<14)-1] = 0;
            window.update_with_buffer(&mem_to_buf(&processor.memory), 128, 128).unwrap();
        }
    }
}