Browse code

Migrated chord example

neauoire authored on 27/02/2021 01:16:45
Showing 2 changed files
1 1
deleted file mode 100644
... ...
@@ -1,230 +0,0 @@
1
-( mouse )
2
-
3
-:dev/r fff8 ( std read port )
4
-:dev/w fff9 ( std write port )
5
-
6
-&Point2d { x 2 y 2 }
7
-&Window2d { x1 2 y1 2 x2 2 y2 2 }
8
-
9
-;pos Point2d
10
-;mouse Point2d
11
-;scenter Point2d
12
-;win Window2d
13
-
14
-( drawing ) ;color 1 ;x1 2 ;x2 2 ;y1 2 ;y2 2 ;i 2
15
-;state 1
16
-
17
-|0100 @RESET 
18
-
19
-	#01 =dev/r ( read screen for size )
20
-	#02 =dev/w ( write to screen )
21
-
22
-	#08 =color
23
-	,paint-pattern JSR
24
-
25
-	#01 =dev/w ( write to screen )
26
-
27
-	#00 IOR2 #0002 DIV2 =scenter.x
28
-	#02 IOR2 #0002 DIV2 =scenter.y
29
-
30
-	~scenter.x #0060 SUB2 
31
-	~scenter.y #0018 SUB2 
32
-	~scenter.x #0060 ADD2 
33
-	~scenter.y #0018 ADD2 ,paint-window JSR
34
-
35
-	#05 =dev/r ( set dev/read mouse )
36
-	#02 =dev/w ( set dev/write to sprite ) 
37
-
38
-	#09 =color
39
-
40
-BRK
41
-
42
-|c000 @FRAME
43
-
44
-	( clear last cursor )
45
-	#10 ,clear_icn ~mouse.x ~mouse.y ,draw-sprite JSR
46
-	( record mouse positions )
47
-	#00 IOR2 =mouse.x 
48
-	#02 IOR2 =mouse.y
49
-	#13 =state
50
-
51
-	( detect click )
52
-	#04 IOR #11 NEQ ,no-click12 ROT JMP? POP2
53
-		,mouse12_text ~win.x1 #0018 ADD2 ~scenter.y #0008 SUB2 ,draw-label JSR
54
-		~color ,mouse12_icn ~win.x1 #0008 ADD2 ~scenter.y #0008 SUB2 ,draw-sprite JSR
55
-		,end-click JSR
56
-	@no-click12
57
-	#04 IOR #01 NEQ ,no-click1 ROT JMP? POP2
58
-		,mouse1_text ~win.x1 #0018 ADD2 ~scenter.y #0008 SUB2 ,draw-label JSR
59
-		~color ,mouse1_icn ~win.x1 #0008 ADD2 ~scenter.y #0008 SUB2 ,draw-sprite JSR
60
-		,end-click JSR
61
-	@no-click1
62
-	#04 IOR #10 NEQ ,no-click2 ROT JMP? POP2
63
-		,mouse2_text ~win.x1 #0018 ADD2 ~scenter.y #0008 SUB2 ,draw-label JSR
64
-		~color ,mouse2_icn ~win.x1 #0008 ADD2 ~scenter.y #0008 SUB2 ,draw-sprite JSR
65
-		,end-click JSR
66
-	@no-click2
67
-	( default )
68
-	#11 =state
69
-	,mouse0_text ~win.x1 #0018 ADD2 ~scenter.y #0008 SUB2 ,draw-label JSR
70
-	~color ,mouse0_icn ~win.x1 #0008 ADD2 ~scenter.y #0008 SUB2 ,draw-sprite JSR
71
-	@end-click
72
-
73
-	( detect chord )
74
-	#05 IOR #01 NEQ ,no-chord1 ROT JMP? POP2
75
-		,chord1_text ~win.x1 #0018 ADD2 ~scenter.y ,draw-label JSR
76
-		,end-chord JSR
77
-	@no-chord1
78
-	#05 IOR #10 NEQ ,no-chord2 ROT JMP? POP2
79
-		,chord2_text ~win.x1 #0018 ADD2 ~scenter.y ,draw-label JSR
80
-		,end-chord JSR
81
-	@no-chord2
82
-	( default )
83
-	,chord0_text ~win.x1 #0018 ADD2 ~scenter.y ,draw-label JSR
84
-	@end-chord
85
-
86
-	( draw mouse )
87
-	~state ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR
88
-
89
-BRK
90
-
91
-@paint-pattern ( nil )
92
-
93
-	#01 =dev/r ( read screen for size )
94
-	#02 =dev/w ( write to sprite )
95
-
96
-	#0000 
97
-	@paint-pattern-loop-hor
98
-	#0000
99
-	@paint-pattern-loop
100
-		( draw ) OVR2 IOW2 DUP2 IOW2 ,pattern IOW2 ~color IOW
101
-		( incr ) #0008 ADD2 DUP2
102
-		#00 IOR2 LTH2 ,paint-pattern-loop ROT JMP? POP2
103
-		POP2
104
-	( incr ) #0008 ADD2 DUP2
105
-	#02 IOR2 LTH2 ,paint-pattern-loop-hor ROT JMP? POP2
106
-	POP2
107
-
108
-RTS
109
-
110
-@paint-window ( name wx1 wy1 wx2 wy2 )
111
-
112
-	=win.y2 =win.x2 =win.y1 =win.x1
113
-
114
-	( Draw shadow )
115
-	#01 =color
116
-	~win.x2 ~win.y1 #0003 ADD2 ~win.x2 #0003 ADD2 ~win.y2 #0003 ADD2 ,fill-rect JSR
117
-	~win.x1 #0003 ADD2 ~win.y2 ~win.x2 #0003 ADD2 ~win.y2 #0003 ADD2 ,fill-rect JSR
118
-	( Fill background )
119
-	#02 =color
120
-	~win.x1 ~win.y1 ~win.x2 ~win.y2 ,fill-rect JSR
121
-	( draw outline )
122
-	#01 =color
123
-	~win.x1 ~win.y1 ~win.x2 ~win.y2 ,line-rect JSR
124
-	#01 =color
125
-	~win.x1 #0002 ADD2 ~win.y1 #0002 ADD2 ~win.x2 #0002 SUB2 ~win.y2 #0002 SUB2 ,line-rect JSR
126
-
127
-RTS
128
-
129
-@draw-label ( text x1 y1 )
130
-	=pos.y =pos.x
131
-	@draw-label-loop
132
-		( draw ) ~pos.x ~pos.y IOW2 IOW2 DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 IOW2 ~color IOW
133
-		( incr ) #0001 ADD2
134
-		( incr ) ~pos.x #0008 ADD2 =pos.x
135
-		DUP2 LDR #00 NEQ ,draw-label-loop ROT JMP? POP2
136
-	POP2
137
-RTS
138
-
139
-@fill-rect ( x1 y1 x2 y2 )
140
-	=y2 =x2 ( stash x1 y1 ) =y1 DUP2 WSR2 =x1
141
-	@fill-rect-ver
142
-		RSW2 DUP2 =x1 WSR2
143
-		@fill-rect-hor
144
-			( draw ) ~x1 ~y1 IOW2 IOW2 ~color IOW
145
-			( incr ) ~x1 #0001 ADD2 DUP2 =x1  
146
-			~x2 LTH2 ,fill-rect-hor ROT JMP? POP2
147
-		~y1 #0001 ADD2 DUP2 =y1
148
-		~y2 LTH2 ,fill-rect-ver ROT JMP? POP2
149
-	RSW2 POP2
150
-RTS
151
-
152
-@line-rect ( x1 y1 x2 y2 )
153
-	=y2 =x2 ( stash x1 y1 ) DUP2 WSR2 =y1 DUP2 WSR2 =x1
154
-	@line-rect-hor
155
-		( draw ) ~x1 ~y1 IOW2 IOW2 ~color IOW
156
-		( draw ) ~x1 ~y2 IOW2 IOW2 ~color IOW
157
-		( incr ) ~x1 #0001 ADD2 DUP2 =x1  
158
-		~x2 #0001 ADD2 LTH2 ,line-rect-hor ROT JMP? POP2
159
-	( restore x1 y1 ) RSW2 =x1 RSW2 =y1
160
-	@line-rect-ver
161
-		( incr ) ~y1 #0001 ADD2 DUP2 =y1  
162
-		( draw ) ~x1 ~y1 IOW2 IOW2 ~color IOW
163
-		( draw ) ~x2 ~y1 IOW2 IOW2 ~color IOW
164
-		~y2 #0001 SUB2 LTH2 ,line-rect-ver ROT JMP? POP2
165
-RTS
166
-
167
-@draw-sprite
168
-	IOW2 ( y byte )
169
-	IOW2 ( x byte )
170
-	IOW2 ( sprite address )
171
-	IOW ( layer-color )
172
-	RTS
173
-
174
-@pattern     [ 0814 2241 8041 2214 ]
175
-
176
-@clear_icn   [ 0000 0000 0000 0000 ]
177
-@cursor_icn  [ 80c0 e0f0 f8e0 1000 ]
178
-
179
-@mouse0_icn  [ 7c82 92ee 8282 4438 ]
180
-@mouse1_icn  [ 7cf2 f2ee 8282 4438 ]
181
-@mouse2_icn  [ 7c9e 9eee 8282 4438 ]
182
-@mouse12_icn [ 7cfe feee 8282 4438 ]
183
-
184
-@font ( spectrum-zx font ) 
185
-[
186
-	0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000
187
-	0010 387c 7c38 1000 0038 387c 6c10 3800 0010 387c 7c10 3800 0000 0018 1800 0000
188
-	007e 4242 4242 7e00 0000 1824 2418 0000 0018 2442 4224 1800 001e 063a 4a48 3000
189
-	0038 446c 107c 1000 000c 0808 0838 3800 003e 2222 2266 6600 0000 0822 0022 0800
190
-	0000 1018 1c18 1000 0000 0818 3818 0800 0008 1c00 001c 0800 0028 2828 2800 2800
191
-	003e 4a4a 3a0a 0a00 000c 3046 620c 3000 0000 0000 0000 ffff 0010 3800 3810 0038
192
-	0008 1c2a 0808 0800 0008 0808 2a1c 0800 0000 0804 7e04 0800 0000 1020 7e20 1000
193
-	0000 4040 7e00 0000 0000 0024 6624 0000 0000 1038 7c00 0000 0000 007c 3810 0000
194
-	0000 0000 0000 0000 0008 0808 0800 0800 0014 1400 0000 0000 0024 7e24 247e 2400
195
-	0008 1e28 1c0a 3c08 0042 0408 1020 4200 0030 4832 4c44 3a00 0008 1000 0000 0000
196
-	0004 0808 0808 0400 0010 0808 0808 1000 0000 1408 3e08 1400 0000 0808 3e08 0800
197
-	0000 0000 0008 0810 0000 0000 3c00 0000 0000 0000 0000 0800 0000 0204 0810 2000
198
-	003c 464a 5262 3c00 0018 2808 0808 3e00 003c 4202 3c40 7e00 003c 421c 0242 3c00
199
-	0008 1828 487e 0800 007e 407c 0242 3c00 003c 407c 4242 3c00 007e 0204 0810 1000
200
-	003c 423c 4242 3c00 003c 4242 3e02 3c00 0000 0008 0000 0800 0000 0800 0008 0810
201
-	0000 0810 2010 0800 0000 003e 003e 0000 0000 1008 0408 1000 003c 4202 0c00 0800
202
-	003c 425a 5442 3c00 0018 2442 7e42 4200 007c 427c 4242 7c00 003c 4240 4042 3c00
203
-	0078 4442 4244 7800 007e 407c 4040 7e00 003e 4040 7c40 4000 003c 4240 4e42 3c00
204
-	0042 427e 4242 4200 003e 0808 0808 3e00 0002 0202 4242 3c00 0044 4870 4844 4200
205
-	0040 4040 4040 7e00 0042 665a 4242 4200 0042 6252 4a46 4200 003c 4242 4242 3c00
206
-	007c 4242 7c40 4000 003c 4242 524a 3c00 007c 4242 7c44 4200 003c 403c 0242 3c00
207
-	00fe 1010 1010 1000 0042 4242 4242 3c00 0042 4242 4224 1800 0042 4242 5a66 4200
208
-	0042 2418 1824 4200 0082 4428 1010 1000 007e 0408 1020 7e00 000c 0808 0808 0c00
209
-	0040 2010 0804 0200 0018 0808 0808 1800 0008 1422 0000 0000 0000 0000 0000 7e00
210
-	0008 0400 0000 0000 0000 1c02 1e22 1e00 0020 203c 2222 3c00 0000 1e20 2020 1e00
211
-	0002 021e 2222 1e00 0000 1c22 3c20 1e00 000c 101c 1010 1000 0000 1c22 221e 021c
212
-	0020 202c 3222 2200 0008 0018 0808 0400 0008 0008 0808 4830 0020 2428 3028 2400
213
-	0010 1010 1010 0c00 0000 6854 5454 5400 0000 5864 4444 4400 0000 3844 4444 3800
214
-	0000 7844 4478 4040 0000 3c44 443c 0406 0000 2c30 2020 2000 0000 3840 3804 7800
215
-	0010 103c 1010 0c00 0000 4444 4444 3800 0000 4444 2828 1000 0000 4454 5454 2800
216
-	0000 4428 1028 4400 0000 4444 443c 0438 0000 7c08 1020 7c00 000c 0810 1008 0c00
217
-	0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c
218
-]
219
-
220
-@chord0_text   [ no chord ] <1 .00
221
-@chord1_text   [ chord 1_ ] <1 .00
222
-@chord2_text   [ chord _2 ] <1 .00
223
-@mouse0_text   [ no click ] <1 .00
224
-@mouse1_text   [ mouse 1_ ] <1 .00
225
-@mouse2_text   [ mouse _2 ] <1 .00
226
-@mouse12_text  [ mouse 12 ] <1 .00
227
-
228
-|d000 @ERROR BRK 
229
-|FFF0 [ f0ff 20df 40bf ] ( palette )
230
-|FFFA .RESET .FRAME .ERROR
... ...
@@ -6,8 +6,10 @@
6 6
 
7 7
 &Point2d { x 2 y 2 }
8 8
 
9
-;cat Point2d ;mouse Point2d
10
-
9
+;cat Point2d 
10
+;mouse Point2d
11
+;pos Point2d
12
+;color 1
11 13
 ;timer 1
12 14
 
13 15
 |0100 @RESET 
... ...
@@ -15,6 +17,7 @@
15 17
 	( position cat )
16 18
 	~dev/screen.width #0002 DIV2 =cat.x 
17 19
 	~dev/screen.height #0038 SUB2 =cat.y
20
+	#01 =color
18 21
 	( draw polycat )
19 22
 	,draw-polycat JSR
20 23
 
... ...
@@ -26,12 +29,36 @@ BRK
26 29
 	#10 ,clear_icn ~mouse.x ~mouse.y ,draw-sprite JSR
27 30
 	( record mouse positions )
28 31
 	~dev/mouse.x =mouse.x ~dev/mouse.y =mouse.y
29
-	( detect click )
32
+	( reset timer -> move cat tail )
30 33
 	~dev/mouse.state #01 NEQ ,no-click ROT JMP? POP2
31 34
 		#50 =timer
32 35
 	@no-click
33
-	( draw mouse )
34
-	~dev/mouse.state #11 ADD ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR
36
+
37
+	( detect click )
38
+	~dev/mouse.state #11 NEQ ,no-click12 ROT JMP? POP2
39
+		,mouse12_text #0058 #0040 ,draw-label JSR
40
+		#10 ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR
41
+		~color ,mouse12_icn #0048 #0040 ,draw-sprite JSR
42
+		,end-click JMP
43
+	@no-click12
44
+	~dev/mouse.state #01 NEQ ,no-click1 ROT JMP? POP2
45
+		,mouse1_text #0058 #0040 ,draw-label JSR
46
+		#12 ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR
47
+		~color ,mouse1_icn #0048 #0040 ,draw-sprite JSR
48
+		,end-click JMP
49
+	@no-click1
50
+	~dev/mouse.state #10 NEQ ,no-click2 ROT JMP? POP2
51
+		,mouse2_text #0058 #0040 ,draw-label JSR
52
+		#13 ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR
53
+		~color ,mouse2_icn #0048 #0040 ,draw-sprite JSR
54
+		,end-click JMP
55
+	@no-click2
56
+	( default )
57
+	,mouse0_text #0058 #0040 ,draw-label JSR
58
+	~color ,mouse0_icn #0048 #0040 ,draw-sprite JSR
59
+	#11 ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR
60
+	@end-click
61
+	
35 62
 	( animate )
36 63
 	,animate-polycat JSR
37 64
 	( update last pos )
... ...
@@ -90,6 +117,16 @@ RTS
90 117
 
91 118
 RTS
92 119
 
120
+@draw-label ( text x1 y1 )
121
+	=pos.y =pos.x
122
+	@draw-label-loop
123
+		( draw ) ~pos.x ~pos.y =dev/sprite.y =dev/sprite.x DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 =dev/sprite.addr ~color =dev/sprite.color
124
+		( incr ) #0001 ADD2
125
+		( incr ) ~pos.x #0008 ADD2 =pos.x
126
+		DUP2 LDR #00 NEQ ,draw-label-loop ROT JMP? POP2
127
+	POP2
128
+RTS
129
+
93 130
 @draw-sprite
94 131
 	=dev/sprite.y
95 132
 	=dev/sprite.x
... ...
@@ -124,6 +161,56 @@ RTS
124 161
 	c0f0 f0e0 e080 8000 c0f1 faf9 fef8 b000
125 162
 ]
126 163
 
164
+
165
+@mouse0_icn  [ 7c82 92ee 8282 4438 ]
166
+@mouse1_icn  [ 7cf2 f2ee 8282 4438 ]
167
+@mouse2_icn  [ 7c9e 9eee 8282 4438 ]
168
+@mouse12_icn [ 7cfe feee 8282 4438 ]
169
+
170
+@font ( spectrum-zx font ) 
171
+[
172
+	0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000
173
+	0010 387c 7c38 1000 0038 387c 6c10 3800 0010 387c 7c10 3800 0000 0018 1800 0000
174
+	007e 4242 4242 7e00 0000 1824 2418 0000 0018 2442 4224 1800 001e 063a 4a48 3000
175
+	0038 446c 107c 1000 000c 0808 0838 3800 003e 2222 2266 6600 0000 0822 0022 0800
176
+	0000 1018 1c18 1000 0000 0818 3818 0800 0008 1c00 001c 0800 0028 2828 2800 2800
177
+	003e 4a4a 3a0a 0a00 000c 3046 620c 3000 0000 0000 0000 ffff 0010 3800 3810 0038
178
+	0008 1c2a 0808 0800 0008 0808 2a1c 0800 0000 0804 7e04 0800 0000 1020 7e20 1000
179
+	0000 4040 7e00 0000 0000 0024 6624 0000 0000 1038 7c00 0000 0000 007c 3810 0000
180
+	0000 0000 0000 0000 0008 0808 0800 0800 0014 1400 0000 0000 0024 7e24 247e 2400
181
+	0008 1e28 1c0a 3c08 0042 0408 1020 4200 0030 4832 4c44 3a00 0008 1000 0000 0000
182
+	0004 0808 0808 0400 0010 0808 0808 1000 0000 1408 3e08 1400 0000 0808 3e08 0800
183
+	0000 0000 0008 0810 0000 0000 3c00 0000 0000 0000 0000 0800 0000 0204 0810 2000
184
+	003c 464a 5262 3c00 0018 2808 0808 3e00 003c 4202 3c40 7e00 003c 421c 0242 3c00
185
+	0008 1828 487e 0800 007e 407c 0242 3c00 003c 407c 4242 3c00 007e 0204 0810 1000
186
+	003c 423c 4242 3c00 003c 4242 3e02 3c00 0000 0008 0000 0800 0000 0800 0008 0810
187
+	0000 0810 2010 0800 0000 003e 003e 0000 0000 1008 0408 1000 003c 4202 0c00 0800
188
+	003c 425a 5442 3c00 0018 2442 7e42 4200 007c 427c 4242 7c00 003c 4240 4042 3c00
189
+	0078 4442 4244 7800 007e 407c 4040 7e00 003e 4040 7c40 4000 003c 4240 4e42 3c00
190
+	0042 427e 4242 4200 003e 0808 0808 3e00 0002 0202 4242 3c00 0044 4870 4844 4200
191
+	0040 4040 4040 7e00 0042 665a 4242 4200 0042 6252 4a46 4200 003c 4242 4242 3c00
192
+	007c 4242 7c40 4000 003c 4242 524a 3c00 007c 4242 7c44 4200 003c 403c 0242 3c00
193
+	00fe 1010 1010 1000 0042 4242 4242 3c00 0042 4242 4224 1800 0042 4242 5a66 4200
194
+	0042 2418 1824 4200 0082 4428 1010 1000 007e 0408 1020 7e00 000c 0808 0808 0c00
195
+	0040 2010 0804 0200 0018 0808 0808 1800 0008 1422 0000 0000 0000 0000 0000 7e00
196
+	0008 0400 0000 0000 0000 1c02 1e22 1e00 0020 203c 2222 3c00 0000 1e20 2020 1e00
197
+	0002 021e 2222 1e00 0000 1c22 3c20 1e00 000c 101c 1010 1000 0000 1c22 221e 021c
198
+	0020 202c 3222 2200 0008 0018 0808 0400 0008 0008 0808 4830 0020 2428 3028 2400
199
+	0010 1010 1010 0c00 0000 6854 5454 5400 0000 5864 4444 4400 0000 3844 4444 3800
200
+	0000 7844 4478 4040 0000 3c44 443c 0406 0000 2c30 2020 2000 0000 3840 3804 7800
201
+	0010 103c 1010 0c00 0000 4444 4444 3800 0000 4444 2828 1000 0000 4454 5454 2800
202
+	0000 4428 1028 4400 0000 4444 443c 0438 0000 7c08 1020 7c00 000c 0810 1008 0c00
203
+	0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c
204
+]
205
+
206
+@chord0_text   [ no chord ] <1 .00
207
+@chord1_text   [ chord 1_ ] <1 .00
208
+@chord2_text   [ chord _2 ] <1 .00
209
+@mouse0_text   [ no click ] <1 .00
210
+@mouse1_text   [ mouse 1_ ] <1 .00
211
+@mouse2_text   [ mouse _2 ] <1 .00
212
+@mouse12_text  [ mouse 12 ] <1 .00
213
+
127 214
 |FF10 ;dev/screen Screen
128 215
 |FF20 ;dev/sprite Sprite
129 216
 |FF50 ;dev/mouse  Mouse