diff --git a/unpletter/unpletter.cpp b/unpletter/unpletter.cpp index 94e1b18..357c0b7 100644 --- a/unpletter/unpletter.cpp +++ b/unpletter/unpletter.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -7,16 +8,21 @@ using data_type = unsigned char; class Uncompressor { public: - explicit Uncompressor(const std::vector& inData) + explicit Uncompressor(const std::vector& inData, bool dsk2rom_tweak = false) : compressedData(inData) { std::vector output; - int q_value = (getBit() << 2 | getBit() << 1 | getBit()) + 1; + // The dsk2rom version has a fixed value of 2 for q_value and doesn't read it from the compressed variable stream + int q_value = 2; + if (!dsk2rom_tweak) + { + q_value = (getBit() << 2 | getBit() << 1 | getBit()) + 1; + } data_type first_byte = getByte(); output.push_back(first_byte); - dataPosition = 2; + dataPosition = dsk2rom_tweak ? 1 : 2; while (dataPosition < inData.size()) { @@ -24,7 +30,7 @@ public: { data_type length = getInterlacedEliasGamma() + 1; - if (length == 255) + if (length == 255 || (dsk2rom_tweak && length == 0)) { break; } @@ -33,8 +39,10 @@ public: if (offset & 0x80) { offset = offset & 0x7F; - switch(q_value) + switch (q_value) { + case 7: + offset = offset | (getBit() << 13); case 6: offset = offset | (getBit() << 12); case 5: @@ -67,10 +75,18 @@ public: } } + int count = 0; for (unsigned char byte: output) { - std::cout << byte; + std::cout << std::hex << std::setw(2) << std::setfill('0') << static_cast(byte) << " "; + if (++count % 30 == 0) + { + std::cout << std::endl; + } } + + std::cout << std::endl; + std::cout << "Output size: " << output.size() << std::endl; } private: