workaround a problem with the harmattan gcc
[drnoksnes] / sar.h
1 /*******************************************************************************
2   Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3  
4   (c) Copyright 1996 - 2003 Gary Henderson (gary.henderson@ntlworld.com) and
5                             Jerremy Koot (jkoot@snes9x.com)
6
7   (c) Copyright 2002 - 2003 Matthew Kendora and
8                             Brad Jorsch (anomie@users.sourceforge.net)
9  
10
11                       
12   C4 x86 assembler and some C emulation code
13   (c) Copyright 2000 - 2003 zsKnight (zsknight@zsnes.com),
14                             _Demo_ (_demo_@zsnes.com), and
15                             Nach (n-a-c-h@users.sourceforge.net)
16                                           
17   C4 C++ code
18   (c) Copyright 2003 Brad Jorsch
19
20   DSP-1 emulator code
21   (c) Copyright 1998 - 2003 Ivar (ivar@snes9x.com), _Demo_, Gary Henderson,
22                             John Weidman (jweidman@slip.net),
23                             neviksti (neviksti@hotmail.com), and
24                             Kris Bleakley (stinkfish@bigpond.com)
25  
26   DSP-2 emulator code
27   (c) Copyright 2003 Kris Bleakley, John Weidman, neviksti, Matthew Kendora, and
28                      Lord Nightmare (lord_nightmare@users.sourceforge.net
29
30   OBC1 emulator code
31   (c) Copyright 2001 - 2003 zsKnight, pagefault (pagefault@zsnes.com)
32   Ported from x86 assembler to C by sanmaiwashi
33
34   SPC7110 and RTC C++ emulator code
35   (c) Copyright 2002 Matthew Kendora with research by
36                      zsKnight, John Weidman, and Dark Force
37
38   S-RTC C emulator code
39   (c) Copyright 2001 John Weidman
40   
41   Super FX x86 assembler emulator code 
42   (c) Copyright 1998 - 2003 zsKnight, _Demo_, and pagefault 
43
44   Super FX C emulator code 
45   (c) Copyright 1997 - 1999 Ivar and Gary Henderson.
46
47
48
49  
50   Specific ports contains the works of other authors. See headers in
51   individual files.
52  
53   Snes9x homepage: http://www.snes9x.com
54  
55   Permission to use, copy, modify and distribute Snes9x in both binary and
56   source form, for non-commercial purposes, is hereby granted without fee,
57   providing that this license information and copyright notice appear with
58   all copies and any derived work.
59  
60   This software is provided 'as-is', without any express or implied
61   warranty. In no event shall the authors be held liable for any damages
62   arising from the use of this software.
63  
64   Snes9x is freeware for PERSONAL USE only. Commercial users should
65   seek permission of the copyright holders first. Commercial use includes
66   charging money for Snes9x or software derived from Snes9x.
67  
68   The copyright holders request that bug fixes and improvements to the code
69   should be forwarded to them so everyone can benefit from the modifications
70   in future versions.
71  
72   Super NES and Super Nintendo Entertainment System are trademarks of
73   Nintendo Co., Limited and its subsidiary companies.
74 *******************************************************************************/
75
76 #ifndef _SAR_H_
77 #define _SAR_H_
78
79 #ifdef HAVE_CONFIG_H
80         #include <config.h>
81 #endif
82
83 #include "port.h"
84
85 #ifndef snes9x_types_defined
86 #define snes9x_types_defined
87
88 typedef unsigned char uint8;
89 typedef unsigned short uint16;
90 typedef unsigned int uint32;
91 typedef unsigned char bool8;
92 typedef signed char int8;
93 typedef short int16;
94 typedef int int32;
95 #endif
96
97 #ifdef RIGHTSHIFT_IS_SAR
98 #define SAR(b, n) ((b)>>(n))
99 #else
100
101 static inline int8 SAR(const int8 b, const int n){
102 #ifndef RIGHTSHIFT_INT8_IS_SAR
103     if(b<0) return (b>>n)|(-1<<(8-n));
104 #endif
105     return b>>n;
106 }
107
108 static inline int16 SAR(const int16 b, const int n){
109 #ifndef RIGHTSHIFT_INT16_IS_SAR
110     if(b<0) return (b>>n)|(-1<<(16-n));
111 #endif
112     return b>>n;
113 }
114
115 static inline int32 SAR(const int32 b, const int n){
116 #ifndef RIGHTSHIFT_INT32_IS_SAR
117     if(b<0) return (b>>n)|(-1<<(32-n));
118 #endif
119     return b>>n;
120 }
121
122 static inline int64 SAR(const int64 b, const int n){
123 #ifndef RIGHTSHIFT_INT64_IS_SAR
124     if(b<0) return (b>>n)|(-1<<(64-n));
125 #endif
126     return b>>n;
127 }
128
129 #endif
130
131 #endif