Browse code

Made simple load/save examples composable

Andrew Alderwick authored on 21/05/2021 13:34:22
Showing 2 changed files
... ...
@@ -12,8 +12,11 @@
12 12
 
13 13
 ( program )
14 14
 
15
-|0100 @reset ( -> )
16
-	
15
+|0100 ( -> )
16
+	;try-load JSR2
17
+	BRK
18
+
19
+@try-load ( -- )
17 20
 	( load contents from file )
18 21
 	#1000 .File/length DEO2
19 22
 	;filename .File/name DEO2
... ...
@@ -24,7 +27,7 @@
24 27
 	#f0f7 .System/r DEO2
25 28
 	#f0f7 .System/g DEO2
26 29
 	#00f7 .System/b DEO2
27
-	BRK
30
+	JMP2r
28 31
 
29 32
 	&success
30 33
 	( read successful: dark blue background, show contents )
... ...
@@ -32,7 +35,7 @@
32 35
 	#00f7 .System/g DEO2
33 36
 	#40f7 .System/b DEO2
34 37
 	;contents DUP2 .File/success DEI2 ADD2 SWP2 ;draw JSR2
35
-	BRK
38
+	JMP2r
36 39
 
37 40
 @draw ( end-ptr* ptr* -- )
38 41
 	EQU2k ,&end JCN
... ...
@@ -3,6 +3,7 @@
3 3
 ( devices )
4 4
 
5 5
 |00 @System     [ &vector $2 &pad    $6 &r      $2 &g     $2 &b      $2 ]
6
+|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ]
6 7
 |a0 @File       [ &vector $2 &success $2 &offset $2 &pad $2 &name $2 &length $2 &load $2 &save $2 ]
7 8
 
8 9
 ( variables )
... ...
@@ -11,8 +12,11 @@
11 12
 
12 13
 ( init )
13 14
 
14
-|0100 @reset ( -> )
15
+|0100 ( -> )
16
+	;try-save JSR2
17
+	BRK
15 18
 
19
+@try-save ( -- )
16 20
 	( save contents to file )
17 21
 	;contents/end ;contents SUB2 .File/length DEO2
18 22
 	;filename .File/name DEO2
... ...
@@ -23,16 +27,16 @@
23 27
 	#f0f7 .System/r DEO2
24 28
 	#f0f7 .System/g DEO2
25 29
 	#00f7 .System/b DEO2
26
-	BRK
30
+	JMP2r
27 31
 
28 32
 	&success
29 33
 	( write successful: dark blue background )
30 34
 	#00f7 .System/r DEO2
31 35
 	#00f7 .System/g DEO2
32 36
 	#40f7 .System/b DEO2
33
-	BRK
37
+	JMP2r
34 38
 
35 39
 @filename "hello.txt 00
36
-@contents "Hello 20 "world, 20 "how 20 "are 20 "you? 0a
40
+@contents "Hello 20 "world, 0a "how 20 "are 20 "you? 0a
37 41
 	&end
38 42