diff --git a/emu/cpu.c b/emu/cpu.c index c952391..cebdefb 100644 --- a/emu/cpu.c +++ b/emu/cpu.c @@ -1,14 +1,39 @@ #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); } } \ No newline at end of file diff --git a/emu/cpu.h b/emu/cpu.h index d1725bb..d70c532 100644 --- a/emu/cpu.h +++ b/emu/cpu.h @@ -6,4 +6,6 @@ #include "cpu/register.h" #include "cpu/instruction.h" +void Run(r16_int entry); + #endif \ No newline at end of file diff --git a/emu/cpu_const.h b/emu/cpu_const.h index b22a2e2..6975821 100644 --- a/emu/cpu_const.h +++ b/emu/cpu_const.h @@ -51,8 +51,8 @@ typedef enum pointerInRegister = 0x3 } ArgumentInfo; -#define INSTRUCTION_BIT_MASK 0b1111111100000000 -#define INSTRUCTION_ARG_1_INFO_MASK 0b0000000000001100 -#define INSTRUCTION_ARG_2_INFO_MASK 0b0000000000000011 +#define INSTRUCTION_BIT_MASK 0b0000000011111111 +#define INSTRUCTION_ARG_1_INFO_MASK 0b0011000000000000 +#define INSTRUCTION_ARG_2_INFO_MASK 0b1100000000000000 #endif \ No newline at end of file diff --git a/emu/main.c b/emu/main.c index e0162f5..c05f1ed 100644 --- a/emu/main.c +++ b/emu/main.c @@ -2,9 +2,9 @@ #include #include #include - #include "../lib/carg-parse/carg-parse.h" #include "./cpu_const.h" +#include "./cpu.h" int main(int argc, char **argv) {