Skip to content

Commit

Permalink
Exceptional handling for APU-MemoryMap connection added
Browse files Browse the repository at this point in the history
  • Loading branch information
v1bh475u committed Sep 1, 2024
1 parent 66b0c65 commit 9ffccb9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,18 @@ bool APU::init()
void APU::setMemoryMap(MemoryMap* mMap)
{
this->mMap = mMap;
// initialize Handlers
initializeReadWriteHandlers();
}

// Initializes the read-write handlers of MemoryMap
void APU::initializeReadWriteHandlers()
{
if (mMap)
if (!mMap)
{
throw std::runtime_error("MemoryMap not set in APU");
}
else
{
mMap->setAudioReadHandler([this](Word address) { return this->readByte(address); });
mMap->setAudioWriteHandler([this](Word address, Byte value) { this->writeByte(address, value); });
Expand Down
1 change: 1 addition & 0 deletions src/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "types.h"
#include <stdio.h>
#include <SDL.h>
#include <stdexcept>
#include "mmap.h"

enum Channel
Expand Down
4 changes: 1 addition & 3 deletions src/gameBoy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ GBE::GBE()

// Unify the APU and MemoryMap
gbe_audio->setMemoryMap(gbe_mMap);
// initialize Handlers
gbe_audio->initializeReadWriteHandlers();

gbe_graphics->init();

Expand All @@ -43,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");

// Set the Boot ROM
Expand Down

0 comments on commit 9ffccb9

Please sign in to comment.