fix more bugs

This commit is contained in:
Vineet K 2024-06-28 10:28:53 -04:00
parent 09692f45f6
commit c1a42045e6

53
cpu.c
View File

@ -138,15 +138,12 @@ opcode_arg(enum addressing_mode mode)
break;
case AM_ABS:
val = peek16(arg);
printf("$%04X", arg);
break;
case AM_ABS_X:
val = peek16(arg + regs.x);
printf("$%04X", arg);
break;
case AM_ABS_Y:
val = peek16(arg + regs.y);
printf("$%04X", arg);
break;
case AM_IND_X:
val = peek(peek((arg + regs.x) % 256) + peek((arg + regs.x + 1) % 256) * 256);
@ -155,7 +152,7 @@ opcode_arg(enum addressing_mode mode)
val = peek(peek(arg) + peek((arg + 1) % 256) * 256 + regs.y);
break;
default:
fprintf(stderr, "INVALID ADDRESSING MODE\n");
fprintf(stderr, "INVALID ADDRESSING MODE %i\n", mode);
abort();
}
@ -196,6 +193,9 @@ opcode_mem(enum addressing_mode mode)
case AM_ABS_Y:
val = arg + regs.y;
break;
case AM_IND:
val = peek16(arg);
break;
case AM_IND_X:
val = peek((arg + regs.x) % 256) + peek((arg + regs.x + 1) % 256) * 256;
break;
@ -754,7 +754,8 @@ tya(void)
static void
interpret(void)
{
uint8_t opcode, cycles_;
uint8_t opcode;
uint32_t cycles_;
for (;;) {
opcode = peek(regs.pc++);
@ -793,11 +794,6 @@ interpret(void)
cycles += 4;
printf("ADC");
break;
case 0x72:
adc(opcode_arg(AM_IND));
cycles += 5;
printf("ADC");
break;
case 0x61:
adc(opcode_arg(AM_IND_X));
cycles += 6;
@ -838,11 +834,6 @@ interpret(void)
cycles += 4;
printf("AND");
break;
case 0x32:
and(opcode_arg(AM_IND));
cycles += 5;
printf("AND");
break;
case 0x21:
and(opcode_arg(AM_IND_X));
cycles += 6;
@ -998,11 +989,6 @@ interpret(void)
cycles += 4;
printf("CMP");
break;
case 0xd2:
cmp(opcode_arg(AM_IND));
cycles += 5;
printf("CMP");
break;
case 0xc1:
cmp(opcode_arg(AM_IND_X));
cycles += 6;
@ -1103,11 +1089,6 @@ interpret(void)
cycles += 4;
printf("EOR");
break;
case 0x52:
eor(opcode_arg(AM_IND));
cycles += 5;
printf("EOR");
break;
case 0x41:
eor(opcode_arg(AM_IND_X));
cycles += 6;
@ -1154,7 +1135,7 @@ interpret(void)
printf("JMP");
break;
case 0x6c:
jmp(opcode_arg(AM_IND));
jmp(opcode_mem(AM_IND));
cycles += 6;
printf("JMP");
break;
@ -1198,11 +1179,6 @@ interpret(void)
cycles += 4;
printf("LDA");
break;
case 0xb2:
lda(opcode_arg(AM_IND));
cycles += 5;
printf("LDA");
break;
case 0xa1:
lda(opcode_arg(AM_IND_X));
cycles += 6;
@ -1323,11 +1299,6 @@ interpret(void)
cycles += 4;
printf("ORA");
break;
case 0x12:
ora(opcode_arg(AM_IND));
cycles += 5;
printf("ORA");
break;
case 0x01:
ora(opcode_arg(AM_IND_X));
cycles += 6;
@ -1448,11 +1419,6 @@ interpret(void)
cycles += 4;
printf("SBC");
break;
case 0xf2:
sbc(opcode_arg(AM_IND));
cycles += 5;
printf("SBC");
break;
case 0xe1:
sbc(opcode_arg(AM_IND_X));
cycles += 6;
@ -1503,11 +1469,6 @@ interpret(void)
cycles += 6;
printf("STA");
break;
case 0x92:
sta(opcode_mem(AM_IND));
cycles += 6;
printf("STA");
break;
case 0x81:
sta(opcode_mem(AM_IND_X));
cycles += 7;