added cmake config
This commit is contained in:
parent
b5de33574d
commit
b5ff47346c
21
.gitignore
vendored
21
.gitignore
vendored
@ -51,4 +51,23 @@ Module.symvers
|
|||||||
Mkfile.old
|
Mkfile.old
|
||||||
dkms.conf
|
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
|
8
.vscode/settings.json
vendored
8
.vscode/settings.json
vendored
@ -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
37
CMakeLists.txt
Normal 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)
|
@ -90,17 +90,21 @@ AsmInstructionArray *InterpretAssembly(char *data)
|
|||||||
AsmInstructionArray *asmIA = malloc(sizeof(AsmInstructionArray));
|
AsmInstructionArray *asmIA = malloc(sizeof(AsmInstructionArray));
|
||||||
uint32_t cSize = 0, mSize = ARRAY_SNAP_SIZE;
|
uint32_t cSize = 0, mSize = ARRAY_SNAP_SIZE;
|
||||||
asmIA->instruction = malloc(sizeof(AsmInstruction) * ARRAY_SNAP_SIZE);
|
asmIA->instruction = malloc(sizeof(AsmInstruction) * ARRAY_SNAP_SIZE);
|
||||||
|
|
||||||
|
int gfususc = 0;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
loopStart:
|
loopStart:
|
||||||
|
printf("asmiloop: %d\n", gfususc++);
|
||||||
|
|
||||||
if (cSize == mSize)
|
if (cSize == mSize)
|
||||||
{
|
{
|
||||||
mSize += ARRAY_SNAP_SIZE;
|
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);
|
d = FindNextNonSpaceChar(d, false);
|
||||||
|
|
||||||
@ -203,7 +207,7 @@ uint16_t *BinaryInstructionToBin(BinaryInstruction instruction)
|
|||||||
return bin;
|
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++)
|
for (int i = 0; i < x; i++)
|
||||||
{
|
{
|
||||||
@ -329,7 +333,6 @@ uint16_t *CompileAsembly(AsmInstructionArray *assembly, AsmLabelArray *labels)
|
|||||||
BinaryInstruction binaryIns;
|
BinaryInstruction binaryIns;
|
||||||
|
|
||||||
int instruction = WhereIn2DCharArray(LEN(CpuInstructionsHumanReadable),
|
int instruction = WhereIn2DCharArray(LEN(CpuInstructionsHumanReadable),
|
||||||
LEN(CpuInstructionsHumanReadable[0]),
|
|
||||||
CpuInstructionsHumanReadable,
|
CpuInstructionsHumanReadable,
|
||||||
assembly->instruction[i].instruction);
|
assembly->instruction[i].instruction);
|
||||||
|
|
||||||
|
12
asm/main.c
12
asm/main.c
@ -1,13 +1,25 @@
|
|||||||
#include "../lib/carg-parse/carg-parse.h"
|
#include "../lib/carg-parse/carg-parse.h"
|
||||||
#include "./asm_const.h"
|
#include "./asm_const.h"
|
||||||
|
#include "./assembler.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.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)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
carg_parse_data* args = carg_parse(argc, 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);
|
carg_parse_free(args);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user