Browse code

Optimized gui examples

neauoire authored on 18/08/2021 18:14:29
Showing 5 changed files
... ...
@@ -63,7 +63,6 @@ You can also use the emulator without graphics by using `uxncli`. You can find a
63 63
 
64 64
 ```
65 65
 cc src/uxn.c -DNDEBUG -Os -g0 -s src/uxncli.c -o bin/uxncli
66
-
67 66
 ```
68 67
 
69 68
 ### I/O
... ...
@@ -1,11 +1,7 @@
1 1
 ( GUI Hover )
2 2
 
3
-%+  { ADD }  %-  { SUB }
4
-%<  { LTH }  %>  { GTH }  %=  { EQU }  %!  { NEQ }
5
-%++ { ADD2 } %-- { SUB2 }
6
-%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }
7 3
 %RTN { JMP2r }
8
-%GTS2 { #8000 ++ SWP2 #8000 ++ << }
4
+%GTS2 { #8000 ADD2 SWP2 #8000 ADD2 LTH2 }
9 5
 
10 6
 ( devices )
11 7
 
... ...
@@ -28,7 +24,11 @@
28 24
 
29 25
 |0100
30 26
 
31
-	( theme ) #0f0f .System/r DEO2 #0fff .System/g DEO2 #0ff0 .System/b DEO2
27
+	( theme ) 
28
+	#0f0f .System/r DEO2 
29
+	#0fff .System/g DEO2 
30
+	#0ff0 .System/b DEO2
31
+
32 32
 	( vectors ) ;on-mouse .Mouse/vector DEO2
33 33
 	
34 34
 	#0020 #0030 #0060 #0060 .r1/y2 STZ2 .r1/x2 STZ2 .r1/y1 STZ2 .r1/x1 STZ2
... ...
@@ -62,27 +62,20 @@
62 62
 		&draw3 
63 63
 	.r3/x1 LDZ2 .r3/y1 LDZ2 .r3/x2 LDZ2 .r3/y2 LDZ2 .color LDZ ;line-rect JSR2
64 64
 
65
-	;draw-cursor JSR2
66
-
67
-BRK
68
-
69
-@draw-cursor ( -- )
70
-
71 65
 	( clear last cursor )
72 66
 	.pointer/x LDZ2 .Screen/x DEO2
73 67
 	.pointer/y LDZ2 .Screen/y DEO2
74 68
 	#40 .Screen/sprite DEO
75 69
 
76 70
 	( record pointer positions )
77
-	.Mouse/x DEI2 .pointer/x STZ2 .Mouse/y DEI2 .pointer/y STZ2
71
+	.Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2 
72
+	.Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2
73
+	.pointer/sprite LDZ2 .Screen/addr DEO2
78 74
 
79 75
 	( draw new cursor )
80
-	.pointer/sprite LDZ2 .Screen/addr DEO2
81
-	.pointer/x LDZ2 .Screen/x DEO2
82
-	.pointer/y LDZ2 .Screen/y DEO2
83 76
 	#41 .Screen/sprite DEO
84 77
 
85
-RTN
78
+BRK
86 79
 
87 80
 @within-rect ( x* y* rect -- flag )
88 81
 	
... ...
@@ -20,13 +20,10 @@
20 20
 
21 21
 |0100
22 22
 	
23
-	( theme ) #0f0f .System/r DEO2 #0fff .System/g DEO2 #0ff0 .System/b DEO2
24
-	
25
-	;draw JSR2
26
-	
27
-BRK
28
-
29
-@draw ( -- )
23
+	( theme ) 
24
+	#0f0f .System/r DEO2 
25
+	#0fff .System/g DEO2 
26
+	#0ff0 .System/b DEO2
30 27
 	
31 28
 	( find screen center )
32 29
 	.Screen/width DEI2 2// .center/x STZ2
... ...
@@ -1,7 +1,7 @@
1 1
 ( GUI Picture )
2 2
 
3 3
 %RTN { JMP2r }
4
-%8+ { #0008 ADD2 }
4
+%LOAD-IMAGE { .File/length DEO2 .File/name DEO2 ;image .File/load DEO2 }
5 5
 
6 6
 ( devices )
7 7
 
... ...
@@ -13,97 +13,93 @@
13 13
 
14 14
 |0000
15 15
 
16
-@color    [ &byte $1 ]
17
-@position [ &x $2 &y $2 ]
18
-@size     [ &width $2 &height $2 ]
16
+@position
17
+	&x $2 &y $2
18
+@size
19
+	&width $2 &height $2
19 20
 
20 21
 ( program )
21 22
 
22 23
 |0100
23 24
 
24
-	( theme ) #f07a .System/r DEO2 #f02a .System/g DEO2 #f02a .System/b DEO2
25
+	( theme ) 
26
+	#072f .System/r DEO2 
27
+	#072f .System/g DEO2 
28
+	#072f .System/b DEO2
25 29
 
26
-	( background ) ;checker_icn #02 ;cover-pattern JSR2
27
-
28
-	( load ) ;icn1_path .File/name DEO2 #1800 .File/length DEO2 ;image .File/load DEO2
29
-	( draw ) #0008 #0008 #0100 #00c0 #07 ;image ;draw-icn JSR2
30
-
31
-	( load ) ;icn2_path .File/name DEO2 #0800 .File/length DEO2 ;image .File/load DEO2
32
-	( draw ) #0010 #0078 #0080 #0080 #07 ;image ;draw-icn JSR2
33
-
34
-	( load ) ;chr1_path .File/name DEO2 #4000 .File/length DEO2 ;image .File/load DEO2
35
-	( draw ) #00a8 #0010 #0100 #0100 #8f ;image ;draw-chr JSR2
36
-
37
-	( load ) ;chr2_path .File/name DEO2 #0900 .File/length DEO2 ;image .File/load DEO2
38
-	( draw ) #0088 #0088 #0060 #0060 #81 ;image ;draw-chr JSR2
30
+	( background ) ;checker-icn #02 ;cover-pattern JSR2
39 31
 
32
+	( load ) ;icn1-path #1800 LOAD-IMAGE
33
+	( draw ) #0008 #0008 #0100 #00c0 ;image #01 ;draw-icn JSR2
34
+	( load ) ;icn2-path #0800 LOAD-IMAGE
35
+	( draw ) #0010 #00a8 #0080 #0080 ;image #03 ;draw-icn JSR2
36
+	( load ) ;chr1-path #4000 LOAD-IMAGE
37
+	( draw ) #00e8 #0080 #0100 #0080 ;image #81 ;draw-chr JSR2
38
+	( load ) ;chr2-path #0900 LOAD-IMAGE
39
+	( draw ) #0068 #0098 #0060 #0060 ;image #85 ;draw-chr JSR2
40 40
 
41 41
 BRK
42 42
 
43
-@draw-icn ( x y width height color addr -- )
43
+@draw-icn ( x* y* width* height* addr* color  -- )
44 44
 	
45
-	( load ) .Screen/addr DEO2 .color STZ .size/height STZ2 .size/width STZ2 .position/y STZ2 .position/x STZ2
46
-	#0000 .size/height LDZ2
45
+	( load ) STH .Screen/addr DEO2 .size/height STZ2 .size/width STZ2 .position/y STZ2 .position/x STZ2
46
+	.size/height LDZ2 #0000 
47 47
 	&ver
48
-		( save ) OVR2 .position/y LDZ2 ADD2 .Screen/y DEO2
49
-		#0000 .size/width LDZ2
48
+		( save ) DUP2 .position/y LDZ2 ADD2 .Screen/y DEO2
49
+		.size/width LDZ2 #0000
50 50
 		&hor
51
-			( save ) OVR2 .position/x LDZ2 ADD2 .Screen/x DEO2
52
-			( draw ) .color LDZ .Screen/sprite DEO
53
-			( incr ) .Screen/addr DEI2 8+ .Screen/addr DEO2
54
-			( incr ) SWP2 8+ SWP2
55
-			LTH2k ,&hor JCN
51
+			( save ) DUP2 .position/x LDZ2 ADD2 .Screen/x DEO2
52
+			( draw ) STHkr .Screen/sprite DEO
53
+			( incr ) .Screen/addr DEI2 #0008 ADD2 .Screen/addr DEO2
54
+			#0008 ADD2 GTH2k ,&hor JCN
56 55
 		POP2 POP2
57
-		( incr ) SWP2 8+ SWP2
58
-		LTH2k ,&ver JCN
56
+		#0008 ADD2 GTH2k ,&ver JCN
59 57
 	POP2 POP2
58
+	POPr
60 59
 
61 60
 RTN
62 61
 
63
-@draw-chr ( x y width height color addr -- )
62
+@draw-chr ( x* y* width* height* addr* color -- )
64 63
 	
65
-	( load ) .Screen/addr DEO2 .color STZ .size/height STZ2 .size/width STZ2 .position/y STZ2 .position/x STZ2
66
-	#0000 .size/height LDZ2
64
+	( load ) STH .Screen/addr DEO2 .size/height STZ2 .size/width STZ2 .position/y STZ2 .position/x STZ2
65
+	.size/height LDZ2 #0000
67 66
 	&ver
68
-		( save ) OVR2 .position/y LDZ2 ADD2 .Screen/y DEO2
69
-		#0000 .size/width LDZ2
67
+		( save ) DUP2 .position/y LDZ2 ADD2 .Screen/y DEO2
68
+		.size/width LDZ2 #0000
70 69
 		&hor
71
-			( save ) OVR2 .position/x LDZ2 ADD2 .Screen/x DEO2
72
-			( draw ) .color LDZ .Screen/sprite DEO
70
+			( save ) DUP2 .position/x LDZ2 ADD2 .Screen/x DEO2
71
+			( draw ) STHkr .Screen/sprite DEO
73 72
 			( incr ) .Screen/addr DEI2 #0010 ADD2 .Screen/addr DEO2
74
-			( incr ) SWP2 8+ SWP2
75
-			LTH2k ,&hor JCN
73
+			#0008 ADD2 GTH2k ,&hor JCN
76 74
 		POP2 POP2
77
-		( incr ) SWP2 8+ SWP2
78
-		LTH2k ,&ver JCN
75
+		#0008 ADD2 GTH2k ,&ver JCN
79 76
 	POP2 POP2
77
+	POPr
80 78
 
81 79
 RTN
82 80
 
83 81
 @cover-pattern ( addr* color -- )
84 82
 	
85
-	( load ) .color/byte STZ .Screen/addr DEO2
86
-	#0000 .Screen/height DEI2
83
+	( load ) STH .Screen/addr DEO2
84
+	.Screen/height DEI2 #0000
87 85
 	&ver
88
-		( save ) OVR2 .Screen/y DEO2
89
-		#0000 .Screen/width DEI2
86
+		( save ) DUP2 .Screen/y DEO2
87
+		.Screen/width DEI2 #0000
90 88
 		&hor
91
-			( save ) OVR2 .Screen/x DEO2
92
-			( draw ) .color LDZ .Screen/sprite DEO
93
-			( incr ) SWP2 8+ SWP2
94
-			LTH2k ,&hor JCN
89
+			( save ) DUP2 .Screen/x DEO2
90
+			( draw ) STHkr .Screen/sprite DEO
91
+			#0008 ADD2 GTH2k ,&hor JCN
95 92
 		POP2 POP2
96
-		( incr ) SWP2 8+ SWP2
97
-		LTH2k ,&ver JCN
93
+		#0008 ADD2 GTH2k ,&ver JCN
98 94
 	POP2 POP2
95
+	POPr
99 96
 
100 97
 RTN
101 98
 
102
-@checker_icn [ f0f0 f0f0 0f0f 0f0f ]
103
-
104
-@icn1_path [ "projects/pictures/ergo100x0c0.bit 00 ]
105
-@icn2_path [ "projects/pictures/dafu80x80.bit 00 ]
106
-@chr1_path [ "projects/pictures/zerotwo2020.chr 00 ]
107
-@chr2_path [ "projects/pictures/felix0cx0c.chr 00 ]
99
+@checker-icn f0f0 f0f0 0f0f 0f0f
100
+@icn1-path   "projects/pictures/ergo100x0c0.bit 00
101
+@icn2-path   "projects/pictures/dafu80x80.bit 00
102
+@chr1-path   "projects/pictures/pc98.chr 00
103
+@chr2-path   "projects/pictures/felix0cx0c.chr 00
108 104
 
109 105
 @image [ ]
110 106
\ No newline at end of file
111 107
similarity index 91%
112 108
rename from projects/pictures/zerotwo2020.chr
113 109
rename to projects/pictures/zerotwo20x20.chr
114 110
Binary files a/projects/pictures/zerotwo2020.chr and b/projects/pictures/zerotwo20x20.chr differ