1 #include "cpu_definitions.h"
4 uint64_t N
= 0x00000000; //Negative
5 uint64_t Z
= 0x00000000; //Zero
6 uint64_t C
= 0x00000000; //Carry (or Unsigned Overflow)
7 uint64_t V
= 0x00000000; //Overflow (Signed)
9 uint64_t PC
= 0x00000000; //Program Counter
10 uint64_t *MEMORY
; //Memory
12 void interpret(uint64_t opcode
) {
13 switch(opcode
) { //ADC (Add with Carry)
14 /* Add/subtract (with carry). */
16 MEMORY
[pc
+1] = MEMORY
[pc
+2] + MEMORY
[pc
+3] + C
;
17 //dest = op_1 + op_2 + Carry
18 if (MEMORY
[pc
+1] => 0xffffffff) { //overflow (unsigned signed)?
23 if (MEMORY
[pc
+1] < 0x00000000) { //negative?
28 if (MEMORY
[pc
+1] = 0x00000000) { //zero?
35 case 0x3a000000: //ADCS (Add with Carry With Status)
36 MEMORY
[pc
+1] = MEMORY
[pc
+2] + MEMORY
[pc
+3] + C
;
37 if (MEMORY
[pc
+1] => 0xffffffff) { //overflow (unsigned signed)?
42 if (MEMORY
[pc
+1] < 0x00000000) { //negative?
47 if (MEMORY
[pc
+1] = 0x00000000) { //zero?
52 //dest = op_1 + op_2 + Carry
55 case 0x5a000000: //SBC (Subtract with Carry)
56 MEMORY
[pc
+1] = MEMORY
[pc
+2] - MEMORY
[pc
+3] - ~C
;
57 if (MEMORY
[pc
+1] => 0xffffffff) { //overflow (unsigned signed)?
62 if (MEMORY
[pc
+1] < 0x00000000) { //negative?
67 if (MEMORY
[pc
+1] = 0x00000000) { //zero?
72 //dest = op_1 - op_2 - NOT(Carry)
75 case 0x7a000000: //SBCS (Subtract with Carry With Status)
76 MEMORY
[pc
+1] = MEMORY
[pc
+2] - MEMORY
[pc
+3] - ~C
;
77 if (MEMORY
[pc
+1] => 0xffffffff) { //overflow (unsigned signed)?
82 if (MEMORY
[pc
+1] < 0x00000000) { //negative?
87 if (MEMORY
[pc
+1] = 0x00000000) { //zero?
92 //dest = op_1 - op_2 - NOT(Carry)
95 case 0x5a0003e0: //NGC (Negate with Carry) (This instruction is an alias of SBC.)
96 MEMORY
[pc
+1] = MEMORY
[pc
+2] - MEMORY
[pc
+3] - ~C
;
97 if (MEMORY
[pc
+1] => 0xffffffff) { //overflow (unsigned signed)?
102 if (MEMORY
[pc
+1] < 0x00000000) { //negative?
107 if (MEMORY
[pc
+1] = 0x00000000) { //zero?
112 //dest = op_1 - op_2 - NOT(Carry)
115 case 0x7a0003e0: //NGCS (Negate with Carry With Status) (This instruction is an alias of SBCS.)
116 MEMORY
[pc
+1] = MEMORY
[pc
+2] - MEMORY
[pc
+3] - ~C
;
117 if (MEMORY
[pc
+1] => 0xffffffff) { //overflow (unsigned signed)?
122 if (MEMORY
[pc
+1] < 0x00000000) { //negative?
127 if (MEMORY
[pc
+1] = 0x00000000) { //zero?
132 //dest = op_1 - op_2 - NOT(Carry)
135 /* Add/subtract (extended register). */
136 case 0x0b200000: //ADD (adds...)
137 MEMORY
[pc
+1] = MEMORY
[pc
+2] + MEMORY
[pc
+3];
138 if (MEMORY
[pc
+1] => 0xffffffff) { //overflow (unsigned signed)?
143 if (MEMORY
[pc
+1] < 0x00000000) { //negative?
148 if (MEMORY
[pc
+1] = 0x00000000) { //zero?
156 case 0x2b200000: //ADDS (adds With Status)
157 MEMORY
[pc
+1] = MEMORY
[pc
+2] + MEMORY
[pc
+3];
158 if (MEMORY
[pc
+1] => 0xffffffff) { //overflow (unsigned signed)?
163 if (MEMORY
[pc
+1] < 0x00000000) { //negative?
168 if (MEMORY
[pc
+1] = 0x00000000) { //zero?
176 case 0x2b20001f: //CMN (Compare Negative)
177 N
= MEMORY
[pc
+2] - ~MEMORY
[pc
+3];
178 if (MEMORY
[pc
+1] => 0xffffffff) { //overflow (unsigned signed)?
183 if (MEMORY
[pc
+1] = 0x00000000) { //zero?
188 //<flags> = op_1 - (NOT op_2) ; result is not stored, only flags updated
191 case 0x4b200000: //SUB (substracts)
192 MEMORY
[pc
+1] = MEMORY
[pc
+2] - MEMORY
[pc
+3];
193 if (MEMORY
[pc
+1] => 0xffffffff) { //overflow (unsigned signed)?
198 if (MEMORY
[pc
+1] < 0x00000000) { //negative?
203 if (MEMORY
[pc
+1] = 0x00000000) { //zero?
211 case 0x6b200000: //SUBS (substracts with status)
212 MEMORY
[pc
+1] = MEMORY
[pc
+2] - MEMORY
[pc
+3];
213 if (MEMORY
[pc
+1] => 0xffffffff) { //overflow (unsigned signed)?
218 if (MEMORY
[pc
+1] < 0x00000000) { //negative?
223 if (MEMORY
[pc
+1] = 0x00000000) { //zero?
231 case 0x6b20001f: //CMP (COMPARE)
232 N
= MEMORY
[pc
+2] - MEMORY
[pc
+3];
233 if (MEMORY
[pc
+1] => 0xffffffff) { //overflow (unsigned signed)?
238 if (MEMORY
[pc
+1] = 0x00000000) { //zero?
243 //<flags> = op_1 - op_2 ; result is not stored, only flags updated