mirror of
https://github.com/kirjavascript/trueLMAO.git
synced 2024-05-20 13:17:26 -04:00
add PAL framerate
This commit is contained in:
parent
c2ab37cd77
commit
cce5f8480c
|
@ -17,9 +17,14 @@ impl Default for FrameTimer {
|
|||
}
|
||||
|
||||
impl FrameTimer {
|
||||
pub fn frame_count(&mut self) -> u64 {
|
||||
pub fn frame_count(&mut self, region: &crate::region::Region) -> u64 {
|
||||
let diff = Instant::now().duration_since(self.epoch);
|
||||
let frames = (diff.as_millis() as f64 * 0.05992274) as u64; // TODO: PAL
|
||||
let rate = if region.is_pal() {
|
||||
0.049701459
|
||||
} else {
|
||||
0.05992274
|
||||
};
|
||||
let frames = (diff.as_millis() as f64 * rate) as u64;
|
||||
// self.emu.gfx.framerate()
|
||||
self.frame_count = frames - self.frames;
|
||||
self.frames = frames;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
pub struct IO {
|
||||
registers: [u8; 0x10],
|
||||
pub registers: [u8; 0x10],
|
||||
pub gamepad: [Gamepad; 2],
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ pub mod frame_timer;
|
|||
pub mod gfx;
|
||||
pub mod io;
|
||||
pub mod mem;
|
||||
pub mod region;
|
||||
pub mod rom;
|
||||
pub mod vdp;
|
||||
pub mod z80;
|
||||
|
@ -25,6 +26,7 @@ pub struct Megadrive {
|
|||
pub core: ConfiguredCore<AutoInterruptController, mem::Mem>,
|
||||
pub gfx: Gfx,
|
||||
pub frame_timer: frame_timer::FrameTimer,
|
||||
pub region: region::Region,
|
||||
// version: NTSC/PAL
|
||||
}
|
||||
|
||||
|
@ -37,17 +39,24 @@ impl Megadrive {
|
|||
|
||||
core.dar[STACK_POINTER_REG] = core.mem.rom.stack_pointer();
|
||||
|
||||
Megadrive {
|
||||
let region = region::Region::detect(&core.mem.rom);
|
||||
|
||||
let mut emu = Megadrive {
|
||||
core,
|
||||
gfx: Gfx::new(),
|
||||
frame_timer: Default::default(),
|
||||
}
|
||||
region,
|
||||
};
|
||||
|
||||
region::Region::set_io_region(&emu.region, &mut emu.core.mem.io);
|
||||
|
||||
emu
|
||||
}
|
||||
|
||||
/// render frame(s) at current instant
|
||||
/// returns number of rendered frames
|
||||
pub fn render(&mut self) -> u64 {
|
||||
let frame_count = self.frame_timer.frame_count();
|
||||
let frame_count = self.frame_timer.frame_count(&self.region);
|
||||
if frame_count > 3 { // magic number
|
||||
self.frame(true);
|
||||
} else if frame_count > 0 {
|
||||
|
|
|
@ -1,22 +1,35 @@
|
|||
enum Video {
|
||||
PAL,
|
||||
NTSC
|
||||
}
|
||||
use crate::rom::ROM;
|
||||
use crate::io::IO;
|
||||
|
||||
enum Region {
|
||||
#[derive(PartialEq)]
|
||||
pub enum Region {
|
||||
US,
|
||||
EU,
|
||||
JP,
|
||||
}
|
||||
|
||||
struct HWRevision {
|
||||
region: Region,
|
||||
video: Video,
|
||||
impl Region {
|
||||
pub fn is_pal(&self) -> bool {
|
||||
self == &Region::EU
|
||||
}
|
||||
|
||||
pub fn detect(rom: &ROM) -> Self {
|
||||
let region_str = rom.region();
|
||||
if region_str.contains('U') {
|
||||
return Region::US
|
||||
} else if region_str.contains('J') {
|
||||
return Region::JP
|
||||
} else if region_str.contains('E') {
|
||||
return Region::EU
|
||||
}
|
||||
Region::US
|
||||
}
|
||||
|
||||
pub fn set_io_region(region: &Region, io: &mut IO) {
|
||||
io.registers[0] = match *region {
|
||||
Region::US => 0xA1,
|
||||
Region::EU => 0xE1,
|
||||
Region::JP => 0x21,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl HWRevision {
|
||||
|
||||
}
|
||||
|
||||
// from ROM
|
||||
|
|
Loading…
Reference in a new issue