-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathfire.mfk
123 lines (112 loc) · 2.43 KB
/
fire.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
import random
array reverse_palette[256] align(256)
#if CBM
const byte COLUMN_COUNT = 40
const byte ROW_COUNT = 25
array palette align(fast) = [black, red, orange, yellow, white]
void cls() {
byte i
for i,0,paralleluntil,250 {
screen[000+i] = 160
screen[250+i] = 160
screen[500+i] = 160
screen[750+i] = 160
}
for i,0,paralleluntil,250 {
colors[000+i] = black
colors[250+i] = black
colors[500+i] = black
colors[750+i] = black
}
}
#endif
#if CBM_64
array colors[1000] @$d800
array screen[1000] @$400
#elseif CBM_264
array colors[1000] @$800
array screen[1000] @$c00
#endif
#if ZX_SPECTRUM
#pragma zilog_syntax
array palette align(fast) = [black*9, red*9, red*9+$40, yellow*9+$40, white*9+$40]
array colors[$300] @$5800
const byte COLUMN_COUNT = 32
const byte ROW_COUNT = 24
void cls() {
pointer p
for p,$4000,paralleluntil,$5800 {
p[0] = $f7
}
for p,$5800,paralleluntil,$5b00 {
p[0] = black*9
}
}
#endif
void build_reverse_palette () {
byte i
#if CBM_64
byte j
for i,0,paralleluntil,palette.length {
for j,0,parallelto,$f {
reverse_palette[palette[i] | (j<<4)] = i
}
}
#else
for i,0,paralleluntil,palette.length {
reverse_palette[palette[i]] = i
}
#endif
}
void main() {
set_border(black)
init_rand_seed()
build_reverse_palette()
cls()
byte i
const word LAST_ROW_START = COLUMN_COUNT * word(ROW_COUNT-1)
for i,0,paralleluntil,COLUMN_COUNT {
colors[LAST_ROW_START+i] = palette[palette.length - 1]
}
while true {
wait_frame()
fire()
}
}
void wait_frame() {
#if CBM_64
while vic_raster != $ff {}
#elseif CBM_264
while ted_raster_y != $ff {}
#elseif ZX_SPECTRUM
asm { halt }
#else
// TODO
#endif
}
void fire() {
byte noise
byte row
byte column
pointer p
byte heat
byte entropy
entropy = 0
p = colors.addr
for row,0,paralleluntil,ROW_COUNT-1 {
for column,0,paralleluntil,COLUMN_COUNT {
if entropy == 0 {
noise = rand()
entropy = 8
}
heat = reverse_palette[p[column+COLUMN_COUNT]]
if noise & 1 != 0 {
if heat != 0 { heat -= 1 }
}
noise >>= 1
entropy -= 1
p[column] = palette[heat]
}
p += COLUMN_COUNT
}
}