#include #include #include #include #include #include "BuzzerSDL.hpp" #include "CountdownTimerSDL.hpp" #include "DisplaySDL.hpp" #include "Interpreter.hpp" #include "Peripherals.hpp" #include "SDL2/SDL_events.h" int main(int argc, char* argv[]) { if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { std::cerr << "Couldn't initialize SDL: " << SDL_GetError() << '\n'; return 1; } class TestKeypad : public chocochip8::Keypad { bool isKeyPressed(chocochip8::Key) override { return false; } }; BuzzerSDL buzzer(440); int N = 4; DisplaySDL display(128*N, 64*N); TestKeypad keypad; CountdownTimerSDL delayTimer(60); CountdownTimerSDL soundTimer(60); CountdownTimerSDL displayTimer(20); chocochip8::Interpreter chip8(display, buzzer, keypad, delayTimer, soundTimer); auto rom = std::vector(); auto romfile = std::ifstream(argv[1] != NULL ? argv[1] : "/dev/stdin", std::ios_base::in | std::ios_base::binary); std::copy( std::istreambuf_iterator(romfile), std::istreambuf_iterator(), std::back_insert_iterator(rom) ); chip8.loadProgram(rom.data(), rom.size()); SDL_Event event; bool done = false; while(!done) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) { done = true; } } chip8.tick(); if(displayTimer.get() == 0) { display.updateWindow(); displayTimer.set(1); } } buzzer.off(); SDL_Quit(); return 0; }