mirror of
https://github.com/gopher64/gopher64.git
synced 2026-07-11 01:25:20 +02:00
@@ -494,6 +494,7 @@ impl Device {
|
||||
vi_counter: 0,
|
||||
min_wait_time: std::time::Duration::from_secs(1),
|
||||
frame_time: 0.0,
|
||||
elapsed_time: 0.0,
|
||||
limit_freq: 2,
|
||||
limit_freq_check: std::time::Instant::now(),
|
||||
},
|
||||
|
||||
+1
-2
@@ -147,8 +147,7 @@ fn eeprom_write_block(device: &mut device::Device, block: usize, offset: usize,
|
||||
}
|
||||
|
||||
fn time2data(device: &mut device::Device, offset: usize) {
|
||||
let timestamp =
|
||||
device.cart.rtc_timestamp + (device.vi.frame_time * device.vi.vi_counter as f64) as i64;
|
||||
let timestamp = device.cart.rtc_timestamp + device.vi.elapsed_time as i64;
|
||||
let now = chrono::DateTime::from_timestamp(timestamp, 0).unwrap();
|
||||
|
||||
device.pif.ram[offset] = byte2bcd(now.second());
|
||||
|
||||
@@ -21,6 +21,7 @@ pub struct GbCart {
|
||||
pub latch: bool,
|
||||
pub rtc_regs: [u8; MBC3_RTC_REGS_COUNT],
|
||||
pub rtc_regs_latch: [u8; MBC3_RTC_REGS_COUNT],
|
||||
pub current_time: i64,
|
||||
pub last_time: i64,
|
||||
}
|
||||
|
||||
@@ -34,9 +35,9 @@ pub enum CartType {
|
||||
MBC5RamBatt,
|
||||
}
|
||||
|
||||
fn update_rtc_regs(cart: &mut device::controller::gbcart::GbCart, now: i64) {
|
||||
let mut diff = now - cart.last_time;
|
||||
cart.last_time = now;
|
||||
fn update_rtc_regs(cart: &mut device::controller::gbcart::GbCart) {
|
||||
let mut diff = cart.current_time - cart.last_time;
|
||||
cart.last_time = cart.current_time;
|
||||
|
||||
if diff > 0 {
|
||||
cart.rtc_regs[MBC3_RTC_SECONDS] += (diff % 60) as u8;
|
||||
@@ -153,7 +154,6 @@ fn write_mbc3(
|
||||
address: u16,
|
||||
data: usize,
|
||||
size: usize,
|
||||
now: i64,
|
||||
) {
|
||||
let value = pif_ram[data + size - 1];
|
||||
if address < 0x2000 {
|
||||
@@ -169,7 +169,7 @@ fn write_mbc3(
|
||||
} else if address < 0x8000 {
|
||||
if cart.cart_type == CartType::MBC3RamBattRtc {
|
||||
if !cart.latch && (value & 0x1) != 0 {
|
||||
update_rtc_regs(cart, now);
|
||||
update_rtc_regs(cart);
|
||||
cart.rtc_regs_latch = cart.rtc_regs;
|
||||
}
|
||||
cart.latch = (value & 0x1) != 0;
|
||||
@@ -196,7 +196,6 @@ fn read_mbc3(
|
||||
address: u16,
|
||||
data: usize,
|
||||
size: usize,
|
||||
now: i64,
|
||||
) {
|
||||
if address < 0x4000 {
|
||||
let banked_address = address & 0x3FFF;
|
||||
@@ -226,7 +225,7 @@ fn read_mbc3(
|
||||
pif_ram[data + i] = cart.rtc_regs_latch[cart.ram_bank as usize - 0x8];
|
||||
}
|
||||
} else {
|
||||
update_rtc_regs(cart, now);
|
||||
update_rtc_regs(cart);
|
||||
for i in 0..size {
|
||||
pif_ram[data + i] = cart.rtc_regs[cart.ram_bank as usize - 0x8];
|
||||
}
|
||||
@@ -307,7 +306,6 @@ pub fn read(
|
||||
address: u16,
|
||||
data: usize,
|
||||
size: usize,
|
||||
now: i64,
|
||||
) {
|
||||
if !cart.enabled {
|
||||
for i in 0..size {
|
||||
@@ -317,8 +315,8 @@ pub fn read(
|
||||
}
|
||||
match cart.cart_type {
|
||||
CartType::MBC1RamBatt => read_mbc1(pif_ram, cart, address, data, size),
|
||||
CartType::MBC3RamBatt => read_mbc3(pif_ram, cart, address, data, size, now),
|
||||
CartType::MBC3RamBattRtc => read_mbc3(pif_ram, cart, address, data, size, now),
|
||||
CartType::MBC3RamBatt => read_mbc3(pif_ram, cart, address, data, size),
|
||||
CartType::MBC3RamBattRtc => read_mbc3(pif_ram, cart, address, data, size),
|
||||
CartType::MBC5RamBatt => read_mbc5(pif_ram, cart, address, data, size),
|
||||
_ => panic!("Unsupported cart type"),
|
||||
}
|
||||
@@ -330,15 +328,14 @@ pub fn write(
|
||||
address: u16,
|
||||
data: usize,
|
||||
size: usize,
|
||||
now: i64,
|
||||
) {
|
||||
if !cart.enabled {
|
||||
return;
|
||||
}
|
||||
match cart.cart_type {
|
||||
CartType::MBC1RamBatt => write_mbc1(pif_ram, cart, address, data, size),
|
||||
CartType::MBC3RamBatt => write_mbc3(pif_ram, cart, address, data, size, now),
|
||||
CartType::MBC3RamBattRtc => write_mbc3(pif_ram, cart, address, data, size, now),
|
||||
CartType::MBC3RamBatt => write_mbc3(pif_ram, cart, address, data, size),
|
||||
CartType::MBC3RamBattRtc => write_mbc3(pif_ram, cart, address, data, size),
|
||||
CartType::MBC5RamBatt => write_mbc5(pif_ram, cart, address, data, size),
|
||||
_ => panic!("Unsupported cart type"),
|
||||
}
|
||||
|
||||
@@ -52,13 +52,13 @@ pub fn read(device: &mut device::Device, channel: usize, address: u16, data: usi
|
||||
}
|
||||
}
|
||||
0xC..=0xF => {
|
||||
pak.cart.current_time = device.vi.elapsed_time as i64;
|
||||
device::controller::gbcart::read(
|
||||
&mut device.pif.ram,
|
||||
&mut pak.cart,
|
||||
0x4000 * pak.bank + (address & 0x7fff) - 0x4000,
|
||||
data,
|
||||
size,
|
||||
(device.vi.frame_time * device.vi.vi_counter as f64) as i64,
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
@@ -119,13 +119,13 @@ pub fn write(device: &mut device::Device, channel: usize, address: u16, data: us
|
||||
}
|
||||
}
|
||||
0xC..=0xF => {
|
||||
pak.cart.current_time = device.vi.elapsed_time as i64;
|
||||
device::controller::gbcart::write(
|
||||
&device.pif.ram,
|
||||
&mut pak.cart,
|
||||
0x4000 * pak.bank + (address & 0x7fff) - 0x4000,
|
||||
data,
|
||||
size,
|
||||
(device.vi.frame_time * device.vi.vi_counter as f64) as i64,
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
|
||||
@@ -29,6 +29,7 @@ pub struct Vi {
|
||||
pub vi_counter: u64,
|
||||
pub min_wait_time: std::time::Duration,
|
||||
pub frame_time: f64,
|
||||
pub elapsed_time: f64,
|
||||
pub limit_freq: u64,
|
||||
#[serde(skip)]
|
||||
#[serde(default = "std::time::Instant::now")]
|
||||
@@ -146,6 +147,7 @@ pub fn vertical_interrupt_event(device: &mut device::Device) {
|
||||
|
||||
ui::video::update_screen();
|
||||
device.vi.vi_counter += 1;
|
||||
device.vi.elapsed_time += device.vi.frame_time;
|
||||
|
||||
if device.netplay.is_none() && paused {
|
||||
if retroachievements::get_hardcore() {
|
||||
|
||||
Reference in New Issue
Block a user