aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2022-03-15 18:54:42 +0100
committerBad Diode <bd@badd10de.dev>2022-03-15 18:54:42 +0100
commit2d072d0d8f72c710ef10f620a9b2c9be604826a7 (patch)
treea9a107f066d46884680f8a71c3ec2a53cd42b5ec
parent685be70c2c44cc239e80b1c7935103076b7167fd (diff)
downloaduxngba-2d072d0d8f72c710ef10f620a9b2c9be604826a7.tar.gz
uxngba-2d072d0d8f72c710ef10f620a9b2c9be604826a7.zip
Add datetime device (always starts at 0)
-rw-r--r--Makefile2
-rw-r--r--src/main.c21
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)
45CFLAGS += $(CONFIG) 45CFLAGS += $(CONFIG)
46LDFLAGS := $(ARCH) $(SPECS) 46LDFLAGS := $(ARCH) $(SPECS)
47LDLIBS := $(LIBGBA) 47LDLIBS := $(LIBGBA)
48RELEASE_CFLAGS := -DNDEBUG -O3 48RELEASE_CFLAGS := -DNDEBUG -O2
49DEBUG_CFLAGS := -DDEBUG -O2 -g 49DEBUG_CFLAGS := -DDEBUG -O2 -g
50 50
51.PHONY: clean run 51.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.
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
73static time_t seconds = 0;
74
72typedef enum { 75typedef 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
201void 204void
202datetime_talk(Device *d, u8 b0, u8 w) { 205datetime_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
208void 221void
@@ -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;