removed c structures

This commit is contained in:
Denis Molony 2020-06-24 07:31:29 +10:00
parent 93719f7b25
commit 8b41a5c54a
3 changed files with 456 additions and 128 deletions

View File

@ -31,8 +31,6 @@ public class DoubleHiResImage extends HiResImage
{ {
super (name, buffer); super (name, buffer);
// assert name.endsWith (".PAC") || name.endsWith ("A2FC");
if (name.endsWith (".PAC")) if (name.endsWith (".PAC"))
{ {
packedBuffer = buffer; packedBuffer = buffer;

View File

@ -5,7 +5,6 @@ package com.bytezone.diskbrowser.applefile;
// -----------------------------------------------------------------------------------// // -----------------------------------------------------------------------------------//
public class ExoBuffer public class ExoBuffer
// -----------------------------------------------------------------------------------//
{ {
private static int PBIT_BITS_ORDER_BE = 0; private static int PBIT_BITS_ORDER_BE = 0;
private static int PBIT_BITS_COPY_GT_7 = 1; private static int PBIT_BITS_COPY_GT_7 = 1;
@ -19,21 +18,53 @@ public class ExoBuffer
private static int PFLAG_BITS_ALIGN_START = (1 << PBIT_BITS_ALIGN_START); private static int PFLAG_BITS_ALIGN_START = (1 << PBIT_BITS_ALIGN_START);
private static int PFLAG_4_OFFSET_TABLES = (1 << PBIT_4_OFFSET_TABLES); private static int PFLAG_4_OFFSET_TABLES = (1 << PBIT_4_OFFSET_TABLES);
int inPos;
int inEnd;
int outPos;
byte[] inBuffer;
byte[] outBuffer = new byte[50000]; byte[] outBuffer = new byte[50000];
int bitBuffer;
int bitsRead;
int flagsProto;
int tableBit[] = new int[8];
int tableOff[] = new int[8];
int tableBi[] = new int[100];
int tableLo[] = new int[100];
int tableHi[] = new int[100];
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public ExoBuffer (byte[] inBuffer) public ExoBuffer (byte[] inBuffer)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
reverse (inBuffer); reverse (inBuffer);
DecCtx decCtx = new DecCtx ();
decCtxInit (decCtx, inBuffer, outBuffer, 23);
// tableDump (decCtx.table);
decCtxDecrunch (decCtx);
if (decCtx.outPos != outBuffer.length) bitsRead = 0;
this.inBuffer = inBuffer;
inEnd = inBuffer.length;
inPos = 2;
flagsProto = 23;
outPos = 0;
if ((flagsProto & PFLAG_BITS_ALIGN_START) != 0)
bitBuffer = 0;
else
bitBuffer = getByte ();
tableInit ();
// tableDump (decCtx.table);
decCtxDecrunch ();
if (outPos != outBuffer.length)
{ {
byte[] outBuffer2 = new byte[decCtx.outPos]; byte[] outBuffer2 = new byte[outPos];
System.arraycopy (outBuffer, 0, outBuffer2, 0, outBuffer2.length); System.arraycopy (outBuffer, 0, outBuffer2, 0, outBuffer2.length);
outBuffer = outBuffer2; outBuffer = outBuffer2;
} }
@ -62,48 +93,48 @@ public class ExoBuffer
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
private int bitBufRotate (DecCtx decCtx, int carry) private int bitBufRotate (int carry)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
int carryOut; int carryOut;
if ((decCtx.flagsProto & PFLAG_BITS_ORDER_BE) != 0) if ((flagsProto & PFLAG_BITS_ORDER_BE) != 0)
{ {
carryOut = (decCtx.bitBuffer & 0x80) == 0 ? 0 : 1; carryOut = (bitBuffer & 0x80) == 0 ? 0 : 1;
decCtx.bitBuffer = (decCtx.bitBuffer << 1) & 0xFF; bitBuffer = (bitBuffer << 1) & 0xFF;
if (carry != 0) if (carry != 0)
decCtx.bitBuffer |= 0x01; bitBuffer |= 0x01;
} }
else else
{ {
carryOut = decCtx.bitBuffer & 0x01; carryOut = bitBuffer & 0x01;
decCtx.bitBuffer = (decCtx.bitBuffer >>> 1) & 0xFF; bitBuffer = (bitBuffer >>> 1) & 0xFF;
if (carry != 0) if (carry != 0)
decCtx.bitBuffer |= 0x80; bitBuffer |= 0x80;
} }
return carryOut; return carryOut;
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
private int getByte (DecCtx decCtx) private int getByte ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
decCtx.bitsRead += 8; bitsRead += 8;
int c = decCtx.inBuffer[decCtx.inPos++] & 0xFF; int c = inBuffer[inPos++] & 0xFF;
return c; return c;
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
private int getBits (DecCtx decCtx, int count) private int getBits (int count)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
int byteCopy = 0; int byteCopy = 0;
int value = 0; int value = 0;
if ((decCtx.flagsProto & PFLAG_BITS_COPY_GT_7) != 0) if ((flagsProto & PFLAG_BITS_COPY_GT_7) != 0)
{ {
while (count > 7) while (count > 7)
{ {
@ -114,78 +145,78 @@ public class ExoBuffer
while (count-- > 0) while (count-- > 0)
{ {
int carry = bitBufRotate (decCtx, 0); int carry = bitBufRotate (0);
if (decCtx.bitBuffer == 0) if (bitBuffer == 0)
{ {
decCtx.bitBuffer = getByte (decCtx); bitBuffer = getByte ();
decCtx.bitsRead -= 8; bitsRead -= 8;
carry = bitBufRotate (decCtx, 1); carry = bitBufRotate (1);
} }
value <<= 1; value <<= 1;
value |= carry; value |= carry;
decCtx.bitsRead++; bitsRead++;
} }
while (byteCopy-- > 0) while (byteCopy-- > 0)
{ {
value <<= 8; value <<= 8;
value |= getByte (decCtx); value |= getByte ();
} }
return value; return value;
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
private int getGammaCode (DecCtx decCtx) private int getGammaCode ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
int gammaCode = 0; int gammaCode = 0;
while (getBits (decCtx, 1) == 0) while (getBits (1) == 0)
++gammaCode; ++gammaCode;
return gammaCode; return gammaCode;
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
private int getCooked (DecCtx decCtx, int index) private int getCooked (int index)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
int base = decCtx.table.tableLo[index] | (decCtx.table.tableHi[index] << 8); int base = tableLo[index] | (tableHi[index] << 8);
return base + getBits (decCtx, decCtx.table.tableBi[index]); return base + getBits (tableBi[index]);
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
private void tableInit (DecCtx decCtx, DecTable decTable) private void tableInit ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
int end; int end;
int a = 0; int a = 0;
int b = 0; int b = 0;
decTable.tableBit[0] = 2; tableBit[0] = 2;
decTable.tableBit[1] = 4; tableBit[1] = 4;
decTable.tableBit[2] = 4; tableBit[2] = 4;
if ((decCtx.flagsProto & PFLAG_4_OFFSET_TABLES) != 0) if ((flagsProto & PFLAG_4_OFFSET_TABLES) != 0)
{ {
end = 68; end = 68;
decTable.tableBit[3] = 4; tableBit[3] = 4;
decTable.tableOff[0] = 64; tableOff[0] = 64;
decTable.tableOff[1] = 48; tableOff[1] = 48;
decTable.tableOff[2] = 32; tableOff[2] = 32;
decTable.tableOff[3] = 16; tableOff[3] = 16;
} }
else else
{ {
end = 52; end = 52;
decTable.tableOff[0] = 48; tableOff[0] = 48;
decTable.tableOff[1] = 32; tableOff[1] = 32;
decTable.tableOff[2] = 16; tableOff[2] = 16;
} }
for (int i = 0; i < end; i++) for (int i = 0; i < end; i++)
@ -195,64 +226,41 @@ public class ExoBuffer
else else
a = 1; a = 1;
decTable.tableLo[i] = a & 0xFF; tableLo[i] = a & 0xFF;
decTable.tableHi[i] = a >>> 8; tableHi[i] = a >>> 8;
if ((decCtx.flagsProto & PFLAG_BITS_COPY_GT_7) != 0) if ((flagsProto & PFLAG_BITS_COPY_GT_7) != 0)
{ {
b = getBits (decCtx, 3); b = getBits (3);
b |= getBits (decCtx, 1) << 3; b |= getBits (1) << 3;
} }
else else
b = getBits (decCtx, 4); b = getBits (4);
decTable.tableBi[i] = b; tableBi[i] = b;
} }
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
private void tableDump (DecTable table) private void tableDump ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
System.out.printf ("%X", table.tableBi[i]); System.out.printf ("%X", tableBi[i]);
for (int j = 0; j < 3; j++) for (int j = 0; j < 3; j++)
{ {
System.out.printf (","); System.out.printf (",");
int start = table.tableOff[j]; int start = tableOff[j];
int end = start + (1 << table.tableBit[j]); int end = start + (1 << tableBit[j]);
for (int i = start; i < end; i++) for (int i = start; i < end; i++)
System.out.printf ("%X", table.tableBi[i]); System.out.printf ("%X", tableBi[i]);
} }
System.out.println (); System.out.println ();
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
private void decCtxInit (DecCtx decCtx, byte[] inBuffer, byte[] outBuffer, int flags) private void decCtxDecrunch ()
// ---------------------------------------------------------------------------------//
{
decCtx.bitsRead = 0;
decCtx.inBuffer = inBuffer;
decCtx.inEnd = inBuffer.length;
decCtx.inPos = 2;
decCtx.flagsProto = flags;
decCtx.outBuffer = outBuffer;
decCtx.outPos = 0;
if ((decCtx.flagsProto & PFLAG_BITS_ALIGN_START) != 0)
decCtx.bitBuffer = 0;
else
decCtx.bitBuffer = getByte (decCtx);
tableInit (decCtx, decCtx.table);
}
// ---------------------------------------------------------------------------------//
private void decCtxDecrunch (DecCtx decCtx)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
int len; int len;
@ -261,92 +269,63 @@ public class ExoBuffer
int val; int val;
int src = 0; int src = 0;
int literal; int literal;
int threshold = (decCtx.flagsProto & PFLAG_4_OFFSET_TABLES) != 0 ? 4 : 3; int threshold = (flagsProto & PFLAG_4_OFFSET_TABLES) != 0 ? 4 : 3;
if ((decCtx.flagsProto & PFLAG_IMPL_1LITERAL) != 0) if ((flagsProto & PFLAG_IMPL_1LITERAL) != 0)
{ {
len = 1; len = 1;
literal = 1; literal = 1;
src = literal (decCtx, len, literal, src); src = literal (len, literal, src);
} }
while (true) while (true)
{ {
literal = 0; literal = 0;
if (getBits (decCtx, 1) != 0) if (getBits (1) != 0)
{ {
len = 1; len = 1;
literal = 1; literal = 1;
src = literal (decCtx, len, literal, src); src = literal (len, literal, src);
continue; continue;
} }
val = getGammaCode (decCtx); val = getGammaCode ();
if (val == 16) if (val == 16)
break; break;
if (val == 17) if (val == 17)
{ {
len = getBits (decCtx, 16); len = getBits (16);
literal = 1; literal = 1;
src = literal (decCtx, len, literal, src); src = literal (len, literal, src);
continue; continue;
} }
len = getCooked (decCtx, val); len = getCooked (val);
i = (len > threshold ? threshold : len) - 1; i = (len > threshold ? threshold : len) - 1;
val = decCtx.table.tableOff[i] + getBits (decCtx, decCtx.table.tableBit[i]); val = tableOff[i] + getBits (tableBit[i]);
offset = getCooked (decCtx, val); offset = getCooked (val);
src = decCtx.outPos - offset; src = outPos - offset;
src = literal (decCtx, len, literal, src); src = literal (len, literal, src);
} }
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
private int literal (DecCtx decCtx, int len, int literal, int src) private int literal (int len, int literal, int src)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
assert len > 0; assert len > 0;
do do
{ {
int val = literal == 0 ? decCtx.outBuffer[src++] : getByte (decCtx); int val = literal == 0 ? outBuffer[src++] : getByte ();
decCtx.outBuffer[decCtx.outPos++] = (byte) (val & 0xFF); outBuffer[outPos++] = (byte) (val & 0xFF);
} while (--len > 0); } while (--len > 0);
return src; return src;
} }
// ---------------------------------------------------------------------------------//
class DecCtx
// ---------------------------------------------------------------------------------//
{
int inPos;
int inEnd;
int outPos;
byte[] inBuffer;
byte[] outBuffer;
int bitBuffer;
DecTable table = new DecTable ();
int bitsRead;
int flagsProto;
}
// ---------------------------------------------------------------------------------//
class DecTable
// ---------------------------------------------------------------------------------//
{
int tableBit[] = new int[8];
int tableOff[] = new int[8];
int tableBi[] = new int[100];
int tableLo[] = new int[100];
int tableHi[] = new int[100];
}
} }

View File

@ -0,0 +1,351 @@
package com.bytezone.diskbrowser.applefile;
// pack::: ~/exomizer-3.0.2/src/exomizer mem -q -P23 -lnone LODE148@0x4000 -o LODE148c
// unpack: ~/exomizer-3.0.2/src/exomizer raw -d -b -P23 LODE148c,0,-2 -o LODE148x
// -----------------------------------------------------------------------------------//
public class ExoBufferC
{
private static int PBIT_BITS_ORDER_BE = 0;
private static int PBIT_BITS_COPY_GT_7 = 1;
private static int PBIT_IMPL_1LITERAL = 2;
private static int PBIT_BITS_ALIGN_START = 3;
private static int PBIT_4_OFFSET_TABLES = 4;
private static int PFLAG_BITS_ORDER_BE = (1 << PBIT_BITS_ORDER_BE);
private static int PFLAG_BITS_COPY_GT_7 = (1 << PBIT_BITS_COPY_GT_7);
private static int PFLAG_IMPL_1LITERAL = (1 << PBIT_IMPL_1LITERAL);
private static int PFLAG_BITS_ALIGN_START = (1 << PBIT_BITS_ALIGN_START);
private static int PFLAG_4_OFFSET_TABLES = (1 << PBIT_4_OFFSET_TABLES);
byte[] outBuffer = new byte[50000];
// ---------------------------------------------------------------------------------//
public ExoBufferC (byte[] inBuffer)
// ---------------------------------------------------------------------------------//
{
reverse (inBuffer);
DecCtx decCtx = new DecCtx ();
decCtxInit (decCtx, inBuffer, outBuffer, 23);
// tableDump (decCtx.table);
decCtxDecrunch (decCtx);
if (decCtx.outPos != outBuffer.length)
{
byte[] outBuffer2 = new byte[decCtx.outPos];
System.arraycopy (outBuffer, 0, outBuffer2, 0, outBuffer2.length);
outBuffer = outBuffer2;
}
reverse (outBuffer);
}
// ---------------------------------------------------------------------------------//
private void reverse (byte[] inBuffer)
// ---------------------------------------------------------------------------------//
{
int lo = 0;
int hi = inBuffer.length - 1;
while (lo < hi)
{
byte temp = inBuffer[lo];
inBuffer[lo++] = inBuffer[hi];
inBuffer[hi--] = temp;
}
}
// ---------------------------------------------------------------------------------//
public byte[] getExpandedBuffer ()
// ---------------------------------------------------------------------------------//
{
return outBuffer;
}
// ---------------------------------------------------------------------------------//
private int bitBufRotate (DecCtx decCtx, int carry)
// ---------------------------------------------------------------------------------//
{
int carryOut;
if ((decCtx.flagsProto & PFLAG_BITS_ORDER_BE) != 0)
{
carryOut = (decCtx.bitBuffer & 0x80) == 0 ? 0 : 1;
decCtx.bitBuffer = (decCtx.bitBuffer << 1) & 0xFF;
if (carry != 0)
decCtx.bitBuffer |= 0x01;
}
else
{
carryOut = decCtx.bitBuffer & 0x01;
decCtx.bitBuffer = (decCtx.bitBuffer >>> 1) & 0xFF;
if (carry != 0)
decCtx.bitBuffer |= 0x80;
}
return carryOut;
}
// ---------------------------------------------------------------------------------//
private int getByte (DecCtx decCtx)
// ---------------------------------------------------------------------------------//
{
decCtx.bitsRead += 8;
int c = decCtx.inBuffer[decCtx.inPos++] & 0xFF;
return c;
}
// ---------------------------------------------------------------------------------//
private int getBits (DecCtx decCtx, int count)
// ---------------------------------------------------------------------------------//
{
int byteCopy = 0;
int value = 0;
if ((decCtx.flagsProto & PFLAG_BITS_COPY_GT_7) != 0)
{
while (count > 7)
{
byteCopy = count >>> 3;
count &= 7;
}
}
while (count-- > 0)
{
int carry = bitBufRotate (decCtx, 0);
if (decCtx.bitBuffer == 0)
{
decCtx.bitBuffer = getByte (decCtx);
decCtx.bitsRead -= 8;
carry = bitBufRotate (decCtx, 1);
}
value <<= 1;
value |= carry;
decCtx.bitsRead++;
}
while (byteCopy-- > 0)
{
value <<= 8;
value |= getByte (decCtx);
}
return value;
}
// ---------------------------------------------------------------------------------//
private int getGammaCode (DecCtx decCtx)
// ---------------------------------------------------------------------------------//
{
int gammaCode = 0;
while (getBits (decCtx, 1) == 0)
++gammaCode;
return gammaCode;
}
// ---------------------------------------------------------------------------------//
private int getCooked (DecCtx decCtx, int index)
// ---------------------------------------------------------------------------------//
{
int base = decCtx.table.tableLo[index] | (decCtx.table.tableHi[index] << 8);
return base + getBits (decCtx, decCtx.table.tableBi[index]);
}
// ---------------------------------------------------------------------------------//
private void tableInit (DecCtx decCtx, DecTable decTable)
// ---------------------------------------------------------------------------------//
{
int end;
int a = 0;
int b = 0;
decTable.tableBit[0] = 2;
decTable.tableBit[1] = 4;
decTable.tableBit[2] = 4;
if ((decCtx.flagsProto & PFLAG_4_OFFSET_TABLES) != 0)
{
end = 68;
decTable.tableBit[3] = 4;
decTable.tableOff[0] = 64;
decTable.tableOff[1] = 48;
decTable.tableOff[2] = 32;
decTable.tableOff[3] = 16;
}
else
{
end = 52;
decTable.tableOff[0] = 48;
decTable.tableOff[1] = 32;
decTable.tableOff[2] = 16;
}
for (int i = 0; i < end; i++)
{
if ((i & 0x0F) != 0)
a += (1 << b);
else
a = 1;
decTable.tableLo[i] = a & 0xFF;
decTable.tableHi[i] = a >>> 8;
if ((decCtx.flagsProto & PFLAG_BITS_COPY_GT_7) != 0)
{
b = getBits (decCtx, 3);
b |= getBits (decCtx, 1) << 3;
}
else
b = getBits (decCtx, 4);
decTable.tableBi[i] = b;
}
}
// ---------------------------------------------------------------------------------//
private void tableDump (DecTable table)
// ---------------------------------------------------------------------------------//
{
for (int i = 0; i < 16; i++)
System.out.printf ("%X", table.tableBi[i]);
for (int j = 0; j < 3; j++)
{
System.out.printf (",");
int start = table.tableOff[j];
int end = start + (1 << table.tableBit[j]);
for (int i = start; i < end; i++)
System.out.printf ("%X", table.tableBi[i]);
}
System.out.println ();
}
// ---------------------------------------------------------------------------------//
private void decCtxInit (DecCtx decCtx, byte[] inBuffer, byte[] outBuffer, int flags)
// ---------------------------------------------------------------------------------//
{
decCtx.bitsRead = 0;
decCtx.inBuffer = inBuffer;
decCtx.inEnd = inBuffer.length;
decCtx.inPos = 2;
decCtx.flagsProto = flags;
decCtx.outBuffer = outBuffer;
decCtx.outPos = 0;
if ((decCtx.flagsProto & PFLAG_BITS_ALIGN_START) != 0)
decCtx.bitBuffer = 0;
else
decCtx.bitBuffer = getByte (decCtx);
tableInit (decCtx, decCtx.table);
}
// ---------------------------------------------------------------------------------//
private void decCtxDecrunch (DecCtx decCtx)
// ---------------------------------------------------------------------------------//
{
int len;
int offset;
int i;
int val;
int src = 0;
int literal;
int threshold = (decCtx.flagsProto & PFLAG_4_OFFSET_TABLES) != 0 ? 4 : 3;
if ((decCtx.flagsProto & PFLAG_IMPL_1LITERAL) != 0)
{
len = 1;
literal = 1;
src = literal (decCtx, len, literal, src);
}
while (true)
{
literal = 0;
if (getBits (decCtx, 1) != 0)
{
len = 1;
literal = 1;
src = literal (decCtx, len, literal, src);
continue;
}
val = getGammaCode (decCtx);
if (val == 16)
break;
if (val == 17)
{
len = getBits (decCtx, 16);
literal = 1;
src = literal (decCtx, len, literal, src);
continue;
}
len = getCooked (decCtx, val);
i = (len > threshold ? threshold : len) - 1;
val = decCtx.table.tableOff[i] + getBits (decCtx, decCtx.table.tableBit[i]);
offset = getCooked (decCtx, val);
src = decCtx.outPos - offset;
src = literal (decCtx, len, literal, src);
}
}
// ---------------------------------------------------------------------------------//
private int literal (DecCtx decCtx, int len, int literal, int src)
// ---------------------------------------------------------------------------------//
{
assert len > 0;
do
{
int val = literal == 0 ? decCtx.outBuffer[src++] : getByte (decCtx);
decCtx.outBuffer[decCtx.outPos++] = (byte) (val & 0xFF);
} while (--len > 0);
return src;
}
// ---------------------------------------------------------------------------------//
class DecCtx
// ---------------------------------------------------------------------------------//
{
int inPos;
int inEnd;
int outPos;
byte[] inBuffer;
byte[] outBuffer;
int bitBuffer;
DecTable table = new DecTable ();
int bitsRead;
int flagsProto;
}
// ---------------------------------------------------------------------------------//
class DecTable
// ---------------------------------------------------------------------------------//
{
int tableBit[] = new int[8];
int tableOff[] = new int[8];
int tableBi[] = new int[100];
int tableLo[] = new int[100];
int tableHi[] = new int[100];
}
}