From de29b11a88dbdd3af0824e59b51528b91ee73c54 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Thu, 30 Nov 2017 22:49:38 +0100 Subject: First commit. Version works on Linux (keyboard only, not configurable) --- src/qda.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/qda.c (limited to 'src/qda.c') diff --git a/src/qda.c b/src/qda.c new file mode 100644 index 0000000..663fa00 --- /dev/null +++ b/src/qda.c @@ -0,0 +1,62 @@ +#include "qda.h" +#include +#include +#include + +//Load headers for each image +//Returns: 0 = file not found | 1 = success | 2 = Invalid file +int initQDA() +{ + int result = 0; + FILE* f; + + char fullPath[80]; + #ifdef _SDL + strcpy(fullPath, "data/"); + #else + strcpy(fullPath, ""); + #endif + #ifdef _3DS + strcat(fullPath, "romfs:/"); + #endif + strcat(fullPath, "bmp.qda"); + + if ( (f = fopen(fullPath, "rb")) ) { + result = 1; + + //Read header data into memory + int allHeadersSize = 0x1F5C; + unsigned char* QDAFile = (unsigned char*)malloc(allHeadersSize); + fread(QDAFile, allHeadersSize, 1, f); + + //Check if QDA file is valid + { + if (QDAFile[4] == 0x51 && QDAFile[5] == 0x44 && QDAFile[6] == 0x41 && QDAFile[7] == 0x30) { + //Load headers separately + { + int numofsheets = 29; + int headerSize = 0x10C; + + int i; + for (i = 0; i < numofsheets; i++) { + //memcpy(&headers[i], &QDAFile[0x100 + (i * headerSize)], sizeof(QDAHeader)); + int offset = 256 + (i * headerSize); + memcpy(&headers[i].offset, &QDAFile[offset], 4); + memcpy(&headers[i].size, &QDAFile[offset + 4], 4); + memcpy(&headers[i].bytes, &QDAFile[offset + 8], 4); + memcpy(&headers[i].fileName, &QDAFile[offset + 12], 0x100); + } + } + }else{ + result = 2; + } + } + + //Cleanup + free(QDAFile); + } + + fclose(f); + + return result; +} \ No newline at end of file -- cgit v1.2.3