Sync updates at 60hz
This commit is contained in:
parent
87ce7bbb4b
commit
6b29a0cb08
2
Makefile
2
Makefile
|
@ -6,7 +6,7 @@ EXE_NAME ?= uxnfb
|
|||
BIN := $(BUILD_DIR)/$(EXE_NAME)
|
||||
UXN_HEAD := $(BASE_UXN)/src/uxn.h
|
||||
TAL_SRC ?= $(BASE_UXN)/projects/examples/devices/screen.tal
|
||||
UXN_ROM ?= $(BUILD_DIR)/screen.rom
|
||||
UXN_ROM ?= $(BUILD_DIR)/rom.rom
|
||||
UXN_ASM ?= $(BUILD_DIR)/uxnasm
|
||||
|
||||
CC ?= cc
|
||||
|
|
35
src/main.c
35
src/main.c
|
@ -1,9 +1,11 @@
|
|||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <linux/fb.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
|
@ -18,6 +20,21 @@ static Device *devctrl;
|
|||
static Device *devmouse;
|
||||
static Device *devaudio;
|
||||
|
||||
typedef struct timespec Time;
|
||||
|
||||
Time
|
||||
time_now(){
|
||||
struct timespec t;
|
||||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t);
|
||||
return t;
|
||||
}
|
||||
|
||||
size_t
|
||||
time_elapsed(Time since){
|
||||
struct timespec now = time_now();
|
||||
return (now.tv_sec - since.tv_sec) * 1e9 + (now.tv_nsec - since.tv_nsec);
|
||||
}
|
||||
|
||||
void
|
||||
nil_talk(Device *d, u8 b0, u8 w) {
|
||||
(void)d;
|
||||
|
@ -228,19 +245,17 @@ main(int argc, char *argv[]) {
|
|||
|
||||
// Main loop.
|
||||
uxn_eval(&u, 0x0100);
|
||||
// u64 current_ticks = timer_get_ticks();
|
||||
Time frame_time = time_now();
|
||||
while (true) {
|
||||
size_t elapsed = time_elapsed(frame_time);
|
||||
if (elapsed >= 16666666) {
|
||||
// Echo input to standard output.
|
||||
uxn_eval(&u, mempeek16(devscreen->dat, 0));
|
||||
|
||||
// Blit ppu.pixels to the framebuffer.
|
||||
blit_framebuffer();
|
||||
|
||||
// TODO: Sync at 60 Hz.
|
||||
// if ((timer_get_ticks() - current_ticks) < 16666) {
|
||||
// wait(16666 - (timer_get_ticks() - current_ticks));
|
||||
// }
|
||||
// current_ticks = timer_get_ticks();
|
||||
frame_time = time_now();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue