home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / quake_src / sys_timer68k.s < prev    next >
Text File  |  2000-06-17  |  4KB  |  210 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. ; M68k support routines for determining PPC bus clock.
  16. ; Reserves/frees CIA timer for PPC.
  17. ; Based on powerpc.library source by Sam Jordan. Thanks Sam!
  18. ; ** This code is used for the PowerUp port only **
  19.  
  20.  
  21.     include    "exec/interrupts.i"
  22.     include    "devices/timer.i"
  23.     include    "hardware/cia.i"
  24.  
  25.  
  26. ; exec, timer and cia LVOs (PowerUp amiga.lib doesn't include those?)
  27. _LVODisable        =    -120
  28. _LVOEnable        =    -126
  29. _LVOOpenResource    =    -498
  30. _LVOCacheClearU        =    -636
  31. _LVOReadEClock        =    -60
  32. _LVOAddICRVector    =    -6
  33. _LVORemICRVector    =    -12
  34. _LVOAbleICR        =    -18
  35.  
  36. ; The CIAs
  37. CIA_A            =    $bfe001
  38. CIA_B            =    $bfd000
  39.  
  40. ; CIATIMER structure
  41. CIATIMER_RESOURCE    =    0
  42. CIATIMER_INTERRUPT    =    4
  43. CIATIMER_CONTROL    =    8
  44. CIATIMER_LOW        =    12
  45. CIATIMER_HIGH        =    16
  46. CIATIMER_STOPMASK    =    20
  47. CIATIMER_STARTMASK    =    21
  48. CIATIMER_ICRBIT        =    22
  49. CIATIMER_ECLOCK        =    24
  50. CIATIMER_SIZE        =    28
  51.  
  52. ; macros
  53.     macro    CALLSYS
  54.     move.l    SysBase,a6
  55.     jsr    _LVO\1(a6)
  56.     endm
  57.  
  58.  
  59. ; external symbols (from PPC)
  60.  
  61.     xref    SysBase
  62.     xref    TimerBase
  63.  
  64.  
  65.  
  66.     code
  67.  
  68.  
  69.  
  70.     cnop    0,4
  71.     xdef    ReserveCIA
  72. ReserveCIA:
  73. ; Reserves a CIA timer and initializes ciatimer structure.
  74. ; a0 = ciatimer structure pointer
  75. ; -> d0 = success (0=error, -1=success)
  76.  
  77.     movem.l    d1-d7/a0-a6,-(sp)
  78.     move.l    a0,d2
  79.     lea    DummyInt,a3
  80.     lea    DummyIntName(pc),a0
  81.     move.l    a0,LN_NAME(a3)
  82.     clr.l    IS_DATA(a3)
  83.     lea    DummyInterrupt(pc),a0
  84.     move.l    a0,IS_CODE(a3)
  85.     lea    CIA_A,a5
  86.     lea    CIAA_name(pc),a1
  87.     CALLSYS    OpenResource
  88.     tst.l    d0
  89.     beq    .error
  90. .loop:
  91.     move.l    d0,a2
  92.     CALLSYS    Disable
  93.     move.l    #ciacra,d7
  94.     move.l    #ciatalo,d6
  95.     move.l    #ciatahi,d5
  96.     move.b    #CIACRAF_TODIN|CIACRAF_PBON|CIACRAF_OUTMODE|CIACRAF_SPMODE,d4
  97.     move.b    #CIACRAF_START,d3
  98.     move.l    a2,a6
  99.     move.w    #CIAICRB_TA,d0
  100.     move.l    d0,-(sp)
  101.     move.l    a3,a1
  102.     jsr    _LVOAddICRVector(a6)
  103.     move.l    (sp)+,d1
  104.     tst.l    d0
  105.     beq    .timerfound
  106.     move.b    #CIACRBF_ALARM|CIACRBF_PBON|CIACRBF_OUTMODE,d4
  107.     move.b    #CIACRBF_START,d3
  108.     move.l    a2,a6
  109.     move.w    #CIAICRB_TB,d0
  110.     move.l    d0,-(sp)
  111.     move.l    a3,a1
  112.     jsr    _LVOAddICRVector(a6)
  113.     move.l    (sp)+,d1
  114.     tst.l    d0
  115.     beq    .timerfound
  116.     CALLSYS    Enable
  117.     lea    CIA_B,a5
  118.     lea    CIAB_name(pc),a1
  119.     CALLSYS    OpenResource
  120.     tst.l    d0
  121.     beq    .error
  122.     bra    .loop
  123.  
  124. .timerfound:
  125.     move.l    a2,a6
  126.     move.w    d1,d0
  127.     move.l    d1,-(sp)
  128.     CALLSYS    AbleICR
  129.     CALLSYS    Enable
  130.     move.l    (sp)+,d1
  131.     move.l    d2,a0
  132.     add.l    a5,d7
  133.     add.l    a5,d6
  134.     add.l    a5,d5
  135.     move.l    a2,CIATIMER_RESOURCE(a0)
  136.     move.l    a3,CIATIMER_INTERRUPT(a0)
  137.     move.l    d7,CIATIMER_CONTROL(a0)
  138.     move.l    d6,CIATIMER_LOW(a0)
  139.     move.l    d5,CIATIMER_HIGH(a0)
  140.     move.b    d4,CIATIMER_STOPMASK(a0)
  141.     move.b    d3,CIATIMER_STARTMASK(a0)
  142.     move.w    d1,CIATIMER_ICRBIT(a0)
  143.     bsr    GetEClock
  144.     move.l    d0,CIATIMER_ECLOCK(a0)
  145.     CALLSYS    CacheClearU
  146.     moveq    #-1,d0
  147.     bra.b    .end
  148.  
  149. .error:
  150.     moveq    #0,d0
  151. .end:
  152.     movem.l (sp)+,d1-d7/a0-a6
  153.     rts
  154.  
  155. CIAA_name:
  156.     dc.b    "ciaa.resource",0
  157. CIAB_name:
  158.     dc.b    "ciab.resource",0
  159. DummyIntName:
  160.     dc.b    "Quake Bus Clock Measuring",0
  161.  
  162.  
  163.     cnop    0,4
  164.     xdef    FreeCIA
  165. FreeCIA:
  166. ; Release CIA timer.
  167. ; a0 = ciatimer structure pointer
  168.  
  169.     move.l    a6,-(sp)
  170.     move.l    CIATIMER_RESOURCE(a0),a6
  171.     move.w    CIATIMER_ICRBIT(a0),d0
  172.     move.l    CIATIMER_INTERRUPT(a0),a1
  173.     jsr    _LVORemICRVector(a6)
  174.     move.l    (sp)+,a6
  175.     rts
  176.  
  177.  
  178.     cnop    0,4
  179. GetEClock:
  180. ; Evaluate E clock (CIA timer clock)
  181. ; -> d0 = EClock
  182.  
  183.     movem.l    d1-d7/a0-a6,-(sp)
  184.     subq.l    #EV_SIZE,sp
  185.     move.l    TimerBase,a6
  186.     move.l    sp,a0
  187.     jsr    _LVOReadEClock(a6)
  188.     addq.l    #EV_SIZE,sp
  189.     movem.l    (sp)+,d1-d7/a0-a6
  190.     rts
  191.  
  192.  
  193.     cnop    0,4
  194. DummyInterrupt:
  195.     moveq    #0,d0
  196.     rts
  197.  
  198.  
  199.  
  200.     section    DummyInt,bss
  201.  
  202. DummyInt:
  203.     ds.b    IS_SIZE
  204.