home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 3 / CD_Magazyn_EXEC_nr_3.iso / Recent / game / wb / Klotz.lha / Klotz / src / TimerUtils.asm < prev   
Assembly Source File  |  1998-03-19  |  5KB  |  261 lines

  1. *
  2. *   $VER:   TimerUtils.asm 0.14 (1.9.93)
  3. *                0.13 (13.8.93)   oh Freitag, der 13te
  4. *
  5. InitTimer
  6. *
  7. * SetUp: OpenDevice AllocMem AllocSignals ...
  8. *   <=     d0  : Fail if <0
  9.     push    a0-a6/d1-d7
  10. *   Gibt's mich schon ?
  11.     CSYS    Forbid
  12.     lea     KlotzName(pc),a1
  13.     CALL    FindPort
  14.     CALL    Permit
  15.     tst.l   d0
  16.     beq.s   .weiter
  17.     pea     ERKlotzOk(pc)
  18.     pea     ERKlotzLauft(pc)
  19.     pea     ERKlotzTitel(pc)
  20.     pea     0
  21.     pea     20    ; es_SIZEOF
  22.     move.l  sp,a1
  23.     clra.l  a0
  24.     clra.l  a2
  25.     clra.l  a3
  26.     CINT    EasyRequestArgs
  27.     lea     20(sp),sp
  28.     bra.s   .ErrorExit2
  29. .weiter
  30.     moveq   #-1,d0
  31.     reloc.w d0,WakeUpTime
  32.     reloc.w d0,WakeUpMove
  33.     reloc.w d0,WakeUpSpin
  34.  
  35.     move.l  #MEMF_PUBLIC!MEMF_CLEAR,d1
  36.     moveq   #MP_SIZE,d0
  37.     CSYS    AllocVec
  38.     reloc.l d0,TPort
  39.     bne.s   .TPortOk
  40. .ErrorExit
  41.     bsr     ExitTimer
  42. .ErrorExit2
  43.     moveq   #-1,d0
  44.     bra     .Exit
  45. .TPortOk
  46.     move.l  d0,a0
  47.     move.b  #NT_MSGPORT,LN_TYPE(a0)
  48.     lea     KlotzName(pc),a1
  49.     move.l  a1,LN_NAME(a0)
  50.     move.b  #PA_SOFTINT,MP_FLAGS(a0)
  51.     lea     InterruptStruct,a1
  52.     move.l  a4,IS_DATA(a1)          ; Globale Daten
  53.     move.l  a1,MP_SOFTINT(A0)
  54.     move.l  a0,a2
  55.     move.l  a0,a1
  56.     CALL    AddPort
  57.     move.l  a2,a0    ;<- Da war er (der die Rev-Nr. hochtreibt)
  58.     moveq   #IOTV_SIZE,d0
  59.     CALL    CreateIORequest
  60.     reloc.l d0,TReq
  61.     beq.s   .ErrorExit
  62.     move.l  d0,a1
  63.     lea     TimerName(pc),a0
  64.     moveq   #UNIT_MICROHZ,d0
  65.     moveq   #0,d1
  66.     CALL    OpenDevice
  67.     tst.l   d0
  68.     bne.s   .ErrorExit
  69.  
  70.     moveq   #-1,d0
  71.     CALL    AllocSignal
  72.     reloc.w d0,WakeUpTime
  73.     bmi.s   .ErrorExit
  74.     moveq   #1,d2
  75.     lsl.l   d0,d2
  76.     reloc.l d2,WUTimeMsk
  77.     moveq   #-1,d0
  78.     CALL    AllocSignal
  79.     reloc.w d0,WakeUpMove
  80.     bmi.s   .ErrorExit
  81.     moveq   #1,d3
  82.     lsl.l   d0,d3
  83.     reloc.l d3,WUMoveMsk
  84.     moveq   #-1,d0
  85.     CALL    AllocSignal
  86.     reloc.w d0,WakeUpSpin
  87.     bmi     .ErrorExit
  88.     moveq   #1,d4
  89.     lsl.l   d0,d4
  90.     reloc.l d4,WUSpinMsk
  91.  
  92.     moveq   #0,d1
  93.     or.l    d4,d1
  94.     or.l    d3,d1
  95.     or.l    d2,d1
  96.     reloc.l d1,WUMsk
  97.     moveq   #0,d0
  98. .Exit
  99.     pop     a0-a6/d1-d7
  100.     rts
  101.  
  102. ExitTimer
  103. *
  104. *   CleanUp
  105. *
  106.     push    d0-d3/a0-a1/a6
  107.     bsr.s   StopTimer
  108.     moveq   #25,d1
  109.     CDOS    Delay
  110.     copy.w  WakeUpSpin,d0
  111.     bmi.s   .NoSpin
  112.     CSYS    FreeSignal
  113. .NoSpin
  114.     copy.w  WakeUpMove,d0
  115.     bmi.s   .NoMove
  116.     CSYS    FreeSignal
  117. .NoMove
  118.     copy.w  WakeUpTime,d0
  119.     bmi.s   .NoTime
  120.     CSYS    FreeSignal
  121. .NoTime
  122.     copy.l  TReq,d3
  123.     beq.s   .noReq
  124.     move.l  d3,a1
  125.     CSYS    CloseDevice
  126.     move.l  d3,a0
  127.     CALL    DeleteIORequest
  128. .noReq
  129.     copy.l  TPort,d3
  130.     beq.s   .noPort
  131.     move.l  d3,a1
  132.     CSYS    RemPort
  133.     move.l  d3,a1
  134.     CALL    FreeVec
  135. .noPort
  136.     pop     d0-d3/a0-a1/a6
  137.     rts
  138.  loc.l TReq  ;dc.l 0
  139.  loc.l TPort ;dc.l 0
  140.  loc.w TCount ;  dc.w 0
  141.  loc.w TCount2 ;dc.w 0
  142.  loc.l WUTimeMsk ;  dc.l 0
  143.  loc.l WUMoveMsk ;  dc.l 0
  144.  loc.l WUSpinMsk ;  dc.l 0
  145.  loc.l WUMsk    ;  dc.l 0
  146.  loc.w WakeUpTime ; dc.w -1
  147.  loc.w WakeUpMove ; dc.w -1
  148.  loc.w WakeUpSpin ; dc.w -1
  149. *    cnop    0,4
  150.  section "data",data
  151. InterruptStruct
  152.     dc.l    0,0
  153.     dc.b    NT_UNKNOWN,16 ;NT_INTERRUPT,0 wegen Cause() ?
  154.     dc.l    KlotzName
  155.     dc.l    0
  156.     dc.l    TimerInterrupt
  157.  section "",code
  158.  loc.b Timer ; dc.b  0
  159.  loc.b pad4017
  160.  even
  161. StopTimer
  162. *
  163. *   Halt-Flag setzen
  164. *
  165.     copy.l  TPort,d0        TPort überhaupt initialisiert ?
  166.     beq.s   .Ende
  167.     move.l  d0,a0
  168.     move.b  #PA_IGNORE,MP_FLAGS(a0)
  169.     sf        Timer(a4)
  170. .Ende
  171.     rts
  172.  
  173. StartTimer
  174. *
  175. *   ( was soll man dazu sagen ? )
  176. *
  177. *   =>     d0  : TimeOut in µs
  178. BeginIO     equ  -30
  179.     lea     Timer(a4),a0
  180.     st        (a0)
  181.     push    a6
  182.     bsr.s   StartTimerInterrupt
  183.     pop     a6
  184.     rts
  185. StartTimerInterrupt
  186.     copy.l  TReq,a1
  187.     move.w  #TR_ADDREQUEST,IO_COMMAND(a1)
  188.     clr.l   IOTV_TIME+TV_SECS(a1)
  189.     move.l  d0,IOTV_TIME+TV_MICRO(a1)
  190.     move.l  IO_DEVICE(a1),a6
  191.     jmp     BeginIO(a6)
  192. TimerWait        ; Levelabhängige Wartezeit etwa altes Level * 85%
  193.     dc.b 80,68,57,48,40,34,28,23,19,16,13,11,9,8,7,6,5,4,3,2,1,0
  194.     even
  195.  
  196. TimerInterrupt
  197.     push    a3/a4/a6
  198.     move.l  a1,a4
  199.     copy.l  TPort,a0
  200.     CSYS    GetMsg
  201.     tst.l   d0
  202.     beq.s   .exitinter
  203.     copy.b  Timer,d0
  204.     beq.s   .exitinter
  205.  
  206.     lea     TCount(a4),a3
  207.     copy.l  Level,d0
  208.  
  209.     move.b  TimerWait(pc,d0),d1
  210.     ext.w   d1
  211.  
  212.     move.w  (a3),d0
  213.     cmp.w   d1,d0
  214.     blt.s   .noTimeOut
  215.     copy.l  OwnTask,a1
  216.     copy.l  WUTimeMsk,d0
  217.     CALL    Signal
  218.     clr.w   (a3)
  219.     bra.s   .StartTimer
  220. .noTimeOut
  221.     addq.w  #1,(a3)
  222.  
  223. *   ...still under development...
  224.     bsr     TestFire
  225.     beq.s   .noFire
  226.     copy.l  OwnTask,a1
  227.     copy.l  WUSpinMsk,d0
  228.     CALL    Signal
  229.     bra.s   .StartTimer
  230. .noFire
  231.     lea     TCount2(a4),a3
  232.     bsr     TestJoy
  233.     bmi.s   .noTimeOutTest
  234.     beq.s   .StartTimer
  235.     move.w  (a3),d0
  236.     cmpi.w  #10,d0        Millisec TimeOut für Movement
  237.     bge.s   .limiterreicht
  238.     addq.w  #1,d0
  239.     move.w  d0,(a3)
  240.     bra.s   .StartTimer
  241. .noTimeOutTest
  242. .limiterreicht
  243.     clr.w   (a3)
  244.     copy.l  OwnTask,a1
  245.     copy.l  WUMoveMsk,d0
  246.     CALL    Signal
  247. *   ...
  248. .StartTimer
  249.     move.l  #10000,d0
  250.     bsr     StartTimerInterrupt
  251. .exitinter
  252.     pop     a3/a4/a6
  253.     moveq   #0,d0
  254.     rts
  255. KlotzName   dc.b 'KlotzTimer',0
  256. TimerName   dc.b 'timer.device',0
  257. ERKlotzTitel dc.b 'Information',0
  258. ERKlotzLauft dc.b 'Klotz is already running.',0
  259. ERKlotzOk    dc.b 'OK',0
  260.  even
  261.