57 lines
1.3 KiB
C++
57 lines
1.3 KiB
C++
#include <iostream>
|
|
#include <iterator>
|
|
#include <fstream>
|
|
#include <vector>
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
#include "BuzzerSDL.hpp"
|
|
#include "DisplaySDL.hpp"
|
|
#include "Interpreter.hpp"
|
|
#include "Peripherals.hpp"
|
|
#include "SDL_events.h"
|
|
#include "SDL_timer.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);
|
|
DisplaySDL display(1280, 640);
|
|
TestKeypad keypad;
|
|
chocochip8::Interpreter chip8(90, 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);
|
|
std::copy(
|
|
std::istreambuf_iterator<char>(romfile),
|
|
std::istreambuf_iterator<char>(),
|
|
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();
|
|
display.updateWindow();
|
|
SDL_Delay(1000.0 / 60);
|
|
}
|
|
|
|
buzzer.off();
|
|
SDL_Quit();
|
|
return 0;
|
|
}
|
|
|