stripped everything down - starting from scratch. reading obj file works
This commit is contained in:
parent
df6caea574
commit
0f9980425c
BIN
helloworld
Normal file
BIN
helloworld
Normal file
Binary file not shown.
77
src/main.rs
77
src/main.rs
@ -1,63 +1,22 @@
|
|||||||
const PC_START: u16 = 0x3000;
|
mod mem;
|
||||||
|
use std::env;
|
||||||
#[allow(dead_code)]
|
use std::fs;
|
||||||
enum Registers {
|
use std::io;
|
||||||
R0 = 0,
|
use std::io::Read;
|
||||||
R1,
|
|
||||||
R2,
|
|
||||||
R3,
|
|
||||||
R4,
|
|
||||||
R5,
|
|
||||||
R6,
|
|
||||||
R7,
|
|
||||||
PC,
|
|
||||||
COND,
|
|
||||||
COUNT
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
enum Opcodes {
|
|
||||||
// https://www.cs.utexas.edu/~fussell/courses/cs310h/lectures/Lecture_10-310h.pdf
|
|
||||||
ADD = 0, // add
|
|
||||||
AND, // and
|
|
||||||
NOT, // not (bitwise)
|
|
||||||
LD, // load (pc relative)
|
|
||||||
LDI, // load indirect
|
|
||||||
LDR, // load base + offset
|
|
||||||
LEA, // load immediate
|
|
||||||
ST, // store pc relative
|
|
||||||
STR, // store base + offset
|
|
||||||
STI, // store indirect
|
|
||||||
BR, // branch
|
|
||||||
JSR, // jump register
|
|
||||||
JMP, // jump
|
|
||||||
RTI, // return from interrupt (unused)
|
|
||||||
TRAP, // trap
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
enum ConditionFlags {
|
|
||||||
POS = 1 << 0,
|
|
||||||
ZERO = 1 << 1,
|
|
||||||
NEG = 1 << 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _memory:[u16; 1 << 16] = [0; 1 << 16];
|
let args: Vec<String> = env::args().collect();
|
||||||
let mut registers:[u16; Registers::COUNT as usize] = [0; Registers::COUNT as usize];
|
let path = args.get(1).expect("enter a file please!");
|
||||||
|
let file = fs::File::open(path).expect("couldnt open file");
|
||||||
registers[Registers::COND as usize] = ConditionFlags::ZERO as u16;
|
let mut reader = io::BufReader::new(file);
|
||||||
registers[Registers::PC as usize] = PC_START;
|
let mut values = Vec::new();
|
||||||
|
let mut buffer:[u8;2] = [0;2];
|
||||||
// set running state
|
while reader.read_exact(&mut buffer).is_ok() {
|
||||||
let mut running:bool = true;
|
let instruction = u16::from_be_bytes(buffer);
|
||||||
while running {
|
values.push(instruction);
|
||||||
let index: u16 = registers[Registers::PC as usize];
|
}
|
||||||
let mut instr:u16 = _memory[index as usize];
|
println!("data: {:?}\n", values);
|
||||||
registers[Registers::PC as usize] += 1;
|
for data in values{
|
||||||
match instr >> 12 {
|
println!("hex data: {:#06X}", data);
|
||||||
op if op == Opcodes::ADD as u16 => todo!(),
|
|
||||||
_ => todo!(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
0
src/mem.rs
Normal file
0
src/mem.rs
Normal file
Loading…
x
Reference in New Issue
Block a user