From 3340066415811b3d5be9f990b3419e105aab1fc4 Mon Sep 17 00:00:00 2001 From: scawful Date: Fri, 8 Nov 2024 21:09:04 -0500 Subject: [PATCH] Refactor CPU and memory components: remove logging dependencies and restructure DMA channel definitions --- src/app/emu/cpu/cpu.h | 3 +- src/app/emu/debug/debugger.h | 56 ---------------------- src/app/emu/debug/log.h | 43 ----------------- src/app/emu/{debug => }/emu.cc | 0 src/app/emu/{debug => memory}/asm_parser.h | 0 src/app/emu/memory/dma.h | 21 -------- src/app/emu/memory/dma_channel.h | 37 ++++++++++++++ src/app/emu/memory/memory.cc | 2 - src/app/emu/memory/memory.h | 3 +- src/app/emu/snes.cc | 1 - src/app/emu/snes.h | 2 - 11 files changed, 39 insertions(+), 129 deletions(-) delete mode 100644 src/app/emu/debug/debugger.h delete mode 100644 src/app/emu/debug/log.h rename src/app/emu/{debug => }/emu.cc (100%) rename src/app/emu/{debug => memory}/asm_parser.h (100%) create mode 100644 src/app/emu/memory/dma_channel.h diff --git a/src/app/emu/cpu/cpu.h b/src/app/emu/cpu/cpu.h index a9168a69..7623283b 100644 --- a/src/app/emu/cpu/cpu.h +++ b/src/app/emu/cpu/cpu.h @@ -10,7 +10,6 @@ #include "app/core/common.h" #include "app/emu/cpu/clock.h" #include "app/emu/cpu/internal/opcodes.h" -#include "app/emu/debug/log.h" #include "app/emu/memory/memory.h" namespace yaze { @@ -36,7 +35,7 @@ class InstructionEntry { std::string instruction; // Human-readable instruction text }; -class Cpu : public Loggable, public core::ExperimentFlags { +class Cpu : public core::ExperimentFlags { public: explicit Cpu(memory::Memory& mem, Clock& vclock, memory::CpuCallbacks& callbacks) diff --git a/src/app/emu/debug/debugger.h b/src/app/emu/debug/debugger.h deleted file mode 100644 index 4c5d0e46..00000000 --- a/src/app/emu/debug/debugger.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef YAZE_APP_EMU_DEBUG_DEBUGGER_H_ -#define YAZE_APP_EMU_DEBUG_DEBUGGER_H_ - -#include "app/emu/audio/apu.h" -#include "app/emu/cpu/cpu.h" -#include "app/emu/video/ppu.h" - -namespace yaze { -namespace app { -namespace emu { - -class Debugger { - public: - Debugger() = default; - // Attach the debugger to the emulator - // Debugger(CPU &cpu, PPU &ppu, Apu &apu); - - // Set a breakpoint - void SetBreakpoint(uint16_t address); - - // Remove a breakpoint - void RemoveBreakpoint(uint16_t address); - - // Step through the code - void Step(); - - // Inspect memory - uint8_t InspectMemory(uint16_t address); - - // Modify memory - void ModifyMemory(uint16_t address, uint8_t value); - - // Inspect registers - uint8_t InspectRegister(uint8_t reg); - - // Modify registers - void ModifyRegister(uint8_t reg, uint8_t value); - - // Handle other debugger tasks - // ... - - private: - // References to the emulator's components - // CPU &cpu; - // PPU &ppu; - // Apu &apu; - - // Breakpoints, watchpoints, etc. - // ... -}; - -} // namespace emu -} // namespace app -} // namespace yaze - -#endif // YAZE_APP_EMU_DBG_H_ \ No newline at end of file diff --git a/src/app/emu/debug/log.h b/src/app/emu/debug/log.h deleted file mode 100644 index 92c7649f..00000000 --- a/src/app/emu/debug/log.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef YAZE_APP_EMU_LOG_H_ -#define YAZE_APP_EMU_LOG_H_ - -#include -#include - -namespace yaze { -namespace app { -namespace emu { - -// Logger.h -class Logger { - public: - static Logger& GetInstance() { - static Logger instance; - return instance; - } - - void Log(const std::string& message) const { - // Write log messages to a file or console - std::cout << message << std::endl; - } - - private: - Logger() = default; - Logger(const Logger&) = delete; - Logger& operator=(const Logger&) = delete; -}; - -// Loggable.h -class Loggable { - protected: - Logger& logger_ = Logger::GetInstance(); - - virtual ~Loggable() = default; - virtual void LogMessage(const std::string& message) { logger_.Log(message); } -}; - -} // namespace emu -} // namespace app -} // namespace yaze - -#endif // YAZE_APP_EMU_LOG_H_ \ No newline at end of file diff --git a/src/app/emu/debug/emu.cc b/src/app/emu/emu.cc similarity index 100% rename from src/app/emu/debug/emu.cc rename to src/app/emu/emu.cc diff --git a/src/app/emu/debug/asm_parser.h b/src/app/emu/memory/asm_parser.h similarity index 100% rename from src/app/emu/debug/asm_parser.h rename to src/app/emu/memory/asm_parser.h diff --git a/src/app/emu/memory/dma.h b/src/app/emu/memory/dma.h index 296c5695..4cbd148e 100644 --- a/src/app/emu/memory/dma.h +++ b/src/app/emu/memory/dma.h @@ -12,27 +12,6 @@ namespace emu { namespace memory { namespace dma { -typedef struct DmaChannel { - uint8_t b_addr; - uint16_t a_addr; - uint8_t a_bank; - uint16_t size; // also indirect hdma adr - uint8_t ind_bank; // hdma - uint16_t table_addr; // hdma - uint8_t rep_count; // hdma - uint8_t unusedByte; - bool dma_active; - bool hdma_active; - uint8_t mode; - bool fixed; - bool decrement; - bool indirect; // hdma - bool from_b; - bool unusedBit; - bool do_transfer; // hdma - bool terminated; // hdma -} DmaChannel; - void Reset(MemoryImpl* memory); void HandleDma(SNES* snes, MemoryImpl* memory, int cpu_cycles); diff --git a/src/app/emu/memory/dma_channel.h b/src/app/emu/memory/dma_channel.h new file mode 100644 index 00000000..385ab472 --- /dev/null +++ b/src/app/emu/memory/dma_channel.h @@ -0,0 +1,37 @@ +#ifndef YAZE_APP_EMU_MEMORY_DMA_CHANNEL_H +#define YAZE_APP_EMU_MEMORY_DMA_CHANNEL_H + +#include + +namespace yaze { +namespace app { +namespace emu { +namespace memory { + +typedef struct DmaChannel { + uint8_t b_addr; + uint16_t a_addr; + uint8_t a_bank; + uint16_t size; // also indirect hdma adr + uint8_t ind_bank; // hdma + uint16_t table_addr; // hdma + uint8_t rep_count; // hdma + uint8_t unusedByte; + bool dma_active; + bool hdma_active; + uint8_t mode; + bool fixed; + bool decrement; + bool indirect; // hdma + bool from_b; + bool unusedBit; + bool do_transfer; // hdma + bool terminated; // hdma +} DmaChannel; + +} // namespace memory +} // namespace emu +} // namespace app +} // namespace yaze + +#endif // YAZE_APP_EMU_MEMORY_DMA_CHANNEL_H \ No newline at end of file diff --git a/src/app/emu/memory/memory.cc b/src/app/emu/memory/memory.cc index e975abf9..4254e132 100644 --- a/src/app/emu/memory/memory.cc +++ b/src/app/emu/memory/memory.cc @@ -7,8 +7,6 @@ #include #include -#include "app/emu/debug/log.h" - namespace yaze { namespace app { namespace emu { diff --git a/src/app/emu/memory/memory.h b/src/app/emu/memory/memory.h index 8564e8c8..241fec23 100644 --- a/src/app/emu/memory/memory.h +++ b/src/app/emu/memory/memory.h @@ -7,7 +7,6 @@ #include #include -#include "app/emu/debug/log.h" #include "app/emu/memory/dma_channel.h" // LoROM (Mode 20): @@ -161,7 +160,7 @@ class Memory { * system. * */ -class MemoryImpl : public Memory, public Loggable { +class MemoryImpl : public Memory { public: uint32_t romSize; uint32_t sramSize; diff --git a/src/app/emu/snes.cc b/src/app/emu/snes.cc index 8797e9ce..e152e03b 100644 --- a/src/app/emu/snes.cc +++ b/src/app/emu/snes.cc @@ -9,7 +9,6 @@ #include "app/emu/audio/spc700.h" #include "app/emu/cpu/clock.h" #include "app/emu/cpu/cpu.h" -#include "app/emu/debug/debugger.h" #include "app/emu/memory/dma.h" #include "app/emu/memory/memory.h" #include "app/emu/video/ppu.h" diff --git a/src/app/emu/snes.h b/src/app/emu/snes.h index 2dee6099..261dfa70 100644 --- a/src/app/emu/snes.h +++ b/src/app/emu/snes.h @@ -10,7 +10,6 @@ #include "app/emu/audio/spc700.h" #include "app/emu/cpu/clock.h" #include "app/emu/cpu/cpu.h" -#include "app/emu/debug/debugger.h" #include "app/emu/memory/memory.h" #include "app/emu/video/ppu.h" #include "app/rom.h" @@ -80,7 +79,6 @@ class SNES { private: // Components of the SNES ClockImpl clock_; - Debugger debugger; memory::MemoryImpl memory_; memory::CpuCallbacks cpu_callbacks_ = {