summaryrefslogtreecommitdiff
path: root/src/fileload.cpp
diff options
context:
space:
mode:
authorColin Noga <Tempus@Spectrum-Song.local>2011-07-23 11:47:43 -0500
committerColin Noga <Tempus@Spectrum-Song.local>2011-07-23 11:47:43 -0500
commit09d075c5469f64f500de70123bbb1042315d7ac0 (patch)
treeee92906230c7fa01e89afb84beeb65b8855393ad /src/fileload.cpp
parentffa9dabc6b535da90b3cd8a7849079c546cacfbd (diff)
downloadkamek-09d075c5469f64f500de70123bbb1042315d7ac0.tar.gz
kamek-09d075c5469f64f500de70123bbb1042315d7ac0.zip
Added Crowd clapper. Changed everything to LF only. If anyone on Windows tries to read the code now, they will be faced with a single impenetrable line!
Diffstat (limited to '')
-rw-r--r--src/fileload.cpp268
1 files changed, 134 insertions, 134 deletions
diff --git a/src/fileload.cpp b/src/fileload.cpp
index 5f60e8c..fac7576 100644
--- a/src/fileload.cpp
+++ b/src/fileload.cpp
@@ -1,134 +1,134 @@
-#include "fileload.h"
-
-extern "C" void UncompressBackward(void *bottom);
-
-
-void *LoadFile(FileHandle *handle, const char *name) {
- OSReport("[LoadFile %s]\n", name);
-
- int entryNum = DVDConvertPathToEntrynum(name);
-
- DVDHandle dvdhandle;
- if (!DVDFastOpen(entryNum, &dvdhandle)) {
- OSReport("Cannot open file %s [%d]\n", name, entryNum);
- return 0;
- }
-
- handle->length = dvdhandle.length;
- handle->filePtr = EGG__Heap__alloc((handle->length+0x1F) & ~0x1F, 0x20, GetArchiveHeap());
-
- int ret = DVDReadPrio(&dvdhandle, handle->filePtr, (handle->length+0x1F) & ~0x1F, 0, 2);
-
- DVDClose(&dvdhandle);
-
- OSReport("[Success %p]\n", handle->filePtr);
-
- return handle->filePtr;
-}
-
-void *LoadCompressedFile(FileHandle *handle, const char *name) {
- OSReport("[LoadCompressedFile %s]\n", name);
-
- int entryNum = DVDConvertPathToEntrynum(name);
-
- DVDHandle dvdhandle;
- if (!DVDFastOpen(entryNum, &dvdhandle)) {
- OSReport("Cannot open file %s [%d]\n", name, entryNum);
- return 0;
- }
-
- u32 infoBlock[0x20 / sizeof(u32)] __attribute__ ((aligned(32)));
- DVDReadPrio(&dvdhandle, infoBlock, 0x20, dvdhandle.length - 8, 2);
-
- // Reverse it!
- infoBlock[1] = (infoBlock[1] >> 24) | ((infoBlock[1] >> 8) & 0xFF00) | ((infoBlock[1] & 0xFF00) << 8) | ((infoBlock[1] & 0xFF) << 24);
-
- u32 uncompSize = dvdhandle.length + infoBlock[1];
- OSReport("[Comp:%d UnComp:%d]\n", dvdhandle.length, uncompSize);
- handle->length = uncompSize;
- handle->filePtr = EGG__Heap__alloc((uncompSize+0x1F) & ~0x1F, 0x20, GetArchiveHeap());
-
- int ret = DVDReadPrio(&dvdhandle, handle->filePtr, (dvdhandle.length+0x1F) & ~0x1F, 0, 2);
-
- DVDClose(&dvdhandle);
-
- UncompressBackward((void*)((u32)handle->filePtr + dvdhandle.length));
-
- OSReport("[Success %p]\n", handle->filePtr);
-
- return handle->filePtr;
-}
-
-bool FreeFile(FileHandle *handle) {
- if (!handle) return false;
-
- if (handle->filePtr) {
- OSReport("[FreeFile %p]\n", handle->filePtr);
- EGG__Heap__free(handle->filePtr, GetArchiveHeap());
- }
-
- handle->filePtr = 0;
- handle->length = 0;
-
- return true;
-}
-
-
-
-
-File::File() {
- m_loaded = false;
-}
-
-File::~File() {
- close();
-}
-
-bool File::open(const char *filename) {
- if (m_loaded)
- close();
-
- void *ret = LoadFile(&m_handle, filename);
- if (ret != 0)
- m_loaded = true;
-
- return (ret != 0);
-}
-
-bool File::openCompressed(const char *filename) {
- if (m_loaded)
- close();
-
- void *ret = LoadCompressedFile(&m_handle, filename);
- if (ret != 0)
- m_loaded = true;
-
- return (ret != 0);
-}
-
-void File::close() {
- if (!m_loaded)
- return;
-
- m_loaded = false;
- FreeFile(&m_handle);
-}
-
-bool File::isOpen() {
- return m_loaded;
-}
-
-void *File::ptr() {
- if (m_loaded)
- return m_handle.filePtr;
- else
- return 0;
-}
-
-u32 File::length() {
- if (m_loaded)
- return m_handle.length;
- else
- return 0xFFFFFFFF;
-}
-
+#include "fileload.h"
+
+extern "C" void UncompressBackward(void *bottom);
+
+
+void *LoadFile(FileHandle *handle, const char *name) {
+ OSReport("[LoadFile %s]\n", name);
+
+ int entryNum = DVDConvertPathToEntrynum(name);
+
+ DVDHandle dvdhandle;
+ if (!DVDFastOpen(entryNum, &dvdhandle)) {
+ OSReport("Cannot open file %s [%d]\n", name, entryNum);
+ return 0;
+ }
+
+ handle->length = dvdhandle.length;
+ handle->filePtr = EGG__Heap__alloc((handle->length+0x1F) & ~0x1F, 0x20, GetArchiveHeap());
+
+ int ret = DVDReadPrio(&dvdhandle, handle->filePtr, (handle->length+0x1F) & ~0x1F, 0, 2);
+
+ DVDClose(&dvdhandle);
+
+ OSReport("[Success %p]\n", handle->filePtr);
+
+ return handle->filePtr;
+}
+
+void *LoadCompressedFile(FileHandle *handle, const char *name) {
+ OSReport("[LoadCompressedFile %s]\n", name);
+
+ int entryNum = DVDConvertPathToEntrynum(name);
+
+ DVDHandle dvdhandle;
+ if (!DVDFastOpen(entryNum, &dvdhandle)) {
+ OSReport("Cannot open file %s [%d]\n", name, entryNum);
+ return 0;
+ }
+
+ u32 infoBlock[0x20 / sizeof(u32)] __attribute__ ((aligned(32)));
+ DVDReadPrio(&dvdhandle, infoBlock, 0x20, dvdhandle.length - 8, 2);
+
+ // Reverse it!
+ infoBlock[1] = (infoBlock[1] >> 24) | ((infoBlock[1] >> 8) & 0xFF00) | ((infoBlock[1] & 0xFF00) << 8) | ((infoBlock[1] & 0xFF) << 24);
+
+ u32 uncompSize = dvdhandle.length + infoBlock[1];
+ OSReport("[Comp:%d UnComp:%d]\n", dvdhandle.length, uncompSize);
+ handle->length = uncompSize;
+ handle->filePtr = EGG__Heap__alloc((uncompSize+0x1F) & ~0x1F, 0x20, GetArchiveHeap());
+
+ int ret = DVDReadPrio(&dvdhandle, handle->filePtr, (dvdhandle.length+0x1F) & ~0x1F, 0, 2);
+
+ DVDClose(&dvdhandle);
+
+ UncompressBackward((void*)((u32)handle->filePtr + dvdhandle.length));
+
+ OSReport("[Success %p]\n", handle->filePtr);
+
+ return handle->filePtr;
+}
+
+bool FreeFile(FileHandle *handle) {
+ if (!handle) return false;
+
+ if (handle->filePtr) {
+ OSReport("[FreeFile %p]\n", handle->filePtr);
+ EGG__Heap__free(handle->filePtr, GetArchiveHeap());
+ }
+
+ handle->filePtr = 0;
+ handle->length = 0;
+
+ return true;
+}
+
+
+
+
+File::File() {
+ m_loaded = false;
+}
+
+File::~File() {
+ close();
+}
+
+bool File::open(const char *filename) {
+ if (m_loaded)
+ close();
+
+ void *ret = LoadFile(&m_handle, filename);
+ if (ret != 0)
+ m_loaded = true;
+
+ return (ret != 0);
+}
+
+bool File::openCompressed(const char *filename) {
+ if (m_loaded)
+ close();
+
+ void *ret = LoadCompressedFile(&m_handle, filename);
+ if (ret != 0)
+ m_loaded = true;
+
+ return (ret != 0);
+}
+
+void File::close() {
+ if (!m_loaded)
+ return;
+
+ m_loaded = false;
+ FreeFile(&m_handle);
+}
+
+bool File::isOpen() {
+ return m_loaded;
+}
+
+void *File::ptr() {
+ if (m_loaded)
+ return m_handle.filePtr;
+ else
+ return 0;
+}
+
+u32 File::length() {
+ if (m_loaded)
+ return m_handle.length;
+ else
+ return 0xFFFFFFFF;
+}
+