summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2019-09-28 17:39:05 -0400
committerAndrew Opalach <andrew@akon.city> 2019-09-28 17:39:05 -0400
commitd20068025b93350b7a1f6443542103c1a3569afe (patch)
tree1633744078fcd28af113e1a9537c4d364169e255
parentebd4ac832a30b97a267514ec83b00651041c54f4 (diff)
downloadchip8-d20068025b93350b7a1f6443542103c1a3569afe.tar.gz
chip8-d20068025b93350b7a1f6443542103c1a3569afe.tar.bz2
chip8-d20068025b93350b7a1f6443542103c1a3569afe.zip
make cpu 500hz
-rwxr-xr-xMakefile2
-rw-r--r--chip8.c6
-rw-r--r--ui_sdl.c15
3 files changed, 15 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 40a53e2..ddd2e05 100755
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ all: executable
win: executable
all: LDFLAGS = -lSDL2
-win: LDFLAGS = -lSDL2
+win: LDFLAGS = $(shell pkg-config --libs sdl2) -lws2_32
executable: chip8.c ui_sdl.c
$(CC) $(CFLAGS) -o $(BIN) chip8.c ui_sdl.c $(LDFLAGS)
diff --git a/chip8.c b/chip8.c
index 4bd8aa6..90c6823 100644
--- a/chip8.c
+++ b/chip8.c
@@ -4,11 +4,11 @@
#include <string.h>
#include <math.h>
#include <time.h>
-#include <arpa/inet.h>
#ifdef _WIN32
-#include <window.h>
-#else
+#include <winsock.h>
+#else
+#include <arpa/inet.h>
#include <unistd.h>
#endif
diff --git a/ui_sdl.c b/ui_sdl.c
index 894e45c..5d14fd3 100644
--- a/ui_sdl.c
+++ b/ui_sdl.c
@@ -1,3 +1,5 @@
+#define SDL_MAIN_HANDLED
+
#include <time.h>
#include <SDL2/SDL.h>
@@ -22,7 +24,7 @@ void draw() {
SDL_SetRenderDrawColor(r, 160, 200, 255, 255);
//SDL_RenderFillRect(r, &box);
for (int x = 0; x < 0x3F; x++) {
- for (int y = 0; y < 0x1F; y++) {
+ for (int y = 0; y <= 0x1F; y++) {
int byte = y * 64 + x;
int bit = byte & 0x07;
if ((vm.screen[byte>>3] & (1 << bit)) != 0) {
@@ -35,12 +37,13 @@ void draw() {
SDL_RenderPresent(r);
}
-int main(void) {
+int main(int argc, char* argv[]) {
srand(time(NULL));
setup();
load_rom();
init_vm();
+ int last_500hz = SDL_GetTicks();
int last_60hz = SDL_GetTicks();
int last_45hz = SDL_GetTicks();
@@ -95,6 +98,12 @@ int main(void) {
}
int cur = SDL_GetTicks();
+
+ if (cur - last_500hz >= (1000/500)) {
+ vm_step();
+ last_500hz = cur;
+ }
+
if (cur - last_60hz >= (1000/60)) {
if (vm.DT > 0) {
vm.DT--;
@@ -111,8 +120,6 @@ int main(void) {
draw();
last_45hz = cur;
}
-
- vm_step();
}
return 0;
}