cpu: fix dec_16

When getting the register index, an incorrect shift was being
used. Fix the test case by correcting this.

Signed-off-by: Max Regan <mgregan2@gmail.com>
This commit is contained in:
2017-04-07 16:36:38 -07:00
parent b6f9557d11
commit f8f17f91d0
3 changed files with 8 additions and 8 deletions

View File

@@ -77,7 +77,6 @@ static void test_dec(const void *test_data)
g_assert_cmpint(lr35902_get_reg_8(&cpu, LR35902_REG_H), ==, 0); g_assert_cmpint(lr35902_get_reg_8(&cpu, LR35902_REG_H), ==, 0);
g_assert_cmpint(lr35902_get_reg_16(&cpu, LR35902_REG_DE), ==, 0xffff); g_assert_cmpint(lr35902_get_reg_16(&cpu, LR35902_REG_DE), ==, 0xffff);
free(src); free(src);
} }

View File

@@ -734,10 +734,9 @@ static void ld_c_offset(struct lr35902_state *cpu, uint8_t instr)
static void ld_hl_d16(struct lr35902_state *cpu, uint8_t inst) static void ld_hl_d16(struct lr35902_state *cpu, uint8_t inst)
{ {
cpu->a = cpu->mem_read(cpu, cpu->hl++); cpu->hl = _pop_stack_16(cpu);
} }
static void inc_16(struct lr35902_state *cpu, uint8_t instr) static void inc_16(struct lr35902_state *cpu, uint8_t instr)
{ {
uint8_t reg; uint8_t reg;
@@ -772,8 +771,11 @@ static void dec(struct lr35902_state *cpu, uint8_t instr)
{ {
uint8_t reg = (instr >> 3) & 0x7; uint8_t reg = (instr >> 3) & 0x7;
uint8_t val = _get_reg_8(cpu, reg); uint8_t val = _get_reg_8(cpu, reg);
val--; DEBUG_LOG("reg=%d, val=%d", reg, val);
val--;
DEBUG_LOG("val2=%d", val);
_set_reg_8(cpu, reg, val); _set_reg_8(cpu, reg, val);
DEBUG_LOG("val3=%d", _get_reg_8(cpu, reg));
WRITE_BIT(cpu->f, LR35902_FLAG_BIT_Z, val == 0); WRITE_BIT(cpu->f, LR35902_FLAG_BIT_Z, val == 0);
WRITE_BIT(cpu->f, LR35902_FLAG_BIT_N, 1); WRITE_BIT(cpu->f, LR35902_FLAG_BIT_N, 1);
@@ -782,7 +784,7 @@ static void dec(struct lr35902_state *cpu, uint8_t instr)
static void dec_16(struct lr35902_state *cpu, uint8_t instr) static void dec_16(struct lr35902_state *cpu, uint8_t instr)
{ {
uint8_t reg = (instr & 0xF0) >> 8; uint8_t reg = (instr & 0xF0) >> 4;
uint16_t val; uint16_t val;
switch (reg) { switch (reg) {
@@ -804,8 +806,8 @@ static void dec_16(struct lr35902_state *cpu, uint8_t instr)
static void rlca(struct lr35902_state *cpu, uint8_t instr) static void rlca(struct lr35902_state *cpu, uint8_t instr)
{ {
uint8_t reg = LR35902_REG_A; uint8_t reg = LR35902_REG_A;
uint8_t val = _get_reg_8(cpu, reg); uint8_t val = _get_reg_8(cpu, reg);
uint8_t new_val = 0; uint8_t new_val = 0;
new_val = (val << 1); new_val = (val << 1);

View File

@@ -37,7 +37,6 @@ typedef enum {
NUM_LR35902_REGS_8 NUM_LR35902_REGS_8
} lr35902_regs_8; } lr35902_regs_8;
typedef enum { typedef enum {
LR35902_INT_ON, LR35902_INT_ON,
LR35902_INT_OFF, LR35902_INT_OFF,