-added missing lowmem setup for channels booted without apploader

-cleaned up channel boot
This commit is contained in:
fix94.1 2013-01-05 20:06:29 +00:00
parent 47fe516390
commit e44ec9cda1
6 changed files with 249 additions and 268 deletions

View File

@ -72,6 +72,22 @@ void Disc_SetLowMem(u32 IOS)
DCFlushRange((void*)0x80000000, 0x3f00);
}
/* Thanks to triiforce for that code */
void Disc_SetLowMemChan()
{
/* Setup low mem */
*Arena_H = 0x00000000; // Arena High, the appldr does this too
*BI2 = 0x817FE000; // BI2, the appldr does this too
*GameID_Address = 0x81000000; // Game id address, 0s at 0x81000000 with appldr
/* Flush low mem */
DCFlushRange((void*)0x80000000, 0x3f00);
/* Clear BI2 */
memset((void *)0x817FE000, 0, 0x2000);
DCFlushRange((void*)0x817FE000, 0x2000);
}
/* Thanks Tinyload */
static struct {
u32 offset;

View File

@ -11,6 +11,7 @@ s32 Disc_FindPartition(u32 *outbuf);
s32 Disc_SetUSB(const u8 *id, bool frag);
void Disc_SetLowMemPre();
void Disc_SetLowMem(u32 IOS);
void Disc_SetLowMemChan();
void Disc_SetTime();
GXRModeObj *Disc_SelectVMode(u8 videoselected, u32 *rmode_reg);

View File

@ -13,102 +13,83 @@
*
******************************************************************************/
#include <gccore.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include "lz77.h"
#include "utils.h"
u32 packBytes(int a, int b, int c, int d)
static inline u32 packBytes(int a, int b, int c, int d)
{
return (d << 24) | (c << 16) | (b << 8) | (a);
}
s32 __decompressLZ77_11(u8 *in, u32 inputLen, u8 **output, u32 *outputLen)
static int __decompressLZ77_11(u8 *in, u32 inputLen, u8 **output, u32 *outputLen)
{
int x, y;
u8 *out = NULL;
int x = 0;
u32 y = 0;
u32 compressedPos = 0x4;
u32 decompressedPos = 0x0;
u32 decompressedSize = 0;
decompressedSize = packBytes(in[0], in[1], in[2], in[3]) >> 8;
if (!decompressedSize)
u32 decompressedPos = 0;
u32 decompressedSize = packBytes(in[0], in[1], in[2], in[3]) >> 8;
if(decompressedSize == 0)
{
decompressedSize = packBytes(in[4], in[5], in[6], in[7]);
compressedPos += 0x4;
}
//printf("Decompressed size : %i\n", decompressedSize);
out = malloc(ALIGN32(decompressedSize));
if (out == NULL)
u8 *out = (u8*)malloc(decompressedSize);
if(out == NULL)
{
printf("Out of memory\n");
//printf("Out of memory\n");
return -1;
}
while (compressedPos < inputLen && decompressedPos < decompressedSize)
while(compressedPos < inputLen && decompressedPos < decompressedSize)
{
u8 byteFlag = in[compressedPos];
compressedPos++;
for (x = 7; x >= 0; x--)
for(x = 7; x >= 0; x--)
{
if ((byteFlag & (1 << x)) > 0)
if((byteFlag & (1 << x)) > 0)
{
u8 first = in[compressedPos];
u8 second = in[compressedPos + 1];
u32 pos, copyLen;
if (first < 0x20)
if(first < 0x20)
{
u8 third = in[compressedPos + 2];
if (first >= 0x10)
if(first >= 0x10)
{
u32 fourth = in[compressedPos + 3];
pos = (u32)(((third & 0xF) << 8) | fourth) + 1;
copyLen = (u32)((second << 4) | ((first & 0xF) << 12) | (third >> 4)) + 273;
compressedPos += 4;
} else
}
else
{
pos = (u32)(((second & 0xF) << 8) | third) + 1;
copyLen = (u32)(((first & 0xF) << 4) | (second >> 4)) + 17;
compressedPos += 3;
}
} else
}
else
{
pos = (u32)(((first & 0xF) << 8) | second) + 1;
copyLen = (u32)(first >> 4) + 1;
compressedPos += 2;
}
for (y = 0; y < (int)copyLen; y++)
{
for(y = 0; y < copyLen; y++)
out[decompressedPos + y] = out[decompressedPos - pos + y];
}
decompressedPos += copyLen;
} else
}
else
{
out[decompressedPos] = in[compressedPos];
decompressedPos++;
compressedPos++;
}
if (compressedPos >= inputLen || decompressedPos >= decompressedSize)
if(compressedPos >= inputLen || decompressedPos >= decompressedSize)
break;
}
}
@ -117,67 +98,51 @@ s32 __decompressLZ77_11(u8 *in, u32 inputLen, u8 **output, u32 *outputLen)
return 0;
}
s32 __decompressLZ77_10(u8 *in, u8 **output, u32 *outputLen)
static int __decompressLZ77_10(u8 *in, u8 **output, u32 *outputLen)
{
int x, y;
u8 *out = NULL;
u32 compressedPos = 0;
u32 decompressedSize = 0x4;
int x = 0;
u32 y = 0;
u32 compressedPos = 0x4;
u32 decompressedPos = 0;
decompressedSize = packBytes(in[0], in[1], in[2], in[3]) >> 8;
//int compressionType = (packBytes(in[0], in[1], in[2], in[3]) >> 4) & 0xF;
u32 decompressedSize = packBytes(in[0], in[1], in[2], in[3]) >> 8;
//printf("Decompressed size : %i\n", decompressedSize);
out = malloc(ALIGN32(decompressedSize));
if (out == NULL)
u8 *out = (u8*)malloc(decompressedSize);
if(out == NULL)
{
printf("Out of memory\n");
//printf("Out of memory\n");
return -1;
}
compressedPos += 0x4;
while (decompressedPos < decompressedSize)
while(decompressedPos < decompressedSize)
{
u8 flag = *(u8*)(in + compressedPos);
compressedPos += 1;
u8 byteFlag = in[compressedPos];
compressedPos ++;
for (x = 0; x < 8; x++)
for(x = 0; x < 8; ++x)
{
if (flag & 0x80)
if(byteFlag & 0x80)
{
u8 first = in[compressedPos];
u8 second = in[compressedPos + 1];
u16 pos = (u16)((((first << 8) + second) & 0xFFF) + 1);
u8 copyLen = (u8)(3 + ((first >> 4) & 0xF));
for (y = 0; y < copyLen; y++)
{
for(y = 0; y < copyLen; y++)
out[decompressedPos + y] = out[decompressedPos - pos + (y % pos)];
}
compressedPos += 2;
decompressedPos += copyLen;
} else
}
else
{
out[decompressedPos] = in[compressedPos];
compressedPos += 1;
decompressedPos += 1;
}
flag <<= 1;
if (decompressedPos >= decompressedSize)
byteFlag <<= 1;
if(decompressedPos >= decompressedSize)
break;
}
}
*output = out;
*outputLen = decompressedSize;
return 0;
@ -185,18 +150,15 @@ s32 __decompressLZ77_10(u8 *in, u8 **output, u32 *outputLen)
int isLZ77compressed(u8 *buffer)
{
if ((buffer[0] == LZ77_0x10_FLAG) || (buffer[0] == LZ77_0x11_FLAG))
{
if((buffer[0] == LZ77_0x10_FLAG) || (buffer[0] == LZ77_0x11_FLAG))
return 1;
}
return 0;
}
int decompressLZ77content(u8 *buffer, u32 length, u8 **output, u32 *outputLen)
{
int ret;
switch (buffer[0])
int ret = 0;
switch(buffer[0])
{
case LZ77_0x10_FLAG:
//printf("LZ77 variant 0x10 compressed content...unpacking may take a while...\n");

View File

@ -121,6 +121,8 @@ int main()
/* Setup Low Memory */
Disc_SetLowMem(GameIOS);
if(normalCFG.BootType == TYPE_CHANNEL && AppEntrypoint != 0x3400)
Disc_SetLowMemChan(); /* Real DOL without appldr */
/* Set time */
Disc_SetTime();