diff options
author | Sebastian Leonhardt <sebastian.leonhardt@web.de> | 2016-01-08 01:05:36 +0100 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2024-06-30 17:24:16 -0400 |
commit | 102c3742487dba76ec72d5f56a2c3041344b2d68 (patch) | |
tree | 4931ad34d2cc0bac56d9984b9ead355d012ad63a /apps/plugins/xrick/system/basic_funcs.h | |
parent | 6f1e67e5e318ba2fd0f5ec1892c7b6633ec6521c (diff) | |
download | rockbox-102c3742487dba76ec72d5f56a2c3041344b2d68.tar.gz rockbox-102c3742487dba76ec72d5f56a2c3041344b2d68.zip |
added xrick game
original xrick code by 'BigOrno' at:
http://www.bigorno.net/xrick/
Rockbox port, plus bugfixes at:
https://github.com/pierluigi-vicinanza/xrick
Further changes:
* Additonal fixes from g#3026
* Port to modern plugin API
* Add Pluginlib keymap fallback
* Support all >1bpp screens
* Fix build warnings in miniz
* Better error message when resources are missing
Change-Id: Id83928bc2539901b0221692f65cbca41389c58e7
Diffstat (limited to 'apps/plugins/xrick/system/basic_funcs.h')
-rw-r--r-- | apps/plugins/xrick/system/basic_funcs.h | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/apps/plugins/xrick/system/basic_funcs.h b/apps/plugins/xrick/system/basic_funcs.h new file mode 100644 index 0000000000..1ac5c58d32 --- /dev/null +++ b/apps/plugins/xrick/system/basic_funcs.h | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | * xrick/system/basic_funcs.h | ||
3 | * | ||
4 | * Copyright (C) 2008-2014 Pierluigi Vicinanza. All rights reserved. | ||
5 | * | ||
6 | * The use and distribution terms for this software are contained in the file | ||
7 | * named README, which can be found in the root of this distribution. By | ||
8 | * using this software in any fashion, you are agreeing to be bound by the | ||
9 | * terms of this license. | ||
10 | * | ||
11 | * You must not remove this notice, or any other, from this software. | ||
12 | */ | ||
13 | |||
14 | #ifndef _BASIC_FUNCS_H | ||
15 | #define _BASIC_FUNCS_H | ||
16 | |||
17 | #include "xrick/system/basic_types.h" | ||
18 | #include "xrick/system/system.h" | ||
19 | |||
20 | #ifdef __WIN32__ | ||
21 | /* Windows is little endian only */ | ||
22 | # define __ORDER_LITTLE_ENDIAN__ 1234 | ||
23 | # define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ | ||
24 | # define USE_DEFAULT_ENDIANNESS_FUNCTIONS | ||
25 | # include <stdlib.h> /* _byteswap_XXX */ | ||
26 | |||
27 | #elif defined(ROCKBOX) | ||
28 | /* Rockbox*/ | ||
29 | # include "plugin.h" | ||
30 | # define __ORDER_LITTLE_ENDIAN__ 1234 | ||
31 | # define __ORDER_BIG_ENDIAN__ 4321 | ||
32 | # ifdef ROCKBOX_BIG_ENDIAN | ||
33 | # define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__ | ||
34 | # else | ||
35 | # define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ | ||
36 | # endif | ||
37 | |||
38 | #elif (defined(__FreeBSD__) && __FreeBSD_version >= 470000) || defined(__OpenBSD__) || defined(__NetBSD__) | ||
39 | /* *BSD */ | ||
40 | # include <sys/endian.h> | ||
41 | # define __ORDER_BIG_ENDIAN__ BIG_ENDIAN | ||
42 | # define __ORDER_LITTLE_ENDIAN__ LITTLE_ENDIAN | ||
43 | # define __BYTE_ORDER__ BYTE_ORDER | ||
44 | |||
45 | #elif (defined(BSD) && (BSD >= 199103)) || defined(__MacOSX__) | ||
46 | /* more BSD */ | ||
47 | # include <machine/endian.h> | ||
48 | # define __ORDER_BIG_ENDIAN__ BIG_ENDIAN | ||
49 | # define __ORDER_LITTLE_ENDIAN__ LITTLE_ENDIAN | ||
50 | # define __BYTE_ORDER__ BYTE_ORDER | ||
51 | |||
52 | #elif defined(__linux__) /*|| defined (__BEOS__)*/ | ||
53 | /* Linux, BeOS */ | ||
54 | # include <endian.h> | ||
55 | # define betoh16(x) be16toh(x) | ||
56 | # define letoh16(x) le16toh(x) | ||
57 | # define betoh32(x) be32toh(x) | ||
58 | # define letoh32(x) le32toh(x) | ||
59 | |||
60 | #else | ||
61 | /* shall we just '#include <endian.h>'? */ | ||
62 | # define USE_DEFAULT_ENDIANNESS_FUNCTIONS | ||
63 | |||
64 | #endif /* __WIN32__ */ | ||
65 | |||
66 | /* define default endianness */ | ||
67 | #ifndef __ORDER_LITTLE_ENDIAN__ | ||
68 | # define __ORDER_LITTLE_ENDIAN__ 1234 | ||
69 | #endif | ||
70 | |||
71 | #ifndef __ORDER_BIG_ENDIAN__ | ||
72 | # define __ORDER_BIG_ENDIAN__ 4321 | ||
73 | #endif | ||
74 | |||
75 | #ifndef __BYTE_ORDER__ | ||
76 | # warning "Byte order not defined on your system, assuming little endian!" | ||
77 | # define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ | ||
78 | #endif | ||
79 | |||
80 | /* provide default endianness functions */ | ||
81 | #ifdef USE_DEFAULT_ENDIANNESS_FUNCTIONS | ||
82 | |||
83 | # define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) | ||
84 | |||
85 | inline uint32_t swap32(uint32_t x) | ||
86 | { | ||
87 | # ifdef _MSC_VER | ||
88 | return _byteswap_ulong(x); | ||
89 | # elif (GCC_VERSION > 40300) || defined(__clang__) | ||
90 | return __builtin_bswap32(x); | ||
91 | # else | ||
92 | return (x >> 24) | | ||
93 | ((x >> 8) & 0x0000FF00) | | ||
94 | ((x << 8) & 0x00FF0000) | | ||
95 | (x << 24); | ||
96 | # endif /* _MSC_VER */ | ||
97 | } | ||
98 | |||
99 | inline uint16_t swap16(uint16_t x) | ||
100 | { | ||
101 | # ifdef _MSC_VER | ||
102 | return _byteswap_ushort(x); | ||
103 | # elif (GCC_VERSION > 40800) || defined(__clang__) | ||
104 | return __builtin_bswap16(x); | ||
105 | # else | ||
106 | return (x << 8)|(x >> 8); | ||
107 | # endif /* _MSC_VER */ | ||
108 | } | ||
109 | |||
110 | # if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__) | ||
111 | inline uint16_t htobe16(uint16_t host) { return swap16(host); } | ||
112 | inline uint16_t htole16(uint16_t host) { return host; } | ||
113 | inline uint16_t betoh16(uint16_t big_endian) { return swap16(big_endian); } | ||
114 | inline uint16_t letoh16(uint16_t little_endian) { return little_endian; } | ||
115 | |||
116 | inline uint32_t htobe32(uint32_t host) { return swap32(host); } | ||
117 | inline uint32_t htole32(uint32_t host) { return host; } | ||
118 | inline uint32_t betoh32(uint32_t big_endian) { return swap32(big_endian); } | ||
119 | inline uint32_t letoh32(uint32_t little_endian) { return little_endian; } | ||
120 | |||
121 | # elif (__BYTE_ORDER__==__ORDER_BIG_ENDIAN__) | ||
122 | inline uint16_t htobe16(uint16_t host) { return host; } | ||
123 | inline uint16_t htole16(uint16_t host) { return swap16(host); } | ||
124 | inline uint16_t betoh16(uint16_t big_endian) { return big_endian; } | ||
125 | inline uint16_t letoh16(uint16_t little_endian) { return swap16(little_endian); } | ||
126 | |||
127 | inline uint32_t htobe32(uint32_t host) { return host; } | ||
128 | inline uint32_t htole32(uint32_t host) { return swap32(host); } | ||
129 | inline uint32_t betoh32(uint32_t big_endian) { return big_endian; } | ||
130 | inline uint32_t letoh32(uint32_t little_endian) { return swap32(little_endian); } | ||
131 | |||
132 | # else | ||
133 | # error "Unknown/unsupported byte order!" | ||
134 | |||
135 | # endif | ||
136 | |||
137 | #endif /* USE_DEFAULT_ENDIANNESS_FUNCTIONS */ | ||
138 | |||
139 | #endif /* ndef _BASIC_FUNCS_H */ | ||
140 | |||
141 | /* eof */ | ||