Implemented most FXXX instructions.
It now passes the Corax+ test.
This commit is contained in:
49
main.cpp
49
main.cpp
@@ -1,12 +1,18 @@
|
||||
#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* args[]) {
|
||||
int main(int argc, char* argv[]) {
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
|
||||
std::cerr << "Couldn't initialize SDL: " << SDL_GetError() << '\n';
|
||||
return 1;
|
||||
@@ -21,33 +27,26 @@ int main(int argc, char* args[]) {
|
||||
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();
|
||||
}
|
||||
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;
|
||||
while(SDL_WaitEvent(&event) && event.type != SDL_QUIT) {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user