[Scummvm-cvs-logs] CVS: scummvm main.cpp,1.13,1.14
Lionel Ulmer
bbrox at users.sourceforge.net
Fri May 3 11:37:11 CEST 2002
Update of /cvsroot/scummvm/scummvm
In directory usw-pr-cvs1:/tmp/cvs-serv28765
Modified Files:
main.cpp
Log Message:
Add a quick dynamic test to see if the memory options (endianness and
alignement) corresponds to what the CPU expects. This could help stop
bugs early on some platforms to almost no loss of start-up speed.
Index: main.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/main.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- main.cpp 1 May 2002 22:36:14 -0000 1.13
+++ main.cpp 3 May 2002 18:24:16 -0000 1.14
@@ -52,6 +52,45 @@
#define DEFAULT_CONFIG_FILE "scummvm.ini"
#endif
+#if defined(UNIX) || defined(UNIX_X11)
+#include <signal.h>
+
+static void handle_errors(int sig_num) {
+ error("Your system does not support unaligned memory accesses. Please rebuild with SCUMM_NEED_ALIGNMENT ");
+}
+
+/* This function is here to test if the endianness / alignement compiled it is matching
+ with the one at run-time. */
+static void do_memory_test(void) {
+ unsigned char test[8] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 };
+ unsigned int value;
+ /* First test endianness */
+#ifdef SCUMM_LITTLE_ENDIAN
+ if (*((int *) test) != 0x44332211) {
+ error("Compiled as LITTLE_ENDIAN on a big endian system. Please rebuild ");
+ }
+ value = 0x55443322;
+#else
+ if (*((int *) test) != 0x11223344) {
+ error("Compiled as BIG_ENDIAN on a little endian system. Please rebuild ");
+ }
+ value = 0x22334455;
+#endif
+ /* Then check if one really supports unaligned memory accesses */
+#ifndef SCUMM_NEED_ALIGNMENT
+ signal(SIGBUS, handle_errors);
+ signal(SIGABRT, handle_errors);
+ signal(SIGSEGV, handle_errors);
+ if (*((int *) ((char *) test + 1)) != value) {
+ error("Your system does not support unaligned memory accesses. Please rebuild with SCUMM_NEED_ALIGNMENT ");
+ }
+ signal(SIGBUS, SIG_DFL);
+ signal(SIGABRT, SIG_DFL);
+ signal(SIGSEGV, SIG_DFL);
+#endif
+}
+
+#endif
int main(int argc, char *argv[])
{
@@ -95,6 +134,9 @@
sprintf(scummhome,"%s/%s", getenv("HOME"), DEFAULT_CONFIG_FILE);
else strcpy(scummhome,DEFAULT_CONFIG_FILE);
scummcfg = new Config(scummhome, "scummvm");
+
+ /* On Unix, do a quick endian / alignement check before starting */
+ do_memory_test();
#else
scummcfg = new Config(DEFAULT_CONFIG_FILE, "scummvm");
#endif
More information about the Scummvm-git-logs
mailing list