~maddie/STT-implementation

ref: 465460b409f3c54cb7a75c77bd730f170528c40d STT-implementation/src/main.rs -rw-r--r-- 871 bytes
465460b4 — kn0000 Add minifb and a function for converting a region of memory into a display buffer 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::{fs,io};
use minifb;

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() {
        let mut byte = 0u16;
        let mut count = 0;
        for digit in line.chars() {
            count += 1;
            match digit {
                '0' => {
                    byte = byte << 1;
                    count += 1;
                }
                '1' => {
                    byte = (byte << 1) | 1;
                    count += 1;
                }
                _ => ()
            }
            if count > 10 {panic!("10 bits only :)")};
        }
        memory[i] = byte;
        i += 1;
    }
}