Browse code

Implemented save/load to noodle

neauoire authored on 28/03/2021 23:43:32
Showing 2 changed files
... ...
@@ -10,7 +10,6 @@
10 10
 
11 11
 	TODO
12 12
 		- Pixel cleanup brush
13
-		- Rename filename
14 13
 )
15 14
 
16 15
 %RTN   { JMP2r }
... ...
@@ -23,14 +22,13 @@
23 22
 %++ { #0001 ADD2 } %-- { #0001 SUB2 }
24 23
 %2/ { #0001 SFT2 }
25 24
 %8/ { #0003 SFT2 } %8* { #0030 SFT2 }
26
-%8+ { #0008 ADD2 }
25
+%8+ { #0008 ADD2 } %8- { #0008 SUB2 }
27 26
 
28 27
 ( variables )
29 28
 
30 29
 ;cursor { x 2 y 2 x0 2 y0 2 dx 2 dy 2 }
31 30
 ;brush { tool 1 size 1 patt 1 drag 1 last 1 oper 2 }
32 31
 ;zoom { active 1 x 2 y 2 }
33
-;document { state 1 edit 1 }
34 32
 ( interface )
35 33
 ;toolpane { x1 2 y1 2 x2 2 y2 2 }
36 34
 ;pattpane { x1 2 y1 2 x2 2 y2 2 }
... ...
@@ -46,10 +44,12 @@
46 44
 ;pt1 { x 2 y 2 }
47 45
 ;pt2 { x 2 y 2 } ( paint-rect )
48 46
 ;px { x 1 y 1 }
47
+;document { state 1 edit 1 namelength 1 name 48 }
48
+;timer { byte 1 }
49 49
 
50 50
 ( devices )
51 51
 
52
-|0100 ;Console { pad 8 char 1 byte 1 short 2 }
52
+|0100 ;Console { pad 8 char 1 byte 1 short 2 string 2 }
53 53
 |0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
54 54
 |0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
55 55
 |0130 ;Controller { buttons 1 }
... ...
@@ -77,7 +77,7 @@
77 77
 	#00 =brush.tool
78 78
 
79 79
 	( load file )
80
-	,filepath ,load-file JSR2
80
+	,document.name ,load-file JSR2
81 81
 
82 82
 	( setup panes )
83 83
 	#0010 =toolpane.x1 #0010 =toolpane.y1
... ...
@@ -92,11 +92,14 @@
92 92
 
93 93
 	( center canvas )
94 94
 	,center JSR2
95
+	,clear JSR2
95 96
 
96 97
 BRK
97 98
 
98 99
 @FRAME 
99 100
 
101
+	~document.edit #01 EQU ,on-document-edit JNZ2
102
+
100 103
 	,draw-cursor JSR2
101 104
 
102 105
 	( release drag )
... ...
@@ -242,15 +245,16 @@ BRK
242 245
 			DUP2 #0000 NEQ2 ^$no-clear-button JNZ
243 246
 				,center JSR2
244 247
 				,clear JSR2
248
+				#01 =document.edit
245 249
 				( release ) #00 =Mouse.state
246 250
 			$no-clear-button
247 251
 			DUP2 #0001 NEQ2 ^$no-load-button JNZ
248
-				,filepath ,load-file JSR2
252
+				,document.name ,load-file JSR2
249 253
 				,draw-canvas JSR2
250 254
 				( release ) #00 =Mouse.state
251 255
 			$no-load-button
252 256
 			DUP2 #0002 NEQ2 ^$no-save-button JNZ
253
-				,filepath ,save-file JSR2
257
+				,document.name ,save-file JSR2
254 258
 				( release ) #00 =Mouse.state
255 259
 			$no-save-button
256 260
 			POP2
... ...
@@ -301,6 +305,44 @@ BRK
301 305
 
302 306
 BRK
303 307
 
308
+@on-document-edit
309
+
310
+	~Keys #00 EQU ,$no-keys JNZ2
311
+
312
+		~Keys #0d NEQ ,$no-enter JNZ2	
313
+			#00 =document.edit
314
+			,redraw JSR2
315
+			BRK
316
+		$no-enter
317
+
318
+		~Keys #08 NEQ ,$no-backspace JNZ2
319
+			( incr ) ~document.namelength #01 SUB =document.namelength
320
+			,$end JSR2
321
+			BRK
322
+		$no-backspace
323
+
324
+		( store key ) ~Keys ,document.name #00 ~document.namelength ADD2 POK2
325
+		( incr ) ~document.namelength #01 ADD =document.namelength
326
+		
327
+		$end
328
+		( store end ) #00 ,document.name #00 ~document.namelength ADD2 POK2
329
+		( release ) #00 =Keys.key
330
+		
331
+	$no-keys
332
+
333
+	( move ) #0008 =Sprite.x ~Screen.height #0010 SUB2 =Sprite.y
334
+	( draw ) ,document.name #01 ~timer #04 DIV #03 AND #03 MUL ADD ,draw-label JSR2
335
+
336
+	~Sprite.x 8- =Sprite.x
337
+	$clear
338
+		~Sprite.x 8+ =Sprite.x
339
+		#00 =Sprite.color
340
+		~Sprite.x ~Screen.width LTH2 ^$clear JNZ
341
+
342
+	~timer #01 ADD =timer
343
+
344
+BRK
345
+
304 346
 @center
305 347
 	
306 348
 	( clear ) ~canvas.x1 #0002 SUB2 ~canvas.y1 #0002 SUB2 ~canvas.x2 #0002 ADD2 ~canvas.y2 #0002 ADD2 #00 ,fill-rect JSR2
... ...
@@ -320,12 +362,15 @@ BRK
320 362
 RTN
321 363
 
322 364
 @clear
323
-		
324
-	,untitled_txt ,filepath 
365
+	
366
+	#00 =document.namelength
367
+
368
+	,untitled_txt ,document.name 
325 369
 	$rename
326 370
 		( copy src->dst ) OVR2 OVR2 SWP2 PEK2 ROT ROT POK2
327 371
 		( incr dst ) ++
328 372
 		( incr src ) SWP2 ++ SWP2
373
+		( incr len ) ~document.namelength #01 ADD =document.namelength
329 374
 		OVR2 PEK2 #00 NEQ ^$rename JNZ
330 375
 	#00 ROT ROT POK2 POP2
331 376
 
... ...
@@ -753,14 +798,14 @@ RTN
753 798
 	#0010 =Sprite.y
754 799
 	( draw width )
755 800
 	~Screen.width #00a0 SUB2 =Sprite.x ,font_hex ~canvas.w #f0 AND #04 SFT #08 MUL ADD2 =Sprite.addr
756
-	( draw ) #03 =Sprite.color
801
+	( draw ) #01 =Sprite.color
757 802
 	~Sprite.x 8+ =Sprite.x ,font_hex ~canvas.w #0f AND #08 MUL ADD2 =Sprite.addr
758
-	( draw ) #03 =Sprite.color
803
+	( draw ) #01 =Sprite.color
759 804
 	( draw height )
760 805
 	~Sprite.x 8+ =Sprite.x ,font_hex ~canvas.h #f0 AND #04 SFT #08 MUL ADD2 =Sprite.addr
761
-	( draw ) #03 =Sprite.color
806
+	( draw ) #01 =Sprite.color
762 807
 	~Sprite.x 8+ =Sprite.x ,font_hex ~canvas.h #0f AND #08 MUL ADD2 =Sprite.addr
763
-	( draw ) #03 =Sprite.color
808
+	( draw ) #01 =Sprite.color
764 809
 
765 810
 	( draw save/load/guides icons )
766 811
 	~Screen.height #0010 SUB2 =Sprite.y
... ...
@@ -777,10 +822,10 @@ RTN
777 822
 	,save_icn =Sprite.addr
778 823
 	#01 =Sprite.color
779 824
 
780
-	( draw filename )
825
+	( draw )
781 826
 
782 827
 	#0008 =Sprite.x
783
-	,filepath #01 ,draw-label JSR2
828
+	,document.name #01 ,draw-label JSR2
784 829
 
785 830
 RTN
786 831
 
... ...
@@ -939,6 +984,4 @@ RTN
939 984
 
940 985
 @ERROR BRK 
941 986
 
942
-|2000 @filepath       [ projects/pictures/tima2a1a.bit 00 ]
943
-
944 987
 |2100 @data
... ...
@@ -337,6 +337,7 @@ console_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
337 337
 	case 0x08: printf("%c", b1); break;
338 338
 	case 0x09: printf("0x%02x\n", b1); break;
339 339
 	case 0x0b: printf("0x%04x\n", (m[ptr + 0x0a] << 8) + b1); break;
340
+	case 0x0d: printf("%s\n", &m[(m[ptr + 0x0c] << 8) + b1]); break;
340 341
 	}
341 342
 	fflush(stdout);
342 343
 	(void)m;