Better c89 compatibility

This commit is contained in:
UnknownShadow200 2025-05-13 19:55:11 +10:00
parent 9c9aa11d77
commit a1f1ce639e
4 changed files with 23 additions and 27 deletions

View File

@ -30,8 +30,8 @@ Copyright 2014-2025 ClassiCube | Licensed under BSD-3
#endif #endif
#ifndef CC_API #ifndef CC_API
#define CC_API __declspec(dllexport, noinline) #define CC_API __declspec(dllexport, noinline)
#define CC_VAR __declspec(dllexport) #define CC_VAR __declspec(dllexport)
#endif #endif
#define CC_HAS_TYPES #define CC_HAS_TYPES
@ -62,9 +62,11 @@ Copyright 2014-2025 ClassiCube | Licensed under BSD-3
#define CC_HAS_TYPES #define CC_HAS_TYPES
#endif #endif
#define CC_INLINE inline #ifndef CC_INLINE
#define CC_NOINLINE __attribute__((noinline)) #define CC_INLINE inline
#define CC_NOINLINE __attribute__((noinline))
#endif
#ifndef CC_API #ifndef CC_API
#ifdef _WIN32 #ifdef _WIN32
#define CC_API __attribute__((dllexport, noinline)) #define CC_API __attribute__((dllexport, noinline))

View File

@ -74,13 +74,6 @@ float Math_Mod1(float x) { return x - (int)x; /* fmodf(x, 1); */ }
/*########################################################################################################################* /*########################################################################################################################*
*-------------------------------------------------------Math intrinsics---------------------------------------------------* *-------------------------------------------------------Math intrinsics---------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
/* For abs(x) function */
#if defined CC_BUILD_AMIGA || defined CC_BUILD_SATURN
static int abs(int x) { return x < 0 ? -x : x; }
#else
#include <stdlib.h>
#endif
/* 32x/Saturn/GBA is missing these intrinsics */ /* 32x/Saturn/GBA is missing these intrinsics */
#if defined CC_BUILD_32X || defined CC_BUILD_SATURN || defined CC_BUILD_GBA #if defined CC_BUILD_32X || defined CC_BUILD_SATURN || defined CC_BUILD_GBA
#include "../third_party/fix16_sqrt.c" #include "../third_party/fix16_sqrt.c"
@ -120,8 +113,6 @@ float sqrtf(float x) {
float Math_SqrtF(float x) { return sqrtf(x); /* MSVC intrinsic */ } float Math_SqrtF(float x) { return sqrtf(x); /* MSVC intrinsic */ }
#endif #endif
int Math_AbsI(int x) { return abs(x); /* MSVC intrinsic */ }
/*########################################################################################################################* /*########################################################################################################################*
*--------------------------------------------------Random number generator------------------------------------------------* *--------------------------------------------------Random number generator------------------------------------------------*

View File

@ -32,7 +32,8 @@ CC_BEGIN_HEADER
#endif #endif
float Math_Mod1(float x); float Math_Mod1(float x);
int Math_AbsI(int x);
static CC_INLINE int Math_AbsI(int x) { return x < 0 ? -x : x; }
static CC_INLINE float Math_SafeDiv(float a, float b) { static CC_INLINE float Math_SafeDiv(float a, float b) {
if (Math_AbsF(b) < 0.000001f) return MATH_LARGENUM; if (Math_AbsF(b) < 0.000001f) return MATH_LARGENUM;

View File

@ -194,27 +194,29 @@ cc_bool DynamicLib_LoadAll(const cc_string* path, const struct DynamicLibSym* sy
/* Encrypts data using XTEA block cipher, with OS specific method to get machine-specific key */ /* Encrypts data using XTEA block cipher, with OS specific method to get machine-specific key */
static void EncipherBlock(cc_uint32* v, const cc_uint32* key, cc_string* dst) { static void EncipherBlock(cc_uint32* v, const cc_uint32* key, cc_string* dst) {
cc_uint32 v0 = v[0], v1 = v[1], sum = 0, delta = 0x9E3779B9; cc_uint32 v0 = v[0], v1 = v[1], sum = 0, delta = 0x9E3779B9;
int i;
for (int i = 0; i < 12; i++) for (i = 0; i < 12; i++)
{ {
v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]); v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]);
sum += delta; sum += delta;
v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]); v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]);
} }
v[0] = v0; v[1] = v1; v[0] = v0; v[1] = v1;
String_AppendAll(dst, v, 8); String_AppendAll(dst, v, 8);
} }
static void DecipherBlock(cc_uint32* v, const cc_uint32* key) { static void DecipherBlock(cc_uint32* v, const cc_uint32* key) {
cc_uint32 v0 = v[0], v1 = v[1], delta = 0x9E3779B9, sum = delta * 12; cc_uint32 v0 = v[0], v1 = v[1], delta = 0x9E3779B9, sum = delta * 12;
int i;
for (int i = 0; i < 12; i++) for (i = 0; i < 12; i++)
{ {
v1 -= (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]); v1 -= (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]);
sum -= delta; sum -= delta;
v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]); v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]);
} }
v[0] = v0; v[1] = v1; v[0] = v0; v[1] = v1;
} }
#define ENC1 0xCC005EC0 #define ENC1 0xCC005EC0