2017-01-08 23:36:10 +00:00
|
|
|
package com.bytezone.diskbrowser.applefile;
|
|
|
|
|
2020-02-07 23:20:56 +00:00
|
|
|
// -----------------------------------------------------------------------------------//
|
|
|
|
public class DoubleScrunch
|
|
|
|
// -----------------------------------------------------------------------------------//
|
2017-01-08 23:36:10 +00:00
|
|
|
{
|
2017-01-10 23:47:15 +00:00
|
|
|
final byte[][] memory = new byte[2][0x2000];
|
2017-01-08 23:36:10 +00:00
|
|
|
private byte[] packedBuffer;
|
|
|
|
|
2017-01-10 23:47:15 +00:00
|
|
|
private final int[] rows = new int[192];
|
|
|
|
private int ptr;
|
|
|
|
private int bank;
|
|
|
|
private int outPtr;
|
|
|
|
private int column;
|
2017-01-08 23:36:10 +00:00
|
|
|
|
2020-02-07 23:20:56 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
|
|
|
public DoubleScrunch (byte[] buffer)
|
|
|
|
// ---------------------------------------------------------------------------------//
|
2017-01-08 23:36:10 +00:00
|
|
|
{
|
2017-01-10 23:47:15 +00:00
|
|
|
int row = 0;
|
|
|
|
|
|
|
|
for (int a = 0x400; a >= 0; a -= 0x400) // reversed!
|
|
|
|
for (int b = 0; b < 0x78; b += 0x28)
|
|
|
|
for (int c = 0; c < 0x400; c += 0x80)
|
|
|
|
for (int d = 0; d < 0x2000; d += 0x800)
|
|
|
|
rows[row++] = a + b + c + d;
|
2017-01-08 23:36:10 +00:00
|
|
|
|
|
|
|
packedBuffer = buffer;
|
|
|
|
|
2017-01-10 23:47:15 +00:00
|
|
|
while (true)
|
|
|
|
{
|
2020-02-07 23:20:56 +00:00
|
|
|
int repeat = packedBuffer[ptr++] & 0xFF;
|
2017-01-10 23:47:15 +00:00
|
|
|
|
2020-02-07 23:20:56 +00:00
|
|
|
if ((repeat & 0x80) == 0) // repeat same byte
|
2017-01-10 23:47:15 +00:00
|
|
|
{
|
|
|
|
byte val = packedBuffer[ptr++];
|
2020-02-07 23:20:56 +00:00
|
|
|
while (repeat-- > 0)
|
2017-01-10 23:47:15 +00:00
|
|
|
if (move (val))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else // copy bytes
|
|
|
|
{
|
2020-02-07 23:20:56 +00:00
|
|
|
repeat &= 0x7F;
|
|
|
|
while (repeat-- > 0)
|
2017-01-10 23:47:15 +00:00
|
|
|
if (move (packedBuffer[ptr++]))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-07 23:20:56 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2017-01-10 23:47:15 +00:00
|
|
|
private boolean move (byte val)
|
2020-02-07 23:20:56 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2017-01-10 23:47:15 +00:00
|
|
|
{
|
|
|
|
memory[bank][rows[outPtr++] + column] = val;
|
|
|
|
|
|
|
|
if (outPtr % 192 == 0) // screen column for this bank is finished
|
|
|
|
{
|
|
|
|
outPtr = 0;
|
|
|
|
if (++bank > 1) // both banks are finished
|
|
|
|
{
|
|
|
|
bank = 0;
|
|
|
|
if (++column >= 40) // whole screen is finished
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-01-08 23:36:10 +00:00
|
|
|
}
|