mirror of
https://github.com/FranLMSP/rmg-001.git
synced 2024-11-23 10:12:11 +00:00
Fix tearing
This commit is contained in:
parent
60bcc39a74
commit
7bfe760a57
@ -109,9 +109,7 @@ impl Emulator {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(&mut self, cpu_cycles: Cycles, frame_buffer: &mut [u8]) {
|
||||
self.cpu.reset_cycles();
|
||||
while self.cpu.get_cycles().to_t().0 <= cpu_cycles.0 {
|
||||
fn tick(&mut self, frame_buffer: &mut [u8]) {
|
||||
self.cpu.run(&mut self.bus);
|
||||
let cycles = self.cpu.get_last_op_cycles().to_t();
|
||||
self.bus.ppu.do_cycles(&mut self.bus.interrupts, cycles, frame_buffer);
|
||||
@ -123,7 +121,23 @@ impl Emulator {
|
||||
|
||||
// 1 CPU cycle = 238.42ns
|
||||
// thread::sleep(time::Duration::from_nanos((self.cpu.get_last_op_cycles().0 * 238).try_into().unwrap()));
|
||||
}
|
||||
|
||||
pub fn run(&mut self, cpu_cycles: Cycles, frame_buffer: &mut [u8]) {
|
||||
self.cpu.reset_cycles();
|
||||
while self.cpu.get_cycles().to_t().0 <= cpu_cycles.0 {
|
||||
self.tick(frame_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_frame(&mut self, frame_buffer: &mut [u8]) {
|
||||
self.cpu.reset_cycles();
|
||||
let mut frame_started = true;
|
||||
while self.bus.ppu.lcd_y() < 144 || frame_started {
|
||||
self.tick(frame_buffer);
|
||||
if self.bus.ppu.lcd_y() == 0 {
|
||||
frame_started = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -345,6 +345,10 @@ impl PPU {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lcd_y(&self) -> u8 {
|
||||
self.lcd_y
|
||||
}
|
||||
|
||||
pub fn set_vram_bank(&mut self, bank: u8) {
|
||||
if self.cgb_mode {
|
||||
self.vram_bank = bank & 1;
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::emulator::Emulator;
|
||||
use crate::frames::Frames;
|
||||
use crate::cpu::Cycles;
|
||||
use crate::ppu::{WIDTH, HEIGHT};
|
||||
|
||||
use log::error;
|
||||
@ -81,7 +80,7 @@ pub fn start_eventloop() {
|
||||
*control_flow = ControlFlow::Exit
|
||||
},
|
||||
Event::MainEventsCleared => {
|
||||
emulator.run(Cycles(70224.0), pixels.get_frame());
|
||||
emulator.run_frame(pixels.get_frame());
|
||||
frame_counter.increment();
|
||||
if frame_counter.elapsed_ms() >= 1000 {
|
||||
window.set_title(&format!("rmg-001 (FPS: {})", frame_counter.count()));
|
||||
|
Loading…
Reference in New Issue
Block a user