aboutsummaryrefslogtreecommitdiff
path: root/src/teakra
diff options
context:
space:
mode:
Diffstat (limited to 'src/teakra')
-rw-r--r--src/teakra/include/teakra/teakra.h9
-rw-r--r--src/teakra/src/shared_memory.h22
-rw-r--r--src/teakra/src/teakra.cpp12
3 files changed, 21 insertions, 22 deletions
diff --git a/src/teakra/include/teakra/teakra.h b/src/teakra/include/teakra/teakra.h
index 32b9064..b0cbcf1 100644
--- a/src/teakra/include/teakra/teakra.h
+++ b/src/teakra/include/teakra/teakra.h
@@ -7,6 +7,11 @@
namespace Teakra {
+struct SharedMemoryCallback {
+ std::function<std::uint16_t(std::uint32_t address)> read16;
+ std::function<void(std::uint32_t address, std::uint16_t value)> write16;
+};
+
struct AHBMCallback {
std::function<std::uint8_t(std::uint32_t address)> read8;
std::function<void(std::uint32_t address, std::uint8_t value)> write8;
@@ -25,9 +30,6 @@ public:
void Reset();
- std::array<std::uint8_t, 0x80000>& GetDspMemory();
- const std::array<std::uint8_t, 0x80000>& GetDspMemory() const;
-
// APBP Data
bool SendDataIsEmpty(std::uint8_t index) const;
void SendData(std::uint8_t index, std::uint16_t value);
@@ -70,6 +72,7 @@ public:
// core
void Run(unsigned cycle);
+ void SetSharedMemoryCallback(const SharedMemoryCallback& callback);
void SetAHBMCallback(const AHBMCallback& callback);
void SetAudioCallback(std::function<void(std::array<std::int16_t, 2>)> callback);
diff --git a/src/teakra/src/shared_memory.h b/src/teakra/src/shared_memory.h
index 8dfcb05..29ea435 100644
--- a/src/teakra/src/shared_memory.h
+++ b/src/teakra/src/shared_memory.h
@@ -5,19 +5,21 @@
namespace Teakra {
struct SharedMemory {
- std::array<u8, 0x80000> raw{};
u16 ReadWord(u32 word_address) const {
- u32 byte_address = word_address * 2;
- u8 low = raw[byte_address];
- u8 high = raw[byte_address + 1];
- return low | ((u16)high << 8);
+ return read_external16(word_address << 1);
}
void WriteWord(u32 word_address, u16 value) {
- u8 low = value & 0xFF;
- u8 high = value >> 8;
- u32 byte_address = word_address * 2;
- raw[byte_address] = low;
- raw[byte_address + 1] = high;
+ write_external16(word_address << 1, value);
}
+
+ void SetExternalMemoryCallback(
+ std::function<u16(u32)> read16, std::function<void(u32, u16)> write16) {
+
+ read_external16 = std::move(read16);
+ write_external16 = std::move(write16);
+ }
+
+ std::function<u16(u32)> read_external16;
+ std::function<void(u32, u16)> write_external16;
};
} // namespace Teakra
diff --git a/src/teakra/src/teakra.cpp b/src/teakra/src/teakra.cpp
index 9559920..fec900d 100644
--- a/src/teakra/src/teakra.cpp
+++ b/src/teakra/src/teakra.cpp
@@ -50,7 +50,6 @@ struct Teakra::Impl {
}
void Reset() {
- //shared_memory.raw.fill(0); // BAD!!!!
miu.Reset();
apbp_from_cpu.Reset();
apbp_from_dsp.Reset();
@@ -71,14 +70,6 @@ void Teakra::Reset() {
impl->Reset();
}
-std::array<std::uint8_t, 0x80000>& Teakra::GetDspMemory() {
- return impl->shared_memory.raw;
-}
-
-const std::array<std::uint8_t, 0x80000>& Teakra::GetDspMemory() const {
- return impl->shared_memory.raw;
-}
-
void Teakra::Run(unsigned cycle) {
impl->processor.Run(cycle);
}
@@ -117,6 +108,9 @@ void Teakra::ClearSemaphore(std::uint16_t value) {
void Teakra::MaskSemaphore(std::uint16_t value) {
impl->apbp_from_dsp.MaskSemaphore(value);
}
+void Teakra::SetSharedMemoryCallback(const SharedMemoryCallback& callback) {
+ impl->shared_memory.SetExternalMemoryCallback(callback.read16, callback.write16);
+}
void Teakra::SetAHBMCallback(const AHBMCallback& callback) {
impl->ahbm.SetExternalMemoryCallback(callback.read8, callback.write8,
callback.read16, callback.write16,