emu_nes

An NES emulator for learning how the 6502 and similar computers of the era worked
Log | Files | Refs | README | LICENSE

commit dd757c4324f856c8f91d79a4f741d8bb6477064a
parent 5fcf579ad42a4fce332bbc04bb4ea364e0034c70
Author: vin <git@vineetk.net>
Date:   Mon, 20 May 2024 19:39:19 +0530

start working on 6502 cpu

Diffstat:
Acpu.c | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+), 0 deletions(-)

diff --git a/cpu.c b/cpu.c @@ -0,0 +1,56 @@ +#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; + } + } +}