added cmake config

This commit is contained in:
Rose Apollo 2024-12-10 10:50:54 +00:00 committed by ROSE BARRATT
parent b5de33574d
commit b5ff47346c
5 changed files with 77 additions and 14 deletions

21
.gitignore vendored
View File

@ -51,4 +51,23 @@ Module.symvers
Mkfile.old
dkms.conf
bin
bin
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json
.vs/
.vscode/
out/
.gitconfig

View File

@ -1,8 +0,0 @@
{
"files.associations": {
"ram.h": "c",
"stdint.h": "c",
"carg-parse.h": "c",
"cpu_human.h": "c"
}
}

37
CMakeLists.txt Normal file
View File

@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 3.15)
project(r16)
set(CMAKE_C_STANDARD 11)
add_library(carg-parse
./lib/carg-parse/carg-parse.c
./lib/carg-parse/carg-parse.h
)
add_executable(r16a
./asm/main.c
./asm/assembler.c
./asm/assembler.h
./asm/asm_const.h
)
add_executable(r16e
./emu/main.c
./emu/cpu/instruction.c
./emu/cpu/instruction.h
./emu/cpu/ram.c
./emu/cpu/ram.h
./emu/cpu/register.c
./emu/cpu/register.h
./emu/cpu/stack.c
./emu/cpu/stack.h
./emu/cpu.c
./emu/cpu.h
./emu/cpu_const.h
./emu/cpu_human.h
)
target_link_libraries(r16a PRIVATE carg-parse)
target_link_libraries(r16e PRIVATE carg-parse)

View File

@ -90,17 +90,21 @@ AsmInstructionArray *InterpretAssembly(char *data)
AsmInstructionArray *asmIA = malloc(sizeof(AsmInstructionArray));
uint32_t cSize = 0, mSize = ARRAY_SNAP_SIZE;
asmIA->instruction = malloc(sizeof(AsmInstruction) * ARRAY_SNAP_SIZE);
int gfususc = 0;
while (true)
{
loopStart:
loopStart:
printf("asmiloop: %d\n", gfususc++);
if (cSize == mSize)
{
mSize += ARRAY_SNAP_SIZE;
asmIA->instruction = realloc(asmIA->instruction, mSize);
asmIA->instruction = realloc(asmIA->instruction, sizeof(AsmInstruction) * mSize);
}
AsmInstruction current = *(asmIA->instruction + (cSize * sizeof(AsmInstruction)));
AsmInstruction current = asmIA->instruction[cSize];
d = FindNextNonSpaceChar(d, false);
@ -203,7 +207,7 @@ uint16_t *BinaryInstructionToBin(BinaryInstruction instruction)
return bin;
}
int WhereIn2DCharArray(int x, int y, char array[x][y], char *val)
int WhereIn2DCharArray(int x, char **array, char *val)
{
for (int i = 0; i < x; i++)
{
@ -329,7 +333,6 @@ uint16_t *CompileAsembly(AsmInstructionArray *assembly, AsmLabelArray *labels)
BinaryInstruction binaryIns;
int instruction = WhereIn2DCharArray(LEN(CpuInstructionsHumanReadable),
LEN(CpuInstructionsHumanReadable[0]),
CpuInstructionsHumanReadable,
assembly->instruction[i].instruction);

View File

@ -1,13 +1,25 @@
#include "../lib/carg-parse/carg-parse.h"
#include "./asm_const.h"
#include "./assembler.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
const char demo[] =
"mov R0, 1\n\
mov ACU, 0\n\
loop: add ACU, R0\n\
out ACU\n\
jmp loop\n";
int main(int argc, char **argv)
{
carg_parse_data* args = carg_parse(argc, argv);
AsmInstructionArray* abin = InterpretAssembly(/*args->values[0]*/ demo);
AsmLabelArray* labels = GenerateLabels(abin);
uint16_t* bin = CompileAsembly(abin, labels);
carg_parse_free(args);
return 0;