... | ... |
@@ -21,7 +21,7 @@ |
21 | 21 |
|60 @Audio3 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] |
22 | 22 |
|80 @Controller [ &vector $2 &button $1 &key $1 ] |
23 | 23 |
|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] |
24 |
-|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] |
|
24 |
+|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] |
|
25 | 25 |
|b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ] |
26 | 26 |
|
27 | 27 |
( variables ) |
... | ... |
@@ -2,7 +2,7 @@ |
2 | 2 |
|
3 | 3 |
|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ] |
4 | 4 |
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ] |
5 |
-|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] |
|
5 |
+|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] |
|
6 | 6 |
|
7 | 7 |
( vectors ) |
8 | 8 |
|
... | ... |
@@ -37,12 +37,12 @@ |
37 | 37 |
Load the output ROM over the currently running program, almost as if |
38 | 38 |
we loaded the ROM with uxnemu directly! |
39 | 39 |
|
40 |
- It's not a totally pristine environment, as File/load doesn't zero out |
|
40 |
+ It's not a totally pristine environment, as File/read doesn't zero out |
|
41 | 41 |
memory beyond the end of the file. So if the assembled program assumes |
42 | 42 |
that all memory above it is zero, it may misbehave. |
43 | 43 |
|
44 | 44 |
Asma itself doesn't use the zero page, but this example code writes a |
45 |
- DEO2 instruction to 0x00ff. In order to execute File/load and have the |
|
45 |
+ DEO2 instruction to 0x00ff. In order to execute File/read and have the |
|
46 | 46 |
CPU continue at memory location 0x0100, we write the final DEO2 |
47 | 47 |
instruction there and jump there as our final act. |
48 | 48 |
|
... | ... |
@@ -52,7 +52,7 @@ |
52 | 52 |
) |
53 | 53 |
;&dest-file .File/name DEO2 |
54 | 54 |
#ff00 .File/length DEO2 |
55 |
- #0100 .File/load |
|
55 |
+ #0100 .File/read |
|
56 | 56 |
LIT DEO2 #00ff STA |
57 | 57 |
LIT BRK #0100 STA |
58 | 58 |
#00ff JMP2 |
... | ... |
@@ -30,7 +30,7 @@ |
30 | 30 |
|70 @Midi [ &vector $2 &channel $1 ¬e $1 &velocity $1 ] |
31 | 31 |
|80 @Controller [ &vector $2 &button $1 &key $1 ] |
32 | 32 |
|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] |
33 |
-|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] |
|
33 |
+|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] |
|
34 | 34 |
|
35 | 35 |
( variables ) |
36 | 36 |
|
... | ... |
@@ -137,7 +137,7 @@ |
137 | 137 |
( load sample ) |
138 | 138 |
OVR TOS #0019 ** ;pad-path ++ .File/name DEO2 |
139 | 139 |
OVR #04 / #40 SFT .Audio0/length + DEI2 .File/length DEO2 |
140 |
- OVR TOS 2** ;pad-addr ++ LDA2 .File/load DEO2 |
|
140 |
+ OVR TOS 2** ;pad-addr ++ LDA2 .File/read DEO2 |
|
141 | 141 |
( draw pad ) |
142 | 142 |
OVR #01 ;draw-pad JSR2 |
143 | 143 |
( draw mixer ) |
... | ... |
@@ -12,7 +12,7 @@ |
12 | 12 |
|
13 | 13 |
|00 @System &vector $2 &pad $6 &r $2 &g $2 &b $2 |
14 | 14 |
|20 @Screen &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 |
15 |
-|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 |
|
15 |
+|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 |
|
16 | 16 |
|
17 | 17 |
( variables ) |
18 | 18 |
|
... | ... |
@@ -30,21 +30,21 @@ |
30 | 30 |
( load font ) |
31 | 31 |
#4900 .File/length DEO2 |
32 | 32 |
;font-path-large .File/name DEO2 |
33 |
- ;font-data .File/load DEO2 |
|
33 |
+ ;font-data .File/read DEO2 |
|
34 | 34 |
( draw label ) |
35 | 35 |
#0020 #0020 ;title #01 ;draw-uf3 JSR2 |
36 | 36 |
|
37 | 37 |
( load font ) |
38 | 38 |
#2100 .File/length DEO2 |
39 | 39 |
;font-path-medium .File/name DEO2 |
40 |
- ;font-data .File/load DEO2 |
|
40 |
+ ;font-data .File/read DEO2 |
|
41 | 41 |
( draw label ) |
42 | 42 |
#0020 #0048 ;body #02 ;draw-uf2 JSR2 |
43 | 43 |
|
44 | 44 |
( load font ) |
45 | 45 |
#0900 .File/length DEO2 |
46 | 46 |
;font-path-small .File/name DEO2 |
47 |
- ;font-data .File/load DEO2 |
|
47 |
+ ;font-data .File/read DEO2 |
|
48 | 48 |
( draw label ) |
49 | 49 |
#0030 #00b8 ;footer #03 ;draw-uf1 JSR2 |
50 | 50 |
|
... | ... |
@@ -27,7 +27,7 @@ |
27 | 27 |
|70 @Midi [ &vector $2 &channel $1 ¬e $1 &velocity $1 ] |
28 | 28 |
|80 @Controller [ &vector $2 &button $1 &key $1 ] |
29 | 29 |
|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] |
30 |
-|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] |
|
30 |
+|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] |
|
31 | 31 |
|
32 | 32 |
( variables ) |
33 | 33 |
|
... | ... |
@@ -4,7 +4,7 @@ |
4 | 4 |
|
5 | 5 |
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] |
6 | 6 |
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] |
7 |
-|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] |
|
7 |
+|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] |
|
8 | 8 |
|
9 | 9 |
( variables ) |
10 | 10 |
|
... | ... |
@@ -20,7 +20,7 @@ |
20 | 20 |
( load contents from file ) |
21 | 21 |
#1000 .File/length DEO2 |
22 | 22 |
;filename .File/name DEO2 |
23 |
- ;contents .File/load DEO2 |
|
23 |
+ ;contents .File/read DEO2 |
|
24 | 24 |
|
25 | 25 |
.File/success DEI2 ORA ,&success JCN |
26 | 26 |
( failed to read: bright yellow background ) |
... | ... |
@@ -3,7 +3,7 @@ |
3 | 3 |
( devices ) |
4 | 4 |
|
5 | 5 |
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] |
6 |
-|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] |
|
6 |
+|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] |
|
7 | 7 |
|
8 | 8 |
( variables ) |
9 | 9 |
|
... | ... |
@@ -19,7 +19,7 @@ |
19 | 19 |
( save contents to file ) |
20 | 20 |
;contents/end ;contents SUB2 .File/length DEO2 |
21 | 21 |
;filename .File/name DEO2 |
22 |
- ;contents .File/save DEO2 |
|
22 |
+ ;contents .File/write DEO2 |
|
23 | 23 |
|
24 | 24 |
.File/success DEI2 ORA ,&success JCN |
25 | 25 |
( failed to write: bright yellow background ) |
... | ... |
@@ -8,7 +8,7 @@ |
8 | 8 |
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] |
9 | 9 |
|10 @Console [ &pad $8 &write $1 ] |
10 | 10 |
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] |
11 |
-|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] |
|
11 |
+|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] |
|
12 | 12 |
|
13 | 13 |
( variables ) |
14 | 14 |
|
... | ... |
@@ -26,7 +26,7 @@ |
26 | 26 |
( load file ) |
27 | 27 |
#1000 .File/length DEO2 |
28 | 28 |
;srcpath .File/name DEO2 |
29 |
- MEMORY .File/load DEO2 |
|
29 |
+ MEMORY .File/read DEO2 |
|
30 | 30 |
|
31 | 31 |
.File/success DEI2 ORA ;on-success JCN2 |
32 | 32 |
|
... | ... |
@@ -58,7 +58,7 @@ BRK |
58 | 58 |
( save file ) |
59 | 59 |
#1000 .File/length DEO2 |
60 | 60 |
;dstpath .File/name DEO2 |
61 |
- MEMORY .File/save DEO2 |
|
61 |
+ MEMORY .File/write DEO2 |
|
62 | 62 |
|
63 | 63 |
BRK |
64 | 64 |
|
... | ... |
@@ -1,13 +1,13 @@ |
1 | 1 |
( GUI Picture ) |
2 | 2 |
|
3 | 3 |
%RTN { JMP2r } |
4 |
-%LOAD-IMAGE { .File/length DEO2 .File/name DEO2 ;image .File/load DEO2 } |
|
4 |
+%LOAD-IMAGE { .File/length DEO2 .File/name DEO2 ;image .File/read DEO2 } |
|
5 | 5 |
|
6 | 6 |
( devices ) |
7 | 7 |
|
8 | 8 |
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] |
9 | 9 |
|20 @Screen [ &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] |
10 |
-|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] |
|
10 |
+|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] |
|
11 | 11 |
|
12 | 12 |
( variables ) |
13 | 13 |
|
... | ... |
@@ -509,7 +509,7 @@ include projects/library/binary-tree.tal |
509 | 509 |
@asma-flush-to-file ( len* -- ) |
510 | 510 |
.File/length DEO2 |
511 | 511 |
;asma/dest-filename LDA2 .File/name DEO2 |
512 |
- ;asma-write-buffer .File/save DEO2 |
|
512 |
+ ;asma-write-buffer .File/write DEO2 |
|
513 | 513 |
JMP2r |
514 | 514 |
|
515 | 515 |
@asma-flush-to-console ( len* -- ) |
... | ... |
@@ -5,7 +5,7 @@ |
5 | 5 |
*** CAUTION: this library is deprecated! *** |
6 | 6 |
|
7 | 7 |
Chunked file reads are now possible in the File device directly: just use |
8 |
-File/load or File/save multiple times. This library exists for compatibility to |
|
8 |
+File/read or File/write multiple times. This library exists for compatibility to |
|
9 | 9 |
keep asma going until it gets a more substantial rewrite. |
10 | 10 |
|
11 | 11 |
*** |
... | ... |
@@ -32,7 +32,7 @@ don't know the file size. Copes with files up to 4,294,967,295 bytes long. |
32 | 32 |
,ffwd JSR |
33 | 33 |
SWP2 ( F* B* U* / FN* SZ* OH* OL* ) |
34 | 34 |
ROT2k NIP2 ( F* B* U* B* F* / FN* SZ* OH* OL* ) |
35 |
- OVR2 .File/load DEO2 ( F* B* U* B* F* / FN* SZ* OH* OL* ) |
|
35 |
+ OVR2 .File/read DEO2 ( F* B* U* B* F* / FN* SZ* OH* OL* ) |
|
36 | 36 |
.File/success DEI2 SWP2 ( F* B* U* B* length* F* / FN* SZ* OH* OL* ) |
37 | 37 |
JSR2 ( F* B* U'* done-up-to* / FN* SZ* OH* OL* ) |
38 | 38 |
ROT2 SWP2 ( F* U'* B* done-up-to* / FN* SZ* OH* OL* ) |
... | ... |
@@ -57,13 +57,13 @@ don't know the file size. Copes with files up to 4,294,967,295 bytes long. |
57 | 57 |
&coarse ( length* offset* ) |
58 | 58 |
GTH2k ,&fine JCN |
59 | 59 |
OVR2 .File/length DEO2 |
60 |
- ,&addr LDR2 .File/load DEO2 |
|
60 |
+ ,&addr LDR2 .File/read DEO2 |
|
61 | 61 |
OVR2 SUB2 |
62 | 62 |
,&coarse JMP |
63 | 63 |
|
64 | 64 |
&fine ( length* offset* ) |
65 | 65 |
.File/length DEO2 ( length* ) |
66 |
- ,&addr LDR2 .File/load DEO2 |
|
66 |
+ ,&addr LDR2 .File/read DEO2 |
|
67 | 67 |
.File/length DEO2 ( ) |
68 | 68 |
JMP2r |
69 | 69 |
|
... | ... |
@@ -14,7 +14,7 @@ |
14 | 14 |
|
15 | 15 |
( return if file can't be found, or zero length ) |
16 | 16 |
#0001 .File/length DEO2 |
17 |
- ;&tmp .File/load DEO2 |
|
17 |
+ ;&tmp .File/read DEO2 |
|
18 | 18 |
.File/success DEI2 ORA JMP JMP2r |
19 | 19 |
|
20 | 20 |
( clear wst ) |
... | ... |
@@ -81,7 +81,7 @@ |
81 | 81 |
OVR2 #f401 ( arguments for STZ2 at fd, plus an extra 01 ) |
82 | 82 |
STHkr ( first argument for ADD2 ) |
83 | 83 |
.File/success ( argument for DEI2 ) |
84 |
- #0100 .File/load ( arguments for DEO2 ) |
|
84 |
+ #0100 .File/read ( arguments for DEO2 ) |
|
85 | 85 |
#ff00 .File/length DEO2 |
86 | 86 |
#00f0 JMP2 |
87 | 87 |
|
... | ... |
@@ -2,7 +2,7 @@ |
2 | 2 |
|
3 | 3 |
|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ] |
4 | 4 |
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ] |
5 |
-|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] |
|
5 |
+|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] |
|
6 | 6 |
|
7 | 7 |
( vectors ) |
8 | 8 |
|
... | ... |
@@ -35,7 +35,7 @@ |
35 | 35 |
|30 @Audio0 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] |
36 | 36 |
|80 @Controller [ &vector $2 &button $1 &key $1 ] |
37 | 37 |
|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] |
38 |
-|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] |
|
38 |
+|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] |
|
39 | 39 |
|
40 | 40 |
( variables ) |
41 | 41 |
|
... | ... |
@@ -581,7 +581,7 @@ RTN |
581 | 581 |
|
582 | 582 |
;theme-txt .File/name DEO2 |
583 | 583 |
#0006 .File/length DEO2 |
584 |
- #fffa .File/load DEO2 |
|
584 |
+ #fffa .File/read DEO2 |
|
585 | 585 |
|
586 | 586 |
.File/success DEI2 #0006 !! ,&ignore JCN |
587 | 587 |
#fffa LDA2 .System/r DEO2 |
... | ... |
@@ -28,7 +28,7 @@ |
28 | 28 |
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 |
29 | 29 |
|80 @Controller &vector $2 &button $1 &key $1 ] |
30 | 30 |
|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] |
31 |
-|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 |
|
31 |
+|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 |
|
32 | 32 |
|b0 @DateTime &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ] |
33 | 33 |
|
34 | 34 |
( variables ) |
... | ... |
@@ -238,7 +238,7 @@ RTN |
238 | 238 |
|
239 | 239 |
;theme-txt .File/name DEO2 |
240 | 240 |
#0006 .File/length DEO2 |
241 |
- #fffa .File/load DEO2 |
|
241 |
+ #fffa .File/read DEO2 |
|
242 | 242 |
|
243 | 243 |
.File/success DEI2 #0006 !! ,&ignore JCN |
244 | 244 |
#fffa LDA2 .System/r DEO2 |
... | ... |
@@ -63,31 +63,29 @@ get_entry(char *p, Uint16 len, const char *pathname, const char *basename, int f |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
static Uint16 |
66 |
-file_read_dir(void *dest, Uint16 len) |
|
66 |
+file_read_dir(char *dest, Uint16 len) |
|
67 | 67 |
{ |
68 |
- static char pathname[PATH_MAX]; |
|
68 |
+ static char pathname[4096]; |
|
69 | 69 |
char *p = dest; |
70 | 70 |
if(de == NULL) de = readdir(d); |
71 | 71 |
for(; de != NULL; de = readdir(d)) { |
72 | 72 |
Uint16 n; |
73 | 73 |
if(de->d_name[0] == '.' && de->d_name[1] == '\0') |
74 | 74 |
continue; |
75 |
- strncpy(pathname, current_filename, sizeof(pathname) - 1); |
|
76 |
- strncat(pathname, "/", sizeof(pathname) - 1); |
|
77 |
- strncat(pathname, de->d_name, sizeof(pathname) - 1); |
|
75 |
+ snprintf(pathname, sizeof(pathname), "%s/%s", current_filename, de->d_name); |
|
78 | 76 |
n = get_entry(p, len, pathname, de->d_name, 1); |
79 | 77 |
if(!n) break; |
80 | 78 |
p += n; |
81 | 79 |
len -= n; |
82 | 80 |
} |
83 |
- return p - (char *)dest; |
|
81 |
+ return p - dest; |
|
84 | 82 |
} |
85 | 83 |
|
86 | 84 |
Uint16 |
87 | 85 |
file_init(void *filename) |
88 | 86 |
{ |
89 | 87 |
reset(); |
90 |
- current_filename = (char *)filename; |
|
88 |
+ current_filename = filename; |
|
91 | 89 |
return 0; |
92 | 90 |
} |
93 | 91 |
|
... | ... |
@@ -111,17 +109,17 @@ file_read(void *dest, Uint16 len) |
111 | 109 |
Uint16 |
112 | 110 |
file_write(void *src, Uint16 len, Uint8 flags) |
113 | 111 |
{ |
112 |
+ Uint16 ret = 0; |
|
114 | 113 |
if(state != FILE_WRITE) { |
115 | 114 |
reset(); |
116 | 115 |
if((f = fopen(current_filename, (flags & 0x01) ? "ab" : "wb")) != NULL) |
117 | 116 |
state = FILE_WRITE; |
118 | 117 |
} |
119 | 118 |
if(state == FILE_WRITE) { |
120 |
- Uint16 ret = fwrite(src, 1, len, f); |
|
121 |
- fflush(f); |
|
122 |
- return ret; |
|
119 |
+ if((ret = fwrite(src, 1, len, f)) > 0 && fflush(f) != 0) |
|
120 |
+ ret = 0; |
|
123 | 121 |
} |
124 |
- return 0; |
|
122 |
+ return ret; |
|
125 | 123 |
} |
126 | 124 |
|
127 | 125 |
Uint16 |