~maddie/STT-implementation

ref: bd62c0375bbf0397295668f165bcf7c25c190360 STT-implementation/src/main.rs -rw-r--r-- 1.4 KiB
bd62c037 — kn0000 Implement the run loop and display, untested for now 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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() {
        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;
    }
    
    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();
        }
    }
}