Changing Clock Speed


Sadistictoaster

Still Fresh
Joined
Sep 12, 2006
Messages
22
Hey

Been trying to figure out how to change the clock speed for the GP2X , but even when I directly copy and paste the code from online tutorials / Squidges' function in 'PocketSnes' ( thanks , by the way , I'm still very new at this , but there's some very interesting looking code in there I'm lookig forward to taking apart ) , I still get the same problem : when the program is run , all I get is a black screen.

I'm clearly missing something : any ideas?

#define SYS_CLK_FREQ 7372800

void gp_setCpuspeed(unsigned int cpuspeed);

gp_setCpuspeed(100);

void gp_setCpuspeed(unsigned int MHZ)
{
unsigned v;
unsigned mdiv,pdiv=3,scale=0;
volatile unsigned short *gp2x_memregs;
MHZ*=1000000;
mdiv=(MHZ*pdiv)/SYS_CLK_FREQ;
mdiv=((mdiv-8)<<8) & 0xff00;
pdiv=((pdiv-2)<<2) & 0xfc;
scale&=3;
v=mdiv | pdiv | scale;
gp2x_memregs[0x910>>1]=v;

}

Many Thanks
 
Well, I know nothing about scripting or anything like that, so I'd recommend dl'ing Gmenu2x by Ryo. Over-clocking is a piece of cake usng this menu as opposed to the default GPH menu.
 
Ah , no , this isn't scripting. I need to know how to change the clock speed programmatically for a game I'm working on. Still , nice idea : thanks anyway.
 
Hey

Been trying to figure out how to change the clock speed for the GP2X , but even when I directly copy and paste the code from online tutorials / Squidges' function in 'PocketSnes' ( thanks , by the way , I'm still very new at this , but there's some very interesting looking code in there I'm lookig forward to taking apart ) , I still get the same problem : when the program is run , all I get is a black screen.

I'm clearly missing something : any ideas?

#define SYS_CLK_FREQ 7372800

void gp_setCpuspeed(unsigned int cpuspeed);

gp_setCpuspeed(100);

void gp_setCpuspeed(unsigned int MHZ)
{
unsigned v;
unsigned mdiv,pdiv=3,scale=0;
volatile unsigned short *gp2x_memregs;
MHZ*=1000000;
mdiv=(MHZ*pdiv)/SYS_CLK_FREQ;
mdiv=((mdiv-8)<<8) & 0xff00;
pdiv=((pdiv-2)<<2) & 0xfc;
scale&=3;
v=mdiv | pdiv | scale;
gp2x_memregs[0x910>>1]=v;

}

Many Thanks

Without looking at Squidges code the pointer gp2x_memregs probably needs some way of actually pointing at the registers, right now it is a random pointer value (any trash left on the stack) with the code you show.
 
Last edited by a moderator:
here is the code from one of the SNES emulators:
Code:
void CPUSetting(int speed)
{
	volatile unsigned short *value;
	unsigned short mdiv = 0;
	unsigned short pdiv = 3;
	unsigned short scale = 0;
	unsigned short wrt;
	static int last_speed = -1;
	int adjusted;
	int mem_fd;

	if(speed == last_speed)
		return;

	mdiv = (pdiv * speed*1000*1000) / SYS_CLK_FREQ;
	adjusted = (mdiv * SYS_CLK_FREQ) / (pdiv * 1000*1000);
	mdiv = ((mdiv-8)<<8) & 0xff00;
	pdiv = ((pdiv-2)<<2) & 0xfc;
	scale &= 3;
	wrt = mdiv | pdiv | scale;

	mem_fd = open("/dev/mem", O_RDWR|O_SYNC);  // get handle to memory
	if(mem_fd > 0) { 
		value = (unsigned short *) mmap( 0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, IOBASE ); // create pointer to memory
		if(value) {
			value[FPLLSETVREG] = wrt; // put new value in memory
			printf ("Clock Adjust : %d MHz(%d MHz)\n", speed, adjusted);
			INI_WriteInt("system", "clock", speed);
			last_speed = speed;
			munmap((void*)value, 0x10000); // unmap pointer
		}
		close(mem_fd);  // close handle
	}
}
 
here is the code from one of the SNES emulators:
Code:
void CPUSetting(int speed)
{
	volatile unsigned short *value;
	unsigned short mdiv = 0;
	unsigned short pdiv = 3;
	unsigned short scale = 0;
	unsigned short wrt;[/quote]
What should be included in order for this function to work?
I tried it but compiler complains about memregs..
 
Last edited by a moderator:
Back
Top