decoupled timers from interpreter tick rate
This commit is contained in:
23
main.cpp
23
main.cpp
@@ -6,11 +6,11 @@
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "BuzzerSDL.hpp"
|
||||
#include "CountdownTimerSDL.hpp"
|
||||
#include "DisplaySDL.hpp"
|
||||
#include "Interpreter.hpp"
|
||||
#include "Peripherals.hpp"
|
||||
#include "SDL2/SDL_events.h"
|
||||
#include "SDL2/SDL_timer.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
|
||||
@@ -23,9 +23,13 @@ int main(int argc, char* argv[]) {
|
||||
};
|
||||
|
||||
BuzzerSDL buzzer(440);
|
||||
DisplaySDL display(1280, 640);
|
||||
int N = 4;
|
||||
DisplaySDL display(128*N, 64*N);
|
||||
TestKeypad keypad;
|
||||
chocochip8::Interpreter chip8(1000, display, buzzer, keypad);
|
||||
CountdownTimerSDL delayTimer(60);
|
||||
CountdownTimerSDL soundTimer(60);
|
||||
CountdownTimerSDL displayTimer(20);
|
||||
chocochip8::Interpreter chip8(display, buzzer, keypad, delayTimer, soundTimer);
|
||||
|
||||
auto rom = std::vector<char>();
|
||||
auto romfile = std::ifstream(argv[1] != NULL ? argv[1] : "/dev/stdin", std::ios_base::in | std::ios_base::binary);
|
||||
@@ -38,8 +42,6 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
SDL_Event event;
|
||||
bool done = false;
|
||||
Uint64 start, end;
|
||||
start = SDL_GetTicks64();
|
||||
while(!done) {
|
||||
while(SDL_PollEvent(&event)) {
|
||||
if(event.type == SDL_QUIT) {
|
||||
@@ -47,16 +49,13 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
}
|
||||
chip8.tick();
|
||||
display.updateWindow();
|
||||
SDL_Delay(1);
|
||||
end = SDL_GetTicks64();
|
||||
if(end - start > 3)
|
||||
std::cout << "Frame took too long: " << end - start << "\n";
|
||||
start = end;
|
||||
if(displayTimer.get() == 0) {
|
||||
display.updateWindow();
|
||||
displayTimer.set(1);
|
||||
}
|
||||
}
|
||||
|
||||
buzzer.off();
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user