home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / quakeworld_src / client / sys_timerppc.s < prev    next >
Encoding:
Text File  |  2000-06-17  |  3.2 KB  |  171 lines

  1. # Copyright (C) 1996-1997 Id Software, Inc. 
  2. # This program is free software; you can redistribute it and/or 
  3. # modify it under the terms of the GNU General Public License 
  4. # as published by the Free Software Foundation; either version 2 
  5. # of the License, or (at your option) any later version. 
  6. # This program is distributed in the hope that it will be useful, 
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of 
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   
  9. # See the GNU General Public License for more details. 
  10. # You should have received a copy of the GNU General Public License 
  11. # along with this program; if not, write to the Free Software 
  12. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
  13.  
  14.  
  15. # Determine PPC bus clock by using CIA timers.
  16. # Based on powerpc.library source by Sam Jordan. Thanks Sam!
  17. # ** This code is used for the PowerUp port only **
  18.  
  19.  
  20. # CIATIMER structure
  21. .set    CIATIMER_RESOURCE,    0
  22. .set    CIATIMER_INTERRUPT,    4
  23. .set    CIATIMER_CONTROL,    8
  24. .set    CIATIMER_LOW,        12
  25. .set    CIATIMER_HIGH,        16
  26. .set    CIATIMER_STOPMASK,    20
  27. .set    CIATIMER_STARTMASK,    21
  28. .set    CIATIMER_ICRBIT,    22
  29. .set    CIATIMER_ECLOCK,    24
  30. .set    CIATIMER_SIZE,        28
  31.  
  32.  
  33.     .text
  34.  
  35.  
  36.     .align    3
  37.     .globl    MeasureBusClock
  38. MeasureBusClock:
  39. # r3 = ciatimer structure pointer
  40. # -> r3 = bus clock in microseconds
  41.  
  42.     mflr    r0
  43.     stw    r0,4(r1)
  44.     stwu    r1,-16(r1)
  45.     li    r10,-1
  46.     lwz    r4,CIATIMER_CONTROL(r3)
  47.     lwz    r5,CIATIMER_LOW(r3)
  48.     lwz    r6,CIATIMER_HIGH(r3)
  49.     lbz    r7,CIATIMER_STOPMASK(r3)
  50.     lbz    r8,CIATIMER_STARTMASK(r3)
  51.     lbz    r0,0(r4)
  52.     and    r0,r0,r7
  53.     stb    r0,0(r4)        # stop CIA timer
  54.     stb    r10,0(r5)        # set to 0xffff
  55.     stb    r10,0(r6)
  56.     lbz    r0,0(r4)
  57.     or    r0,r0,r8
  58.     mftbl    r9            # PPC start time
  59.     stb    r0,0(r4)        # start CIA timer
  60.     sync
  61. check:
  62.     lbz    r0,0(r6)
  63.     mr.    r0,r0
  64.     bne    check
  65. check2:
  66.     lbz    r0,0(r6)
  67.     mr.    r0,r0
  68.     beq    check2
  69. check3:
  70.     lbz    r0,0(r6)
  71.     mr.    r0,r0
  72.     bne    check3
  73.     mftbl    r8            # PPC stop time
  74.     lbz    r6,0(r5)
  75.     lbz    r0,0(r4)
  76.     and    r0,r0,r7
  77.     stb    r0,0(r4)        # stop CIA timer
  78.     subf    r8,r9,r8        # PPC timer difference
  79.     lis    r7,0x1ffff@h
  80.     ori    r7,r7,0x1ffff@l
  81.     subf    r7,r6,r7
  82.     lwz    r5,CIATIMER_ECLOCK(r3)
  83.     lis    r9,4000000000@h
  84.     ori    r9,r9,4000000000@l
  85.     mullw    r4,r7,r9
  86.     mulhwu    r3,r7,r9
  87.     bl    Div64_32
  88.     mr    r5,r3
  89.     mullw    r4,r8,r9
  90.     mulhwu    r3,r8,r9
  91.     bl    Div64_32
  92.     slwi    r3,r3,2            # PPC timer is busclock/4
  93.     addi    r1,r1,16
  94.     lwz    r0,4(r1)
  95.     mtlr    r0
  96.     blr
  97.  
  98.     .type    MeasureBusClock,@function
  99.     .size    MeasureBusClock,$-MeasureBusClock
  100.  
  101.  
  102.     .align    3
  103.     .globl    CorrectBusClock
  104. CorrectBusClock:
  105. # r3 = bus clock measured
  106. # -> r3 = bus clock corrected
  107.  
  108.     mr    r5,r3
  109.     mulli    r3,r3,3
  110.     lis    r4,5000000@h
  111.     ori    r4,r4,5000000@l
  112.     add    r3,r3,r4
  113.     lis    r4,10000000@h
  114.     ori    r4,r4,10000000@l
  115.     divwu    r3,r3,r4
  116.     mullw    r3,r3,r4
  117.     li    r4,3
  118.     divwu    r3,r3,r4
  119.     blr
  120.  
  121.     .type    CorrectBusClock,@function
  122.     .size    CorrectBusClock,$-CorrectBusClock
  123.  
  124.  
  125.     .align    3
  126. Div64_32:
  127.     mfctr    r0
  128.     stwu    r1,-32(r1)
  129.     stw    r0,8(r1)
  130.     stw    r4,12(r1)
  131.     stw    r5,16(r1)
  132.     stw    r6,20(r1)
  133.     li    r0,32
  134.     mtctr    r0
  135.     li    r6,0
  136. loop:
  137.     mr.    r3,r3
  138.     bge    cont
  139.     addc    r4,r4,r4
  140.     adde    r3,r3,r3
  141.     add    r6,r6,r6
  142.     b    cont1
  143. cont:
  144.     addc    r4,r4,r4
  145.     adde    r3,r3,r3
  146.     add    r6,r6,r6
  147.     cmplw    r5,r3
  148.     bgt    cont2
  149. cont1:
  150.     subf.    r3,r5,r3
  151.     addi    r6,r6,1
  152. cont2:
  153.     bdnz    loop
  154.     lwz    r0,8(r1)
  155.     mr    r3,r6
  156.     mtctr    r0
  157.     lwz    r4,12(r1)
  158.     lwz    r5,16(r1)
  159.     lwz    r6,20(r1)
  160.     addi    r1,r1,32
  161.     blr
  162.  
  163.     .type    Div64_32,@function
  164.     .size    Div64_32,$-Div64_32
  165.