-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathpowder-sim.arm
More file actions
361 lines (315 loc) · 9.84 KB
/
powder-sim.arm
File metadata and controls
361 lines (315 loc) · 9.84 KB
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#AS
///////////////
// Variables //
///////////////
define $expLoc0 = 53500
define $expLoc1 = 53501
define $expLoc2 = 53502
define $pixOffset = 53871 // Beginning of video memory
define $charOffset = *[1]$0pos // Beginning of character memory
define $CursorMoveSpeed = 10000
define $cursorCount = 0
define $cursorX = 54
define $cursorY = 54
define $drawSpeed = 10000
define $drawCount = 0
define $drawType = 1 // 0 = nothing, 1 = sand, 2 = water
define $waterColor = 3484
define $sandColor = 0b110111011101110
change *[1]$expLoc0 = 168
change $lastKey = 168
define $bufferALoc = 20000
define $bufferBLoc = 31664
change $0pos = 53546
change $1pos = 53547
change $2pos = 53548
change $3pos = 53549
change $4pos = 53550
#Start
// Set default UI
change *[1]$0pos = 's'
change *[1]$1pos = 'a'
change *[1]$2pos = 'n'
change *[1]$3pos = 'd'
change *[1]$4pos = 0
#MainLoop
if $drawCount==$drawSpeed:
// Process all of the pixels to calculate their next position
change $copyOffset = 0
#Processor
add $bufferALoc,$copyOffset -> $loc1
add $bufferBLoc,$copyOffset -> $loc2
change $currentPixel = *[0]$loc1
if $currentPixel==0: // Only process pixels with something in them
add 1,$copyOffset -> $copyOffset
goto #Processor
endif
if $loc1>31556: // Only process pixels that aren't in the bottom layer
goto #EndofProcessLoop
endif
// Handle sand type
if $currentPixel==$sandColor:
// Calculate next position
add $loc1,108 -> $loc1
change $pixelVal1 = *[0]$loc1
if $pixelVal1==0: // If the pixel below this one is empty
change *[0]$loc2 = 0
add $bufferBLoc,$copyOffset -> $loc2
add $loc2,108 -> $loc2
change *[0]$loc2 = $currentPixel
endif
if $pixelVal1==$waterColor: // If the pixel below this one is water, then fall through it
change *[0]$loc2 = $waterColor
add $bufferBLoc,$copyOffset -> $loc2
add $loc2,108 -> $loc2
change *[0]$loc2 = $currentPixel
endif
if $pixelVal1!=0: // If the pixel below this one is full
// Check if bottom-left pixel is empty
sub $loc1,1 -> $loc1
if *[0]$loc1==0:
change *[0]$loc2 = 0
add $bufferBLoc,$copyOffset -> $loc2
add $loc2,107 -> $loc2
change *[0]$loc2 = $currentPixel
goto #EndofProcessLoop
endif
// Check if bottom-right pixel is empty
add $loc1,2 -> $loc1
if *[0]$loc1==0:
change *[0]$loc2 = 0
add $bufferBLoc,$copyOffset -> $loc2
add $loc2,109 -> $loc2
change *[0]$loc2 = $currentPixel
goto #EndofProcessLoop
endif
endif
endif
// Handle water type
if $currentPixel==$waterColor:
// Calculate next position
add $loc1,108 -> $loc1
change $pixelVal1 = *[0]$loc1
if $pixelVal1==0: // If the pixel below this one is empty
change *[0]$loc2 = 0
add $bufferBLoc,$copyOffset -> $loc2
add $loc2,108 -> $loc2
change *[0]$loc2 = $currentPixel
endif
if $pixelVal1!=0: // If the pixel below this one is full
// Check if bottom-left pixel is empty
sub $loc1,1 -> $loc1
if *[0]$loc1==0:
change *[0]$loc2 = 0
add $bufferBLoc,$copyOffset -> $loc2
add $loc2,107 -> $loc2
change *[0]$loc2 = $currentPixel
goto #EndofProcessLoop
endif
// Check if bottom-right pixel is empty
add $loc1,2 -> $loc1
if *[0]$loc1==0:
change *[0]$loc2 = 0
add $bufferBLoc,$copyOffset -> $loc2
add $loc2,109 -> $loc2
change *[0]$loc2 = $currentPixel
goto #EndofProcessLoop
endif
// Check if right pixel is empty
sub $loc1,108 -> $loc1
if *[0]$loc1==0:
add $loc2,1 -> $loc2
if *[0]$loc2==0:
add $bufferBLoc,$copyOffset -> $loc2
change *[0]$loc2 = 0
add $loc2,1 -> $loc2
change *[0]$loc2 = $currentPixel
endif
goto #EndofProcessLoop
endif
// Check if left pixel is empty
sub $loc1,2 -> $loc1
if *[0]$loc1==0:
sub $loc2,1 -> $loc2
if *[0]$loc2==0:
add $bufferBLoc,$copyOffset -> $loc2
change *[0]$loc2 = 0
sub $loc2,1 -> $loc2
change *[0]$loc2 = $currentPixel
endif
goto #EndofProcessLoop
endif
endif
endif
#EndofProcessLoop
add 1,$copyOffset -> $copyOffset
gotoif $copyOffset<11664, #Processor
// Copies everything from buffer B into buffer A
change $copyOffset = 0
#Copier
add $bufferALoc,$copyOffset -> $loc1
add $bufferBLoc,$copyOffset -> $loc2
change *[0]$loc1 = *[0]$loc2
add $pixOffset,$copyOffset -> $pixLoc
change *[1]$pixLoc = *[0]$loc2
add 1,$copyOffset -> $copyOffset
gotoif $copyOffset<11664, #Copier
// ///////////////////////
// // Draw cursor color //
// ///////////////////////
// // Get center pixel
// mult $cursorY,108 -> $temp
// add $cursorX,$temp -> $temp
// change $bufCoord = $temp
// add $pixOffset,$temp -> $temp
// // Left crosshair
// sub $temp,2 -> $temp
// change *[1]$temp = 65535
// sub $temp,1 -> $temp
// change *[1]$temp = 65535
// // Right crosshair
// add $temp,5 -> $temp
// change *[1]$temp = 65535
// add $temp,1 -> $temp
// change *[1]$temp = 65535
// // Top crosshair
// sub $temp,3 -> $temp
// sub $temp,216 -> $temp
// change *[1]$temp = 65535
// sub $temp,108 -> $temp
// change *[1]$temp = 65535
// // Bottom crosshair
// add $temp,540 -> $temp
// change *[1]$temp = 65535
// add $temp,108 -> $temp
// change *[1]$temp = 65535
change $drawCount = 0
endif
if $CursorMoveSpeed==$cursorCount:
// ////////////////////////
// // Clear cursor color //
// ////////////////////////
// // Get center pixel
// mult $cursorY,108 -> $temp
// add $cursorX,$temp -> $temp
// add $pixOffset,$temp -> $temp
// // Left crosshair
// sub $temp,2 -> $temp
// change *[1]$temp = 0
// sub $temp,1 -> $temp
// change *[1]$temp = 0
// // Right crosshair
// add $temp,5 -> $temp
// change *[1]$temp = 0
// add $temp,1 -> $temp
// change *[1]$temp = 0
// // Top crosshair
// sub $temp,3 -> $temp
// sub $temp,216 -> $temp
// change *[1]$temp = 0
// sub $temp,108 -> $temp
// change *[1]$temp = 0
// // Bottom crosshair
// add $temp,540 -> $temp
// change *[1]$temp = 0
// add $temp,108 -> $temp
// change *[1]$temp = 0
change $keypress = *[1]$expLoc0
change $mousePos = *[1]$expLoc1
and $mousePos,0b1111111 -> $newYPos
bsr $mousePos,7 -> $newXPos
and $newXPos,0b1111111 -> $newXPos
if $newYPos>3:
if $newYPos<104:
change $cursorY = $newYPos
endif
endif
if $newXPos>3:
if $newXPos<104:
change $cursorX = $newXPos
endif
endif
if $keypress=='o':
if $keypress!=$lastKey:
add $drawType,1 -> $drawType
if $drawType==3:
change $drawType = 0
endif
if $drawType==0:
change *[1]$0pos = 'n'
change *[1]$1pos = 'o'
change *[1]$2pos = 'n'
change *[1]$3pos = 'e'
change *[1]$4pos = 0
endif
if $drawType==1:
change *[1]$0pos = 's'
change *[1]$1pos = 'a'
change *[1]$2pos = 'n'
change *[1]$3pos = 'd'
change *[1]$4pos = 0
endif
if $drawType==2:
change *[1]$0pos = 'w'
change *[1]$1pos = 'a'
change *[1]$2pos = 't'
change *[1]$3pos = 'e'
change *[1]$4pos = 'r'
endif
endif
endif
#ExitIf
if $keypress!=$lastKey:
change $lastKey = $keypress
endif
///////////////////////
// Draw cursor color //
///////////////////////
// Get center pixel
mult $cursorY,108 -> $temp
add $cursorX,$temp -> $temp
change $bufCoord = $temp
add $pixOffset,$temp -> $temp
// If the left mouse button is pressed down
if $mousePos>=16384:
// Draw the correct particle
if $drawType==0:
add $bufferALoc,$bufCoord -> $bufCoord
change *[0]$bufCoord = 0
endif
if $drawType==1:
add $bufferALoc,$bufCoord -> $bufCoord
change *[0]$bufCoord = $sandColor
endif
if $drawType==2:
add $bufferALoc,$bufCoord -> $bufCoord
change *[0]$bufCoord = $waterColor
endif
endif
// Left crosshair
sub $temp,2 -> $temp
change *[1]$temp = 65535
sub $temp,1 -> $temp
change *[1]$temp = 65535
// Right crosshair
add $temp,5 -> $temp
change *[1]$temp = 65535
add $temp,1 -> $temp
change *[1]$temp = 65535
// Top crosshair
sub $temp,3 -> $temp
sub $temp,216 -> $temp
change *[1]$temp = 65535
sub $temp,108 -> $temp
change *[1]$temp = 65535
// Bottom crosshair
add $temp,540 -> $temp
change *[1]$temp = 65535
add $temp,108 -> $temp
change *[1]$temp = 65535
change $cursorCount = 0
endif
#EndOfMainLoop
add 1,$cursorCount -> $cursorCount
add 1,$drawCount -> $drawCount
goto #MainLoop