]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_timer.c
==== REPO AND DEBUG WORK==== I did many things to the repo and adding ability to...
[16.git] / src / lib / 16_timer.c
1 /* Project 16 Source Code~\r
2  * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
3  *\r
4  * This file is part of Project 16.\r
5  *\r
6  * Project 16 is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * Project 16 is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
19  * Fifth Floor, Boston, MA 02110-1301 USA.\r
20  *\r
21  */\r
22 \r
23 #include "src/lib/16_timer.h"\r
24 \r
25 static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */\r
26 \r
27 clock_t start_timer(global_game_variables_t *gv)\r
28 {\r
29         gv->kurokku.t = clock();\r
30         gv->kurokku.tiku = 0; gv->video.sfip = 0;\r
31         gv->kurokku.clock_start = *clockw;\r
32         gv->kurokku.clock = (word *)clockw;\r
33         gv->kurokku.wcpu = WCPU_detectcpu();\r
34 \r
35         //turn this off if XT\r
36         switch(gv->kurokku.wcpu)\r
37         {\r
38                 case 0:\r
39                         gv->kurokku.fpscap=0;\r
40                         gv->kurokku.frames_per_second=1;\r
41                 break;\r
42                 default:\r
43                         gv->kurokku.fpscap=1;\r
44                         gv->kurokku.frames_per_second=FPSVALUE;\r
45                 break;\r
46         }\r
47         return gv->kurokku.t;\r
48 }\r
49 \r
50 double elapsed_timer(global_game_variables_t *gv)\r
51 {\r
52         return (clock() - gv->kurokku.t) / CLOCKS_PER_SEC;\r
53 }\r
54 \r
55 double ticktock(global_game_variables_t *gv)\r
56 {\r
57         double clocku;\r
58         clocku = (clock() - gv->kurokku.t) / CLOCKS_PER_SEC;\r
59         gv->kurokku.t = clock();\r
60         return clocku;\r
61 }\r
62 \r
63 double time_in_seconds(global_game_variables_t *gv)\r
64 {\r
65         return (gv->kurokku.t) / CLOCKS_PER_SEC;\r
66 }\r
67 \r
68 /*double time_in_seconds(time_t in_t)\r
69 {\r
70         return (in_t) / CLOCKS_PER_SEC;\r
71 }*/\r
72 \r
73 #if 0\r
74 /*      sync    */\r
75 void shinkutxt(global_game_variables_t *gv)\r
76 {\r
77         //float t;\r
78         if(elapsed_timer(gv) >= (1.0 / gv->kurokku.frames_per_second))\r
79         {\r
80                 //t=(((*(gv->clock))-gv->clock_start) /18.2);\r
81                 sprintf(global_temp_status_text, "%.0f fps", (double)gv->kurokku.tiku/ticktock(gv));\r
82                 fprintf(stderr, "%s\n", global_temp_status_text);\r
83                 //(gv->clock_start)=*(gv->clock);\r
84                 gv->kurokku.tiku=0;\r
85         }\r
86         gv->kurokku.tiku++;\r
87 //      switch(gv->kurokku.fpscap)\r
88 //      {\r
89 //              case 0:\r
90 //                      gv->kurokku.frames_per_second=1;\r
91 //              break;\r
92 //              case 1:\r
93 //                      //turn this off if XT\r
94 //                      WaitPee();\r
95 //                      gv->kurokku.frames_per_second=60;\r
96 //              break;\r
97 //      }\r
98 }\r
99 \r
100 //#if 0\r
101 void WaitPee()\r
102 {\r
103     while(inp(INPUT_STATUS_1)  & 8)  {\r
104         /* spin */\r
105     }\r
106 \r
107     while(!(inp(INPUT_STATUS_1)  & 8))  {\r
108         /* spin */\r
109     }\r
110 }\r
111 #endif\r