commit 2997738
Devine Lu Linvega
·
2025-05-17 22:23:57 +0000 UTC
parent c2825bc
Cleanup
1 files changed,
+65,
-70
+65,
-70
1@@ -26,12 +26,12 @@ typedef struct {
2 static Uint8 *ram, dev[0x100];
3 static Stack wst, rst;
4
5-Uint8 emu_dei(Uint8 addr);
6+unsigned int emu_dei(Uint8 addr);
7 void emu_deo(Uint8 addr, Uint8 value);
8
9 /* clang-format off */
10
11-#define RAM_PAGES 0x10
12+#define BANKS 0x10
13 #define PEEK2(d) (*(d) << 8 | (d)[1])
14 #define POKE2(d, v) { *(d) = (v) >> 8; (d)[1] = (v); }
15
16@@ -140,18 +140,18 @@ system_load(char *rom_path)
17 {
18 FILE *f = fopen(rom_path, "rb");
19 if(f) {
20- int i = 0, l = fread(ram + 0x100, 0x10000 - 0x100, 1, f);
21- while(l && ++i < RAM_PAGES)
22- l = fread(ram + i * 0x10000, 0x10000, 1, f);
23+ unsigned int i = 0, l = fread(ram + 0x100, 0x10000 - 0x100, 1, f);
24+ while(l && ++i < BANKS)
25+ l = fread(ram + (i * 0x10000), 0x10000, 1, f);
26 fclose(f);
27 }
28 return !!f;
29 }
30
31 static int
32-system_boot(char *rom_path, int has_args)
33+system_boot(char *rom_path, unsigned int has_args)
34 {
35- ram = (Uint8 *)calloc(RAM_PAGES * 0x10000, sizeof(Uint8));
36+ ram = (Uint8 *)calloc(BANKS * 0x10000, sizeof(Uint8));
37 system_boot_path = rom_path;
38 dev[0x17] = has_args;
39 return system_load(rom_path);
40@@ -363,7 +363,7 @@ start_fork(void)
41 }
42
43 static int
44-console_input(int c, int type)
45+console_input(unsigned int c, unsigned int type)
46 {
47 if(c == EOF) c = 0, type = 4;
48 dev[0x12] = c, dev[0x17] = type;
49@@ -407,25 +407,25 @@ make_pathfile(char *pathbuf, const char *filepath, const char *basename)
50 *pathbuf = 0;
51 }
52
53-static int
54-put_fill(Uint8 *dest, int len, char c)
55+static unsigned int
56+put_fill(Uint8 *dest, unsigned int len, char c)
57 {
58- int i;
59+ unsigned int i;
60 for(i = 0; i < len; i++)
61 *dest = c, dest++;
62 return len;
63 }
64
65-static int
66-put_size(Uint8 *dest, int len, int size)
67+static unsigned int
68+put_size(Uint8 *dest, unsigned int len, unsigned int size)
69 {
70- int i;
71+ unsigned int i;
72 for(i = 0, dest += len; i < len; i++, size >>= 4)
73 *(--dest) = "0123456789abcdef"[(Uint8)(size & 0xf)];
74 return len;
75 }
76
77-static int
78+static unsigned int
79 put_text(Uint8 *dest, const char *text)
80 {
81 Uint8 *anchor = dest;
82@@ -435,8 +435,8 @@ put_text(Uint8 *dest, const char *text)
83 return dest - anchor;
84 }
85
86-static int
87-put_stat(Uint8 *dest, int len, int size, int err, int dir, int capsize)
88+static unsigned int
89+put_stat(Uint8 *dest, unsigned int len, unsigned int size, unsigned int err, unsigned int dir, unsigned int capsize)
90 {
91 if(err) return put_fill(dest, len, '!');
92 if(dir) return put_fill(dest, len, '-');
93@@ -444,10 +444,10 @@ put_stat(Uint8 *dest, int len, int size, int err, int dir, int capsize)
94 return put_size(dest, len, size);
95 }
96
97-static int
98+static unsigned int
99 put_statfile(Uint8 *dest, const char *filepath, const char *basename)
100 {
101- int err, dir;
102+ unsigned int err, dir;
103 struct stat st;
104 Uint8 *anchor = dest;
105 char pathbuf[0x2000];
106@@ -461,10 +461,10 @@ put_statfile(Uint8 *dest, const char *filepath, const char *basename)
107 return dest - anchor;
108 }
109
110-static int
111-put_fdir(Uint8 *dest, int len, const char *filepath, DIR *dir)
112+static unsigned int
113+put_fdir(Uint8 *dest, unsigned int len, const char *filepath, DIR *dir)
114 {
115- int i;
116+ unsigned int i;
117 struct dirent *de = readdir(dir);
118 for(_dirbuf = dirbuf; de != NULL; de = readdir(dir)) {
119 char *name = de->d_name;
120@@ -479,26 +479,26 @@ put_fdir(Uint8 *dest, int len, const char *filepath, DIR *dir)
121 return i;
122 }
123
124-static int
125+static unsigned int
126 is_dir_path(char *p)
127 {
128 char c;
129- int saw_slash = 0;
130+ unsigned int saw_slash = 0;
131 while((c = *p++)) saw_slash = c == '/';
132 return saw_slash;
133 }
134
135-static int
136+static unsigned int
137 is_dir_real(char *p)
138 {
139 struct stat st;
140 return stat(p, &st) == 0 && S_ISDIR(st.st_mode);
141 }
142
143-static int
144+static unsigned int
145 file_write_dir(char *p)
146 {
147- int ok = 1;
148+ unsigned int ok = 1;
149 char c, *s = p;
150 for(; ok && (c = *p); p++) {
151 if(c == '/') {
152@@ -511,23 +511,23 @@ file_write_dir(char *p)
153 }
154
155 static void
156-file_reset(int id)
157+file_reset(unsigned int id)
158 {
159 if(ufs[id].f != NULL) fclose(ufs[id].f), ufs[id].f = NULL;
160 if(ufs[id].dir != NULL) closedir(ufs[id].dir), ufs[id].dir = NULL;
161 ufs[id].state = IDLE;
162 }
163
164-static int
165-file_init(int id, Uint16 addr)
166+static unsigned int
167+file_init(unsigned int id, Uint16 addr)
168 {
169 file_reset(id);
170 ufs[id].filepath = (char *)&ram[addr];
171 return 0;
172 }
173
174-static int
175-file_not_ready(int id)
176+static unsigned int
177+file_not_ready(unsigned int id)
178 {
179 if(ufs[id].filepath == 0) {
180 fprintf(stderr, "File %d is uninitialized\n", id);
181@@ -536,8 +536,8 @@ file_not_ready(int id)
182 return 0;
183 }
184
185-static int
186-file_read(int id, Uint16 addr, int len)
187+static unsigned int
188+file_read(unsigned int id, Uint16 addr, unsigned int len)
189 {
190 void *dest = &ram[addr];
191 if(file_not_ready(id))
192@@ -556,10 +556,10 @@ file_read(int id, Uint16 addr, int len)
193 return 0;
194 }
195
196-static int
197-file_write(int id, Uint16 addr, int len, Uint8 flags)
198+static unsigned int
199+file_write(unsigned int id, Uint16 addr, unsigned int len, Uint8 flags)
200 {
201- int ret = 0;
202+ unsigned int ret = 0;
203 if(file_not_ready(id))
204 return 0;
205 file_write_dir(ufs[id].filepath);
206@@ -578,10 +578,10 @@ file_write(int id, Uint16 addr, int len, Uint8 flags)
207 return ret;
208 }
209
210-static int
211-file_stat(int id, Uint16 addr, int len)
212+static unsigned int
213+file_stat(unsigned int id, Uint16 addr, unsigned int len)
214 {
215- int err, dir;
216+ unsigned int err, dir;
217 struct stat st;
218 if(file_not_ready(id))
219 return 0;
220@@ -590,8 +590,8 @@ file_stat(int id, Uint16 addr, int len)
221 return put_stat(&ram[addr], len, st.st_size, err, dir, 0);
222 }
223
224-static int
225-file_delete(int id)
226+static unsigned int
227+file_delete(unsigned int id)
228 {
229 if(file_not_ready(id))
230 return -1;
231@@ -599,47 +599,24 @@ file_delete(int id)
232 }
233
234 static void
235-file_success(int port, int value)
236+file_success(unsigned int port, unsigned int value)
237 {
238 POKE2(&dev[port], value);
239 }
240
241 /* file registers */
242
243-static int rL1, rL2;
244+static unsigned int rL1, rL2;
245
246 /*
247 @|Datetime ---------------------------------------------------------- */
248
249 #include <time.h>
250
251-static Uint8
252-datetime_dei(Uint8 addr)
253-{
254- time_t seconds = time(NULL);
255- struct tm zt = {0};
256- struct tm *t = localtime(&seconds);
257- if(t == NULL) t = &zt;
258- switch(addr) {
259- case 0xc0: return (t->tm_year + 1900) >> 8;
260- case 0xc1: return (t->tm_year + 1900);
261- case 0xc2: return t->tm_mon;
262- case 0xc3: return t->tm_mday;
263- case 0xc4: return t->tm_hour;
264- case 0xc5: return t->tm_min;
265- case 0xc6: return t->tm_sec;
266- case 0xc7: return t->tm_wday;
267- case 0xc8: return t->tm_yday >> 8;
268- case 0xc9: return t->tm_yday;
269- case 0xca: return t->tm_isdst;
270- default: return dev[addr];
271- }
272-}
273-
274 /*
275 @|Core -------------------------------------------------------------- */
276
277-Uint8
278+unsigned int
279 emu_dei(Uint8 addr)
280 {
281 switch(addr) {
282@@ -650,8 +627,26 @@ emu_dei(Uint8 addr)
283 case CMD_LIVE:
284 case CMD_EXIT: check_child(); break;
285 }
286- if((addr & 0xf0) == 0xc0)
287- return datetime_dei(addr);
288+ /* Datetime */
289+ if((addr & 0xf0) == 0xc0) {
290+ time_t seconds = time(NULL);
291+ struct tm zt = {0};
292+ struct tm *t = localtime(&seconds);
293+ if(t == NULL) t = &zt;
294+ switch(addr) {
295+ case 0xc0: return (t->tm_year + 1900) >> 8;
296+ case 0xc1: return (t->tm_year + 1900);
297+ case 0xc2: return t->tm_mon;
298+ case 0xc3: return t->tm_mday;
299+ case 0xc4: return t->tm_hour;
300+ case 0xc5: return t->tm_min;
301+ case 0xc6: return t->tm_sec;
302+ case 0xc7: return t->tm_wday;
303+ case 0xc8: return t->tm_yday >> 8;
304+ case 0xc9: return t->tm_yday;
305+ case 0xca: return t->tm_isdst;
306+ }
307+ }
308 return dev[addr];
309 }
310