[NO TESTS] WIP

This commit is contained in:
Reid 'arrdem' McKenzie 2022-12-13 00:51:18 -07:00
parent e6faac5788
commit 15cc949472
2 changed files with 35 additions and 4 deletions

View file

@ -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();
println!("{:?}", vm);
fn main() -> Result<(), std::io::Error> {
let mut vm = Uxn::new();
let argv: Vec<String> = 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(())
}

View file

@ -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(())
}
}