commit c1320e9

Devine Lu Linvega  ·  2025-01-22 17:07:48 +0000 UTC
parent c8eaf26
(file.c) Cleanup
5 files changed,  +51, -27
+24, -0
 1@@ -0,0 +1,24 @@
 2+( )
 3+
 4+|00 @System &vector $2 &expansion $2 &wst $1 &rst $1 &metadata $2 &r $2 &g $2 &b $2 &debug $1 &state $1
 5+|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
 6+
 7+|100
 8+
 9+@on-reset ( -> )
10+	;file .File/name DEO2
11+	#0004 .File/length DEO2
12+	;mem .File/stat DEO2
13+	;mem <pstr>
14+	#0a18 DEO
15+	BRK
16+
17+@<pstr> ( str* -- )
18+	LDAk #18 DEO
19+	INC2 LDAk ?<pstr>
20+	POP2 JMP2r
21+
22+@file "README.md $1
23+
24+@mem "........
25+
+4, -1
 1@@ -18,7 +18,7 @@ debug: bin/uxnasm-debug bin/uxncli-debug bin/uxn11-debug bin/opctest.rom bin/con
 2 screen: bin/uxn11 
 3 	@ uxnasm etc/screen.bounds.tal bin/test.rom
 4 	@ bin/uxn11 bin/test.rom
 5-test: all bin/opctest.rom bin/expansion.rom
 6+test: all bin/opctest.rom bin/expansion.rom bin/file.rom
 7 	bin/uxncli
 8 	bin/uxncli -v
 9 	bin/uxn11
10@@ -27,6 +27,7 @@ test: all bin/opctest.rom bin/expansion.rom
11 	bin/uxnasm -v
12 	bin/uxncli bin/opctest.rom
13 	bin/uxncli bin/expansion.rom
14+	bin/uxncli bin/file.rom
15 install: all
16 	@ mkdir -p ${PREFIX}/bin
17 	@ cp bin/uxn11 bin/uxnasm bin/uxncli ${PREFIX}/bin
18@@ -49,6 +50,8 @@ bin/opctest.rom: bin/uxnasm
19 	@ bin/uxnasm etc/opctest.tal bin/opctest.rom
20 bin/expansion.rom: bin/uxnasm
21 	@ bin/uxnasm etc/system.expansion.tal bin/expansion.rom
22+bin/file.rom: bin/uxnasm
23+	@ bin/uxnasm etc/file.tal bin/file.rom
24 bin/mouse.rom: bin/uxnasm etc/mouse.tal
25 	@ bin/uxnasm etc/mouse.tal bin/mouse.rom
26 bin/console.rom: bin/uxnasm etc/console.tal
+21, -24
 1@@ -59,6 +59,24 @@ typedef struct {
 2 
 3 static UxnFile uxn_file[2];
 4 
 5+static Uint16
 6+put_fill(Uint8 *dest, Uint16 len, char c)
 7+{
 8+	Uint16 i;
 9+	for(i = 0; i < len; i++)
10+		*(dest++) = c;
11+	return len;
12+}
13+
14+static Uint16
15+put_size(Uint8 *dest, Uint16 len, off_t size)
16+{
17+	Uint16 i;
18+	for(i = 0, dest += len; i < len; i++, size >>= 4)
19+		*(--dest) = "0123456789abcdef"[(Uint8)(size & 0xf)];
20+	return len;
21+}
22+
23 static void
24 file_reset(UxnFile *c)
25 {
26@@ -270,27 +288,6 @@ file_write(UxnFile *c, Uint16 addr, Uint16 len, Uint8 flags)
27 	return ret;
28 }
29 
30-static Uint16
31-stat_fill(Uint8 *dest, Uint16 len, char c)
32-{
33-	Uint16 i;
34-	for(i = 0; i < len; i++)
35-		*(dest++) = c;
36-	return len;
37-}
38-
39-static Uint16
40-stat_size(Uint8 *dest, Uint16 len, off_t size)
41-{
42-	Uint16 i;
43-	dest += len - 1;
44-	for(i = 0; i < len; i++) {
45-		*(dest--) = "0123456789abcdef"[(Uint8)(size & 0xf)];
46-		size = size >> 4;
47-	}
48-	return size == 0 ? len : stat_fill(dest, len, '?');
49-}
50-
51 static Uint16
52 file_stat(UxnFile *c, Uint16 addr, Uint16 len)
53 {
54@@ -301,11 +298,11 @@ file_stat(UxnFile *c, Uint16 addr, Uint16 len)
55 	if(c->outside_sandbox)
56 		return 0;
57 	else if(stat(c->current_filename, &st))
58-		return stat_fill(dest, len, '!');
59+		return put_fill(dest, len, '!');
60 	else if(S_ISDIR(st.st_mode))
61-		return stat_fill(dest, len, '-');
62+		return put_fill(dest, len, '-');
63 	else
64-		return stat_size(dest, len, st.st_size);
65+		return put_size(dest, len, st.st_size);
66 }
67 
68 static Uint16
+1, -1
1@@ -247,7 +247,7 @@ main(int argc, char **argv)
2 {
3 	int i = 1;
4 	if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
5-		return !fprintf(stdout, "Uxn11 - Varvara Emulator, 21 Jan 2025.\n");
6+		return !fprintf(stdout, "Uxn11 - Varvara Emulator, 22 Jan 2025.\n");
7 	else if(argc == 1)
8 		return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
9 	else if(!display_init())
+1, -1
1@@ -48,7 +48,7 @@ main(int argc, char **argv)
2 {
3 	int i = 1;
4 	if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
5-		return !fprintf(stdout, "Uxn(cli) - Varvara Emulator, 20 Jan 2025.\n");
6+		return !fprintf(stdout, "Uxn(cli) - Varvara Emulator, 22 Jan 2025.\n");
7 	else if(argc == 1)
8 		return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
9 	else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++], argc > 2))