diff --git a/biosandbox/Emulation.h b/biosandbox/Emulation.h index fa767f7..0094e6d 100644 --- a/biosandbox/Emulation.h +++ b/biosandbox/Emulation.h @@ -37,13 +37,21 @@ namespace bio { std::map registers; virtual void load_app(application& app) = 0; - virtual void run_symbol(int symbol) = 0; + virtual bool run_symbol(int symbol) = 0; + void clear_registers() { + registers.clear(); + } + void clear_memory() { + times(memsize) { + memory[___i] = 0; + } + } }; memory_dependent class linear_emulator_base : public memory_passdown(emulator_base) { public: int instructionPointer; - void run_symbol(int symbol) { + bool run_symbol(int symbol) { // check symbol ID is within symbol count if (symbol > this->symbols.size() && symbol != -1) throw std::out_of_range( @@ -78,7 +86,9 @@ namespace bio { } if (returned) { std::print("Exited through conventional means [returned out of symbol]\n"); + return true; } + return false; } }; diff --git a/biosandbox/TestFramework.h b/biosandbox/TestFramework.h new file mode 100644 index 0000000..56c7758 --- /dev/null +++ b/biosandbox/TestFramework.h @@ -0,0 +1,16 @@ +#pragma once +#include "bsuml.h" +#include + +namespace bio { + namespace tests { + struct test { + std::string title; + native_callable function; + }; + + inline bool operator==(test& lhs, bool rhs) { + return lhs.function() == rhs; + } + } +} \ No newline at end of file diff --git a/biosandbox/biosandbox.vcxproj b/biosandbox/biosandbox.vcxproj index d3317cb..23b8902 100644 --- a/biosandbox/biosandbox.vcxproj +++ b/biosandbox/biosandbox.vcxproj @@ -148,6 +148,7 @@ + diff --git a/biosandbox/biosandbox.vcxproj.filters b/biosandbox/biosandbox.vcxproj.filters index 843082e..1ddb26d 100644 --- a/biosandbox/biosandbox.vcxproj.filters +++ b/biosandbox/biosandbox.vcxproj.filters @@ -59,5 +59,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/biosandbox/main.cpp b/biosandbox/main.cpp index 45fa9f6..e9816da 100644 --- a/biosandbox/main.cpp +++ b/biosandbox/main.cpp @@ -1,16 +1,42 @@ #include "bsuml.h" #include "Intel.h" #include "BinFile.h" +#include +#include "TestFramework.h" -entry { - ptr> i8086 = new bio::Intel::iAPX86<1024>; - ptr bin = new bio::BinFile("code/test"); +bio::tests::test iapxTest{ + "iAPX Test Suite", + []() -> bool { + ptr> i8086 = new bio::Intel::iAPX86<1024>; - i8086->load_app(*bin->getApp()); - i8086->run_symbol(-1); + std::filesystem::directory_iterator it("code/tests/bin"); - std::println("AX: {}", i8086->registers["ax"]); - std::println("CX: {}", i8086->registers["cx"]); - std::println("DX: {}", i8086->registers["dx"]); - std::println("BX: {}", i8086->registers["bx"]); + bool okay = true; + + for (const std::filesystem::directory_entry& e : it) { + ptr bin = new bio::BinFile(e.path().string()); + std::println("Running {}", e.path().string()); + std::println("==============================="); + + i8086->load_app(*bin->getApp()); + if (!i8086->run_symbol(-1)) okay = false; + + std::println("AX: {}", (signed long long)i8086->registers["ax"]); + std::println("CX: {}", (signed long long)i8086->registers["cx"]); + std::println("DX: {}", (signed long long)i8086->registers["dx"]); + std::println("BX: {}", (signed long long)i8086->registers["bx"]); + i8086->clear_registers(); + i8086->clear_memory(); + + std::println("-------------------------------\n"); + } + return okay; + } +}; + + +entry{ + if (iapxTest == true) { + std::println("Everything is fine."); + } } \ No newline at end of file diff --git a/gameenv/code/test b/gameenv/code/tests/bin/test similarity index 100% rename from gameenv/code/test rename to gameenv/code/tests/bin/test diff --git a/gameenv/code/tests/bin/test2 b/gameenv/code/tests/bin/test2 new file mode 100644 index 0000000..1dbf0d3 Binary files /dev/null and b/gameenv/code/tests/bin/test2 differ diff --git a/gameenv/code/test.asm b/gameenv/code/tests/test.asm similarity index 100% rename from gameenv/code/test.asm rename to gameenv/code/tests/test.asm diff --git a/gameenv/code/tests/test2.asm b/gameenv/code/tests/test2.asm new file mode 100644 index 0000000..8309a0c --- /dev/null +++ b/gameenv/code/tests/test2.asm @@ -0,0 +1,10 @@ +section .text: + mov ax, 10 + mov cx, 20 + mov dx, 30 + mov bx, 40 + sub cx, ax + sub dx, cx + sub bx, dx + sub ax, bx + ret \ No newline at end of file diff --git a/readme.md b/readme.md index 9306b85..446ea77 100644 --- a/readme.md +++ b/readme.md @@ -7,7 +7,7 @@ - [rxi/dyad](https://github.com/rxi/dyad) ## 8086 emulator compatibility -All features the 8086 emulator of the engine supports are demonstrated in the [test assembly file and binary](gameenv/code/test.asm). +All features the 8086 emulator of the engine supports are demonstrated in the [test suite](gameenv/code/tests/). - addition on (A/C/D/B)X from (A/C/D/B)X - subtraction on (A/C/D/B)X from (A/C/D/B)X