53 lines
944 B
C
53 lines
944 B
C
|
#include "vcpu.h"
|
||
|
#include "mem.h"
|
||
|
#include "screen.h"
|
||
|
|
||
|
// 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;
|
||
|
|
||
|
// General purpose registers (8 bits each)
|
||
|
// Note last one often used as a flag register
|
||
|
unsigned char R[16];
|
||
|
|
||
|
// Delay timer (8 bits)
|
||
|
unsigned char DT;
|
||
|
|
||
|
// Sound timer (8 bits)
|
||
|
unsigned char ST;
|
||
|
|
||
|
// Current VCPU state
|
||
|
VCPU_State State;
|
||
|
|
||
|
void VCPUInit(){
|
||
|
PC=ADDR_ROM;
|
||
|
}
|
||
|
|
||
|
void VCPUFetch(){
|
||
|
MemRead((char *)&(State.opcode),2,PC);
|
||
|
PC+=2;
|
||
|
}
|
||
|
|
||
|
void VCPUDecode(){
|
||
|
char X=(State.opcode<<4) & 0xF0;
|
||
|
char Y=(State.opcode<<8) & 0xF0;
|
||
|
char N=(State.opcode<<12) & 0xF0;
|
||
|
char NN=(State.opcode<<8) & 0xFF;
|
||
|
short NNN=(State.opcode<<4) & 0xFFF0;
|
||
|
}
|
||
|
|
||
|
void VCPUExecute(){
|
||
|
switch(State.opcode){
|
||
|
case 0x00E0:
|
||
|
ScreenClear();
|
||
|
break
|
||
|
;;
|
||
|
|
||
|
}
|
||
|
}
|