even more

This commit is contained in:
Rose Apollo 2024-04-19 09:05:10 +00:00
parent a8abdb667a
commit da7317ced2
11 changed files with 151 additions and 13 deletions

2
.gitignore vendored
View File

@ -50,3 +50,5 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf
bin

View File

@ -38,17 +38,17 @@
| 0x5 | PC | Program Counter |
| 0x6 | SP | Stack Pointer |
| Area of RAM | reserved | usage |
|:-------------:|:--------:|-------------------|
| 00000 - 00064 | YES | system header |
| 00064 - 65263 | NO | executable |
| 65263 - 65519 | YES | interupt pointers |
| 65519 - 65535 | YES | stack |
| Area of RAM | reserved | Writable | usage |
|:-------------:|:--------:|:--------:|-------------------|
| 00000 - 00064 | YES | NO | system header |
| 00064 - 65023 | NO | YES | executable |
| 65023 - 65279 | YES | YES | interupt pointers |
| 65279 - 65535 | YES | YES | stack |
| BYTE 1 | | | BYTE 2 | BYTE 2 |
|------------|-------------|-------------|------------|------------|
| OPCODE | arg 1 info | arg 2 info | ARGUMENT 1 | ARGUMENT 2 |
| bit 0 - 12 | bit 12 - 14 | bit 14 - 16 | bit 0 - 16 | bit 0 - 16 |
| BYTE 1 | | | | BYTE 2 | BYTE 2 |
|--------|--------|------------|------------|------------|------------|
| OPCODE | UNUSED | ARG 1 INFO | ARG 2 INFO | ARGUMENT 1 | ARGUMENT 2 |
| 8 bits | 4 bits | 2 bits | 2 bits | 16 bits | 16 bits |
| State | Argument Interpretation |
|------:|---------------------------------------------|

2
build.sh Executable file
View File

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

28
emu/cpu/ram.c Normal file
View File

@ -0,0 +1,28 @@
#include "ram.h"
#include <stdlib.h>
r16_int* ram = NULL;
void InitRam()
{
ram = (r16_int*)malloc(sizeof(r16_int) * UINT16_MAX);
}
r16_int GetValue(r16_int address)
{
#ifdef RAM_DO_NULL_CHECK
if (ram == NULL) { InitRam(); }
#endif
return ram[address.u];
}
void SetValue(r16_int address, r16_int value)
{
#ifdef RAM_DO_NULL_CHECK
if (ram == NULL) { InitRam(); }
#endif
ram[address.u] = value;
}

18
emu/cpu/ram.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef EMU_CPU_RAM_H
#define EMU_CPU_RAM_H
#define RAM_DO_NULL_CHECK
#include <stdint.h>
typedef union
{
int16_t s;
uint16_t u;
} r16_int;
void InitRam();
void SetValue(r16_int address, r16_int value);
r16_int GetValue(r16_int address);
#endif

37
emu/cpu/register.c Normal file
View File

@ -0,0 +1,37 @@
#include "./register.h"
#include <stdlib.h>
r16_int r0, r1, r2, r3, acu, pc, sp;
r16_int *GetRegPoint(CpuRegisters reg)
{
switch (reg)
{
case R0:
return &r0;
case R1:
return &r1;
case R2:
return &r2;
case R3:
return &r3;
case ACU:
return &acu;
case PC:
return &pc;
case SP:
return &sp;
}
return NULL;
}
r16_int GetRegister(CpuRegisters reg)
{
return *(GetRegPoint(reg));
}
void SetRegister(CpuRegisters reg, r16_int value)
{
*(GetRegPoint(reg)) = value;
}

10
emu/cpu/register.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef EMU_CPU_REGISTER_H
#define EMU_CPU_REGISTER_H
#include "../cpu_const.h"
#include "./ram.h"
r16_int GetRegister(CpuRegisters reg);
void SetRegister(CpuRegisters reg, r16_int value);
#endif

13
emu/cpu/stack.c Normal file
View File

@ -0,0 +1,13 @@
#include "./stack.h"
r16_int pop()
{
#ifdef DO_STACK_CHECKS
if ()
#endif
}
void push(r16_int value)
{
}

12
emu/cpu/stack.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef EMU_CPU_STACK_H
#define EMU_CPU_STACK_H
#include "./ram.h"
#include "./register.h"
#define STACK_SIZE 256
#define STACK_LOCATION (UINT16_MAX - STACK_SIZE)
#define DO_STACK_CHECKS
#endif

View File

@ -1,6 +1,8 @@
#ifndef EMU_CPU_CONST_H
#define EMU_CPU_CONST_H
#include <stdint.h>
typedef enum
{
HLT = 0x00,
@ -44,12 +46,12 @@ typedef enum
typedef enum
{
value = 0x0,
register = 0x1,
ram = 0x2,
valueInRegister = 0x1,
valueInRam = 0x2,
pointerInRegister = 0x3
} ArgumentInfo;
#define INSTRUCTION_BIT_MASK 0b1111111111110000
#define INSTRUCTION_BIT_MASK 0b1111111100000000
#define INSTRUCTION_ARG_1_INFO_MASK 0b0000000000001100
#define INSTRUCTION_ARG_2_INFO_MASK 0b0000000000000011

14
emu/main.c Normal file
View File

@ -0,0 +1,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include "../lib/carg-parse/carg-parse.h"
#include "./cpu_const.h"
int main(int argc, char **argv)
{
carg_parse_data* args = carg_parse(argc, argv);
carg_parse_free(args);
}