summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorDaniel Jones <admin@danieljon.es>2020-08-16 23:05:55 +0930
committerDaniel Jones <admin@danieljon.es>2020-08-16 23:05:55 +0930
commit32336b183a5d3cbf64d2c67100afe036cf610694 (patch)
tree6e819be7850966f962554825ad5435fa6c139551 /main.c
parenteb19009d216f4fb0f7911b939b2f1bc698e40c79 (diff)
downloadchip8-32336b183a5d3cbf64d2c67100afe036cf610694.tar.gz
chip8-32336b183a5d3cbf64d2c67100afe036cf610694.zip
began chip8 interpreter, reading rom file
Diffstat (limited to 'main.c')
-rw-r--r--main.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/main.c b/main.c
index 056e5b1..a3b9539 100644
--- a/main.c
+++ b/main.c
@@ -1,8 +1,8 @@
#include <stdio.h>
+#include <stdlib.h>
#include <SDL2/SDL.h>
-#define WIDTH 64
-#define HEIGHT 32
+#include "chip8.h"
/* references
* https://austinmorlan.com/posts/chip8_emulator/
@@ -21,6 +21,15 @@ void init_video();
void update_video();
void toggle_pixel(int x, int y);
void quit();
+void usage(char *);
+
+extern uint32_t video[WIDTH*HEIGHT];
+
+void
+usage(char *program)
+{
+ printf("usage: %s [romfile]\n", program);
+}
void
quit()
@@ -41,8 +50,6 @@ init_video()
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STREAMING, WIDTH, HEIGHT);
}
-uint32_t video[WIDTH*HEIGHT];
-
void
update_video()
{
@@ -79,6 +86,20 @@ toggle_pixel(int x, int y)
int main(int argc, char *argv[])
{
+ if (argc < 2)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ if (!load_rom(argv[1]))
+ {
+ fprintf(stderr, "cannot start interpreter\n");
+ exit(EXIT_FAILURE);
+ }
+
+ chip8_init();
+
init_video();
const int fps = 60;
@@ -101,5 +122,5 @@ int main(int argc, char *argv[])
}
quit();
- return 0;
+ return EXIT_SUCCESS;
}