Skip to content

Commit

Permalink
Write dec B and update flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Aviii06 authored and r41k0u committed Jan 21, 2023
1 parent 3042c51 commit c4dab4b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
36 changes: 34 additions & 2 deletions src/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,41 @@ int CPU::LD_BC_A()
return 8;
}

int CPU::INC_BC() { return 0; }
int CPU::INC_BC()
{
reg_BC.dat += 1;
reg_PC.dat += 1;
printf("INC BC\n");
return 8;
}
int CPU::INC_B() { return 0; }
int CPU::DEC_B() { return 0; }
int CPU::DEC_B()
{
reg_BC.hi -= 1;
if (reg_BC.hi == 0)
{
reg_AF.lo |= FLAG_ZERO_z;
}
else
{
reg_AF.lo &= ~FLAG_ZERO_z;
}

reg_AF.lo |= FLAG_SUBTRACT_n;

if (reg_BC.hi == 0xFF)
{
reg_AF.lo |= FLAG_HALF_CARRY_h;
}
else
{
reg_AF.lo &= ~FLAG_HALF_CARRY_h;
}

reg_PC.dat += 1;
printf("DEC B\n");
return 4;
}
int CPU::LD_B_u8() { return 0; }
int CPU::RLCA() { return 0; }
int CPU::LD_u16_SP() { return 0; }
Expand Down
8 changes: 4 additions & 4 deletions src/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class CPU
// Bit 0-3 are not used
enum Flags
{
FLAG_CARRY_c = 4,
FLAG_HALF_CARRY_h = 5,
FLAG_SUBTRACT_n = 6,
FLAG_ZERO_z = 7
FLAG_CARRY_c = 0x10,
FLAG_HALF_CARRY_h = 0x20,
FLAG_SUBTRACT_n = 0x40,
FLAG_ZERO_z = 0x80
};

// Memory Map
Expand Down

0 comments on commit c4dab4b

Please sign in to comment.