Skip to content

Commit

Permalink
1st test passed
Browse files Browse the repository at this point in the history
  • Loading branch information
v1bh475u committed Aug 21, 2024
1 parent e077f31 commit d590617
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 104 deletions.
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ elif [[ $last_keyword == "gbemu" ]]; then
echo "making new build directory"
mkdir build
cd build
cmake ..
cmake -DDEBUG=on ..
cmake --build . -j8
./gbemu
fi
Expand Down
24 changes: 17 additions & 7 deletions src/audio.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "audio.h"
#include "types.h"

APU::APU()
{
Expand Down Expand Up @@ -58,7 +57,7 @@ void APU::test()

void APU::writeByte(Word address, Byte value)
{
printf("APU Address: %X, Value: %X\n", address, value);
printf("APU Address: %04X, Value: %04X\n", address, value);
if (address == 0xFF26)
{
bool enable = (value & 0x80) >> 7;
Expand Down Expand Up @@ -126,6 +125,7 @@ void APU::writeByte(Word address, Byte value)

Byte APU::readByte(Word address)
{
printf("Address: %04X\n", address);
if (address >= 0xFF10 && address <= 0xFF14)
{
return channel1->readByte(address);
Expand Down Expand Up @@ -171,11 +171,15 @@ Byte APU::readByte(Word address)

void APU::stepAPU(int cycles)
{
// Audio checker
Byte flag = mMap->getAudioWriteFlag();
Word address = 0;
if (flag)
address = mMap->getAudioWriteAddress();
// Audio write regsisters
while (!mMap->isQueueEmpty())
{
printf("APU working\n");
audioRegs writtenRegister = mMap->popAudioWriteQueue();
APU::writeByte(writtenRegister.address, writtenRegister.value);
Byte value = APU::readByte(writtenRegister.address);
mMap->writeMemory(writtenRegister.address, value, false);
}

sampleCounter += cycles;
frameSequencerCounter += cycles;
Expand Down Expand Up @@ -212,6 +216,12 @@ void APU::clearRegisters()
channel2->powerOff();
channel3->powerOff();
channel4->powerOff();
// 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->writeMemory(address, reg, false);
}
}

// PulseChannel
Expand Down
Loading

0 comments on commit d590617

Please sign in to comment.