home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 13 / MA_Cover_13.bin / source / c / nfsd / src / timerdev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-30  |  1.4 KB  |  61 lines

  1. /*  timerdev.c - open/close timer.device
  2.  
  3.     ©1999 Henryk Richter <tfa652@uni-rostock.de>
  4.  
  5.     This software is distributed under the terms of the GNU General Public
  6.     License; either version 2 of the License, or (at your option) any
  7.     later version.
  8. */
  9.  
  10. /*
  11.     08-Apr-1999 Restructured by Joseph Walton
  12.                     (hopefully without breaking anything)
  13. */
  14.  
  15. #include "timerdev.h"
  16.  
  17. #include <devices/timer.h>
  18. #include <proto/timer.h>
  19. #include <proto/exec.h>
  20.  
  21. struct Library *TimerBase = NULL;       
  22.  
  23. static struct timerequest *timerIO = NULL;
  24. static struct MsgPort *timerMP = NULL;
  25. static BOOL timerIsOpen = FALSE;
  26.  
  27. BOOL td_opentimer()
  28. {
  29.     if (timerMP = CreateMsgPort()) {
  30.         if (timerIO = (struct timerequest *)CreateIORequest(timerMP,
  31.             sizeof(struct timerequest)))
  32.         {
  33.             if (0 == OpenDevice(TIMERNAME, UNIT_VBLANK,
  34.                 (struct IORequest *)timerIO, 0L))
  35.             {
  36.                 timerIsOpen = TRUE;
  37.                 TimerBase = (struct Library *)timerIO->tr_node.io_Device;
  38.             }
  39.         }
  40.     }
  41.  
  42.     return timerIsOpen;
  43. }
  44.  
  45. void td_closetimer()
  46. {
  47.     if (timerIO) {
  48.         if (timerIsOpen) {
  49.             CloseDevice( (struct IORequest *) timerIO);
  50.             timerIsOpen = FALSE;
  51.         }
  52.         DeleteIORequest(timerIO);
  53.         timerIO = NULL;
  54.     }
  55.     if (timerMP) {
  56.         DeleteMsgPort(timerMP);
  57.         timerMP = NULL;
  58.     }
  59. }
  60.  
  61.