fix peek
This commit is contained in:
parent
36a8eefd00
commit
bd85b80ba7
16
cpu.c
16
cpu.c
@ -47,12 +47,12 @@ uint8_t memory[0x16000];
|
||||
uint8_t program[] = { 0xa9, 0xc0, 0xaa, 0xe8, 0x00 };
|
||||
|
||||
uint8_t
|
||||
peek(uint16_t addr)
|
||||
peek(uint8_t addr)
|
||||
{
|
||||
return memory[addr];
|
||||
}
|
||||
|
||||
uint16_t
|
||||
uint8_t
|
||||
peek16(uint16_t addr)
|
||||
{
|
||||
/* bytes are stored in little-endian (low then high) */
|
||||
@ -93,7 +93,10 @@ lda(enum addressing_mode mode)
|
||||
{
|
||||
uint8_t arg, val;
|
||||
|
||||
if (mode != AM_ABS && mode != AM_ABS_X && mode != AM_ABS_Y)
|
||||
arg = peek(regs.pc++);
|
||||
else
|
||||
arg = peek16(regs.pc++);
|
||||
|
||||
switch (mode) {
|
||||
case AM_IMM: /* $A9 */
|
||||
@ -103,16 +106,16 @@ lda(enum addressing_mode mode)
|
||||
val = peek(arg % 256);
|
||||
break;
|
||||
case AM_ABS: /* $AD */
|
||||
val = peek(arg);
|
||||
val = peek16(arg);
|
||||
break;
|
||||
case AM_ZP_X: /* $B5 */
|
||||
val = peek((arg + regs.x) % 256);
|
||||
break;
|
||||
case AM_ABS_X: /* $BD */
|
||||
val = peek(arg + regs.x);
|
||||
val = peek16(arg + regs.x);
|
||||
break;
|
||||
case AM_ABS_Y: /* $B9 */
|
||||
val = peek(arg + regs.y);
|
||||
val = peek16(arg + regs.y);
|
||||
break;
|
||||
case AM_IND_X: /* $A1 */
|
||||
val = peek(peek((arg + regs.x) % 256) + peek((arg + regs.x + 1) % 256) * 256);
|
||||
@ -121,7 +124,8 @@ lda(enum addressing_mode mode)
|
||||
val = peek(peek(arg) + peek((arg + 1) % 256) * 256 + regs.y);
|
||||
break;
|
||||
default:
|
||||
regs.pc--;
|
||||
fprintf(stderr, "INVALID LDA ADDRESSING MODE\n");
|
||||
abort();
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user