Added timer

This commit is contained in:
neauoire 2022-03-27 19:10:32 -07:00
parent 6b2c815e50
commit a5d1172d22
3 changed files with 19 additions and 4 deletions

View File

@ -9,7 +9,7 @@ echo "Building.."
mkdir -p bin mkdir -p bin
# Build(debug) # Build(debug)
gcc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined src/uxn.c src/devices/system.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -o bin/uxn11 -lX11 gcc -std=c89 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined src/uxn.c src/devices/system.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -o bin/uxn11 -lX11
# Build(release) # Build(release)
# gcc src/uxn.c src/devices/system.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -o bin/uxn11 -lX11 # gcc src/uxn.c src/devices/system.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -o bin/uxn11 -lX11

BIN
etc/file.rom Normal file

Binary file not shown.

View File

@ -2,6 +2,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <sys/timerfd.h>
#include <unistd.h>
#include <poll.h>
#include "uxn.h" #include "uxn.h"
#include "devices/system.h" #include "devices/system.h"
@ -206,6 +209,9 @@ main(int argc, char **argv)
{ {
Uxn u; Uxn u;
int i; int i;
char expirations[8];
struct pollfd fds[2];
static const struct itimerspec screen_tspec = {{0, 16666666}, {0, 16666666}};
if(argc < 2) if(argc < 2)
return error("Usage", "uxncli game.rom args"); return error("Usage", "uxncli game.rom args");
if(!start(&u, argv[1])) if(!start(&u, argv[1]))
@ -218,13 +224,22 @@ main(int argc, char **argv)
while(*p) console_input(&u, *p++); while(*p) console_input(&u, *p++);
console_input(&u, '\n'); console_input(&u, '\n');
} }
fds[0].fd = XConnectionNumber(display);
fds[1].fd = timerfd_create(CLOCK_MONOTONIC, 0);
timerfd_settime(fds[1].fd, 0, &screen_tspec, NULL);
fds[0].events = fds[1].events = POLLIN;
/* main loop */ /* main loop */
while(1) { while(1) {
processEvent(); if(poll(fds, 2, 1000) <= 0)
uxn_eval(&u, GETVECTOR(devscreen)); continue;
while(XPending(display))
processEvent();
if(poll(&fds[1], 1, 0)) {
read(fds[1].fd, expirations, 8); /* Indicate we handled the timer */
uxn_eval(&u, GETVECTOR(devscreen)); /* Call the vector once, even if the timer fired multiple times */
}
if(uxn_screen.fg.changed || uxn_screen.bg.changed) if(uxn_screen.fg.changed || uxn_screen.bg.changed)
redraw(); redraw();
/* sleep(0.01); */
} }
XDestroyImage(ximage); XDestroyImage(ximage);
return 0; return 0;