add memory namespace, update comments
This commit is contained in:
@@ -5,8 +5,9 @@
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
namespace emu {
|
||||
namespace memory {
|
||||
|
||||
void DMA::StartDMATransfer(uint8_t channelMask) {
|
||||
void DirectMemoryAccess::StartDMATransfer(uint8_t channelMask) {
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
if ((channelMask & (1 << i)) != 0) {
|
||||
Channel& ch = channels[i];
|
||||
@@ -20,8 +21,9 @@ void DMA::StartDMATransfer(uint8_t channelMask) {
|
||||
// Determine the transfer size based on the DMAPn register
|
||||
bool transferTwoBytes = (ch.DMAPn & 0x40) != 0;
|
||||
|
||||
// Perform the DMA transfer based on the channel parameters
|
||||
std::cout << "Starting DMA transfer for channel " << i << std::endl;
|
||||
// Perform the DirectMemoryAccess transfer based on the channel parameters
|
||||
std::cout << "Starting DirectMemoryAccess transfer for channel " << i
|
||||
<< std::endl;
|
||||
|
||||
for (uint16_t j = 0; j < ch.DASn; ++j) {
|
||||
// Read a byte or two bytes from memory based on the transfer size
|
||||
@@ -46,7 +48,7 @@ void DMA::StartDMATransfer(uint8_t channelMask) {
|
||||
MDMAEN = channelMask; // Set the MDMAEN register to the channel mask
|
||||
}
|
||||
|
||||
void DMA::EnableHDMATransfers(uint8_t channelMask) {
|
||||
void DirectMemoryAccess::EnableHDMATransfers(uint8_t channelMask) {
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
if ((channelMask & (1 << i)) != 0) {
|
||||
Channel& ch = channels[i];
|
||||
@@ -70,6 +72,7 @@ void DMA::EnableHDMATransfers(uint8_t channelMask) {
|
||||
HDMAEN = channelMask; // Set the HDMAEN register to the channel mask
|
||||
}
|
||||
|
||||
} // namespace memory
|
||||
} // namespace emu
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
@@ -6,11 +6,11 @@
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
namespace emu {
|
||||
namespace memory {
|
||||
|
||||
// Direct Memory Address
|
||||
class DMA {
|
||||
class DirectMemoryAccess {
|
||||
public:
|
||||
DMA() {
|
||||
DirectMemoryAccess() {
|
||||
// Initialize DMA and HDMA channels
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
channels[i].DMAPn = 0;
|
||||
@@ -52,6 +52,8 @@ class DMA {
|
||||
uint8_t MDMAEN = 0; // Start DMA transfer
|
||||
uint8_t HDMAEN = 0; // Enable HDMA transfers
|
||||
};
|
||||
|
||||
} // namespace memory
|
||||
} // namespace emu
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
namespace emu {
|
||||
namespace memory {
|
||||
|
||||
void DrawSnesMemoryMapping(const MemoryImpl& memory) {
|
||||
// Using those as a base value to create width/height that are factor of the
|
||||
@@ -77,6 +78,7 @@ void DrawSnesMemoryMapping(const MemoryImpl& memory) {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace memory
|
||||
} // namespace emu
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
@@ -28,12 +28,13 @@
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
namespace emu {
|
||||
namespace memory {
|
||||
|
||||
enum ROMSpeed { SLOW_ROM = 0x00, FAST_ROM = 0x07 };
|
||||
enum RomSpeed { SLOW_ROM = 0x00, FAST_ROM = 0x07 };
|
||||
|
||||
enum BankSize { LOW_ROM = 0x00, HI_ROM = 0x01 };
|
||||
|
||||
enum ROMType {
|
||||
enum RomType {
|
||||
ROM_DEFAULT = 0x00,
|
||||
ROM_RAM = 0x01,
|
||||
ROM_SRAM = 0x02,
|
||||
@@ -43,7 +44,7 @@ enum ROMType {
|
||||
FX = 0x06
|
||||
};
|
||||
|
||||
enum ROMSize {
|
||||
enum RomSize {
|
||||
SIZE_2_MBIT = 0x08,
|
||||
SIZE_4_MBIT = 0x09,
|
||||
SIZE_8_MBIT = 0x0A,
|
||||
@@ -51,7 +52,7 @@ enum ROMSize {
|
||||
SIZE_32_MBIT = 0x0C
|
||||
};
|
||||
|
||||
enum SRAMSize {
|
||||
enum SramSize {
|
||||
NO_SRAM = 0x00,
|
||||
SRAM_16_KBIT = 0x01,
|
||||
SRAM_32_KBIT = 0x02,
|
||||
@@ -73,14 +74,14 @@ enum License {
|
||||
// ... and other licenses
|
||||
};
|
||||
|
||||
class ROMInfo {
|
||||
class RomInfo {
|
||||
public:
|
||||
std::string title;
|
||||
ROMSpeed romSpeed;
|
||||
RomSpeed romSpeed;
|
||||
BankSize bankSize;
|
||||
ROMType romType;
|
||||
ROMSize romSize;
|
||||
SRAMSize sramSize;
|
||||
RomType romType;
|
||||
RomSize romSize;
|
||||
SramSize sramSize;
|
||||
CountryCode countryCode;
|
||||
License license;
|
||||
uint8_t version;
|
||||
@@ -105,7 +106,9 @@ constexpr uint32_t kVRAMSize = 0x10000;
|
||||
constexpr uint32_t kOAMStart = 0x218000;
|
||||
constexpr uint32_t kOAMSize = 0x220;
|
||||
|
||||
// memory.h
|
||||
/**
|
||||
* @brief Memory interface
|
||||
*/
|
||||
class Memory {
|
||||
public:
|
||||
virtual ~Memory() = default;
|
||||
@@ -137,6 +140,29 @@ class Memory {
|
||||
|
||||
enum class MemoryMapping { SNES_LOROM = 0, PC_ADDRESS = 1 };
|
||||
|
||||
/**
|
||||
* @class MemoryImpl
|
||||
* @brief Implementation of the Memory interface for emulating memory in a SNES
|
||||
* system.
|
||||
*
|
||||
* The MemoryImpl class provides methods for initializing and accessing memory
|
||||
* in a SNES system. It implements the Memory interface and inherits from the
|
||||
* Loggable class.
|
||||
*
|
||||
* The class supports different memory mappings, including LoROM and PC_ADDRESS
|
||||
* mappings. It provides methods for reading and writing bytes, words, and longs
|
||||
* from/to memory. It also supports stack operations for pushing and popping
|
||||
* values.
|
||||
*
|
||||
* The class maintains separate vectors for ROM, RAM, VRAM, and OAM memory
|
||||
* regions. It provides methods for accessing these memory regions and
|
||||
* retrieving their sizes.
|
||||
*
|
||||
* The class also allows adding observers to be notified when memory is read or
|
||||
* written.
|
||||
*
|
||||
* @note This class assumes a 16-bit address space.
|
||||
*/
|
||||
class MemoryImpl : public Memory, public Loggable {
|
||||
public:
|
||||
void Initialize(const std::vector<uint8_t>& romData, bool verbose = false,
|
||||
@@ -396,6 +422,7 @@ class MemoryImpl : public Memory, public Loggable {
|
||||
|
||||
void DrawSnesMemoryMapping(const MemoryImpl& memory);
|
||||
|
||||
} // namespace memory
|
||||
} // namespace emu
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
|
||||
@@ -8,10 +8,14 @@
|
||||
#include "app/emu/cpu/cpu.h"
|
||||
#include "app/emu/memory/memory.h"
|
||||
|
||||
using yaze::app::emu::Clock;
|
||||
using yaze::app::emu::Cpu;
|
||||
using yaze::app::emu::Memory;
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
namespace emu {
|
||||
namespace memory {
|
||||
|
||||
/**
|
||||
* @brief Mock CPU class for testing
|
||||
*/
|
||||
class MockClock : public Clock {
|
||||
public:
|
||||
MOCK_METHOD(void, UpdateClock, (double delta), (override));
|
||||
@@ -21,9 +25,23 @@ class MockClock : public Clock {
|
||||
MOCK_METHOD(float, GetFrequency, (), (const, override));
|
||||
};
|
||||
|
||||
// 0x1000000 is 16 MB, simplifying the memory layout for testing
|
||||
// 2 MB is = 0x200000
|
||||
|
||||
/**
|
||||
* @class MockMemory
|
||||
* @brief A mock implementation of the Memory class.
|
||||
*
|
||||
* This class is used for testing purposes and provides a mock implementation of
|
||||
* the Memory class. It allows for reading and writing bytes, words, and longs
|
||||
* to memory, as well as pushing and popping values onto and from the stack. It
|
||||
* also provides methods for setting and getting the stack pointer, initializing
|
||||
* memory with ROM data, and clearing memory.
|
||||
*
|
||||
* The mock memory is represented by a vector of uint8_t values, where each
|
||||
* element represents a byte of memory. The memory can be accessed using the []
|
||||
* operator, and its contents can be set using the SetMemoryContents() method.
|
||||
*
|
||||
* @note This class is intended for testing purposes only and should not be used
|
||||
* in production code.
|
||||
*/
|
||||
class MockMemory : public Memory {
|
||||
public:
|
||||
MOCK_CONST_METHOD1(ReadByte, uint8_t(uint32_t address));
|
||||
@@ -85,6 +103,8 @@ class MockMemory : public Memory {
|
||||
}
|
||||
}
|
||||
|
||||
// 16MB = 0x1000000
|
||||
// 02MB = 0x200000
|
||||
void Initialize(const std::vector<uint8_t>& romData) {
|
||||
// 16 MB, simplifying the memory layout for testing
|
||||
memory_.resize(0x1000000);
|
||||
@@ -186,4 +206,9 @@ class MockMemory : public Memory {
|
||||
uint16_t SP_ = 0x01FF;
|
||||
};
|
||||
|
||||
} // namespace memory
|
||||
} // namespace emu
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_TEST_MOCK_MOCK_MEMORY_H
|
||||
Reference in New Issue
Block a user