From a7c2c26d7881abcd9efba63a000a4ba97a820607 Mon Sep 17 00:00:00 2001 From: Logan McNaughton <848146+loganmc10@users.noreply.github.com> Date: Sun, 2 Feb 2025 11:23:32 +0100 Subject: [PATCH] minor tweak to interrupt system (#211) --- src/device.rs | 1 + src/device/cop0.rs | 1 + src/device/events.rs | 2 ++ src/device/exceptions.rs | 2 +- src/ui/audio.rs | 2 +- 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/device.rs b/src/device.rs index 47dda62..86f2673 100644 --- a/src/device.rs +++ b/src/device.rs @@ -196,6 +196,7 @@ impl Device { regs: [0; cop0::COP0_REGS_COUNT as usize], reg_write_masks: [0; cop0::COP0_REGS_COUNT as usize], reg_latch: 0, + is_event: false, pending_compare_interrupt: false, instrs: [cop0::reserved; 32], instrs2: [cop0::reserved; 32], diff --git a/src/device/cop0.rs b/src/device/cop0.rs index c4c34c6..36820f5 100644 --- a/src/device/cop0.rs +++ b/src/device/cop0.rs @@ -97,6 +97,7 @@ pub struct Cop0 { pub tlb_lut_r: Vec, pub tlb_lut_w: Vec, pub tlb_entries: [device::tlb::TlbEntry; 32], + pub is_event: bool, pub pending_compare_interrupt: bool, } diff --git a/src/device/events.rs b/src/device/events.rs index 70d4f13..3aa48ed 100644 --- a/src/device/events.rs +++ b/src/device/events.rs @@ -53,7 +53,9 @@ pub fn trigger_event(device: &mut device::Device) { device.cpu.events[next_event_name].enabled = false; let handler = device.cpu.events[next_event_name].handler; + device.cpu.cop0.is_event = true; handler(device); + device.cpu.cop0.is_event = false; set_next_event(device); } diff --git a/src/device/exceptions.rs b/src/device/exceptions.rs index 892a7fa..1e72d2c 100644 --- a/src/device/exceptions.rs +++ b/src/device/exceptions.rs @@ -30,7 +30,7 @@ pub fn check_pending_interrupts(device: &mut device::Device) { return; } - if device.cpu.cop0.regs[device::cop0::COP0_CAUSE_REG as usize] == device::cop0::COP0_CAUSE_IP7 { + if device.cpu.cop0.is_event { interrupt_exception(device); } else { device::events::create_event( diff --git a/src/ui/audio.rs b/src/ui/audio.rs index f0fbe19..fd309d9 100644 --- a/src/ui/audio.rs +++ b/src/ui/audio.rs @@ -116,7 +116,7 @@ pub fn play_audio(device: &mut device::Device, dram_addr: usize, length: u64) { let min_latency = (device.ui.audio_freq * 0.02) * 4.0; if audio_queued < min_latency { - let silence_buffer: Vec = vec![0; (min_latency - audio_queued) as usize & !3]; + let silence_buffer: Vec = vec![0; min_latency as usize & !3]; if !unsafe { sdl3_sys::audio::SDL_PutAudioStreamData( device.ui.audio_stream,