Skip to content

Commit

Permalink
Ref #85 system,video_systemの配列アクセスを置き換え。あまり早くならず
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiyaowl committed Sep 25, 2019
1 parent 1cbf788 commit 682b01f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/apu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ impl Apu {
/// TODO: 実装
#[allow(dead_code)]
fn increment_seq(&mut self, cpu_cyc: u8) {
self.frame_seq_counter = (self.frame_seq_counter + u16::from(cpu_cyc)) & 0x03ff; // 11bit
self.frame_seq_counter = (self.frame_seq_counter + u16::from(cpu_cyc)) & 0x03ff;
// 11bit
}
/// APUの処理を進めます
pub fn step(&mut self, _cpu: &mut Cpu, _cpu_cyc: u8) {
// TODO:がんばる

}
}
18 changes: 9 additions & 9 deletions src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ pub trait EmulateControl {
#[cfg(feature = "unsafe-opt")]
#[allow(unused_macros)]
macro_rules! arr_read {
($arr:expr, $index:expr) => (
($arr:expr, $index:expr) => {
unsafe { *$arr.get_unchecked($index) }
)
};
}

#[cfg(feature = "unsafe-opt")]
#[allow(unused_macros)]
macro_rules! arr_write {
($arr:expr, $index:expr, $data:expr) => (
($arr:expr, $index:expr, $data:expr) => {
unsafe { *$arr.get_unchecked_mut($index) = $data }
)
};
}

#[cfg(not(feature = "unsafe-opt"))]
#[allow(unused_macros)]
macro_rules! arr_read {
($arr:expr, $index:expr) => (
($arr:expr, $index:expr) => {
$arr[$index]
)
};
}

#[cfg(not(feature = "unsafe-opt"))]
#[allow(unused_macros)]
macro_rules! arr_write {
($arr:expr, $index:expr, $data:expr) => (
($arr:expr, $index:expr, $data:expr) => {
$arr[$index] = $data
)
}
};
}
26 changes: 13 additions & 13 deletions src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl SystemBus for System {
if addr < PPU_REG_BASE_ADDR {
// mirror support
let index = usize::from(addr) % self.wram.len();
self.wram[index]
arr_read!(self.wram, index)
} else if addr < APU_IO_REG_BASE_ADDR {
// mirror support
let index = usize::from(addr - PPU_REG_BASE_ADDR) % self.ppu_reg.len();
Expand All @@ -135,18 +135,18 @@ impl SystemBus for System {
if !is_nondestructive {
self.read_oam_data = true;
}
self.ppu_reg[index]
arr_read!(self.ppu_reg, index)
}
// PPU_DATA update/address incrementのためにフラグを立てる
// バッファが入るので1step遅れで結果が入る
0x07 => {
if !is_nondestructive {
self.read_ppu_data = true;
}
self.ppu_reg[index]
arr_read!(self.ppu_reg, index)
}
// default
_ => self.ppu_reg[index],
_ => arr_read!(self.ppu_reg, index),
}
} else if addr < CASSETTE_BASE_ADDR {
let index = usize::from(addr - APU_IO_REG_BASE_ADDR);
Expand All @@ -155,10 +155,10 @@ impl SystemBus for System {
// TODO: APU
0x16 => self.pad1.read_out(), // pad1
0x17 => self.pad2.read_out(), // pad2
_ => self.io_reg[index],
_ => arr_read!(self.io_reg, index),
}
} else {
self.io_reg[index]
arr_read!(self.io_reg, index)
}
} else {
self.cassette.read_u8(addr, is_nondestructive)
Expand All @@ -168,7 +168,7 @@ impl SystemBus for System {
if addr < PPU_REG_BASE_ADDR {
// mirror support
let index = usize::from(addr) % self.wram.len();
self.wram[index] = data;
arr_write!(self.wram, index, data);
} else if addr < APU_IO_REG_BASE_ADDR {
// mirror support
let index = usize::from(addr - PPU_REG_BASE_ADDR) % self.ppu_reg.len();
Expand All @@ -178,7 +178,7 @@ impl SystemBus for System {
if !is_nondestructive {
self.written_oam_data = true
}
self.ppu_reg[index] = data;
arr_write!(self.ppu_reg, index, data);
}
// $2005 PPU_SCROLL 2回書き
0x05 => {
Expand All @@ -190,7 +190,7 @@ impl SystemBus for System {
self.written_ppu_scroll = true;
}
} else {
self.ppu_reg[index] = data;
arr_write!(self.ppu_reg, index, data);
if !is_nondestructive {
self.ppu_is_second_write = true;
}
Expand All @@ -206,23 +206,23 @@ impl SystemBus for System {
self.written_ppu_addr = true;
}
} else {
self.ppu_reg[index] = data;
arr_write!(self.ppu_reg, index, data);
if !is_nondestructive {
self.ppu_is_second_write = true;
}
}
}
// $2007 PPU_DATA addr autoincrement
0x07 => {
self.ppu_reg[index] = data;
arr_write!(self.ppu_reg, index, data);
if !is_nondestructive {
// PPUに書いてもらおう
self.written_ppu_data = true;
}
}
// default
_ => {
self.ppu_reg[index] = data;
arr_write!(self.ppu_reg, index, data);
}
};
} else if addr < CASSETTE_BASE_ADDR {
Expand All @@ -236,7 +236,7 @@ impl SystemBus for System {
_ => {}
}
}
self.io_reg[index] = data;
arr_write!(self.io_reg, index, data);
} else {
self.cassette.write_u8(addr, data, is_nondestructive);
}
Expand Down
4 changes: 2 additions & 2 deletions src/video_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl VideoSystem {
0x14 => self.palette[0x04],
0x18 => self.palette[0x08],
0x1c => self.palette[0x0c],
_ => self.palette[index],
_ => arr_read!(self.palette, index),
}
}
}
Expand All @@ -147,7 +147,7 @@ impl VideoSystem {
0x14 => self.palette[0x04] = data,
0x18 => self.palette[0x08] = data,
0x1c => self.palette[0x0c] = data,
_ => self.palette[index] = data,
_ => arr_write!(self.palette, index, data),
};
}
}
Expand Down

0 comments on commit 682b01f

Please sign in to comment.