Browse code

Improved the keys example top reflect mods

neauoire authored on 25/06/2021 15:36:33
Showing 1 changed files
... ...
@@ -1,15 +1,31 @@
1 1
 ( dev/controller/keys )
2 2
 
3
+%+  { ADD } %-   { SUB }  %*  { MUL }  %/  { DIV }
4
+%<  { LTH } %>   { GTH }  %=  { EQU }  %!  { NEQ }
5
+%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 }
6
+%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }
7
+
3 8
 %RTN { JMP2r }
4
-%8+  { #0008 ADD2 }
5
-%8*  { #30 SFT2 }
9
+%TOS { #00 SWP }
10
+
11
+%DEBUG  { .Console/byte DEO #0a .Console/char DEO }
12
+%DEBUG2 { .Console/short DEO2 #0a .Console/char DEO }
6 13
 
7 14
 ( devices )
8 15
 
9 16
 |00 @System     [ &vector $2 &pad    $6 &r      $2 &g     $2 &b      $2 ]
17
+|10 @Console    &vector $2 &pad      $6 &char   $1 &byte  $1 &short  $2 &string $2 ]
10 18
 |20 @Screen     [ &vector $2 &width  $2 &height $2 &pad   $2 &x      $2 &y $2 &addr $2 &color $1 ]
11 19
 |80 @Controller [ &vector $2 &button $1 &key    $1 ]
12 20
 
21
+( variables )
22
+
23
+|0000
24
+
25
+@position
26
+	&x $2
27
+	&y $2
28
+
13 29
 ( init )
14 30
 
15 31
 |0100 ( -> )
... ...
@@ -26,33 +42,70 @@
26 42
 BRK
27 43
 
28 44
 @on-button ( -> )
29
-	
45
+
30 46
 	( skip ) .Controller/key DEI #01 JCN [ BRK ] 
31 47
 
48
+	( print button-key code )
49
+	#0000 .Screen/x DEO2
50
+	.Screen/height DEI2 #0008 -- .Screen/y DEO2
51
+	.Controller/button DEI2 #21 ;draw-short JSR2
52
+
53
+	.position/x LDZ2 .Screen/x DEO2
54
+	.position/y LDZ2 .Screen/y DEO2
55
+
56
+	( linebreak )
32 57
 	.Controller/key DEI #0d NEQ ,&no-return JCN 
33 58
 		( draw ) #20 .Screen/color DEO
34
-		( reset ) #0000 .Screen/x DEO2
35
-		( incr ) .Screen/y DEI2 8+ .Screen/y DEO2
59
+		( reset ) #0000 .position/x STZ2
60
+		( incr ) .position/y LDZ2 #0008 ++ .position/y STZ2
36 61
 		;draw-cursor JSR2
37 62
 		BRK
38 63
 	&no-return
39 64
 
40
-	;font #00 .Controller/key DEI 8* ADD2 .Screen/addr DEO2
41
-	( draw ) #21 .Screen/color DEO
42
-	( incr ) .Screen/x DEI2 8+ .Screen/x DEO2
43
-	
44
-	;draw-cursor JSR2
65
+	;font #00 .Controller/key DEI #0008 ** ++ .Screen/addr DEO2
66
+	.Controller/button DEI ;mod-color JSR2 .Screen/color DEO
67
+	( incr ) .position/x LDZ2 #0008 ++ .position/x STZ2
68
+	,draw-cursor JSR
45 69
 
46 70
 BRK
47 71
 
72
+@mod-color ( mod -- color )
73
+	 
74
+	( ctrl )  DUP #01 = #01 * STH
75
+	( alt )   DUP #02 = #03 * STH
76
+	( shift ) #04 = #0e * STH2r + +
77
+	#21 + 
78
+
79
+RTN
80
+
48 81
 @draw-cursor ( -- )
49 82
 	
83
+	.position/x LDZ2 .Screen/x DEO2
84
+	.position/y LDZ2 .Screen/y DEO2
50 85
 	;cursor .Screen/addr DEO2 
51 86
 	#22 .Screen/color DEO
52 87
 
53 88
 RTN
54 89
 
55
-@cursor [ ffff ffff ffff ffff ]
90
+@draw-short ( short* color -- )
91
+
92
+	STH SWP 
93
+	DUP #04 SFT TOS #0008 ** ;font-hex ++ .Screen/addr DEO2
94
+	( draw ) STHkr .Screen/color DEO
95
+	#0f AND TOS #0008 ** ;font-hex ++ .Screen/addr DEO2
96
+	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
97
+	( draw ) STHkr .Screen/color DEO
98
+	DUP #04 SFT TOS #0008 ** ;font-hex ++ .Screen/addr DEO2
99
+	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
100
+	( draw ) STHkr .Screen/color DEO
101
+	#0f AND TOS #0008 ** ;font-hex ++ .Screen/addr DEO2
102
+	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
103
+	( draw ) STHr .Screen/color DEO
104
+
105
+RTN
106
+
107
+@cursor 
108
+	ffff ffff ffff ffff
56 109
 
57 110
 @font ( spectrum-zx font ) 
58 111
 	0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000
... ...
@@ -87,3 +140,13 @@ RTN
87 140
 	0010 103c 1010 0c00 0000 4444 4444 3800 0000 4444 2828 1000 0000 4454 5454 2800
88 141
 	0000 4428 1028 4400 0000 4444 443c 0438 0000 7c08 1020 7c00 000c 0810 1008 0c00
89 142
 	0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c
143
+
144
+@font-hex 
145
+	003c 464a 5262 3c00 0018 0808 0808 1c00
146
+	003c 4202 3c40 7e00 003c 421c 0242 3c00
147
+	000c 1424 447e 0400 007e 407c 0242 3c00
148
+	003c 407c 4242 3c00 007e 0204 0810 1000
149
+	003c 423c 4242 3c00 003c 4242 3e02 3c00
150
+	003c 4242 7e42 4200 007c 427c 4242 7c00
151
+	003c 4240 4042 3c00 007c 4242 4242 7c00
152
+	007e 4078 4040 7e00 007e 4078 4040 4000 
90 153
\ No newline at end of file