... | ... |
@@ -59,6 +59,8 @@ then |
59 | 59 |
clang-format -i src/devices/mouse.c |
60 | 60 |
clang-format -i src/devices/controller.h |
61 | 61 |
clang-format -i src/devices/controller.c |
62 |
+ clang-format -i src/devices/datetime.h |
|
63 |
+ clang-format -i src/devices/datetime.c |
|
62 | 64 |
clang-format -i src/uxnasm.c |
63 | 65 |
clang-format -i src/uxnemu.c |
64 | 66 |
clang-format -i src/uxncli.c |
... | ... |
@@ -97,8 +99,8 @@ fi |
97 | 99 |
|
98 | 100 |
echo "Building.." |
99 | 101 |
${CC} ${CFLAGS} src/uxnasm.c -o bin/uxnasm |
100 |
-${CC} ${CFLAGS} ${CORE} src/devices/system.c src/devices/file.c src/devices/mouse.c src/devices/controller.c src/devices/screen.c src/devices/audio.c src/uxnemu.c ${UXNEMU_LDFLAGS} -o bin/uxnemu |
|
101 |
-${CC} ${CFLAGS} ${CORE} src/devices/system.c src/devices/file.c src/uxncli.c -o bin/uxncli |
|
102 |
+${CC} ${CFLAGS} ${CORE} src/devices/system.c src/devices/file.c src/devices/datetime.c src/devices/mouse.c src/devices/controller.c src/devices/screen.c src/devices/audio.c src/uxnemu.c ${UXNEMU_LDFLAGS} -o bin/uxnemu |
|
103 |
+${CC} ${CFLAGS} ${CORE} src/devices/system.c src/devices/file.c src/devices/datetime.c src/uxncli.c -o bin/uxncli |
|
102 | 104 |
|
103 | 105 |
if [ -d "$HOME/bin" ] |
104 | 106 |
then |
105 | 107 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,40 @@ |
1 |
+#include <time.h> |
|
2 |
+ |
|
3 |
+#include "../uxn.h" |
|
4 |
+#include "datetime.h" |
|
5 |
+ |
|
6 |
+/* |
|
7 |
+Copyright (c) 2021 Devine Lu Linvega |
|
8 |
+Copyright (c) 2021 Andrew Alderwick |
|
9 |
+ |
|
10 |
+Permission to use, copy, modify, and distribute this software for any |
|
11 |
+purpose with or without fee is hereby granted, provided that the above |
|
12 |
+copyright notice and this permission notice appear in all copies. |
|
13 |
+ |
|
14 |
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
15 |
+WITH REGARD TO THIS SOFTWARE. |
|
16 |
+*/ |
|
17 |
+ |
|
18 |
+Uint8 |
|
19 |
+datetime_dei(Device *d, Uint8 port) |
|
20 |
+{ |
|
21 |
+ time_t seconds = time(NULL); |
|
22 |
+ struct tm zt = {0}; |
|
23 |
+ struct tm *t = localtime(&seconds); |
|
24 |
+ if(t == NULL) |
|
25 |
+ t = &zt; |
|
26 |
+ switch(port) { |
|
27 |
+ case 0x0: return (t->tm_year + 1900) >> 8; |
|
28 |
+ case 0x1: return (t->tm_year + 1900); |
|
29 |
+ case 0x2: return t->tm_mon; |
|
30 |
+ case 0x3: return t->tm_mday; |
|
31 |
+ case 0x4: return t->tm_hour; |
|
32 |
+ case 0x5: return t->tm_min; |
|
33 |
+ case 0x6: return t->tm_sec; |
|
34 |
+ case 0x7: return t->tm_wday; |
|
35 |
+ case 0x8: return t->tm_yday >> 8; |
|
36 |
+ case 0x9: return t->tm_yday; |
|
37 |
+ case 0xa: return t->tm_isdst; |
|
38 |
+ default: return d->dat[port]; |
|
39 |
+ } |
|
40 |
+} |
|
0 | 41 |
\ No newline at end of file |
1 | 42 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,13 @@ |
1 |
+/* |
|
2 |
+Copyright (c) 2021 Devine Lu Linvega |
|
3 |
+Copyright (c) 2021 Andrew Alderwick |
|
4 |
+ |
|
5 |
+Permission to use, copy, modify, and distribute this software for any |
|
6 |
+purpose with or without fee is hereby granted, provided that the above |
|
7 |
+copyright notice and this permission notice appear in all copies. |
|
8 |
+ |
|
9 |
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
10 |
+WITH REGARD TO THIS SOFTWARE. |
|
11 |
+*/ |
|
12 |
+ |
|
13 |
+Uint8 datetime_dei(Device *d, Uint8 port); |
|
0 | 14 |
\ No newline at end of file |
... | ... |
@@ -149,6 +149,16 @@ file_deo(Device *d, Uint8 port) |
149 | 149 |
case 0x1: |
150 | 150 |
DEVPEEK16(d->vector, 0x0); |
151 | 151 |
break; |
152 |
+ case 0x5: |
|
153 |
+ DEVPEEK16(a, 0x4); |
|
154 |
+ DEVPEEK16(b, 0xa); |
|
155 |
+ res = file_stat(&d->mem[a], b); |
|
156 |
+ DEVPOKE16(0x2, res); |
|
157 |
+ break; |
|
158 |
+ case 0x6: |
|
159 |
+ res = file_delete(); |
|
160 |
+ DEVPOKE16(0x2, res); |
|
161 |
+ break; |
|
152 | 162 |
case 0x9: |
153 | 163 |
DEVPEEK16(a, 0x8); |
154 | 164 |
res = file_init(&d->mem[a]); |
... | ... |
@@ -166,15 +176,5 @@ file_deo(Device *d, Uint8 port) |
166 | 176 |
res = file_write(&d->mem[a], b, d->dat[0x7]); |
167 | 177 |
DEVPOKE16(0x2, res); |
168 | 178 |
break; |
169 |
- case 0x5: |
|
170 |
- DEVPEEK16(a, 0x4); |
|
171 |
- DEVPEEK16(b, 0xa); |
|
172 |
- res = file_stat(&d->mem[a], b); |
|
173 |
- DEVPOKE16(0x2, res); |
|
174 |
- break; |
|
175 |
- case 0x6: |
|
176 |
- res = file_delete(); |
|
177 |
- DEVPOKE16(0x2, res); |
|
178 |
- break; |
|
179 | 179 |
} |
180 | 180 |
} |
181 | 181 |
\ No newline at end of file |
... | ... |
@@ -122,10 +122,11 @@ uxn_boot(Uxn *u, Uint8 *ram, Uint8 *devpage, Stack *wst, Stack *rst) |
122 | 122 |
} |
123 | 123 |
|
124 | 124 |
Device * |
125 |
-uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *d, Uint8 port), void (*deofn)(Device *d, Uint8 port)) |
|
125 |
+uxn_port(Uxn *u, Uint8 id, Uint16 mask, Uint8 (*deifn)(Device *d, Uint8 port), void (*deofn)(Device *d, Uint8 port)) |
|
126 | 126 |
{ |
127 | 127 |
Device *d = &u->dev[id]; |
128 | 128 |
d->u = u; |
129 |
+ d->mask = mask; |
|
129 | 130 |
d->mem = u->ram; |
130 | 131 |
d->dei = deifn; |
131 | 132 |
d->deo = deofn; |
... | ... |
@@ -37,7 +37,7 @@ typedef struct { |
37 | 37 |
typedef struct Device { |
38 | 38 |
struct Uxn *u; |
39 | 39 |
Uint8 *dat, *mem; |
40 |
- Uint16 vector; |
|
40 |
+ Uint16 vector, mask; |
|
41 | 41 |
Uint8 (*dei)(struct Device *d, Uint8); |
42 | 42 |
void (*deo)(struct Device *d, Uint8); |
43 | 43 |
} Device; |
... | ... |
@@ -51,4 +51,4 @@ typedef struct Uxn { |
51 | 51 |
int uxn_boot(Uxn *u, Uint8 *ram, Uint8 *devpage, Stack *wst, Stack *rst); |
52 | 52 |
int uxn_eval(Uxn *u, Uint16 pc); |
53 | 53 |
int uxn_halt(Uxn *u, Uint8 error, Uint16 addr); |
54 |
-Device *uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *, Uint8), void (*deofn)(Device *, Uint8)); |
|
54 |
+Device *uxn_port(Uxn *u, Uint8 id, Uint16 mask, Uint8 (*deifn)(Device *, Uint8), void (*deofn)(Device *, Uint8)); |
... | ... |
@@ -2,9 +2,11 @@ |
2 | 2 |
#include <stdlib.h> |
3 | 3 |
#include <unistd.h> |
4 | 4 |
#include <time.h> |
5 |
+ |
|
5 | 6 |
#include "uxn.h" |
6 | 7 |
#include "devices/system.h" |
7 | 8 |
#include "devices/file.h" |
9 |
+#include "devices/datetime.h" |
|
8 | 10 |
|
9 | 11 |
/* |
10 | 12 |
Copyright (c) 2021 Devine Lu Linvega |
... | ... |
@@ -64,30 +66,6 @@ console_deo(Device *d, Uint8 port) |
64 | 66 |
write(port - 0x7, (char *)&d->dat[port], 1); |
65 | 67 |
} |
66 | 68 |
|
67 |
-static Uint8 |
|
68 |
-datetime_dei(Device *d, Uint8 port) |
|
69 |
-{ |
|
70 |
- time_t seconds = time(NULL); |
|
71 |
- struct tm zt = {0}; |
|
72 |
- struct tm *t = localtime(&seconds); |
|
73 |
- if(t == NULL) |
|
74 |
- t = &zt; |
|
75 |
- switch(port) { |
|
76 |
- case 0x0: return (t->tm_year + 1900) >> 8; |
|
77 |
- case 0x1: return (t->tm_year + 1900); |
|
78 |
- case 0x2: return t->tm_mon; |
|
79 |
- case 0x3: return t->tm_mday; |
|
80 |
- case 0x4: return t->tm_hour; |
|
81 |
- case 0x5: return t->tm_min; |
|
82 |
- case 0x6: return t->tm_sec; |
|
83 |
- case 0x7: return t->tm_wday; |
|
84 |
- case 0x8: return t->tm_yday >> 8; |
|
85 |
- case 0x9: return t->tm_yday; |
|
86 |
- case 0xa: return t->tm_isdst; |
|
87 |
- default: return d->dat[port]; |
|
88 |
- } |
|
89 |
-} |
|
90 |
- |
|
91 | 69 |
static Uint8 |
92 | 70 |
nil_dei(Device *d, Uint8 port) |
93 | 71 |
{ |
... | ... |
@@ -146,22 +124,22 @@ main(int argc, char **argv) |
146 | 124 |
if(!uxn_boot(&u, memory, shadow + PAGE_DEV, (Stack *)(shadow + PAGE_WST), (Stack *)(shadow + PAGE_RST))) |
147 | 125 |
return error("Boot", "Failed"); |
148 | 126 |
|
149 |
- /* system */ devsystem = uxn_port(&u, 0x0, system_dei, system_deo); |
|
150 |
- /* console */ devconsole = uxn_port(&u, 0x1, nil_dei, console_deo); |
|
151 |
- /* empty */ uxn_port(&u, 0x2, nil_dei, nil_deo); |
|
152 |
- /* empty */ uxn_port(&u, 0x3, nil_dei, nil_deo); |
|
153 |
- /* empty */ uxn_port(&u, 0x4, nil_dei, nil_deo); |
|
154 |
- /* empty */ uxn_port(&u, 0x5, nil_dei, nil_deo); |
|
155 |
- /* empty */ uxn_port(&u, 0x6, nil_dei, nil_deo); |
|
156 |
- /* empty */ uxn_port(&u, 0x7, nil_dei, nil_deo); |
|
157 |
- /* empty */ uxn_port(&u, 0x8, nil_dei, nil_deo); |
|
158 |
- /* empty */ uxn_port(&u, 0x9, nil_dei, nil_deo); |
|
159 |
- /* file */ uxn_port(&u, 0xa, nil_dei, file_deo); |
|
160 |
- /* datetime */ uxn_port(&u, 0xb, datetime_dei, nil_deo); |
|
161 |
- /* empty */ uxn_port(&u, 0xc, nil_dei, nil_deo); |
|
162 |
- /* empty */ uxn_port(&u, 0xd, nil_dei, nil_deo); |
|
163 |
- /* empty */ uxn_port(&u, 0xe, nil_dei, nil_deo); |
|
164 |
- /* empty */ uxn_port(&u, 0xf, nil_dei, nil_deo); |
|
127 |
+ /* system */ devsystem = uxn_port(&u, 0x0, 0xffff, system_dei, system_deo); |
|
128 |
+ /* console */ devconsole = uxn_port(&u, 0x1, 0xffff, nil_dei, console_deo); |
|
129 |
+ /* empty */ uxn_port(&u, 0x2, 0xffff, nil_dei, nil_deo); |
|
130 |
+ /* empty */ uxn_port(&u, 0x3, 0xffff, nil_dei, nil_deo); |
|
131 |
+ /* empty */ uxn_port(&u, 0x4, 0xffff, nil_dei, nil_deo); |
|
132 |
+ /* empty */ uxn_port(&u, 0x5, 0xffff, nil_dei, nil_deo); |
|
133 |
+ /* empty */ uxn_port(&u, 0x6, 0xffff, nil_dei, nil_deo); |
|
134 |
+ /* empty */ uxn_port(&u, 0x7, 0xffff, nil_dei, nil_deo); |
|
135 |
+ /* empty */ uxn_port(&u, 0x8, 0xffff, nil_dei, nil_deo); |
|
136 |
+ /* empty */ uxn_port(&u, 0x9, 0xffff, nil_dei, nil_deo); |
|
137 |
+ /* file */ uxn_port(&u, 0xa, 0xffff, nil_dei, file_deo); |
|
138 |
+ /* datetime */ uxn_port(&u, 0xb, 0xffff, datetime_dei, nil_deo); |
|
139 |
+ /* empty */ uxn_port(&u, 0xc, 0xffff, nil_dei, nil_deo); |
|
140 |
+ /* empty */ uxn_port(&u, 0xd, 0xffff, nil_dei, nil_deo); |
|
141 |
+ /* empty */ uxn_port(&u, 0xe, 0xffff, nil_dei, nil_deo); |
|
142 |
+ /* empty */ uxn_port(&u, 0xf, 0xffff, nil_dei, nil_deo); |
|
165 | 143 |
|
166 | 144 |
for(i = 1; i < argc; i++) { |
167 | 145 |
if(!loaded++) { |
... | ... |
@@ -14,6 +14,7 @@ |
14 | 14 |
#include "devices/file.h" |
15 | 15 |
#include "devices/controller.h" |
16 | 16 |
#include "devices/mouse.h" |
17 |
+#include "devices/datetime.h" |
|
17 | 18 |
#pragma GCC diagnostic pop |
18 | 19 |
#pragma clang diagnostic pop |
19 | 20 |
|
... | ... |
@@ -218,30 +219,6 @@ audio_deo(Device *d, Uint8 port) |
218 | 219 |
} |
219 | 220 |
} |
220 | 221 |
|
221 |
-static Uint8 |
|
222 |
-datetime_dei(Device *d, Uint8 port) |
|
223 |
-{ |
|
224 |
- time_t seconds = time(NULL); |
|
225 |
- struct tm zt = {0}; |
|
226 |
- struct tm *t = localtime(&seconds); |
|
227 |
- if(t == NULL) |
|
228 |
- t = &zt; |
|
229 |
- switch(port) { |
|
230 |
- case 0x0: return (t->tm_year + 1900) >> 8; |
|
231 |
- case 0x1: return (t->tm_year + 1900); |
|
232 |
- case 0x2: return t->tm_mon; |
|
233 |
- case 0x3: return t->tm_mday; |
|
234 |
- case 0x4: return t->tm_hour; |
|
235 |
- case 0x5: return t->tm_min; |
|
236 |
- case 0x6: return t->tm_sec; |
|
237 |
- case 0x7: return t->tm_wday; |
|
238 |
- case 0x8: return t->tm_yday >> 8; |
|
239 |
- case 0x9: return t->tm_yday; |
|
240 |
- case 0xa: return t->tm_isdst; |
|
241 |
- default: return d->dat[port]; |
|
242 |
- } |
|
243 |
-} |
|
244 |
- |
|
245 | 222 |
static Uint8 |
246 | 223 |
nil_dei(Device *d, Uint8 port) |
247 | 224 |
{ |
... | ... |
@@ -287,27 +264,27 @@ start(Uxn *u, char *rom) |
287 | 264 |
if(!load(u, rom)) |
288 | 265 |
return error("Boot", "Failed to load rom."); |
289 | 266 |
|
290 |
- /* system */ devsystem = uxn_port(u, 0x0, system_dei, system_deo); |
|
291 |
- /* console */ devconsole = uxn_port(u, 0x1, nil_dei, console_deo); |
|
292 |
- /* screen */ devscreen = uxn_port(u, 0x2, screen_dei, screen_deo); |
|
293 |
- /* audio0 */ devaudio0 = uxn_port(u, 0x3, audio_dei, audio_deo); |
|
294 |
- /* audio1 */ uxn_port(u, 0x4, audio_dei, audio_deo); |
|
295 |
- /* audio2 */ uxn_port(u, 0x5, audio_dei, audio_deo); |
|
296 |
- /* audio3 */ uxn_port(u, 0x6, audio_dei, audio_deo); |
|
297 |
- /* unused */ uxn_port(u, 0x7, nil_dei, nil_deo); |
|
298 |
- /* control */ devctrl = uxn_port(u, 0x8, nil_dei, nil_deo); |
|
299 |
- /* mouse */ devmouse = uxn_port(u, 0x9, nil_dei, nil_deo); |
|
300 |
- /* file */ uxn_port(u, 0xa, nil_dei, file_deo); |
|
301 |
- /* datetime */ uxn_port(u, 0xb, datetime_dei, nil_deo); |
|
302 |
- /* unused */ uxn_port(u, 0xc, nil_dei, nil_deo); |
|
303 |
- /* unused */ uxn_port(u, 0xd, nil_dei, nil_deo); |
|
304 |
- /* unused */ uxn_port(u, 0xe, nil_dei, nil_deo); |
|
305 |
- /* unused */ uxn_port(u, 0xf, nil_dei, nil_deo); |
|
267 |
+ /* system */ devsystem = uxn_port(u, 0x0, 0xffff, system_dei, system_deo); |
|
268 |
+ /* console */ devconsole = uxn_port(u, 0x1, 0xffff, nil_dei, console_deo); |
|
269 |
+ /* screen */ devscreen = uxn_port(u, 0x2, 0xffff, screen_dei, screen_deo); |
|
270 |
+ /* audio0 */ devaudio0 = uxn_port(u, 0x3, 0xffff, audio_dei, audio_deo); |
|
271 |
+ /* audio1 */ uxn_port(u, 0x4, 0xffff, audio_dei, audio_deo); |
|
272 |
+ /* audio2 */ uxn_port(u, 0x5, 0xffff, audio_dei, audio_deo); |
|
273 |
+ /* audio3 */ uxn_port(u, 0x6, 0xffff, audio_dei, audio_deo); |
|
274 |
+ /* unused */ uxn_port(u, 0x7, 0xffff, nil_dei, nil_deo); |
|
275 |
+ /* control */ devctrl = uxn_port(u, 0x8, 0xffff, nil_dei, nil_deo); |
|
276 |
+ /* mouse */ devmouse = uxn_port(u, 0x9, 0xffff, nil_dei, nil_deo); |
|
277 |
+ /* file */ uxn_port(u, 0xa, 0xffff, nil_dei, file_deo); |
|
278 |
+ /* datetime */ uxn_port(u, 0xb, 0xffff, datetime_dei, nil_deo); |
|
279 |
+ /* unused */ uxn_port(u, 0xc, 0xffff, nil_dei, nil_deo); |
|
280 |
+ /* unused */ uxn_port(u, 0xd, 0xffff, nil_dei, nil_deo); |
|
281 |
+ /* unused */ uxn_port(u, 0xe, 0xffff, nil_dei, nil_deo); |
|
282 |
+ /* unused */ uxn_port(u, 0xf, 0xffff, nil_dei, nil_deo); |
|
306 | 283 |
|
307 | 284 |
/* Supervisor */ |
308 |
- uxn_port(&supervisor, 0x0, system_dei, system_deo); |
|
309 |
- uxn_port(&supervisor, 0x1, nil_dei, console_deo); |
|
310 |
- uxn_port(&supervisor, 0x2, screen_dei, screen_deo); |
|
285 |
+ uxn_port(&supervisor, 0x0, 0xffff, system_dei, system_deo); |
|
286 |
+ uxn_port(&supervisor, 0x1, 0xffff, nil_dei, console_deo); |
|
287 |
+ uxn_port(&supervisor, 0x2, 0xffff, screen_dei, screen_deo); |
|
311 | 288 |
|
312 | 289 |
uxn_eval(&supervisor, PAGE_PROGRAM); |
313 | 290 |
|