2023-12-25 07:24:17 +01:00
|
|
|
#pragma once
|
|
|
|
|
2023-12-26 09:06:40 +01:00
|
|
|
#define VCPU_FREQ 600
|
|
|
|
#define DTST_FREQ 60
|
|
|
|
#define SCREEN_FREQ 60
|
2023-12-25 09:25:14 +01:00
|
|
|
#define REG_FLAG 0xF
|
|
|
|
|
2023-12-25 07:24:17 +01:00
|
|
|
typedef struct VCPU_State {
|
2023-12-25 07:32:11 +01:00
|
|
|
// Program Counter (16 bits but only 12 bits used (4096 memory addresses))
|
|
|
|
unsigned short PC;
|
|
|
|
|
|
|
|
// Index register (16 bits but only 12 bits used (4096 memory addresses))
|
|
|
|
unsigned short I;
|
|
|
|
|
|
|
|
// Stack register (16 bits)
|
|
|
|
unsigned short S;
|
2023-12-25 10:07:12 +01:00
|
|
|
unsigned short stack[100]; // Emulated stack
|
2023-12-25 07:32:11 +01:00
|
|
|
|
|
|
|
// General purpose registers (8 bits each)
|
|
|
|
// Note last one often used as a flag register
|
|
|
|
unsigned char V[16];
|
|
|
|
|
|
|
|
// Delay timer (8 bits)
|
|
|
|
unsigned char DT;
|
|
|
|
|
|
|
|
// Sound timer (8 bits)
|
|
|
|
unsigned char ST;
|
|
|
|
|
|
|
|
// Intruction (opcode + decoded fields)
|
2023-12-25 09:11:45 +01:00
|
|
|
unsigned short opcode;
|
2023-12-25 15:03:22 +01:00
|
|
|
unsigned char X;
|
|
|
|
unsigned char Y;
|
|
|
|
unsigned char N;
|
|
|
|
unsigned char NN;
|
2023-12-25 09:11:45 +01:00
|
|
|
unsigned short NNN;
|
2023-12-26 09:06:40 +01:00
|
|
|
|
|
|
|
// Keypressed
|
2023-12-26 13:17:52 +01:00
|
|
|
int keypressed; // Not 0 if a key was pressed
|
|
|
|
unsigned char key;
|
2023-12-26 09:06:40 +01:00
|
|
|
|
|
|
|
// Count VCPU ticks
|
2023-12-26 13:17:52 +01:00
|
|
|
int dt_ticks;
|
|
|
|
int st_ticks;
|
2023-12-26 09:06:40 +01:00
|
|
|
int screen_ticks;
|
2023-12-25 07:24:17 +01:00
|
|
|
} VCPU_State;
|
|
|
|
|
|
|
|
void VCPUInit();
|
|
|
|
void VCPUFetch();
|
|
|
|
void VCPUDecode();
|
|
|
|
void VCPUExecute();
|
2023-12-26 09:06:40 +01:00
|
|
|
void VCPUTick();
|
2023-12-25 15:03:22 +01:00
|
|
|
void VCPUDoubleDabble(unsigned char x, unsigned char *u, unsigned char *t, unsigned char *h);
|
2023-12-25 09:11:45 +01:00
|
|
|
void VCPUDump();
|