Browse code

Ported mouse example

neauoire authored on 21/04/2021 16:48:04
Showing 9 changed files
... ...
@@ -22,11 +22,17 @@ To build the Uxn emulator, you must have [SDL2](https://wiki.libsdl.org/).
22 22
 Read more in the [Uxambly Guide](https://wiki.xxiivv.com/site/uxambly.html).
23 23
 
24 24
 ```
25
+( dev/console )
26
+
25 27
 %RTN { JMP2r }
26 28
 
27
-( program )
29
+( devices )
30
+
31
+|10 @Console    [ &pad $8 &char $1 ]
32
+
33
+( init )
28 34
 
29
-|0100
35
+|0100 ( -> )
30 36
 	
31 37
 	;hello-word ;print JSR2
32 38
 	
... ...
@@ -43,10 +49,6 @@ BRK
43 49
 RTN
44 50
 
45 51
 @hello-word [ 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 ]
46
-
47
-( devices )
48
-
49
-|ff10 @Console    [ &pad $8 &char $1 ]
50 52
 ```
51 53
 
52 54
 ## TODOs
... ...
@@ -32,7 +32,7 @@ else
32 32
 fi
33 33
 
34 34
 echo "Assembling.."
35
-./bin/assembler projects/examples/dev.controller.keys.usm bin/boot.rom
35
+./bin/assembler projects/examples/dev.mouse.usm bin/boot.rom
36 36
 
37 37
 echo "Running.."
38 38
 if [ "${2}" = '--cli' ]; 
... ...
@@ -1,17 +1,12 @@
1 1
 ( a blank file )
2 2
 
3
-%RTN { JMP2r }
4
-
5 3
 ( devices )
6 4
 
7
-|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
8
-|0110 ;Console { vector 2 pad 6 char 1 byte 1 short 2 string 2 }
9
-|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 }
10
-|0130 ;Audio { wave 2 envelope 2 pad 4 volume 1 pitch 1 play 1 value 2 delay 2 finish 1 }
11
-|0140 ;Controller { vector 2 button 1 key 1 }
12
-|0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 }
13
-|0170 ;File { vector 2 success 2 offset 2 pad 2 name 2 length 2 load 2 save 2 }
14
-|01a0 ;DateTime { year 2 month 1 day 1 hour 1 minute 1 second 1 dotw 1 doty 2 isdst 1 refresh 1 }
15
-
16
-|0200 
5
+|00 @System     [ &vector $2 &pad     $6 &r      $2 &g     $2 &b      $2 ]
6
+|10 @Console    [ &pad    $8 &char    $1 &byte   $1 &short $2 &string $2 ]
7
+|20 @Screen     [ &vector $2 &width   $2 &height $2 &pad   $2 &x      $2 &y     $2 &addr $2 &color $1 ]
8
+|40 @Controller [ &vector $2 &button  $1 &key    $1 ]
9
+|60 @Mouse      [ &vector $2 &x       $2 &y      $2 &state $1 &chord $1 ]
10
+|70 @File       [ &vector $2 &success $2 &offset $2 &pad   $2 &name  $2 &length $2 &load $2 &save $2 ]
17 11
 
12
+|1000 ( program )
... ...
@@ -6,13 +6,9 @@
6 6
 
7 7
 |10 @Console    [ &pad $8 &char $1 ]
8 8
 
9
-( variables )
9
+( init )
10 10
 
11
-|0000
12
-
13
-( program )
14
-
15
-|0100
11
+|0100 ( -> )
16 12
 	
17 13
 	;hello-word ;print JSR2
18 14
 	
... ...
@@ -29,4 +25,3 @@ BRK
29 25
 RTN
30 26
 
31 27
 @hello-word [ 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 ]
32
-
... ...
@@ -10,7 +10,7 @@
10 10
 
11 11
 |00 @System     [ &vector $2 &pad    $6 &r      $2 &g     $2 &b      $2 ]
12 12
 |20 @Screen     [ &vector $2 &width  $2 &height $2 &pad   $2 &x      $2 &y $2 &addr $2 &color $1 ]
13
-|40 @Controller [ &vector $2 &button $1 &key    $1 ]
13
+|40 @Controller [ &vector $2 &button $1 &key    $1 ] 
14 14
 
15 15
 ( variables )
16 16
 
... ...
@@ -18,7 +18,9 @@
18 18
 
19 19
 @slime $1
20 20
 
21
-|0100
21
+( init )
22
+
23
+|0100 ( -> )
22 24
 	
23 25
 	( theme ) 
24 26
 	#0daf .System/r IOW2 
... ...
@@ -38,7 +40,7 @@
38 40
 
39 41
 BRK
40 42
 
41
-@on-frame
43
+@on-frame ( -> )
42 44
 
43 45
 	#2a .slime POK
44 46
 	;default_icn =>SC/ADDR
... ...
@@ -10,13 +10,9 @@
10 10
 |20 @Screen     [ &vector $2 &width  $2 &height $2 &pad   $2 &x      $2 &y $2 &addr $2 &color $1 ]
11 11
 |40 @Controller [ &vector $2 &button $1 &key    $1 ]
12 12
 
13
-( variables )
13
+( init )
14 14
 
15
-|0000
16
-
17
-@slime $1
18
-
19
-|0100
15
+|0100 ( -> )
20 16
 
21 17
 	( theme ) 
22 18
 	#0f73 .System/r IOW2 
... ...
@@ -29,7 +25,7 @@
29 25
 	
30 26
 BRK
31 27
 
32
-@on-button
28
+@on-button ( -> )
33 29
 	
34 30
 	.Controller/key IOR #00 NEQ ,&skip JNZ BRK &skip  
35 31
 
... ...
@@ -49,14 +45,13 @@ BRK
49 45
 
50 46
 BRK
51 47
 
52
-@draw-cursor
48
+@draw-cursor ( -- )
53 49
 	
54 50
 	;cursor .Screen/addr IOW2 #22 .Screen/color IOW
55 51
 
56 52
 RTN
57 53
 
58
-@cursor 
59
-	ffff ffff ffff ffff
54
+@cursor [ ffff ffff ffff ffff ]
60 55
 
61 56
 @font ( spectrum-zx font ) 
62 57
 	0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000
63 58
deleted file mode 100644
... ...
@@ -1,188 +0,0 @@
1
-( Dev/File )
2
-
3
-%RTN { JMP2r }
4
-%STEP8 { #0033 SFT2 }
5
-%++ { #01 ADD }
6
-
7
-%MEMORY { #1000 }
8
-
9
-;loadbtn { x 2 y 2 }
10
-;output { x 2 y 2 }
11
-;pointer { x 2 y 2 }
12
-;label { x 2 y 2 color 1 addr 2 }
13
-
14
-( devices )
15
-
16
-|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
17
-|0110 ;Console { vector 2 pad 6 char 1 byte 1 short 2 string 2 }
18
-|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 }
19
-|0160 ;Mouse  { vector 2 x 2 y 2 state 1 chord 1 }
20
-|0170 ;File { vector 2 success 2 offset 2 pad 2 name 2 length 2 load 2 save 2 }
21
-
22
-( program )
23
-
24
-|0200 
25
-
26
-	( theme ) #804b =System.r #804b =System.g #e0bb =System.b
27
-	( vectors ) ,on-mouse =Mouse.vector
28
-	( vectors ) ,on-transfer =File.vector
29
-
30
-	#0020 =loadbtn.x
31
-	#0020 =loadbtn.y
32
-	#0020 =output.x
33
-	#0030 =output.y
34
-
35
-	~loadbtn.x ~loadbtn.y #26 ,load_txt ,draw-label JSR2
36
-
37
-	,draw-file JSR2
38
-
39
-BRK
40
-
41
-@on-transfer ( -> )
42
-
43
-	,draw-file JSR2
44
-	~output.x ~output.y #0088 ADD2 #23 ,done_txt ,draw-label JSR2
45
-	( release ) #00 =Mouse.state
46
-
47
-BRK
48
-
49
-@on-mouse ( -> )
50
- 	
51
-	~loadbtn.x ~loadbtn.y #26 ,load_txt ,draw-label JSR2
52
-	~loadbtn.x #0028 ADD2 ~loadbtn.y #23 ,srcpath ,draw-label JSR2
53
-
54
-	~Mouse.state #00 EQU ^$touch-end JNZ
55
-
56
-		~Mouse.y STEP8 ~loadbtn.y NEQ2 ^$no-touch-load JNZ
57
-			~loadbtn.x ~loadbtn.y #27 ,load_txt ,draw-label JSR2
58
-			,srcpath #0100 ,load-file JSR2
59
-			( release ) #00 =Mouse.state
60
-		$no-touch-load
61
-
62
-	$touch-end
63
-
64
-	,draw-cursor JSR2
65
-
66
-BRK 
67
-
68
-@draw-file ( -- )
69
-
70
-	#00 #10
71
-	$ver
72
-		( pos-y ) OVR #00 SWP #0008 MUL2 ~output.y ADD2 =Screen.y
73
-		#00 #10
74
-		$hor
75
-			( pos-x )   OVR #00 SWP #0008 MUL2 ~output.x ADD2 =Screen.x 
76
-			( get x,y ) SWP2 OVR STH SWP2 OVR STHr 
77
-			( get id ) #10 MUL ADD
78
-			( get data ) #00 SWP MEMORY ADD2 PEK2 
79
-			( get sprite ) #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr
80
-			( draw ) #2d =Screen.color
81
-			( incr )    SWP ++ SWP
82
-			DUP2 NEQ ^$hor JNZ
83
-		POP2
84
-		( incr ) SWP ++ SWP
85
-		DUP2 NEQ ^$ver JNZ
86
-	POP2
87
-
88
-RTN
89
-
90
-@load-file ( path length -- )
91
-	
92
-	=File.length =File.name MEMORY =File.load
93
-
94
-RTN
95
-
96
-@draw-cursor ( -- )
97
-
98
-	( clear last cursor )
99
-	,clear_icn =Screen.addr 
100
-	~pointer.x =Screen.x 
101
-	~pointer.y =Screen.y 
102
-	#30 =Screen.color
103
-
104
-	( record pointer positions )
105
-	~Mouse.x =pointer.x ~Mouse.y =pointer.y
106
-
107
-	( draw new cursor )
108
-	,cursor_icn =Screen.addr 
109
-	~pointer.x =Screen.x 
110
-	~pointer.y =Screen.y 
111
-	#32 ~Mouse.state #00 NEQ ADD =Screen.color
112
-
113
-RTN
114
-
115
-@draw-label ( x y color addr -- )
116
-	
117
-	( load ) =label.addr =label.color =Screen.y =Screen.x 
118
-	~label.addr
119
-	$loop
120
-		( draw ) DUP2 PEK2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr ~label.color =Screen.color
121
-		( incr ) #0001 ADD2
122
-		( incr ) ~Screen.x #0008 ADD2 =Screen.x
123
-		DUP2 PEK2 #00 NEQ ^$loop JNZ
124
-	POP2
125
-
126
-RTN
127
-
128
-@clear_icn   [ 0000 0000 0000 0000 ]
129
-@cursor_icn  [ 80c0 e0f0 f8e0 1000 ]
130
-
131
-@done_txt [ LOAD 20 SUCCESS! 00 ]
132
-@load_txt [ LOAD 00 ]
133
-@save_txt [ SAVE 00 ]
134
-
135
-@srcpath [ README.md 00 ]
136
-@dstpath [ bin/export.md 00 ]
137
-
138
-@font ( specter8-frag font ) 
139
-[
140
-	0000 0000 0000 0000 0008 0808 0800 0800
141
-	0014 1400 0000 0000 0024 7e24 247e 2400
142
-	0008 1e28 1c0a 3c08 0000 2204 0810 2200
143
-	0030 4832 4c44 3a00 0008 1000 0000 0000
144
-	0004 0808 0808 0400 0020 1010 1010 2000
145
-	0000 2214 0814 2200 0000 0808 3e08 0800
146
-	0000 0000 0000 0810 0000 0000 3e00 0000
147
-	0000 0000 0000 0800 0000 0204 0810 2000
148
-	003c 464a 5262 3c00 0018 0808 0808 1c00
149
-	003c 4202 3c40 7e00 003c 421c 0242 3c00
150
-	000c 1424 447e 0400 007e 407c 0242 3c00
151
-	003c 407c 4242 3c00 007e 0204 0810 1000
152
-	003c 423c 4242 3c00 003c 4242 3e02 3c00
153
-	0000 0010 0000 1000 0000 1000 0010 1020
154
-	0000 0810 2010 0800 0000 003e 003e 0000
155
-	0000 1008 0408 1000 003c 420c 1000 1000
156
-	003c 4232 4a42 3c00 003c 4242 7e42 4200
157
-	007c 427c 4242 7c00 003c 4240 4042 3c00
158
-	007c 4242 4242 7c00 007e 4078 4040 7e00
159
-	007e 4078 4040 4000 003c 4240 4642 3c00
160
-	0042 427e 4242 4200 001c 0808 0808 1c00
161
-	007e 0202 0242 3c00 0042 4478 4442 4200
162
-	0040 4040 4040 7e00 0042 665a 4242 4200
163
-	0042 6252 4a46 4200 003c 4242 4242 3c00
164
-	007c 4242 7c40 4000 003c 4242 4244 3a00
165
-	007c 4242 7c44 4200 003e 403c 0242 3c00
166
-	007e 0808 0808 1000 0042 4242 4244 3a00
167
-	0042 4242 4224 1800 0042 4242 5a66 4200
168
-	0042 423c 4242 4200 0042 423e 0242 3c00
169
-	007e 020c 3040 7e00 000c 0808 0808 0c00
170
-	0040 2010 0804 0200 0030 1010 1010 3000
171
-	0008 1400 0000 0000 0000 0000 0000 7e00
172
-	0008 0400 0000 0000 0000 3c02 3e42 3a00
173
-	0040 407c 4242 7c00 0000 3c42 4042 3c00
174
-	0002 023e 4242 3e00 0000 3c42 7e40 3e00
175
-	0000 3e40 7840 4000 0000 3c42 3e02 3c00
176
-	0040 405c 6242 4200 0008 0018 0808 0400
177
-	0008 0018 0808 4830 0040 4244 7844 4200
178
-	0010 1010 1010 0c00 0000 6c52 5252 5200
179
-	0000 5c62 4242 4200 0000 3c42 4242 3c00
180
-	0000 7c42 427c 4040 0000 3e42 423e 0202
181
-	0000 5c62 4040 4000 0000 3e40 3c02 7c00
182
-	0008 7e08 0808 1000 0000 4242 4244 3a00
183
-	0000 4242 4224 1800 0000 5252 5252 2e00
184
-	0000 4224 1824 4200 0000 4242 3e02 7c00
185
-	0000 7e02 3c40 7e00 000c 0810 1008 0c00
186
-	0008 0808 0808 0800 0030 1008 0810 3000
187
-	0000 0032 4c00 0000 3c42 99a1 a199 423c
188
-]
189 0
\ No newline at end of file
... ...
@@ -34,9 +34,9 @@
34 34
 @pointer [ &x $2 &y $2 ]
35 35
 @label [ &x $2 &y $2 &color $1 &addr $2 ]
36 36
 
37
-( program )
37
+( init )
38 38
 
39
-|0100 
39
+|0100 ( -> )
40 40
 
41 41
 	( theme )
42 42
 	#804b .System/r IOW2
... ...
@@ -204,4 +204,3 @@ RTN
204 204
 	0008 0808 0808 0800 0030 1008 0810 3000
205 205
 	0000 0032 4c00 0000 3c42 99a1 a199 423c
206 206
 ]
207
-
208 207
new file mode 100644
... ...
@@ -0,0 +1,63 @@
1
+( dev/mouse )
2
+
3
+%RTN { JMP2r }
4
+%8+  { #0008 ADD2 }
5
+%++  { #0001 ADD2 }
6
+%--  { #0001 SUB2 }
7
+
8
+( devices )
9
+
10
+|00 @System     [ &vector $2 &pad     $6 &r      $2 &g     $2 &b      $2 ]
11
+|10 @Console    [ &pad    $8 &char    $1 &byte   $1 &short $2 &string $2 ]
12
+|20 @Screen     [ &vector $2 &width   $2 &height $2 &pad   $2 &x      $2 &y     $2 &addr $2 &color $1 ]
13
+|40 @Controller [ &vector $2 &button  $1 &key    $1 ]
14
+|60 @Mouse      [ &vector $2 &x       $2 &y      $2 &state $1 &chord $1 ]
15
+
16
+|0000
17
+
18
+@pointer [ &x $2 &y $2 ]
19
+
20
+( program )
21
+
22
+|0100 ( -> )
23
+
24
+	( theme ) 
25
+	#03fd .System/r IOW2 
26
+	#0ef3 .System/g IOW2 
27
+	#0bf2 .System/b IOW2
28
+
29
+	( vectors ) ;on-mouse .Mouse/vector IOW2
30
+
31
+BRK
32
+
33
+@on-mouse ( -> )
34
+
35
+	;draw-cursor JSR2
36
+
37
+BRK 
38
+
39
+@draw-cursor ( -- )
40
+	
41
+	( clear last cursor )
42
+	;clear .Screen/addr IOW2 
43
+	.pointer/x LDR .Screen/x IOW2 
44
+	.pointer/y LDR .Screen/y IOW2 
45
+	#30 .Screen/color IOW
46
+
47
+	( record pointer positions )
48
+	.Mouse/x IOR2 .pointer/x STR 
49
+	.Mouse/y IOR2 .pointer/y STR
50
+
51
+	( draw new cursor )
52
+	;cursor .Screen/addr IOW2 
53
+	.pointer/x LDR .Screen/x IOW2 
54
+	.pointer/y LDR .Screen/y IOW2 
55
+
56
+	( colorize on state )
57
+	.Mouse/state IOR #00 NEQ
58
+	#31 ADD .Screen/color IOW
59
+
60
+RTN
61
+
62
+@clear   [ 0000 0000 0000 0000 ]
63
+@cursor  [ 80c0 e0f0 f8e0 1000 ]