Merge branch 'master' of https://github.com/spieglt/nestur
This commit is contained in:
commit
82faa58456
|
@ -114,7 +114,6 @@ fn main() -> Result<(), String> {
|
|||
|
||||
println!("samples per second: {}", sps);
|
||||
sps = 0;
|
||||
|
||||
}
|
||||
}
|
||||
// PROFILER.lock().unwrap().stop().unwrap();
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
use std::rc::Rc;
|
||||
use std::cell::RefCell;
|
||||
|
||||
fn main() {
|
||||
let mapper = Rc::new(RefCell::new(Mmc1{a:32}));
|
||||
|
||||
let ppu = Ppu{mapper: mapper.clone()};
|
||||
let cpu = Cpu{mapper: mapper.clone()};
|
||||
println!("{}", cpu.mapper.borrow_mut().doit());
|
||||
println!("{}", ppu.mapper.borrow_mut().doit());
|
||||
}
|
||||
|
||||
struct Mmc1 {
|
||||
a: u8,
|
||||
}
|
||||
|
||||
trait Mapper {
|
||||
fn doit(&mut self) -> u8;
|
||||
}
|
||||
|
||||
impl Mapper for Mmc1 {
|
||||
fn doit(&mut self) -> u8 {
|
||||
self.a += 1;
|
||||
self.a
|
||||
}
|
||||
}
|
||||
|
||||
struct Ppu {
|
||||
mapper: Rc<RefCell<dyn Mapper>>,
|
||||
}
|
||||
|
||||
struct Cpu {
|
||||
mapper: Rc<RefCell<dyn Mapper>>,
|
||||
}
|
|
@ -142,12 +142,6 @@ impl super::Ppu {
|
|||
let mut low_bit = 0;
|
||||
let mut high_bit = 0;
|
||||
let mut secondary_index = 0;
|
||||
// Every cycle, the 8 x-position counters for the sprites are decremented by one.
|
||||
for i in 0..self.num_sprites {
|
||||
if self.sprite_counters[i] > 0 {
|
||||
self.sprite_counters[i] -= 1;
|
||||
}
|
||||
}
|
||||
for i in 0..self.num_sprites {
|
||||
// If the counter is zero, the sprite becomes "active", and the respective pair of shift registers for the sprite is shifted once every cycle.
|
||||
// This output accompanies the data in the sprite's latch, to form a pixel.
|
||||
|
@ -169,6 +163,12 @@ impl super::Ppu {
|
|||
self.sprite_pattern_table_srs[i].1 <<= 1;
|
||||
}
|
||||
}
|
||||
// Every cycle, the 8 x-position counters for the sprites are decremented by one.
|
||||
for i in 0..self.num_sprites {
|
||||
if self.sprite_counters[i] > 0 {
|
||||
self.sprite_counters[i] -= 1;
|
||||
}
|
||||
}
|
||||
((high_bit << 1) | low_bit, secondary_index)
|
||||
} else {
|
||||
(0, 0)
|
||||
|
@ -193,6 +193,7 @@ impl super::Ppu {
|
|||
}
|
||||
}
|
||||
self.num_sprites = sprite_count;
|
||||
|
||||
}
|
||||
|
||||
pub fn fetch_sprites(&mut self) {
|
||||
|
@ -201,7 +202,7 @@ impl super::Ppu {
|
|||
let sprite_y_position = self.secondary_oam[(4*i)+0] as usize; // byte 0 of sprite, sprite's vertical position on screen
|
||||
let sprite_tile_index = self.secondary_oam[(4*i)+1] as usize; // byte 1 of sprite, sprite's location within pattern table
|
||||
let sprite_attributes = self.secondary_oam[(4*i)+2]; // byte 2 of sprite, sprite's palette, priority, and flip attributes
|
||||
let sprite_x_position = self.secondary_oam[(4*i)+3] + 1; // byte 3 of sprite, sprite's horizontal position on screen
|
||||
let sprite_x_position = self.secondary_oam[(4*i)+3]; // byte 3 of sprite, sprite's horizontal position on screen
|
||||
// For 8x8 sprites, this is the tile number of this sprite within the pattern table selected in bit 3 of PPUCTRL ($2000).
|
||||
if self.sprite_size == 8 {
|
||||
address = self.sprite_pattern_table_base;
|
||||
|
|
Loading…
Reference in New Issue