Skip to content

Commit

Permalink
add LD_(BC)_A() opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
r41k0u committed Jan 21, 2023
1 parent ea18927 commit 8d0f4e8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
18 changes: 16 additions & 2 deletions src/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CPU::CPU()
int CPU::NOP()
{
reg_PC.dat += 1;
printf("NOP");
printf("NOP\n");
return 4;
}

Expand All @@ -40,10 +40,24 @@ int CPU::LD_BC_u16()
// OR the second byte
reg_BC.dat = ((*mMap)[reg_PC.dat + 1] << 8) | (*mMap)[reg_PC.dat + 2];
reg_PC.dat += 3;
printf("LD BC, u16");
printf("LD BC, u16\n");
return 12;
}

// LD (BC), A
// Loads the contents of A into the memory address pointed to by BC
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.lo);

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

printf("LD (BC), A\n");
return 8;
}

int CPU::executeNextInstruction()
{
// Get the opcode
Expand Down
11 changes: 8 additions & 3 deletions src/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class CPU
// ISA
// Pulled from https://izik1.github.io/gbops/index.html
typedef int (CPU::*method_function)();
method_function method_pointer[0x02] = {
method_function method_pointer[0x03] = {
&CPU::NOP,
&CPU::LD_BC_u16
// &CPU::LD_BC_A,
&CPU::LD_BC_u16,
&CPU::LD_BC_A
// &CPU::INC_BC,
// &CPU::INC_B,
// &CPU::DEC_B,
Expand Down Expand Up @@ -321,6 +321,9 @@ class CPU
// LD nn, nn
int LD_BC_u16();

// LD (BC), A
int LD_BC_A();

public:
const int clockSpeed = 4194304; // 4.194304 MHz CPU
const int clockSpeedPerFrame = 70224; // 4194304 / 59.73fps
Expand All @@ -330,5 +333,7 @@ class CPU
// set the memory map
void setMemory(MemoryMap* memory) { mMap = memory; }

void set_reg_BC(Word value) { reg_BC.dat = value; }

int executeNextInstruction();
};
3 changes: 3 additions & 0 deletions src/gameBoy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ GBE::GBE()
gbe_mMap->debugWriteMemory(0x0101, 0x01);
gbe_mMap->debugWriteMemory(0x0102, 0x02);
gbe_mMap->debugWriteMemory(0x0103, 0x03);
gbe_cpu->set_reg_BC(0x8001);
gbe_mMap->debugWriteMemory(0x0104, 0x02);
gbe_mMap->debugWriteMemory(0x0105, 0x04);

update();
}
Expand Down

0 comments on commit 8d0f4e8

Please sign in to comment.