What's new

Problem with For loops...

ShizZy

Emulator Developer
I feel kind of silly for asking this question, but I've been having the same problem with infinite For loops when running my emulators. They seam to hog my entire CPU, and thus luck up my app. Nothing's getting displayed, my output window stays blank - and I have to Ctrl+Alt+Delete to exit the program. Here's an example of one of them...

Code:
void Chip8Emulate()
{
	int CpuCyclesPerRender = 500;

	for(;;){
		for(int i; i<CpuCyclesPerRender; i++){
			 Chip8InterpretASM();	// interpret asm
		}

		/* For every CpuCyclesPerRender, update input/output: */
		if (cpu.delayTimer>0)cpu.delayTimer-=1;
		if (cpu.soundTimer>0)cpu.soundTimer-=1;

		Chip8UpdateScreen();		// update screen
		//Chip8UpdateSound();			// update sound
		//Chip8UpdateControls();		// update controls
	}
}

I grab the opcodes in Chip8InterpretASM(), and they appear to be the right ones. So what's the secret to not making a For loop lock up? :blush:
 

Top