Initial commit

This commit is contained in:
Safariminer 2025-12-28 13:56:24 -05:00
commit b93c498d8c
23 changed files with 643 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
deps
x64
*/x64
.vs
*.ipch

31
biosandbox.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36717.8 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "biosandbox", "biosandbox\biosandbox.vcxproj", "{A7BCCB8D-F194-4005-830C-9A23D4D9B442}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A7BCCB8D-F194-4005-830C-9A23D4D9B442}.Debug|x64.ActiveCfg = Debug|x64
{A7BCCB8D-F194-4005-830C-9A23D4D9B442}.Debug|x64.Build.0 = Debug|x64
{A7BCCB8D-F194-4005-830C-9A23D4D9B442}.Debug|x86.ActiveCfg = Debug|Win32
{A7BCCB8D-F194-4005-830C-9A23D4D9B442}.Debug|x86.Build.0 = Debug|Win32
{A7BCCB8D-F194-4005-830C-9A23D4D9B442}.Release|x64.ActiveCfg = Release|x64
{A7BCCB8D-F194-4005-830C-9A23D4D9B442}.Release|x64.Build.0 = Release|x64
{A7BCCB8D-F194-4005-830C-9A23D4D9B442}.Release|x86.ActiveCfg = Release|Win32
{A7BCCB8D-F194-4005-830C-9A23D4D9B442}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {83F47753-8975-4B19-BD85-FDE054F2D4B4}
EndGlobalSection
EndGlobal

43
biosandbox/BinFile.cpp Normal file
View File

@ -0,0 +1,43 @@
#include "BinFile.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
bio::BinFile::BinFile()
{
}
bio::BinFile::BinFile(std::string path)
{
LoadFile(path);
}
void bio::BinFile::LoadFile(std::string path)
{
std::ifstream fileHandle(path, std::ios::binary);
std::stringstream fileContentHandle;
fileContentHandle << fileHandle.rdbuf();
std::string file = fileContentHandle.str();
app.bufferLength = file.size();
app.buffer = (unsigned char*) malloc(app.bufferLength);
for (int i = 0; i < app.bufferLength; i++) {
app.buffer[i] = 0;
}
memcpy(app.buffer, file.data(), app.bufferLength);
bio::emu::symbol sym;
sym.offset = 0;
app.symbols.push_back(sym);
}
bio::BinFile::~BinFile()
{
free((void*)app.buffer);
app.symbols.clear();
}

26
biosandbox/BinFile.h Normal file
View File

@ -0,0 +1,26 @@
#pragma once
#include "bsuml.h"
#include "Emulation.h"
#include <iostream>
namespace bio {
// the simplest executable, no symbols, no nothing.
class BinFile {
bio::emu::application app;
public:
BinFile();
BinFile(std::string path);
void LoadFile(std::string path);
bio::emu::application* getApp() { return &app; }
~BinFile();
};
}

1
biosandbox/Emulation.cpp Normal file
View File

@ -0,0 +1 @@
#include "Emulation.h"

79
biosandbox/Emulation.h Normal file
View File

@ -0,0 +1,79 @@
#pragma once
#include <vector>
#include "bsuml.h"
#include <stdexcept>
#include <format>
namespace bio {
namespace emu {
using instruction_set = std::vector<native_callable<int, int, unsigned char*, bool*>>;
memory_dependent using mem_buffer = unsigned char[memsize];
struct symbol {
unsigned offset;
};
struct application {
std::vector<symbol> symbols;
// contents
unsigned bufferLength;
unsigned char* buffer;
};
memory_dependent class emulator_base {
public:
instruction_set isa;
mem_buffer<memsize> memory;
std::vector<symbol> symbols;
virtual void load_app(application& app) = 0;
virtual void run_symbol(int symbol) = 0;
};
memory_dependent class linear_emulator_base : public memory_passdown(emulator_base) {
public:
int instructionPointer;
void run_symbol(int symbol) {
// check symbol ID is within symbol count
if (symbol > this->symbols.size() && symbol != -1)
throw std::out_of_range(
std::format("Symbol is outside of the symbol range ({} > {}, described as a maximum of {})",
symbol,
this->symbols.size(),
this->symbols.size() - 1
)
);
// check if symbol ID is erroneous
if (symbol < -1)
throw std::out_of_range(
std::format("Symbol ID for entry at start is explicitly -1 (received {} instead)",
symbol
)
);
// apply instruction pointer
if (symbol >= 0) instructionPointer = this->symbols[symbol].offset;
else instructionPointer = 0;
// execute
bool returned = false;
until(returned || instructionPointer >= memsize) {
this->instructionPointer +=
this->isa[this->memory[instructionPointer]](instructionPointer, this->memory, &returned);
if (instructionPointer < 0 || instructionPointer > memsize) {
throw std::out_of_range("Symbol causes instruction pointer to err out of memory");
}
}
}
};
}
}

16
biosandbox/Intel.cpp Normal file
View File

@ -0,0 +1,16 @@
#include "bsuml.h"
#include "Emulation.h"
#include "Intel.h"
#include <print>
#include <stdexcept>
isa_instruction(bio::Intel::ISAs::iAPX86::invalid) {
std::println("Invalid opcode used - {} at {}", memory[position], position);
return 1;
}
isa_instruction(bio::Intel::ISAs::iAPX86::nop) {
return 1;
}

45
biosandbox/Intel.h Normal file
View File

@ -0,0 +1,45 @@
#pragma once
#include "bsuml.h"
#include "Emulation.h"
namespace bio {
// emulation of Intel(-related) architectures
namespace Intel {
namespace ISAs {
namespace iAPX86 {
isa_instruction(invalid);
isa_instruction(nop);
}
}
// 8086 emulation
memory_dependent class iAPX86 : public memory_passdown(::bio::emu::linear_emulator_base){
public:
iAPX86() {
times(256) {
this->isa.push_back(ISAs::iAPX86::invalid);
}
this->isa[0x90] = ISAs::iAPX86::nop;
times(sizeof(this->memory)) {
this->memory[___i] = '\0';
}
}
void load_app(bio::emu::application& app) {
this->symbols = app.symbols;
memcpy(this->memory, app.buffer, app.bufferLength);
}
~iAPX86(){}
};
}
}

31
biosandbox/Network.cpp Normal file
View File

@ -0,0 +1,31 @@
#include "Network.h"
#include <dyad.h>
bool dyadUp = false;
ptr<dyad_Stream> stream;
bio::Server::Server()
{
}
bio::Server::Server(int port)
{
if (!dyadUp) {
dyad_init();
dyadUp = true;
}
stream = dyad_newStream();
}
void bio::Server::update()
{
}
bio::Server::~Server()
{
}

31
biosandbox/Network.h Normal file
View File

@ -0,0 +1,31 @@
#pragma once
#include "Object.h"
#ifndef socket_app_update
#define socket_app_update update()
#endif
namespace bio {
class network_object : public object {
};
class socket_app {
public:
virtual void socket_app_update = 0;
};
class Server : public socket_app {
bool ready = false;
public:
Server();
Server(int port);
void socket_app_update;
~Server();
};
}

28
biosandbox/Object.h Normal file
View File

@ -0,0 +1,28 @@
#pragma once
#include <variant>
#include <raymath.h>
#include "bsuml.h"
#define native_game_callback native_callable<void, ptr<::bio::object>>
namespace bio {
class object {
public:
bool native;
Vector3 position;
using callback =
std::variant<
native_game_callback
>;
callback start;
callback update;
callback stop;
};
}

27
biosandbox/Playables.h Normal file
View File

@ -0,0 +1,27 @@
#pragma once
#include <concepts>
#include "Object.h"
namespace bio {
// base class for concepts
class _Playable : public object{
public:
};
template<typename T>
concept playable = std::is_base_of<_Playable, T>::value;
class Guardian : public _Playable {
public:
Guardian();
~Guardian();
};
class Keymaker : public _Playable {
Keymaker();
~Keymaker();
};
}

View File

@ -0,0 +1,155 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" 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>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{a7bccb8d-f194-4005-830c-9a23d4d9b442}</ProjectGuid>
<RootNamespace>biosandbox</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v145</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v145</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v145</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v145</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</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>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<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|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
<LanguageStandard_C>stdclatest</LanguageStandard_C>
<AdditionalIncludeDirectories>$(SOLUTIONDIR)deps/include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SOLUTIONDIR)deps/lib</AdditionalLibraryDirectories>
<AdditionalDependencies>ws2_32.lib;winmm.lib;raylibdll.lib;raylib.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
<LanguageStandard_C>stdclatest</LanguageStandard_C>
<AdditionalIncludeDirectories>$(SOLUTIONDIR)deps/include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SOLUTIONDIR)deps/lib</AdditionalLibraryDirectories>
<AdditionalDependencies>ws2_32.lib;winmm.lib;raylibdll.lib;raylib.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\deps\include\dyad.c" />
<ClCompile Include="BinFile.cpp" />
<ClCompile Include="Emulation.cpp" />
<ClCompile Include="Intel.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="Network.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="BinFile.h" />
<ClInclude Include="bsuml.h" />
<ClInclude Include="Emulation.h" />
<ClInclude Include="Intel.h" />
<ClInclude Include="Network.h" />
<ClInclude Include="Object.h" />
<ClInclude Include="Playables.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,63 @@
<?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;c++;cppm;ixx;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;h++;hm;inl;inc;ipp;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>
<Filter Include="ext">
<UniqueIdentifier>{5b851266-c200-4d2b-8749-619796a9be7a}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\deps\include\dyad.c">
<Filter>ext</Filter>
</ClCompile>
<ClCompile Include="Network.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Emulation.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Intel.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="BinFile.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="bsuml.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Playables.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Object.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Network.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Intel.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Emulation.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="BinFile.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>$(SOLUTIONDIR)gameenv</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerWorkingDirectory>$(SOLUTIONDIR)gameenv</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

25
biosandbox/bsuml.h Normal file
View File

@ -0,0 +1,25 @@
// bioSandbox Usings and Macro Library (bsuml.h)
#pragma once
#ifndef BSUML_H
#define BSUML_H
// redefining syntax
#define entry int main(int argc, char** argv)
#define until(x) while(!(x))
#define times(x) for(unsigned ___i = 0; ___i < x; ___i++)
template<typename T>
using ptr = T*; // a more C++ way of writing raw pointers
template <typename T, typename ... args>
using native_callable = T(*)(args...);
// emulation-related definitions
#define isa_instruction(x) int x(int position, unsigned char* memory, bool* emu_return)
#define memory_dependent template<int memsize>
#define memory_passdown(x) x<memsize>
#endif

11
biosandbox/main.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "bsuml.h"
#include "Intel.h"
#include "BinFile.h"
entry{
ptr<bio::Intel::iAPX86<1024>> i8086 = new bio::Intel::iAPX86<1024>;
ptr<bio::BinFile> bin = new bio::BinFile("code/test");
i8086->load_app(*bin->getApp());
i8086->run_symbol(-1);
}

BIN
gameenv/code/test Normal file

Binary file not shown.

7
gameenv/code/test.asm Normal file
View File

@ -0,0 +1,7 @@
global main
section .text
func:
mov eax, 1
ret
main:
call func

BIN
gameenv/code/test.exe Normal file

Binary file not shown.

BIN
gameenv/raylib.dll Normal file

Binary file not shown.

7
license Normal file
View File

@ -0,0 +1,7 @@
Copyright (c) 2025 Safariminer
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1
readme.md Normal file
View File

@ -0,0 +1 @@
# bioSandbox