57 lines
914 B
C
57 lines
914 B
C
|
#include <stdint.h>
|
||
|
|
||
|
struct cpu_flags {
|
||
|
uint8_t carry : 1;
|
||
|
uint8_t zero : 1;
|
||
|
uint8_t interrupt_disable : 1;
|
||
|
uint8_t decimal_mode : 1;
|
||
|
uint8_t brk : 1;
|
||
|
uint8_t unused : 1;
|
||
|
uint8_t overflow : 1;
|
||
|
uint8_t negative : 1;
|
||
|
};
|
||
|
|
||
|
struct registers {
|
||
|
uint8_t acc, x, y, sp;
|
||
|
struct cpu_flags status;
|
||
|
uint16_t pc;
|
||
|
};
|
||
|
struct registers regs;
|
||
|
|
||
|
enum addressing_mode {
|
||
|
AM_ACCUMULATOR,
|
||
|
AM_IMMEDIATE,
|
||
|
AM_ZERO_PAGE,
|
||
|
AM_ZERO_PAGE_X,
|
||
|
AM_ZERO_PAGE_Y,
|
||
|
AM_RELATIVE,
|
||
|
AM_ABSOLUTE,
|
||
|
AM_ABSOLUTE_X,
|
||
|
AM_ABSOLUTE_Y,
|
||
|
AM_INDIRECT,
|
||
|
AM_INDIRECT_X,
|
||
|
AM_INDIRECT_Y,
|
||
|
AM_INDEXED_INDIRECT,
|
||
|
AM_INDIRECT_INDEXED,
|
||
|
};
|
||
|
|
||
|
uint8_t addrbus[0x10000];
|
||
|
|
||
|
/* example program taken from https://bugzmanov.github.io/nes_ebook/chapter_3_1.html */
|
||
|
uint8_t program[] = { 0xa9, 0xc0, 0xaa, 0xe8, 0x00 };
|
||
|
|
||
|
void interpret(void)
|
||
|
{
|
||
|
uint8_t opcode;
|
||
|
regs.pc = 0;
|
||
|
|
||
|
for (;;) {
|
||
|
opcode = program[regs.pc++];
|
||
|
|
||
|
switch (opcode) {
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|