redesigned display peripheral

This commit is contained in:
2025-03-14 15:48:15 -04:00
parent af39b2ab07
commit ac5313a6ca
5 changed files with 63 additions and 53 deletions

View File

@@ -9,8 +9,8 @@
#include "DisplaySDL.hpp"
#include "Interpreter.hpp"
#include "Peripherals.hpp"
#include "SDL_events.h"
#include "SDL_timer.h"
#include "SDL2/SDL_events.h"
#include "SDL2/SDL_timer.h"
int main(int argc, char* argv[]) {
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
@@ -25,7 +25,7 @@ int main(int argc, char* argv[]) {
BuzzerSDL buzzer(440);
DisplaySDL display(1280, 640);
TestKeypad keypad;
chocochip8::Interpreter chip8(90, display, buzzer, keypad);
chocochip8::Interpreter chip8(1000, display, buzzer, keypad);
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,6 +38,8 @@ 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) {
@@ -46,7 +48,11 @@ int main(int argc, char* argv[]) {
}
chip8.tick();
display.updateWindow();
SDL_Delay(1000.0 / 60);
SDL_Delay(1);
end = SDL_GetTicks64();
if(end - start > 3)
std::cout << "Frame took too long: " << end - start << "\n";
start = end;
}
buzzer.off();