X-Git-Url: http://deadsoftware.ru/gitweb?p=flatwaifu.git;a=blobdiff_plain;f=src%2Fmiscc.c;h=4f5a302458bda126792daa857a8fb9fb14917e0e;hp=7123938b16356714846b4fed3ba705b5ab6c4c19;hb=da79be9b6a4134aa9cd19e6f5909fedb20d318cb;hpb=e5c2eddc151a59db4e611a77901732d7c15fde90 diff --git a/src/miscc.c b/src/miscc.c index 7123938..4f5a302 100644 --- a/src/miscc.c +++ b/src/miscc.c @@ -613,33 +613,43 @@ void Z_calc_time(dword t,word *h,word *m,word *s) *h = t; } -unsigned short int short2host (unsigned short int x) { -#if __BIG_ENDIAN__ +#define SWAP_VAR(a, b) do { unsigned char t = a; a = b; b = t; } while(0) + +uint16_t short2swap (uint16_t x) { union { - unsigned char a[2]; - unsigned short int x; + uint8_t a[2]; + uint16_t x; } y; y.x = x; - unsigned char t = y.a[0]; y.a[0] = y.a[1]; y.a[1] = t; + SWAP_VAR(y.a[0], y.a[1]); return y.x; -#else - return x; -#endif } -unsigned int int2host (unsigned int x) { -#if __BIG_ENDIAN__ +uint32_t int2swap (uint32_t x) { union { - unsigned char a[4]; - unsigned int x; + uint8_t a[4]; + uint32_t x; } y; y.x = x; - #define SWAP_VAR(a, b) do { unsigned char t = a; a = b; b = t; } while(0) SWAP_VAR(y.a[0], y.a[3]); SWAP_VAR(y.a[1], y.a[2]); - #undef SWAP_VAR return y.x; +} + +#undef SWAP_VAR + +uint16_t short2host (uint16_t x) { +#if __BIG_ENDIAN__ + return short2swap(x); #else return x; #endif } + +uint32_t int2host (uint32_t x) { +#if __BIG_ENDIAN__ + return int2swap(x); +#else + return x; +#endif +} \ No newline at end of file