Refactor CPU and memory components: remove logging dependencies and restructure DMA channel definitions
This commit is contained in:
@@ -10,7 +10,6 @@
|
|||||||
#include "app/core/common.h"
|
#include "app/core/common.h"
|
||||||
#include "app/emu/cpu/clock.h"
|
#include "app/emu/cpu/clock.h"
|
||||||
#include "app/emu/cpu/internal/opcodes.h"
|
#include "app/emu/cpu/internal/opcodes.h"
|
||||||
#include "app/emu/debug/log.h"
|
|
||||||
#include "app/emu/memory/memory.h"
|
#include "app/emu/memory/memory.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
@@ -36,7 +35,7 @@ class InstructionEntry {
|
|||||||
std::string instruction; // Human-readable instruction text
|
std::string instruction; // Human-readable instruction text
|
||||||
};
|
};
|
||||||
|
|
||||||
class Cpu : public Loggable, public core::ExperimentFlags {
|
class Cpu : public core::ExperimentFlags {
|
||||||
public:
|
public:
|
||||||
explicit Cpu(memory::Memory& mem, Clock& vclock,
|
explicit Cpu(memory::Memory& mem, Clock& vclock,
|
||||||
memory::CpuCallbacks& callbacks)
|
memory::CpuCallbacks& callbacks)
|
||||||
|
|||||||
@@ -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_
|
|
||||||
@@ -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_
|
|
||||||
@@ -12,27 +12,6 @@ namespace emu {
|
|||||||
namespace memory {
|
namespace memory {
|
||||||
namespace dma {
|
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 Reset(MemoryImpl* memory);
|
||||||
void HandleDma(SNES* snes, MemoryImpl* memory, int cpu_cycles);
|
void HandleDma(SNES* snes, MemoryImpl* memory, int cpu_cycles);
|
||||||
|
|
||||||
|
|||||||
37
src/app/emu/memory/dma_channel.h
Normal file
37
src/app/emu/memory/dma_channel.h
Normal 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
|
||||||
@@ -7,8 +7,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "app/emu/debug/log.h"
|
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace app {
|
namespace app {
|
||||||
namespace emu {
|
namespace emu {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "app/emu/debug/log.h"
|
|
||||||
#include "app/emu/memory/dma_channel.h"
|
#include "app/emu/memory/dma_channel.h"
|
||||||
|
|
||||||
// LoROM (Mode 20):
|
// LoROM (Mode 20):
|
||||||
@@ -161,7 +160,7 @@ class Memory {
|
|||||||
* system.
|
* system.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class MemoryImpl : public Memory, public Loggable {
|
class MemoryImpl : public Memory {
|
||||||
public:
|
public:
|
||||||
uint32_t romSize;
|
uint32_t romSize;
|
||||||
uint32_t sramSize;
|
uint32_t sramSize;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#include "app/emu/audio/spc700.h"
|
#include "app/emu/audio/spc700.h"
|
||||||
#include "app/emu/cpu/clock.h"
|
#include "app/emu/cpu/clock.h"
|
||||||
#include "app/emu/cpu/cpu.h"
|
#include "app/emu/cpu/cpu.h"
|
||||||
#include "app/emu/debug/debugger.h"
|
|
||||||
#include "app/emu/memory/dma.h"
|
#include "app/emu/memory/dma.h"
|
||||||
#include "app/emu/memory/memory.h"
|
#include "app/emu/memory/memory.h"
|
||||||
#include "app/emu/video/ppu.h"
|
#include "app/emu/video/ppu.h"
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
#include "app/emu/audio/spc700.h"
|
#include "app/emu/audio/spc700.h"
|
||||||
#include "app/emu/cpu/clock.h"
|
#include "app/emu/cpu/clock.h"
|
||||||
#include "app/emu/cpu/cpu.h"
|
#include "app/emu/cpu/cpu.h"
|
||||||
#include "app/emu/debug/debugger.h"
|
|
||||||
#include "app/emu/memory/memory.h"
|
#include "app/emu/memory/memory.h"
|
||||||
#include "app/emu/video/ppu.h"
|
#include "app/emu/video/ppu.h"
|
||||||
#include "app/rom.h"
|
#include "app/rom.h"
|
||||||
@@ -80,7 +79,6 @@ class SNES {
|
|||||||
private:
|
private:
|
||||||
// Components of the SNES
|
// Components of the SNES
|
||||||
ClockImpl clock_;
|
ClockImpl clock_;
|
||||||
Debugger debugger;
|
|
||||||
memory::MemoryImpl memory_;
|
memory::MemoryImpl memory_;
|
||||||
|
|
||||||
memory::CpuCallbacks cpu_callbacks_ = {
|
memory::CpuCallbacks cpu_callbacks_ = {
|
||||||
|
|||||||
Reference in New Issue
Block a user