Refactor CPU and memory components: remove logging dependencies and restructure DMA channel definitions

This commit is contained in:
scawful
2024-11-08 21:09:04 -05:00
parent 8785e19a18
commit 3340066415
11 changed files with 39 additions and 129 deletions

View File

@@ -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)

View File

@@ -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_

View File

@@ -1,43 +0,0 @@
#ifndef YAZE_APP_EMU_LOG_H_
#define YAZE_APP_EMU_LOG_H_
#include <iostream>
#include <string>
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_

View File

@@ -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);

View File

@@ -0,0 +1,37 @@
#ifndef YAZE_APP_EMU_MEMORY_DMA_CHANNEL_H
#define YAZE_APP_EMU_MEMORY_DMA_CHANNEL_H
#include <cstdint>
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

View File

@@ -7,8 +7,6 @@
#include <string>
#include <vector>
#include "app/emu/debug/log.h"
namespace yaze {
namespace app {
namespace emu {

View File

@@ -7,7 +7,6 @@
#include <string>
#include <vector>
#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;

View File

@@ -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"

View File

@@ -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_ = {