began implementing cpu proper

This commit is contained in:
Rose Apollo 2024-04-19 10:08:32 +00:00
parent da7317ced2
commit 764f2406dd
5 changed files with 75 additions and 4 deletions

View File

@ -1,2 +1,2 @@
mkdir ./bin
clang -o ./bin/r16e ./emu/main.c ./emu/cpu/ram.c ./lib/carg-parse/carg-parse.c
clang -o ./bin/r16e ./emu/main.c ./emu/cpu/ram.c ./emu/cpu/register.c ./emu/cpu/stack.c ./lib/carg-parse/carg-parse.c

41
emu/cpu/instruction.c Normal file
View File

@ -0,0 +1,41 @@
#include "./instruction.h"
r16_int GetArgVal(ArgumentInfo argInfo, r16_int arg)
{
}
void ExecuteInstruction(CpuInstructions instruction, ArgumentInfo arg1Info,
ArgumentInfo arg2Info, r16_int arg1, r16_int arg2)
{
switch (instruction)
{
case HLT:
printf("program halted\n");
exit(0);
case ADD:
case SUB:
case MUL:
case DIV:
case LBS:
case RBS:
case BAN:
case BOR:
case BXO:
case BNO:
case PUS:
case POP:
case JMP:
case JEQ:
case JNZ:
case CAL:
case RET:
case REG:
case INT:
case INP:
case OUT:
case DIN:
case DOT:
case MOV:
}
}

9
emu/cpu/instruction.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef EMU_CPU_INSTRUCTION_H
#define EMU_CPU_INSTRUCTION_H
#include "../cpu_const.h"
#include "./ram.h"
#include "./register.h"
#include "./stack.h"
#endif

View File

@ -1,13 +1,31 @@
#include "./stack.h"
#include <stdlib.h>
#include <stdio.h>
r16_int pop()
r16_int StackPop()
{
#ifdef DO_STACK_CHECKS
if ()
#endif
}
void push(r16_int value)
if (GetRegister(SP).u == 0)
{
fprintf(stderr, "STACK UNDERFLOW\n");
exit(-1);
}
#endif
SetRegister(SP, (r16_int){ GetRegister(SP).u - 1 });
return GetValue((r16_int){ GetRegister(SP).u + STACK_LOCATION });
}
void StackPush(r16_int value)
{
#ifdef DO_STACK_CHECKS
if (GetRegister(SP).u >= STACK_SIZE)
{
fprintf(stderr, "STACK OVERFLOW\n");
exit(-1);
}
#endif
SetValue((r16_int){ GetRegister(SP).u + STACK_LOCATION }, value);
SetRegister(SP, (r16_int){ GetRegister(SP).u + 1 });
}

View File

@ -9,4 +9,7 @@
#define DO_STACK_CHECKS
r16_int StackPop();
void StackPush(r16_int value);
#endif