Browse code

Improved shapes example

neauoire authored on 30/08/2021 21:53:01
Showing 2 changed files
... ...
@@ -16,4 +16,4 @@
16 16
 
17 17
 BRK
18 18
 
19
-@hello-word "Hello 20 "World!
20 19
\ No newline at end of file
20
+@hello-word "Hello 20 "Uxn!
21 21
\ No newline at end of file
... ...
@@ -1,10 +1,11 @@
1 1
 ( GUI Shapes )
2 2
 
3 3
 %RTN { JMP2r }
4
-%--  { #0001 SUB2 }
5 4
 %8++  { #0008 ADD2 }
6 5
 %2** { #10 SFT2 }
7 6
 %4** { #20 SFT2 }
7
+%2// { #01 SFT2 }
8
+%4// { #02 SFT2 }
8 9
 %ABS2 { DUP2 #0f SFT2 EQU #05 JCN #0000 SWP2 SUB2 }
9 10
 %LTS2  { #8000 ADD2 SWP2 #8000 ADD2 GTH2 }
10 11
 %GTS2  { #8000 ADD2 SWP2 #8000 ADD2 LTH2 }
... ...
@@ -13,6 +14,8 @@
13 14
 	STH2 STH2 OVR2 STH2r ADD2 OVR2 STH2r ADD2
14 15
 } ( x y w h -- x1 y1 x2 y2 )
15 16
 
17
+%WIDTH { #0100 } %HEIGHT { #00a0 }
18
+
16 19
 ( devices )
17 20
 
18 21
 |00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
... ...
@@ -34,24 +37,37 @@
34 37
 |0100
35 38
 	
36 39
 	( theme ) 
37
-	#f03f .System/r DEO2 
40
+	#f0ff .System/r DEO2 
38 41
 	#f03c .System/g DEO2 
39 42
 	#f03f .System/b DEO2
40 43
 
41 44
 	( background ) ;checker_icn #03 ;cover-pattern JSR2
42 45
 
43
-	#0010 #0030 #0020 #0020 SIZE-TO-RECT #01 ;line-slow JSR2
44
-	#0070 #0040 #0010 #01 ;draw-circle JSR2
45
-	#0038 #0030 #0020 #0020 SIZE-TO-RECT #01 ;line-rect JSR2
46
-	#0038 #0058 #0020 #0020 SIZE-TO-RECT #01 ;fill-rect JSR2
47
-	#0010 #0030 #0068 #01 ;line-hor JSR2
48
-	#0020 #0058 #0078 #01 ;line-ver JSR2
46
+	.Screen/width DEI2 2// WIDTH 2// SUB2 #0008 ADD2
47
+	.Screen/height DEI2 2// HEIGHT 2// SUB2 #0008 ADD2
48
+	WIDTH HEIGHT
49
+	SIZE-TO-RECT #02 ;fill-rect JSR2
50
+
51
+	.Screen/width DEI2 2// WIDTH 2// SUB2
52
+	.Screen/height DEI2 2// HEIGHT 2// SUB2
53
+	WIDTH HEIGHT
54
+	SIZE-TO-RECT #01 ;fill-rect JSR2
55
+
56
+	.Screen/width DEI2 2// WIDTH 2// SUB2  #0008 ADD2
57
+	.Screen/height DEI2 2// HEIGHT 2// SUB2  #0008 ADD2
58
+	WIDTH #0010 SUB2 HEIGHT #0010 SUB2
59
+	SIZE-TO-RECT #03 ;line-rect JSR2
60
+
61
+	.Screen/width DEI2 2// .Screen/height DEI2 2// WIDTH 4// #02 ;draw-circle JSR2
62
+
63
+	#0010 #0030 #0068 #02 ;line-hor JSR2
64
+	#0020 #0058 #0078 #02 ;line-ver JSR2
49 65
 	
50 66
 BRK
51 67
 
52 68
 @line-slow ( x1 y1 x2 y2 color -- )
53 69
 	
54
-	( load ) .color STZ -- .line/y0 STZ2 -- .line/x0 STZ2 .line/y STZ2 .line/x STZ2
70
+	( load ) .color STZ #0001 SUB2 .line/y0 STZ2 #0001 SUB2 .line/x0 STZ2 .line/y STZ2 .line/x STZ2
55 71
 	.line/x0 LDZ2 .line/x LDZ2 SUB2 ABS2 .line/dx STZ2
56 72
 	.line/y0 LDZ2 .line/y LDZ2 SUB2 ABS2 #0000 SWP2 SUB2 .line/dy STZ2
57 73
 	#ffff #00 .line/x LDZ2 .line/x0 LDZ2 LTS2 2** ADD2 .line/sx STZ2
... ...
@@ -77,27 +93,28 @@ RTN
77 93
 
78 94
 @line-rect ( x1* y1* x2* y2* color -- )
79 95
 
80
-	( load ) .color STZ 
81
-	STH2k .rect/y2 STZ2 .rect/x2 STZ2 
82
-	STH2k .rect/y1 STZ2 .rect/x1 STZ2
96
+	( load ) STH
97
+	STH2k ,&y2 STR2 ,&x2 STR2 
98
+	STH2k ,&y1 STR2 ,&x1 STR2
83 99
 	STH2r STH2r SWP2
84 100
 	&ver
85 101
 		( save ) DUP2 .Screen/y DEO2
86
-		( draw ) .rect/x1 LDZ2 .Screen/x DEO2 .color LDZ DUP .Screen/pixel DEO
87
-		( draw ) .rect/x2 LDZ2 .Screen/x DEO2 .Screen/pixel DEO
102
+		( draw ) ,&x1 LDR2 .Screen/x DEO2 STHkr .Screen/pixel DEO
103
+		( draw ) ,&x2 LDR2 .Screen/x DEO2 STHkr .Screen/pixel DEO
88 104
 		( incr ) INC2
89 105
 		OVR2 OVR2 GTS2 ,&ver JCN
90 106
 	POP2 POP2
91
-	.rect/x1 LDZ2 .rect/x2 LDZ2 SWP2
107
+	,&x1 LDR2 ,&x2 LDR2 SWP2
92 108
 	&hor
93 109
 		( save ) DUP2 .Screen/x DEO2
94
-		( draw ) .rect/y1 LDZ2 .Screen/y DEO2 .color LDZ DUP .Screen/pixel DEO
95
-		( draw ) .rect/y2 LDZ2 .Screen/y DEO2 .Screen/pixel DEO
110
+		( draw ) ,&y1 LDR2 .Screen/y DEO2 STHkr .Screen/pixel DEO
111
+		( draw ) ,&y2 LDR2 .Screen/y DEO2 STHkr .Screen/pixel DEO
96 112
 		( incr ) INC2
97 113
 		OVR2 INC2 OVR2 GTS2 ,&hor JCN
98
-	POP2 POP2
114
+	POP2 POP2 POPr
99 115
 
100 116
 RTN
117
+	&x1 $2 &y1 $2 &x2 $2 &y2 $2 
101 118
 
102 119
 @fill-rect ( x1* y1* x2* y2* color -- )
103 120
 	
... ...
@@ -128,14 +145,14 @@ RTN
128 145
 	&loop
129 146
 		( incr ) .circle/x LDZ2 INC2 .circle/x STZ2
130 147
 		.circle/d LDZ2 #0001 LTS2 ,&else JCN
131
-			( decr ) .circle/y LDZ2 -- .circle/y STZ2
148
+			( decr ) .circle/y LDZ2 #0001 SUB2 .circle/y STZ2
132 149
 			.circle/x LDZ2 .circle/y LDZ2 SUB2 4** .circle/d LDZ2 ADD2 .circle/d STZ2
133 150
 			;&end JMP2
134 151
 		&else
135 152
 			.circle/x LDZ2 4** .circle/d LDZ2 ADD2 .circle/d STZ2
136 153
 		&end
137 154
 		( draw ) ;&seg JSR2
138
-		.circle/y LDZ2 .circle/x LDZ2 -- GTS2 ,&loop JCN
155
+		.circle/y LDZ2 .circle/x LDZ2 #0001 SUB2 GTS2 ,&loop JCN
139 156
 	RTN
140 157
 	&seg
141 158
 		.circle/xc LDZ2 .circle/x LDZ2 ADD2 .Screen/x DEO2 .circle/yc LDZ2 .circle/y LDZ2 ADD2 .Screen/y DEO2 .color LDZ .Screen/pixel DEO