mirror of
https://github.com/sehugg/rustyapple.git
synced 2025-02-16 02:32:06 +00:00
updated to compile w/ latest Rust master
This commit is contained in:
parent
e6eb6f97e7
commit
63ce8cbc26
9
a2.rs
9
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
12
cpu.rs
12
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 {
|
||||
|
92
util.rs
92
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
|
||||
//
|
||||
|
Loading…
x
Reference in New Issue
Block a user