aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp59
1 files changed, 46 insertions, 13 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 1eb5c30..941072d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,9 +7,38 @@
#define WINDOW_TITLE "chip8emu"
+Platform pPlatform(
+ WINDOW_TITLE,
+ VIDEO_WIDTH * 10,
+ VIDEO_HEIGHT * 10,
+ VIDEO_WIDTH, VIDEO_HEIGHT
+);
+
+Chip8* pChip8;
+
+void mainLoop() {
+ Platform* platform = &pPlatform;
+ platform->ProcessInput(&pChip8->keypad);
+
+ usleep(2 * 1000);
+ platform->ProcessInput(&pChip8->keypad);
+ pChip8->Cycle();
+ platform->Update(pChip8->video, 10);
+}
+
+#ifdef __EMSCRIPTEN__
+
+#include <emscripten.h>
+int main() {
+ int videoScale = 10;
+ int cycleDelay = 0;
+ char const* filename = "test_opcode.ch8";
+
+#else
+
int main(int argc, char** argv) {
if (argc != 4) {
- std::cerr << "Usage: " << argv[0] << " <Scale> <Delay> <ROM>\n";
+ std::cerr << "Usage: " << argv[0] << " <Scale> <Delay> <ROM>" << std::endl;
std::exit(EXIT_FAILURE);
}
@@ -17,6 +46,8 @@ int main(int argc, char** argv) {
int cycleDelay = std::stoi(argv[2]);
char const* filename = argv[3];
+#endif
+
Chip8* chip8 = new Chip8();
Table* table = new Table(chip8);
@@ -24,26 +55,28 @@ int main(int argc, char** argv) {
chip8->LoadROM(filename);
- Platform platform(
+ pChip8 = chip8;
+
+ /* Platform platform(
WINDOW_TITLE,
VIDEO_WIDTH * videoScale,
VIDEO_HEIGHT * videoScale,
VIDEO_WIDTH, VIDEO_HEIGHT
- );
+ ); */
- std::thread timerThread(&Chip8::TimerUpdateThread, chip8, &platform);
+ // std::thread timerThread(&Chip8::TimerUpdateThread, chip8, &platform);
+#ifdef __EMSCRIPTEN__
- bool quit = false;
- while (!quit) {
- quit = platform.ProcessInput(&chip8->keypad);
+ emscripten_set_main_loop(mainLoop, 0, 0);
- usleep(cycleDelay * 1000);
-
- chip8->Cycle();
- platform.Update(chip8->video, videoScale);
- }
+#else
+
+ bool quit = false;
+ while (!quit)
+ mainLoop();
- timerThread.detach();
+#endif
+ // timerThread.detach();
return 0;
}