Annotation of previous_trunk/src/cpu/sysdeps.h, revision 1.1.1.1

1.1       root        1: #ifndef UAE_SYSDEPS_H
                      2: #define UAE_SYSDEPS_H
                      3: 
                      4: /*
                      5:   * UAE - The Un*x Amiga Emulator
                      6:   *
                      7:   * Try to include the right system headers and get other system-specific
                      8:   * stuff right & other collected kludges.
                      9:   *
                     10:   * If you think about modifying this, think twice. Some systems rely on
                     11:   * the exact order of the #include statements. That's also the reason
                     12:   * why everything gets included unconditionally regardless of whether
                     13:   * it's actually needed by the .c file.
                     14:   *
                     15:   * Copyright 1996, 1997 Bernd Schmidt
                     16:   */
                     17: //#include <string>
                     18: //using namespace std;
                     19: 
                     20: #include <stdio.h>
                     21: #include <stdlib.h>
                     22: #include <errno.h>
                     23: #include <assert.h>
                     24: #include <limits.h>
                     25: //#include <tchar.h>
                     26: #include "compat.h"
                     27: 
                     28: #ifndef __STDC__
                     29: #ifndef _MSC_VER
                     30: #error "Your compiler is not ANSI. Get a real one."
                     31: #endif
                     32: #endif
                     33: 
                     34: #include <stdarg.h>
                     35: 
                     36: #ifdef HAVE_SYS_TYPES_H
                     37: #include <sys/types.h>
                     38: #endif
                     39: 
                     40: #ifdef HAVE_VALUES_H
                     41: #include <values.h>
                     42: #endif
                     43: 
                     44: #ifdef HAVE_STRINGS_H
                     45: #include <strings.h>
                     46: #endif
                     47: #ifdef HAVE_STRING_H
                     48: #include <string.h>
                     49: #endif
                     50: 
                     51: #ifdef HAVE_UNISTD_H
                     52: #include <unistd.h>
                     53: #endif
                     54: #ifdef HAVE_FCNTL_H
                     55: #include <fcntl.h>
                     56: #endif
                     57: 
                     58: #ifdef HAVE_UTIME_H
                     59: #include <utime.h>
                     60: #endif
                     61: 
                     62: #ifdef HAVE_SYS_STAT_H
                     63: #include <sys/stat.h>
                     64: #endif
                     65: 
                     66: #if TIME_WITH_SYS_TIME
                     67: # include <sys/time.h>
                     68: # include <time.h>
                     69: #else
                     70: # if HAVE_SYS_TIME_H
                     71: #  include <sys/time.h>
                     72: # else
                     73: #  include <time.h>
                     74: # endif
                     75: #endif
                     76: 
                     77: #if HAVE_DIRENT_H
                     78: # include <dirent.h>
                     79: #else
                     80: # define dirent direct
                     81: # if HAVE_SYS_NDIR_H
                     82: #  include <sys/ndir.h>
                     83: # endif
                     84: # if HAVE_SYS_DIR_H
                     85: #  include <sys/dir.h>
                     86: # endif
                     87: # if HAVE_NDIR_H
                     88: #  include <ndir.h>
                     89: # endif
                     90: #endif
                     91: 
                     92: #ifdef HAVE_SYS_UTIME_H
                     93: # include <sys/utime.h>
                     94: #endif
                     95: 
                     96: #include <errno.h>
                     97: #include <assert.h>
                     98: 
                     99: #if EEXIST == ENOTEMPTY
                    100: #define BROKEN_OS_PROBABLY_AIX
                    101: #endif
                    102: 
                    103: #ifdef __NeXT__
                    104: #define S_IRUSR S_IREAD
                    105: #define S_IWUSR S_IWRITE
                    106: #define S_IXUSR S_IEXEC
                    107: #define S_ISDIR(val) (S_IFDIR & val)
                    108: struct utimbuf
                    109: {
                    110:     time_t actime;
                    111:     time_t modtime;
                    112: };
                    113: #endif
                    114: 
                    115: #if defined(__GNUC__) && defined(AMIGA)
                    116: /* gcc on the amiga need that __attribute((regparm)) must */
                    117: /* be defined in function prototypes as well as in        */
                    118: /* function definitions !                                 */
                    119: #define REGPARAM2 REGPARAM
                    120: #else /* not(GCC & AMIGA) */
                    121: #define REGPARAM2
                    122: #endif
                    123: 
                    124: /* sam: some definitions so that SAS/C can compile UAE */
                    125: #if defined(__SASC) && defined(AMIGA)
                    126: #define REGPARAM2
                    127: #define REGPARAM
                    128: #define S_IRUSR S_IREAD
                    129: #define S_IWUSR S_IWRITE
                    130: #define S_IXUSR S_IEXECUTE
                    131: #define S_ISDIR(val) (S_IFDIR & val)
                    132: #define mkdir(x,y) mkdir(x)
                    133: #define truncate(x,y) 0
                    134: #define creat(x,y) open("T:creat",O_CREAT|O_TEMP|O_RDWR) /* sam: for zfile.c */
                    135: #define strcasecmp stricmp
                    136: #define utime(file,time) 0
                    137: struct utimbuf
                    138: {
                    139:     time_t actime;
                    140:     time_t modtime;
                    141: };
                    142: #endif
                    143: 
                    144: #if defined(WARPUP)
                    145: #include "devices/timer.h"
                    146: #include "osdep/posixemu.h"
                    147: #define REGPARAM
                    148: #define REGPARAM2
                    149: #define RETSIGTYPE
                    150: #define USE_ZFILE
                    151: #define strcasecmp stricmp
                    152: #define memcpy q_memcpy
                    153: #define memset q_memset
                    154: #define strdup my_strdup
                    155: #define random rand
                    156: #define creat(x,y) open("T:creat",O_CREAT|O_RDWR|O_TRUNC,777)
                    157: void* q_memset(void*,int,size_t);
                    158: void* q_memcpy(void*,const void*,size_t);
                    159: #endif
                    160: 
                    161: #ifdef __DOS__
                    162: #include <pc.h>
                    163: #include <io.h>
                    164: #endif
                    165: 
                    166: /* Acorn specific stuff */
                    167: #ifdef ACORN
                    168: 
                    169: #define S_IRUSR S_IREAD
                    170: #define S_IWUSR S_IWRITE
                    171: #define S_IXUSR S_IEXEC
                    172: 
                    173: #define strcasecmp stricmp
                    174: 
                    175: #endif
                    176: 
                    177: #ifndef L_tmpnam
                    178: #define L_tmpnam 128 /* ought to be safe */
                    179: #endif
                    180: 
                    181: /* If char has more then 8 bits, good night. */
                    182: typedef unsigned char uae_u8;
                    183: typedef signed char uae_s8;
                    184: typedef char uae_char;
                    185: 
                    186: typedef struct { uae_u8 RGB[3]; } RGB;
                    187: 
                    188: #if SIZEOF_SHORT == 2
                    189: typedef unsigned short uae_u16;
                    190: typedef short uae_s16;
                    191: #elif SIZEOF_INT == 2
                    192: typedef unsigned int uae_u16;
                    193: typedef int uae_s16;
                    194: #else
                    195: #error No 2 byte type, you lose.
                    196: #endif
                    197: 
                    198: #if SIZEOF_INT == 4
                    199: typedef unsigned int uae_u32;
                    200: typedef int uae_s32;
                    201: #elif SIZEOF_LONG == 4
                    202: typedef unsigned long uae_u32;
                    203: typedef long uae_s32;
                    204: #else
                    205: #error No 4 byte type, you lose.
                    206: #endif
                    207: 
                    208: typedef uae_u32 uaecptr;
                    209: 
                    210: #undef uae_s64
                    211: #undef uae_u64
                    212: 
                    213: #if SIZEOF_LONG_LONG == 8
                    214: #define uae_s64 long long
                    215: #define uae_u64 unsigned long long
                    216: #define VAL64(a) (a ## LL)
                    217: #define UVAL64(a) (a ## uLL)
                    218: #elif SIZEOF___INT64 == 8
                    219: #define uae_s64 __int64
                    220: #define uae_u64 unsigned __int64
                    221: #define VAL64(a) (a)
                    222: #define UVAL64(a) (a)
                    223: #elif SIZEOF_LONG == 8
                    224: #define uae_s64 long;
                    225: #define uae_u64 unsigned long;
                    226: #define VAL64(a) (a ## l)
                    227: #define UVAL64(a) (a ## ul)
                    228: #endif
                    229: 
                    230: #ifdef HAVE_STRDUP
                    231: #define my_strdup _tcsdup
                    232: #else
                    233: TCHAR *my_strdup (const TCHAR*s);
                    234: #endif
                    235: TCHAR *my_strdup_ansi (const char*);
                    236: TCHAR *au (const char*);
                    237: char *ua (const TCHAR*);
                    238: TCHAR *aucp (const char *s, unsigned int cp);
                    239: char *uacp (const TCHAR *s, unsigned int cp);
                    240: TCHAR *au_fs (const char*);
                    241: char *ua_fs (const TCHAR*, int);
                    242: char *ua_copy (char *dst, int maxlen, const TCHAR *src);
                    243: TCHAR *au_copy (TCHAR *dst, int maxlen, const char *src);
                    244: char *ua_fs_copy (char *dst, int maxlen, const TCHAR *src, int defchar);
                    245: TCHAR *au_fs_copy (TCHAR *dst, int maxlen, const char *src);
                    246: char *uutf8 (const TCHAR *s);
                    247: TCHAR *utf8u (const char *s);
                    248: void unicode_init (void);
                    249: void to_lower (TCHAR *s, int len);
                    250: void to_upper (TCHAR *s, int len);
                    251: /* We can only rely on GNU C getting enums right. Mickeysoft VSC++ is known
                    252:  * to have problems, and it's likely that other compilers choke too. */
                    253: #ifdef __GNUC__
                    254: #define ENUMDECL typedef enum
                    255: #define ENUMNAME(name) name
                    256: 
                    257: /* While we're here, make abort more useful.  */
                    258: /*#define abort() \
                    259:   do { \
                    260:     write_log ("Internal error; file %s, line %d\n", __FILE__, __LINE__); \
                    261:     (abort) (); \
                    262: } while (0)
                    263: */#else
                    264: #define ENUMDECL enum
                    265: #define ENUMNAME(name) ; typedef int name
                    266: #endif
                    267: 
                    268: /*
                    269:  * Porters to weird systems, look! This is the preferred way to get
                    270:  * filesys.c (and other stuff) running on your system. Define the
                    271:  * appropriate macros and implement wrappers in a machine-specific file.
                    272:  *
                    273:  * I guess the Mac port could use this (Ernesto?)
                    274:  */
                    275: 
                    276: #undef DONT_HAVE_POSIX
                    277: #undef DONT_HAVE_REAL_POSIX /* define if open+delete doesn't do what it should */
                    278: #undef DONT_HAVE_STDIO
                    279: #undef DONT_HAVE_MALLOC
                    280: 
                    281: #if defined(WARPUP)
                    282: #define DONT_HAVE_POSIX
                    283: #endif
                    284: 
                    285: #if defined _WIN32
                    286: 
                    287: #if defined __WATCOMC__
                    288: 
                    289: #define O_NDELAY 0
                    290: #include <direct.h>
                    291: #define dirent direct
                    292: #define mkdir(a,b) mkdir(a)
                    293: #define strcasecmp stricmp
                    294: 
                    295: #elif defined __MINGW32__
                    296: 
                    297: #define O_NDELAY 0
                    298: #define mkdir(a,b) mkdir(a)
                    299: 
                    300: #elif defined _MSC_VER
                    301: 
                    302: #ifdef HAVE_GETTIMEOFDAY
                    303: #include <winsock.h> // for 'struct timeval' definition
                    304: void gettimeofday( struct timeval *tv, void *blah );
                    305: #endif
                    306: 
                    307: #define O_NDELAY 0
                    308: 
                    309: #define FILEFLAG_DIR     0x1
                    310: #define FILEFLAG_ARCHIVE 0x2
                    311: #define FILEFLAG_WRITE   0x4
                    312: #define FILEFLAG_READ    0x8
                    313: #define FILEFLAG_EXECUTE 0x10
                    314: #define FILEFLAG_SCRIPT  0x20
                    315: #define FILEFLAG_PURE    0x40
                    316: 
                    317: #ifdef REGPARAM2
                    318: #undef REGPARAM2
                    319: #endif
                    320: #define REGPARAM2 __fastcall
                    321: #define REGPARAM3 __fastcall
                    322: #define REGPARAM
                    323: 
                    324: #include <io.h>
                    325: #define O_BINARY _O_BINARY
                    326: #define O_WRONLY _O_WRONLY
                    327: #define O_RDONLY _O_RDONLY
                    328: #define O_RDWR   _O_RDWR
                    329: #define O_CREAT  _O_CREAT
                    330: #define O_TRUNC  _O_TRUNC
                    331: #define strcasecmp _tcsicmp 
                    332: #define strncasecmp _tcsncicmp 
                    333: #define W_OK 0x2
                    334: #define R_OK 0x4
                    335: #define STAT struct stat
                    336: #define DIR struct DIR
                    337: struct direct
                    338: {
                    339:     TCHAR d_name[1];
                    340: };
                    341: #include <sys/utime.h>
                    342: #define utimbuf __utimbuf64
                    343: #define USE_ZFILE
                    344: 
                    345: #undef S_ISDIR
                    346: #undef S_IWUSR
                    347: #undef S_IRUSR
                    348: #undef S_IXUSR
                    349: #define S_ISDIR(a) (a&FILEFLAG_DIR)
                    350: #define S_ISARC(a) (a&FILEFLAG_ARCHIVE)
                    351: #define S_IWUSR FILEFLAG_WRITE
                    352: #define S_IRUSR FILEFLAG_READ
                    353: #define S_IXUSR FILEFLAG_EXECUTE
                    354: 
                    355: /* These are prototypes for functions from the Win32 posixemu file */
                    356: void get_time (time_t t, long* days, long* mins, long* ticks);
                    357: time_t put_time (long days, long mins, long ticks);
                    358: 
                    359: /* #define DONT_HAVE_POSIX - don't need all of Mathias' posixemu_functions, just a subset (below) */
                    360: #define chmod(a,b) posixemu_chmod ((a), (b))
                    361: int posixemu_chmod (const TCHAR *, int);
                    362: #define stat(a,b) posixemu_stat ((a), (b))
                    363: int posixemu_stat (const TCHAR *, struct _stat64 *);
                    364: #define mkdir(x,y) mkdir(x)
                    365: #define truncate posixemu_truncate
                    366: int posixemu_truncate (const TCHAR *, long int);
                    367: #define utime posixemu_utime
                    368: int posixemu_utime (const TCHAR *, struct utimbuf *);
                    369: #define opendir posixemu_opendir
                    370: DIR * posixemu_opendir (const TCHAR *);
                    371: #define readdir posixemu_readdir
                    372: struct dirent* posixemu_readdir (DIR *);
                    373: #define closedir posixemu_closedir
                    374: void posixemu_closedir (DIR *);
                    375: 
                    376: #endif
                    377: 
                    378: #endif /* _WIN32 */
                    379: 
                    380: #ifdef DONT_HAVE_POSIX
                    381: 
                    382: #define access posixemu_access
                    383: int posixemu_access (const TCHAR *, int);
                    384: #define open posixemu_open
                    385: int posixemu_open (const TCHAR *, int, int);
                    386: #define close posixemu_close
                    387: void posixemu_close (int);
                    388: #define read posixemu_read
                    389: int posixemu_read (int, TCHAR *, int);
                    390: #define write posixemu_write
                    391: int posixemu_write (int, const TCHAR *, int);
                    392: #undef lseek
                    393: #define lseek posixemu_seek
                    394: int posixemu_seek (int, int, int);
                    395: #define stat(a,b) posixemu_stat ((a), (b))
                    396: int posixemu_stat (const TCHAR *, STAT *);
                    397: #define mkdir posixemu_mkdir
                    398: int mkdir (const TCHAR *, int);
                    399: #define rmdir posixemu_rmdir
                    400: int posixemu_rmdir (const TCHAR *);
                    401: #define unlink posixemu_unlink
                    402: int posixemu_unlink (const TCHAR *);
                    403: #define truncate posixemu_truncate
                    404: int posixemu_truncate (const TCHAR *, long int);
                    405: #define rename posixemu_rename
                    406: int posixemu_rename (const TCHAR *, const TCHAR *);
                    407: #define chmod posixemu_chmod
                    408: int posixemu_chmod (const TCHAR *, int);
                    409: #define tmpnam posixemu_tmpnam
                    410: void posixemu_tmpnam (TCHAR *);
                    411: #define utime posixemu_utime
                    412: int posixemu_utime (const TCHAR *, struct utimbuf *);
                    413: #define opendir posixemu_opendir
                    414: DIR * posixemu_opendir (const TCHAR *);
                    415: #define readdir posixemu_readdir
                    416: struct dirent* readdir (DIR *);
                    417: #define closedir posixemu_closedir
                    418: void closedir (DIR *);
                    419: 
                    420: /* This isn't the best place for this, but it fits reasonably well. The logic
                    421:  * is that you probably don't have POSIX errnos if you don't have the above
                    422:  * functions. */
                    423: long dos_errno (void);
                    424: 
                    425: #endif
                    426: 
                    427: #ifdef DONT_HAVE_STDIO
                    428: 
                    429: FILE *stdioemu_fopen (const TCHAR *, const TCHAR *);
                    430: #define fopen(a,b) stdioemu_fopen(a, b)
                    431: int stdioemu_fseek (FILE *, int, int);
                    432: #define fseek(a,b,c) stdioemu_fseek(a, b, c)
                    433: int stdioemu_fread (TCHAR *, int, int, FILE *);
                    434: #define fread(a,b,c,d) stdioemu_fread(a, b, c, d)
                    435: int stdioemu_fwrite (const TCHAR *, int, int, FILE *);
                    436: #define fwrite(a,b,c,d) stdioemu_fwrite(a, b, c, d)
                    437: int stdioemu_ftell (FILE *);
                    438: #define ftell(a) stdioemu_ftell(a)
                    439: int stdioemu_fclose (FILE *);
                    440: #define fclose(a) stdioemu_fclose(a)
                    441: 
                    442: #endif
                    443: 
                    444: #ifdef DONT_HAVE_MALLOC
                    445: 
                    446: #define malloc(a) mallocemu_malloc(a)
                    447: void *mallocemu_malloc (int size);
                    448: #define free(a) mallocemu_free(a)
                    449: void mallocemu_free (void *ptr);
                    450: 
                    451: #endif
                    452: 
                    453: #ifdef X86_ASSEMBLY
                    454: #define ASM_SYM_FOR_FUNC(a) __asm__(a)
                    455: #else
                    456: #define ASM_SYM_FOR_FUNC(a)
                    457: #endif
                    458: 
                    459: //#include "target.h"
                    460: 
                    461: #ifdef UAE_CONSOLE
                    462: #undef write_log
                    463: #define write_log write_log_standard
                    464: #endif
                    465: 
                    466: #if __GNUC__ - 1 > 1 || __GNUC_MINOR__ - 1 > 6
                    467: void write_log (const TCHAR *, ...) __attribute__ ((format (printf, 1, 2)));
                    468: #else
                    469: void write_log (const TCHAR *, ...);
                    470: #endif
                    471: void write_dlog (const TCHAR *, ...);
                    472: 
                    473: void flush_log (void);
                    474: void close_console (void);
                    475: void reopen_console (void);
                    476: void console_out (const TCHAR *);
                    477: void console_flush (void);
                    478: int console_get (TCHAR *, int);
                    479: TCHAR console_getch (void);
                    480: void gui_message (const TCHAR *,...);
                    481: int gui_message_multibutton (int flags, const TCHAR *format,...);
                    482: #define write_log_err write_log
                    483: void logging_init (void);
                    484: FILE *log_open (const TCHAR *name, int append, int bootlog);
                    485: void log_close (FILE *f);
                    486: 
                    487: 
                    488: #ifndef O_BINARY
                    489: #define O_BINARY 0
                    490: #endif
                    491: 
                    492: #ifndef STATIC_INLINE
                    493: #if __GNUC__ - 1 > 1 && __GNUC_MINOR__ - 1 >= 0
                    494: #define STATIC_INLINE static __inline__ __attribute__ ((always_inline))
                    495: #define NOINLINE __attribute__ ((noinline))
                    496: #define NORETURN __attribute__ ((noreturn))
                    497: #elif _MSC_VER
                    498: #define STATIC_INLINE static __forceinline
                    499: #define NOINLINE __declspec(noinline)
                    500: #define NORETURN __declspec(noreturn)
                    501: #else
                    502: #define STATIC_INLINE static __inline__
                    503: #define NOINLINE
                    504: #define NORETURN
                    505: #endif
                    506: #endif
                    507: 
                    508: /*
                    509:  * You can specify numbers from 0 to 5 here. It is possible that higher
                    510:  * numbers will make the CPU emulation slightly faster, but if the setting
                    511:  * is too high, you will run out of memory while compiling.
                    512:  * Best to leave this as it is.
                    513:  */
                    514: #define CPU_EMU_SIZE 0
                    515: 
                    516: /*
                    517:  * Byte-swapping functions
                    518:  */
                    519: 
                    520: /* Try to use system bswap_16/bswap_32 functions. */
                    521: #if defined HAVE_BSWAP_16 && defined HAVE_BSWAP_32
                    522: # include <byteswap.h>
                    523: #  ifdef HAVE_BYTESWAP_H
                    524: #  include <byteswap.h>
                    525: # endif
                    526: #else
                    527: /* Else, if using SDL, try SDL's endian functions. */
                    528: # ifdef USE_SDL
                    529: #  include <SDL_endian.h>
                    530: #  define bswap_16(x) SDL_Swap16(x)
                    531: #  define bswap_32(x) SDL_Swap32(x)
                    532: # else
                    533: /* Otherwise, we'll roll our own. */
                    534: #  define bswap_16(x) (((x) >> 8) | (((x) & 0xFF) << 8))
                    535: #  define bswap_32(x) (((x) << 24) | (((x) << 8) & 0x00FF0000) | (((x) >> 8) & 0x0000FF00) | ((x) >> 24))
                    536: # endif
                    537: #endif
                    538: 
                    539: #endif
                    540: 
                    541: #ifndef __cplusplus
                    542: 
                    543: #define xmalloc(T, N) malloc(sizeof (T) * (N))
                    544: #define xcalloc(T, N) calloc(sizeof (T), N)
                    545: #define xfree(T) free(T)
                    546: #define xrealloc(T, TP, N) realloc(TP, sizeof (T) * (N))
                    547: 
                    548: #else
                    549: 
                    550: #define xmalloc(T, N) static_cast<T*>(malloc (sizeof (T) * (N)))
                    551: #define xcalloc(T, N) static_cast<T*>(calloc (sizeof (T), N))
                    552: #define xrealloc(T, TP, N) static_cast<T*>(realloc (TP, sizeof (T) * (N)))
                    553: #define xfree(T) free(T)
                    554: 
                    555: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.