diff --git a/.vscode/settings.json b/.vscode/settings.json index 122b2db..d48e3bc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,7 @@ { "files.associations": { - "ram.h": "c" + "ram.h": "c", + "stdint.h": "c", + "carg-parse.h": "c" } } \ No newline at end of file diff --git a/asm/asm_const.h b/asm/asm_const.h new file mode 100644 index 0000000..7033d6b --- /dev/null +++ b/asm/asm_const.h @@ -0,0 +1,49 @@ +#ifndef ASM_ASM_CONST_H +#define ASM_ASM_CONST_H + +#include "../emu/cpu_const.h" +#include "../emu/cpu_human.h" +#include + +typedef struct +{ + char label[64]; + char instruction[4]; + char arg1[64]; + char arg2[64]; +} AsmInstruction; + +typedef struct +{ + uint16_t length; + AsmInstruction *instruction; +} AsmInstructionArray; + +typedef struct +{ + CpuInstructions instruction; + ArgumentInfo arg1Info; + ArgumentInfo arg2Info; + uint16_t arg1; + uint16_t arg2; +} BinaryInstruction; + +typedef struct +{ + uint16_t length; + BinaryInstruction *instructions; +} BinaryInstructionArray; + +typedef struct +{ + char label[64]; + uint16_t location; +} AsmLabel; + +typedef struct +{ + uint16_t length; + AsmLabel *labels; +} AsmLabelArray; + +#endif \ No newline at end of file diff --git a/asm/assembler.c b/asm/assembler.c new file mode 100644 index 0000000..d4a0b4b --- /dev/null +++ b/asm/assembler.c @@ -0,0 +1,14 @@ +#include "./assembler.h" +#include "../emu/cpu_const.h" +#include "../emu/cpu_human.h" +#include "./asm_const.h" +#include +#include +#include + +AsmInstructionArray InterpretAssembly(char *data) +{ + char *d = data; + + +} \ No newline at end of file diff --git a/asm/assembler.h b/asm/assembler.h new file mode 100644 index 0000000..76dee9a --- /dev/null +++ b/asm/assembler.h @@ -0,0 +1,6 @@ +#ifndef ASM_ASSEMBLER_H +#define ASM_ASSEMBLER_H + + + +#endif \ No newline at end of file diff --git a/asm/main.c b/asm/main.c new file mode 100644 index 0000000..cab41a5 --- /dev/null +++ b/asm/main.c @@ -0,0 +1,16 @@ +#include "../emu/cpu_const.h" +#include "../emu/cpu_human.h" +#include "../lib/carg-parse/carg-parse.h" +#include "./asm_const.h" +#include +#include +#include + +int main(int argc, char **argv) +{ + carg_parse_data* args = carg_parse(argc, argv); + + carg_parse_free(args); + + return 0; +} \ No newline at end of file diff --git a/build.sh b/build.sh index 9b7b068..e9566fd 100755 --- a/build.sh +++ b/build.sh @@ -1,2 +1,5 @@ mkdir ./bin -clang -o ./bin/r16e ./emu/main.c ./emu/cpu/instruction.c ./emu/cpu/ram.c ./emu/cpu/register.c ./emu/cpu/stack.c ./lib/carg-parse/carg-parse.c \ No newline at end of file +clang -O2 -o ./bin/r16emu ./emu/main.c ./emu/cpu/instruction.c ./emu/cpu/ram.c ./emu/cpu/register.c ./emu/cpu/stack.c ./lib/carg-parse/carg-parse.c +echo "built emulator" +clang -O2 -o ./bin/r16asm ./asm/main.c ./lib/carg-parse/carg-parse.c +echo "built assemblor" \ No newline at end of file diff --git a/emu/cpu/ram.h b/emu/cpu/ram.h index 21d23fb..5868906 100644 --- a/emu/cpu/ram.h +++ b/emu/cpu/ram.h @@ -4,12 +4,7 @@ #define RAM_DO_NULL_CHECK #include - -typedef union -{ - int16_t s; - uint16_t u; -} r16_int; +#include "../cpu_const.h" void InitRam(); void SetValue(r16_int address, r16_int value); diff --git a/emu/cpu_const.h b/emu/cpu_const.h index 95d4923..2f5e1be 100644 --- a/emu/cpu_const.h +++ b/emu/cpu_const.h @@ -51,6 +51,12 @@ typedef enum pointerInRegister = 0x3 } ArgumentInfo; +typedef union +{ + int16_t s; + uint16_t u; +} r16_int; + #define INSTRUCTION_BIT_MASK 0b0000000011111111 #define INSTRUCTION_ARG_1_INFO_MASK 0b0011000000000000 #define INSTRUCTION_ARG_2_INFO_MASK 0b1100000000000000