#include "cpu.h" #include void GetInstructionAndArgs(r16_int *instruct, r16_int *a1, r16_int *a2, ArgumentInfo *a1i, ArgumentInfo *a2i) { r16_int tmpInstruct, tmpPC; tmpPC = GetRegister(PC); tmpInstruct = GetValue(tmpPC); tmpPC.u++; *a1 = GetValue(tmpPC); tmpPC.u++; *a2 = GetValue(tmpPC); tmpPC.u++; SetRegister(PC, tmpPC); *instruct = (r16_int){ tmpInstruct.u & INSTRUCTION_BIT_MASK }; *a1i = (ArgumentInfo)((tmpInstruct.u & INSTRUCTION_ARG_1_INFO_MASK) >> 12); *a2i = (ArgumentInfo)((tmpInstruct.u & INSTRUCTION_ARG_2_INFO_MASK) >> 14); } void Run(r16_int entry) { r16_int instruction, arg1, arg2; ArgumentInfo arg1Info, arg2Info; SetRegister(PC, entry); while (true) { GetInstructionAndArgs(&instruction, &arg1, &arg2, &arg1Info, &arg2Info); ExecuteInstruction((CpuInstructions)instruction.u, arg1Info, arg2Info, arg1, arg2); } }