-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconways.txt
220 lines (185 loc) · 2.85 KB
/
conways.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
JSR restartpixelpointer
initloopstart:
LDA $fe ; Load random number into register A
CMP #$30 ; The higher this number, the more life there is
BCS loadblack ; White being life
;loadwhite:
LDA #$01
JMP storecolor
loadblack:
LDA #$00
JMP storecolor
storecolor:
LDY #0
STA ($00),Y ;Store color in referred address
INC $00 ; Move to next pixel
BNE initloopstart ; If zero flag set, continue
INC $01 ; increment most significant byte
LDA #$06
CMP $01 ;If this is equal, we're out of bounds
BNE initloopstart
; Initialisation ends here
JSR restartpixelpointers
generatepixels:
JSR copycurrentpixellocation
JSR generatenextstep
INC $00 ; Move to next pixel
BNE generatepixels ; If zero flag set, continue
INC $01 ; increment most significant byte
LDA #$06
CMP $01 ;If this is equal, we're out of bounds
BNE generatepixels
JMP redisplay
generatenextstep:
JSR checkpixel
CPX #$04
BCC checkovercrowd
JMP clearpixel
checkovercrowd:
CPX #$02
BEQ keepalive
BCS checkequal3
JMP clearpixel
keepalive: ;if alive, keep alive
LDY #0
LDA ($00),Y
BEQ clearpixel
JMP setpixel
checkequal3: ;if we have 3 neighbours, we're alive
CPX #$03
BEQ setpixel
JMP clearpixel
clearpixel:
LDA $01
ORA #$F0
STA $01
LDA #$00
STA ($00), Y
LDA $01
EOR #$F0
STA $01
LDA #$00
RTS
setpixel:
LDA $01
ORA #$F0
STA $01
LDA #$01
STA ($00), Y
LDA $01
EOR #$F0
STA $01
LDA #$00
RTS
checkpixel:
LDX #0
JSR left
JSR up
JSR right
JSR right
JSR down
JSR down
JSR left
JSR left
RTS
left:
DEC $02
LDA $02
AND #$1f
CMP #$1f
BNE checkforpixel
; Need to add #$10 to get in the right row
LDA $02
CLC
ADC #$20
STA $02
JMP checkforpixel
up:
LDA $02
SEC
SBC #$20
STA $02
BCS checkforpixel
DEC $03
LDA #$01
CMP $03
BNE checkforpixel
; If significant byte is 3, we need to wraparound
LDA #$05
STA $03
JMP checkforpixel
right:
INC $02
LDA #$1f
BIT $02
BNE checkforpixel
; Need to add #$10 to get in the right row
LDA $02
SEC
SBC #$20
STA $02
JMP checkforpixel
down:
LDA $02
CLC
ADC #$20
STA $02
BCC checkforpixel
INC $03
LDA #$06
CMP $03
BNE checkforpixel
; If significant byte is 6, we need to wraparound
LDA #$02
STA $03
JMP checkforpixel
;-------------
checkforpixel:
LDY #0
LDA ($02),Y
BNE incrementandreturn ; If #$01, increment life counter
RTS
incrementandreturn:
INX
RTS
;SUBROUTINES
restartpixelpointers:
LDX #$02
STX $01
LDX #$00
STX $00
RTS
redisplay:
JSR restartpixelpointers
LDA $00
STA $02
LDA $01
ORA #$F0
STA $03
transferpixel:
LDY #0
LDA ($02),Y
STA ($00),Y
INC $02
INC $00 ; Move to next pixel
BNE transferpixel ; If zero flag set, continue
INC $03
INC $01 ; increment most significant byte
LDA #$06
CMP $01 ;If this is equal, we're out of bounds
BNE transferpixel
JSR restartpixelpointer
JMP generatepixels
copycurrentpixellocation:
LDA $00
STA $02
LDA $01
STA $03
RTS
restartpixelpointer:
; $00-$01 -> Pointer to current pixel on display
LDX #$02
STX $01
LDX #$00
STX $00;X stores least significant pixel address byte
RTS