Files
choco-chip8/main.cpp

58 lines
1.3 KiB
C++

#include <iostream>
#include <SDL2/SDL.h>
#include "BuzzerSDL.hpp"
#include "DisplaySDL.hpp"
#include "Interpreter.hpp"
#include "Peripherals.hpp"
int main(int argc, char* args[]) {
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);
uint8_t prog[] = {
0xA0, 0x00, // LD I,0
0x60, 0x00, // LD $0,0
0x61, 0x00, // LD $1,0
0xD0, 0x15, // DRW $0, $1, 5
0xA0, 0x05, // LD I,5
0x60, 0x3C, // LD $0,60
0x61, 0x00, // LD $1,0
0xD0, 0x15, // DRW $0, $1, 5
0xA0, 0x0A, // LD I,10
0x60, 0x00, // LD $0,0
0x61, 0x1B, // LD $1,27
0xD0, 0x15, // DRW $0, $1, 5
0xA0, 0x0F, // LD I,15
0x60, 0x3C, // LD $0,60
0x61, 0x1B, // LD $1,27
0xD0, 0x15, // DRW $0, $1, 5
};
chip8.loadProgram((char*)prog, sizeof(prog));
for(int i = 0; i < sizeof(prog) / 2; i++) {
chip8.tick();
}
SDL_Event event;
while(SDL_WaitEvent(&event) && event.type != SDL_QUIT) {
display.updateWindow();
}
buzzer.off();
SDL_Quit();
return 0;
}