Corrigiendo instrucciones segun flags test

This commit is contained in:
2025-06-28 19:02:35 -04:00
parent 4b897f48e0
commit 437fab8efe

View File

@@ -363,16 +363,9 @@ void Interpreter::add_vx_vy(const Instruction& instruction) const
const auto& vy = this->machine_state->v[instruction.y]; const auto& vy = this->machine_state->v[instruction.y];
auto& vf = this->machine_state->v[0xF]; auto& vf = this->machine_state->v[0xF];
if (vx + vy > 0x100) const bool carry = vx + vy > 0x100;
{
vf = 1;
}
else
{
vf = 0;
}
vx = (vx + vy) & 0xFF; vx = (vx + vy) & 0xFF;
vf = carry ? 1 : 0;
} }
void Interpreter::sub_vx_vy(const Instruction& instruction) const void Interpreter::sub_vx_vy(const Instruction& instruction) const
@@ -381,16 +374,9 @@ void Interpreter::sub_vx_vy(const Instruction& instruction) const
const auto& vy = this->machine_state->v[instruction.y]; const auto& vy = this->machine_state->v[instruction.y];
auto& vf = this->machine_state->v[0xF]; auto& vf = this->machine_state->v[0xF];
if (vx >= vy) const bool carry = vx >= vy;
{
vf = 1;
}
else
{
vf = 0;
}
vx = (vx - vy) & 0xFF; vx = (vx - vy) & 0xFF;
vf = carry ? 1 : 0;
} }
void Interpreter::shr_vx_vy(const Instruction& instruction) const void Interpreter::shr_vx_vy(const Instruction& instruction) const
@@ -404,16 +390,9 @@ void Interpreter::shr_vx_vy(const Instruction& instruction) const
vx = vy; vx = vy;
} }
if (vx & 0x01) const bool carry = vx & 0x01;
{
vf = 1;
}
else
{
vf = 0;
}
vx = vx >> 1; vx = vx >> 1;
vf = carry ? 1 : 0;
} }
void Interpreter::subn_vx_vy(const Instruction& instruction) const void Interpreter::subn_vx_vy(const Instruction& instruction) const
@@ -422,16 +401,9 @@ void Interpreter::subn_vx_vy(const Instruction& instruction) const
const auto& vy = this->machine_state->v[instruction.y]; const auto& vy = this->machine_state->v[instruction.y];
auto& vf = this->machine_state->v[0xF]; auto& vf = this->machine_state->v[0xF];
if (vy >= vx) const bool carry = vy >= vx;
{
vf = 1;
}
else
{
vf = 0;
}
vx = (vy - vx) & 0xFF; vx = (vy - vx) & 0xFF;
vf = carry ? 1 : 0;
} }
void Interpreter::shl_vx_vy(const Instruction& instruction) const void Interpreter::shl_vx_vy(const Instruction& instruction) const
@@ -445,16 +417,9 @@ void Interpreter::shl_vx_vy(const Instruction& instruction) const
vx = vy; vx = vy;
} }
if (vx & 0x80) const bool carry = vx & 0x80;
{
vf = 1;
}
else
{
vf = 0;
}
vx = vx << 1 & 0xFF; vx = vx << 1 & 0xFF;
vf = carry ? 1 : 0;
} }
void Interpreter::sne_vx_vy(const Instruction& instruction) const void Interpreter::sne_vx_vy(const Instruction& instruction) const
@@ -503,6 +468,7 @@ void Interpreter::drw_vx_vy_nibble(const Instruction& instruction) const
const uint8_t start_y = vy & 31; const uint8_t start_y = vy & 31;
vf = 0; vf = 0;
bool carry = false;
for (auto row = 0; row < instruction.n; row++) for (auto row = 0; row < instruction.n; row++)
{ {
const auto current_y = start_y + row; const auto current_y = start_y + row;
@@ -531,7 +497,7 @@ void Interpreter::drw_vx_vy_nibble(const Instruction& instruction) const
if (display[index]) if (display[index])
{ {
display[index] = false; display[index] = false;
vf = 1; carry = true;
} }
else else
{ {
@@ -540,6 +506,8 @@ void Interpreter::drw_vx_vy_nibble(const Instruction& instruction) const
} }
} }
} }
vf = carry ? 1 : 0;
} }
void Interpreter::skp_vx(const Instruction& instruction) const void Interpreter::skp_vx(const Instruction& instruction) const