M src/lib.rs => src/lib.rs +3 -1
@@ 156,4 156,6 @@ pub fn keys_to_state(keys: Vec<Key>) -> Vec<u16> { //output is using only 10 bit
output
}
-
+pub fn merge(a: u8, b: u8) -> u16 {
+ ((a as u16) << 8) | (b as u16)
+}
M src/main.rs => src/main.rs +12 -24
@@ 1,36 1,24 @@
-use std::{fs, io};
+use std::{fs, env};
use minifb::{Window, WindowOptions};
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 argument: String = env::args().collect::<Vec<String>>()[1].clone();
+ if argument == "-h" || argument == "--help" {
+ println!("Takes the path of a binary file and runs it in the STT vm thing");
+ return
+ }
+
+ let program = fs::read(argument).expect("Unable to read file");
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;
+
+ while program.get(2*i) != None {
+ memory[i] = merge(program[2*i], *program.get(2*i + 1).expect("Bad parity"));
i += 1;
}
-
+
let mut processor = Processor {
stack_a: new_stack(),
stack_b: new_stack(),