diff options
author | Bad Diode <bd@badd10de.dev> | 2022-03-15 18:54:42 +0100 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2022-03-15 18:54:42 +0100 |
commit | 2d072d0d8f72c710ef10f620a9b2c9be604826a7 (patch) | |
tree | a9a107f066d46884680f8a71c3ec2a53cd42b5ec | |
parent | 685be70c2c44cc239e80b1c7935103076b7167fd (diff) | |
download | uxngba-2d072d0d8f72c710ef10f620a9b2c9be604826a7.tar.gz uxngba-2d072d0d8f72c710ef10f620a9b2c9be604826a7.zip |
Add datetime device (always starts at 0)
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/main.c | 21 |
2 files changed, 21 insertions, 2 deletions
@@ -45,7 +45,7 @@ CFLAGS += $(INC_FLAGS) | |||
45 | CFLAGS += $(CONFIG) | 45 | CFLAGS += $(CONFIG) |
46 | LDFLAGS := $(ARCH) $(SPECS) | 46 | LDFLAGS := $(ARCH) $(SPECS) |
47 | LDLIBS := $(LIBGBA) | 47 | LDLIBS := $(LIBGBA) |
48 | RELEASE_CFLAGS := -DNDEBUG -O3 | 48 | RELEASE_CFLAGS := -DNDEBUG -O2 |
49 | DEBUG_CFLAGS := -DDEBUG -O2 -g | 49 | DEBUG_CFLAGS := -DDEBUG -O2 -g |
50 | 50 | ||
51 | .PHONY: clean run | 51 | .PHONY: clean run |
@@ -10,6 +10,7 @@ WITH REGARD TO THIS SOFTWARE. | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <string.h> | 12 | #include <string.h> |
13 | #include <time.h> | ||
13 | 14 | ||
14 | #include "common.h" | 15 | #include "common.h" |
15 | #include "bitmap.h" | 16 | #include "bitmap.h" |
@@ -69,6 +70,8 @@ WITH REGARD TO THIS SOFTWARE. | |||
69 | #define PROF_INIT() | 70 | #define PROF_INIT() |
70 | #endif | 71 | #endif |
71 | 72 | ||
73 | static time_t seconds = 0; | ||
74 | |||
72 | typedef enum { | 75 | typedef enum { |
73 | CONTROL_CONTROLLER, | 76 | CONTROL_CONTROLLER, |
74 | CONTROL_MOUSE, | 77 | CONTROL_MOUSE, |
@@ -200,9 +203,19 @@ audio_talk(Device *d, u8 b0, u8 w) { | |||
200 | 203 | ||
201 | void | 204 | void |
202 | datetime_talk(Device *d, u8 b0, u8 w) { | 205 | datetime_talk(Device *d, u8 b0, u8 w) { |
203 | (void)d; | ||
204 | (void)b0; | 206 | (void)b0; |
205 | (void)w; | 207 | (void)w; |
208 | struct tm *t = gmtime(&seconds); | ||
209 | t->tm_year += 1900; | ||
210 | DEVPOKE16(0x0, t->tm_year); | ||
211 | d->dat[0x2] = t->tm_mon; | ||
212 | d->dat[0x3] = t->tm_mday; | ||
213 | d->dat[0x4] = t->tm_hour; | ||
214 | d->dat[0x5] = t->tm_min; | ||
215 | d->dat[0x6] = t->tm_sec; | ||
216 | d->dat[0x7] = t->tm_wday; | ||
217 | DEVPOKE16(0x08, t->tm_yday); | ||
218 | d->dat[0xa] = t->tm_isdst; | ||
206 | } | 219 | } |
207 | 220 | ||
208 | void | 221 | void |
@@ -461,6 +474,7 @@ int main(void) { | |||
461 | // Main loop. | 474 | // Main loop. |
462 | uxn_eval(&u, PAGE_PROGRAM); | 475 | uxn_eval(&u, PAGE_PROGRAM); |
463 | PROF_INIT(); | 476 | PROF_INIT(); |
477 | u8 frame_counter = 0; | ||
464 | while(true) { | 478 | while(true) { |
465 | bios_vblank_wait(); | 479 | bios_vblank_wait(); |
466 | PROF(handle_input(&u), input_cycles); | 480 | PROF(handle_input(&u), input_cycles); |
@@ -468,6 +482,11 @@ int main(void) { | |||
468 | PROF(sound_mix(), mix_cycles); | 482 | PROF(sound_mix(), mix_cycles); |
469 | PROF_SHOW(); | 483 | PROF_SHOW(); |
470 | PROF(flipbuf(&ppu), flip_cycles); | 484 | PROF(flipbuf(&ppu), flip_cycles); |
485 | frame_counter++; | ||
486 | if (frame_counter == 60) { | ||
487 | seconds++; | ||
488 | frame_counter = 0; | ||
489 | } | ||
471 | } | 490 | } |
472 | 491 | ||
473 | return 0; | 492 | return 0; |