use std::{fs, io}; use minifb::{Window, WindowOptions, Key}; use implementation::*; fn main() { let mut filename = String::new(); println!("Enter filename of the program to load into memory"); io::stdin().read_line(&mut filename).unwrap(); let program = fs::read_to_string(filename.trim()).unwrap(); let mut i = 0; let mut memory = [0u16;MEMORY_SIZE]; for line in program.lines() { let mut byte = 0u16; let mut count = 0; for digit in line.chars() { match digit { '0' => { byte = byte << 1; count += 1; } '1' => { byte = (byte << 1) | 1; count += 1; } _ => () } if count > 10 {panic!("10 bits only :)\nFailed at line {i}")}; } memory[i] = byte; i += 1; } let mut processor = Processor { stack_a: new_stack(), stack_b: new_stack(), memory, carry: false, pc: 0 }; let mut window = Window::new("STT Display", SCREEN_WIDTH, SCREEN_HEIGHT, WindowOptions::default()).unwrap(); window.update_with_buffer(&[0;(1<<14)],128,128).unwrap(); let mut instructions_run = 0; while window.is_open() && processor.run() { if processor.memory[SCREEN_UPDATE_ADDRESS] != 0 { processor.memory[SCREEN_UPDATE_ADDRESS] = 0; window.update_with_buffer(&mem_to_buf(&processor.memory), SCREEN_WIDTH, SCREEN_HEIGHT).unwrap(); } instructions_run += 1; if instructions_run%1000 == 0 { println!("Program running"); } } println!("Stack A: {0:?}\nStack B: {1:?}", processor.stack_a, processor.stack_b); }