Browse code

Added drawing to the mouse example

neauoire authored on 22/04/2021 18:08:06
Showing 4 changed files
... ...
@@ -32,7 +32,7 @@ else
32 32
 fi
33 33
 
34 34
 echo "Assembling.."
35
-./bin/assembler projects/examples/dev.audio.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' ]; 
... ...
@@ -14,6 +14,10 @@ contexts:
14 14
     - match: '\@(\S+)\s?'
15 15
       scope: string.control
16 16
       pop: true
17
+      
18
+    - match: '\&(\S+)\s?'
19
+      scope: string.control
20
+      pop: true
17 21
     # jump
18 22
     - match: '\|(\S+)\s?'
19 23
       scope: variable.control
... ...
@@ -26,15 +30,15 @@ contexts:
26 30
 
27 31
     # Special
28 32
 
29
-    - match: '\&(\S+)\s?'
30
-      scope: entity.name.type
31
-      pop: true
32 33
 
33 34
     # Pushing to stack
34 35
 
35 36
     - match: '\#(\S+)\s?'
36 37
       scope: keyword.control
37 38
       pop: true
39
+    - match: '\"(\S+)\s?'
40
+      scope: entity.control
41
+      pop: true
38 42
     
39 43
     # Addressing
40 44
     - match: '\.(\S+)\s?'     # zero-page
... ...
@@ -20,10 +20,9 @@
20 20
 |0100 ( -> )
21 21
 	
22 22
 	( set color pallete )
23
-	#0fff DUP2 DUP2 
24
-	.System/r DEO2 
25
-	.System/g DEO2 
26
-	.System/b DEO2 
23
+	#00ff .System/r DEO2 
24
+	#0f0f .System/g DEO2 
25
+	#0ff0 .System/b DEO2 
27 26
 
28 27
 	;on-frame .Screen/vector DEO2 ( run on-frame every 1/60th of a second )
29 28
 	#ff .Audio/vol DEO            ( set volume to max )
... ...
@@ -35,7 +34,7 @@ BRK
35 34
 @on-frame ( -> )
36 35
 
37 36
 	( incr ) .timer PEK #01 ADD .timer POK 
38
-	( skip ) .timer PEK #10 NEQ ;silence JNZ2
37
+	( skip ) .timer PEK #10 EQU ,&play-note JNZ BRK &play-note
39 38
 
40 39
 	( get note )
41 40
 	;melody #00 .progress PEK ADD2 GET ( -- note )
... ...
@@ -4,6 +4,7 @@
4 4
 %8+  { #0008 ADD2 }
5 5
 %++  { #0001 ADD2 }
6 6
 %--  { #0001 SUB2 }
7
+%ABS2 { DUP2 #000f SFT2 EQU #04 JNZ #ffff MUL2 }
7 8
 
8 9
 ( devices )
9 10
 
... ...
@@ -15,27 +16,69 @@
15 16
 
16 17
 |0000
17 18
 
18
-@pointer [ &x $2 &y $2 ]
19
+@line    [ &x0 $2 &y0 $2 &x $2 &y $2 &sx $2 &sy $2 &dx $2 &dy $2 &e1 $2 &e2 $2 ]
20
+
21
+@pointer [ &x $2 &y $2 &lastx $2 &lasty $2 &state $1 ]
22
+@color $1
19 23
 
20 24
 ( program )
21 25
 
22 26
 |0100 ( -> )
23 27
 
24 28
 	( theme ) 
25
-	#03fd .System/r DEO2 
26
-	#0ef3 .System/g DEO2 
27
-	#0bf2 .System/b DEO2
29
+	#0ffd .System/r DEO2 
30
+	#0f03 .System/g DEO2 
31
+	#0f02 .System/b DEO2
28 32
 
29 33
 	( vectors ) ;on-mouse .Mouse/vector DEO2
30 34
 
35
+	#0010 #0030 #0050 #0070 #01 ;hairline JSR2
36
+	#0000 #0000 #0020 #0090 #01 ;hairline JSR2
37
+
31 38
 BRK
32 39
 
33 40
 @on-mouse ( -> )
34 41
 
35 42
 	;draw-cursor JSR2
36 43
 
44
+	( on down )
45
+	.Mouse/state DEI #00 NEQ 
46
+	.pointer/state PEK #00 EQU
47
+	#0101 EQU2 ,on-mouse-down JNZ
48
+
49
+	( on drag )
50
+	.Mouse/state DEI 
51
+	#00 NEQ ,on-mouse-drag JNZ
52
+
53
+	.Mouse/state DEI .pointer/state POK
54
+
37 55
 BRK 
38 56
 
57
+@on-mouse-down ( -> )
58
+
59
+	( record last position )
60
+	.Mouse/x DEI2 .pointer/x POK2 
61
+	.Mouse/y DEI2 .pointer/y POK2
62
+
63
+	.Mouse/x DEI2 .pointer/lastx POK2 
64
+	.Mouse/y DEI2 .pointer/lasty POK2
65
+
66
+	.Mouse/state DEI .pointer/state POK
67
+
68
+BRK
69
+
70
+@on-mouse-drag ( -> )
71
+	
72
+	.pointer/lastx PEK2 .pointer/lasty PEK2 .pointer/x PEK2 .pointer/y PEK2 #01 .Mouse/state DEI #10 EQU #02 MUL ADD ;hairline JSR2
73
+
74
+	( record last position )
75
+	.Mouse/x DEI2 .pointer/lastx POK2 
76
+	.Mouse/y DEI2 .pointer/lasty POK2
77
+
78
+	.Mouse/state DEI .pointer/state POK
79
+
80
+BRK
81
+
39 82
 @draw-cursor ( -- )
40 83
 	
41 84
 	( clear last cursor )
... ...
@@ -59,5 +102,30 @@ BRK
59 102
 
60 103
 RTN
61 104
 
105
+@hairline ( x1 y1 x2 y2 color -- )
106
+	
107
+	( load ) .color POK .line/y0 POK2 .line/x0 POK2 .line/y POK2 .line/x POK2
108
+	.line/x0 PEK2 .line/x PEK2 SUB2 ABS2 .line/dx POK2
109
+	.line/y0 PEK2 .line/y PEK2 SUB2 ABS2 #0000 SWP2 SUB2 .line/dy POK2
110
+	#ffff #00 .line/x PEK2 .line/x0 PEK2 LTS2 #0002 MUL2 ADD2 .line/sx POK2 
111
+	#ffff #00 .line/y PEK2 .line/y0 PEK2 LTS2 #0002 MUL2 ADD2 .line/sy POK2 
112
+	.line/dx PEK2 .line/dy PEK2 ADD2 .line/e1 POK2
113
+	&loop
114
+		.line/x PEK2 .Screen/x DEO2 .line/y PEK2 .Screen/y DEO2 .color PEK .Screen/color DEO
115
+		.line/x PEK2 .line/x0 PEK2 EQU2 .line/y PEK2 .line/y0 PEK2 EQU2 #0101 EQU2 ,&end JNZ
116
+		.line/e1 PEK2 #0002 MUL2 .line/e2 POK2
117
+		.line/e2 PEK2 .line/dy PEK2 LTS2 ,&skipy JNZ
118
+			.line/e1 PEK2 .line/dy PEK2 ADD2 .line/e1 POK2
119
+			.line/x PEK2 .line/sx PEK2 ADD2 .line/x POK2
120
+		&skipy
121
+		.line/e2 PEK2 .line/dx PEK2 GTS2 ,&skipx JNZ
122
+			.line/e1 PEK2 .line/dx PEK2 ADD2 .line/e1 POK2
123
+			.line/y PEK2 .line/sy PEK2 ADD2 .line/y POK2
124
+		&skipx
125
+		,&loop JMP
126
+	&end
127
+
128
+RTN
129
+
62 130
 @clear   [ 0000 0000 0000 0000 ]
63 131
 @cursor  [ 80c0 e0f0 f8e0 1000 ]