Fixed Branch Basics and Clock Timing. Mega Man now Fully Repos
This commit is contained in:
parent
353f12f7d9
commit
9c785f3f68
|
@ -42,7 +42,7 @@ impl super::Cpu {
|
|||
|
||||
pub fn branch_page_cross(&mut self, old_address: usize, new_address: usize) {
|
||||
if old_address >> 8 != new_address >> 8 {
|
||||
self.clock += 2;
|
||||
self.clock += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
46
src/main.rs
46
src/main.rs
|
@ -303,31 +303,7 @@ fn run_game(
|
|||
while new_frames < FRAMES_TO_CONSIDER {
|
||||
// step CPU: perform 1 cpu instruction, getting back number of clock cycles it took
|
||||
|
||||
// A the start of each new frame set our input for that frame...
|
||||
if prev_frame == 0 || prev_frame != frames {
|
||||
match fuzzing_input.get_frame_input(frames) {
|
||||
Some(input) => {
|
||||
match input.console_action {
|
||||
ConsoleAction::None => {}
|
||||
ConsoleAction::SoftReset => {
|
||||
cpu.soft_reset();
|
||||
frames += 1;
|
||||
}
|
||||
}
|
||||
|
||||
cpu.button_states = input.player_1_input;
|
||||
cpu.button_states2 = input.player_2_input;
|
||||
}
|
||||
_ => {
|
||||
cpu.button_states = 0;
|
||||
cpu.button_states2 = 0;
|
||||
}
|
||||
};
|
||||
prev_frame = frames;
|
||||
}
|
||||
|
||||
let cpu_cycles = cpu.step();
|
||||
|
||||
// clock PPU three times for every CPU cycle
|
||||
for _ in 0..cpu_cycles * 3 {
|
||||
let (pixel, end_of_frame) = cpu.ppu.clock();
|
||||
|
@ -346,13 +322,31 @@ fn run_game(
|
|||
window
|
||||
.update_with_buffer(&screen.display, 256, 240)
|
||||
.unwrap();
|
||||
prev_frame = frames;
|
||||
frames += 1;
|
||||
new_frames += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Checking for Inputs...
|
||||
match fuzzing_input.get_frame_input(frames) {
|
||||
Some(input) => {
|
||||
match input.console_action {
|
||||
ConsoleAction::None => {}
|
||||
ConsoleAction::SoftReset => {
|
||||
println!("soft reset");
|
||||
cpu.soft_reset();
|
||||
frames += 1;
|
||||
}
|
||||
}
|
||||
//if cpu.strobe {
|
||||
cpu.button_states = input.player_1_input;
|
||||
// FIXME PLayer 2 doesn't play nicely with some games (e.g. mario)
|
||||
// So to enable player 2 controls you also have to uncomment the
|
||||
// bus in cpu/mod.rs
|
||||
cpu.button_states2 = input.player_2_input;
|
||||
//}
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
|
||||
send_results
|
||||
|
|
|
@ -88,6 +88,7 @@ pub struct Ppu {
|
|||
previous_nmi: bool,
|
||||
nmi_delay: usize,
|
||||
|
||||
pub clocks_since_vbl_set: usize,
|
||||
read_buffer: u8, // used with PPUDATA register
|
||||
pub recent_bits: u8, // Least significant bits previously written into a PPU register
|
||||
pub open_bus: u8,
|
||||
|
@ -104,6 +105,7 @@ impl Ppu {
|
|||
t: 0,
|
||||
x: 0,
|
||||
w: 0,
|
||||
clocks_since_vbl_set: 0,
|
||||
open_bus: 0,
|
||||
mapper: mapper,
|
||||
nametable_a: vec![0u8; 0x0400],
|
||||
|
@ -161,8 +163,14 @@ impl Ppu {
|
|||
}
|
||||
}
|
||||
|
||||
let mut pixel: Option<(usize, usize, (u8, u8, u8))> = None;
|
||||
let rendering = self.rendering();
|
||||
if self.scanline == 0 && self.line_cycle == 0 && self.frame % 2 != 0 && rendering {
|
||||
// Idle cycle, unless it's an odd frame and rendering is enabled.
|
||||
// If it's an odd frame, go directly to the next cycle.
|
||||
self.line_cycle = 1;
|
||||
}
|
||||
let mut pixel: Option<(usize, usize, (u8, u8, u8))> = None;
|
||||
|
||||
|
||||
// Visible scanlines (0-239)
|
||||
if rendering && (self.scanline < 240 || self.scanline == 261) {
|
||||
|
@ -219,7 +227,7 @@ impl Ppu {
|
|||
self.nmi_change();
|
||||
}
|
||||
|
||||
if self.scanline == 261 && self.line_cycle == 1 {
|
||||
if self.scanline == 260 && self.line_cycle == 330 {
|
||||
self.vertical_blank = false;
|
||||
self.nmi_change();
|
||||
self.sprite_zero_hit = false;
|
||||
|
@ -227,28 +235,23 @@ impl Ppu {
|
|||
}
|
||||
|
||||
// signal time to draw frame
|
||||
let end_of_frame = self.line_cycle == 256 && self.scanline == 240;
|
||||
|
||||
// advance clock
|
||||
// For odd frames, the cycle at the end of the pre-render scanline is skipped
|
||||
if self.line_cycle == 339 && self.scanline == 261 && self.frame % 2 != 0 {
|
||||
self.line_cycle = 0;
|
||||
self.scanline = 0;
|
||||
self.frame = self.frame.wrapping_add(1);
|
||||
// Otherwise, if at the last cycle of the last row of a frame, advance it.
|
||||
} else if self.line_cycle == 340 && self.scanline == 261 {
|
||||
self.line_cycle = 0;
|
||||
self.scanline = 0;
|
||||
self.frame = self.frame.wrapping_add(1);
|
||||
// If at a normal line end, advance to next
|
||||
} else if self.line_cycle == 340 {
|
||||
self.line_cycle = 0;
|
||||
|
||||
|
||||
self.line_cycle += 1;
|
||||
|
||||
if self.line_cycle == 341 {
|
||||
self.scanline += 1;
|
||||
// If none of the above, just go to next cycle in the row
|
||||
} else {
|
||||
self.line_cycle += 1;
|
||||
self.line_cycle = 0;
|
||||
}
|
||||
|
||||
if self.scanline == 262 {
|
||||
self.scanline = 0;
|
||||
self.frame = self.frame.wrapping_add(1);
|
||||
}
|
||||
|
||||
let mut end_of_frame = self.line_cycle == 256 && self.scanline == 240;
|
||||
|
||||
// deal with mapper MMC3
|
||||
let current_a12 = if self.v & 1 << 12 != 0 { 1 } else { 0 };
|
||||
if rendering && (0..241).contains(&self.scanline) && current_a12 != self.previous_a12 {
|
||||
|
|
Loading…
Reference in New Issue