diff --git a/src/device/cart_rom.rs b/src/device/cart_rom.rs index 67af3cc..03e7f0d 100644 --- a/src/device/cart_rom.rs +++ b/src/device/cart_rom.rs @@ -104,7 +104,7 @@ pub fn init(device: &mut device::Device, rom_file: Vec) { let data = std::str::from_utf8(&device.cart.rom[0x20 as usize..(0x20 + 0x14) as usize]).unwrap(); let hash = calculate_hash(&device.cart.rom); - device.ui.game_name = format!("{}-{}", data.trim(), hash); + device.ui.game_name = format!("{}-{}", data.trim().trim_matches(char::from(0)), hash); device.ui.game_id = String::from_utf8(device.cart.rom[0x3B..0x3E].to_vec()).unwrap(); } diff --git a/src/device/cop0.rs b/src/device/cop0.rs index b0541aa..1242d11 100644 --- a/src/device/cop0.rs +++ b/src/device/cop0.rs @@ -185,6 +185,7 @@ pub fn get_control_registers(device: &mut device::Device, index: u32) -> u64 { pub fn set_control_registers(device: &mut device::Device, index: u32, mut data: u64) { device.cpu.cop0.reg_latch = data; + data &= device.cpu.cop0.reg_write_masks[index as usize]; match index { COP0_COUNT_REG => { data <<= 1; @@ -197,14 +198,14 @@ pub fn set_control_registers(device: &mut device::Device, index: u32, mut data: COP0_WIRED_REG => device.cpu.cop0.regs[COP0_RANDOM_REG as usize] = 31, COP0_COMPARE_REG => { let current_count = (device.cpu.cop0.regs[COP0_COUNT_REG as usize] >> 1) & 0xFFFFFFFF; - let mut event_time = - (device.cpu.cop0.regs[COP0_COUNT_REG as usize] & 0xFFFFFFFF00000000) | (data << 1); + let mut compare_event_time = + (device.cpu.cop0.regs[COP0_COUNT_REG as usize] & 0xFFFFFFFF00000000) + (data << 1); if current_count >= data { - event_time += !0 as u32 as u64 + compare_event_time += !0 as u32 as u64 } let compare_event: &mut device::events::Event = device::events::get_event(device, device::events::EventType::Compare).unwrap(); - compare_event.count = event_time; // reschedule the next compare interrupt event + compare_event.count = compare_event_time; // reschedule the next compare interrupt event device::events::set_next_event(device); device.cpu.cop0.regs[COP0_CAUSE_REG as usize] &= !COP0_CAUSE_IP7; } @@ -215,11 +216,7 @@ pub fn set_control_registers(device: &mut device::Device, index: u32, mut data: } _ => {} } - device::memory::masked_write_64( - &mut device.cpu.cop0.regs[index as usize], - data, - device.cpu.cop0.reg_write_masks[index as usize], - ); + device::memory::masked_write_64(&mut device.cpu.cop0.regs[index as usize], data, !0 as u64); device::exceptions::check_pending_interrupts(device); } diff --git a/src/device/events.rs b/src/device/events.rs index 59c8eb3..a8fd78c 100644 --- a/src/device/events.rs +++ b/src/device/events.rs @@ -66,7 +66,9 @@ pub fn set_next_event(device: &mut device::Device) { pub fn translate_events(device: &mut device::Device, old_count: u64, new_count: u64) { for i in device.cpu.events.iter_mut() { - i.count = i.count - old_count + new_count + if i.enabled { + i.count = i.count - old_count + new_count; + } } set_next_event(device); } diff --git a/src/device/vi.rs b/src/device/vi.rs index cbef522..e07d6b1 100644 --- a/src/device/vi.rs +++ b/src/device/vi.rs @@ -5,7 +5,7 @@ use governor::clock::Clock; pub const VI_STATUS_REG: u32 = 0; //pub const VI_ORIGIN_REG: u32 = 1; //pub const VI_WIDTH_REG: u32 = 2; -pub const VI_V_INTR_REG: u32 = 3; +//pub const VI_V_INTR_REG: u32 = 3; pub const VI_CURRENT_REG: u32 = 4; //pub const VI_BURST_REG: u32 = 5; pub const VI_V_SYNC_REG: u32 = 6; @@ -46,9 +46,7 @@ pub fn set_expected_refresh_rate(device: &mut device::Device) { } pub fn set_vertical_interrupt(device: &mut device::Device) { - if device::events::get_event(device, device::events::EventType::VI) == None - && device.vi.regs[VI_V_INTR_REG as usize] < device.vi.regs[VI_V_SYNC_REG as usize] - { + if device::events::get_event(device, device::events::EventType::VI) == None { device::events::create_event( device, device::events::EventType::VI, @@ -94,13 +92,6 @@ pub fn write_regs(device: &mut device::Device, address: u64, value: u32, mask: u let reg = (address & 0xFFFF) >> 2; match reg as u32 { VI_CURRENT_REG => device::mi::clear_rcp_interrupt(device, device::mi::MI_INTR_VI), - VI_V_INTR_REG => { - if device.vi.regs[reg as usize] != value & mask { - device::memory::masked_write_32(&mut device.vi.regs[reg as usize], value, mask); - set_vertical_interrupt(device); - ui::video::set_register(reg as u32, device.vi.regs[reg as usize]) - } - } VI_V_SYNC_REG => { if device.vi.regs[reg as usize] != value & mask { device::memory::masked_write_32(&mut device.vi.regs[reg as usize], value, mask);