From 338549f9cd49fa0f3001826c6605663fa6dd019b Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sat, 20 May 2023 17:20:46 -0400 Subject: first commit --- include/lib94/lib94.hpp | 88 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 include/lib94/lib94.hpp (limited to 'include') diff --git a/include/lib94/lib94.hpp b/include/lib94/lib94.hpp new file mode 100644 index 0000000..1d061ec --- /dev/null +++ b/include/lib94/lib94.hpp @@ -0,0 +1,88 @@ +#ifndef LIB94_HPP +#define LIB94_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef CORE_SIZE +#define CORE_SIZE 8000 +#endif + +typedef uint32_t number_t; + +enum opcode : uint8_t { + DAT, MOV, ADD, SUB, + MUL, DIV, MOD, JMP, + JMZ, JMN, DJN, SEQ, + SNE, SLT, SPL, NOP +}; + +enum modifier : uint8_t { + A, B, AB, BA, + F, X, I +}; + +enum mode : uint8_t { + IMMEDIATE, DIRECT, + A_INDIRECT, B_INDIRECT, + A_DECREMENT, B_DECREMENT, + A_INCREMENT, B_INCREMENT +}; + +struct instruction { + opcode op; + modifier mod; + mode amode; + mode bmode; + number_t anumber; + number_t bnumber; +}; + +struct warrior { + std::string name; + std::string author; + + number_t org; + + std::vector instructions; +}; + +void seed_prng(uint_fast64_t seed); + +std::variant compile_warrior(std::string source); +bool save_warrior(const warrior &w, const std::filesystem::path &to); +std::optional load_warrior(const std::filesystem::path &from); + +void clear_core(const instruction &background); +void clear_core_random(); + +//warrior pointers need to remain valid for other +//functions to return valid things during the round +bool init_round(const std::vector &warriors); + +size_t alive_warrior_count(); + +//asserts that there is a next warrior +const warrior *get_next_warrior(); +const std::queue &get_processes(const warrior *for_warrior); +//asserts that there is a next process +number_t get_next_process(const warrior *for_warrior); + +const std::set &get_modified_addresses(); +void clear_modified_addresses(); + +const instruction &get_instruction(number_t address); + +//asserts that there is a next warrior +void single_step(); + +const warrior *run_until_warrior_death(); +const warrior *run_until_winner(); + +#endif -- cgit v1.2.3