diff --git a/.gitignore b/.gitignore index dfb8efe..17b136f 100644 --- a/.gitignore +++ b/.gitignore @@ -51,4 +51,23 @@ Module.symvers Mkfile.old dkms.conf -bin \ No newline at end of file +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 \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 0bc5109..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "files.associations": { - "ram.h": "c", - "stdint.h": "c", - "carg-parse.h": "c", - "cpu_human.h": "c" - } -} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..25470fd --- /dev/null +++ b/CMakeLists.txt @@ -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) \ No newline at end of file diff --git a/asm/assembler.c b/asm/assembler.c index 02fb700..97d7eba 100644 --- a/asm/assembler.c +++ b/asm/assembler.c @@ -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); diff --git a/asm/main.c b/asm/main.c index 1fee886..513b2b3 100644 --- a/asm/main.c +++ b/asm/main.c @@ -1,13 +1,25 @@ #include "../lib/carg-parse/carg-parse.h" #include "./asm_const.h" +#include "./assembler.h" #include #include #include +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;