source: abuse/trunk/src/imlib/timer.cpp @ 57

Last change on this file since 57 was 56, checked in by Sam Hocevar, 14 years ago
  • Add licensing terms to most C / C++ files (Ref #5).
File size: 1.9 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *
5 *  This software was released into the Public Domain. As with most public
6 *  domain software, no warranty is made or implied by Crack dot Com or
7 *  Jonathan Clark.
8 */
9
10#include "config.h"
11
12#include "system.h"
13
14#ifdef __UNIX_XWIN
15#include <stdio.h>
16#include <sys/time.h>
17#include <stdlib.h>
18#include <signal.h>
19#include <unistd.h>
20#include <signal.h>
21
22
23//#ifndef setitimer
24//extern "C" {
25//int setitimer(int Which, struct itimerval *Value,
26//                              struct itimerval *Ovalue);
27//} ;
28//#endif
29
30struct sigaction sa;
31typedef void (*int_handler)();
32#define SETSIG(sig,fun) (int_handler)sa.sa_handler=fun; \
33                        sa.sa_flags=0; \
34                        sigemptyset(&sa.sa_mask); \
35                        sigaddset(&sa.sa_mask,SIGALRM); \
36                        sigaction(sig,&sa,NULL);
37
38
39
40//void timer_handler()
41//{
42//  SETSIG(SIGALRM,timer_handler);
43//  printf("%ld\n",jclock++);
44//  fflush(stdout);
45//}
46
47
48void init_timer(int_handler int_proc, long utime)
49{
50  itimerval newt;
51  SETSIG(SIGALRM,int_proc);
52  newt.it_interval.tv_sec=0;
53  newt.it_interval.tv_usec=utime;
54  newt.it_value.tv_sec=0;
55  newt.it_value.tv_usec=utime;
56  setitimer(ITIMER_REAL,&newt,NULL);
57}
58#else
59  #ifdef __BCPLUSPLUS__
60  #include <stdio.h>
61  #include <dos.h>
62  #include <conio.h>
63
64  #define INTR 0X1C    /* The clock tick interrupt */
65  void interrupt ( *oldhandler)(...);
66
67  int count=0;
68
69  void interrupt handler(...)
70  {
71  /* increase the global counter */
72     count++;
73
74  /* call the old routine */
75     oldhandler();
76  }
77
78  int main(void)
79  {
80  /* save the old interrupt vector */
81     oldhandler = getvect(INTR);
82
83  /* install the new interrupt handler */
84     setvect(INTR, handler);
85
86  /* loop until the counter exceeds 20 */
87     while (count < 20)
88        printf("count is %d\n",count);
89
90  /* reset the old interrupt handler */
91     setvect(INTR, oldhandler);
92
93     return 0;
94  }
95
96
97
98  #else
99  #error Timer not supported for this compiler! Use Borland or gcc
100  #endif
101#endif
102
103
104
105
106
107
108
109
110
111
112
113
Note: See TracBrowser for help on using the repository browser.