summaryrefslogtreecommitdiff
path: root/apps/plugins/sdl/progs/quake/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/sdl/progs/quake/common.c')
-rw-r--r--apps/plugins/sdl/progs/quake/common.c97
1 files changed, 76 insertions, 21 deletions
diff --git a/apps/plugins/sdl/progs/quake/common.c b/apps/plugins/sdl/progs/quake/common.c
index 11be234834..5e842b09ae 100644
--- a/apps/plugins/sdl/progs/quake/common.c
+++ b/apps/plugins/sdl/progs/quake/common.c
@@ -446,58 +446,111 @@ float (*LittleFloat) (float l);
446 446
447short ShortSwap (short l) 447short ShortSwap (short l)
448{ 448{
449 byte b1,b2; 449 byte b1,b2;
450 450
451 b1 = l&255; 451 b1 = l&255;
452 b2 = (l>>8)&255; 452 b2 = (l>>8)&255;
453 453
454 return (b1<<8) + b2; 454 return (b1<<8) + b2;
455} 455}
456 456
457short ShortNoSwap (short l) 457short ShortNoSwap (short l)
458{ 458{
459 return l; 459 return l;
460} 460}
461 461
462int LongSwap (int l) 462int LongSwap (int l)
463{ 463{
464 byte b1,b2,b3,b4; 464 byte b1,b2,b3,b4;
465 465
466 b1 = l&255; 466 b1 = l&255;
467 b2 = (l>>8)&255; 467 b2 = (l>>8)&255;
468 b3 = (l>>16)&255; 468 b3 = (l>>16)&255;
469 b4 = (l>>24)&255; 469 b4 = (l>>24)&255;
470 470
471 return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4; 471 return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
472} 472}
473 473
474int LongNoSwap (int l) 474int LongNoSwap (int l)
475{ 475{
476 return l; 476 return l;
477} 477}
478 478
479float FloatSwap (float f) 479float FloatSwap (float f)
480{ 480{
481 union
482 {
483 float f;
484 byte b[4];
485 } dat1, dat2;
486
487
488 dat1.f = f;
489 dat2.b[0] = dat1.b[3];
490 dat2.b[1] = dat1.b[2];
491 dat2.b[2] = dat1.b[1];
492 dat2.b[3] = dat1.b[0];
493 return dat2.f;
494}
495
496float FloatNoSwap (float f)
497{
498 return f;
499}
500
501// safe for unaligned accesses
502short ReadLittleShort (char *l)
503{
504 return *(l + 0) | (*(l + 1) << 8);
505}
506
507short ReadBigShort (char *l)
508{
509 return *(l + 1) | (*(l + 0) << 8);
510}
511
512int ReadLittleLong (char *l)
513{
514 return *(l + 0) | (*(l + 1) << 8) | (*(l + 2) << 16) | (*(l + 3) << 24);
515}
516
517int ReadBigLong (char *l)
518{
519 return *(l + 3) | (*(l + 2) << 8) | (*(l + 1) << 16) | (*(l + 0) << 24);
520}
521
522// same
523float ReadLittleFloat (char *f)
524{
481 union 525 union
482 { 526 {
483 float f; 527 float f;
484 byte b[4]; 528 byte b[4];
485 } dat1, dat2; 529 } dat2;
486 530
487 531
488 dat1.f = f; 532 dat2.b[0] = f[0];
489 dat2.b[0] = dat1.b[3]; 533 dat2.b[1] = f[1];
490 dat2.b[1] = dat1.b[2]; 534 dat2.b[2] = f[2];
491 dat2.b[2] = dat1.b[1]; 535 dat2.b[3] = f[3];
492 dat2.b[3] = dat1.b[0];
493 return dat2.f; 536 return dat2.f;
494} 537}
495 538
496float FloatNoSwap (float f) 539float ReadBigFloat (char *f)
497{ 540{
498 return f; 541 union
542 {
543 float f;
544 byte b[4];
545 } dat2;
546
547
548 dat2.b[0] = f[0];
549 dat2.b[1] = f[1];
550 dat2.b[2] = f[2];
551 dat2.b[3] = f[3];
552 return dat2.f;
499} 553}
500
501/* 554/*
502============================================================================== 555==============================================================================
503 556
@@ -1136,6 +1189,7 @@ void COM_Init (char *basedir)
1136{ 1189{
1137 byte swaptest[2] = {1,0}; 1190 byte swaptest[2] = {1,0};
1138 1191
1192#if 1
1139// set the byte swapping variables in a portable manner 1193// set the byte swapping variables in a portable manner
1140#ifdef SDL 1194#ifdef SDL
1141 // This is necessary because egcs 1.1.1 mis-compiles swaptest with -O2 1195 // This is necessary because egcs 1.1.1 mis-compiles swaptest with -O2
@@ -1162,6 +1216,7 @@ void COM_Init (char *basedir)
1162 BigFloat = FloatNoSwap; 1216 BigFloat = FloatNoSwap;
1163 LittleFloat = FloatSwap; 1217 LittleFloat = FloatSwap;
1164 } 1218 }
1219#endif
1165 1220
1166 Cvar_RegisterVariable (&registered); 1221 Cvar_RegisterVariable (&registered);
1167 Cvar_RegisterVariable (&cmdline); 1222 Cvar_RegisterVariable (&cmdline);