NESEmulator/NES Emulator/cpu.h

105 lines
1.5 KiB
C
Raw Permalink Normal View History

2021-10-20 20:39:29 +00:00
#ifndef _CPU_H_
#define _CPU_H_
#include "types.h"
struct Bus;
2021-10-22 14:39:48 +00:00
enum Operation
2021-10-21 17:24:53 +00:00
{
XXX = 0,
ADC, AND, ASL, BCC, BCS, BEQ, BIT, BMI,
BNE, BPL, BRK, BVC, BVS, CLC, CLD, CLI,
CLV, CMP, CPX, CPY, DEC, DEX, DEY, EOR,
INC, INX, INY, JMP, JSR, LDA, LDX, LDY,
LSR, NOP, ORA, PHA, PHP, PLA, PLP, ROL,
ROR, RTI, RTS, SBC, SEC, SED, SEI, STA,
2021-10-22 23:29:15 +00:00
STX, STY, TAX, TAY, TSX, TXA, TXS, TYA,
ANC, ASR, ARR, DCP, ISC, JAM, LAS, LAX,
RLA, RRA, SAX, SBX, SLO, SHA, SHS, SHX,
SHY, SRE, XAA
2021-10-22 14:39:48 +00:00
};
2021-10-21 17:24:53 +00:00
2021-10-22 14:39:48 +00:00
enum AddrMode
2021-10-21 17:24:53 +00:00
{
2021-10-22 14:39:48 +00:00
ACC, ABS, ABX, ABY, IMM, IMP, IND, INDX, INDY, REL, ZPG, ZPX, ZPY
};
2021-10-21 17:24:53 +00:00
struct Opcode
{
2021-10-22 14:39:48 +00:00
enum Operation op;
enum AddrMode addr;
2021-10-21 17:24:53 +00:00
Byte cycles;
2021-10-22 15:49:20 +00:00
Byte length;
2021-10-22 23:29:15 +00:00
Byte illegal;
2021-10-21 17:24:53 +00:00
const char str[4];
};
2021-10-29 20:17:01 +00:00
extern const struct Opcode OPCODE_TABLE[256];
2021-10-21 17:24:53 +00:00
2021-10-20 20:39:29 +00:00
struct CPU
{
Byte acc;
Byte x, y;
Byte sp;
union
{
struct
{
Byte carry : 1;
Byte zero : 1;
Byte id : 1;
Byte decimal : 1;
Byte unused : 2;
Byte overflow : 1;
Byte negative : 1;
};
Byte raw;
} status;
2021-10-22 22:47:33 +00:00
union
{
struct
{
Byte lo;
Byte hi;
};
Word word;
} pc;
2021-10-20 20:39:29 +00:00
2021-10-22 23:29:15 +00:00
char remainingCycles;
2021-10-29 20:33:34 +00:00
QWord totalCycles;
2021-10-22 14:39:48 +00:00
2021-10-21 17:24:53 +00:00
Byte fetchedVal;
Word fetchedAddress;
2021-10-22 14:39:48 +00:00
char fetchedRelAddress;
2021-10-24 14:52:15 +00:00
Byte irq;
Byte nmi;
2021-10-21 17:24:53 +00:00
const struct Opcode* currentOpcode;
2021-10-20 20:39:29 +00:00
struct Bus* bus;
};
struct CPU* createCPU(struct Bus* parent);
void destroyCPU(struct CPU* cpu);
2021-10-22 15:49:20 +00:00
int tickCPU(struct CPU* cpu);
2021-10-21 17:24:53 +00:00
void tickInstr(struct CPU* cpu);
void prepareFetch(struct CPU* cpu);
2021-10-21 17:24:53 +00:00
void fetch(struct CPU* cpu);
void execute(struct CPU* cpu);
2021-10-24 14:52:15 +00:00
void IRQ(struct CPU* cpu);
void NMI(struct CPU* cpu);
2021-10-29 20:17:01 +00:00
#endif // _CPU_H_