diff --git a/run.sh b/run.sh index f6fd32c..9ddc0bf 100755 --- a/run.sh +++ b/run.sh @@ -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 diff --git a/src/audio.cpp b/src/audio.cpp index 2cbbae2..b0c604b 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -1,5 +1,4 @@ #include "audio.h" -#include "types.h" APU::APU() { @@ -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; @@ -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); @@ -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; @@ -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 diff --git a/src/cpu.cpp b/src/cpu.cpp index 3586279..4c3978d 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -5,7 +5,7 @@ #define debugPrint(...) #endif #ifdef DEBUG -#define debugPrint(...) printf(__V _ARGS__) +#define debugPrint(...) printf(__VA_ARGS__) #endif // Setters of Flags @@ -33,16 +33,6 @@ #define GET_HALF_CARRY_FLAG ((reg_AF.lo & FLAG_HALF_CARRY_h) >> 5) #define GET_CARRY_FLAG ((reg_AF.lo & FLAG_CARRY_c) >> 4) -static void CPU::audioUpdate(Word address) -{ - bool isAudioRegion = (address >= 0xFF10) & (address <= 0xFF3F); - if (isAudioRegion) - { - mMap->setAudioWriteFlag(isAudioRegion); - mMap->setAudioWriteAddress(address); - } -} - CPU::CPU() { @@ -103,7 +93,6 @@ int CPU::LD_BC_A() { // Write the contents of A into the memory address pointed to by BC mMap->writeMemory(reg_BC.dat, reg_AF.hi); - CPU::audioUpdate(reg_BC.dat); // Increment the program counter reg_PC.dat += 1; @@ -205,7 +194,6 @@ int CPU::LD_u16_SP() // Write the contents of SP into the memory address pointed to by the next 2 bytes mMap->writeMemory(address, reg_SP.lo); mMap->writeMemory(address + 1, reg_SP.hi); - CPU::audioUpdate(address); // Increment the program counter reg_PC.dat += 3; @@ -356,7 +344,6 @@ int CPU::LD_DE_u16() int CPU::LD_DE_A() { mMap->writeMemory(reg_DE.dat, reg_AF.hi); - CPU::audioUpdate(reg_DE.dat); reg_PC.dat += 1; debugPrint("LD (DE), A\n"); return 8; @@ -609,7 +596,6 @@ int CPU::LD_HL_u16() int CPU::LD_HLp_A() { mMap->writeMemory(reg_HL.dat, reg_AF.hi); - CPU::audioUpdate(reg_HL.dat); reg_HL.dat += 1; reg_PC.dat += 1; debugPrint("LD (HL+), A\n"); @@ -872,7 +858,6 @@ int CPU::LD_SP_u16() int CPU::LD_HLm_A() { mMap->writeMemory(reg_HL.dat, reg_AF.hi); - CPU::audioUpdate(reg_HL.dat); reg_HL.dat -= 1; reg_PC.dat += 1; debugPrint("LD (HL-), A\n"); @@ -906,7 +891,6 @@ int CPU::INC_HLp() ((*mMap)[reg_HL.dat] & 0x0F) == 0x0F ? SET_HALF_CARRY_FLAG : UNSET_HALF_CARRY_FLAG; mMap->writeMemory(reg_HL.dat, temp); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("INC (HL)\n"); return 12; @@ -930,7 +914,6 @@ int CPU::DEC_HLp() SET_SUBTRACT_FLAG; mMap->writeMemory(reg_HL.dat, temp); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("DEC (HL)\n"); return 12; @@ -941,7 +924,6 @@ int CPU::DEC_HLp() int CPU::LD_HLp_u8() { mMap->writeMemory(reg_HL.dat, (*mMap)[reg_PC.dat + 1]); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 2; debugPrint("LD (HL), u8\n"); return 12; @@ -1072,6 +1054,7 @@ int CPU::LD_A_u8() { reg_AF.hi = (*mMap)[reg_PC.dat + 1]; reg_PC.dat += 2; + // printf("%02X\n", reg_AF.hi); debugPrint("LD A, u8\n"); return 8; } @@ -1574,7 +1557,6 @@ int CPU::LD_L_A() int CPU::LD_HLp_B() { mMap->writeMemory(reg_HL.dat, reg_BC.hi); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("LD (HL), B\n"); return 8; @@ -1585,7 +1567,6 @@ int CPU::LD_HLp_B() int CPU::LD_HLp_C() { mMap->writeMemory(reg_HL.dat, reg_BC.lo); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("LD (HL), C\n"); return 8; @@ -1596,7 +1577,6 @@ int CPU::LD_HLp_C() int CPU::LD_HLp_D() { mMap->writeMemory(reg_HL.dat, reg_DE.hi); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("LD (HL), D\n"); return 8; @@ -1607,7 +1587,6 @@ int CPU::LD_HLp_D() int CPU::LD_HLp_E() { mMap->writeMemory(reg_HL.dat, reg_DE.lo); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("LD (HL), E\n"); return 8; @@ -1618,7 +1597,6 @@ int CPU::LD_HLp_E() int CPU::LD_HLp_H() { mMap->writeMemory(reg_HL.dat, reg_HL.hi); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("LD (HL), H\n"); return 8; @@ -1629,7 +1607,6 @@ int CPU::LD_HLp_H() int CPU::LD_HLp_L() { mMap->writeMemory(reg_HL.dat, reg_HL.lo); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("LD (HL), L\n"); return 8; @@ -1684,7 +1661,6 @@ int CPU::HALT() int CPU::LD_HLA() { mMap->writeMemory(reg_HL.dat, reg_AF.hi); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("LD (HL), A\n"); return 8; @@ -3684,7 +3660,6 @@ int CPU::RST_18H() int CPU::LDH_a8_A() { mMap->writeMemory(0xFF00 + (*mMap)[reg_PC.dat + 1], reg_AF.hi); - CPU::audioUpdate(0xFF00 + (*mMap)[reg_PC.dat + 1]); reg_PC.dat += 2; debugPrint("LDH (%02X), A\n", (*mMap)[reg_PC.dat + 1]); return 12; @@ -3706,7 +3681,6 @@ int CPU::POP_HL() int CPU::LDH_C_A() { mMap->writeMemory(0xFF00 + reg_BC.lo, reg_AF.hi); - CPU::audioUpdate(0xFF00 + reg_BC.lo); reg_PC.dat += 1; debugPrint("LD (C), A\n"); return 8; @@ -3783,7 +3757,6 @@ int CPU::LD_u16_A() // u16 is ((*mMap)[reg_PC.dat + 1] << 8) | (*mMap)[reg_PC.dat + 2] // Writing the value of A into the (u16) mMap->writeMemory((*mMap)[reg_PC.dat + 2] << 8 | (*mMap)[reg_PC.dat + 1], reg_AF.hi); - CPU::audioUpdate((*mMap)[reg_PC.dat + 2] << 8 | (*mMap)[reg_PC.dat + 1]); reg_PC.dat += 3; debugPrint("LD (u16), A\n"); return 16; @@ -3997,6 +3970,7 @@ int CPU::executeNextInstruction() { // Get the opcode Byte opcode = (*mMap)[reg_PC.dat]; + // printf("Instr %4X:%2X\n", reg_PC.dat, opcode); return (this->*method_pointer[opcode])(); } @@ -4139,7 +4113,6 @@ int CPU::RLC_HLp() // Rotate the value at memory address pointed to by HL left by 1 mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] << 1) | ((*mMap)[reg_HL.dat] >> 7)); - CPU::audioUpdate(reg_HL.dat); (*mMap)[reg_HL.dat] ? UNSET_ZERO_FLAG : SET_ZERO_FLAG; reg_PC.dat += 1; @@ -4299,7 +4272,6 @@ int CPU::RRC_HLp() // Rotate the value at memory address pointed to by HL right by 1 mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] >> 1) | ((*mMap)[reg_HL.dat] << 7)); - CPU::audioUpdate(reg_HL.dat); (*mMap)[reg_HL.dat] ? UNSET_ZERO_FLAG : SET_ZERO_FLAG; reg_PC.dat += 1; @@ -4468,7 +4440,6 @@ int CPU::RL_HLp() // Rotate the value at memory address pointed to by HL left by 1 mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] << 1) | ((*mMap)[reg_HL.dat] >> 7)); - CPU::audioUpdate(reg_HL.dat); // swap the values of 0th bit of the value at memory address pointed to by HL and the carry flag mMap->writeMemory(reg_HL.dat, (*mMap)[reg_HL.dat] ^ GET_CARRY_FLAG); GET_CARRY_FLAG ^ ((*mMap)[reg_HL.dat] & 1) ? SET_CARRY_FLAG : UNSET_CARRY_FLAG; @@ -4644,7 +4615,6 @@ int CPU::RR_HLp() // Rotate the value at memory address pointed to by HL right by 1 mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] >> 1) | ((*mMap)[reg_HL.dat] << 7)); - CPU::audioUpdate(reg_HL.dat); // swap the values of 7th bit of the value at memory address pointed to by HL and the carry flag mMap->writeMemory(reg_HL.dat, (*mMap)[reg_HL.dat] ^ GET_CARRY_FLAG << 7); GET_CARRY_FLAG ^ ((*mMap)[reg_HL.dat] >> 7) ? SET_CARRY_FLAG : UNSET_CARRY_FLAG; @@ -4811,7 +4781,6 @@ int CPU::SLA_HLp() // Shift the value at memory address pointed to by HL left by 1 mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] << 1)); - CPU::audioUpdate(reg_HL.dat); (*mMap)[reg_HL.dat] ? UNSET_ZERO_FLAG : SET_ZERO_FLAG; reg_PC.dat += 1; @@ -4971,7 +4940,6 @@ int CPU::SRA_HLp() // Shift the value at memory address pointed to by HL right by 1 while leaving 7th bit unchanged mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] >> 1) | ((*mMap)[reg_HL.dat] & 0x80)); - CPU::audioUpdate(reg_HL.dat); (*mMap)[reg_HL.dat] ? UNSET_ZERO_FLAG : SET_ZERO_FLAG; reg_PC.dat += 1; @@ -5117,7 +5085,6 @@ int CPU::SWAP_HLp() // swap the upper and lower nibbles mMap->writeMemory(reg_HL.dat, ((((*mMap)[reg_HL.dat] & 0x0F) << 4) | (((*mMap)[reg_HL.dat] & 0xF0) >> 4))); - CPU::audioUpdate(reg_HL.dat); (*mMap)[reg_HL.dat] ? UNSET_ZERO_FLAG : SET_ZERO_FLAG; reg_PC.dat += 1; @@ -5275,7 +5242,6 @@ int CPU::SRL_HLp() // Shift the value at memory address pointed to by HL right by 1 mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] >> 1)); - CPU::audioUpdate(reg_HL.dat); (*mMap)[reg_HL.dat] & 0xFF ? UNSET_ZERO_FLAG : SET_ZERO_FLAG; reg_PC.dat += 1; @@ -6341,7 +6307,6 @@ int CPU::RES_0_HLp() { // unset the 0th bit mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] & (0xFF ^ (1 << 0)))); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("RES 0, (HL)\n"); return 12; @@ -6437,7 +6402,6 @@ int CPU::RES_1_HLp() { // unset the 1st bit mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] & (0xFF ^ (1 << 1)))); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("RES 1, (HL)\n"); return 12; @@ -6533,7 +6497,6 @@ int CPU::RES_2_HLp() { // unset the 2nd bit mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] & (0xFF ^ (1 << 2)))); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("RES 2, (HL)\n"); return 12; @@ -6629,7 +6592,6 @@ int CPU::RES_3_HLp() { // unset the 3rd bit mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] & (0xFF ^ (1 << 3)))); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("RES 3, (HL)\n"); return 12; @@ -6725,7 +6687,6 @@ int CPU::RES_4_HLp() { // unset the 4th bit mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] & (0xFF ^ (1 << 4)))); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("RES 4, (HL)\n"); return 12; @@ -6821,7 +6782,6 @@ int CPU::RES_5_HLp() { // unset the 5th bit mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] & (0xFF ^ (1 << 5)))); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("RES 5, (HL)\n"); return 12; @@ -6917,7 +6877,6 @@ int CPU::RES_6_HLp() { // unset the 6th bit mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] & (0xFF ^ (1 << 6)))); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("RES 6, (HL)\n"); return 12; @@ -7013,7 +6972,6 @@ int CPU::RES_7_HLp() { // unset the 7th bit mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] & (0xFF ^ (1 << 7)))); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("RES 7, (HL)\n"); return 12; @@ -7109,7 +7067,6 @@ int CPU::SET_0_HLp() { // set the 0th bit mMap->writeMemory(reg_HL.dat, (*mMap)[reg_HL.dat] | (1 << 0)); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("SET 0, (HL)\n"); return 12; @@ -7205,7 +7162,6 @@ int CPU::SET_1_HLp() { // set the 1st bit mMap->writeMemory(reg_HL.dat, (*mMap)[reg_HL.dat] | (1 << 1)); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("SET 1, (HL)\n"); return 12; @@ -7301,7 +7257,6 @@ int CPU::SET_2_HLp() { // set the 2nd bit mMap->writeMemory(reg_HL.dat, (*mMap)[reg_HL.dat] | (1 << 2)); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("SET 2, (HL)\n"); return 12; @@ -7397,7 +7352,6 @@ int CPU::SET_3_HLp() { // set the 3rd bit mMap->writeMemory(reg_HL.dat, (*mMap)[reg_HL.dat] | (1 << 3)); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("SET 3, (HL)\n"); return 12; @@ -7493,7 +7447,6 @@ int CPU::SET_4_HLp() { // set the 4th bit mMap->writeMemory(reg_HL.dat, (*mMap)[reg_HL.dat] | (1 << 4)); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("SET 4, (HL)\n"); return 12; @@ -7589,7 +7542,6 @@ int CPU::SET_5_HLp() { // set the 5th bit mMap->writeMemory(reg_HL.dat, (*mMap)[reg_HL.dat] | (1 << 5)); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("SET 5, (HL)\n"); @@ -7686,7 +7638,6 @@ int CPU::SET_6_HLp() { // set the 6th bit mMap->writeMemory(reg_HL.dat, (*mMap)[reg_HL.dat] | (1 << 6)); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("SET 6, (HL)\n"); @@ -7783,7 +7734,6 @@ int CPU::SET_7_HLp() { // set the 7th bit mMap->writeMemory(reg_HL.dat, (*mMap)[reg_HL.dat] | (1 << 7)); - CPU::audioUpdate(reg_HL.dat); reg_PC.dat += 1; debugPrint("SET 7, (HL)\n"); diff --git a/src/cpu.h b/src/cpu.h index 8eeb1e0..b7f3e48 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -1170,7 +1170,4 @@ class CPU // update the timers void updateTimers(int cycles); - - // audio write checker - static void audioUpdate(Word address); }; diff --git a/src/gameBoy.cpp b/src/gameBoy.cpp index ecdcb1a..672145a 100644 --- a/src/gameBoy.cpp +++ b/src/gameBoy.cpp @@ -33,15 +33,15 @@ GBE::GBE() // Open the Boot ROM if ((bootROM = fopen("../src/dmg_boot.gb", "rb")) == NULL) - printf("boot rom file not opened"); + printf("boot rom file not opened\n"); // // Open the Game ROM // if ((gameROM = fopen("../tests/tetris.gb", "rb")) == NULL) // printf("game rom file not opened"); // Open the Game ROM - if ((gameROM = fopen("../tests/dmg_sound/rom_singles/03-trigger.gb", "rb")) == NULL) - printf("game rom file not opened"); + 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 gbe_mMap->setBootRomFile(bootROM); @@ -105,9 +105,9 @@ GBE::GBE() gbe_mMap->debugWriteMemory(0x131, 0xB9); gbe_mMap->debugWriteMemory(0x132, 0x33); gbe_mMap->debugWriteMemory(0x133, 0x3E); - + printf("Loading boot\n"); executeBootROM(); - + printf("Exited boot\n"); update(); } diff --git a/src/gameBoy.h b/src/gameBoy.h index 9ee0c48..f7ac04f 100644 --- a/src/gameBoy.h +++ b/src/gameBoy.h @@ -3,6 +3,7 @@ #include "cpu.h" #include "mmap.h" #include "graphics.h" +#include "audio.h" // GBE stands for GameBoyEmulator diff --git a/src/mmap.cpp b/src/mmap.cpp index 6d71288..4fba3a3 100644 --- a/src/mmap.cpp +++ b/src/mmap.cpp @@ -104,18 +104,32 @@ MemoryMap::MemoryMap() bootRomFile = nullptr; romFile = nullptr; - audio = new APU(); - mbcMode = 0x0; } +// Push to audio write queue +void MemoryMap::pushAudioWriteQueue(Word address, Byte value) +{ + audioRegs temp = { address, value }; + MemoryMap::audioWriteQueue.push(temp); +} + +// 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) +bool MemoryMap::writeMemory(Word address, Byte value, bool audioWrite) { if (address < 0x8000) { - printf("Writing to ROM is not allowed! Write attempted at %04X", address); + + printf("Writing to ROM is not allowed! Write attempted at %04X\n", address); return false; } else if (address < 0xA000) @@ -174,13 +188,14 @@ bool MemoryMap::writeMemory(Word address, Byte value) { readInput(value); } - // Write to Audio Registers - else if (address >= 0xFF10 && address <= 0xFF3F) - { - audio->writeByte(address, value); - } else + { ioPorts[address - 0xFF00] = value; + if (address >= 0xFF10 && address <= 0xFF3F && audioWrite) + { + MemoryMap::pushAudioWriteQueue(address, value); + } + } } else if (address < 0xFFFF) { @@ -194,7 +209,7 @@ bool MemoryMap::writeMemory(Word address, Byte value) } else { - printf("Invalid address"); + printf("Invalid address\n"); return false; } @@ -251,14 +266,8 @@ Byte MemoryMap::readMemory(Word address) } else if (address < 0xFF80) { - // Read from Audio Registers - if (address >= 0xFF10 && address <= 0xFF3F) - { - return audio->readByte(address); - } // Read from I/O Ports - else - return ioPorts[address - 0xFF00]; + return ioPorts[address - 0xFF00]; } else if (address < 0xFFFF) { diff --git a/src/mmap.h b/src/mmap.h index 2eb8786..e7078c8 100644 --- a/src/mmap.h +++ b/src/mmap.h @@ -1,8 +1,7 @@ #pragma once #include "types.h" #include -#include "audio.h" - +#include // The Memory Map for GBE // Pulled from https://gbdev.io/pandocs/Memory_Map.html @@ -138,11 +137,8 @@ class MemoryMap // Stays in the I/O Ports at 0xFF4B Byte* reg_WX; - // audio write flag - Byte* audioWriteFlag; - - // audio write address - Word* audioWriteAddress; + // Audio write queue + std::queue audioWriteQueue; public: // Audio Unit @@ -189,7 +185,7 @@ class MemoryMap Byte* getInterruptEnableRegister() { return interruptEnableRegister; } // Writes a byte to the memory address - bool writeMemory(Word address, Byte value); + bool writeMemory(Word address, Byte value, bool audioWrite = true); void debugWriteMemory(Word address, Byte value); // Reads a byte from the memory address @@ -276,15 +272,12 @@ class MemoryMap // sets the ROM file void setRomFile(FILE* file) { romFile = file; } - // get audio write flag - Byte getAudioWriteFlag() { return *audioWriteFlag; } - - // get audio write address - Word getAudioWriteAddress() { return *audioWriteAddress; } + // push to queue + void pushAudioWriteQueue(Word address, Byte value); - // set audio write flag - void setAudioWriteFlag(Byte value) { *audioWriteFlag = value; } + // is queue empty + bool isQueueEmpty() { return audioWriteQueue.empty(); }; - // store audio write address - void storeAudioWriteAddress(Word address) { *audioWriteAddress = address; } + // pop queue + audioRegs popAudioWriteQueue(); }; \ No newline at end of file diff --git a/src/types.h b/src/types.h index edd42d2..9ce281b 100644 --- a/src/types.h +++ b/src/types.h @@ -7,4 +7,10 @@ typedef unsigned char Byte; typedef char SByte; typedef unsigned short Word; typedef signed short SWord; -typedef unsigned int color; \ No newline at end of file +typedef unsigned int color; + +typedef struct +{ + Word address; + Byte value; +} audioRegs; \ No newline at end of file