| 1 | /* daemon.c for GP2X Version 2.0 |
| 2 | Copyright (C) 2006 jannis harder |
| 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 | |
| 21 | #include <sys/types.h> |
| 22 | #include <sys/stat.h> |
| 23 | #include <sys/mman.h> |
| 24 | #include <fcntl.h> |
| 25 | #include <unistd.h> |
| 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <string.h> |
| 29 | #include <pthread.h> |
| 30 | |
| 31 | #include "gp2xminilib.h" |
| 32 | #include "cpuctrl.h" |
| 33 | #include "display.h" |
| 34 | |
| 35 | #include "daemon.h" |
| 36 | |
| 37 | |
| 38 | extern unsigned COLORFONDO; // background-color |
| 39 | extern unsigned WHITE; |
| 40 | extern unsigned TEXTBACK; |
| 41 | |
| 42 | extern unsigned char cad[256]; |
| 43 | |
| 44 | extern unsigned short *gp2x_memregs; |
| 45 | extern pthread_t gp2x_sound_thread; |
| 46 | |
| 47 | int start_daemon( |
| 48 | unsigned int minimal_cpu_speed, unsigned int maximal_cpu_speed, unsigned int start_cpu_speed, int cpu_speed_step, |
| 49 | unsigned long hotkey, unsigned long incrementkey, unsigned long decrementkey, |
| 50 | int speed_display, int foreground, |
| 51 | unsigned long delay) |
| 52 | { |
| 53 | pid_t pid, sid; |
| 54 | |
| 55 | if(!foreground) { |
| 56 | kill_running_daemon(); |
| 57 | |
| 58 | |
| 59 | FILE * pidfile = fopen("/tmp/cpu_daemon.pid","w"); |
| 60 | |
| 61 | if(!pidfile) { |
| 62 | printf("couldn't write pidfile\r\n"); |
| 63 | exit(-2); |
| 64 | } |
| 65 | |
| 66 | pid = fork(); |
| 67 | |
| 68 | if(pid > 0) { |
| 69 | fprintf(pidfile,"%i\n",pid); |
| 70 | fclose(pidfile); |
| 71 | } |
| 72 | if(pid != 0) |
| 73 | return pid; |
| 74 | |
| 75 | |
| 76 | fclose(pidfile); |
| 77 | |
| 78 | umask(0); |
| 79 | sid = setsid(); |
| 80 | |
| 81 | |
| 82 | close(STDIN_FILENO); |
| 83 | close(STDOUT_FILENO); |
| 84 | close(STDERR_FILENO); |
| 85 | } |
| 86 | |
| 87 | if(foreground) |
| 88 | printf("daemon ready\r\n"); |
| 89 | |
| 90 | nano_setup(); // loading the full minilib would be overkill and i guess some games/emus wouldn't like it |
| 91 | |
| 92 | |
| 93 | unsigned int current_cpu_speed = start_cpu_speed; |
| 94 | |
| 95 | while(1) { |
| 96 | usleep(delay); |
| 97 | unsigned long keystate = gp2x_joystick_read(); |
| 98 | |
| 99 | unsigned int last_cpu_speed = 0; |
| 100 | |
| 101 | while( |
| 102 | (hotkey && (keystate & hotkey) == hotkey) || |
| 103 | ((!hotkey) && ( |
| 104 | (incrementkey && (keystate & incrementkey) == incrementkey) || |
| 105 | (decrementkey && (keystate & decrementkey) == decrementkey) |
| 106 | )) |
| 107 | ) { |
| 108 | if(foreground && !last_cpu_speed) |
| 109 | printf("cpu daemon activated!\r\n"); |
| 110 | |
| 111 | if(incrementkey && (keystate & incrementkey) == incrementkey) { |
| 112 | current_cpu_speed += cpu_speed_step; |
| 113 | while((keystate & incrementkey) == incrementkey) usleep(100000),keystate = gp2x_joystick_read(); |
| 114 | } |
| 115 | else if(decrementkey && (keystate & decrementkey) == decrementkey) { |
| 116 | current_cpu_speed -= cpu_speed_step; |
| 117 | while((keystate & decrementkey) == decrementkey) usleep(100000),keystate = gp2x_joystick_read(); |
| 118 | } |
| 119 | |
| 120 | if(current_cpu_speed < minimal_cpu_speed) |
| 121 | current_cpu_speed = minimal_cpu_speed; |
| 122 | if(current_cpu_speed > maximal_cpu_speed) |
| 123 | current_cpu_speed = maximal_cpu_speed; |
| 124 | |
| 125 | |
| 126 | |
| 127 | if(last_cpu_speed != current_cpu_speed) { |
| 128 | set_FCLK(current_cpu_speed); |
| 129 | } |
| 130 | last_cpu_speed = current_cpu_speed; |
| 131 | keystate = gp2x_joystick_read(); |
| 132 | } |
| 133 | |
| 134 | } |
| 135 | |
| 136 | } |
| 137 | |
| 138 | int kill_running_daemon() { |
| 139 | |
| 140 | FILE * pidfile = fopen("/tmp/cpu_daemon.pid","r"); |
| 141 | char pid_buffer[14]; |
| 142 | pid_buffer[0] = 'k'; |
| 143 | pid_buffer[1] = 'i'; |
| 144 | pid_buffer[2] = 'l'; |
| 145 | pid_buffer[3] = 'l'; |
| 146 | pid_buffer[4] = ' '; |
| 147 | pid_buffer[5] = 0; |
| 148 | if(pidfile) { |
| 149 | printf("found pidfile\r\n"); |
| 150 | fgets(&(pid_buffer[5]),10,pidfile); |
| 151 | fclose(pidfile); |
| 152 | int return_code = system(pid_buffer); |
| 153 | if(return_code) |
| 154 | printf("daemon wasn't running\r\n"); |
| 155 | else |
| 156 | printf("killed old daemon\r\n"); |
| 157 | unlink("/tmp/cpu_daemon.pid"); |
| 158 | return 1; |
| 159 | } |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | |
| 164 | void nano_setup() { |
| 165 | if(!gp2x_sound_thread) { |
| 166 | gp2x_memregs=(unsigned short *)mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, open("/dev/mem", O_RDWR), 0xc0000000); |
| 167 | cpuctrl_init(); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | void cmd_daemon(int argc, char *argv[]) { |
| 172 | |
| 173 | int cpu_div = get_920_Div(); |
| 174 | int sysfreq=get_freq_920_CLK(); |
| 175 | sysfreq*=cpu_div+1; |
| 176 | int cpufreq=sysfreq/1000000; |
| 177 | |
| 178 | unsigned int minimal_value = 33; |
| 179 | unsigned int maximal_value = 260; |
| 180 | unsigned int start_value = cpufreq; |
| 181 | unsigned int step = 10; |
| 182 | unsigned long hotkey = GP2X_L | GP2X_R; |
| 183 | unsigned long downkey = GP2X_VOL_UP; |
| 184 | unsigned long upkey = GP2X_VOL_DOWN; |
| 185 | int foreground = 0; |
| 186 | int display = 1; |
| 187 | float delay = 1; |
| 188 | |
| 189 | int i; |
| 190 | for( i = 2; i < argc; i++) { |
| 191 | if(!strcmp(argv[i],"--min")) { |
| 192 | if(i+1 == argc){printf ("%s is missing it's parameter\r\n",argv[i]);gp2x_deinit();exit(1);} |
| 193 | minimal_value = atoi(argv[i+1]); |
| 194 | if(minimal_value < 33) |
| 195 | minimal_value = 33; |
| 196 | } |
| 197 | else if(!strcmp(argv[i],"--max")) { |
| 198 | if(i+1 == argc){printf ("%s is missing it's parameter\r\n",argv[i]);gp2x_deinit();exit(1);} |
| 199 | maximal_value = atoi(argv[i+1]); |
| 200 | if(maximal_value > 340) |
| 201 | maximal_value = 340; |
| 202 | } |
| 203 | else if(!strcmp(argv[i],"--start")) { |
| 204 | if(i+1 == argc){printf ("%s is missing it's parameter\r\n",argv[i]);gp2x_deinit();exit(1);} |
| 205 | start_value = atoi(argv[i+1]); |
| 206 | } |
| 207 | else if(!strcmp(argv[i],"--step")) { |
| 208 | if(i+1 == argc){printf ("%s is missing it's parameter\r\n",argv[i]);gp2x_deinit();exit(1);} |
| 209 | step = atoi(argv[i+1]); |
| 210 | } |
| 211 | else if(!strcmp(argv[i],"--hotkey")) { |
| 212 | if(i+1 == argc){printf ("%s is missing it's parameter\r\n",argv[i]);gp2x_deinit();exit(1);} |
| 213 | hotkey = parse_key_sequence(argv[i+1]); |
| 214 | } |
| 215 | else if(!strcmp(argv[i],"--incr")) { |
| 216 | if(i+1 == argc){printf ("%s is missing it's parameter\r\n",argv[i]);gp2x_deinit();exit(1);} |
| 217 | upkey = parse_key_sequence(argv[i+1]); |
| 218 | } |
| 219 | else if(!strcmp(argv[i],"--decr")) { |
| 220 | if(i+1 == argc){printf ("%s is missing it's parameter\r\n",argv[i]);gp2x_deinit();exit(1);} |
| 221 | downkey = parse_key_sequence(argv[i+1]); |
| 222 | } |
| 223 | else if(!strcmp(argv[i],"--delay")) { |
| 224 | if(i+1 == argc){printf ("%s is missing it's parameter\r\n",argv[i]);gp2x_deinit();exit(1);} |
| 225 | delay = atof(argv[i+1]); |
| 226 | } |
| 227 | else if(!strcmp(argv[i],"--no-incr")) { |
| 228 | upkey = 0; |
| 229 | } |
| 230 | else if(!strcmp(argv[i],"--no-decr")) { |
| 231 | downkey = 0; |
| 232 | } |
| 233 | else if(!strcmp(argv[i],"--no-hotkey")) { |
| 234 | hotkey = 0; |
| 235 | } |
| 236 | else if(!strcmp(argv[i],"--foreground")) { |
| 237 | foreground = 1; |
| 238 | } |
| 239 | else if(!strcmp(argv[i],"--background")) { |
| 240 | foreground = 0; |
| 241 | } |
| 242 | else if(!strcmp(argv[i],"--display")) { |
| 243 | display = 1; |
| 244 | } |
| 245 | else if(!strcmp(argv[i],"--no-display")) { |
| 246 | display = 0; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | if((hotkey & downkey) == downkey) |
| 251 | printf("warning: hotkey includes decrement keypress!\r\n"); |
| 252 | if((hotkey & upkey) == upkey) |
| 253 | printf("warning: hotkey includes increment keypress!\r\n"); |
| 254 | |
| 255 | int pid = start_daemon(minimal_value, maximal_value, start_value, step, hotkey, upkey, downkey, display, foreground, delay* 1000000); |
| 256 | |
| 257 | if(pid < 0) { |
| 258 | printf("couldn't start daemon\r\n"); |
| 259 | exit(1); |
| 260 | } |
| 261 | else if(pid > 0) { |
| 262 | printf("daemon started\r\n"); |
| 263 | exit(0); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | unsigned long parse_key_sequence(char *key_sequence) { |
| 268 | unsigned long hotkey = 0; |
| 269 | if(!strcmp(key_sequence,"None")) |
| 270 | return 0; |
| 271 | char *mask = key_sequence; |
| 272 | while(*mask) { |
| 273 | switch(*mask) { |
| 274 | case 'l': |
| 275 | case 'L': |
| 276 | hotkey |= GP2X_L; |
| 277 | break; |
| 278 | case 'r': |
| 279 | case 'R': |
| 280 | hotkey |= GP2X_R; |
| 281 | break; |
| 282 | case 'a': |
| 283 | case 'A': |
| 284 | hotkey |= GP2X_A; |
| 285 | break; |
| 286 | case 'b': |
| 287 | case 'B': |
| 288 | hotkey |= GP2X_B; |
| 289 | break; |
| 290 | case 'x': |
| 291 | case 'X': |
| 292 | hotkey |= GP2X_X; |
| 293 | break; |
| 294 | case 'y': |
| 295 | case 'Y': |
| 296 | hotkey |= GP2X_Y; |
| 297 | break; |
| 298 | case '+': |
| 299 | hotkey |= GP2X_VOL_DOWN; |
| 300 | break; |
| 301 | case '-': |
| 302 | hotkey |= GP2X_VOL_UP; |
| 303 | break; |
| 304 | case 'S': |
| 305 | case 's': |
| 306 | hotkey |= GP2X_START; |
| 307 | break; |
| 308 | case '/': |
| 309 | hotkey |= GP2X_SELECT; |
| 310 | break; |
| 311 | case '@': |
| 312 | hotkey |= GP2X_PUSH; |
| 313 | break; |
| 314 | case '\n': |
| 315 | break; |
| 316 | default: |
| 317 | printf("unknown key %c\r\n",*mask); |
| 318 | } |
| 319 | mask++; |
| 320 | } |
| 321 | return hotkey; |
| 322 | } |
| 323 | |
| 324 | int daemonsettings[8]; |
| 325 | |
| 326 | |
| 327 | void cleardisp(); |
| 328 | |
| 329 | |
| 330 | void formatkey(char * base, unsigned long keyseq) { |
| 331 | |
| 332 | if(!keyseq) |
| 333 | strcat(base,"None"); |
| 334 | |
| 335 | if(keyseq & GP2X_L) |
| 336 | strcat(base,"L"); |
| 337 | if(keyseq & GP2X_R) |
| 338 | strcat(base,"R"); |
| 339 | if(keyseq & GP2X_A) |
| 340 | strcat(base,"A"); |
| 341 | if(keyseq & GP2X_B) |
| 342 | strcat(base,"B"); |
| 343 | if(keyseq & GP2X_X) |
| 344 | strcat(base,"X"); |
| 345 | if(keyseq & GP2X_Y) |
| 346 | strcat(base,"Y"); |
| 347 | if(keyseq & GP2X_VOL_DOWN) |
| 348 | strcat(base,"+"); |
| 349 | if(keyseq & GP2X_VOL_UP) |
| 350 | strcat(base,"-"); |
| 351 | if(keyseq & GP2X_START) |
| 352 | strcat(base,"S"); |
| 353 | if(keyseq & GP2X_SELECT) |
| 354 | strcat(base,"/"); |
| 355 | if(keyseq & GP2X_PUSH) |
| 356 | strcat(base,"@"); |
| 357 | } |
| 358 | |
| 359 | |
| 360 | |
| 361 | #define VALID_KEYS ((GP2X_L) | (GP2X_R) | (GP2X_X) | (GP2X_Y) | (GP2X_A) | (GP2X_B) | (GP2X_START) | (GP2X_SELECT) | (GP2X_VOL_UP) | (GP2X_VOL_DOWN) | (GP2X_PUSH) ) |
| 362 | |
| 363 | int running; |
| 364 | |
| 365 | void daemon_itemhelp(int menuitem) |
| 366 | { |
| 367 | switch(menuitem) { |
| 368 | case 0: |
| 369 | v_putcad(26,8,0xffffff,COLORFONDO,"Choose a"); |
| 370 | v_putcad(26,9,0xffffff,COLORFONDO,"minimal"); |
| 371 | v_putcad(26,10,0xffffff,COLORFONDO,"clockspeed"); |
| 372 | v_putcad(26,11,0xffffff,COLORFONDO,"with R/L or"); |
| 373 | v_putcad(26,12,0xffffff,COLORFONDO,"Vol UP/Down."); |
| 374 | v_putcad(26,14,0xffffff,COLORFONDO,"Valid speeds"); |
| 375 | v_putcad(26,15,0xffffff,COLORFONDO,"are:"); |
| 376 | v_putcad(26,16,0xffffff,COLORFONDO,"33 to 340Mhz"); |
| 377 | break; |
| 378 | case 1: |
| 379 | v_putcad(26,8,0xffffff,COLORFONDO,"Choose a"); |
| 380 | v_putcad(26,9,0xffffff,COLORFONDO,"maximal"); |
| 381 | v_putcad(26,10,0xffffff,COLORFONDO,"clockspeed"); |
| 382 | v_putcad(26,11,0xffffff,COLORFONDO,"with R/L or"); |
| 383 | v_putcad(26,12,0xffffff,COLORFONDO,"Vol UP/Down."); |
| 384 | v_putcad(26,14,0xffffff,COLORFONDO,"Valid speeds"); |
| 385 | v_putcad(26,15,0xffffff,COLORFONDO,"are:"); |
| 386 | v_putcad(26,16,0xffffff,COLORFONDO,"33 to 340Mhz"); |
| 387 | break; |
| 388 | case 2: |
| 389 | v_putcad(26,8,0xffffff,COLORFONDO,"Choose a step"); |
| 390 | v_putcad(26,9,0xffffff,COLORFONDO,"width for"); |
| 391 | v_putcad(26,10,0xffffff,COLORFONDO,"changing the"); |
| 392 | v_putcad(26,11,0xffffff,COLORFONDO,"clockspeed."); |
| 393 | v_putcad(26,13,0xffffff,COLORFONDO,"Use R/L or"); |
| 394 | v_putcad(26,14,0xffffff,COLORFONDO,"Vol UP/Down."); |
| 395 | break; |
| 396 | case 3: |
| 397 | v_putcad(26,8,0xffffff,COLORFONDO,"Choose a"); |
| 398 | v_putcad(26,9,0xffffff,COLORFONDO,"delay between"); |
| 399 | v_putcad(26,10,0xffffff,COLORFONDO,"each hotkey"); |
| 400 | v_putcad(26,11,0xffffff,COLORFONDO,"check"); |
| 401 | v_putcad(26,13,0xffffff,COLORFONDO,"Use R/L or"); |
| 402 | v_putcad(26,14,0xffffff,COLORFONDO,"Vol UP/Down."); |
| 403 | break; |
| 404 | case 4: |
| 405 | v_putcad(26,8,0xffffff,COLORFONDO,"Choose a"); |
| 406 | v_putcad(26,9,0xffffff,COLORFONDO,"hotkey."); |
| 407 | v_putcad(26,10,0xffffff,COLORFONDO,"Add or delete"); |
| 408 | v_putcad(26,11,0xffffff,COLORFONDO,"a button by"); |
| 409 | v_putcad(26,12,0xffffff,COLORFONDO,"pressing it."); |
| 410 | v_putcad(26,14,0x0000DD,COLORFONDO,"Joystick is"); |
| 411 | v_putcad(26,15,0x0000DD,COLORFONDO,"not allowed."); |
| 412 | break; |
| 413 | case 5: |
| 414 | v_putcad(26,8,0xffffff,COLORFONDO,"Choose a"); |
| 415 | v_putcad(26,9,0xffffff,COLORFONDO,"key for"); |
| 416 | v_putcad(26,10,0xffffff,COLORFONDO,"incrementing"); |
| 417 | v_putcad(26,11,0xffffff,COLORFONDO,"the clkspeed."); |
| 418 | v_putcad(26,12,0xffffff,COLORFONDO,"Add or delete"); |
| 419 | v_putcad(26,13,0xffffff,COLORFONDO,"a button by"); |
| 420 | v_putcad(26,14,0xffffff,COLORFONDO,"pressing it."); |
| 421 | v_putcad(26,16,0x0000DD,COLORFONDO,"Joystick is"); |
| 422 | v_putcad(26,17,0x0000DD,COLORFONDO,"not allowed."); |
| 423 | break; |
| 424 | case 6: |
| 425 | v_putcad(26,8,0xffffff,COLORFONDO,"Choose a"); |
| 426 | v_putcad(26,9,0xffffff,COLORFONDO,"key for"); |
| 427 | v_putcad(26,10,0xffffff,COLORFONDO,"decrementing"); |
| 428 | v_putcad(26,11,0xffffff,COLORFONDO,"the clkspeed."); |
| 429 | v_putcad(26,12,0xffffff,COLORFONDO,"Add or delete"); |
| 430 | v_putcad(26,13,0xffffff,COLORFONDO,"a button by"); |
| 431 | v_putcad(26,14,0xffffff,COLORFONDO,"pressing it."); |
| 432 | v_putcad(26,16,0x0000DD,COLORFONDO,"Joystick is"); |
| 433 | v_putcad(26,17,0x0000DD,COLORFONDO,"not allowed."); |
| 434 | break; |
| 435 | case 7: |
| 436 | /* v_putcad(26,8,0xffffff,COLORFONDO,"Enable or"); |
| 437 | v_putcad(26,9,0xffffff,COLORFONDO,"disable"); |
| 438 | v_putcad(26,10,0xffffff,COLORFONDO,"on screen"); |
| 439 | v_putcad(26,11,0xffffff,COLORFONDO,"display."); |
| 440 | v_putcad(26,13,0x0000DD,COLORFONDO,"May cause"); |
| 441 | v_putcad(26,14,0x0000DD,COLORFONDO,"conflicts"); |
| 442 | v_putcad(26,15,0x0000DD,COLORFONDO,"with"); |
| 443 | v_putcad(26,16,0x0000DD,COLORFONDO,"some apps!");*/ |
| 444 | v_putcad(26,8,0x0000DD,COLORFONDO,"COMING SOON"); |
| 445 | break; |
| 446 | case 8: |
| 447 | if(running) { |
| 448 | v_putcad(26,8,0xffffff,COLORFONDO,"Press B to"); |
| 449 | v_putcad(26,9,0xffffff,COLORFONDO,"kill the"); |
| 450 | v_putcad(26,10,0xffffff,COLORFONDO,"running"); |
| 451 | v_putcad(26,11,0xffffff,COLORFONDO,"daemon"); |
| 452 | v_putcad(26,12,0xffffff,COLORFONDO,"process."); |
| 453 | } |
| 454 | else { |
| 455 | v_putcad(26,8,0xffffff,COLORFONDO,"Press B to"); |
| 456 | v_putcad(26,9,0xffffff,COLORFONDO,"start the "); |
| 457 | v_putcad(26,10,0xffffff,COLORFONDO,"daemon in the"); |
| 458 | v_putcad(26,11,0xffffff,COLORFONDO, "background."); |
| 459 | } |
| 460 | break; |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | void daemonmenu() { |
| 465 | |
| 466 | int menupoint = 0; |
| 467 | running = !access("/tmp/cpu_daemon.pid",R_OK); |
| 468 | |
| 469 | |
| 470 | unsigned long gp2x_nKeys; |
| 471 | while(1) { |
| 472 | |
| 473 | if(daemonsettings[0] < 33) |
| 474 | daemonsettings[0] = 33; |
| 475 | if(daemonsettings[1] > 340) |
| 476 | daemonsettings[1] = 340; |
| 477 | if(daemonsettings[1] < daemonsettings[0]) |
| 478 | daemonsettings[1] = daemonsettings[0]; |
| 479 | if(daemonsettings[0] > daemonsettings[1]) |
| 480 | daemonsettings[0] = daemonsettings[1]; |
| 481 | if(daemonsettings[2] < 1) |
| 482 | daemonsettings[2] = 1; |
| 483 | if(daemonsettings[3] < 1) |
| 484 | daemonsettings[3] = 1; |
| 485 | //if(daemonsettings[7] == 10 || daemonsettings[7] == -10) |
| 486 | // daemonsettings[7] = 1; |
| 487 | //if(daemonsettings[7] == 11 || daemonsettings[7] == -9) |
| 488 | daemonsettings[7] = 0; |
| 489 | |
| 490 | |
| 491 | |
| 492 | cleardisp(); |
| 493 | v_putcad(13,2,WHITE,COLORFONDO,"Daemon Setup"); |
| 494 | |
| 495 | v_putcad(2,5,0xffff00,COLORFONDO,"CPU Clockspeed:"); |
| 496 | |
| 497 | sprintf(cad,"From: %huMhz",daemonsettings[0]); |
| 498 | |
| 499 | v_putcad(2,7,0xffff,COLORFONDO,cad); |
| 500 | if(menupoint == 0) |
| 501 | v_putcad(2,7,0xffff,TEXTBACK,cad); |
| 502 | |
| 503 | sprintf(cad,"To: %huMhz",daemonsettings[1]); |
| 504 | |
| 505 | v_putcad(2,8,0xffff,COLORFONDO,cad); |
| 506 | if(menupoint == 1) |
| 507 | v_putcad(2,8,0xffff,TEXTBACK,cad); |
| 508 | |
| 509 | sprintf(cad,"Step: %huMhz",daemonsettings[2]); |
| 510 | |
| 511 | v_putcad(2,9,0xffff,COLORFONDO,cad); |
| 512 | if(menupoint == 2) |
| 513 | v_putcad(2,9,0xffff,TEXTBACK,cad); |
| 514 | |
| 515 | |
| 516 | v_putcad(2,11,0xffff00,COLORFONDO,"Buttons:"); |
| 517 | |
| 518 | sprintf(cad,"Delay: %0.1fsec",daemonsettings[3]/10.0f); |
| 519 | |
| 520 | v_putcad(2,13,0xffff,COLORFONDO,cad); |
| 521 | if(menupoint == 3) |
| 522 | v_putcad(2,13,0xffff,TEXTBACK,cad); |
| 523 | |
| 524 | sprintf(cad,"Hotkey: "); |
| 525 | |
| 526 | formatkey(cad,daemonsettings[4]); |
| 527 | |
| 528 | v_putcad(2,15,0xffff,COLORFONDO,cad); |
| 529 | if(menupoint == 4) |
| 530 | v_putcad(2,15,0xffff,TEXTBACK,cad); |
| 531 | |
| 532 | |
| 533 | sprintf(cad,"IncrKey: "); |
| 534 | |
| 535 | formatkey(cad,daemonsettings[5]); |
| 536 | |
| 537 | v_putcad(2,16,0xffff,COLORFONDO,cad); |
| 538 | if(menupoint == 5) |
| 539 | v_putcad(2,16,0xffff,TEXTBACK,cad); |
| 540 | |
| 541 | sprintf(cad,"DecrKey: "); |
| 542 | |
| 543 | formatkey(cad,daemonsettings[6]); |
| 544 | |
| 545 | v_putcad(2,17,0xffff,COLORFONDO,cad); |
| 546 | if(menupoint == 6) |
| 547 | v_putcad(2,17,0xffff,TEXTBACK,cad); |
| 548 | |
| 549 | if(menupoint >= 4 && menupoint <=6) |
| 550 | v_putcad(2,26,WHITE,COLORFONDO,"---------- Stick:UP/DOWN"); |
| 551 | |
| 552 | v_putcad(2,19,0xffff00,COLORFONDO,"Misc:"); |
| 553 | |
| 554 | |
| 555 | v_putcad(2,21,0xffff,COLORFONDO,(daemonsettings[7] ? "On Screen Display: On" : "On Screen Display: Off")); |
| 556 | if(menupoint == 7) |
| 557 | v_putcad(2,21,0xffff,TEXTBACK,(daemonsettings[7] ? "On Screen Display: On" : "On Screen Display: Off")); |
| 558 | |
| 559 | |
| 560 | v_putcad(2,23,0xffff,COLORFONDO,(running ? "Kill Running Daemon" : "Start Daemon")); |
| 561 | if(menupoint == 8) |
| 562 | v_putcad(2,23,0xffff,TEXTBACK,(running ? "Kill Running Daemon" : "Start Daemon")); |
| 563 | |
| 564 | |
| 565 | |
| 566 | daemon_itemhelp(menupoint); |
| 567 | |
| 568 | gp2x_video_flip(); |
| 569 | while(1) |
| 570 | { |
| 571 | gp2x_nKeys=gp2x_joystick_read(); |
| 572 | |
| 573 | |
| 574 | |
| 575 | if((gp2x_nKeys & GP2X_DOWN)) |
| 576 | { |
| 577 | menupoint++; |
| 578 | if(menupoint>8) menupoint=0; |
| 579 | usleep(200000); |
| 580 | break; |
| 581 | } |
| 582 | |
| 583 | if((gp2x_nKeys & GP2X_UP)) |
| 584 | { |
| 585 | menupoint--; |
| 586 | if(menupoint<0) menupoint=8; |
| 587 | usleep(200000); |
| 588 | break; |
| 589 | } |
| 590 | |
| 591 | if((menupoint >= 4) && (menupoint <= 6) && (gp2x_nKeys & VALID_KEYS)) |
| 592 | { |
| 593 | daemonsettings[menupoint] ^= (gp2x_nKeys & VALID_KEYS); |
| 594 | usleep(200000); |
| 595 | break; |
| 596 | } |
| 597 | |
| 598 | if(menupoint < 8 &&(gp2x_nKeys & GP2X_R)) |
| 599 | { |
| 600 | daemonsettings[menupoint] += 10; |
| 601 | usleep(200000); |
| 602 | break; |
| 603 | } |
| 604 | |
| 605 | if(menupoint < 4 && (gp2x_nKeys & GP2X_VOL_UP)) |
| 606 | { |
| 607 | daemonsettings[menupoint] -= 1; |
| 608 | usleep(200000); |
| 609 | break; |
| 610 | } |
| 611 | |
| 612 | if(menupoint < 4 && (gp2x_nKeys & GP2X_VOL_DOWN)) |
| 613 | { |
| 614 | daemonsettings[menupoint] += 1; |
| 615 | usleep(200000); |
| 616 | break; |
| 617 | } |
| 618 | |
| 619 | if(menupoint < 8 && (gp2x_nKeys & GP2X_L)) |
| 620 | { |
| 621 | daemonsettings[menupoint] -= 10; |
| 622 | usleep(200000); |
| 623 | break; |
| 624 | } |
| 625 | if(menupoint == 8 && (gp2x_nKeys & GP2X_B)) |
| 626 | { |
| 627 | if(running) |
| 628 | kill_running_daemon(); |
| 629 | else { |
| 630 | int cpu_div = get_920_Div(); |
| 631 | int sysfreq=get_freq_920_CLK(); |
| 632 | sysfreq*=cpu_div+1; |
| 633 | int cpufreq=sysfreq/1000000; |
| 634 | |
| 635 | start_daemon_by_settings(); |
| 636 | } |
| 637 | usleep(200000); |
| 638 | running = !access("/tmp/cpu_daemon.pid",R_OK); |
| 639 | break; |
| 640 | } |
| 641 | |
| 642 | |
| 643 | if((gp2x_nKeys & GP2X_START)) |
| 644 | { |
| 645 | while(1) |
| 646 | { |
| 647 | gp2x_nKeys=gp2x_joystick_read(); |
| 648 | if(!(gp2x_nKeys & GP2X_START)) break; |
| 649 | } |
| 650 | |
| 651 | if(running) { // update values! |
| 652 | start_daemon_by_settings(); |
| 653 | } |
| 654 | |
| 655 | |
| 656 | return; |
| 657 | } |
| 658 | |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | void start_daemon_by_settings() { |
| 664 | int cpu_div = get_920_Div(); |
| 665 | int sysfreq=get_freq_920_CLK(); |
| 666 | sysfreq*=cpu_div+1; |
| 667 | int cpufreq=sysfreq/1000000; |
| 668 | |
| 669 | start_daemon(daemonsettings[0], daemonsettings[1], cpufreq, daemonsettings[2], daemonsettings[4], daemonsettings[5], |
| 670 | daemonsettings[6], daemonsettings[7], 0, daemonsettings[3] * 100000); |
| 671 | } |