From 15cc94947251249f687c4f12938633e0a6e47b89 Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Tue, 13 Dec 2022 00:51:18 -0700 Subject: [PATCH] [NO TESTS] WIP --- src/bin/main.rs | 23 +++++++++++++++++++++-- src/lib.rs | 16 ++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index 3b013e6..4c27b8e 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -1,6 +1,25 @@ +use std::env::args; +use std::fs::File; +use std::io; +use std::io::BufReader; +use std::io::Read; + use uxn::Uxn; -fn main() { - let vm = Uxn::new(); +fn main() -> Result<(), std::io::Error> { + let mut vm = Uxn::new(); + + let argv: Vec = args().collect(); + let f: File = File::open(&argv[1])?; + let reader = BufReader::new(f); + + let mut i = 0x0100u16; + for b in reader.bytes() { + vm.sta1(i, b?).expect("Write failed"); + i += 1; + } + println!("{:?}", vm); + + Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index 1f641d1..30bf3b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,8 +5,10 @@ use std::cell::{Cell, RefCell, RefMut}; use std::rc::Rc; use std::*; -use memory::TrivialMemory; -use stack::Stack; +use memory::MemoryError; + +use crate::memory::{Memory, TrivialMemory}; +use crate::stack::Stack; trait Device: std::fmt::Debug { /** @@ -157,4 +159,14 @@ impl Uxn { pub fn deo2(&mut self, port: u8, val: u16) { self.device(port).borrow_mut().deo2(self, port, val); } + + pub fn sta1(&mut self, address: u16, val: u8) -> Result<(), MemoryError> { + self.memory.borrow_mut().set1(address, val)?; + Ok(()) + } + + pub fn sta2(&mut self, address: u16, val: u16) -> Result<(), MemoryError> { + self.memory.borrow_mut().set2(address, val)?; + Ok(()) + } }