aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/chip8.cpp2
-rw-r--r--src/main.cpp59
-rw-r--r--src/platform.cpp11
-rw-r--r--src/test_opcode.ch8bin0 -> 478 bytes
4 files changed, 54 insertions, 18 deletions
diff --git a/src/chip8.cpp b/src/chip8.cpp
index dc63239..818a445 100644
--- a/src/chip8.cpp
+++ b/src/chip8.cpp
@@ -7,6 +7,8 @@
#include <thread>
#include <mutex>
+#include <string.h>
+
const uint32_t FONTSET_START_ADDRESS = 0x050;
const uint32_t ROM_START_ADDRESS = 0x200;
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;
}
diff --git a/src/platform.cpp b/src/platform.cpp
index 34a39e5..5d77180 100644
--- a/src/platform.cpp
+++ b/src/platform.cpp
@@ -45,12 +45,13 @@ void Platform::Update(const std::bitset<2048> bitset, int videoScale) {
for (int y = 0; y < 32; ++y) {
for (int x = 0; x < 64; ++x) {
SDL_Rect pixelRect = {x * videoScale, y * videoScale, videoScale, videoScale};
- if (bitset[y * 64 + x]) {
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
- } else {
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- }
- SDL_RenderFillRect(renderer, &pixelRect);
+ if (bitset[y * 64 + x]) {
+ SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
+ } else {
+ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
+ }
+ SDL_RenderFillRect(renderer, &pixelRect);
}
}
SDL_RenderPresent(renderer);
diff --git a/src/test_opcode.ch8 b/src/test_opcode.ch8
new file mode 100644
index 0000000..f540f69
--- /dev/null
+++ b/src/test_opcode.ch8
Binary files differ