|
|
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
1.1.1.3 ! root 155: #define random uaerand
1.1 root 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:
1.1.1.3 ! root 230: #ifndef TRUE
! 231: #define TRUE 1
! 232: #endif
! 233: #ifndef FALSE
! 234: #define FALSE 0
! 235: #endif
! 236:
1.1 root 237: #ifdef HAVE_STRDUP
238: #define my_strdup _tcsdup
239: #else
240: extern TCHAR *my_strdup (const TCHAR*s);
241: #endif
242: extern TCHAR *my_strdup_ansi (const char*);
243: extern TCHAR *au (const char*);
244: extern char *ua (const TCHAR*);
245: extern TCHAR *aucp (const char *s, unsigned int cp);
246: extern char *uacp (const TCHAR *s, unsigned int cp);
247: extern TCHAR *au_fs (const char*);
248: extern char *ua_fs (const TCHAR*, int);
249: extern char *ua_copy (char *dst, int maxlen, const TCHAR *src);
250: extern TCHAR *au_copy (TCHAR *dst, int maxlen, const char *src);
251: extern char *ua_fs_copy (char *dst, int maxlen, const TCHAR *src, int defchar);
252: extern TCHAR *au_fs_copy (TCHAR *dst, int maxlen, const char *src);
253: extern char *uutf8 (const TCHAR *s);
254: extern TCHAR *utf8u (const char *s);
255: extern void unicode_init (void);
256: extern void to_lower (TCHAR *s, int len);
257: extern void to_upper (TCHAR *s, int len);
258: /* We can only rely on GNU C getting enums right. Mickeysoft VSC++ is known
259: * to have problems, and it's likely that other compilers choke too. */
260: #ifdef __GNUC__
261: #define ENUMDECL typedef enum
262: #define ENUMNAME(name) name
263:
264: /* While we're here, make abort more useful. */
265: /*#define abort() \
266: do { \
267: write_log ("Internal error; file %s, line %d\n", __FILE__, __LINE__); \
268: (abort) (); \
269: } while (0)
270: */#else
271: #define ENUMDECL enum
272: #define ENUMNAME(name) ; typedef int name
273: #endif
274:
275: /*
276: * Porters to weird systems, look! This is the preferred way to get
277: * filesys.c (and other stuff) running on your system. Define the
278: * appropriate macros and implement wrappers in a machine-specific file.
279: *
280: * I guess the Mac port could use this (Ernesto?)
281: */
282:
283: #undef DONT_HAVE_POSIX
284: #undef DONT_HAVE_REAL_POSIX /* define if open+delete doesn't do what it should */
285: #undef DONT_HAVE_STDIO
286: #undef DONT_HAVE_MALLOC
287:
288: #if defined(WARPUP)
289: #define DONT_HAVE_POSIX
290: #endif
291:
292: #if defined _WIN32
293:
294: #if defined __WATCOMC__
295:
296: #define O_NDELAY 0
297: #include <direct.h>
298: #define dirent direct
299: #define mkdir(a,b) mkdir(a)
300: #define strcasecmp stricmp
301:
302: #elif defined __MINGW32__
303:
304: #define O_NDELAY 0
305: #define mkdir(a,b) mkdir(a)
306:
307: #elif defined _MSC_VER
308:
309: #ifdef HAVE_GETTIMEOFDAY
310: #include <winsock.h> // for 'struct timeval' definition
311: extern void gettimeofday( struct timeval *tv, void *blah );
312: #endif
313:
314: #define O_NDELAY 0
315:
316: #define FILEFLAG_DIR 0x1
317: #define FILEFLAG_ARCHIVE 0x2
318: #define FILEFLAG_WRITE 0x4
319: #define FILEFLAG_READ 0x8
320: #define FILEFLAG_EXECUTE 0x10
321: #define FILEFLAG_SCRIPT 0x20
322: #define FILEFLAG_PURE 0x40
323:
324: #ifdef REGPARAM2
325: #undef REGPARAM2
326: #endif
327: #define REGPARAM2 __fastcall
328: #define REGPARAM3 __fastcall
329: #define REGPARAM
330:
331: #include <io.h>
332: #define O_BINARY _O_BINARY
333: #define O_WRONLY _O_WRONLY
334: #define O_RDONLY _O_RDONLY
335: #define O_RDWR _O_RDWR
336: #define O_CREAT _O_CREAT
337: #define O_TRUNC _O_TRUNC
338: #define strcasecmp _tcsicmp
339: #define strncasecmp _tcsncicmp
340: #define W_OK 0x2
341: #define R_OK 0x4
342: #define STAT struct stat
343: #define DIR struct DIR
344: struct direct
345: {
346: TCHAR d_name[1];
347: };
348: #include <sys/utime.h>
349: #define utimbuf __utimbuf64
350: #define USE_ZFILE
351:
352: #undef S_ISDIR
353: #undef S_IWUSR
354: #undef S_IRUSR
355: #undef S_IXUSR
356: #define S_ISDIR(a) (a&FILEFLAG_DIR)
357: #define S_ISARC(a) (a&FILEFLAG_ARCHIVE)
358: #define S_IWUSR FILEFLAG_WRITE
359: #define S_IRUSR FILEFLAG_READ
360: #define S_IXUSR FILEFLAG_EXECUTE
361:
362: /* These are prototypes for functions from the Win32 posixemu file */
363: extern void get_time (time_t t, long* days, long* mins, long* ticks);
364: extern time_t put_time (long days, long mins, long ticks);
365:
366: /* #define DONT_HAVE_POSIX - don't need all of Mathias' posixemu_functions, just a subset (below) */
367: #define chmod(a,b) posixemu_chmod ((a), (b))
368: extern int posixemu_chmod (const TCHAR *, int);
369: #define stat(a,b) posixemu_stat ((a), (b))
370: extern int posixemu_stat (const TCHAR *, struct _stat64 *);
371: #define mkdir(x,y) mkdir(x)
372: #define truncate posixemu_truncate
373: extern int posixemu_truncate (const TCHAR *, long int);
374: #define utime posixemu_utime
375: extern int posixemu_utime (const TCHAR *, struct utimbuf *);
376: #define opendir posixemu_opendir
377: extern DIR * posixemu_opendir (const TCHAR *);
378: #define readdir posixemu_readdir
379: extern struct dirent* posixemu_readdir (DIR *);
380: #define closedir posixemu_closedir
381: extern void posixemu_closedir (DIR *);
382:
383: #endif
384:
385: #endif /* _WIN32 */
386:
387: #ifdef DONT_HAVE_POSIX
388:
389: #define access posixemu_access
390: extern int posixemu_access (const TCHAR *, int);
391: #define open posixemu_open
392: extern int posixemu_open (const TCHAR *, int, int);
393: #define close posixemu_close
394: extern void posixemu_close (int);
395: #define read posixemu_read
396: extern int posixemu_read (int, TCHAR *, int);
397: #define write posixemu_write
398: extern int posixemu_write (int, const TCHAR *, int);
399: #undef lseek
400: #define lseek posixemu_seek
401: extern int posixemu_seek (int, int, int);
402: #define stat(a,b) posixemu_stat ((a), (b))
403: extern int posixemu_stat (const TCHAR *, STAT *);
404: #define mkdir posixemu_mkdir
405: extern int mkdir (const TCHAR *, int);
406: #define rmdir posixemu_rmdir
407: extern int posixemu_rmdir (const TCHAR *);
408: #define unlink posixemu_unlink
409: extern int posixemu_unlink (const TCHAR *);
410: #define truncate posixemu_truncate
411: extern int posixemu_truncate (const TCHAR *, long int);
412: #define rename posixemu_rename
413: extern int posixemu_rename (const TCHAR *, const TCHAR *);
414: #define chmod posixemu_chmod
415: extern int posixemu_chmod (const TCHAR *, int);
416: #define tmpnam posixemu_tmpnam
417: extern void posixemu_tmpnam (TCHAR *);
418: #define utime posixemu_utime
419: extern int posixemu_utime (const TCHAR *, struct utimbuf *);
420: #define opendir posixemu_opendir
421: extern DIR * posixemu_opendir (const TCHAR *);
422: #define readdir posixemu_readdir
423: extern struct dirent* readdir (DIR *);
424: #define closedir posixemu_closedir
425: extern void closedir (DIR *);
426:
427: /* This isn't the best place for this, but it fits reasonably well. The logic
428: * is that you probably don't have POSIX errnos if you don't have the above
429: * functions. */
430: extern long dos_errno (void);
431:
432: #endif
433:
434: #ifdef DONT_HAVE_STDIO
435:
436: extern FILE *stdioemu_fopen (const TCHAR *, const TCHAR *);
437: #define fopen(a,b) stdioemu_fopen(a, b)
438: extern int stdioemu_fseek (FILE *, int, int);
439: #define fseek(a,b,c) stdioemu_fseek(a, b, c)
440: extern int stdioemu_fread (TCHAR *, int, int, FILE *);
441: #define fread(a,b,c,d) stdioemu_fread(a, b, c, d)
442: extern int stdioemu_fwrite (const TCHAR *, int, int, FILE *);
443: #define fwrite(a,b,c,d) stdioemu_fwrite(a, b, c, d)
444: extern int stdioemu_ftell (FILE *);
445: #define ftell(a) stdioemu_ftell(a)
446: extern int stdioemu_fclose (FILE *);
447: #define fclose(a) stdioemu_fclose(a)
448:
449: #endif
450:
451: #ifdef DONT_HAVE_MALLOC
452:
453: #define malloc(a) mallocemu_malloc(a)
454: extern void *mallocemu_malloc (int size);
455: #define free(a) mallocemu_free(a)
456: extern void mallocemu_free (void *ptr);
457:
458: #endif
459:
460: #ifdef X86_ASSEMBLY
461: #define ASM_SYM_FOR_FUNC(a) __asm__(a)
462: #else
463: #define ASM_SYM_FOR_FUNC(a)
464: #endif
465:
466: //#include "target.h"
467:
468: #ifdef UAE_CONSOLE
469: #undef write_log
470: #define write_log write_log_standard
471: #endif
472:
473: #if __GNUC__ - 1 > 1 || __GNUC_MINOR__ - 1 > 6
474: extern void write_log (const TCHAR *, ...) __attribute__ ((format (printf, 1, 2)));
475: #else
476: extern void write_log (const TCHAR *, ...);
477: #endif
478: extern void write_dlog (const TCHAR *, ...);
1.1.1.3 ! root 479: extern int read_log(void);
1.1 root 480:
481: extern void flush_log (void);
482: extern void close_console (void);
483: extern void reopen_console (void);
1.1.1.3 ! root 484: //extern void console_out (const TCHAR *);
! 485: //extern void console_out_f (const TCHAR *, ...);
1.1 root 486: extern void console_flush (void);
487: extern int console_get (TCHAR *, int);
488: extern TCHAR console_getch (void);
1.1.1.3 ! root 489: //extern void f_out (void *, const TCHAR *, ...);
1.1 root 490: extern TCHAR* buf_out (TCHAR *buffer, int *bufsize, const TCHAR *format, ...);
1.1.1.3 ! root 491: //extern void gui_message (const TCHAR *,...);
1.1 root 492: extern int gui_message_multibutton (int flags, const TCHAR *format,...);
493: #define write_log_err write_log
494: extern void logging_init (void);
495: extern FILE *log_open (const TCHAR *name, int append, int bootlog);
496: extern void log_close (FILE *f);
497:
498:
499: #ifndef O_BINARY
500: #define O_BINARY 0
501: #endif
502:
503: #ifndef STATIC_INLINE
504: #if __GNUC__ - 1 > 1 && __GNUC_MINOR__ - 1 >= 0
505: #define STATIC_INLINE static __inline__ __attribute__ ((always_inline))
506: #define NOINLINE __attribute__ ((noinline))
507: #define NORETURN __attribute__ ((noreturn))
508: #elif _MSC_VER
509: #define STATIC_INLINE static __forceinline
510: #define NOINLINE __declspec(noinline)
511: #define NORETURN __declspec(noreturn)
512: #else
513: #define STATIC_INLINE static __inline__
514: #define NOINLINE
515: #define NORETURN
516: #endif
517: #endif
518:
519: /* Every Amiga hardware clock cycle takes this many "virtual" cycles. This
520: used to be hardcoded as 1, but using higher values allows us to time some
521: stuff more precisely.
1.1.1.3 ! root 522: 512 is the official value from now on - it can't change, unless we want
! 523: _another_ config option "finegrain2_m68k_speed".
! 524:
1.1 root 525: We define this value here rather than in events.h so that gencpu.c sees
526: it. */
1.1.1.3 ! root 527: #define CYCLE_UNIT 512
! 528:
! 529: /* This one is used by cfgfile.c. We could reduce the CYCLE_UNIT back to 1,
! 530: I'm not 100% sure this code is bug free yet. */
! 531: #define OFFICIAL_CYCLE_UNIT 512
1.1 root 532:
533: /*
534: * You can specify numbers from 0 to 5 here. It is possible that higher
535: * numbers will make the CPU emulation slightly faster, but if the setting
536: * is too high, you will run out of memory while compiling.
537: * Best to leave this as it is.
538: */
539: #define CPU_EMU_SIZE 0
540:
541: /*
542: * Byte-swapping functions
543: */
544:
545: /* Try to use system bswap_16/bswap_32 functions. */
546: #if defined HAVE_BSWAP_16 && defined HAVE_BSWAP_32
547: # include <byteswap.h>
548: # ifdef HAVE_BYTESWAP_H
549: # include <byteswap.h>
550: # endif
551: #else
552: /* Else, if using SDL, try SDL's endian functions. */
553: # ifdef USE_SDL
554: # include <SDL_endian.h>
555: # define bswap_16(x) SDL_Swap16(x)
556: # define bswap_32(x) SDL_Swap32(x)
557: # else
558: /* Otherwise, we'll roll our own. */
559: # define bswap_16(x) (((x) >> 8) | (((x) & 0xFF) << 8))
560: # define bswap_32(x) (((x) << 24) | (((x) << 8) & 0x00FF0000) | (((x) >> 8) & 0x0000FF00) | ((x) >> 24))
561: # endif
562: #endif
563:
564: #endif
565:
566: #ifndef __cplusplus
567:
568: #define xmalloc(T, N) malloc(sizeof (T) * (N))
569: #define xcalloc(T, N) calloc(sizeof (T), N)
570: #define xfree(T) free(T)
571: #define xrealloc(T, TP, N) realloc(TP, sizeof (T) * (N))
572:
573: #if 0
574: extern void *xmalloc (size_t);
575: extern void *xcalloc (size_t, size_t);
576: extern void xfree (const void*);
577: #endif
578:
579: #else
580:
581: #define xmalloc(T, N) static_cast<T*>(malloc (sizeof (T) * (N)))
582: #define xcalloc(T, N) static_cast<T*>(calloc (sizeof (T), N))
583: #define xrealloc(T, TP, N) static_cast<T*>(realloc (TP, sizeof (T) * (N)))
584: #define xfree(T) free(T)
585:
586: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.