From 23008662cea16d4ad2a3253d883a634258378d60 Mon Sep 17 00:00:00 2001 From: vin Date: Sun, 9 Jun 2024 22:50:33 +0530 Subject: [PATCH] implement more instructions --- cpu.c | 66 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/cpu.c b/cpu.c index 65e60d4..8c88959 100644 --- a/cpu.c +++ b/cpu.c @@ -244,7 +244,7 @@ bit(uint8_t arg) { regs.status.zero = (regs.a & arg) == 0; regs.status.overflow = (arg & (1 << 6)) > 0; - regs.status.negative = (arg & (1 << 7)) > 0; + STATUS_UPDATE_NEGATIVE(arg); } static void @@ -329,7 +329,7 @@ cmp(uint8_t arg) regs.status.carry = regs.a >= arg; regs.status.zero = regs.a == arg; - regs.status.negative = (tmp & (1 << 7)) > 0; + STATUS_UPDATE_NEGATIVE(tmp); } static void @@ -341,7 +341,7 @@ cpx(uint8_t arg) regs.status.carry = regs.x >= arg; regs.status.zero = regs.x == arg; - regs.status.negative = (tmp & (1 << 7)) > 0; + STATUS_UPDATE_NEGATIVE(tmp); } static void @@ -353,37 +353,52 @@ cpy(uint8_t arg) regs.status.carry = regs.y >= arg; regs.status.zero = regs.y == arg; - regs.status.negative = (tmp & (1 << 7)) > 0; + STATUS_UPDATE_NEGATIVE(tmp); } static void dec(uint16_t mem) { memwrite(mem, peek(mem) - 1); + + STATUS_UPDATE_ZERO(peek(mem)); + STATUS_UPDATE_NEGATIVE(peek(mem)); } 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 -dey(uint8_t arg) +dey(void) { -/* TODO: complete this */ + regs.y--; + + STATUS_UPDATE_ZERO(regs.y); + STATUS_UPDATE_NEGATIVE(regs.y); } static void eor(uint8_t arg) { -/* TODO: complete this */ + regs.a ^= arg; + + STATUS_UPDATE_ZERO(regs.a); + STATUS_UPDATE_NEGATIVE(regs.a); } 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 @@ -398,13 +413,16 @@ inx(void) static void iny(uint8_t arg) { -/* TODO: complete this */ + regs.y++; + + STATUS_UPDATE_ZERO(regs.y); + STATUS_UPDATE_NEGATIVE(regs.y); } static void jmp(uint8_t arg) { -/* TODO: complete this */ + regs.pc = arg; } static void @@ -416,7 +434,6 @@ jsr(uint8_t arg) static void lda(uint8_t arg) { - printf("arg1 $%02X\n", arg); regs.a = arg; STATUS_UPDATE_ZERO(regs.a); @@ -426,13 +443,19 @@ lda(uint8_t arg) static void ldx(uint8_t arg) { -/* TODO: complete this */ + regs.x = arg; + + STATUS_UPDATE_ZERO(regs.x); + STATUS_UPDATE_NEGATIVE(regs.x); } static void ldy(uint8_t arg) { -/* TODO: complete this */ + regs.y = arg; + + STATUS_UPDATE_ZERO(regs.y); + STATUS_UPDATE_NEGATIVE(regs.y); } static void @@ -444,13 +467,16 @@ lsr(uint8_t arg) static void nop(uint8_t arg) { -/* TODO: complete this */ + return; } static void ora(uint8_t arg) { -/* TODO: complete this */ + regs.a |= arg; + + STATUS_UPDATE_ZERO(regs.a); + STATUS_UPDATE_NEGATIVE(regs.a); } static void @@ -975,11 +1001,11 @@ interpret(void) cycles += 7; break; case 0xca: - dex(opcode_arg(AM_ACC)); + dex(); cycles += 2; break; case 0x88: - dey(opcode_arg(AM_ACC)); + dey(); cycles += 2; break; case 0x49: