Add support for the dsk2rom tweak.

This commit is contained in:
Sylvain Glaize 2024-02-21 22:43:31 +01:00
parent 9378eadf71
commit 2e0a6f1a12

View File

@ -1,4 +1,5 @@
#include <fstream> #include <fstream>
#include <iomanip>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
@ -7,16 +8,21 @@ using data_type = unsigned char;
class Uncompressor class Uncompressor
{ {
public: public:
explicit Uncompressor(const std::vector<unsigned char>& inData) explicit Uncompressor(const std::vector<unsigned char>& inData, bool dsk2rom_tweak = false)
: compressedData(inData) : compressedData(inData)
{ {
std::vector<unsigned char> output; std::vector<unsigned char> 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(); data_type first_byte = getByte();
output.push_back(first_byte); output.push_back(first_byte);
dataPosition = 2; dataPosition = dsk2rom_tweak ? 1 : 2;
while (dataPosition < inData.size()) while (dataPosition < inData.size())
{ {
@ -24,7 +30,7 @@ public:
{ {
data_type length = getInterlacedEliasGamma() + 1; data_type length = getInterlacedEliasGamma() + 1;
if (length == 255) if (length == 255 || (dsk2rom_tweak && length == 0))
{ {
break; break;
} }
@ -33,8 +39,10 @@ public:
if (offset & 0x80) if (offset & 0x80)
{ {
offset = offset & 0x7F; offset = offset & 0x7F;
switch(q_value) switch (q_value)
{ {
case 7:
offset = offset | (getBit() << 13);
case 6: case 6:
offset = offset | (getBit() << 12); offset = offset | (getBit() << 12);
case 5: case 5:
@ -67,10 +75,18 @@ public:
} }
} }
int count = 0;
for (unsigned char byte: output) for (unsigned char byte: output)
{ {
std::cout << byte; std::cout << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(byte) << " ";
if (++count % 30 == 0)
{
std::cout << std::endl;
}
} }
std::cout << std::endl;
std::cout << "Output size: " << output.size() << std::endl;
} }
private: private: