2023-08-26 19:04:02 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
class Cpu;
|
|
|
|
class Mem_device;
|
|
|
|
|
|
|
|
enum Flags {
|
|
|
|
F_ZERO = 0x8,
|
|
|
|
F_SUB = 0x4,
|
|
|
|
F_HALF = 0x2,
|
|
|
|
F_CARRY = 0x1,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Cpu_state {
|
|
|
|
// Registers
|
|
|
|
union {
|
|
|
|
u16 BC;
|
|
|
|
struct { u8 B; u8 C; };
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
u16 DE;
|
|
|
|
struct { u8 D; u8 E; };
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
u16 HL;
|
|
|
|
struct { u8 H; u8 L; };
|
|
|
|
};
|
|
|
|
|
|
|
|
u8 A;
|
|
|
|
u16 SP;
|
|
|
|
u16 PC;
|
|
|
|
|
|
|
|
bool zero;
|
|
|
|
bool subtract;
|
|
|
|
bool halfcarry;
|
|
|
|
bool carry;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Cpu {
|
|
|
|
private:
|
|
|
|
Cpu_state state;
|
|
|
|
Mem_device* bus;
|
|
|
|
|
|
|
|
typedef u8 opcode_t;
|
|
|
|
|
|
|
|
private:
|
2023-08-26 21:17:47 +02:00
|
|
|
u8 readPC8();
|
|
|
|
u16 readPC16();
|
2023-08-26 19:04:02 +02:00
|
|
|
|
2023-08-26 21:17:47 +02:00
|
|
|
void pushStack8(u8 data);
|
|
|
|
u8 popStack8();
|
2023-08-26 19:04:02 +02:00
|
|
|
|
2023-08-26 21:17:47 +02:00
|
|
|
void pushStack16(u16 data);
|
|
|
|
u16 popStack16();
|
2023-08-26 19:04:02 +02:00
|
|
|
public:
|
|
|
|
Cpu();
|
|
|
|
|
|
|
|
void step();
|
|
|
|
};
|