From 63ce8cbc26a2b7102ed1107171bdcc99a3795a69 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sat, 8 Feb 2014 14:36:43 -0500 Subject: [PATCH] updated to compile w/ latest Rust master --- a2.rs | 9 ++++-- cpu.rs | 12 ++++---- util.rs | 92 --------------------------------------------------------- 3 files changed, 13 insertions(+), 100 deletions(-) diff --git a/a2.rs b/a2.rs index 377ea9b..a1479b8 100644 --- a/a2.rs +++ b/a2.rs @@ -238,7 +238,12 @@ impl AppleII use std::io::File; use std::vec::bytes::copy_memory; let ap2rom = File::open(&Path::new("apple2.rom")).read_bytes(0x3000); - copy_memory(self.mem.mut_slice(0xd000, 0xd000+0x3000), ap2rom); - info!("loaded apple2.rom"); + match ap2rom { + Ok(rom) => { + copy_memory(self.mem.mut_slice(0xd000, 0xd000+0x3000), rom); + info!("loaded apple2.rom"); + } + Err(e) => fail!(e) + } } } diff --git a/cpu.rs b/cpu.rs index 81ec4ce..5aedc45 100644 --- a/cpu.rs +++ b/cpu.rs @@ -50,12 +50,12 @@ static CYCLE_TABLE: [u8, ..256] = [ // struct Regs { - a: u8, - x: u8, - y: u8, - s: u8, - flags: u8, - pc: u16 + pub a: u8, + pub x: u8, + pub y: u8, + pub s: u8, + pub flags: u8, + pub pc: u16 } impl Regs { diff --git a/util.rs b/util.rs index a0d80eb..438de56 100644 --- a/util.rs +++ b/util.rs @@ -8,98 +8,6 @@ use std::io::File; use std::libc::{c_int, c_void, time_t}; use std::ptr::null; -// -// A tiny custom serialization infrastructure, used for savestates. -// -// TODO: Use the standard library's ToBytes and add a FromBytes -- or don't; this is such a small -// amount of code it barely seems worth it. -// - -pub trait Save { - fn save(&mut self, fd: &mut File); - fn load(&mut self, fd: &mut File); -} - -impl Save for u8 { - fn save(&mut self, fd: &mut File) { fd.write([ *self ]) } - fn load(&mut self, fd: &mut File) { let mut buf = [ 0 ]; fd.read(buf); *self = buf[0]; } -} - -impl Save for u16 { - fn save(&mut self, fd: &mut File) { fd.write([ *self as u8, (*self >> 8) as u8 ]) } - fn load(&mut self, fd: &mut File) { - let mut buf = [ 0, 0 ]; - fd.read(buf); - *self = (buf[0] as u16) | ((buf[1] as u16) << 8); - } -} - -impl Save for u64 { - fn save(&mut self, fd: &mut File) { - let mut buf = [ 0, ..8 ]; - for i in range(0, 8) { - buf[i] = ((*self) >> (i * 8)) as u8; - } - fd.write(buf); - } - fn load(&mut self, fd: &mut File) { - let mut buf = [ 0, ..8 ]; - fd.read(buf); - *self = 0; - for i in range(0, 8) { - *self = *self | (buf[i] as u64 << (i * 8)); - } - } -} - -impl<'a> Save for &'a mut [u8] { - fn save(&mut self, fd: &mut File) { - fd.write(*self); - } - fn load(&mut self, fd: &mut File) { - fd.read(*self); - } -} - -impl Save for bool { - fn save(&mut self, fd: &mut File) { fd.write([ if *self { 0 } else { 1 } ]) } - fn load(&mut self, fd: &mut File) { - let mut val: [u8, ..1] = [ 0 ]; - fd.read(val); - *self = val[0] != 0 - } -} - -// A convenience macro to save and load entire structs. -macro_rules! save_struct( - ($name:ident { $($field:ident),* }) => ( - impl Save for $name { - fn save(&mut self, fd: &mut File) { - $(self.$field.save(fd);)* - } - fn load(&mut self, fd: &mut File) { - $(self.$field.load(fd);)* - } - } - ) -) - -macro_rules! save_enum( - ($name:ident { $val_0:ident, $val_1:ident }) => ( - impl Save for $name { - fn save(&mut self, fd: &mut File) { - let mut val: u8 = match *self { $val_0 => 0, $val_1 => 1 }; - val.save(fd) - } - fn load(&mut self, fd: &mut File) { - let mut val: u8 = 0; - val.load(fd); - *self = if val == 0 { $val_0 } else { $val_1 }; - } - } - ) -) - // // Random number generation //