From 4c36a0319d04a0ea45717856490e9e043788b277 Mon Sep 17 00:00:00 2001 From: vincentadamczyk Date: Mon, 10 Jun 2024 16:53:46 +0200 Subject: [PATCH] kleine fixes an RET step() switch unt an RETI der ei() aufruf entfernt --- src/cpu.rs | 3 +++ src/cpu/instructions/jumps_subroutines.rs | 5 ++++- src/cpu/instructions/misc.rs | 1 + src/cpu/step.rs | 7 ++++++- src/main.rs | 7 ++++++- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/cpu.rs b/src/cpu.rs index 570ee44..8b2c48d 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -37,6 +37,8 @@ pub struct CPU { last_execution_time: std::time::Instant, cycles: u64, stop_mode: bool, + pub instruction: i32, + } /// Note, please look at the relevant modules for the actual implementations @@ -53,6 +55,7 @@ impl CPU { last_execution_time: std::time::Instant::now(), cycles: 0, stop_mode: false, + instruction: 0, } } diff --git a/src/cpu/instructions/jumps_subroutines.rs b/src/cpu/instructions/jumps_subroutines.rs index de66023..7c92303 100644 --- a/src/cpu/instructions/jumps_subroutines.rs +++ b/src/cpu/instructions/jumps_subroutines.rs @@ -152,7 +152,10 @@ impl CPU { } /// Enables interrupts and pops PC from the stack, returning to the last pushed instruction pub fn reti(&mut self) -> InstructionResult { - self.ei(); + // self.ei(); Der Ei aufruf funktioniert hier nicht, da unser superloop nicht durhclaufen wird und + // somit die Cycels nicht aktualisiert werden. D.H. EI aktualsiert das IME flag zu spät. ==> + // direkt IME Flag setzen oder enable ime flag = 1 d.h. nach dieser Instruction + self.ime_flag = true; self.pop_r16(Register16Bit::PC); InstructionResult { diff --git a/src/cpu/instructions/misc.rs b/src/cpu/instructions/misc.rs index 50d77e6..02ca9d9 100644 --- a/src/cpu/instructions/misc.rs +++ b/src/cpu/instructions/misc.rs @@ -42,6 +42,7 @@ impl CPU { /// deactivates the IME flag, enabling Interrupts pub fn di(&mut self) -> InstructionResult { self.ime_flag = false; + self.enable_ime = 0; InstructionResult { cycles: 1, bytes: 1, diff --git a/src/cpu/step.rs b/src/cpu/step.rs index f6073e0..67c5081 100644 --- a/src/cpu/step.rs +++ b/src/cpu/step.rs @@ -1,6 +1,8 @@ use core::task; use std::{thread::sleep, time::Duration}; +use crate::cpu::instructions::ConditionCodes; + use super::{ instructions::{FlagState, InstParam, InstructionCondition, InstructionResult, Instructions}, registers::{self, Register16Bit, Register8Bit}, @@ -389,7 +391,10 @@ impl CPU { _ => return Err(format!("Handling of {:?} not implemented", target)), }, Instructions::RET(condition) => match condition { - InstParam::ConditionCodes(cond) => self.ret_cc(self.check_condition(cond)), + InstParam::ConditionCodes(cond) => match cond{ + InstructionCondition::SkipConditionCodes => self.ret(), + _ => self.ret_cc(self.check_condition(cond)), + } _ => self.ret(), }, Instructions::RETI => self.reti(), diff --git a/src/main.rs b/src/main.rs index 70cd91f..f16fb41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,7 @@ const DOTS_PER_LINE: u32 = 456; const TIME_PER_FRAME: f32 = 1.0 / 60.0 * 1000.0; const DUMP_GAMEBOY_DOCTOR_LOG: bool = true; -const WINDOWS: bool = false; +const WINDOWS: bool = true; #[macroquad::main("GB Emulator")] async fn main() { @@ -111,6 +111,11 @@ async fn main() { } loop { + cpu.instruction += 1; + if cpu.instruction == 31415{ + cpu.instruction += 1; + cpu.instruction -= 1; + } if DUMP_GAMEBOY_DOCTOR_LOG { // Dump registers to file for Gameboy Doctor like this // A:00 F:11 B:22 C:33 D:44 E:55 H:66 L:77 SP:8888 PC:9999 PCMEM:AA,BB,CC,DD