diff --git b/.gitignore a/.gitignore new file mode 100644 index 0000000..1cc4572 --- /dev/null +++ a/.gitignore @@ -0,0 +1 @@ +.idea/workspace.xml diff --git b/.idea/misc.xml a/.idea/misc.xml new file mode 100644 index 0000000..3eb495b --- /dev/null +++ a/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git b/.idea/modules.xml a/.idea/modules.xml new file mode 100644 index 0000000..f1d385a --- /dev/null +++ a/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git b/.idea/synacorvm.iml a/.idea/synacorvm.iml new file mode 100644 index 0000000..cda13ed --- /dev/null +++ a/.idea/synacorvm.iml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git b/CMakeLists.txt a/CMakeLists.txt new file mode 100644 index 0000000..93f9a87 --- /dev/null +++ a/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.5) +project(synacorvm) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + +set(SOURCE_FILES main.c cpu.c cpu.h binary_decoder.c binary_decoder.h registers.h mem.h stack.c stack.h) +add_executable(synacorvm ${SOURCE_FILES}) \ No newline at end of file diff --git b/binary_decoder.c a/binary_decoder.c new file mode 100644 index 0000000..30c3b89 --- /dev/null +++ a/binary_decoder.c @@ -0,0 +1,5 @@ +// +// Created by imanol on 12/25/16. +// + +#include "binary_decoder.h" diff --git b/binary_decoder.h a/binary_decoder.h new file mode 100644 index 0000000..cd04ac3 --- /dev/null +++ a/binary_decoder.h @@ -0,0 +1,8 @@ +// +// Created by imanol on 12/25/16. +// + +#ifndef SYNACORVM_BINARY_DECODER_H +#define SYNACORVM_BINARY_DECODER_H + +#endif //SYNACORVM_BINARY_DECODER_H diff --git b/cpu.c a/cpu.c new file mode 100644 index 0000000..25f79ab --- /dev/null +++ a/cpu.c @@ -0,0 +1,16 @@ +// +// Created by imanol on 12/25/16. +// + +#include "cpu.h" + +void nop() +{ + return; +} + +void out(unsigned char a) +{ + printf("%c",a); +} + diff --git b/cpu.h a/cpu.h new file mode 100644 index 0000000..a14d8a1 --- /dev/null +++ a/cpu.h @@ -0,0 +1,10 @@ +// +// Created by imanol on 12/25/16. +// + +#ifndef SYNACORVM_CPU_H +#define SYNACORVM_CPU_H + +#include + +#endif //SYNACORVM_CPU_H diff --git b/main.c a/main.c new file mode 100644 index 0000000..7a69bbb --- /dev/null +++ a/main.c @@ -0,0 +1,6 @@ +#include + +int main(int argc, char** argv) +{ + return 0; +} \ No newline at end of file diff --git b/mem.h a/mem.h new file mode 100644 index 0000000..562584a --- /dev/null +++ a/mem.h @@ -0,0 +1,10 @@ +// +// Created by imanol on 12/25/16. +// + +#ifndef SYNACORVM_MEM_H +#define SYNACORVM_MEM_H + +short mem[32768]; //64KiB RAM + +#endif //SYNACORVM_MEM_H diff --git b/registers.h a/registers.h new file mode 100644 index 0000000..255d65f --- /dev/null +++ a/registers.h @@ -0,0 +1,19 @@ +// +// Created by imanol on 12/25/16. +// + +#ifndef SYNACORVM_REGISTERS_H +#define SYNACORVM_REGISTERS_H + +short r0 = 0; +short r1 = 0; +short r2 = 0; +short r3 = 0; +short r4 = 0; +short r5 = 0; +short r6 = 0; +short r7 = 0; + +short pc = 0; + +#endif //SYNACORVM_REGISTERS_H diff --git b/stack.c a/stack.c new file mode 100644 index 0000000..50a4cae --- /dev/null +++ a/stack.c @@ -0,0 +1,47 @@ +// +// Created by imanol on 12/25/16. +// + +#include +#include "stack.h" + +#define EXTEND_SIZE 10 + +uint32_t stack_size = EXTEND_SIZE; +uint32_t stack_pos = 0; +short *stack; + +void initialize_stack() +{ + stack = calloc(EXTEND_SIZE,sizeof(short)); +} + +void extend_stack() +{ + stack_size += EXTEND_SIZE; + realloc(stack,stack_size*sizeof(short)); +} + +void shrink_stack() +{ + stack_size -= EXTEND_SIZE; + realloc(stack,stack_size*sizeof(short)); +} + +void push(short value) +{ + stack[stack_pos++] = value; + if(stack_pos == stack_size-1) + { + extend_stack(); + } +} +short pop() +{ + short value = stack[stack_pos--]; + if(stack_size - stack_pos == 2*EXTEND_SIZE) + { + shrink_stack(); + } + return value; +} \ No newline at end of file diff --git b/stack.h a/stack.h new file mode 100644 index 0000000..0261eb7 --- /dev/null +++ a/stack.h @@ -0,0 +1,14 @@ +// +// Created by imanol on 12/25/16. +// + +#ifndef SYNACORVM_STACK_H +#define SYNACORVM_STACK_H + +#include + +void initialize_stack(); +void push(short value); +short pop(); + +#endif //SYNACORVM_STACK_H