From 875f6588d94c03a74fdb35f43ffe8a93e80fb03c Mon Sep 17 00:00:00 2001 From: WeebDataHoarder <57538841+weebdatahoarder@users.noreply.github.com> Date: Thu, 5 Aug 2021 16:29:07 +0200 Subject: [PATCH] Implement proper Init OutputContext --- src/instructions/Init.cpp | 28 +++++++++++++++++++++++----- src/instructions/Init.h | 12 ++++++------ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/instructions/Init.cpp b/src/instructions/Init.cpp index cc45e69..dcf6b2d 100644 --- a/src/instructions/Init.cpp +++ b/src/instructions/Init.cpp @@ -29,6 +29,7 @@ #include "../Registers.h" #include #include +#include "../OutputContext.h" void Instruction::Init::fromBytes(uint32_t offset, const std::vector &bytes) { _address = offset; @@ -69,18 +70,35 @@ std::string Instruction::Init::toString() const { if (count > 1 && increment) { op << " UNTIL " << getAddressRegisterName(address + count - 1, addressOffset); } - op << " COUNT " << std::hex << std::setw(6) << std::setfill('0') << count; op << " INCREMENT " << std::dec << (uint32_t) increment; + op << " COUNT " << std::hex << std::setw(6) << std::setfill('0') << count; op << " DATA 0x" << std::hex << std::setw(8) << std::setfill('0') << data; - op << " INC 0x" << std::hex << std::setw(8) << std::setfill('0') << data_add; + op << " ADD 0x" << std::hex << std::setw(8) << std::setfill('0') << data_add; return op.str(); } std::vector Instruction::Init::toOutputFormat(const OutputContext &context) const { - return std::vector{ - //TODO + std::vector f{ + OutputFormat{getAddress() + 0 * 4, + dynamic_cast(std::stringstream("") << "INIT" << " " + << context.getAddressRegisterName( + address, addressOffset) + << ", INC " << std::dec + << (uint32_t) increment).str()} }; + + f.emplace_back(OutputFormat{getAddress() + 1 * 4, + dynamic_cast(std::stringstream("") << " COUNT " << std::dec + << count).str()}); + + f.emplace_back(OutputFormat{getAddress() + 2 * 4, + dynamic_cast(std::stringstream("") << " DATA 0x" << std::hex << std::setw(8) << std::setfill('0') << data).str()}); + + f.emplace_back(OutputFormat{getAddress() + 3 * 4, + dynamic_cast(std::stringstream("") << " ADD 0x" << std::hex << std::setw(8) << std::setfill('0') << data_add).str()}); + + return f; } std::vector Instruction::Init::getPossibleBranches() const { @@ -90,7 +108,7 @@ std::vector Instruction::Init::getPossibleBranches() const { std::vector>> Instruction::Init::execute(AnalysisState &state) const { for (uint32_t i = 0; i < count; ++i) { - state.setRegister(address + (increment ? i : 0), data + data_add * i); + state.setRegister(address + increment, data + data_add * i); } state.current = _endAddress; diff --git a/src/instructions/Init.h b/src/instructions/Init.h index 13da6dd..d0d2b7d 100644 --- a/src/instructions/Init.h +++ b/src/instructions/Init.h @@ -54,11 +54,11 @@ namespace Instruction { execute(AnalysisState &state) const override; - uint8_t addressOffset; - uint8_t increment; - uint32_t address; - uint32_t count; - uint32_t data; - uint32_t data_add; + uint8_t addressOffset{}; + uint8_t increment{}; + uint32_t address{}; + uint32_t count{}; + uint32_t data{}; + uint32_t data_add{}; }; } \ No newline at end of file