forked from KarolS/millfork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlife.mfk
208 lines (185 loc) · 3.95 KB
/
life.mfk
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
#if CBM_64 || CBM_264
const byte width = 40
const byte height = 25
#endif
#if ZX_SPECTRUM
const byte width = 32
const byte height = 24
#endif
#if ATARI_8
const byte width = 40
const byte height = 24
#endif
const word area = word(width) * word(height)
// representation: $1 live now $80 live soon
const byte ALIVE = $81
const byte DEAD = 0
array buffer [width * height] align(256)
void init_buffer() {
pointer p
for p,buffer.addr,paralleluntil,buffer.addr+area {
p[0] = DEAD
}
// glider:
buffer[1*width + 2] = ALIVE
buffer[2*width + 3] = ALIVE
buffer[3*width + 1] = ALIVE
buffer[3*width + 2] = ALIVE
buffer[3*width + 3] = ALIVE
}
void do_round() align(fast) {
byte x, y, sum, j
pointer p
p = buffer.addr - width - 1
for y,0,until,height {
for x,0,until,width {
sum = 0
if y != 0 {
if x != 0 { sum += p[0] }
sum += p[1]
if x != width - 1 { sum += p[2] }
}
if true {
if x != 0 { sum += p[width] }
if x != width - 1 { sum += p[width + 2] }
}
if y != height - 1 {
if x != 0 { sum += p[2 * width] }
sum += p[2 * width + 1]
if x != width - 1 { sum += p[2 * width + 2] }
}
sum &= $7f
if sum == 3 {
p[width + 1] |= $80
} else if sum != 2 {
p[width + 1] &= $7f
}
p += 1
}
}
p = buffer.addr
for j,0,paralleluntil,height {
for x,0,paralleluntil,width {
if p[x] & $80 != 0 { p[x] = ALIVE }
else { p[x] = DEAD }
}
p += width
}
}
#if CBM_64
void init_gfx() {
byte i
for i,0,paralleluntil,250 {
c64_color_ram[i+000]=light_blue
c64_color_ram[i+250]=light_blue
c64_color_ram[i+500]=light_blue
c64_color_ram[i+750]=light_blue
}
}
void redraw() align(fast) {
pointer src, dest
byte x, y
src = buffer.addr
dest = $400
for y,0,until,height {
for x,0,until,width {
if src[x] != 0 {
dest[x] = 128 + ' '
} else {
dest[x] = ' '
}
}
src += width
dest += width
}
}
void wait_frame() align(fast) {
while vic_raster != $ff {}
while vic_raster == $ff {}
}
#endif
#if CBM_264
void init_gfx() {
}
void redraw() align(fast) {
pointer src, dest
byte x, y
src = buffer.addr
dest = $c00
for y,0,until,height {
for x,0,until,width {
if src[x] != 0 {
dest[x] = 128 + ' '
} else {
dest[x] = ' '
}
}
src += width
dest += width
}
}
void wait_frame() align(fast) {
while ted_raster_y != $ff {}
while ted_raster_y == $ff {}
}
#endif
#if ATARI_8
pointer screen_start @$58
byte clock @$14
void init_gfx() {
}
void redraw() align(fast) {
pointer src, dest
byte x, y
src = buffer.addr
dest = screen_start
for y,0,until,height {
for x,0,until,width {
if src[x] != 0 {
dest[x] = 128 + ' 'scr
} else {
dest[x] = ' 'scr
}
}
src += width
dest += width
}
}
void wait_frame() align(fast) {
while clock != clock {}
}
#endif
#if ZX_SPECTRUM
void init_gfx() {
}
void redraw() align(fast) {
pointer src, dest
byte x, y
src = buffer.addr
dest = $5800
for y,0,until,height {
for x,0,until,width {
if src[x] != 0 {
dest[x] = 0
} else {
dest[x] = $3f
}
}
src += width
dest += width
}
}
asm macro void wait_frame() {
halt
}
#endif
void main() {
init_gfx()
init_buffer()
redraw()
while true {
wait_frame()
do_round()
redraw()
}
}