Pausing program execution?

I'm currently programming a NES emulator using SDL 1.2 for video and keyboard I/O. I've looked online and attempted a solution to my problem, but my program just locks up no matter what I do. I'm trying to set my program up so that I can hit the p key and toggle stepping mode. While in stepping mode, my emulator will execute one CPU instruction and then print out debug information. It will then wait until I press the spacebar. Once spacebar has been hit, another instruction will execute and the new debug information will be printed.

This is how I've been trying to do it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if(keyboard[SDLK_p]) startStep = true;	//Starts stepping

	while(startStep == true && spaceHit == false)
	{
		if(printDebug)
		{
			printDebug = false;
			core->printDebug();
			video->printDebug();	
		}	

		if(keyboard[SDLK_p]) startStep = false;	//Starts stepping
		if(keyboard[SDLK_SPACE]) spaceHit = true;	//Starts stepping
	}

	spaceHit = false;
        printDebug = true;


I'm just trying to toggle a bool for the step mode and another bool for the spacebar. For some reason this code enters the loop without me ever hitting p, and then it just locks the program up. I have to kill -9 the process to end the process. What should I be doing differently?
Last edited on
Just in case you didn't know, SDL2 has hardware acceleration, SDL 1.2 doesn't.
Also, I'd use SDL_Event structure instead of keystates. You can see more SDL tutorials on lazyfoo's site(he uses SDL 1.2, but it's really similar with SDL 2.0).

Cheers!
I wanted to use SDL 2.0, but there was only 1.2 on the repo for Linux Mint 14, so I ended up using that. I'll look into using events instead of keystates. Thanks!
closed account (Dy7SLyTq)
just build from source. sdl 1.2 has lots of bugs
Topic archived. No new replies allowed.