summaryrefslogtreecommitdiff
path: root/src/vcpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vcpu.c')
-rw-r--r--src/vcpu.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/vcpu.c b/src/vcpu.c
new file mode 100644
index 0000000..e35d07e
--- /dev/null
+++ b/src/vcpu.c
@@ -0,0 +1,52 @@
+#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
+ ;;
+
+ }
+}