2823a4c8 |
1 | /* speedtest.c for GP2X (CPU/LCD/RAM-Tuner Version 2.0) |
2 | Copyright (C) 2006 god_at_hell |
3 | |
4 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or |
7 | (at your option) any later version. |
8 | |
9 | This program is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | GNU General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU General Public License |
15 | along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
17 | |
18 | */ |
19 | |
20 | #include <stdio.h> |
21 | #include <stdlib.h> |
22 | #include <string.h> |
23 | #include <fcntl.h> |
24 | #include <math.h> |
25 | #include <unistd.h> |
26 | |
27 | #include "display.h" |
28 | #include "cpuctrl.h" |
29 | #include "gp2xminilib.h" |
30 | |
31 | void prim() |
32 | { |
33 | //FILE *primout; |
34 | unsigned char cad[256]; |
35 | char p = 0; |
36 | int primnumber; |
37 | int l = 1; |
38 | float g = 0; |
39 | int i = 3; |
40 | |
41 | while(i != 500000) |
42 | { |
43 | int m = 2; |
44 | float temp = sqrt(i); |
45 | float ifloat = (float)i; |
46 | |
47 | if(temp == (int)temp) |
48 | { |
49 | m = i; |
50 | p = 1; |
51 | } |
52 | |
53 | while(m < temp) |
54 | { |
55 | g = ifloat/m; |
56 | if (g == (int)g) |
57 | { |
58 | m = i; |
59 | p = 1; |
60 | } |
61 | m++; |
62 | } |
63 | |
64 | if (p == 0) |
65 | { |
66 | l += 1; |
67 | primnumber = i; |
68 | sprintf(cad,"%u is primnumber",i); |
69 | v_putcad(1,13,0xffffff,0xB00000,cad); |
70 | //primout = fopen("/mnt/sd/primnumber.txt", "a"); |
71 | //fprintf(primout,"%u: %u\n", l, i); |
72 | //fclose(primout); |
73 | //execl("sync",NULL); |
74 | gp2x_video_flip(); |
75 | } |
76 | p = 0; |
77 | i++; |
78 | } |
79 | } |
80 | |
81 | void ant() |
82 | { |
83 | int i,n; |
84 | unsigned char cad[256]; |
85 | short direction = 0; //clockwise ... 0 = Up, 1 = Right |
86 | unsigned short col1, col2; |
87 | col1=gp2x_video_color15(0,0,0,0); |
88 | col2=gp2x_video_color15(0xFF,0xFF,0xFF,0); |
89 | short antx = 200; |
90 | short anty = 140; |
91 | for(i = 0; i < 9000; i++) |
92 | { |
93 | for(n = 0; n < 500000; n++); |
94 | if(gp2x_screen15[(320*anty) + antx]==col1) |
95 | { |
96 | for(n = 0; n < 3; n++) |
97 | { |
98 | int m = 0; |
99 | for(m = 0; m < 3; m++) |
100 | { |
101 | gp2x_screen15[320*(anty+n)+antx+m] = col2; |
102 | } |
103 | } |
104 | sprintf(cad,"%u steps left ",8999-i); |
105 | v_putcad(1,3,0x000000,0xffffff,cad); |
106 | gp2x_video_flip(); |
107 | for(n = 0; n < 3; n++) |
108 | { |
109 | int m = 0; |
110 | for(m = 0; m < 3; m++) |
111 | { |
112 | gp2x_screen15[320*(anty+n)+antx+m] = col2; |
113 | } |
114 | } |
115 | sprintf(cad,"%u steps left ",8999-i); |
116 | v_putcad(1,3,0x000000,0xffffff,cad); |
117 | gp2x_video_flip(); |
118 | if(direction == 0) antx-=3; |
119 | if(direction == 1) anty-=3; |
120 | if(direction == 2) antx+=3; |
121 | if(direction == 3) anty+=3; |
122 | direction--; |
123 | if(direction < 0) direction=3; |
124 | } |
125 | if(gp2x_screen15[(320*anty) + antx]==col2) |
126 | { |
127 | for(n = 0; n < 3; n++) |
128 | { |
129 | int m = 0; |
130 | for(m = 0; m < 3; m++) |
131 | { |
132 | gp2x_screen15[320*(anty+n)+antx+m] = col1; |
133 | } |
134 | } |
135 | sprintf(cad,"%u steps left ",8999-i); |
136 | v_putcad(1,3,0x000000,0xffffff,cad); |
137 | gp2x_video_flip(); |
138 | for(n = 0; n < 3; n++) |
139 | { |
140 | int m = 0; |
141 | for(m = 0; m < 3; m++) |
142 | { |
143 | gp2x_screen15[320*(anty+n)+antx+m] = col1; |
144 | } |
145 | } |
146 | sprintf(cad,"%u steps left ",8999-i); |
147 | v_putcad(1,3,0x000000,0xffffff,cad); |
148 | gp2x_video_flip(); |
149 | if(direction == 0) antx+=3; |
150 | if(direction == 1) anty+=3; |
151 | if(direction == 2) antx-=3; |
152 | if(direction == 3) anty-=3; |
153 | direction++; |
154 | if(direction > 3) direction=0; |
155 | } |
156 | } |
157 | } |
158 | |
159 | void speedtest(short test) |
160 | { |
161 | unsigned BACKGROUND; |
162 | if(test == 0) BACKGROUND=0xB00000; |
163 | if(test == 1) BACKGROUND=0xFFFFFF; |
164 | short start = 240; |
165 | short cpuspeed = start; |
166 | unsigned char cad[256]; |
167 | FILE *speed; |
168 | |
169 | do |
170 | { |
171 | speed = fopen("/mnt/sd/speed.txt", "w"); |
172 | ClearScreen(BACKGROUND); |
173 | if(test == 0) v_putcad(1,1,0x00ff00,BACKGROUND,"Prim-Speedtest"); |
174 | if(test == 1) v_putcad(1,1,0x006600,BACKGROUND,"Ant-Speedtest"); |
175 | v_putcad(1,6,0xffffff,BACKGROUND,"Testing Speed"); |
176 | if(cpuspeed > start) |
177 | { |
178 | sprintf(cad,"%uMhz checked",cpuspeed-5); |
179 | v_putcad(1,9,0xffffff,BACKGROUND,cad); |
180 | } |
181 | gp2x_video_flip(); |
182 | ClearScreen(BACKGROUND); |
183 | if(test == 0) v_putcad(1,1,0x00ff00,BACKGROUND,"Prim-Speedtest"); |
184 | if(test == 1) v_putcad(1,1,0x006600,BACKGROUND,"Ant-Speedtest"); |
185 | v_putcad(1,6,0xffffff,BACKGROUND,"Testing Speed"); |
186 | if(cpuspeed > start) |
187 | { |
188 | sprintf(cad,"%uMhz checked",cpuspeed-5); |
189 | if(test == 0) v_putcad(1,9,0xffffff,BACKGROUND,cad); |
190 | if(test == 1) v_putcad(1,9,0x000000,BACKGROUND,cad); |
191 | } |
192 | gp2x_video_flip(); |
193 | fprintf (speed,"set CPU-Frequency = %uMHz\r\n",cpuspeed); |
194 | set_FCLK(cpuspeed); |
195 | |
196 | if(test == 0) prim(); |
197 | if(test == 1) ant(); |
198 | |
199 | fprintf(speed,"%uMhz checked\n\n", cpuspeed); |
200 | cpuspeed = cpuspeed + 5; |
201 | fclose(speed); |
202 | execl("sync",NULL); |
203 | } |
204 | while(1); |
205 | } |