From e0dcc5f2e471abd55acbade310d4661e85da03a4 Mon Sep 17 00:00:00 2001 From: vibhatsu Date: Sun, 25 Aug 2024 01:32:21 +0530 Subject: [PATCH 1/8] Signals and slots implemented --- .gitignore | 2 +- .vscode/settings.json | 31 ++++++++++++++++++++++++++++++- src/audio.cpp | 38 ++++++++++++++++++++++---------------- src/audio.h | 6 +++++- src/gameBoy.cpp | 2 +- src/mmap.cpp | 30 ++++++++++++++++-------------- src/mmap.h | 15 ++------------- 7 files changed, 77 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index 2f4aa67..a66f954 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,6 @@ cmake-build-debug/ src/.vscode/ src/dmg_boot.gb tests/* -.vscode/ +.vscode/* run.sh output.txt \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 31053f6..3300a6c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -54,6 +54,35 @@ "ios": "cpp", "queue": "cpp", "semaphore": "cpp", - "cinttypes": "cpp" + "cinttypes": "cpp", + "any": "cpp", + "hash_map": "cpp", + "strstream": "cpp", + "charconv": "cpp", + "codecvt": "cpp", + "complex": "cpp", + "condition_variable": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "unordered_set": "cpp", + "optional": "cpp", + "source_location": "cpp", + "format": "cpp", + "fstream": "cpp", + "future": "cpp", + "iomanip": "cpp", + "iostream": "cpp", + "istream": "cpp", + "mutex": "cpp", + "shared_mutex": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdfloat": "cpp", + "text_encoding": "cpp", + "cfenv": "cpp", + "typeindex": "cpp", + "valarray": "cpp", + "variant": "cpp" } } \ No newline at end of file diff --git a/src/audio.cpp b/src/audio.cpp index 6071407..263fe28 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -20,6 +20,7 @@ APU::APU() channel2 = new PulseChannel(CH2); channel3 = new WaveChannel(); channel4 = new NoiseChannel(); + globalFunction = std::bind(&APU::onWrite, this, std::placeholders::_1, std::placeholders::_2); } bool APU::init() @@ -171,18 +172,6 @@ Byte APU::readByte(Word address) void APU::stepAPU(int cycles) { - // Audio write regsisters - while (!mMap->isQueueEmpty()) - { - printf("APU working\n"); - audioRegs writtenRegister = mMap->popAudioWriteQueue(); - writeByte(writtenRegister.address, writtenRegister.value); - Byte value = readByte(writtenRegister.address); - mMap->writeBackMemory(writtenRegister.address, value); - value = readByte(0xFF26); - mMap->writeBackMemory(0xFF26, value); - } - sampleCounter += cycles; frameSequencerCounter += cycles; @@ -207,8 +196,7 @@ void APU::stepAPU(int cycles) Word address[] = { 0xFF19, 0xFF1E, 0xFF23, 0xFF26 }; for (auto addr : address) { - Byte reg = readByte(addr); - mMap->writeBackMemory(addr, reg); + writeUpdate(addr, 0xFF); } printf("FramerSequencer ends\n"); } @@ -230,9 +218,27 @@ void APU::clearRegisters() // Could be done by simply writing 0s but for checking's sake done as such for (int address = 0xFF10; address <= 0xFF3F; address++) { - Byte reg = readByte(address); - mMap->writeBackMemory(address, reg); + writeUpdate(address, 0xFF); + } +} + +// Write on Memory Write +void APU::onWrite(Word address, Byte value) +{ + writeUpdate(address, value, true); + writeUpdate(0xFF26, 0xFF); +} + +// Write Update +void APU::writeUpdate(Word address, Byte value, bool MemWrite) +{ + if (MemWrite) + { + value = mMap->readMemory(address); + writeByte(address, value); } + value = readByte(address); + mMap->writeBackMemory(address, value); } // PulseChannel diff --git a/src/audio.h b/src/audio.h index fdee437..8e23789 100644 --- a/src/audio.h +++ b/src/audio.h @@ -2,7 +2,7 @@ #include "types.h" #include "mmap.h" #include -#include +#include // SDL Audio enum Channel { @@ -172,4 +172,8 @@ class APU void stepAPU(int cycles); void clearRegisters(); void setMemoryMap(MemoryMap* map) { mMap = map; } + // Writes back on Memory Write + void onWrite(Word address, Byte value); + // Write update + void writeUpdate(Word address, Byte value, bool WriteMem = false); }; \ No newline at end of file diff --git a/src/gameBoy.cpp b/src/gameBoy.cpp index 672145a..f373b9c 100644 --- a/src/gameBoy.cpp +++ b/src/gameBoy.cpp @@ -40,7 +40,7 @@ GBE::GBE() // printf("game rom file not opened"); // Open the Game ROM - if ((gameROM = fopen("../tests/dmg_sound/rom_singles/02-len ctr.gb", "rb")) == NULL) + if ((gameROM = fopen("../tests/dmg_sound/rom_singles/03-trigger.gb", "rb")) == NULL) printf("game rom file not opened\n"); // Set the Boot ROM diff --git a/src/mmap.cpp b/src/mmap.cpp index db92347..e22a8a0 100644 --- a/src/mmap.cpp +++ b/src/mmap.cpp @@ -1,6 +1,8 @@ #include "mmap.h" #include +std::function globalFunction = nullptr; + // Constructor MemoryMap::MemoryMap() { @@ -107,21 +109,21 @@ MemoryMap::MemoryMap() mbcMode = 0x0; } -// Push to audio write queue -void MemoryMap::pushAudioWriteQueue(Word address, Byte value) +// MemoryMap Destructor +MemoryMap::~MemoryMap() { - audioRegs temp = { address, value }; - MemoryMap::audioWriteQueue.push(temp); + delete romBank0; + delete romBank1; + delete videoRam; + delete externalRam; + delete workRam; + delete oamTable; + delete ioPorts; + delete highRam; + delete interruptEnableRegister; + delete joyPadState; } -// remove the first element from queue -audioRegs MemoryMap::popAudioWriteQueue() -{ - audioRegs t = audioWriteQueue.front(); - audioWriteQueue.pop(); - return t; -}; - // Write to memory // TODO: Make emulation memory secure bool MemoryMap::writeMemory(Word address, Byte value) @@ -193,7 +195,7 @@ bool MemoryMap::writeMemory(Word address, Byte value) ioPorts[address - 0xFF00] = value; if (address >= 0xFF10 && address <= 0xFF3F) { - MemoryMap::pushAudioWriteQueue(address, value); + globalFunction(address, value); } } } @@ -350,4 +352,4 @@ void MemoryMap::unloadBootRom() { fseek(romFile, 0x00, SEEK_SET); fread(romBank0, 1, 256, romFile); -} \ No newline at end of file +} diff --git a/src/mmap.h b/src/mmap.h index 29e280a..65dd9e7 100644 --- a/src/mmap.h +++ b/src/mmap.h @@ -1,7 +1,8 @@ #pragma once #include "types.h" #include -#include +#include +extern std::function globalFunction; // The Memory Map for GBE // Pulled from https://gbdev.io/pandocs/Memory_Map.html @@ -137,9 +138,6 @@ class MemoryMap // Stays in the I/O Ports at 0xFF4B Byte* reg_WX; - // Audio write queue - std::queue audioWriteQueue; - public: // Audio Unit // I know this is not the best way to do it @@ -274,13 +272,4 @@ class MemoryMap // sets the ROM file void setRomFile(FILE* file) { romFile = file; } - - // push to queue - void pushAudioWriteQueue(Word address, Byte value); - - // is queue empty - bool isQueueEmpty() { return audioWriteQueue.empty(); }; - - // pop queue - audioRegs popAudioWriteQueue(); }; \ No newline at end of file From 843cfa6394ef42068b5e0da903ce4c049787cfb5 Mon Sep 17 00:00:00 2001 From: vibhatsu Date: Sun, 25 Aug 2024 23:07:45 +0530 Subject: [PATCH 2/8] Freed from global variable --- src/audio.cpp | 1 - src/audio.h | 7 +++++++ src/gameBoy.cpp | 3 ++- src/mmap.cpp | 3 ++- src/mmap.h | 7 ++++++- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/audio.cpp b/src/audio.cpp index 263fe28..15e7faf 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -20,7 +20,6 @@ APU::APU() channel2 = new PulseChannel(CH2); channel3 = new WaveChannel(); channel4 = new NoiseChannel(); - globalFunction = std::bind(&APU::onWrite, this, std::placeholders::_1, std::placeholders::_2); } bool APU::init() diff --git a/src/audio.h b/src/audio.h index 8e23789..17cc753 100644 --- a/src/audio.h +++ b/src/audio.h @@ -176,4 +176,11 @@ class APU void onWrite(Word address, Byte value); // Write update void writeUpdate(Word address, Byte value, bool WriteMem = false); + + void setSignalCallback() + { + if (mMap) + mMap->connectObserver([this](Word address, Byte value) + { this->onWrite(address, value); }); + } }; \ No newline at end of file diff --git a/src/gameBoy.cpp b/src/gameBoy.cpp index f373b9c..af3bebd 100644 --- a/src/gameBoy.cpp +++ b/src/gameBoy.cpp @@ -30,6 +30,7 @@ GBE::GBE() // Unify the APU and MemoryMap gbe_audio->setMemoryMap(gbe_mMap); + gbe_audio->setSignalCallback(); // Open the Boot ROM if ((bootROM = fopen("../src/dmg_boot.gb", "rb")) == NULL) @@ -40,7 +41,7 @@ GBE::GBE() // printf("game rom file not opened"); // Open the Game ROM - if ((gameROM = fopen("../tests/dmg_sound/rom_singles/03-trigger.gb", "rb")) == NULL) + if ((gameROM = fopen("../tests/dmg_sound/rom_singles/02-len ctr.gb", "rb")) == NULL) printf("game rom file not opened\n"); // Set the Boot ROM diff --git a/src/mmap.cpp b/src/mmap.cpp index e22a8a0..4e3a4d4 100644 --- a/src/mmap.cpp +++ b/src/mmap.cpp @@ -1,7 +1,7 @@ #include "mmap.h" #include -std::function globalFunction = nullptr; +// std::function globalFunction = nullptr; // Constructor MemoryMap::MemoryMap() @@ -105,6 +105,7 @@ MemoryMap::MemoryMap() bootRomFile = nullptr; romFile = nullptr; + globalFunction = nullptr; mbcMode = 0x0; } diff --git a/src/mmap.h b/src/mmap.h index 65dd9e7..8859ece 100644 --- a/src/mmap.h +++ b/src/mmap.h @@ -2,7 +2,7 @@ #include "types.h" #include #include -extern std::function globalFunction; +// extern std::function globalFunction; // The Memory Map for GBE // Pulled from https://gbdev.io/pandocs/Memory_Map.html @@ -138,6 +138,8 @@ class MemoryMap // Stays in the I/O Ports at 0xFF4B Byte* reg_WX; + std::function globalFunction; + public: // Audio Unit // I know this is not the best way to do it @@ -272,4 +274,7 @@ class MemoryMap // sets the ROM file void setRomFile(FILE* file) { romFile = file; } + + // connects the global function + void connectObserver(const std::function& function) { globalFunction = function; } }; \ No newline at end of file From 160fea2d95de2fc7314b033613a6c297311bb50e Mon Sep 17 00:00:00 2001 From: vibhatsu Date: Wed, 28 Aug 2024 12:23:50 +0530 Subject: [PATCH 3/8] Modified the code --- src/audio.cpp | 8 ++++++++ src/audio.h | 7 +------ src/mmap.h | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/audio.cpp b/src/audio.cpp index 15e7faf..3761b41 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -55,6 +55,14 @@ void APU::test() printf("APU test\n"); } +// Connecting CallBack function +void APU::setSignalCallback() +{ + if (mMap) + mMap->connectObserver([this](Word address, Byte value) + { this->onWrite(address, value); }); +} + void APU::writeByte(Word address, Byte value) { printf("APU Address: %04X, Value: %02X\n", address, value); diff --git a/src/audio.h b/src/audio.h index 17cc753..3e0b551 100644 --- a/src/audio.h +++ b/src/audio.h @@ -177,10 +177,5 @@ class APU // Write update void writeUpdate(Word address, Byte value, bool WriteMem = false); - void setSignalCallback() - { - if (mMap) - mMap->connectObserver([this](Word address, Byte value) - { this->onWrite(address, value); }); - } + void setSignalCallback(); }; \ No newline at end of file diff --git a/src/mmap.h b/src/mmap.h index 8859ece..cffe16e 100644 --- a/src/mmap.h +++ b/src/mmap.h @@ -138,6 +138,7 @@ class MemoryMap // Stays in the I/O Ports at 0xFF4B Byte* reg_WX; + // Audio Write Listener std::function globalFunction; public: From 1fd6bdc18a20e8c961851117c036a9f71cd4c17a Mon Sep 17 00:00:00 2001 From: vibhatsu Date: Wed, 28 Aug 2024 12:34:41 +0530 Subject: [PATCH 4/8] Modified the code --- src/audio.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/audio.cpp b/src/audio.cpp index 3761b41..fd1baf5 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -59,8 +59,7 @@ void APU::test() void APU::setSignalCallback() { if (mMap) - mMap->connectObserver([this](Word address, Byte value) - { this->onWrite(address, value); }); + mMap->connectObserver([this](Word address, Byte value){ this->onWrite(address, value); }); } void APU::writeByte(Word address, Byte value) @@ -775,4 +774,4 @@ void NoiseChannel::trigger() { LFSR = 0x7FFF; enabled = dacEnabled; -} \ No newline at end of file +} From ca1bc909c42088ec20b825200caf2cc4c9935a2d Mon Sep 17 00:00:00 2001 From: vibhatsu Date: Wed, 28 Aug 2024 12:36:30 +0530 Subject: [PATCH 5/8] Modified the code --- src/audio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/audio.cpp b/src/audio.cpp index fd1baf5..c497095 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -59,7 +59,7 @@ void APU::test() void APU::setSignalCallback() { if (mMap) - mMap->connectObserver([this](Word address, Byte value){ this->onWrite(address, value); }); + mMap->connectObserver([this](Word address, Byte value) { this->onWrite(address, value); }); } void APU::writeByte(Word address, Byte value) From efc9386a1a2e0406bb123af850dfc5e689236ab5 Mon Sep 17 00:00:00 2001 From: vibhatsu Date: Fri, 30 Aug 2024 14:12:40 +0530 Subject: [PATCH 6/8] naming fixed, redundancies removed --- src/audio.cpp | 25 ++++++++++++++----------- src/audio.h | 18 ++++++++++++++---- src/gameBoy.cpp | 5 +++-- src/mmap.cpp | 5 +++-- src/mmap.h | 7 ++++--- 5 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/audio.cpp b/src/audio.cpp index c497095..ac79828 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -55,11 +55,11 @@ void APU::test() printf("APU test\n"); } -// Connecting CallBack function -void APU::setSignalCallback() +// initialize the writehandler of memorymap +void APU::initializeWriteHandler() { if (mMap) - mMap->connectObserver([this](Word address, Byte value) { this->onWrite(address, value); }); + mMap->setAduioWriteHandler([this](Word address) { this->onWrite(address); }); } void APU::writeByte(Word address, Byte value) @@ -202,7 +202,7 @@ void APU::stepAPU(int cycles) Word address[] = { 0xFF19, 0xFF1E, 0xFF23, 0xFF26 }; for (auto addr : address) { - writeUpdate(addr, 0xFF); + writeUpdate(addr, AUDIO_WRITE); } printf("FramerSequencer ends\n"); } @@ -224,21 +224,24 @@ void APU::clearRegisters() // Could be done by simply writing 0s but for checking's sake done as such for (int address = 0xFF10; address <= 0xFF3F; address++) { - writeUpdate(address, 0xFF); + writeUpdate(address, AUDIO_WRITE); } } -// Write on Memory Write -void APU::onWrite(Word address, Byte value) +// Updates APU registers on write in MemoryMap +void APU::onWrite(Word address) { - writeUpdate(address, value, true); - writeUpdate(0xFF26, 0xFF); + // address where write has occurred + writeUpdate(address, AUDIO_MEMORY_WRITE); + // Update the audio channel controller register + writeUpdate(AUDIO_CHANNEL_CONTROL, AUDIO_WRITE); } // Write Update -void APU::writeUpdate(Word address, Byte value, bool MemWrite) +void APU::writeUpdate(Word address, audioWriteFlag flag) { - if (MemWrite) + Byte value = 0xFF; + if (flag) { value = mMap->readMemory(address); writeByte(address, value); diff --git a/src/audio.h b/src/audio.h index 3e0b551..8d58240 100644 --- a/src/audio.h +++ b/src/audio.h @@ -4,6 +4,8 @@ #include #include // SDL Audio +#define AUDIO_CHANNEL_CONTROL 0xFF26 + enum Channel { CH1 = 0, @@ -12,6 +14,14 @@ enum Channel CH4 = 3 }; +// For checking whether Write is due to memory or APU itself +enum audioWriteFlag +{ + AUDIO_WRITE = 0, + AUDIO_MEMORY_WRITE = 1 + +}; + class PulseChannel { private: @@ -173,9 +183,9 @@ class APU void clearRegisters(); void setMemoryMap(MemoryMap* map) { mMap = map; } // Writes back on Memory Write - void onWrite(Word address, Byte value); + void onWrite(Word address); // Write update - void writeUpdate(Word address, Byte value, bool WriteMem = false); - - void setSignalCallback(); + void writeUpdate(Word address, audioWriteFlag flag); + // initializes the audioWriteHandler of MemoryMap + void initializeWriteHandler(); }; \ No newline at end of file diff --git a/src/gameBoy.cpp b/src/gameBoy.cpp index af3bebd..3ff18da 100644 --- a/src/gameBoy.cpp +++ b/src/gameBoy.cpp @@ -30,7 +30,8 @@ GBE::GBE() // Unify the APU and MemoryMap gbe_audio->setMemoryMap(gbe_mMap); - gbe_audio->setSignalCallback(); + // initialize the write handler + gbe_audio->initializeWriteHandler(); // Open the Boot ROM if ((bootROM = fopen("../src/dmg_boot.gb", "rb")) == NULL) @@ -41,7 +42,7 @@ GBE::GBE() // printf("game rom file not opened"); // Open the Game ROM - if ((gameROM = fopen("../tests/dmg_sound/rom_singles/02-len ctr.gb", "rb")) == NULL) + if ((gameROM = fopen("../tests/dmg_sound/rom_singles/03-trigger.gb", "rb")) == NULL) printf("game rom file not opened\n"); // Set the Boot ROM diff --git a/src/mmap.cpp b/src/mmap.cpp index 4e3a4d4..59f2676 100644 --- a/src/mmap.cpp +++ b/src/mmap.cpp @@ -105,7 +105,7 @@ MemoryMap::MemoryMap() bootRomFile = nullptr; romFile = nullptr; - globalFunction = nullptr; + audioWriteHandler = nullptr; mbcMode = 0x0; } @@ -194,9 +194,10 @@ bool MemoryMap::writeMemory(Word address, Byte value) else { ioPorts[address - 0xFF00] = value; + // Checks for write in aduio registers and calls audioWriteHandler if (address >= 0xFF10 && address <= 0xFF3F) { - globalFunction(address, value); + audioWriteHandler(address); } } } diff --git a/src/mmap.h b/src/mmap.h index cffe16e..37b4aaf 100644 --- a/src/mmap.h +++ b/src/mmap.h @@ -139,7 +139,8 @@ class MemoryMap Byte* reg_WX; // Audio Write Listener - std::function globalFunction; + // updates and writes back after audio write + std::function audioWriteHandler; public: // Audio Unit @@ -276,6 +277,6 @@ class MemoryMap // sets the ROM file void setRomFile(FILE* file) { romFile = file; } - // connects the global function - void connectObserver(const std::function& function) { globalFunction = function; } + // sets audiowritehandler function + void setAduioWriteHandler(const std::function& function) { audioWriteHandler = function; } }; \ No newline at end of file From 779921884b35f563779107929ab4c31fc3de6ca6 Mon Sep 17 00:00:00 2001 From: vibhatsu Date: Sat, 31 Aug 2024 00:34:25 +0530 Subject: [PATCH 7/8] applied modifications --- src/audio.cpp | 17 +++++++++-------- src/audio.h | 10 +++++----- src/gameBoy.cpp | 2 +- src/mmap.cpp | 4 +--- src/mmap.h | 6 +++--- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/audio.cpp b/src/audio.cpp index ac79828..c4816e4 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -59,7 +59,8 @@ void APU::test() void APU::initializeWriteHandler() { if (mMap) - mMap->setAduioWriteHandler([this](Word address) { this->onWrite(address); }); + mMap->setAudioWriteHandler([this](Word address) + { this->onMemoryWrite(address); }); } void APU::writeByte(Word address, Byte value) @@ -202,7 +203,7 @@ void APU::stepAPU(int cycles) Word address[] = { 0xFF19, 0xFF1E, 0xFF23, 0xFF26 }; for (auto addr : address) { - writeUpdate(addr, AUDIO_WRITE); + audioRegisterUpdate(addr, AudioWrite); } printf("FramerSequencer ends\n"); } @@ -224,21 +225,21 @@ void APU::clearRegisters() // Could be done by simply writing 0s but for checking's sake done as such for (int address = 0xFF10; address <= 0xFF3F; address++) { - writeUpdate(address, AUDIO_WRITE); + audioRegisterUpdate(address, AudioWrite); } } // Updates APU registers on write in MemoryMap -void APU::onWrite(Word address) +void APU::onMemoryWrite(Word address) { // address where write has occurred - writeUpdate(address, AUDIO_MEMORY_WRITE); + audioRegisterUpdate(address, AudioMemoryWrite); // Update the audio channel controller register - writeUpdate(AUDIO_CHANNEL_CONTROL, AUDIO_WRITE); + audioRegisterUpdate(AUDIO_MASTER_CONTROL_REGISTER, AudioWrite); } // Write Update -void APU::writeUpdate(Word address, audioWriteFlag flag) +void APU::audioRegisterUpdate(Word address, audioWriteFlag flag) { Byte value = 0xFF; if (flag) @@ -247,7 +248,7 @@ void APU::writeUpdate(Word address, audioWriteFlag flag) writeByte(address, value); } value = readByte(address); - mMap->writeBackMemory(address, value); + mMap->MemoryWriteBack(address, value); } // PulseChannel diff --git a/src/audio.h b/src/audio.h index 8d58240..464f06f 100644 --- a/src/audio.h +++ b/src/audio.h @@ -4,7 +4,7 @@ #include #include // SDL Audio -#define AUDIO_CHANNEL_CONTROL 0xFF26 +#define AUDIO_MASTER_CONTROL_REGISTER 0xFF26 enum Channel { @@ -17,8 +17,8 @@ enum Channel // For checking whether Write is due to memory or APU itself enum audioWriteFlag { - AUDIO_WRITE = 0, - AUDIO_MEMORY_WRITE = 1 + AudioWrite = 0, + AudioMemoryWrite = 1 }; @@ -183,9 +183,9 @@ class APU void clearRegisters(); void setMemoryMap(MemoryMap* map) { mMap = map; } // Writes back on Memory Write - void onWrite(Word address); + void onMemoryWrite(Word address); // Write update - void writeUpdate(Word address, audioWriteFlag flag); + void audioRegisterUpdate(Word address, audioWriteFlag flag); // initializes the audioWriteHandler of MemoryMap void initializeWriteHandler(); }; \ No newline at end of file diff --git a/src/gameBoy.cpp b/src/gameBoy.cpp index 3ff18da..41c07b8 100644 --- a/src/gameBoy.cpp +++ b/src/gameBoy.cpp @@ -42,7 +42,7 @@ GBE::GBE() // printf("game rom file not opened"); // Open the Game ROM - if ((gameROM = fopen("../tests/dmg_sound/rom_singles/03-trigger.gb", "rb")) == NULL) + if ((gameROM = fopen("../tests/dmg_sound/rom_singles/02-len ctr.gb", "rb")) == NULL) printf("game rom file not opened\n"); // Set the Boot ROM diff --git a/src/mmap.cpp b/src/mmap.cpp index 59f2676..5f6da9b 100644 --- a/src/mmap.cpp +++ b/src/mmap.cpp @@ -1,8 +1,6 @@ #include "mmap.h" #include -// std::function globalFunction = nullptr; - // Constructor MemoryMap::MemoryMap() { @@ -225,7 +223,7 @@ void MemoryMap::debugWriteMemory(Word address, Byte value) romBank0[address] = value; } -bool MemoryMap::writeBackMemory(Word address, Byte value) +bool MemoryMap::MemoryWriteBack(Word address, Byte value) { if (address >= 0xFF10 && address <= 0xFF3F) { diff --git a/src/mmap.h b/src/mmap.h index 37b4aaf..17cd4ee 100644 --- a/src/mmap.h +++ b/src/mmap.h @@ -2,7 +2,7 @@ #include "types.h" #include #include -// extern std::function globalFunction; + // The Memory Map for GBE // Pulled from https://gbdev.io/pandocs/Memory_Map.html @@ -191,7 +191,7 @@ class MemoryMap void debugWriteMemory(Word address, Byte value); // Write Back - bool writeBackMemory(Word address, Byte value); + bool MemoryWriteBack(Word address, Byte value); // Reads a byte from the memory address Byte readMemory(Word address); @@ -278,5 +278,5 @@ class MemoryMap void setRomFile(FILE* file) { romFile = file; } // sets audiowritehandler function - void setAduioWriteHandler(const std::function& function) { audioWriteHandler = function; } + void setAudioWriteHandler(const std::function& function) { audioWriteHandler = function; } }; \ No newline at end of file From 2c3ef03291d01fe098ed31ab6a73884d15c25763 Mon Sep 17 00:00:00 2001 From: vibhatsu Date: Sat, 31 Aug 2024 00:36:14 +0530 Subject: [PATCH 8/8] applied modifications --- src/audio.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/audio.cpp b/src/audio.cpp index c4816e4..d4f1d37 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -59,8 +59,7 @@ void APU::test() void APU::initializeWriteHandler() { if (mMap) - mMap->setAudioWriteHandler([this](Word address) - { this->onMemoryWrite(address); }); + mMap->setAudioWriteHandler([this](Word address) { this->onMemoryWrite(address); }); } void APU::writeByte(Word address, Byte value)