From d20068025b93350b7a1f6443542103c1a3569afe Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Sat, 28 Sep 2019 17:39:05 -0400 Subject: make cpu 500hz --- Makefile | 2 +- chip8.c | 6 +++--- ui_sdl.c | 15 +++++++++++---- 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 #include #include -#include #ifdef _WIN32 -#include -#else +#include +#else +#include #include #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 #include @@ -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; } -- cgit v1.2.3-101-g0448