commit b49c1e543fc95566b46e83740805849348115df9 Author: Raimon Zamora Date: Tue Jan 24 13:17:59 2017 +0100 First commit diff --git a/.hgignore b/.hgignore new file mode 100644 index 0000000..1de44aa --- /dev/null +++ b/.hgignore @@ -0,0 +1,16 @@ +syntax: glob + +aee +recursos/* +bin/* +obj/* +Debug/* +Release/* +data/* +*.suo +*.sdf +*.opensdf +*.user +*.dll +.DS_Store +trick.ini \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..7386918 --- /dev/null +++ b/main.cpp @@ -0,0 +1,8 @@ +#include +#include + +int main(int argc, char** argv) { + + + return 0; +} \ No newline at end of file diff --git a/stack.cpp b/stack.cpp new file mode 100644 index 0000000..75104ea --- /dev/null +++ b/stack.cpp @@ -0,0 +1,39 @@ +#include "stack.h" +#include + +t_stack stack_new(const int size) { + t_stack stack; + stack.max = size; + stack.top = -1; + stack.data = (unsigned char*)malloc(size); + return stack; +} + +const bool stack_isempty(t_stack& stack) { + return stack.top == -1; +} + +const bool stack_isfull(t_stack& stack) { + return stack.top == stack.max; +} + +void stack_push(t_stack& stack, const char value) { + if (!stack_isfull(stack)) { + stack.data[++stack.top] = value; + } +} + +const char stack_pop(t_stack& stack) { + if (!stack_isempty(stack)) { + return stack.data[stack.top--]; + } + +} + +const char stack_peek(t_stack& stack) { + return stack.data[stack.top]; +} + +void stack_delete(t_stack& stack) { + free(stack.data); +} diff --git a/stack.h b/stack.h new file mode 100644 index 0000000..65b5500 --- /dev/null +++ b/stack.h @@ -0,0 +1,15 @@ +#pragma once + +struct t_stack { + unsigned char* data{ nullptr }; + int top{ 0 }; + int max{ 0 }; +}; + +t_stack stack_new(const int size); +const bool stack_isempty(t_stack& stack); +const bool stack_isfull(t_stack& stack); +void stack_push(t_stack& stack, const char value); +const char stack_pop(t_stack& stack); +const char stack_peek(t_stack& stack); +void stack_delete(t_stack& stack); diff --git a/vbvm.sln b/vbvm.sln new file mode 100644 index 0000000..9ddaf96 --- /dev/null +++ b/vbvm.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vbvm", "vbvm.vcxproj", "{E0E409C8-8E79-4688-A9FB-29BD309B1B52}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E0E409C8-8E79-4688-A9FB-29BD309B1B52}.Debug|Win32.ActiveCfg = Debug|Win32 + {E0E409C8-8E79-4688-A9FB-29BD309B1B52}.Debug|Win32.Build.0 = Debug|Win32 + {E0E409C8-8E79-4688-A9FB-29BD309B1B52}.Release|Win32.ActiveCfg = Release|Win32 + {E0E409C8-8E79-4688-A9FB-29BD309B1B52}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/vbvm.vcxproj b/vbvm.vcxproj new file mode 100644 index 0000000..392a2e4 --- /dev/null +++ b/vbvm.vcxproj @@ -0,0 +1,83 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {E0E409C8-8E79-4688-A9FB-29BD309B1B52} + Win32Proj + vbvm + + + + Application + true + v120 + Unicode + + + Application + false + v120 + true + Unicode + + + + + + + + + + + + + true + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + + + + \ No newline at end of file diff --git a/vbvm.vcxproj.filters b/vbvm.vcxproj.filters new file mode 100644 index 0000000..f81daba --- /dev/null +++ b/vbvm.vcxproj.filters @@ -0,0 +1,17 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + \ No newline at end of file diff --git a/vm.cpp b/vm.cpp new file mode 100644 index 0000000..5bb5d7e --- /dev/null +++ b/vm.cpp @@ -0,0 +1,54 @@ +#include "vm.h" + +enum OPS { + OP_NOP = 0, + OP_PUSH, + OP_POP, + OP_DUP, + + OP_LOAD, + OP_STORE, + + OP_JMP, + OP_JNT, + OP_JTR, + OP_JSR, + OP_RET, + OP_CALL, + + OP_ADD, + OP_SUB, + OP_MUL, + OP_DIV, + OP_MOD, + OP_AND, + OP_OR, + OP_NOT, + OP_NEG, + OP_INC, + + OP_EQ, + OP_NEQ, + OP_LT, + OP_GT +}; + +typedef void(*t_extcall)(t_stack&); +t_extcall external_calls[100]; +int numcallbacks = 0; + +const unsigned char* vm_program = nullptr; +int vm_pc = 0; + +void vm_init(const unsigned char* program) { + vm_program = program; + vm_pc = 0; +} + +void vm_step() { + +} + +void vm_register_call(void(*callback)(t_stack&)) { + external_calls[numcallbacks++] = callback; +} diff --git a/vm.h b/vm.h new file mode 100644 index 0000000..adc7ff6 --- /dev/null +++ b/vm.h @@ -0,0 +1,6 @@ +#pragma once +#include "stack.h" + +void vm_init(const unsigned char* program); +void vm_step(); +void vm_register_call(void(*callback)(t_stack&));