First commit
This commit is contained in:
16
.hgignore
Normal file
16
.hgignore
Normal file
@@ -0,0 +1,16 @@
|
||||
syntax: glob
|
||||
|
||||
aee
|
||||
recursos/*
|
||||
bin/*
|
||||
obj/*
|
||||
Debug/*
|
||||
Release/*
|
||||
data/*
|
||||
*.suo
|
||||
*.sdf
|
||||
*.opensdf
|
||||
*.user
|
||||
*.dll
|
||||
.DS_Store
|
||||
trick.ini
|
||||
8
main.cpp
Normal file
8
main.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
39
stack.cpp
Normal file
39
stack.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "stack.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
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);
|
||||
}
|
||||
15
stack.h
Normal file
15
stack.h
Normal file
@@ -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);
|
||||
22
vbvm.sln
Normal file
22
vbvm.sln
Normal file
@@ -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
|
||||
83
vbvm.vcxproj
Normal file
83
vbvm.vcxproj
Normal file
@@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{E0E409C8-8E79-4688-A9FB-29BD309B1B52}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>vbvm</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
17
vbvm.vcxproj.filters
Normal file
17
vbvm.vcxproj.filters
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
54
vm.cpp
Normal file
54
vm.cpp
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user