Properly put in the data and fix bugs for the tests
This commit is contained in:
parent
3d184a0280
commit
07ab2d7b46
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1709,6 +1709,10 @@ nop
|
||||||
.org 0x82DB284 :: dw m2_credits_font
|
.org 0x82DB284 :: dw m2_credits_font
|
||||||
.org 0x801352E :: bl printPlayerNameCredits
|
.org 0x801352E :: bl printPlayerNameCredits
|
||||||
|
|
||||||
|
//Repoint cast graphical data
|
||||||
|
.org 0x82DB25C :: dw m2_cast_graphics
|
||||||
|
.org 0x82DB264 :: dw m2_cast_arrangements
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
// Move stuff around in order to make space for the code
|
// Move stuff around in order to make space for the code
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
@ -1871,6 +1875,14 @@ m2_coord_table_file:
|
||||||
m2_credits_conversion_table:
|
m2_credits_conversion_table:
|
||||||
.incbin "data/m2-credits-conversion-table.bin"
|
.incbin "data/m2-credits-conversion-table.bin"
|
||||||
|
|
||||||
|
.align 4
|
||||||
|
m2_cast_graphics:
|
||||||
|
.incbin "data/cast_roll_graphics_[c].bin"
|
||||||
|
|
||||||
|
.align 4
|
||||||
|
m2_cast_arrangements:
|
||||||
|
.incbin "data/cast_roll_arrangements_[c].bin"
|
||||||
|
|
||||||
.align 4
|
.align 4
|
||||||
m2_credits_font:
|
m2_credits_font:
|
||||||
.incbin "data/m2-credits-font_[c].bin"
|
.incbin "data/m2-credits-font_[c].bin"
|
||||||
|
|
|
@ -0,0 +1,171 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace GBA
|
||||||
|
{
|
||||||
|
class LZ77
|
||||||
|
{
|
||||||
|
public static int Decompress(byte[] data, int address, out byte[] output)
|
||||||
|
{
|
||||||
|
output = null;
|
||||||
|
int start = address;
|
||||||
|
|
||||||
|
if (data[address++] != 0x10) return -1; // Check for LZ77 signature
|
||||||
|
|
||||||
|
// Read the block length
|
||||||
|
int length = data[address++];
|
||||||
|
length += (data[address++] << 8);
|
||||||
|
length += (data[address++] << 16);
|
||||||
|
output = new byte[length];
|
||||||
|
|
||||||
|
int bPos = 0;
|
||||||
|
while (bPos < length)
|
||||||
|
{
|
||||||
|
byte ch = data[address++];
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
switch ((ch >> (7 - i)) & 1)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
|
||||||
|
// Direct copy
|
||||||
|
if (bPos >= length) break;
|
||||||
|
output[bPos++] = data[address++];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
|
||||||
|
// Compression magic
|
||||||
|
int t = (data[address++] << 8);
|
||||||
|
t += data[address++];
|
||||||
|
int n = ((t >> 12) & 0xF) + 3; // Number of bytes to copy
|
||||||
|
int o = (t & 0xFFF);
|
||||||
|
|
||||||
|
// Copy n bytes from bPos-o to the output
|
||||||
|
for (int j = 0; j < n; j++)
|
||||||
|
{
|
||||||
|
if (bPos >= length) break;
|
||||||
|
output[bPos] = output[bPos - o - 1];
|
||||||
|
bPos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return address - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] Compress(byte[] data)
|
||||||
|
{
|
||||||
|
return Compress(data, 0, data.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] Compress(byte[] data, int address, int length)
|
||||||
|
{
|
||||||
|
int start = address;
|
||||||
|
|
||||||
|
List<byte> obuf = new List<byte>();
|
||||||
|
List<byte> tbuf = new List<byte>();
|
||||||
|
int control = 0;
|
||||||
|
|
||||||
|
// Let's start by encoding the signature and the length
|
||||||
|
obuf.Add(0x10);
|
||||||
|
obuf.Add((byte)(length & 0xFF));
|
||||||
|
obuf.Add((byte)((length >> 8) & 0xFF));
|
||||||
|
obuf.Add((byte)((length >> 16) & 0xFF));
|
||||||
|
|
||||||
|
while ((address - start) < length)
|
||||||
|
{
|
||||||
|
tbuf.Clear();
|
||||||
|
control = 0;
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
// First byte should be raw
|
||||||
|
if (address == start)
|
||||||
|
{
|
||||||
|
tbuf.Add(data[address++]);
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
else if ((address - start) >= length)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// We're looking for the longest possible string
|
||||||
|
// The farthest possible distance from the current address is 0x1000
|
||||||
|
int max_length = -1;
|
||||||
|
int max_distance = -1;
|
||||||
|
|
||||||
|
for (int k = 1; k <= 0x1000; k++)
|
||||||
|
{
|
||||||
|
if ((address - k) < start) break;
|
||||||
|
|
||||||
|
int l = 0;
|
||||||
|
for (; l < 18; l++)
|
||||||
|
{
|
||||||
|
if (((address - start + l) >= length) ||
|
||||||
|
(data[address - k + l] != data[address + l]))
|
||||||
|
{
|
||||||
|
if (l > max_length)
|
||||||
|
{
|
||||||
|
max_length = l;
|
||||||
|
max_distance = k;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Corner case: we matched all 18 bytes. This is
|
||||||
|
// the maximum length, so don't bother continuing
|
||||||
|
if (l == 18)
|
||||||
|
{
|
||||||
|
max_length = 18;
|
||||||
|
max_distance = k;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max_length >= 3)
|
||||||
|
{
|
||||||
|
address += max_length;
|
||||||
|
|
||||||
|
// We hit a match, so add it to the output
|
||||||
|
int t = (max_distance - 1) & 0xFFF;
|
||||||
|
t |= (((max_length - 3) & 0xF) << 12);
|
||||||
|
tbuf.Add((byte)((t >> 8) & 0xFF));
|
||||||
|
tbuf.Add((byte)(t & 0xFF));
|
||||||
|
|
||||||
|
// Set the control bit
|
||||||
|
control |= (1 << (7 - i));
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
// If we didn't find any strings, copy the byte to the output
|
||||||
|
tbuf.Add(data[address++]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flush the temp buffer
|
||||||
|
obuf.Add((byte)(control & 0xFF));
|
||||||
|
obuf.AddRange(tbuf.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
return obuf.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,14 +39,14 @@ namespace RenderCastRoll
|
||||||
List<Render> renders = JsonConvert.DeserializeObject<RenderRoot>(rendersJson).Renders;
|
List<Render> renders = JsonConvert.DeserializeObject<RenderRoot>(rendersJson).Renders;
|
||||||
BitsToNybbleLookup = Asset.ReadAllBytes("bits_to_nybbles.bin");
|
BitsToNybbleLookup = Asset.ReadAllBytes("bits_to_nybbles.bin");
|
||||||
m12CharByteLookup = JsonConvert.DeserializeObject<Dictionary<string, byte>>(Asset.ReadAllText("m12-byte-lookup.json"));
|
m12CharByteLookup = JsonConvert.DeserializeObject<Dictionary<string, byte>>(Asset.ReadAllText("m12-byte-lookup.json"));
|
||||||
Graphics = new byte[0x6000];
|
Graphics = new byte[0x8000];
|
||||||
Arrangements = new ushort[0x4E80];
|
Arrangements = new ushort[0x48E0];
|
||||||
|
|
||||||
for (int i = 0; i < Arrangements.Length; i++)
|
for (int i = 0; i < Arrangements.Length; i++)
|
||||||
Arrangements[i] = 0x3FF; //Empty tile
|
Arrangements[i] = 0x3FF; //Empty tile
|
||||||
|
|
||||||
for (int i = 0; i < CastGraphics.Length; i++)
|
for (int i = 0; i < CastGraphics.Length; i++)
|
||||||
Graphics[0x6000 - CastGraphics.Length + i] = CastGraphics[i]; //Put the CAST graphics in
|
Graphics[0x8000 - CastGraphics.Length + i] = CastGraphics[i]; //Put the CAST graphics in
|
||||||
|
|
||||||
int castArrPos = readIntLE(CastArrangements, 0); //First 4 bytes are the position of the CAST arrangements
|
int castArrPos = readIntLE(CastArrangements, 0); //First 4 bytes are the position of the CAST arrangements
|
||||||
for (int i = 0; i < ((CastArrangements.Length - 4) >> 1); i++) //Put the CAST arrangements in
|
for (int i = 0; i < ((CastArrangements.Length - 4) >> 1); i++) //Put the CAST arrangements in
|
||||||
|
@ -83,18 +83,21 @@ namespace RenderCastRoll
|
||||||
//Convert the 1bpp tiles to 4bpp
|
//Convert the 1bpp tiles to 4bpp
|
||||||
for (int tile = 0; tile < UsedTiles; tile++)
|
for (int tile = 0; tile < UsedTiles; tile++)
|
||||||
{
|
{
|
||||||
int basePos = tile * 0x20;
|
int basePos = (tile * 0x20) + 0x2000;
|
||||||
_1bppTile pre_converted_tile = _1bppGraphics[tile];
|
_1bppTile pre_converted_tile = _1bppGraphics[tile];
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
int row = BitsToNybbleLookup[pre_converted_tile.getRow(i)];
|
int row = readIntLE(BitsToNybbleLookup, pre_converted_tile.getRow(i) * 4);
|
||||||
for (int j = 0; j < 4; j++)
|
for (int j = 0; j < 4; j++)
|
||||||
Graphics[basePos + (i * 4) + j] = (byte)((row >> (j * 8)) & 0xFF);
|
Graphics[basePos + (i * 4) + j] = (byte)((row >> (j * 8)) & 0xFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
File.WriteAllBytes(dataFolder + "cast_roll_graphics.bin", Graphics);
|
//File.WriteAllBytes(dataFolder + "cast_roll_graphics.bin", Graphics);
|
||||||
File.WriteAllBytes(dataFolder + "cast_roll_arrangement.bin", convertUShortArrToByteLE(Arrangements));
|
//File.WriteAllBytes(dataFolder + "cast_roll_arrangements.bin", convertUShortArrToByteLE(Arrangements));
|
||||||
|
|
||||||
|
File.WriteAllBytes(dataFolder + "cast_roll_graphics_[c].bin", GBA.LZ77.Compress(Graphics));
|
||||||
|
File.WriteAllBytes(dataFolder + "cast_roll_arrangements_[c].bin", GBA.LZ77.Compress(convertUShortArrToByteLE(Arrangements)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int readIntLE(byte[] arr, int pos)
|
static int readIntLE(byte[] arr, int pos)
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Asset.cs" />
|
<Compile Include="Asset.cs" />
|
||||||
|
<Compile Include="LZ77.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="RenderTools.cs" />
|
<Compile Include="RenderTools.cs" />
|
||||||
|
|
|
@ -45,13 +45,13 @@ namespace RenderCastRoll
|
||||||
|
|
||||||
public byte getRow(int i)
|
public byte getRow(int i)
|
||||||
{
|
{
|
||||||
return (byte)((tile >> i) & 0xFF);
|
return (byte)((tile >> (i * 8)) & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRow(int i, byte val)
|
public void setRow(int i, byte val)
|
||||||
{
|
{
|
||||||
UInt64 mask = ~((UInt64)(0xFF) << i);
|
UInt64 mask = ~((UInt64)(0xFF) << (i * 8));
|
||||||
tile = (tile & mask) | ((UInt64)val << i);
|
tile = (tile & mask) | ((UInt64)val << (i * 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public UInt64 getColumn(int i)
|
public UInt64 getColumn(int i)
|
||||||
|
|
Loading…
Reference in New Issue