diff options
| -rwxr-xr-x | Makefile | 2 | ||||
| -rw-r--r-- | chip8.c | 6 | ||||
| -rw-r--r-- | ui_sdl.c | 15 |
3 files changed, 15 insertions, 8 deletions
@@ -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) @@ -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 @@ -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; } |