-
Notifications
You must be signed in to change notification settings - Fork 1
/
morph3d.asm
445 lines (367 loc) · 8.06 KB
/
morph3d.asm
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
; (C) May 1, 2001 M. Feliks
include sys.inc
include math3d.inc
MAX_POINTS equ 125
.model tiny
.code
.386
org 100h
entrypoint:
call do_startup
mov dx, 03c8h
xor ax, ax
out dx, al
inc dx
mov cx, 256
do_palette:
out dx, al
out dx, al
out dx, al
inc ah
mov al, ah
shr al, 2
dec cx
jnz do_palette
call make_random
mov si, offset model_object
mov di, offset current_object
mov cx, MAX_POINTS*3
cld
rep movsd
call make_circle
call clear_buffer
main_loop:
inc morph_counter
cmp morph_counter, 600
jb m_continue
mov morph_counter, 0
cmp morph_number, 0
je morph1
cmp morph_number, 1
je morph2
cmp morph_number, 2
je morph3
call make_circle
mov morph_number, 0
jmp m_continue
morph1:
call make_random
mov morph_number, 1
jmp m_continue
morph2:
call make_spiral
mov morph_number, 2
jmp m_continue
morph3:
call make_cube
mov morph_number, 3
m_continue:
call morph_object
mov si, offset current_object
mov di, offset rotated_object
mov cx, MAX_POINTS*3
cld
rep movsd
mov si, offset angle_x
mov di, offset rotated_object
mov cx, MAX_POINTS
call rotate_points_old
mov si, offset rotated_object
mov di, offset coord2d
mov cx, MAX_POINTS
call translate_points
fld angle_x
fadd inc_angle
fstp angle_x
fld angle_y
fadd inc_angle
fstp angle_y
fld angle_z
fadd inc_angle
fstp angle_z
push es
mov es, buffer_seg
mov si, offset coord2d
mov cx, MAX_POINTS
dp_loop:
mov bx, word ptr [si+2]
cmp bx, 0
jb dp_next
cmp bx, 198
ja dp_next
mov ax, word ptr [si]
cmp ax, 0
jb dp_next
cmp ax, 318
ja dp_next
mov di, bx
shl bx, 6
shl di, 8
add bx, di
add bx, ax
push bx
mov ax, bx
mov bx, MAX_POINTS
sub bx, cx
push bx
shl bx, 1
mov word ptr saved_offsets[bx], ax
pop bx
mov ax, bx
shl ax, 2
shl bx, 3
add bx, ax
fld dword ptr rotated_object[bx+8]
fadd dword ptr [color_add]
fmul dword ptr [color_scale]
fistp dword ptr [color_dump]
mov eax, 255
sub eax, dword ptr [color_dump]
cmp eax, 0
jge color_check
xor eax, eax
jmp color_done
color_check:
cmp eax, 255
jbe color_done
mov eax, 255
color_done:
mov ah, al
pop bx
mov word ptr es:[bx], ax
mov word ptr es:[bx+320], ax
dp_next:
add si, 4
dec cx
jnz dp_loop
pop es
call copy_buffer
call timer_wait
push es
mov es, word ptr [buffer_seg]
mov si, offset saved_offsets
mov cx, MAX_POINTS
erase_points:
lodsw
mov di, ax
xor ax, ax
stosw
add di, 320 - 2
stosw
loop erase_points
pop es
mov ah, 6h
mov dl, 0ffh
int 21h
jz main_loop
call do_shutdown
morph_object proc
push bp
mov bp, sp
sub sp, 2 ; bp-2 status of copro
mov si, offset model_object
mov di, offset current_object
mov cx, MAX_POINTS*3
mo_loop:
fld dword ptr [di]
fcom dword ptr [si]
fstsw word ptr [bp-2]
mov ah, byte ptr [bp-1]
sahf
ja mo_dec_coord
jb mo_inc_coord
jmp mo_write
mo_dec_coord:
fsub delta_coord
jmp mo_write
mo_inc_coord:
fadd delta_coord
mo_write:
fstp dword ptr [di]
add si, 4
add di, 4
dec cx
jnz mo_loop
add sp, 2
pop bp
ret
endp
make_circle proc
push bp
mov bp, sp
sub sp, 4 ; bp-4 angle
mov dword ptr [bp-4], 0
mov si, offset model_object
mov cx, MAX_POINTS
mc_loop:
fld dword ptr [bp-4]
fld st(0)
fld st(0)
fsin
fmul circle_radius
fstp dword ptr [si]
fcos
fmul circle_radius
fstp dword ptr [si+4]
mov dword ptr [si+8], 0
fadd circle_inc_angle
fstp dword ptr [bp-4]
cmp cx, (MAX_POINTS/2)+1
jb mc_next
mov eax, dword ptr [si+4]
mov dword ptr [si+8], eax
mov dword ptr [si+4], 0
mc_next:
add si, 12
dec cx
jnz mc_loop
add sp, 4
pop bp
ret
endp
make_random proc
push bp
mov bp, sp
sub sp, 2 ; bp-2 temp value
mov si, offset model_object
mov cx, MAX_POINTS*3
mr_loop:
push word ptr 50
push word ptr -50
call random
mov word ptr [bp-2], ax
fild word ptr [bp-2]
fstp dword ptr [si]
add si, 4
dec cx
jnz mr_loop
add sp, 2
pop bp
ret
endp
make_spiral proc
push bp
mov bp, sp
sub sp, 8 ; bp-4 angle
; bp-8 z coordinate
mov dword ptr [bp-4], 0
fld spiral_start_z
fstp dword ptr [bp-8]
mov si, offset model_object
mov cx, MAX_POINTS
ms_loop:
fld dword ptr [bp-4]
fld st(0)
fld st(0)
fsin
fmul spiral_radius
fstp dword ptr [si]
fcos
fmul spiral_radius
fstp dword ptr [si+4]
fadd spiral_inc_angle
fstp dword ptr [bp-4]
fld dword ptr [bp-8]
fld st(0)
fstp dword ptr [si+8]
fadd spiral_inc_z
fstp dword ptr [bp-8]
add si, 12
dec cx
jnz ms_loop
add sp, 8
pop bp
ret
endp
make_cube proc
push bp
mov bp, sp
sub sp, 12
; bp-4 coordinate x
; bp-8 y
; bp-12 z
mov si, offset model_object
fld cube_start_coord
fstp dword ptr [bp-4] ; start x
mov cx, 5
mc_loop_x:
fld cube_start_coord
fstp dword ptr [bp-8] ; start y
push cx
mov cx, 5
mc_loop_y:
fld cube_start_coord
fstp dword ptr [bp-12] ; start z
push cx
mov cx, 5
mc_loop_z:
fld dword ptr [bp-4]
fstp dword ptr [si] ; write x
fld dword ptr [bp-8]
fstp dword ptr [si+4] ; write y
fld dword ptr [bp-12]
fld st(0)
fstp dword ptr [si+8] ; write z
fadd cube_inc_coord ; update z
fstp dword ptr [bp-12]
add si, 12
dec cx
jnz mc_loop_z
fld dword ptr [bp-8]
fadd cube_inc_coord ; update y
fstp dword ptr [bp-8]
pop cx
dec cx
jnz mc_loop_y
fld dword ptr [bp-4]
fadd cube_inc_coord ; update x
fstp dword ptr [bp-4]
pop cx
dec cx
jnz mc_loop_x
add sp, 12
pop bp
ret
endp
random proc ; +4 min, +6 max
push bp
mov bp, sp
mov bx, random_seed
add bx, 9248h
ror bx, 3
mov random_seed, bx
mov ax, word ptr [bp+6]
sub ax, word ptr [bp+4]
mul bx
mov ax, dx
add ax, word ptr [bp+4] ; ax - random number
pop bp
ret 4
endp
.data
morph_counter dw 0
morph_number dw 0
angle_x dd 0.0
angle_y dd 0.0
angle_z dd 0.0
inc_angle dd 0.0174533
delta_coord dd 0.5
circle_radius dd 85.0
circle_inc_angle dd 0.100530965 ; 360/MAX_POINTS*2*PI/180
spiral_radius dd 25.0
spiral_start_z dd -125.0
spiral_inc_z dd 2.0
spiral_inc_angle dd 0.628319 ; 0.0628319*10
cube_inc_coord dd 25.0
cube_start_coord dd -50.0
color_add dd 125.0
color_scale dd 1.024 ; 256 / (2 * 125)
color_dump dd ?
.data?
random_seed dw ?
model_object dd MAX_POINTS dup(?, ?, ?)
current_object dd MAX_POINTS dup(?, ?, ?)
rotated_object dd MAX_POINTS dup(?, ?, ?)
coord2d dw MAX_POINTS dup(?, ?)
saved_offsets dw MAX_POINTS dup(?)
end entrypoint