/*---------------------------------------------------------------------------* Project: Horizon File: main.cpp Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 46365 $ *---------------------------------------------------------------------------*/ #include #include #include void nnMain() { // With this flag, the API used for expansion is switched // false : UncompressBLZ() ......... Although the error check is insufficient, it is faster than the Secure version // true : SecureUncompressBLZ() ... Error check is performed, but is slower than the non-Secure version const bool uncompressWithErrorCheck = false; NN_LOG("UncompressBlz demo\n"); // Call only nn::applet::Enable to also allow execution from the HOME Menu // HOME Menu transitions, POWER Button presses, and sleep are all unsupported nn::applet::Enable(); // Initialize fs, mount ROM nn::fs::Initialize(); const size_t ROMFS_BUFFER_SIZE = 1024 * 64; static char buffer[ROMFS_BUFFER_SIZE]; NN_UTIL_PANIC_IF_FAILED(nn::fs::MountRom(16, 16, buffer, ROMFS_BUFFER_SIZE)); // Load compressed file, and get the data size after expansion u8 archive[4096]; nn::fs::FileReader reader; reader.Initialize("rom:/archive.bin"); u32 inSize = reader.GetSize(); reader.Read(archive, inSize); // The data size after decompression is "size of compressed file" + "value written to the last 4 bytes of the compressed file" // u32 outSize; reader.Seek(-4, nn::fs::POSITION_BASE_END); reader.Read(&outSize, 4); outSize += inSize; reader.Finalize(); // Confirm if the buffer length is insufficient if (outSize > sizeof(archive)) { NN_PANIC("ERROR: buffer is not large enough\n"); } // BLZ decompression // The expanded data is overwritten to the input buffer if (uncompressWithErrorCheck) { s32 ret = nn::cx::SecureUncompressBLZ(archive, inSize, sizeof(archive)); // Confirm if an error occur during expansion if (ret != 0) { NN_PANIC("ERROR: decode error has occurred\n"); } } else { nn::cx::UncompressBLZ(archive, inSize, sizeof(archive)); } // Comparison to original data u8 data[4096]; reader.Initialize("rom:/data.bin"); // Confirm if this matches the expansion size obtained from the compressed file if (outSize != reader.GetSize()) { NN_PANIC("ERROR: original data size != uncompressed data size\n"); } reader.Read(data, outSize); reader.Finalize(); for (int i = 0; i < outSize; i++) { if (archive[i] != data[i]) { NN_PANIC("ERROR: original data != uncompressed data\n"); } } NN_LOG("UncompressBlz demo finished\n"); } /*---------------------------------------------------------------------------* End of file *---------------------------------------------------------------------------*/