From 2d072d0d8f72c710ef10f620a9b2c9be604826a7 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Tue, 15 Mar 2022 18:54:42 +0100 Subject: Add datetime device (always starts at 0) --- Makefile | 2 +- src/main.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3f68019..100c861 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ CFLAGS += $(INC_FLAGS) CFLAGS += $(CONFIG) LDFLAGS := $(ARCH) $(SPECS) LDLIBS := $(LIBGBA) -RELEASE_CFLAGS := -DNDEBUG -O3 +RELEASE_CFLAGS := -DNDEBUG -O2 DEBUG_CFLAGS := -DDEBUG -O2 -g .PHONY: clean run diff --git a/src/main.c b/src/main.c index e73a740..296373f 100644 --- a/src/main.c +++ b/src/main.c @@ -10,6 +10,7 @@ WITH REGARD TO THIS SOFTWARE. */ #include +#include #include "common.h" #include "bitmap.h" @@ -69,6 +70,8 @@ WITH REGARD TO THIS SOFTWARE. #define PROF_INIT() #endif +static time_t seconds = 0; + typedef enum { CONTROL_CONTROLLER, CONTROL_MOUSE, @@ -200,9 +203,19 @@ audio_talk(Device *d, u8 b0, u8 w) { void datetime_talk(Device *d, u8 b0, u8 w) { - (void)d; (void)b0; (void)w; + struct tm *t = gmtime(&seconds); + t->tm_year += 1900; + DEVPOKE16(0x0, t->tm_year); + d->dat[0x2] = t->tm_mon; + d->dat[0x3] = t->tm_mday; + d->dat[0x4] = t->tm_hour; + d->dat[0x5] = t->tm_min; + d->dat[0x6] = t->tm_sec; + d->dat[0x7] = t->tm_wday; + DEVPOKE16(0x08, t->tm_yday); + d->dat[0xa] = t->tm_isdst; } void @@ -461,6 +474,7 @@ int main(void) { // Main loop. uxn_eval(&u, PAGE_PROGRAM); PROF_INIT(); + u8 frame_counter = 0; while(true) { bios_vblank_wait(); PROF(handle_input(&u), input_cycles); @@ -468,6 +482,11 @@ int main(void) { PROF(sound_mix(), mix_cycles); PROF_SHOW(); PROF(flipbuf(&ppu), flip_cycles); + frame_counter++; + if (frame_counter == 60) { + seconds++; + frame_counter = 0; + } } return 0; -- cgit v1.2.1