Skip to content

Commit

Permalink
applied modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
v1bh475u committed Aug 30, 2024
1 parent efc9386 commit 7799218
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
17 changes: 9 additions & 8 deletions src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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");
}
Expand All @@ -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)
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdio.h>
#include <SDL.h> // SDL Audio

#define AUDIO_CHANNEL_CONTROL 0xFF26
#define AUDIO_MASTER_CONTROL_REGISTER 0xFF26

enum Channel
{
Expand All @@ -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

};

Expand Down Expand Up @@ -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();
};
2 changes: 1 addition & 1 deletion src/gameBoy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/mmap.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "mmap.h"
#include <cstring>

// std::function<void(Word, Byte)> globalFunction = nullptr;

// Constructor
MemoryMap::MemoryMap()
{
Expand Down Expand Up @@ -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)
{
Expand Down
6 changes: 3 additions & 3 deletions src/mmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "types.h"
#include <stdio.h>
#include <functional>
// extern std::function<void(Word, Byte)> globalFunction;

// The Memory Map for GBE
// Pulled from https://gbdev.io/pandocs/Memory_Map.html

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -278,5 +278,5 @@ class MemoryMap
void setRomFile(FILE* file) { romFile = file; }

// sets audiowritehandler function
void setAduioWriteHandler(const std::function<void(Word)>& function) { audioWriteHandler = function; }
void setAudioWriteHandler(const std::function<void(Word)>& function) { audioWriteHandler = function; }
};

0 comments on commit 7799218

Please sign in to comment.