cpu
This commit is contained in:
parent
e6e01700f7
commit
062b44b4f1
25
emu/cpu.c
25
emu/cpu.c
@ -1,14 +1,39 @@
|
|||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
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)
|
void Run(r16_int entry)
|
||||||
{
|
{
|
||||||
r16_int instruction, arg1, arg2;
|
r16_int instruction, arg1, arg2;
|
||||||
|
ArgumentInfo arg1Info, arg2Info;
|
||||||
|
|
||||||
SetRegister(PC, entry);
|
SetRegister(PC, entry);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
GetInstructionAndArgs(&instruction, &arg1, &arg2, &arg1Info, &arg2Info);
|
||||||
|
|
||||||
|
ExecuteInstruction((CpuInstructions)instruction.u, arg1Info, arg2Info, arg1, arg2);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,4 +6,6 @@
|
|||||||
#include "cpu/register.h"
|
#include "cpu/register.h"
|
||||||
#include "cpu/instruction.h"
|
#include "cpu/instruction.h"
|
||||||
|
|
||||||
|
void Run(r16_int entry);
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -51,8 +51,8 @@ typedef enum
|
|||||||
pointerInRegister = 0x3
|
pointerInRegister = 0x3
|
||||||
} ArgumentInfo;
|
} ArgumentInfo;
|
||||||
|
|
||||||
#define INSTRUCTION_BIT_MASK 0b1111111100000000
|
#define INSTRUCTION_BIT_MASK 0b0000000011111111
|
||||||
#define INSTRUCTION_ARG_1_INFO_MASK 0b0000000000001100
|
#define INSTRUCTION_ARG_1_INFO_MASK 0b0011000000000000
|
||||||
#define INSTRUCTION_ARG_2_INFO_MASK 0b0000000000000011
|
#define INSTRUCTION_ARG_2_INFO_MASK 0b1100000000000000
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -2,9 +2,9 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "../lib/carg-parse/carg-parse.h"
|
#include "../lib/carg-parse/carg-parse.h"
|
||||||
#include "./cpu_const.h"
|
#include "./cpu_const.h"
|
||||||
|
#include "./cpu.h"
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user