home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / quakeworld_src / client / sys_timer.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-17  |  2.5 KB  |  90 lines

  1. /* 
  2. Copyright (C) 1996-1997 Id Software, Inc. 
  3.  
  4. This program is free software; you can redistribute it and/or 
  5. modify it under the terms of the GNU General Public License 
  6. as published by the Free Software Foundation; either version 2 
  7. of the License, or (at your option) any later version. 
  8.  
  9. This program is distributed in the hope that it will be useful, 
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of 
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   
  12.  
  13. See the GNU General Public License for more details. 
  14.  
  15. You should have received a copy of the GNU General Public License 
  16. along with this program; if not, write to the Free Software 
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
  18.  
  19. */ 
  20.  
  21. /*
  22. ** GetSysTimerPPC emulation for PowerUp by Frank Wille <frank@phoenix.owl.de>
  23. ** Bus clock determination code is based on powerpc.library source
  24. ** by Sam Jordan. Thanks Sam!
  25. */
  26.  
  27. #pragma amig-align
  28. #include <devices/timer.h>
  29. #include <powerup/ppclib/time.h>
  30. #include <powerup/gcclib/powerup_protos.h>
  31. #pragma default-align
  32. #include "sys_timer.h"
  33.  
  34.  
  35. static char gap1[32];
  36. static struct ciatimer ctim;
  37. static char gap2[32];
  38. static ULONG TicksPerSec[2];
  39.  
  40.  
  41. #ifdef __VBCC__
  42. ULONG mftbu(void) = "\tmftbu\t3";
  43. ULONG mftbl(void) = "\tmftbl\t3";
  44. #else
  45. #error Please write an external assembler module for mftbl/mftbu
  46. #endif
  47.  
  48.  
  49.  
  50. void InitSysTimePPC(void)
  51. {
  52.   static ULONG one[2] = { 1,0 };
  53.   struct Caos MyCaos;
  54.   unsigned long clk;
  55.  
  56.   PPCCacheFlush(&ctim,sizeof(struct ciatimer));
  57.   MyCaos.caos_Un.Function = (APTR)ReserveCIA;
  58.   MyCaos.a0 = (ULONG)&ctim;
  59.   MyCaos.M68kCacheMode = IF_CACHEFLUSHALL;
  60.   MyCaos.PPCCacheMode = IF_CACHEFLUSHALL;
  61.   if (PPCCallM68k(&MyCaos)) {  /* ReserveCIA() */
  62.     /* This should run in supervisor mode, for a better precision, */
  63.     /* but it seems sufficient for Quake... */
  64.     clk = MeasureBusClock(&ctim);
  65.     MyCaos.caos_Un.Function = (APTR)FreeCIA;
  66.     MyCaos.a0 = (ULONG)&ctim;
  67.     MyCaos.M68kCacheMode = IF_CACHEFLUSHALL;
  68.     MyCaos.PPCCacheMode = IF_CACHEFLUSHALL;
  69.     PPCCallM68k(&MyCaos);  /* FreeCIA() */
  70.   }
  71.   TicksPerSec[0] = 0;
  72.   TicksPerSec[1] = CorrectBusClock(clk) >> 2; /* PPC timer counts every 4th */
  73. }
  74.  
  75.  
  76. void GetSysTimePPC(struct timeval *tv)
  77. {
  78.   static ULONG mill[2] = { 0,1000000 };
  79.   ULONG r[2],secs[2];
  80.  
  81.   secs[0] = r[0] = mftbu();
  82.   secs[1] = r[1] = mftbl();
  83.   PPCDivu64p((int *)secs,(int *)TicksPerSec);
  84.   tv->tv_secs = secs[1];
  85.   PPCModu64p((int *)r,(int *)TicksPerSec);
  86.   PPCMulu64p((int *)r,(int *)mill);
  87.   PPCDivu64p((int *)r,(int *)TicksPerSec);
  88.   tv->tv_micro = r[1];
  89. }
  90.