cpu: get blargh cpu test 3 passing
This commit is contained in:
@@ -25,7 +25,7 @@ assert $hl == 0x9ffe
|
|||||||
step
|
step
|
||||||
|
|
||||||
assert $pc == 10
|
assert $pc == 10
|
||||||
assert $f == 0x2
|
assert $f == 0x20
|
||||||
step
|
step
|
||||||
|
|
||||||
runto 0xc
|
runto 0xc
|
||||||
|
|||||||
@@ -22,6 +22,10 @@
|
|||||||
#define CALC_H_ADD(a, b) ((((a) & 0xf) + ((b) & 0xf)) > 0xf)
|
#define CALC_H_ADD(a, b) ((((a) & 0xf) + ((b) & 0xf)) > 0xf)
|
||||||
#define CALC_H_SUB(a, b) (((a) & 0xf) < ((b) & 0xf))
|
#define CALC_H_SUB(a, b) (((a) & 0xf) < ((b) & 0xf))
|
||||||
|
|
||||||
|
#define CARRY_MASK(idx) ((1 << idx) - 1)
|
||||||
|
#define ADD_CARRY(a, b, idx) \
|
||||||
|
((((a) & CARRY_MASK(idx)) + ((b) & CARRY_MASK(idx))) > CARRY_MASK(idx))
|
||||||
|
|
||||||
#define CALC_C_ADD_16(a, b) (0xffff - (a) < (b))
|
#define CALC_C_ADD_16(a, b) (0xffff - (a) < (b))
|
||||||
#define CALC_C_ADD_8(a, b) (0xff - (a) < (b))
|
#define CALC_C_ADD_8(a, b) (0xff - (a) < (b))
|
||||||
#define CALC_C_SUB(a, b) ((a) < (b))
|
#define CALC_C_SUB(a, b) ((a) < (b))
|
||||||
@@ -400,8 +404,10 @@ int lr35902_cycle(struct lr35902_state *cpu)
|
|||||||
WRITE_BIT(cpu->a, 0, cpu->cf);
|
WRITE_BIT(cpu->a, 0, cpu->cf);
|
||||||
break;
|
break;
|
||||||
case 0x08: /* LD (a16), SP */
|
case 0x08: /* LD (a16), SP */
|
||||||
cpu->sp = gb_mem_read(cpu->memory, cpu->pc++);
|
val_16 = gb_mem_read(cpu->memory, cpu->pc++);
|
||||||
cpu->sp |= gb_mem_read(cpu->memory, cpu->pc++) << 8;
|
val_16 |= gb_mem_read(cpu->memory, cpu->pc++) << 8;
|
||||||
|
gb_mem_write(cpu->memory, val_16, cpu->sp & 0xff);
|
||||||
|
gb_mem_write(cpu->memory, val_16 + 1, (cpu->sp >> 8) & 0xff);
|
||||||
break;
|
break;
|
||||||
case 0x09: /* ADD HL, BC */
|
case 0x09: /* ADD HL, BC */
|
||||||
ADD_16(cpu, cpu->hl, cpu->bc);
|
ADD_16(cpu, cpu->hl, cpu->bc);
|
||||||
@@ -1538,8 +1544,17 @@ int lr35902_cycle(struct lr35902_state *cpu)
|
|||||||
case 0xe7: /* RST 0x20 */
|
case 0xe7: /* RST 0x20 */
|
||||||
RST(cpu, 0x20);
|
RST(cpu, 0x20);
|
||||||
break;
|
break;
|
||||||
case 0xe8:
|
case 0xe8: /* ADD SP, r8 */
|
||||||
ASSERT(0);
|
val_16 = gb_mem_read(cpu->memory, cpu->pc++);
|
||||||
|
if (val_16 & 0x80) {
|
||||||
|
val_16 |= 0xff00;
|
||||||
|
}
|
||||||
|
cpu->cf = ADD_CARRY(cpu->sp, val_16, 8);
|
||||||
|
cpu->hf = ADD_CARRY(cpu->sp, val_16, 4);
|
||||||
|
cpu->zf = 0;
|
||||||
|
cpu->nf = 0;
|
||||||
|
cpu->sp += val_16;
|
||||||
|
break;
|
||||||
case 0xe9: /* JP (hl) */
|
case 0xe9: /* JP (hl) */
|
||||||
cpu->pc = cpu->hl;
|
cpu->pc = cpu->hl;
|
||||||
break;
|
break;
|
||||||
@@ -1597,9 +1612,19 @@ int lr35902_cycle(struct lr35902_state *cpu)
|
|||||||
case 0xf7: /* RST 0x30 */
|
case 0xf7: /* RST 0x30 */
|
||||||
RST(cpu, 0x30);
|
RST(cpu, 0x30);
|
||||||
break;
|
break;
|
||||||
case 0xf8:
|
case 0xf8: /* LD HL, SP+r8 */
|
||||||
case 0xf9:
|
val_16 = gb_mem_read(cpu->memory, cpu->pc++);
|
||||||
ASSERT(0);
|
if (val_16 & 0x80) {
|
||||||
|
val_16 |= 0xff00;
|
||||||
|
}
|
||||||
|
cpu->cf = ADD_CARRY(cpu->sp, val_16, 8);
|
||||||
|
cpu->hf = ADD_CARRY(cpu->sp, val_16, 4);
|
||||||
|
cpu->zf = 0;
|
||||||
|
cpu->nf = 0;
|
||||||
|
cpu->hl = cpu->sp + val_16;
|
||||||
|
break;
|
||||||
|
case 0xf9: /* LD SP, HL */
|
||||||
|
cpu->sp = cpu->hl;
|
||||||
break;
|
break;
|
||||||
case 0xfa:
|
case 0xfa:
|
||||||
val_16 = gb_mem_read(cpu->memory, cpu->pc++);
|
val_16 = gb_mem_read(cpu->memory, cpu->pc++);
|
||||||
@@ -1607,7 +1632,7 @@ int lr35902_cycle(struct lr35902_state *cpu)
|
|||||||
cpu->a = gb_mem_read(cpu->memory, val_16);
|
cpu->a = gb_mem_read(cpu->memory, val_16);
|
||||||
break;
|
break;
|
||||||
case 0xfb: /* EI */
|
case 0xfb: /* EI */
|
||||||
gb_log0("Interrupts ON\n");
|
gb_log("Interrupts ON\n");
|
||||||
break;
|
break;
|
||||||
case 0xfc: /* UNDEF */
|
case 0xfc: /* UNDEF */
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user