|
csosdefs.h00001 #ifndef __NeXT_csosdefs_h 00002 #define __NeXT_csosdefs_h 00003 //============================================================================= 00004 // 00005 // Copyright (C)1999-2002 by Eric Sunshine <sunshine@sunshineco.com> 00006 // 00007 // The contents of this file are copyrighted by Eric Sunshine. This work is 00008 // distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 00009 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 00010 // PARTICULAR PURPOSE. You may distribute this file provided that this 00011 // copyright notice is retained. Send comments to <sunshine@sunshineco.com>. 00012 // 00013 //============================================================================= 00014 //----------------------------------------------------------------------------- 00015 // csosdefs.h 00016 // 00017 // Platform-specific interface to common functionality. Compatible 00018 // with MacOS/X, MacOS/X Server 1.0 (Rhapsody), OpenStep, and NextStep. 00019 // 00020 //----------------------------------------------------------------------------- 00021 00022 //----------------------------------------------------------------------------- 00023 // Define the appropriate PROC_ flag for the current architecture for MacOS/X 00024 // Server, OpenStep, and NextStep multi-architecture binary (MAB) compilations. 00025 // It is necessary to perform this step here since this information is not 00026 // known at makefile configuration time or even at the time when the compiler 00027 // is invoked on account of the ability to build multi-architecture binaries 00028 // with a single invocation of the compiler. Therefore, this is the first 00029 // chance we have of actually determining the proper PROC_ flag. Also set 00030 // CS_PROCESSOR_NAME to an appropriate value. 00031 //----------------------------------------------------------------------------- 00032 #if defined(__m68k__) 00033 # if !defined(PROC_M68K) 00034 # define PROC_M68K 00035 # undef CS_PROCESSOR_NAME 00036 # define CS_PROCESSOR_NAME "M68K" 00037 # endif 00038 #elif defined(__i386__) 00039 # if !defined(PROC_X86) 00040 # define PROC_X86 00041 # undef CS_PROCESSOR_NAME 00042 # define CS_PROCESSOR_NAME "X86" 00043 # endif 00044 #elif defined(__sparc__) 00045 # if !defined(PROC_SPARC) 00046 # define PROC_SPARC 00047 # undef CS_PROCESSOR_NAME 00048 # define CS_PROCESSOR_NAME "Sparc" 00049 # endif 00050 #elif defined(__hppa__) 00051 # if !defined(PROC_HPPA) 00052 # define PROC_HPPA 00053 # undef CS_PROCESSOR_NAME 00054 # define CS_PROCESSOR_NAME "PA-RISC" 00055 # endif 00056 #elif defined(__ppc__) 00057 # if !defined(PROC_POWERPC) 00058 # define PROC_POWERPC 00059 # undef CS_PROCESSOR_NAME 00060 # define CS_PROCESSOR_NAME "PowerPC" 00061 # endif 00062 #else 00063 # if !defined(PROC_UNKNOWN) 00064 # define PROC_UNKNOWN 00065 # undef CS_PROCESSOR_NAME 00066 # define CS_PROCESSOR_NAME "Unknown" 00067 # endif 00068 #endif 00069 00070 00071 //----------------------------------------------------------------------------- 00072 // The 2D graphics driver used by the software renderer on this platform. 00073 //----------------------------------------------------------------------------- 00074 #undef CS_SOFTWARE_2D_DRIVER 00075 #ifdef __APPLE__ 00076 # define CS_SOFTWARE_2D_DRIVER "crystalspace.graphics2d.coregraphics" 00077 #else 00078 # define CS_SOFTWARE_2D_DRIVER "crystalspace.graphics2d.next" 00079 #endif 00080 00081 #undef CS_OPENGL_2D_DRIVER 00082 #define CS_OPENGL_2D_DRIVER "crystalspace.graphics2d.glosx" 00083 00084 #undef CS_SOUND_DRIVER 00085 #define CS_SOUND_DRIVER "crystalspace.sound.driver.coreaudio" 00086 00087 00088 //----------------------------------------------------------------------------- 00089 // NeXT does not supply strdup() so fake one up. 00090 //----------------------------------------------------------------------------- 00091 #include <stdlib.h> 00092 #include <string.h> 00093 00094 #if defined(OS_NEXT_NEXTSTEP) || defined(OS_NEXT_OPENSTEP) 00095 00096 static inline char* strdup(char const* s) 00097 { 00098 if (s == 0) s = ""; 00099 char* p = (char*)malloc(strlen(s) + 1); 00100 strcpy(p, s); 00101 return p; 00102 } 00103 00104 #endif 00105 00106 00107 //----------------------------------------------------------------------------- 00108 // Provide CS_MAXPATHLEN with a reasonable value. 00109 //----------------------------------------------------------------------------- 00110 #include <sys/param.h> 00111 #define CS_MAXPATHLEN MAXPATHLEN 00112 00113 00114 //----------------------------------------------------------------------------- 00115 // Pull in definitions for getwd(), ntohl(), htonl(), select(), etc. 00116 // *NOTE* On MacOS/X Server 1.0, libc.h pulls in sys/mount.h which pulls in 00117 // net/radix.h which defines a macro named Free(). This macro interferes with 00118 // several Crystal Space classes which have methods named Free(), so we must 00119 // #undef it. 00120 //----------------------------------------------------------------------------- 00121 #if defined(CS_SYSDEF_PROVIDE_GETCWD) || \ 00122 defined(CS_SYSDEF_PROVIDE_SOCKETS) || \ 00123 defined(CS_SYSDEF_PROVIDE_SELECT) || \ 00124 defined(CS_SYSDEF_PROVIDE_ACCESS) 00125 #include <libc.h> 00126 #undef Free 00127 #endif 00128 00129 #if defined(CS_SYSDEF_PROVIDE_SOCKETS) 00130 #define CS_USE_FAKE_SOCKLEN_TYPE 00131 #endif 00132 00133 #if defined(CS_SYSDEF_PROVIDE_SELECT) 00134 #include <string.h> // For memset() 00135 #define bzero(b,len) memset(b,0,len) /* bzero used by FD_ZERO */ 00136 #undef CS_SYSDEF_PROVIDE_SELECT 00137 #endif 00138 00139 00140 //----------------------------------------------------------------------------- 00141 // NeXT does not supply getcwd() so fake one up using getwd(). 00142 //----------------------------------------------------------------------------- 00143 #if defined(OS_NEXT_NEXTSTEP) || \ 00144 defined(OS_NEXT_OPENSTEP) || \ 00145 defined(OS_NEXT_MACOSXS) 00146 00147 #if defined(CS_SYSDEF_PROVIDE_GETCWD) 00148 #undef CS_SYSDEF_PROVIDE_GETCWD 00149 00150 #include <sys/param.h> 00151 00152 static inline char* getcwd(char* p, size_t size) 00153 { 00154 char s[ CS_MAXPATHLEN ]; 00155 char* r = getwd(s); 00156 if (r != 0) 00157 { 00158 strncpy(p, r, size - 1); 00159 p[ size - 1 ] = '\0'; 00160 r = p; 00161 } 00162 return r; 00163 } 00164 00165 #endif // CS_SYSDEF_PROVIDE_GETCWD 00166 #endif // OS_NEXT_NEXTSTEP || OS_NEXT_OPENSTEP || OS_NEXT_MACOSXS 00167 00168 00169 //----------------------------------------------------------------------------- 00170 // NeXT does not properly support Posix 'dirent', so fake it with 'direct'. 00171 //----------------------------------------------------------------------------- 00172 #ifdef CS_SYSDEF_PROVIDE_DIR 00173 00174 #ifdef _POSIX_SOURCE 00175 # undef _POSIX_SOURCE 00176 # include <sys/dir.h> 00177 # define _POSIX_SOURCE 00178 #else 00179 # include <sys/dir.h> 00180 #endif 00181 #include <sys/dirent.h> // Just so it gets included *before* #define below. 00182 #define dirent direct 00183 00184 #define __NEED_GENERIC_ISDIR 00185 #endif // CS_SYSDEF_PROVIDE_DIR 00186 00187 00188 //----------------------------------------------------------------------------- 00189 // NeXT uses built-in alloca(). 00190 //----------------------------------------------------------------------------- 00191 #ifdef CS_SYSDEF_PROVIDE_ALLOCA 00192 #undef CS_SYSDEF_PROVIDE_ALLOCA 00193 #define alloca(x) __builtin_alloca(x) 00194 #define ALLOC_STACK_ARRAY(var,type,size) type var[size] 00195 #endif // CS_SYSDEF_PROVIDE_ALLOCA 00196 00197 00198 //----------------------------------------------------------------------------- 00199 // Endian support. 00200 //----------------------------------------------------------------------------- 00201 #if defined (__LITTLE_ENDIAN__) 00202 # define CS_LITTLE_ENDIAN 00203 #elif defined (__BIG_ENDIAN__) 00204 # define CS_BIG_ENDIAN 00205 #else 00206 # error "Please define a suitable CS_XXX_ENDIAN macro in next/csosdefs.h!" 00207 #endif 00208 00209 00210 //----------------------------------------------------------------------------- 00211 // NextStep's gcc infrequently throws an exception when confronted with an 00212 // expression such as `static const Foo[] = {...};'. There are two ways to 00213 // work around this problem. (1) Remove the `const' or (2) specify the exact 00214 // table size, as in `Foo[3]'. This patch employs work-around #1. 00215 //----------------------------------------------------------------------------- 00216 #undef CS_STATIC_TABLE 00217 #define CS_STATIC_TABLE static 00218 00219 00220 //----------------------------------------------------------------------------- 00221 // Although the IEEE double-format optimizations of QInt() and QRound() work 00222 // on M68K, there are cases (particularly in the software renderer) where the 00223 // compiler corrupts the emitted code for these functions. Therefore, disable 00224 // these optimizations. 00225 // Note by Matt Reda: I did some rough testing of QInt() and friends on the 00226 // PowerPC. It appears to work ok, but is actually slower. Some simple 00227 // tests show that QInt() is roughly twice as slow as a cast from double 00228 // to long 00229 //----------------------------------------------------------------------------- 00230 #if !defined(PROC_X86) 00231 # define CS_NO_IEEE_OPTIMIZATIONS 00232 #endif 00233 00234 00235 //----------------------------------------------------------------------------- 00236 // The special Intel assembly version of qsqrt() (from CS/include/qsqrt.h) 00237 // fails to compile on NeXT. However, Matthew Reda <mreda@mac.com> added a 00238 // PowerPC version which works well for Macintosh and MacOS/X using GCC. 00239 //----------------------------------------------------------------------------- 00240 #if !defined(PROC_POWERPC) 00241 # define CS_NO_QSQRT 00242 #endif 00243 00244 00245 //----------------------------------------------------------------------------- 00246 // This is the (hopefully) MAC OS X compliant mmap code. 00247 // It supplies the hardware interface for memory-mapped I/O 00248 //----------------------------------------------------------------------------- 00249 00250 #if defined(OS_NEXT_MACOSX) 00251 00252 #ifdef CS_SYSDEF_PROVIDE_HARDWARE_MMIO 00253 00254 // Needed for Memory-Mapped IO functions below. 00255 #include <unistd.h> 00256 #include <sys/mman.h> 00257 #include <sys/types.h> 00258 #include <sys/stat.h> 00259 #include <fcntl.h> 00260 00261 // Defines that this platform supports hardware memory-mapped i/o 00262 #define CS_HAS_MEMORY_MAPPED_IO 1 00263 00264 // Unix specific memory mapped I/O platform dependent stuff 00265 struct mmioInfo 00266 { 00268 int hMappedFile; 00269 00271 unsigned char *data; 00272 00274 unsigned int file_size; 00275 }; 00276 00277 // Fills in the mmioInfo struct by mapping in filename. Returns true on success, false otherwise. 00278 inline 00279 bool 00280 MemoryMapFile(mmioInfo *platform, char *filename) 00281 { 00282 struct stat statInfo; 00283 00284 // Have 'nix map this file in for use 00285 if ( 00286 (platform->hMappedFile = open(filename, O_RDONLY)) == -1 || 00287 (fstat(platform->hMappedFile, &statInfo )) == -1 || 00288 (int)(platform->data = (unsigned char *)mmap(0, statInfo.st_size, PROT_READ, 0, platform->hMappedFile, 0)) == -1 00289 ) 00290 { 00291 return false; 00292 } 00293 else 00294 { 00295 platform->file_size=statInfo.st_size; 00296 return true; 00297 } 00298 } 00299 00300 inline 00301 void 00302 UnMemoryMapFile(mmioInfo *platform) 00303 { 00304 if (platform->data != NULL) 00305 munmap(platform->data, platform->file_size); 00306 00307 if (platform->hMappedFile != -1) 00308 close(platform->hMappedFile); 00309 } 00310 00311 #endif // memory-mapped I/O 00312 00313 00314 #endif // OS_NEXT_MACOSX 00315 00316 00317 #endif // __NeXT_csosdefs_h Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |