1 /*
2 * UAE - The Un*x Amiga Emulator - CPU core
3 *
4 * Big endian memory access functions.
5 *
6 * Copyright 1996 Bernd Schmidt
7 *
8 * Adaptation to Hatari by Thomas Huth, Eero Tamminen
9 *
10 * This file is distributed under the GNU General Public License, version 2
11 * or at your option any later version. Read the file gpl.txt for details.
12 */
13
14 #ifndef UAE_MACCESS_H
15 #define UAE_MACCESS_H
16
17
18 /* Can the actual CPU access unaligned memory? */
19 #ifndef CPU_CAN_ACCESS_UNALIGNED
20 # if defined(__i386__) || defined(powerpc) || defined(__mc68020__)
21 # define CPU_CAN_ACCESS_UNALIGNED 1
22 # else
23 # define CPU_CAN_ACCESS_UNALIGNED 0
24 # endif
25 #endif
26
27
28 /* If the CPU can access unaligned memory, use these accelerated functions: */
29 #if CPU_CAN_ACCESS_UNALIGNED
30
31 #include <SDL_endian.h>
32
do_get_mem_long(void * a)33 static inline uae_u32 do_get_mem_long(void *a)
34 {
35 return SDL_SwapBE32(*(uae_u32 *)a);
36 }
37
do_get_mem_word(void * a)38 static inline uae_u16 do_get_mem_word(void *a)
39 {
40 return SDL_SwapBE16(*(uae_u16 *)a);
41 }
42
43
do_put_mem_long(void * a,uae_u32 v)44 static inline void do_put_mem_long(void *a, uae_u32 v)
45 {
46 *(uae_u32 *)a = SDL_SwapBE32(v);
47 }
48
do_put_mem_word(void * a,uae_u16 v)49 static inline void do_put_mem_word(void *a, uae_u16 v)
50 {
51 *(uae_u16 *)a = SDL_SwapBE16(v);
52 }
53
54
55 #else /* Cpu can not access unaligned memory: */
56
57
do_get_mem_long(void * a)58 static inline uae_u32 do_get_mem_long(void *a)
59 {
60 uae_u8 *b = (uae_u8 *)a;
61
62 return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];
63 }
64
do_get_mem_word(void * a)65 static inline uae_u16 do_get_mem_word(void *a)
66 {
67 uae_u8 *b = (uae_u8 *)a;
68
69 return (b[0] << 8) | b[1];
70 }
71
72
do_put_mem_long(void * a,uae_u32 v)73 static inline void do_put_mem_long(void *a, uae_u32 v)
74 {
75 uae_u8 *b = (uae_u8 *)a;
76
77 b[0] = v >> 24;
78 b[1] = v >> 16;
79 b[2] = v >> 8;
80 b[3] = v;
81 }
82
do_put_mem_word(void * a,uae_u16 v)83 static inline void do_put_mem_word(void *a, uae_u16 v)
84 {
85 uae_u8 *b = (uae_u8 *)a;
86
87 b[0] = v >> 8;
88 b[1] = v;
89 }
90
91
92 #endif /* CPU_CAN_ACCESS_UNALIGNED */
93
94
95 /* These are same for all architectures: */
96
do_get_mem_byte(uae_u8 * a)97 static inline uae_u8 do_get_mem_byte(uae_u8 *a)
98 {
99 return *a;
100 }
101
do_put_mem_byte(uae_u8 * a,uae_u8 v)102 static inline void do_put_mem_byte(uae_u8 *a, uae_u8 v)
103 {
104 *a = v;
105 }
106
107
108 #endif /* UAE_MACCESS_H */
109