Fix some weird bugs caused by the main loop running once every opcode

This commit is contained in:
2018-10-30 22:39:12 -04:00
parent 0e3c6f8e73
commit 53c5b6ab9c

26
main.c
View File

@@ -71,7 +71,6 @@ int main(int argc, char **argv) {
int delay = 0; int delay = 0;
int sound = 0; int sound = 0;
int frame = 0;
int press = 0; int press = 0;
int wait = 0; int wait = 0;
int store = 0; int store = 0;
@@ -79,14 +78,10 @@ int main(int argc, char **argv) {
while (1) { while (1) {
if (DEBUG) printf("0x%x ", state.program_counter); if (DEBUG) printf("0x%x ", state.program_counter);
if (frame == 10) if (delay > 0) --delay;
{ if (sound > 0) --sound;
frame = 0; memset(state.input, 0, 0x10);
if (delay > 0) --delay; press = 0;
if (sound > 0) --sound;
memset(state.input, 0, 0x10);
press = 0;
}
// opcodes are 16 bits // opcodes are 16 bits
@@ -117,6 +112,10 @@ int main(int argc, char **argv) {
wait = 0; wait = 0;
} }
int ops = 0;
loop:;
word opcode = (state.memory[state.program_counter++] << 8) | (state.memory[state.program_counter++]); word opcode = (state.memory[state.program_counter++] << 8) | (state.memory[state.program_counter++]);
switch (opcode & 0xF000) switch (opcode & 0xF000)
@@ -403,6 +402,12 @@ int main(int argc, char **argv) {
} }
if (DEBUG) printf("\n"); if (DEBUG) printf("\n");
if (ops < 10)
{
ops++;
goto loop;
}
for (int x = 0; x < 64; ++x) { for (int x = 0; x < 64; ++x) {
for (int y = 0; y < 32; ++y) for (int y = 0; y < 32; ++y)
{ {
@@ -422,8 +427,7 @@ int main(int argc, char **argv) {
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
SDL_Delay(1); SDL_Delay(16);
++frame;
// SDL_DestroyWindow(window); // SDL_DestroyWindow(window);
// SDL_Quit(); // SDL_Quit();
} }