From e745b3821919a1eadf44bfbd5f20f29dc0fc1002 Mon Sep 17 00:00:00 2001 From: Adrien Bertrand Date: Tue, 9 Jul 2024 14:55:29 +0200 Subject: [PATCH] Make ownerPID a standalone header field --- src/TIVarFile.cpp | 2 ++ src/TIVarFile.h | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/TIVarFile.cpp b/src/TIVarFile.cpp index f954eb1..ab4688b 100644 --- a/src/TIVarFile.cpp +++ b/src/TIVarFile.cpp @@ -106,6 +106,7 @@ namespace tivars const auto signature = this->get_string_bytes(sizeof(var_header_t::signature)); const auto sig_extra = this->get_raw_bytes(sizeof(var_header_t::sig_extra)); + this->header.ownerPID = this->get_raw_byte(); const auto comment = this->get_string_bytes(sizeof(var_header_t::comment)); std::copy(signature.begin(), signature.end(), this->header.signature); std::copy(sig_extra.begin(), sig_extra.end(), this->header.sig_extra); @@ -376,6 +377,7 @@ namespace tivars { bin_data.insert(bin_data.end(), this->header.signature, this->header.signature + sizeof(var_header_t::signature)); bin_data.insert(bin_data.end(), this->header.sig_extra, this->header.sig_extra + sizeof(var_header_t::sig_extra)); + bin_data.push_back(this->header.ownerPID); bin_data.insert(bin_data.end(), this->header.comment, this->header.comment + sizeof(var_header_t::comment)); bin_data.push_back((uint8_t) (this->header.entries_len & 0xFF)); bin_data.push_back((uint8_t) ((this->header.entries_len >> 8) & 0xFF)); } diff --git a/src/TIVarFile.h b/src/TIVarFile.h index 02e8760..5f1e08b 100644 --- a/src/TIVarFile.h +++ b/src/TIVarFile.h @@ -25,7 +25,8 @@ namespace tivars struct var_header_t { uint8_t signature[8] = {}; - uint8_t sig_extra[3] = { 0x1A, 0x0A, OWNER_PID_NONE }; + uint8_t sig_extra[2] = { 0x1A, 0x0A }; // this never actually changes + uint8_t ownerPID = OWNER_PID_NONE; // informational - may reflect what's on the version field in the var entries uint8_t comment[42] = {}; uint16_t entries_len = 0; }; @@ -48,7 +49,7 @@ namespace tivars }; // comes right after the var header, so == its size - static const constexpr uint16_t firstVarEntryOffset = sizeof(var_header_t::signature) + sizeof(var_header_t::sig_extra) + sizeof(var_header_t::comment) + sizeof(var_header_t::entries_len); + static const constexpr uint16_t firstVarEntryOffset = sizeof(var_header_t::signature) + sizeof(var_header_t::sig_extra) + sizeof(var_header_t::ownerPID) + sizeof(var_header_t::comment) + sizeof(var_header_t::entries_len); static_assert(firstVarEntryOffset == 55, "firstVarEntryOffset size needs to be 55"); static const constexpr uint16_t varEntryOldLength = sizeof(var_entry_t::data_length) + sizeof(var_entry_t::typeID) + sizeof(var_entry_t::varname);