Added new tests for 8086 emulation + test FW

This commit is contained in:
Safariminer 2025-12-28 16:55:03 -05:00
parent b1fb32c0c1
commit 244be9f1ae
10 changed files with 78 additions and 12 deletions

View File

@ -37,13 +37,21 @@ namespace bio {
std::map<std::string, unsigned long long> 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;
}
};

View File

@ -0,0 +1,16 @@
#pragma once
#include "bsuml.h"
#include <iostream>
namespace bio {
namespace tests {
struct test {
std::string title;
native_callable<bool> function;
};
inline bool operator==(test& lhs, bool rhs) {
return lhs.function() == rhs;
}
}
}

View File

@ -148,6 +148,7 @@
<ClInclude Include="Network.h" />
<ClInclude Include="Object.h" />
<ClInclude Include="Playables.h" />
<ClInclude Include="TestFramework.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -59,5 +59,8 @@
<ClInclude Include="BinFile.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TestFramework.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -1,16 +1,42 @@
#include "bsuml.h"
#include "Intel.h"
#include "BinFile.h"
#include <filesystem>
#include "TestFramework.h"
entry {
ptr<bio::Intel::iAPX86<1024>> i8086 = new bio::Intel::iAPX86<1024>;
ptr<bio::BinFile> bin = new bio::BinFile("code/test");
bio::tests::test iapxTest{
"iAPX Test Suite",
[]() -> bool {
ptr<bio::Intel::iAPX86<1024>> 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<bio::BinFile> 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.");
}
}

Binary file not shown.

View File

@ -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

View File

@ -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