Browse code

Added cell count to GOL

neauoire authored on 06/05/2021 17:38:38
Showing 6 changed files
... ...
@@ -145,7 +145,7 @@ RTN
145 145
 @draw-cursor ( -- )
146 146
 	
147 147
 	( clear last cursor )
148
-	#fff8 .Screen/addr DEO2 
148
+	;cursor .Screen/addr DEO2 
149 149
 	.pointer/x PEK2 .Screen/x DEO2 
150 150
 	.pointer/y PEK2 .Screen/y DEO2 
151 151
 	#30 .Screen/color DEO
... ...
@@ -153,7 +153,6 @@ RTN
153 153
 	.Mouse/x DEI2 .pointer/x POK2 
154 154
 	.Mouse/y DEI2 .pointer/y POK2
155 155
 	( draw new cursor )
156
-	;cursor .Screen/addr DEO2 
157 156
 	.pointer/x PEK2 .Screen/x DEO2 
158 157
 	.pointer/y PEK2 .Screen/y DEO2 
159 158
 	( colorize on state )
... ...
@@ -503,7 +503,7 @@ RTN
503 503
 @draw-cursor ( -- )
504 504
 	
505 505
 	( clear last cursor )
506
-	#fff8 .Screen/addr DEO2 
506
+	;cursor-icn .Screen/addr DEO2 
507 507
 	.pointer/x PEK2 .Screen/x DEO2 
508 508
 	.pointer/y PEK2 .Screen/y DEO2 
509 509
 	#30 .Screen/color DEO
... ...
@@ -511,7 +511,6 @@ RTN
511 511
 	.Mouse/x DEI2 .pointer/x POK2 
512 512
 	.Mouse/y DEI2 .pointer/y POK2
513 513
 	( draw new cursor )
514
-	;cursor-icn .Screen/addr DEO2 
515 514
 	.pointer/x PEK2 .Screen/x DEO2 
516 515
 	.pointer/y PEK2 .Screen/y DEO2 
517 516
 	( colorize on state )
... ...
@@ -1,21 +1,20 @@
1
-( game of life
1
+( Game Of Life
2 2
 	Any live cell with fewer than two live neighbours dies, as if by underpopulation.
3
-    Any live cell with two or three live neighbours lives on to the next generation.
4
-    Any live cell with more than three live neighbours dies, as if by overpopulation.
5
-    Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. )
3
+	Any live cell with two or three live neighbours lives on to the next generation.
4
+	Any live cell with more than three live neighbours dies, as if by overpopulation.
5
+	Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. )
6 6
 
7 7
 %+  { ADD } %-   { SUB }  %*  { MUL } %/   { DIV }  
8 8
 %<  { LTH } %>   { GTH }  %=  { EQU } %!   { NEQ } 
9 9
 %++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 } 
10 10
 %<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }  
11 11
 
12
-%INCR { #01 + }  %DECR { #01 - }
13
-%TOS { #00 SWP } %TOB { SWP POP }
14
-%RTN { JMP2r }
15
-%MOD { DUP2 / * - }
16
-%SFL { #40 SFT SFT }
12
+%INCR { #01 + }   %DECR { #01 - }
13
+%TOS  { #00 SWP } %TOB  { SWP POP }
14
+%RTN  { JMP2r }   %MOD  { DUP2 / * - }
15
+%SFL  { #40 SFT SFT }
17 16
 
18
-%WIDTH { #40 } %HEIGHT { #40 }
17
+%WIDTH { #40 }   %HEIGHT { #40 }
19 18
 %BANK1 { #8000 } %BANK2 { #a000 }
20 19
 
21 20
 %GET-SIZE { WIDTH TOS #0008 // HEIGHT TOS ** }
... ...
@@ -24,14 +23,15 @@
24 23
 
25 24
 |00 @System     [ &vector $2 &wst      $1 &rst    $1 &pad   $4 &r      $2 &g     $2 &b      $2 ]
26 25
 |20 @Screen     [ &vector $2 &width    $2 &height $2 &pad   $2 &x      $2 &y      $2 &addr  $2 &color $1 ]
26
+|80 @Controller [ &vector $2 &button   $1 &key    $1 ]
27 27
 |90 @Mouse      [ &vector $2 &x        $2 &y      $2 &state $1 &chord $1 ]
28 28
 
29 29
 ( variables )
30 30
 
31 31
 |0000
32 32
 
33
-@timer $1
34
-@anchor [ &x $2 &y $2 ]
33
+@world   [ &paused $1 &frame $1 &count $2 ]
34
+@anchor  [ &x $2 &y $2 ]
35 35
 @pointer [ &x $2 &y $2 ]
36 36
 
37 37
 ( program )
... ...
@@ -39,13 +39,14 @@
39 39
 |0100 ( -> )
40 40
 
41 41
 	( theme ) 
42
-	#ef05 .System/r DEO2 
43
-	#cf05 .System/g DEO2 
44
-	#2f05 .System/b DEO2
42
+	#02fe .System/r DEO2 
43
+	#02fc .System/g DEO2 
44
+	#02f2 .System/b DEO2
45 45
 
46 46
 	( vectors )
47 47
 	;on-frame   .Screen/vector DEO2
48 48
 	;on-mouse   .Mouse/vector DEO2
49
+	;on-control .Controller/vector DEO2
49 50
 
50 51
 	( glider )
51 52
 	#07 #03 ;set-cell JSR2
... ...
@@ -57,13 +58,17 @@
57 58
 	.Screen/width DEI2 #0002 // WIDTH TOS -- .anchor/x POK2
58 59
 	.Screen/height DEI2 #0002 // HEIGHT TOS -- .anchor/y POK2
59 60
 
61
+	#01 .world/paused POK
62
+
60 63
 BRK
61 64
 
62 65
 @on-frame ( -> )
63 66
 	
64 67
 	.Mouse/state DEI #00 = #01 JNZ [ BRK ]
68
+	.world/paused PEK #00 ! #01 JNZ [ BRK ]
65 69
 
66
-	.timer PEK #01 + [ DUP ] .timer POK
70
+	( incr frame ) .world/frame PEK INCR [ DUP ] .world/frame POK
71
+	( reset count ) #0000 .world/count POK2
67 72
 
68 73
 	#10 MOD #00 ! #01 JNZ [ BRK ] 
69 74
 
... ...
@@ -88,12 +93,17 @@ BRK
88 93
 
89 94
 	;draw-grid JSR2
90 95
 
96
+	( draw cell count )
97
+	.anchor/x PEK2 .Screen/x DEO2
98
+	.anchor/y PEK2 HEIGHT #02 * TOS ++ .Screen/y DEO2
99
+	.world/count PEK2 #22 ;draw-short JSR2
100
+
91 101
 BRK
92 102
 
93 103
 @on-mouse ( -> )
94 104
 	
95 105
 	( clear last cursor )
96
-	#fff8 .Screen/addr DEO2 
106
+	;cursor .Screen/addr DEO2 
97 107
 	.pointer/x PEK2 .Screen/x DEO2 
98 108
 	.pointer/y PEK2 .Screen/y DEO2 
99 109
 	#30 .Screen/color DEO
... ...
@@ -103,7 +113,6 @@ BRK
103 113
 	.Mouse/y DEI2 .pointer/y POK2
104 114
 
105 115
 	( draw new cursor )
106
-	;cursor .Screen/addr DEO2 
107 116
 	.pointer/x PEK2 .Screen/x DEO2 
108 117
 	.pointer/y PEK2 .Screen/y DEO2 
109 118
 
... ...
@@ -124,6 +133,16 @@ BRK
124 133
 
125 134
 BRK
126 135
 
136
+@on-control ( -> )
137
+
138
+	.Controller/key DEI #00 ! #01 JNZ [ BRK ]
139
+
140
+	.Controller/key DEI #20 ! ,&no-toggle JNZ
141
+		.world/paused PEK #01 ! .world/paused POK
142
+	&no-toggle
143
+
144
+BRK
145
+
127 146
 @draw-grid ( -- )
128 147
 
129 148
 	#00 HEIGHT
... ...
@@ -133,11 +152,11 @@ BRK
133 152
 		#00 WIDTH
134 153
 		&hor
135 154
 			OVR TOS #0002 ** .anchor/x PEK2 ++ .Screen/x DEO2
136
-			OVR DUPr STHr ,get-cell JSR #01 + .Screen/color DEO
137
-			SWP #01 + SWP
155
+			OVR DUPr STHr ,get-cell JSR INCR .Screen/color DEO
156
+			SWP INCR SWP
138 157
 			DUP2 ! ,&hor JNZ
139 158
 		POP2 POPr
140
-		SWP #01 + SWP
159
+		SWP INCR SWP
141 160
 		DUP2 ! ,&ver JNZ
142 161
 	POP2
143 162
 
... ...
@@ -194,10 +213,10 @@ RTN
194 213
 			( neighbours ) DUP2r STH2r ,get-neighbours JSR
195 214
 			( state ) STH2r ;get-cell JSR2
196 215
 			,run-cell JSR
197
-			SWP #01 + SWP
216
+			SWP INCR SWP
198 217
 			DUP2 ! ,&hor JNZ
199 218
 		POP2 POPr
200
-		SWP #01 + SWP
219
+		SWP INCR SWP
201 220
 		DUP2 ! ,&ver JNZ
202 221
 	POP2
203 222
 
... ...
@@ -222,6 +241,8 @@ RTN
222 241
 	( get index )
223 242
 	HEIGHT MOD SWP WIDTH MOD SWP
224 243
 	WIDTH #08 / TOS ROT TOS ** ROT #08 / TOS ++ [ BANK2 ++ ]
244
+	( incr count )
245
+	.world/count PEK2 #0001 ADD2 .world/count POK2
225 246
 	( save in buffer )
226 247
 	STH2
227 248
 	DUP2 POP #08 MOD #01 SWP SFL 
... ...
@@ -230,5 +251,33 @@ RTN
230 251
 
231 252
 RTN
232 253
 
254
+@draw-short ( short* color -- )
255
+
256
+	STH SWP 
257
+	DUP #04 SFT TOS #0008 ** ;font-hex ++ .Screen/addr DEO2
258
+	( draw ) DUPr STHr .Screen/color DEO
259
+	#0f AND TOS #0008 ** ;font-hex ++ .Screen/addr DEO2
260
+	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
261
+	( draw ) DUPr STHr .Screen/color DEO
262
+	DUP #04 SFT TOS #0008 ** ;font-hex ++ .Screen/addr DEO2
263
+	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
264
+	( draw ) DUPr STHr .Screen/color DEO
265
+	#0f AND TOS #0008 ** ;font-hex ++ .Screen/addr DEO2
266
+	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
267
+	( draw ) STHr .Screen/color DEO
268
+
269
+RTN
270
+
271
+@font-hex ( 0-F )
272
+[
273
+	007c 8282 8282 827c 0030 1010 1010 1010
274
+	007c 8202 7c80 80fe 007c 8202 1c02 827c
275
+	000c 1424 4484 fe04 00fe 8080 7c02 827c
276
+	007c 8280 fc82 827c 007c 8202 1e02 0202
277
+	007c 8282 7c82 827c 007c 8282 7e02 827c
278
+	007c 8202 7e82 827e 00fc 8282 fc82 82fc
279
+	007c 8280 8080 827c 00fc 8282 8282 82fc
280
+	007c 8280 f080 827c 007c 8280 f080 8080 ]
281
+
233 282
 @cursor [ 
234
-	80c0 e0f0 f8e0 1000 ]
235 283
\ No newline at end of file
284
+	80c0 e0f0 f8e0 1000 ]
... ...
@@ -256,7 +256,7 @@ RTN
256 256
 @draw-cursor ( -- )
257 257
 	
258 258
 	( clear last cursor )
259
-	#fff8 .Screen/addr DEO2 
259
+	;cursor .Screen/addr DEO2 
260 260
 	.pointer/x PEK2 .Screen/x DEO2 
261 261
 	.pointer/y PEK2 .Screen/y DEO2 
262 262
 	#30 .Screen/color DEO
... ...
@@ -264,7 +264,6 @@ RTN
264 264
 	.Mouse/x DEI2 .pointer/x POK2 
265 265
 	.Mouse/y DEI2 .pointer/y POK2
266 266
 	( draw new cursor )
267
-	;cursor .Screen/addr DEO2 
268 267
 	.pointer/x PEK2 .Screen/x DEO2 
269 268
 	.pointer/y PEK2 .Screen/y DEO2 
270 269
 	( colorize on state )
... ...
@@ -106,7 +106,7 @@ RTN
106 106
 @draw-cursor ( -- )
107 107
 	
108 108
 	( clear last cursor )
109
-	#fff8 .Screen/addr DEO2 
109
+	;cursor .Screen/addr DEO2 
110 110
 	.pointer/x PEK2 .Screen/x DEO2 
111 111
 	.pointer/y PEK2 .Screen/y DEO2 
112 112
 	#30 .Screen/color DEO
... ...
@@ -116,7 +116,6 @@ RTN
116 116
 	.Mouse/y DEI2 .pointer/y POK2
117 117
 
118 118
 	( draw new cursor )
119
-	;cursor .Screen/addr DEO2 
120 119
 	.pointer/x PEK2 .Screen/x DEO2 
121 120
 	.pointer/y PEK2 .Screen/y DEO2 
122 121
 
... ...
@@ -239,7 +239,7 @@ RTN
239 239
 @draw-cursor ( -- )
240 240
 	
241 241
 	( clear last cursor )
242
-	#fff8 .Screen/addr DEO2
242
+	;pointer_icn .Screen/addr DEO2
243 243
 	.pointer/x PEK2 .Screen/x DEO2
244 244
 	.pointer/y PEK2 .Screen/y DEO2
245 245
 	#30 .Screen/color DEO
... ...
@@ -249,7 +249,6 @@ RTN
249 249
 	.Mouse/y DEI2 .pointer/y POK2
250 250
 
251 251
 	( draw new cursor )
252
-	;pointer_icn .Screen/addr DEO2
253 252
 	.pointer/x PEK2 .Screen/x DEO2
254 253
 	.pointer/y PEK2 .Screen/y DEO2
255 254
 	#33 .Mouse/state DEI #00 NEQ #02 MUL SUB .Screen/color DEO