[NO TESTS] WIP
This commit is contained in:
parent
e6faac5788
commit
15cc949472
2 changed files with 35 additions and 4 deletions
|
@ -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;
|
use uxn::Uxn;
|
||||||
|
|
||||||
fn main() {
|
fn main() -> Result<(), std::io::Error> {
|
||||||
let vm = Uxn::new();
|
let mut vm = Uxn::new();
|
||||||
println!("{:?}", vm);
|
|
||||||
|
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(())
|
||||||
}
|
}
|
||||||
|
|
16
src/lib.rs
16
src/lib.rs
|
@ -5,8 +5,10 @@ use std::cell::{Cell, RefCell, RefMut};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::*;
|
use std::*;
|
||||||
|
|
||||||
use memory::TrivialMemory;
|
use memory::MemoryError;
|
||||||
use stack::Stack;
|
|
||||||
|
use crate::memory::{Memory, TrivialMemory};
|
||||||
|
use crate::stack::Stack;
|
||||||
|
|
||||||
trait Device: std::fmt::Debug {
|
trait Device: std::fmt::Debug {
|
||||||
/**
|
/**
|
||||||
|
@ -157,4 +159,14 @@ impl Uxn {
|
||||||
pub fn deo2(&mut self, port: u8, val: u16) {
|
pub fn deo2(&mut self, port: u8, val: u16) {
|
||||||
self.device(port).borrow_mut().deo2(self, port, val);
|
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(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue