began assembler

This commit is contained in:
Rose Apollo 2024-04-22 13:05:10 +00:00
parent b30a4b1832
commit 885a091400
8 changed files with 99 additions and 8 deletions

View File

@ -1,5 +1,7 @@
{ {
"files.associations": { "files.associations": {
"ram.h": "c" "ram.h": "c",
"stdint.h": "c",
"carg-parse.h": "c"
} }
} }

49
asm/asm_const.h Normal file
View File

@ -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 <stdbool.h>
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

14
asm/assembler.c Normal file
View File

@ -0,0 +1,14 @@
#include "./assembler.h"
#include "../emu/cpu_const.h"
#include "../emu/cpu_human.h"
#include "./asm_const.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
AsmInstructionArray InterpretAssembly(char *data)
{
char *d = data;
}

6
asm/assembler.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef ASM_ASSEMBLER_H
#define ASM_ASSEMBLER_H
#endif

16
asm/main.c Normal file
View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(int argc, char **argv)
{
carg_parse_data* args = carg_parse(argc, argv);
carg_parse_free(args);
return 0;
}

View File

@ -1,2 +1,5 @@
mkdir ./bin 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 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"

View File

@ -4,12 +4,7 @@
#define RAM_DO_NULL_CHECK #define RAM_DO_NULL_CHECK
#include <stdint.h> #include <stdint.h>
#include "../cpu_const.h"
typedef union
{
int16_t s;
uint16_t u;
} r16_int;
void InitRam(); void InitRam();
void SetValue(r16_int address, r16_int value); void SetValue(r16_int address, r16_int value);

View File

@ -51,6 +51,12 @@ typedef enum
pointerInRegister = 0x3 pointerInRegister = 0x3
} ArgumentInfo; } ArgumentInfo;
typedef union
{
int16_t s;
uint16_t u;
} r16_int;
#define INSTRUCTION_BIT_MASK 0b0000000011111111 #define INSTRUCTION_BIT_MASK 0b0000000011111111
#define INSTRUCTION_ARG_1_INFO_MASK 0b0011000000000000 #define INSTRUCTION_ARG_1_INFO_MASK 0b0011000000000000
#define INSTRUCTION_ARG_2_INFO_MASK 0b1100000000000000 #define INSTRUCTION_ARG_2_INFO_MASK 0b1100000000000000