commit b93c498d8cedc16f041c9af21ec181aac1a18c55 Author: Safariminer Date: Sun Dec 28 13:56:24 2025 -0500 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5bc5628 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +deps +x64 +*/x64 +.vs +*.ipch \ No newline at end of file diff --git a/biosandbox.sln b/biosandbox.sln new file mode 100644 index 0000000..8c8ce88 --- /dev/null +++ b/biosandbox.sln @@ -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 diff --git a/biosandbox/BinFile.cpp b/biosandbox/BinFile.cpp new file mode 100644 index 0000000..89c3c63 --- /dev/null +++ b/biosandbox/BinFile.cpp @@ -0,0 +1,43 @@ +#include "BinFile.h" + +#include +#include +#include +#include + +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(); + + +} diff --git a/biosandbox/BinFile.h b/biosandbox/BinFile.h new file mode 100644 index 0000000..c57a890 --- /dev/null +++ b/biosandbox/BinFile.h @@ -0,0 +1,26 @@ +#pragma once + +#include "bsuml.h" +#include "Emulation.h" +#include + +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(); + + }; + +} \ No newline at end of file diff --git a/biosandbox/Emulation.cpp b/biosandbox/Emulation.cpp new file mode 100644 index 0000000..1e80a92 --- /dev/null +++ b/biosandbox/Emulation.cpp @@ -0,0 +1 @@ +#include "Emulation.h" diff --git a/biosandbox/Emulation.h b/biosandbox/Emulation.h new file mode 100644 index 0000000..4812fa5 --- /dev/null +++ b/biosandbox/Emulation.h @@ -0,0 +1,79 @@ +#pragma once +#include +#include "bsuml.h" +#include +#include + +namespace bio { + namespace emu { + + using instruction_set = std::vector>; + + memory_dependent using mem_buffer = unsigned char[memsize]; + + struct symbol { + unsigned offset; + }; + + struct application { + + std::vector symbols; + + // contents + unsigned bufferLength; + unsigned char* buffer; + + }; + + memory_dependent class emulator_base { + public: + + instruction_set isa; + mem_buffer memory; + std::vector 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"); + } + } + } + }; + + } +} \ No newline at end of file diff --git a/biosandbox/Intel.cpp b/biosandbox/Intel.cpp new file mode 100644 index 0000000..685d1fe --- /dev/null +++ b/biosandbox/Intel.cpp @@ -0,0 +1,16 @@ +#include "bsuml.h" +#include "Emulation.h" +#include "Intel.h" +#include +#include + + + +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; +} \ No newline at end of file diff --git a/biosandbox/Intel.h b/biosandbox/Intel.h new file mode 100644 index 0000000..31dcb71 --- /dev/null +++ b/biosandbox/Intel.h @@ -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(){} + + }; + } +} \ No newline at end of file diff --git a/biosandbox/Network.cpp b/biosandbox/Network.cpp new file mode 100644 index 0000000..b348fda --- /dev/null +++ b/biosandbox/Network.cpp @@ -0,0 +1,31 @@ +#include "Network.h" +#include + +bool dyadUp = false; +ptr 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() +{ +} diff --git a/biosandbox/Network.h b/biosandbox/Network.h new file mode 100644 index 0000000..bf16036 --- /dev/null +++ b/biosandbox/Network.h @@ -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(); + }; + +} \ No newline at end of file diff --git a/biosandbox/Object.h b/biosandbox/Object.h new file mode 100644 index 0000000..af4a012 --- /dev/null +++ b/biosandbox/Object.h @@ -0,0 +1,28 @@ +#pragma once +#include +#include +#include "bsuml.h" + +#define native_game_callback native_callable> + +namespace bio { + + class object { + public: + + bool native; + Vector3 position; + + using callback = + std::variant< + native_game_callback + >; + + callback start; + callback update; + callback stop; + + + + }; +} \ No newline at end of file diff --git a/biosandbox/Playables.h b/biosandbox/Playables.h new file mode 100644 index 0000000..9942631 --- /dev/null +++ b/biosandbox/Playables.h @@ -0,0 +1,27 @@ +#pragma once +#include +#include "Object.h" + +namespace bio { + // base class for concepts + class _Playable : public object{ + public: + + }; + + template + concept playable = std::is_base_of<_Playable, T>::value; + + + class Guardian : public _Playable { + public: + Guardian(); + ~Guardian(); + }; + + class Keymaker : public _Playable { + Keymaker(); + ~Keymaker(); + }; + +} \ No newline at end of file diff --git a/biosandbox/biosandbox.vcxproj b/biosandbox/biosandbox.vcxproj new file mode 100644 index 0000000..d3317cb --- /dev/null +++ b/biosandbox/biosandbox.vcxproj @@ -0,0 +1,155 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {a7bccb8d-f194-4005-830c-9a23d4d9b442} + biosandbox + 10.0 + + + + Application + true + v145 + Unicode + + + Application + false + v145 + true + Unicode + + + Application + true + v145 + Unicode + + + Application + false + v145 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + _CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpplatest + stdclatest + $(SOLUTIONDIR)deps/include + + + Console + true + $(SOLUTIONDIR)deps/lib + ws2_32.lib;winmm.lib;raylibdll.lib;raylib.lib;$(CoreLibraryDependencies);%(AdditionalDependencies) + + + + + Level3 + true + true + true + _CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpplatest + stdclatest + $(SOLUTIONDIR)deps/include + + + Console + true + $(SOLUTIONDIR)deps/lib + ws2_32.lib;winmm.lib;raylibdll.lib;raylib.lib;$(CoreLibraryDependencies);%(AdditionalDependencies) + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/biosandbox/biosandbox.vcxproj.filters b/biosandbox/biosandbox.vcxproj.filters new file mode 100644 index 0000000..843082e --- /dev/null +++ b/biosandbox/biosandbox.vcxproj.filters @@ -0,0 +1,63 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;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 + + + {5b851266-c200-4d2b-8749-619796a9be7a} + + + + + Source Files + + + ext + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/biosandbox/biosandbox.vcxproj.user b/biosandbox/biosandbox.vcxproj.user new file mode 100644 index 0000000..ba2f8fc --- /dev/null +++ b/biosandbox/biosandbox.vcxproj.user @@ -0,0 +1,11 @@ + + + + $(SOLUTIONDIR)gameenv + WindowsLocalDebugger + + + $(SOLUTIONDIR)gameenv + WindowsLocalDebugger + + \ No newline at end of file diff --git a/biosandbox/bsuml.h b/biosandbox/bsuml.h new file mode 100644 index 0000000..94a2891 --- /dev/null +++ b/biosandbox/bsuml.h @@ -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 +using ptr = T*; // a more C++ way of writing raw pointers + +template +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 +#define memory_passdown(x) x + +#endif diff --git a/biosandbox/main.cpp b/biosandbox/main.cpp new file mode 100644 index 0000000..1577248 --- /dev/null +++ b/biosandbox/main.cpp @@ -0,0 +1,11 @@ +#include "bsuml.h" +#include "Intel.h" +#include "BinFile.h" + +entry{ + ptr> i8086 = new bio::Intel::iAPX86<1024>; + ptr bin = new bio::BinFile("code/test"); + + i8086->load_app(*bin->getApp()); + i8086->run_symbol(-1); +} \ No newline at end of file diff --git a/gameenv/code/test b/gameenv/code/test new file mode 100644 index 0000000..97781c5 Binary files /dev/null and b/gameenv/code/test differ diff --git a/gameenv/code/test.asm b/gameenv/code/test.asm new file mode 100644 index 0000000..80ecbaa --- /dev/null +++ b/gameenv/code/test.asm @@ -0,0 +1,7 @@ +global main +section .text +func: +mov eax, 1 +ret +main: +call func \ No newline at end of file diff --git a/gameenv/code/test.exe b/gameenv/code/test.exe new file mode 100644 index 0000000..fa204e4 Binary files /dev/null and b/gameenv/code/test.exe differ diff --git a/gameenv/raylib.dll b/gameenv/raylib.dll new file mode 100644 index 0000000..12ea7c8 Binary files /dev/null and b/gameenv/raylib.dll differ diff --git a/license b/license new file mode 100644 index 0000000..fb3b80a --- /dev/null +++ b/license @@ -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. \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..6dd2acc --- /dev/null +++ b/readme.md @@ -0,0 +1 @@ +# bioSandbox \ No newline at end of file