|
|
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: extern void* q_memset(void*,int,size_t); ! 158: extern 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: extern TCHAR *my_strdup (const TCHAR*s); ! 234: #endif ! 235: extern TCHAR *my_strdup_ansi (const char*); ! 236: extern TCHAR *au (const char*); ! 237: extern char *ua (const TCHAR*); ! 238: extern TCHAR *aucp (const char *s, unsigned int cp); ! 239: extern char *uacp (const TCHAR *s, unsigned int cp); ! 240: extern TCHAR *au_fs (const char*); ! 241: extern char *ua_fs (const TCHAR*, int); ! 242: extern char *ua_copy (char *dst, int maxlen, const TCHAR *src); ! 243: extern TCHAR *au_copy (TCHAR *dst, int maxlen, const char *src); ! 244: extern char *ua_fs_copy (char *dst, int maxlen, const TCHAR *src, int defchar); ! 245: extern TCHAR *au_fs_copy (TCHAR *dst, int maxlen, const char *src); ! 246: extern char *uutf8 (const TCHAR *s); ! 247: extern TCHAR *utf8u (const char *s); ! 248: extern void unicode_init (void); ! 249: extern void to_lower (TCHAR *s, int len); ! 250: extern 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: extern 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: extern void get_time (time_t t, long* days, long* mins, long* ticks); ! 357: extern 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: extern int posixemu_chmod (const TCHAR *, int); ! 362: #define stat(a,b) posixemu_stat ((a), (b)) ! 363: extern int posixemu_stat (const TCHAR *, struct _stat64 *); ! 364: #define mkdir(x,y) mkdir(x) ! 365: #define truncate posixemu_truncate ! 366: extern int posixemu_truncate (const TCHAR *, long int); ! 367: #define utime posixemu_utime ! 368: extern int posixemu_utime (const TCHAR *, struct utimbuf *); ! 369: #define opendir posixemu_opendir ! 370: extern DIR * posixemu_opendir (const TCHAR *); ! 371: #define readdir posixemu_readdir ! 372: extern struct dirent* posixemu_readdir (DIR *); ! 373: #define closedir posixemu_closedir ! 374: extern void posixemu_closedir (DIR *); ! 375: ! 376: #endif ! 377: ! 378: #endif /* _WIN32 */ ! 379: ! 380: #ifdef DONT_HAVE_POSIX ! 381: ! 382: #define access posixemu_access ! 383: extern int posixemu_access (const TCHAR *, int); ! 384: #define open posixemu_open ! 385: extern int posixemu_open (const TCHAR *, int, int); ! 386: #define close posixemu_close ! 387: extern void posixemu_close (int); ! 388: #define read posixemu_read ! 389: extern int posixemu_read (int, TCHAR *, int); ! 390: #define write posixemu_write ! 391: extern int posixemu_write (int, const TCHAR *, int); ! 392: #undef lseek ! 393: #define lseek posixemu_seek ! 394: extern int posixemu_seek (int, int, int); ! 395: #define stat(a,b) posixemu_stat ((a), (b)) ! 396: extern int posixemu_stat (const TCHAR *, STAT *); ! 397: #define mkdir posixemu_mkdir ! 398: extern int mkdir (const TCHAR *, int); ! 399: #define rmdir posixemu_rmdir ! 400: extern int posixemu_rmdir (const TCHAR *); ! 401: #define unlink posixemu_unlink ! 402: extern int posixemu_unlink (const TCHAR *); ! 403: #define truncate posixemu_truncate ! 404: extern int posixemu_truncate (const TCHAR *, long int); ! 405: #define rename posixemu_rename ! 406: extern int posixemu_rename (const TCHAR *, const TCHAR *); ! 407: #define chmod posixemu_chmod ! 408: extern int posixemu_chmod (const TCHAR *, int); ! 409: #define tmpnam posixemu_tmpnam ! 410: extern void posixemu_tmpnam (TCHAR *); ! 411: #define utime posixemu_utime ! 412: extern int posixemu_utime (const TCHAR *, struct utimbuf *); ! 413: #define opendir posixemu_opendir ! 414: extern DIR * posixemu_opendir (const TCHAR *); ! 415: #define readdir posixemu_readdir ! 416: extern struct dirent* readdir (DIR *); ! 417: #define closedir posixemu_closedir ! 418: extern 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: extern long dos_errno (void); ! 424: ! 425: #endif ! 426: ! 427: #ifdef DONT_HAVE_STDIO ! 428: ! 429: extern FILE *stdioemu_fopen (const TCHAR *, const TCHAR *); ! 430: #define fopen(a,b) stdioemu_fopen(a, b) ! 431: extern int stdioemu_fseek (FILE *, int, int); ! 432: #define fseek(a,b,c) stdioemu_fseek(a, b, c) ! 433: extern int stdioemu_fread (TCHAR *, int, int, FILE *); ! 434: #define fread(a,b,c,d) stdioemu_fread(a, b, c, d) ! 435: extern int stdioemu_fwrite (const TCHAR *, int, int, FILE *); ! 436: #define fwrite(a,b,c,d) stdioemu_fwrite(a, b, c, d) ! 437: extern int stdioemu_ftell (FILE *); ! 438: #define ftell(a) stdioemu_ftell(a) ! 439: extern 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: extern void *mallocemu_malloc (int size); ! 448: #define free(a) mallocemu_free(a) ! 449: extern 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: extern void write_log (const TCHAR *, ...) __attribute__ ((format (printf, 1, 2))); ! 468: #else ! 469: extern void write_log (const TCHAR *, ...); ! 470: #endif ! 471: extern void write_dlog (const TCHAR *, ...); ! 472: ! 473: extern void flush_log (void); ! 474: extern void close_console (void); ! 475: extern void reopen_console (void); ! 476: extern void console_out (const TCHAR *); ! 477: extern void console_out_f (const TCHAR *, ...); ! 478: extern void console_flush (void); ! 479: extern int console_get (TCHAR *, int); ! 480: extern TCHAR console_getch (void); ! 481: /*extern void f_out (void *, const TCHAR *, ...);*/ ! 482: extern TCHAR* buf_out (TCHAR *buffer, int *bufsize, const TCHAR *format, ...); ! 483: extern void gui_message (const TCHAR *,...); ! 484: extern int gui_message_multibutton (int flags, const TCHAR *format,...); ! 485: #define write_log_err write_log ! 486: extern void logging_init (void); ! 487: extern FILE *log_open (const TCHAR *name, int append, int bootlog); ! 488: extern void log_close (FILE *f); ! 489: ! 490: ! 491: #ifndef O_BINARY ! 492: #define O_BINARY 0 ! 493: #endif ! 494: ! 495: #ifndef STATIC_INLINE ! 496: #if __GNUC__ - 1 > 1 && __GNUC_MINOR__ - 1 >= 0 ! 497: #define STATIC_INLINE static __inline__ __attribute__ ((always_inline)) ! 498: #define NOINLINE __attribute__ ((noinline)) ! 499: #define NORETURN __attribute__ ((noreturn)) ! 500: #elif _MSC_VER ! 501: #define STATIC_INLINE static __forceinline ! 502: #define NOINLINE __declspec(noinline) ! 503: #define NORETURN __declspec(noreturn) ! 504: #else ! 505: #define STATIC_INLINE static __inline__ ! 506: #define NOINLINE ! 507: #define NORETURN ! 508: #endif ! 509: #endif ! 510: ! 511: /* Every Amiga hardware clock cycle takes this many "virtual" cycles. This ! 512: used to be hardcoded as 1, but using higher values allows us to time some ! 513: stuff more precisely. ! 514: 512 is the official value from now on - it can't change, unless we want ! 515: _another_ config option "finegrain2_m68k_speed". ! 516: ! 517: We define this value here rather than in events.h so that gencpu.c sees ! 518: it. */ ! 519: #define CYCLE_UNIT 512 ! 520: ! 521: /* This one is used by cfgfile.c. We could reduce the CYCLE_UNIT back to 1, ! 522: I'm not 100% sure this code is bug free yet. */ ! 523: #define OFFICIAL_CYCLE_UNIT 512 ! 524: ! 525: /* ! 526: * You can specify numbers from 0 to 5 here. It is possible that higher ! 527: * numbers will make the CPU emulation slightly faster, but if the setting ! 528: * is too high, you will run out of memory while compiling. ! 529: * Best to leave this as it is. ! 530: */ ! 531: #define CPU_EMU_SIZE 0 ! 532: ! 533: /* ! 534: * Byte-swapping functions ! 535: */ ! 536: ! 537: /* Try to use system bswap_16/bswap_32 functions. */ ! 538: #if defined HAVE_BSWAP_16 && defined HAVE_BSWAP_32 ! 539: # include <byteswap.h> ! 540: # ifdef HAVE_BYTESWAP_H ! 541: # include <byteswap.h> ! 542: # endif ! 543: #else ! 544: /* Else, if using SDL, try SDL's endian functions. */ ! 545: # ifdef USE_SDL ! 546: # include <SDL_endian.h> ! 547: # define bswap_16(x) SDL_Swap16(x) ! 548: # define bswap_32(x) SDL_Swap32(x) ! 549: # else ! 550: /* Otherwise, we'll roll our own. */ ! 551: # define bswap_16(x) (((x) >> 8) | (((x) & 0xFF) << 8)) ! 552: # define bswap_32(x) (((x) << 24) | (((x) << 8) & 0x00FF0000) | (((x) >> 8) & 0x0000FF00) | ((x) >> 24)) ! 553: # endif ! 554: #endif ! 555: ! 556: #endif ! 557: ! 558: #ifndef __cplusplus ! 559: ! 560: #define xmalloc(T, N) malloc(sizeof (T) * (N)) ! 561: #define xcalloc(T, N) calloc(sizeof (T), N) ! 562: #define xfree(T) free(T) ! 563: #define xrealloc(T, TP, N) realloc(TP, sizeof (T) * (N)) ! 564: ! 565: #if 0 ! 566: extern void *xmalloc (size_t); ! 567: extern void *xcalloc (size_t, size_t); ! 568: extern void xfree (const void*); ! 569: #endif ! 570: ! 571: #else ! 572: ! 573: #define xmalloc(T, N) static_cast<T*>(malloc (sizeof (T) * (N))) ! 574: #define xcalloc(T, N) static_cast<T*>(calloc (sizeof (T), N)) ! 575: #define xrealloc(T, TP, N) static_cast<T*>(realloc (TP, sizeof (T) * (N))) ! 576: #define xfree(T) free(T) ! 577: ! 578: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.