Skip to content

Commit

Permalink
code modified
Browse files Browse the repository at this point in the history
  • Loading branch information
v1bh475u committed Aug 31, 2024
1 parent 2c3ef03 commit 777fc01
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ Byte APU::readByte(Word address)

case 0xFF26:
val = (enabled ? 0x80 : 0) | (channel1->isEnabled() ? 0x01 : 0) | (channel2->isEnabled() ? 0x02 : 0) | (channel3->isEnabled() ? 0x04 : 0) | (channel4->isEnabled() ? 0x08 : 0) | 0x70;
// printf("APU Read 0xFF26: %04X\n", val);
return val;

default:
Expand Down Expand Up @@ -241,7 +240,7 @@ void APU::onMemoryWrite(Word address)
void APU::audioRegisterUpdate(Word address, audioWriteFlag flag)
{
Byte value = 0xFF;
if (flag)
if (flag == AudioMemoryWrite)
{
value = mMap->readMemory(address);
writeByte(address, value);
Expand Down
25 changes: 21 additions & 4 deletions src/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ 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);

// Increment the program counter
reg_PC.dat += 3;

Expand Down Expand Up @@ -1054,7 +1055,6 @@ 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;
}
Expand Down Expand Up @@ -3970,7 +3970,6 @@ 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])();
}

Expand Down Expand Up @@ -4113,8 +4112,8 @@ 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));
(*mMap)[reg_HL.dat] ? UNSET_ZERO_FLAG : SET_ZERO_FLAG;

(*mMap)[reg_HL.dat] ? UNSET_ZERO_FLAG : SET_ZERO_FLAG;
reg_PC.dat += 1;
debugPrint("RLC (HL)\n");
return 12;
Expand Down Expand Up @@ -4273,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));
(*mMap)[reg_HL.dat] ? UNSET_ZERO_FLAG : SET_ZERO_FLAG;

reg_PC.dat += 1;
debugPrint("RRC (HL)\n");
return 12;
Expand Down Expand Up @@ -4440,6 +4438,7 @@ 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));

// 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;
Expand Down Expand Up @@ -4615,6 +4614,7 @@ 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));

// 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;
Expand Down Expand Up @@ -4781,6 +4781,7 @@ 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));

(*mMap)[reg_HL.dat] ? UNSET_ZERO_FLAG : SET_ZERO_FLAG;

reg_PC.dat += 1;
Expand Down Expand Up @@ -4940,6 +4941,7 @@ 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));

(*mMap)[reg_HL.dat] ? UNSET_ZERO_FLAG : SET_ZERO_FLAG;

reg_PC.dat += 1;
Expand Down Expand Up @@ -5085,6 +5087,7 @@ 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)));

(*mMap)[reg_HL.dat] ? UNSET_ZERO_FLAG : SET_ZERO_FLAG;

reg_PC.dat += 1;
Expand Down Expand Up @@ -5242,6 +5245,7 @@ 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));

(*mMap)[reg_HL.dat] & 0xFF ? UNSET_ZERO_FLAG : SET_ZERO_FLAG;

reg_PC.dat += 1;
Expand Down Expand Up @@ -6307,6 +6311,7 @@ int CPU::RES_0_HLp()
{
// unset the 0th bit
mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] & (0xFF ^ (1 << 0))));

reg_PC.dat += 1;
debugPrint("RES 0, (HL)\n");
return 12;
Expand Down Expand Up @@ -6402,6 +6407,7 @@ int CPU::RES_1_HLp()
{
// unset the 1st bit
mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] & (0xFF ^ (1 << 1))));

reg_PC.dat += 1;
debugPrint("RES 1, (HL)\n");
return 12;
Expand Down Expand Up @@ -6497,6 +6503,7 @@ int CPU::RES_2_HLp()
{
// unset the 2nd bit
mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] & (0xFF ^ (1 << 2))));

reg_PC.dat += 1;
debugPrint("RES 2, (HL)\n");
return 12;
Expand Down Expand Up @@ -6592,6 +6599,7 @@ int CPU::RES_3_HLp()
{
// unset the 3rd bit
mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] & (0xFF ^ (1 << 3))));

reg_PC.dat += 1;
debugPrint("RES 3, (HL)\n");
return 12;
Expand Down Expand Up @@ -6687,6 +6695,7 @@ int CPU::RES_4_HLp()
{
// unset the 4th bit
mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] & (0xFF ^ (1 << 4))));

reg_PC.dat += 1;
debugPrint("RES 4, (HL)\n");
return 12;
Expand Down Expand Up @@ -6782,6 +6791,7 @@ int CPU::RES_5_HLp()
{
// unset the 5th bit
mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] & (0xFF ^ (1 << 5))));

reg_PC.dat += 1;
debugPrint("RES 5, (HL)\n");
return 12;
Expand Down Expand Up @@ -6877,6 +6887,7 @@ int CPU::RES_6_HLp()
{
// unset the 6th bit
mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] & (0xFF ^ (1 << 6))));

reg_PC.dat += 1;
debugPrint("RES 6, (HL)\n");
return 12;
Expand Down Expand Up @@ -6972,6 +6983,7 @@ int CPU::RES_7_HLp()
{
// unset the 7th bit
mMap->writeMemory(reg_HL.dat, ((*mMap)[reg_HL.dat] & (0xFF ^ (1 << 7))));

reg_PC.dat += 1;
debugPrint("RES 7, (HL)\n");
return 12;
Expand Down Expand Up @@ -7067,6 +7079,7 @@ int CPU::SET_0_HLp()
{
// set the 0th bit
mMap->writeMemory(reg_HL.dat, (*mMap)[reg_HL.dat] | (1 << 0));

reg_PC.dat += 1;
debugPrint("SET 0, (HL)\n");
return 12;
Expand Down Expand Up @@ -7162,6 +7175,7 @@ int CPU::SET_1_HLp()
{
// set the 1st bit
mMap->writeMemory(reg_HL.dat, (*mMap)[reg_HL.dat] | (1 << 1));

reg_PC.dat += 1;
debugPrint("SET 1, (HL)\n");
return 12;
Expand Down Expand Up @@ -7257,6 +7271,7 @@ int CPU::SET_2_HLp()
{
// set the 2nd bit
mMap->writeMemory(reg_HL.dat, (*mMap)[reg_HL.dat] | (1 << 2));

reg_PC.dat += 1;
debugPrint("SET 2, (HL)\n");
return 12;
Expand Down Expand Up @@ -7352,6 +7367,7 @@ int CPU::SET_3_HLp()
{
// set the 3rd bit
mMap->writeMemory(reg_HL.dat, (*mMap)[reg_HL.dat] | (1 << 3));

reg_PC.dat += 1;
debugPrint("SET 3, (HL)\n");
return 12;
Expand Down Expand Up @@ -7447,6 +7463,7 @@ int CPU::SET_4_HLp()
{
// set the 4th bit
mMap->writeMemory(reg_HL.dat, (*mMap)[reg_HL.dat] | (1 << 4));

reg_PC.dat += 1;
debugPrint("SET 4, (HL)\n");
return 12;
Expand Down
1 change: 1 addition & 0 deletions src/gameBoy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ 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");
Expand Down
3 changes: 1 addition & 2 deletions src/mmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ bool MemoryMap::writeMemory(Word address, Byte value)
{
if (address < 0x8000)
{

printf("Writing to ROM is not allowed! Write attempted at %04X\n", address);
return false;
}
Expand Down Expand Up @@ -214,7 +213,7 @@ bool MemoryMap::writeMemory(Word address, Byte value)
printf("Invalid address\n");
return false;
}
printf("MMAP Address: %04X , value: %02X\n", address, value);

return true;
}

Expand Down

0 comments on commit 777fc01

Please sign in to comment.