| 1 | |
| 2 | /* commandline.c for GP2X Version 2.0 |
| 3 | Copyright (C) 2006 god_at_hell |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | |
| 19 | */ |
| 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
| 24 | #include "cpuctrl.h" |
| 25 | #include "gp2xminilib.h" |
| 26 | #include "cpuctrl.h" |
| 27 | |
| 28 | |
| 29 | void fallback(int argc, char *argv[]) |
| 30 | { |
| 31 | //beginning commandline-utilizing |
| 32 | if (argc == 3) |
| 33 | { |
| 34 | if (atoi(argv[1]) == 0) |
| 35 | { |
| 36 | if(atoi(argv[2]) > 36){gp2x_deinit();exit(1);} |
| 37 | if(atoi(argv[2]) < -20){gp2x_deinit();exit(1);} |
| 38 | set_add_FLCDCLK(atoi(argv[2])); |
| 39 | } |
| 40 | else |
| 41 | { |
| 42 | if(atoi(argv[2]) > 10){gp2x_deinit();exit(1);} |
| 43 | if(atoi(argv[2]) < -5){gp2x_deinit();exit(1);} |
| 44 | set_add_ULCDCLK(atoi(argv[2])); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | if (argc == 4) |
| 49 | { |
| 50 | if(atoi(argv[3]) > 320){gp2x_deinit();exit(1);} |
| 51 | if(atoi(argv[3]) < 33){gp2x_deinit();exit(1);} |
| 52 | if (atoi(argv[1]) == 0) |
| 53 | { |
| 54 | if(atoi(argv[2]) > 36){gp2x_deinit();exit(1);} |
| 55 | if(atoi(argv[2]) < -20){gp2x_deinit();exit(1);} |
| 56 | set_add_FLCDCLK(atoi(argv[2])); |
| 57 | } |
| 58 | else |
| 59 | { |
| 60 | if(atoi(argv[2]) > 10){gp2x_deinit();exit(1);} |
| 61 | if(atoi(argv[2]) < -5){gp2x_deinit();exit(1);} |
| 62 | set_add_ULCDCLK(atoi(argv[2])); |
| 63 | } |
| 64 | set_FCLK(atoi(argv[3])); |
| 65 | } |
| 66 | |
| 67 | if (argc == 5) |
| 68 | { |
| 69 | if(atoi(argv[3]) > 320){gp2x_deinit();exit(1);} |
| 70 | if(atoi(argv[3]) < 33){gp2x_deinit();exit(1);} |
| 71 | if(atof(argv[4]) > 10){gp2x_deinit();exit(1);} |
| 72 | if(atof(argv[4]) < 0.02){gp2x_deinit();exit(1);} |
| 73 | if (atoi(argv[1]) == 0) |
| 74 | { |
| 75 | if(atoi(argv[2]) > 36){gp2x_deinit();exit(1);} |
| 76 | if(atoi(argv[2]) < -20){gp2x_deinit();exit(1);} |
| 77 | set_add_FLCDCLK(atoi(argv[2])); |
| 78 | } |
| 79 | else |
| 80 | { |
| 81 | if(atoi(argv[2]) > 10){gp2x_deinit();exit(1);} |
| 82 | if(atoi(argv[2]) < -5){gp2x_deinit();exit(1);} |
| 83 | set_add_ULCDCLK(atoi(argv[2])); |
| 84 | } |
| 85 | set_FCLK(atoi(argv[3])); |
| 86 | set_gamma(atof(argv[4])); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | void cmdhelp() |
| 91 | { |
| 92 | printf ("\ngpSP2X v0.9003 Beta by Exophase/ZodTTD\r\n"); |
| 93 | printf ("cpu_speed by god_at_hell\r\n"); |
| 94 | printf ("Usage: cpu_speed.gpe [option1] [value1] [option2]...\r\n"); |
| 95 | printf ("Options:\r\n"); |
| 96 | printf (" RAM-Options\r\n"); |
| 97 | printf (" -----------\r\n"); |
| 98 | printf (" --cas CAS Latency. Delay in clock cycles between the registration \n\t\tof a READ command and the first bit of output data. \n\t\tValid values are 2 and 3 cycles.\r\n"); |
| 99 | printf (" --trc ACTIVE to ACTIVE /AUTOREFRESH command delay. Defines ACTIVE \n\t\tto ACTIVE/auto refresh command period delay. \n\t\tValid values are from 1 to 16 cycles.\r\n"); |
| 100 | printf (" --tras ACTIVE to PRECHARGE delay. Defines the delay between the ACTIVE \n\t\tand PRECHARGE commands. \n\t\tValid values are from 1 to 16 cycles.\r\n"); |
| 101 | printf (" --twr Write recovery time in cycles.\n\t\tValid values are from 1 to 16 cycles.\r\n"); |
| 102 | printf (" --tmrd LOAD MODE REGISTER command cycle time.\n\t\tValid values are from 1 to 16 cycles.\r\n"); |
| 103 | printf (" --trfc AUTO REFRESH command period in cycles.\n\t\tValid values are from 1 to 16 cycles.\r\n"); |
| 104 | printf (" --trp PRECHARGE command period in cycles.\n\t\tValid values are from 1 to 16 cycles.\r\n"); |
| 105 | printf (" --trcd RAS to CAS Delay in cycles.\n\t\tValid values are from 1 to 16 cycles.\r\n"); |
| 106 | printf (" --refperd Refresh Period. Defines maximum time period between \n\t\tAUTOREFRESH commands.\n\t\tValid values are from 1 to 65535 (default ~ 250) cycles.\r\n"); |
| 107 | printf (" --ramdiv Divider for the Memory-Clock which is 1/2 of the CPU-Clock. \n\t\tValid values are from 1 to 8.\r\n"); |
| 108 | printf ("\n CPU-Options\r\n"); |
| 109 | printf (" -----------\r\n"); |
| 110 | printf (" --cpuclk Sets the CPU-Frequency in Mhz. \n\t\tValid values are from 33 to 340.\r\n"); |
| 111 | printf (" --cpudiv Divider for the CPU-Clock. \n\t\tValid values are from 1 to 8.\r\n"); |
| 112 | printf ("\n Display-Options\r\n"); |
| 113 | printf ("----------------\r\n"); |
| 114 | printf (" --fpll Sets clockgenerator to fpll (for firmware 1.0 - 1.0.1).\r\n"); |
| 115 | printf (" --upll Sets clockgenerator to upll (for the rest).\r\n"); |
| 116 | printf (" --timing Timing Prescaler to eliminate flickering. \n\t\tValid values are: -20 to 36 with fpll.\n\t\t\t\t -6 to 10 with upll.\r\n"); |
| 117 | printf (" --gamma Regulates the gamma. \n\t\tValid values are from 0.0001 to 15.0000.\r\n"); |
| 118 | printf ("\n Daemon-Mode \r\n"); |
| 119 | printf ("----------------\r\n"); |
| 120 | printf ("Usage: cpu_speed.gpe --daemon [option1] [value1] [option2]...\r\n"); |
| 121 | printf ("Shutdown: cpu_speed.gpe --kill[-daemon]\r\n"); |
| 122 | printf ("Options:\r\n"); |
| 123 | printf (" --min Sets the minimum CPU-Frequency in Mhz. \n\t\tValid values are from 33 to 340.\r\n"); |
| 124 | printf (" --max Sets the maximum CPU-Frequency in Mhz. \n\t\tValid values are from 33 to 340.\r\n"); |
| 125 | printf (" --start Sets the CPU-Frequency in Mhz. \n\t\tValid values are from 33 to 340.\r\n"); |
| 126 | printf (" --step Sets the CPU-Frequency step in Mhz. \n\t\tValid values are from 1 to 340.\r\n"); |
| 127 | printf (" --hotkey Sets the hotkey. (Default: LR) \n\t\tValid values are a combination of LRXYZAB+-S/@ or ``None''\n\t\t (+- are volume, S is Start, / is Select, @ is Stick).\r\n"); |
| 128 | printf (" --incr Sets the increment key. (Default: +) \n\t\tValid values are a combination of LRXYZAB+-S/@ or ``None''\n\t\t (+- are volume, S is Start, / is Select, @ is Stick).\r\n"); |
| 129 | printf (" --decr Sets the decrement key. (Default: -) \n\t\tValid values are a combination of LRXYZAB+-S/@ or ``None''\n\t\t (+- are volume, S is Start, / is Select, @ is Stick).\r\n"); |
| 130 | printf (" --no-hotkey Alias for --hotkey None.\r\n"); |
| 131 | printf (" --no-incr Alias for --incr None.\r\n"); |
| 132 | printf (" --no-decr Alias for --decr None.\r\n"); |
| 133 | printf (" --foreground Do not switch to daemon mode. (Useful for debugging)\r\n"); |
| 134 | printf (" --background Switch to daemon mode. (Default)\r\n"); |
| 135 | printf (" --display Enable on screen display. COMING SOON!\r\n"); |
| 136 | printf (" --no-display Disable on screen display.\r\n"); |
| 137 | printf ("\nNOTE:\nThe old commandline-settings are working ... read more about this in the readme\n\n"); |
| 138 | } |
| 139 | |
| 140 | void cmdline(int argc, char *argv[]) |
| 141 | { |
| 142 | short i,n; |
| 143 | short varis = 11; |
| 144 | char clockgen = get_Clkgen(); |
| 145 | char var[11][9]={"--cas","--trc","--tras","--twr","--tmrd","--trfc","--trp","--trcd","--ramdiv","--cpuclk","--cpudiv"}; |
| 146 | |
| 147 | short val[varis]; |
| 148 | for(n=0;n<varis;n++) //initialize the variable-array |
| 149 | { |
| 150 | val[n] = -1; |
| 151 | } |
| 152 | |
| 153 | short timing = -100; |
| 154 | int refperd = -1; |
| 155 | float gamma = -1.; |
| 156 | |
| 157 | |
| 158 | for(i=1; i<argc; i++) |
| 159 | { |
| 160 | if(strcmp(argv[i], "--fpll") == 0) clockgen = 0; |
| 161 | if(strcmp(argv[i], "--upll") == 0) clockgen = 1; |
| 162 | |
| 163 | for(n=0; n<varis; n++) |
| 164 | { |
| 165 | if(strcmp(argv[i], var[n]) == 0) |
| 166 | { |
| 167 | if(i+1 == argc){printf ("%s is missing it's parameter\r\n",var[n]);gp2x_deinit();exit(1);} |
| 168 | val[n] = atoi(argv[i+1]); |
| 169 | } |
| 170 | } |
| 171 | if(strcmp(argv[i], "--refperd") == 0) |
| 172 | { |
| 173 | if(i+1 == argc){printf ("%s is missing it's parameter\r\n",argv[i]);gp2x_deinit();exit(1);} |
| 174 | refperd = atoi(argv[i+1]); |
| 175 | } |
| 176 | if(strcmp(argv[i], "--gamma") == 0) |
| 177 | { |
| 178 | if(i+1 == argc){printf ("%s is missing it's parameter\r\n",argv[i]);gp2x_deinit();exit(1);} |
| 179 | gamma = atof(argv[i+1]); |
| 180 | } |
| 181 | if(strcmp(argv[i], "--timing") == 0) |
| 182 | { |
| 183 | if(i+1 == argc){printf ("%s is missing it's parameter\r\n",argv[i]);gp2x_deinit();exit(1);} |
| 184 | timing = atoi(argv[i+1]); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | if(clockgen == 0) |
| 189 | { |
| 190 | if(timing > -21) |
| 191 | { |
| 192 | if(timing < 37) set_add_FLCDCLK(timing); |
| 193 | } |
| 194 | else set_add_FLCDCLK(get_LCDClk(clockgen)); |
| 195 | } |
| 196 | if(clockgen == 1) |
| 197 | { |
| 198 | if(timing > -7) |
| 199 | { |
| 200 | if(timing < 11) set_add_ULCDCLK(timing); |
| 201 | } |
| 202 | else set_add_ULCDCLK(get_LCDClk(clockgen)); |
| 203 | } |
| 204 | if(refperd-1 > -1) |
| 205 | { |
| 206 | if(refperd-1 < 0xffff) set_REFPERD(refperd-1); |
| 207 | } |
| 208 | if(gamma > 0.) |
| 209 | { |
| 210 | if(gamma < 15.) set_gamma(gamma); |
| 211 | } |
| 212 | if(val[0]-2 > -1) |
| 213 | { |
| 214 | if(val[0]-2 < 2) set_CAS(val[0]-2); |
| 215 | } |
| 216 | if(val[1]-1 > -1) |
| 217 | { |
| 218 | if(val[1]-1 < 16) set_tRC(val[1]-1); |
| 219 | } |
| 220 | if(val[2]-1 > -1) |
| 221 | { |
| 222 | if(val[2]-1 < 16) set_tRAS(val[2]-1); |
| 223 | } |
| 224 | if(val[3]-1 > -1) |
| 225 | { |
| 226 | if(val[3]-1 < 16) set_tWR(val[3]-1); |
| 227 | } |
| 228 | if(val[4]-1 > -1) |
| 229 | { |
| 230 | if(val[4]-1 < 16) set_tMRD(val[4]-1); |
| 231 | } |
| 232 | if(val[5]-1 > -1) |
| 233 | { |
| 234 | if(val[5]-1 < 16) set_tRFC(val[5]-1); |
| 235 | } |
| 236 | if(val[6]-1 > -1) |
| 237 | { |
| 238 | if(val[6] < 16) set_tRP(val[6]-1); |
| 239 | } |
| 240 | if(val[7]-1 > -1) |
| 241 | { |
| 242 | if(val[7]-1 < 16) set_tRCD(val[7]-1); |
| 243 | } |
| 244 | if(val[8]-1 > -1) |
| 245 | { |
| 246 | if(val[8]-1 < 8) set_DCLK_Div(val[8]-1); |
| 247 | } |
| 248 | if(val[9] > 32) |
| 249 | { |
| 250 | if(val[9] < 341) set_FCLK(val[9]); |
| 251 | } |
| 252 | if(val[10]-1 > -1) |
| 253 | { |
| 254 | if(val[10]-1 < 8) set_920_Div(val[10]-1); |
| 255 | } |
| 256 | } |