#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 V[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(){ State.X=(State.opcode<<4) & 0xF0; State.Y=(State.opcode<<8) & 0xF0; State.N=(State.opcode<<12) & 0xF0; State.NN=(State.opcode<<8) & 0xFF; State.NNN=(State.opcode<<4) & 0xFFF0; } void VCPUExecute(){ switch(State.opcode & 0xF){ case 0x0: ScreenClear(); break ;; case 0x1: PC=State.NNN; break ;; case 0x6: V[State.X]=State.NN; break ;; case 0x7: V[State.X]+=State.NN; break ;; case 0xA: I=State.NNN; break ;; } }