You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB
C

/*
* emu6502
*
* MOS 6502 emulator
*/
#ifndef _EMU6502_H
#define _EMU6502_H
#include <stdint.h>
typedef uint16_t word;
typedef uint8_t byte;
#define CPUFLAG_NEGATIVE 0x80
#define CPUFLAG_OVERFLOW 0x40
#define CPUFLAG_ALWAYSONE 0x20
#define CPUFLAG_BREAK 0x10
#define CPUFLAG_DECIMAL 0x08
#define CPUFLAG_INTERRUPT 0x04
#define CPUFLAG_ZERO 0x02
#define CPUFLAG_CARRY 0x01
typedef struct CPU6502 {
byte a, x, y, sp; // 8-bit registers
word pc; // 16-bit registers
byte flags; // CPU flags
// Better for memory-mapped I/O!
void (*write)(struct CPU6502*, word, byte);
byte (*read)(struct CPU6502*, word);
} CPU6502;
// fn(cpu, address, byte)
typedef void (*CPUwrite)(struct CPU6502*, word, byte);
// fn(cpu, address)
typedef byte (*CPUread)(struct CPU6502*, word);
// opcodes.c
void emu6502_init_cpu(CPU6502* cpu);
void emu6502_run_opcode(CPU6502* cpu);
void emu6502_reset(CPU6502*);
void emu6502_irq(CPU6502*);
void emu6502_nmi(CPU6502*);
#define CPUWRITE(cpu,addr,val) (cpu->write(cpu, addr, val))
#define CPUREAD(cpu,addr) (cpu->read(cpu, addr))
#define CPUPUSH(cpu,v) (cpu->write(cpu, 0x100 + (cpu->sp--), v))
#define CPUPOP(cpu) (cpu->read(cpu, 0x100 + (++cpu->sp)))
#endif