Browse code

Moved file APIs in device/file

neauoire authored on 27/12/2021 04:26:27
Showing 4 changed files
... ...
@@ -24,11 +24,12 @@ WITH REGARD TO THIS SOFTWARE.
24 24
 static FILE *f;
25 25
 static DIR *d;
26 26
 static char *current_filename = "";
27
+static struct dirent *de;
28
+
27 29
 static enum { IDLE,
28 30
 	FILE_READ,
29 31
 	FILE_WRITE,
30 32
 	DIR_READ } state;
31
-static struct dirent *de;
32 33
 
33 34
 static void
34 35
 reset(void)
... ...
@@ -80,7 +81,7 @@ file_read_dir(char *dest, Uint16 len)
80 81
 	return p - dest;
81 82
 }
82 83
 
83
-Uint16
84
+static Uint16
84 85
 file_init(void *filename)
85 86
 {
86 87
 	reset();
... ...
@@ -88,7 +89,7 @@ file_init(void *filename)
88 89
 	return 0;
89 90
 }
90 91
 
91
-Uint16
92
+static Uint16
92 93
 file_read(void *dest, Uint16 len)
93 94
 {
94 95
 	if(state != FILE_READ && state != DIR_READ) {
... ...
@@ -105,7 +106,7 @@ file_read(void *dest, Uint16 len)
105 106
 	return 0;
106 107
 }
107 108
 
108
-Uint16
109
+static Uint16
109 110
 file_write(void *src, Uint16 len, Uint8 flags)
110 111
 {
111 112
 	Uint16 ret = 0;
... ...
@@ -121,7 +122,7 @@ file_write(void *src, Uint16 len, Uint8 flags)
121 122
 	return ret;
122 123
 }
123 124
 
124
-Uint16
125
+static Uint16
125 126
 file_stat(void *dest, Uint16 len)
126 127
 {
127 128
 	char *basename = strrchr(current_filename, '/');
... ...
@@ -132,8 +133,23 @@ file_stat(void *dest, Uint16 len)
132 133
 	return get_entry(dest, len, current_filename, basename, 0);
133 134
 }
134 135
 
135
-Uint16
136
+static Uint16
136 137
 file_delete(void)
137 138
 {
138 139
 	return unlink(current_filename);
139 140
 }
141
+
142
+/* API */
143
+
144
+void
145
+file_deo(Device *d, Uint8 port)
146
+{
147
+	switch(port) {
148
+	case 0x1: d->vector = peek16(d->dat, 0x0); break;
149
+	case 0x9: poke16(d->dat, 0x2, file_init(&d->mem[peek16(d->dat, 0x8)])); break;
150
+	case 0xd: poke16(d->dat, 0x2, file_read(&d->mem[peek16(d->dat, 0xc)], peek16(d->dat, 0xa))); break;
151
+	case 0xf: poke16(d->dat, 0x2, file_write(&d->mem[peek16(d->dat, 0xe)], peek16(d->dat, 0xa), d->dat[0x7])); break;
152
+	case 0x5: poke16(d->dat, 0x2, file_stat(&d->mem[peek16(d->dat, 0x4)], peek16(d->dat, 0xa))); break;
153
+	case 0x6: poke16(d->dat, 0x2, file_delete()); break;
154
+	}
155
+}
140 156
\ No newline at end of file
... ...
@@ -10,8 +10,4 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 10
 WITH REGARD TO THIS SOFTWARE.
11 11
 */
12 12
 
13
-Uint16 file_init(void *filename);
14
-Uint16 file_read(void *dest, Uint16 len);
15
-Uint16 file_write(void *src, Uint16 len, Uint8 flags);
16
-Uint16 file_stat(void *dest, Uint16 len);
17
-Uint16 file_delete(void);
13
+void file_deo(Device *d, Uint8 port);
18 14
\ No newline at end of file
... ...
@@ -76,19 +76,6 @@ console_deo(Device *d, Uint8 port)
76 76
 		write(port - 0x7, (char *)&d->dat[port], 1);
77 77
 }
78 78
 
79
-static void
80
-file_deo(Device *d, Uint8 port)
81
-{
82
-	switch(port) {
83
-	case 0x1: d->vector = peek16(d->dat, 0x0); break;
84
-	case 0x9: poke16(d->dat, 0x2, file_init(&d->mem[peek16(d->dat, 0x8)])); break;
85
-	case 0xd: poke16(d->dat, 0x2, file_read(&d->mem[peek16(d->dat, 0xc)], peek16(d->dat, 0xa))); break;
86
-	case 0xf: poke16(d->dat, 0x2, file_write(&d->mem[peek16(d->dat, 0xe)], peek16(d->dat, 0xa), d->dat[0x7])); break;
87
-	case 0x5: poke16(d->dat, 0x2, file_stat(&d->mem[peek16(d->dat, 0x4)], peek16(d->dat, 0xa))); break;
88
-	case 0x6: poke16(d->dat, 0x2, file_delete()); break;
89
-	}
90
-}
91
-
92 79
 static Uint8
93 80
 datetime_dei(Device *d, Uint8 port)
94 81
 {
... ...
@@ -291,27 +291,14 @@ screen_deo(Device *d, Uint8 port)
291 291
 		Uint8 *addr = &d->mem[peek16(d->dat, 0xc)];
292 292
 		Uint8 twobpp = !!(d->dat[0xf] & 0x80);
293 293
 		ppu_blit(&ppu, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] & 0x10, d->dat[0xf] & 0x20, twobpp);
294
-		if(d->dat[0x6] & 0x04) poke16(d->dat, 0xc, peek16(d->dat, 0xc) + 8 + twobpp*8); /* auto addr+8 / auto addr+16 */
295
-		if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 8); /* auto x+8 */
296
-		if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 8); /* auto y+8 */
294
+		if(d->dat[0x6] & 0x04) poke16(d->dat, 0xc, peek16(d->dat, 0xc) + 8 + twobpp * 8); /* auto addr+8 / auto addr+16 */
295
+		if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 8);                                /* auto x+8 */
296
+		if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 8);                                /* auto y+8 */
297 297
 		break;
298 298
 	}
299 299
 	}
300 300
 }
301 301
 
302
-static void
303
-file_deo(Device *d, Uint8 port)
304
-{
305
-	switch(port) {
306
-	case 0x1: d->vector = peek16(d->dat, 0x0); break;
307
-	case 0x9: poke16(d->dat, 0x2, file_init(&d->mem[peek16(d->dat, 0x8)])); break;
308
-	case 0xd: poke16(d->dat, 0x2, file_read(&d->mem[peek16(d->dat, 0xc)], peek16(d->dat, 0xa))); break;
309
-	case 0xf: poke16(d->dat, 0x2, file_write(&d->mem[peek16(d->dat, 0xe)], peek16(d->dat, 0xa), d->dat[0x7])); break;
310
-	case 0x5: poke16(d->dat, 0x2, file_stat(&d->mem[peek16(d->dat, 0x4)], peek16(d->dat, 0xa))); break;
311
-	case 0x6: poke16(d->dat, 0x2, file_delete()); break;
312
-	}
313
-}
314
-
315 302
 static Uint8
316 303
 audio_dei(Device *d, Uint8 port)
317 304
 {