Browse code

Implemented file vectors in nasu/noodle

neauoire authored on 13/04/2021 19:29:36
Showing 7 changed files
... ...
@@ -32,7 +32,7 @@ else
32 32
 fi
33 33
 
34 34
 echo "Assembling.."
35
-./bin/assembler projects/examples/dev.file.usm bin/boot.rom
35
+./bin/assembler projects/software/noodle.usm bin/boot.rom
36 36
 
37 37
 echo "Running.."
38 38
 if [ "${2}" = '--cli' ]; 
... ...
@@ -8,7 +8,7 @@
8 8
 |0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
9 9
 |0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 }
10 10
 |0160 ;Mouse  { vector 2 x 2 y 2 state 1 chord 1 }
11
-|0170 ;File { pad 8 name 2 length 2 load 2 save 2 }
11
+|0170 ;File { vector 2 pad 6 name 2 length 2 load 2 save 2 }
12 12
 
13 13
 ( program )
14 14
 
... ...
@@ -16,22 +16,29 @@
16 16
 
17 17
 	( theme ) #ac52 =System.r #a362 =System.g #b253 =System.b
18 18
 	( vectors ) ,on-mouse =Mouse.vector
19
+	( vectors ) ,on-transfer =File.vector
19 20
 
20 21
 	( load )
21 22
 	
22 23
 	#0000 #0000 #0100 #0100 #2c ,pict_large ,draw-picture JSR2
23 24
 
24
-	( load ) ,filepath =File.name #4000 =File.length ,img =File.load
25
-	( draw ) #0080 #0020 #0100 #0100 #41 ,img ,draw-chr JSR2
26 25
 
27 26
 	#0128 #0010 #0080 #0080 #2e ,pict_medium ,draw-picture JSR2
28 27
 	#0020 #00d0 #0020 #0020 #25 ,pict_small ,draw-picture JSR2
29 28
 
30 29
 	#0010 #0010 #0020 #0010 #25 ,dvd_icn ,draw-picture JSR2
31 30
 
31
+	( load ) ,filepath =File.name #4000 =File.length ,img =File.load
32
+
33
+BRK
34
+
35
+@on-transfer ( -> )
36
+
37
+	( draw ) #0080 #0020 #0100 #0100 #41 ,img ,draw-chr JSR2
38
+
32 39
 BRK
33 40
 
34
-@on-mouse 
41
+@on-mouse ( -> )
35 42
 
36 43
 	( clear last cursor )
37 44
 	,clear_icn =Screen.addr 
... ...
@@ -45,6 +45,7 @@
45 45
 	( theme ) #e0fc =System.r #30cc =System.g #30ac =System.b
46 46
 	( vectors ) ,on-button =Controller.vector
47 47
 	( vectors ) ,on-mouse =Mouse.vector
48
+	( vectors ) ,on-transfer =File.vector
48 49
 
49 50
 	~Screen.width 2/ #008a SUB2 =bankview.x 
50 51
 	~Screen.height 2/ #003f SUB2 =bankview.y 
... ...
@@ -61,7 +62,13 @@
61 62
 
62 63
 BRK
63 64
 
64
-@on-button
65
+@on-transfer ( -> )
66
+	
67
+	,redraw JSR2
68
+	
69
+BRK
70
+
71
+@on-button ( -> )
65 72
 	
66 73
 	~Controller.button
67 74
 	DUP #10 EQU ^$no-ctrl-up JNZ
... ...
@@ -83,7 +90,7 @@ BRK
83 90
 
84 91
 BRK
85 92
 
86
-@on-mouse
93
+@on-mouse ( -> )
87 94
 	
88 95
 	~Mouse.state #00 EQU ,$click-end JNZ2
89 96
 
... ...
@@ -68,6 +68,7 @@
68 68
 	( vectors ) ,on-screen =Screen.vector
69 69
 	( vectors ) ,on-button =Controller.vector
70 70
 	( vectors ) ,on-mouse =Mouse.vector
71
+	( vectors ) ,on-transfer =File.vector
71 72
 
72 73
 	~theme.r0 =System.r ~theme.g0 =System.g ~theme.b0 =System.b
73 74
 
... ...
@@ -79,7 +80,6 @@
79 80
 
80 81
 	( load file )
81 82
 	,untitled_txt ,path.name ,strcpy JSR2
82
-	,path.name ,load-file JSR2
83 83
 
84 84
 	( setup panes )
85 85
 	#0010 =toolpane.x1 #0010 =toolpane.y1 ~toolpane.x1 #0028 ADD2 =toolpane.x2 ~toolpane.y1 #0008 ADD2 =toolpane.y2
... ...
@@ -91,9 +91,19 @@
91 91
 	,center JSR2
92 92
 	,clear JSR2
93 93
 
94
+	( load default file )
95
+	,path.name ,load-file JSR2
96
+
97
+BRK
98
+
99
+@on-transfer ( -> )
100
+	
101
+	,draw-canvas JSR2
102
+	( release ) #00 =Mouse.state
103
+
94 104
 BRK
95 105
 
96
-@on-screen ( -- )
106
+@on-screen ( -> )
97 107
 	
98 108
 	~document.edit #01 NEQ ^$no-edit JNZ
99 109
 		#0008 =Screen.x 
... ...
@@ -108,7 +118,7 @@ BRK
108 118
 
109 119
 BRK
110 120
 
111
-@on-mouse
121
+@on-mouse ( -> )
112 122
 	
113 123
 	,draw-cursor JSR2
114 124
 
... ...
@@ -218,15 +218,15 @@ file_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
218 218
 {
219 219
 	Uint8 *m = u->ram.dat;
220 220
 	char *name = (char *)&m[(m[ptr + 8] << 8) + m[ptr + 8 + 1]];
221
-	Uint16 length = (m[ptr + 8 + 2] << 8) + m[ptr + 8 + 3];
222
-	Uint16 offset = (m[ptr + 2] << 8) + m[ptr + 3];
221
+	Uint16 length = mempeek16(u, ptr + 8 + 2);
222
+	Uint16 offset = mempeek16(u, ptr + 2);
223 223
 	if(b0 == 0x0d) {
224 224
 		Uint16 addr = (m[ptr + 8 + 4] << 8) + b1;
225 225
 		FILE *f = fopen(name, "r");
226 226
 		if(f && fseek(f, offset, SEEK_SET) != -1 && fread(&m[addr], length, 1, f)) {
227 227
 			fclose(f);
228 228
 			printf("Loaded %d bytes, at %04x from %s\n", length, addr, name);
229
-			evaluxn(u, devfile->vector);
229
+			evaluxn(u, mempeek16(u, devfile->addr));
230 230
 		}
231 231
 	} else if(b0 == 0x0f) {
232 232
 		Uint16 addr = (m[ptr + 8 + 6] << 8) + b1;
... ...
@@ -234,7 +234,7 @@ file_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
234 234
 		if(f && fseek(f, offset, SEEK_SET) != -1 && fwrite(&m[addr], length, 1, f)) {
235 235
 			fclose(f);
236 236
 			printf("Saved %d bytes, at %04x from %s\n", length, addr, name);
237
-			evaluxn(u, devfile->vector);
237
+			evaluxn(u, mempeek16(u, devfile->addr));
238 238
 		}
239 239
 	}
240 240
 	return b1;
... ...
@@ -293,9 +293,8 @@ datetime_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
293 293
 Uint8
294 294
 system_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
295 295
 {
296
-	Uint8 *m = u->ram.dat;
297
-	m[PAGE_DEVICE + b0] = b1;
298
-	getcolors(&ppu, &m[PAGE_DEVICE + 0x0008]);
296
+	u->ram.dat[ptr + b0] = b1;
297
+	getcolors(&ppu, &u->ram.dat[ptr + 0x0008]);
299 298
 	reqdraw = 1;
300 299
 	(void)ptr;
301 300
 	return b1;
... ...
@@ -315,7 +314,7 @@ ppnil(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
315 314
 int
316 315
 start(Uxn *u)
317 316
 {
318
-	inituxn(u, 0x0200);
317
+	evaluxn(u, 0x0200);
319 318
 	redraw(ppu.output, u);
320 319
 	while(1) {
321 320
 		SDL_Event event;
... ...
@@ -333,14 +332,14 @@ start(Uxn *u)
333 332
 			case SDL_KEYDOWN:
334 333
 			case SDL_KEYUP:
335 334
 				doctrl(u, &event, event.type == SDL_KEYDOWN);
336
-				evaluxn(u, devctrl->vector);
335
+				evaluxn(u, mempeek16(u, devctrl->addr));
337 336
 				u->ram.dat[devctrl->addr + 3] = 0;
338 337
 				break;
339 338
 			case SDL_MOUSEBUTTONUP:
340 339
 			case SDL_MOUSEBUTTONDOWN:
341 340
 			case SDL_MOUSEMOTION:
342 341
 				domouse(u, &event);
343
-				evaluxn(u, devmouse->vector);
342
+				evaluxn(u, mempeek16(u, devmouse->addr));
344 343
 				break;
345 344
 			case SDL_WINDOWEVENT:
346 345
 				if(event.window.event == SDL_WINDOWEVENT_EXPOSED)
... ...
@@ -348,7 +347,7 @@ start(Uxn *u)
348 347
 				break;
349 348
 			}
350 349
 		}
351
-		evaluxn(u, devscreen->vector);
350
+		evaluxn(u, mempeek16(u, devscreen->addr));
352 351
 		SDL_UnlockAudioDevice(audio_id);
353 352
 		if(reqdraw)
354 353
 			redraw(ppu.output, u);
... ...
@@ -151,17 +151,6 @@ evaluxn(Uxn *u, Uint16 vec)
151 151
 	return 1;
152 152
 }
153 153
 
154
-int
155
-inituxn(Uxn *u, Uint16 vec)
156
-{
157
-	Uint8 i = 0;
158
-	if(!evaluxn(u, vec))
159
-		return 0;
160
-	for(i = 0; i < 0x10; ++i)
161
-		u->dev[i].vector = mempeek16(u, u->dev[i].addr);
162
-	return 1;
163
-}
164
-
165 154
 int
166 155
 bootuxn(Uxn *u)
167 156
 {
... ...
@@ -32,7 +32,7 @@ typedef struct {
32 32
 struct Uxn;
33 33
 
34 34
 typedef struct Device {
35
-	Uint16 addr, vector;
35
+	Uint16 addr;
36 36
 	Uint8 (*poke)(struct Uxn *, Uint16, Uint8, Uint8);
37 37
 } Device;
38 38
 
... ...
@@ -44,7 +44,6 @@ typedef struct Uxn {
44 44
 
45 45
 int loaduxn(Uxn *c, char *filepath);
46 46
 int bootuxn(Uxn *c);
47
-int inituxn(Uxn *u, Uint16 vec);
48 47
 int evaluxn(Uxn *u, Uint16 vec);
49 48
 void mempoke16(Uxn *u, Uint16 a, Uint16 b);
50 49
 Uint16 mempeek16(Uxn *u, Uint16 a);