6502-emu/6502.h

78 lines
1.3 KiB
C
Raw Permalink Normal View History

2017-01-03 19:39:48 +00:00
#include <stdint.h>
2017-01-07 21:25:34 +00:00
#include <stdbool.h>
2017-01-03 19:39:48 +00:00
#define CPU_FREQ 4e6 // 4Mhz
#define STEP_DURATION 10e6 // 10ms
2017-01-03 19:39:48 +00:00
#define ONE_SECOND 1e9
#define NUM_MODES 14
2017-01-03 19:39:48 +00:00
#define NMI_VEC 0xFFFA
#define RST_VEC 0xFFFC
#define IRQ_VEC 0xFFFE
extern uint8_t memory[1<<16];
extern uint8_t A;
extern uint8_t X;
extern uint8_t Y;
extern uint16_t PC;
extern uint8_t SP; // points to first empty stack location
extern uint8_t extra_cycles;
extern uint64_t total_cycles;
2017-01-03 19:39:48 +00:00
2020-12-11 16:18:42 +00:00
extern void *read_addr;
extern void *write_addr;
2017-01-03 19:39:48 +00:00
struct StatusBits{
2017-01-07 21:25:34 +00:00
bool carry:1; // bit 0
bool zero:1;
bool interrupt:1;
bool decimal:1;
bool brk:1; // "break" is a reserved word :(
bool unused:1;
bool overflow:1;
bool sign:1; // bit 7
2017-01-03 19:39:48 +00:00
};
union StatusReg { // this means we can access the status register as a byte, or as individual bits.
struct StatusBits bits;
uint8_t byte;
};
extern union StatusReg SR;
2017-01-03 19:39:48 +00:00
typedef enum {
ACC,
ABS,
ABSX,
ABSY,
IMM,
IMPL,
IND,
XIND,
INDY,
REL,
ZP,
ZPX,
2017-12-18 19:27:17 +00:00
ZPY,
JMP_IND_BUG,
2017-01-03 19:39:48 +00:00
} Mode;
typedef struct {
const char *mnemonic;
2017-01-03 19:39:48 +00:00
void (*function)();
Mode mode;
uint8_t cycles;
2017-01-03 19:39:48 +00:00
} Instruction;
2020-12-11 16:18:42 +00:00
//extern Instruction instructions[0x100];
2017-01-03 19:39:48 +00:00
2020-12-11 16:18:42 +00:00
//void init_tables();
2017-01-03 19:39:48 +00:00
void reset_cpu(int _a, int _x, int _y, int _sp, int _sr, int _pc);
2017-01-03 19:39:48 +00:00
2020-12-11 16:18:42 +00:00
int load_rom(char *filename, int load_addr);
2017-01-03 19:39:48 +00:00
int step_cpu(int verbose);
void save_memory(const char *filename);