shorten addressing mode enum names

This commit is contained in:
Vineet K 2024-06-04 16:16:11 +05:30
parent 7245191e86
commit 36a8eefd00

58
cpu.c
View File

@ -26,20 +26,18 @@ struct registers {
struct registers regs; struct registers regs;
enum addressing_mode { enum addressing_mode {
AM_ACCUMULATOR, AM_ACC,
AM_IMMEDIATE, AM_IMM,
AM_ZERO_PAGE, AM_ZP,
AM_ZERO_PAGE_X, AM_ZP_X,
AM_ZERO_PAGE_Y, AM_ZP_Y,
AM_RELATIVE, AM_REL,
AM_ABSOLUTE, AM_ABS,
AM_ABSOLUTE_X, AM_ABS_X,
AM_ABSOLUTE_Y, AM_ABS_Y,
AM_INDIRECT, AM_IND,
AM_INDIRECT_X, AM_IND_X,
AM_INDIRECT_Y, AM_IND_Y,
AM_INDEXED_INDIRECT,
AM_INDIRECT_INDEXED,
}; };
/* 64K address space, 16bit words */ /* 64K address space, 16bit words */
@ -98,28 +96,28 @@ lda(enum addressing_mode mode)
arg = peek(regs.pc++); arg = peek(regs.pc++);
switch (mode) { switch (mode) {
case AM_IMMEDIATE: /* $A9 */ case AM_IMM: /* $A9 */
val = arg; val = arg;
break; break;
case AM_ZERO_PAGE: /* $A5 */ case AM_ZP: /* $A5 */
val = peek(arg % 256); val = peek(arg % 256);
break; break;
case AM_ABSOLUTE: /* $AD */ case AM_ABS: /* $AD */
val = peek(arg); val = peek(arg);
break; break;
case AM_ZERO_PAGE_X: /* $B5 */ case AM_ZP_X: /* $B5 */
val = peek((arg + regs.x) % 256); val = peek((arg + regs.x) % 256);
break; break;
case AM_ABSOLUTE_X: /* $BD */ case AM_ABS_X: /* $BD */
val = peek(arg + regs.x); val = peek(arg + regs.x);
break; break;
case AM_ABSOLUTE_Y: /* $B9 */ case AM_ABS_Y: /* $B9 */
val = peek(arg + regs.y); val = peek(arg + regs.y);
break; break;
case AM_INDIRECT_X: /* $A1 */ case AM_IND_X: /* $A1 */
val = peek(peek((arg + regs.x) % 256) + peek((arg + regs.x + 1) % 256) * 256); val = peek(peek((arg + regs.x) % 256) + peek((arg + regs.x + 1) % 256) * 256);
break; break;
case AM_INDIRECT_Y: /* $B1 */ case AM_IND_Y: /* $B1 */
val = peek(peek(arg) + peek((arg + 1) % 256) * 256 + regs.y); val = peek(peek(arg) + peek((arg + 1) % 256) * 256 + regs.y);
break; break;
default: default:
@ -149,31 +147,31 @@ interpret(void)
brk(); brk();
return; return;
case 0xa1: case 0xa1:
lda(AM_INDIRECT_X); lda(AM_IND_X);
break; break;
case 0xa5: case 0xa5:
lda(AM_ZERO_PAGE); lda(AM_ZP);
break; break;
case 0xa9: case 0xa9:
lda(AM_IMMEDIATE); lda(AM_IMM);
break; break;
case 0xaa: case 0xaa:
tax(); tax();
break; break;
case 0xad: case 0xad:
lda(AM_ABSOLUTE); lda(AM_ABS);
break; break;
case 0xb1: case 0xb1:
lda(AM_INDIRECT_Y); lda(AM_IND_Y);
break; break;
case 0xb5: case 0xb5:
lda(AM_ZERO_PAGE_X); lda(AM_ZP_X);
break; break;
case 0xb9: case 0xb9:
lda(AM_ABSOLUTE_Y); lda(AM_ABS_Y);
break; break;
case 0xbd: case 0xbd:
lda(AM_ABSOLUTE_X); lda(AM_ABS_X);
break; break;
case 0xe8: case 0xe8:
inx(); inx();