implement more instructions

This commit is contained in:
Vineet K 2024-06-09 22:50:33 +05:30
parent 68ecbce235
commit 23008662ce

66
cpu.c
View File

@ -244,7 +244,7 @@ bit(uint8_t arg)
{ {
regs.status.zero = (regs.a & arg) == 0; regs.status.zero = (regs.a & arg) == 0;
regs.status.overflow = (arg & (1 << 6)) > 0; regs.status.overflow = (arg & (1 << 6)) > 0;
regs.status.negative = (arg & (1 << 7)) > 0; STATUS_UPDATE_NEGATIVE(arg);
} }
static void static void
@ -329,7 +329,7 @@ cmp(uint8_t arg)
regs.status.carry = regs.a >= arg; regs.status.carry = regs.a >= arg;
regs.status.zero = regs.a == arg; regs.status.zero = regs.a == arg;
regs.status.negative = (tmp & (1 << 7)) > 0; STATUS_UPDATE_NEGATIVE(tmp);
} }
static void static void
@ -341,7 +341,7 @@ cpx(uint8_t arg)
regs.status.carry = regs.x >= arg; regs.status.carry = regs.x >= arg;
regs.status.zero = regs.x == arg; regs.status.zero = regs.x == arg;
regs.status.negative = (tmp & (1 << 7)) > 0; STATUS_UPDATE_NEGATIVE(tmp);
} }
static void static void
@ -353,37 +353,52 @@ cpy(uint8_t arg)
regs.status.carry = regs.y >= arg; regs.status.carry = regs.y >= arg;
regs.status.zero = regs.y == arg; regs.status.zero = regs.y == arg;
regs.status.negative = (tmp & (1 << 7)) > 0; STATUS_UPDATE_NEGATIVE(tmp);
} }
static void static void
dec(uint16_t mem) dec(uint16_t mem)
{ {
memwrite(mem, peek(mem) - 1); memwrite(mem, peek(mem) - 1);
STATUS_UPDATE_ZERO(peek(mem));
STATUS_UPDATE_NEGATIVE(peek(mem));
} }
static void static void
dex(uint8_t arg) dex(void)
{ {
/* TODO: complete this */ regs.x--;
STATUS_UPDATE_ZERO(regs.x);
STATUS_UPDATE_NEGATIVE(regs.x);
} }
static void static void
dey(uint8_t arg) dey(void)
{ {
/* TODO: complete this */ regs.y--;
STATUS_UPDATE_ZERO(regs.y);
STATUS_UPDATE_NEGATIVE(regs.y);
} }
static void static void
eor(uint8_t arg) eor(uint8_t arg)
{ {
/* TODO: complete this */ regs.a ^= arg;
STATUS_UPDATE_ZERO(regs.a);
STATUS_UPDATE_NEGATIVE(regs.a);
} }
static void static void
inc(uint8_t arg) inc(uint16_t mem)
{ {
/* TODO: complete this */ memwrite(mem, peek(mem) + 1);
STATUS_UPDATE_ZERO(peek(mem));
STATUS_UPDATE_NEGATIVE(peek(mem));
} }
static void static void
@ -398,13 +413,16 @@ inx(void)
static void static void
iny(uint8_t arg) iny(uint8_t arg)
{ {
/* TODO: complete this */ regs.y++;
STATUS_UPDATE_ZERO(regs.y);
STATUS_UPDATE_NEGATIVE(regs.y);
} }
static void static void
jmp(uint8_t arg) jmp(uint8_t arg)
{ {
/* TODO: complete this */ regs.pc = arg;
} }
static void static void
@ -416,7 +434,6 @@ jsr(uint8_t arg)
static void static void
lda(uint8_t arg) lda(uint8_t arg)
{ {
printf("arg1 $%02X\n", arg);
regs.a = arg; regs.a = arg;
STATUS_UPDATE_ZERO(regs.a); STATUS_UPDATE_ZERO(regs.a);
@ -426,13 +443,19 @@ lda(uint8_t arg)
static void static void
ldx(uint8_t arg) ldx(uint8_t arg)
{ {
/* TODO: complete this */ regs.x = arg;
STATUS_UPDATE_ZERO(regs.x);
STATUS_UPDATE_NEGATIVE(regs.x);
} }
static void static void
ldy(uint8_t arg) ldy(uint8_t arg)
{ {
/* TODO: complete this */ regs.y = arg;
STATUS_UPDATE_ZERO(regs.y);
STATUS_UPDATE_NEGATIVE(regs.y);
} }
static void static void
@ -444,13 +467,16 @@ lsr(uint8_t arg)
static void static void
nop(uint8_t arg) nop(uint8_t arg)
{ {
/* TODO: complete this */ return;
} }
static void static void
ora(uint8_t arg) ora(uint8_t arg)
{ {
/* TODO: complete this */ regs.a |= arg;
STATUS_UPDATE_ZERO(regs.a);
STATUS_UPDATE_NEGATIVE(regs.a);
} }
static void static void
@ -975,11 +1001,11 @@ interpret(void)
cycles += 7; cycles += 7;
break; break;
case 0xca: case 0xca:
dex(opcode_arg(AM_ACC)); dex();
cycles += 2; cycles += 2;
break; break;
case 0x88: case 0x88:
dey(opcode_arg(AM_ACC)); dey();
cycles += 2; cycles += 2;
break; break;
case 0x49: case 0x49: