uint8_t * ReadFile(const char * filename, uint32_t * size)
{
- FILE * fp = fopen(filename, "r");
+ FILE * fp = fopen(filename, "rb");
if (!fp)
return NULL;
bool LoadA2R(const char * filename)
{
-/*
-Really, this crap should go into fileio.cpp. !!! FIX !!!
-*/
- static uint8_t a2rHdr[8] = { 0x41, 0x32, 0x52, 0x32, 0xFF, 0x0A, 0x0D, 0x0A };
- static uint8_t a2rHdr1[8] = { 0x41, 0x32, 0x52, 0x31, 0xFF, 0x0A, 0x0D, 0x0A };
+ static uint8_t a2rHdr1[] = "A2R1\xFF\x0A\x0D\x0A";
+ static uint8_t a2rHdr[] = "A2R2\xFF\x0A\x0D\x0A";
if (Global::a2r != NULL)
free(Global::a2r);
if (Global::a2rSize > (60 + Uint32LE(Global::a2r->strmSize)))
{
- Global::metadata = (A2RMetadata *)((uint8_t *)Global::a2r + (60 + Uint32LE(Global::a2r->strmSize)));
+ Global::metadata = (Metadata *)((uint8_t *)Global::a2r + (60 + Uint32LE(Global::a2r->strmSize)));
// Make sure it's plausible metadata
if (memcmp(Global::metadata->metaTag, "META", 4) != 0)
Global::metadata = NULL;
+ else
+ UnpackMetadata(Global::metadata);
}
// Unpack TMNG & XTMG streams to simplify analysis
return true;
}
+
+void UnpackMetadata(Metadata * data)
+{
+ uint32_t start = 0;
+ uint32_t end = Uint32LE(data->metaSize);
+ uint32_t i = 0;
+ Global::metaCount = 0;
+
+ while (start < end)
+ {
+ if (i < 255)
+ Global::meta[Global::metaCount][i++] = data->data[start];
+
+ start++;
+
+ if (data->data[start] == '\x0A')
+ {
+ Global::meta[Global::metaCount][i] = 0;
+ Global::metaCount++;
+ i = 0;
+ start++;
+ }
+ }
+}
+
+
+uint8_t * GetMetadata(const char * keyword)
+{
+ uint32_t kwLen = strlen(keyword);
+
+ for(uint8_t i=0; i<Global::metaCount; i++)
+ {
+ if ((strlen((char *)Global::meta[i]) >= kwLen)
+ && (memcmp(Global::meta[i], keyword, kwLen) == 0)
+ && (Global::meta[i][kwLen] == 0x09))
+ {
+ return &Global::meta[i][kwLen + 1];
+ }
+ }
+
+ return NULL;
+}
+
+
+uint16_t GetRequiredMachineBits(void)
+{
+ uint8_t * kw = GetMetadata("requires_machine");
+ uint32_t kwLen = strlen((char *)kw);
+ uint16_t bits = 0;
+ char type[8];
+ uint8_t typeLen = 0;
+
+ for(uint32_t i=0; i<kwLen; i++)
+ {
+ type[typeLen++] = kw[i];
+
+ if ((kw[i + 1] == '|') || (kw[i + 1] == '\0'))
+ {
+ type[typeLen] = 0;
+
+ if (strcmp(type, "2") == 0)
+ bits |= 0x001;
+ else if (strcmp(type, "2+") == 0)
+ bits |= 0x002;
+ else if (strcmp(type, "2e") == 0)
+ bits |= 0x004;
+ else if (strcmp(type, "2c") == 0)
+ bits |= 0x008;
+ else if (strcmp(type, "2e+") == 0)
+ bits |= 0x010;
+ else if (strcmp(type, "2gs") == 0)
+ bits |= 0x020;
+ else if (strcmp(type, "2c+") == 0)
+ bits |= 0x040;
+ else if (strcmp(type, "3") == 0)
+ bits |= 0x080;
+ else if (strcmp(type, "3+") == 0)
+ bits |= 0x100;
+
+ typeLen = 0;
+ i++;
+ }
+ }
+
+ return bits;
+}
+
+
+uint16_t GetRequiredRAMInK(void)
+{
+ uint16_t ram[13] = { 16, 24, 32, 48, 64, 128, 256, 512, 768, 1024, 1280, 1536, 0 };
+ return ram[GetRequiredRAMIndex()];
+}
+
+
+uint16_t GetRequiredRAMIndex(void)
+{
+ char * kw = (char *)GetMetadata("requires_ram");
+
+ if (strcmp(kw, "16K") == 0)
+ return 0;
+ else if (strcmp(kw, "24K") == 0)
+ return 1;
+ else if (strcmp(kw, "32K") == 0)
+ return 2;
+ else if (strcmp(kw, "48K") == 0)
+ return 3;
+ else if (strcmp(kw, "64K") == 0)
+ return 4;
+ else if (strcmp(kw, "128K") == 0)
+ return 5;
+ else if (strcmp(kw, "256K") == 0)
+ return 6;
+ else if (strcmp(kw, "512K") == 0)
+ return 7;
+ else if (strcmp(kw, "768K") == 0)
+ return 8;
+ else if (strcmp(kw, "1M") == 0)
+ return 9;
+ else if (strcmp(kw, "1.25M") == 0)
+ return 10;
+ else if (strcmp(kw, "1.5M+") == 0)
+ return 11;
+
+ return 12;
+}
+/*
+METADATA Keywords (standard)
+----------------------------
+title, subtitle, publisher, developer, copyright, version, language, requires_ram, requires_machine, notes, side, side_name, contributor, image_date
+
+ram: 16K|24K|32K|48K|64K|128K|256K|512K|768K|1M|1.25M|1.5M+|Unknown
+mch: 2|2+|2e|2c|2e+|2gs|2c+|3|3+
+*/
+