add lda immediate and brk

This commit is contained in:
Vineet K 2024-05-24 11:50:08 +05:30
parent dd757c4324
commit 24ca08a83d

60
cpu.c
View File

@ -40,6 +40,39 @@ uint8_t addrbus[0x10000];
/* example program taken from https://bugzmanov.github.io/nes_ebook/chapter_3_1.html */ /* example program taken from https://bugzmanov.github.io/nes_ebook/chapter_3_1.html */
uint8_t program[] = { 0xa9, 0xc0, 0xaa, 0xe8, 0x00 }; uint8_t program[] = { 0xa9, 0xc0, 0xaa, 0xe8, 0x00 };
void brk(void)
{
/* TODO: push regs.pc and regs.status to stack and load IRQ vector */
regs.status.brk = 1;
return;
}
void lda(enum addressing_mode mode)
{
uint8_t val;
switch (mode) {
case AM_IMMEDIATE: /* $A9 */
val = program[regs.pc++];
regs.acc = val;
break;
case AM_ZERO_PAGE: /* $A5 */
case AM_ZERO_PAGE_X: /* $B5 */
case AM_ABSOLUTE: /* $AD */
case AM_ABSOLUTE_X: /* $BD */
case AM_ABSOLUTE_Y: /* $B9 */
case AM_INDIRECT_X: /* $A1 */
case AM_INDIRECT_Y: /* $B1 */
/* TODO */
break;
default:
return;
}
regs.status.zero = regs.acc == 0;
regs.status.negative = (regs.acc & (1 << 7)) != 0;
}
void interpret(void) void interpret(void)
{ {
uint8_t opcode; uint8_t opcode;
@ -49,6 +82,33 @@ void interpret(void)
opcode = program[regs.pc++]; opcode = program[regs.pc++];
switch (opcode) { switch (opcode) {
case 0x00:
brk();
return;
case 0xa9:
lda(AM_IMMEDIATE);
break;
case 0xa5:
lda(AM_ZERO_PAGE);
break;
case 0xb5:
lda(AM_ZERO_PAGE_X);
break;
case 0xad:
lda(AM_ABSOLUTE);
break;
case 0xbd:
lda(AM_ABSOLUTE_X);
break;
case 0xb9:
lda(AM_ABSOLUTE_Y);
break;
case 0xa1:
lda(AM_INDIRECT_X);
break;
case 0xb1:
lda(AM_INDIRECT_Y);
break;
default: default:
break; break;
} }