diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/glk/alan3/main.cpp | 35 | ||||
-rw-r--r-- | engines/glk/alan3/reverse.cpp | 2 | ||||
-rw-r--r-- | engines/glk/alan3/reverse.h | 1 | ||||
-rw-r--r-- | engines/glk/alan3/sysdep.cpp | 7 | ||||
-rw-r--r-- | engines/glk/alan3/sysdep.h | 2 |
5 files changed, 17 insertions, 30 deletions
diff --git a/engines/glk/alan3/main.cpp b/engines/glk/alan3/main.cpp index f09a54c6be..52c14761e6 100644 --- a/engines/glk/alan3/main.cpp +++ b/engines/glk/alan3/main.cpp @@ -134,27 +134,19 @@ static int crcStart(const byte version[4]) { /*----------------------------------------------------------------------*/ static void readTemporaryHeader(ACodeHeader *tmphdr) { codfil->seek(0); - codfil->read(&tmphdr->tag[0], 4); - - Aword *ptr = (Aword *)tmphdr + 1; - uint i; - for (i = 1; i < sizeof(ACodeHeader) / sizeof(Aword); ++i, ++ptr) - *ptr = codfil->readUint32BE(); - - if (strncmp((char *)tmphdr, "ALAN", 4) != 0) + if (codfil->read(&tmphdr->tag[0], sizeof(ACodeHeader)) != sizeof(ACodeHeader) || + strncmp((char *)tmphdr, "ALAN", 4) != 0) playererr("Not an Alan game file, does not start with \"ALAN\""); } /*----------------------------------------------------------------------*/ static void reverseMemory() { - if (littleEndian()) { - if (debugOption || traceSectionOption || traceInstructionOption) - output("<Hmm, this is a little-endian machine, fixing byte ordering...."); - reverseACD(); /* Reverse content of the ACD file */ - if (debugOption || traceSectionOption || traceInstructionOption) - output("OK.>$n"); - } + if (debugOption || traceSectionOption || traceInstructionOption) + output("<Hmm, this is a little-endian machine, fixing byte ordering...."); + reverseACD(); /* Reverse content of the ACD file */ + if (debugOption || traceSectionOption || traceInstructionOption) + output("OK.>$n"); } @@ -183,12 +175,10 @@ static void loadAndCheckMemory(ACodeHeader tmphdr, Aword crc, char err[]) { } memTop = tmphdr.size; - if ((int)(sizeof(Aword) * tmphdr.size) > codfil->size()) + codfil->seek(0); + if (codfil->read(memory, sizeof(Aword) * memTop) != (sizeof(Aword) * memTop)) syserr("Could not read all ACD code."); - for (i = 0; i < (int)tmphdr.size; ++i) - memory[i] = codfil->readUint32LE(); - /* Calculate checksum */ for (i = crcStart(tmphdr.version); i < memTop; i++) { crc += memory[i] & 0xff; @@ -368,14 +358,19 @@ static void load(void) { checkVersion(&tmphdr); /* Allocate and load memory */ +#ifdef SCUMM_LITTLE_ENDIAN + reverseHdr(&tmphdr); +#endif + if (tmphdr.size <= sizeof(ACodeHeader) / sizeof(Aword)) syserr("Malformed game file. Too small."); loadAndCheckMemory(tmphdr, crc, err); +#ifdef SCUMM_LITTLE_ENDIAN reverseMemory(); +#endif setupHeader(tmphdr); - } diff --git a/engines/glk/alan3/reverse.cpp b/engines/glk/alan3/reverse.cpp index 4dcba1258a..ead87251ea 100644 --- a/engines/glk/alan3/reverse.cpp +++ b/engines/glk/alan3/reverse.cpp @@ -573,7 +573,7 @@ static void reversePreBeta2() { /*======================================================================*/ -static void reverseHdr(ACodeHeader *hdr) { +void reverseHdr(ACodeHeader *hdr) { uint i; /* Reverse all words in the header except the tag and the version marking */ diff --git a/engines/glk/alan3/reverse.h b/engines/glk/alan3/reverse.h index cca38c0c27..ebcc0f5f8f 100644 --- a/engines/glk/alan3/reverse.h +++ b/engines/glk/alan3/reverse.h @@ -32,6 +32,7 @@ namespace Alan3 { /* Functions: */ +extern void reverseHdr(ACodeHeader *hdr); extern void reverseACD(void); extern void reverse(Aword *word); extern Aword reversed(Aword word); diff --git a/engines/glk/alan3/sysdep.cpp b/engines/glk/alan3/sysdep.cpp index 58f0fa0098..ae8625f2f0 100644 --- a/engines/glk/alan3/sysdep.cpp +++ b/engines/glk/alan3/sysdep.cpp @@ -313,13 +313,6 @@ void toNative(char copy[], char original[], int charset) { /*======================================================================*/ -int littleEndian() { - int x = 1; - return (*(char *)&x == 1); -} - - -/*======================================================================*/ char *baseNameStart(char *fullPathName) { const char *delimiters = "\\>]/:"; int i; diff --git a/engines/glk/alan3/sysdep.h b/engines/glk/alan3/sysdep.h index 87b95fc03d..1889a3ea00 100644 --- a/engines/glk/alan3/sysdep.h +++ b/engines/glk/alan3/sysdep.h @@ -130,8 +130,6 @@ extern void toNative(char copy[], /* OUT - Mapped string */ char original[], /* IN - string to convert */ int charset); /* IN - current character set */ -extern int littleEndian(void); - extern char *baseNameStart(char *fullPathName); } // End of namespace Alan3 |