Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
661 ataualpa 1
;
2
;   application     :  3d shaking waved spiral
3
;   compilator      :  fasm
4
;   system          :  MenuetOS
5
;   author          :  macgub
6
;   email           :  macgub3@wp
7
 
8
timeout equ 3
9
maxx equ 600        ; window size
10
maxy equ 420
11
use32
12
 
13
               org    0x0
14
 
15
               db     'MENUET01'              ; 8 byte id
16
               dd     0x01                    ; header version
17
               dd     START                   ; start of code
18
               dd     I_END                   ; size of image
19
               dd     0x100000                ; memory for app
20
               dd     0xbffff                 ; esp
21
               dd     0x0 , 0x0               ; I_Param , I_Icon
22
 
23
START:                          ; start of execution
24
 
25
     call draw_window
26
 
27
still:
28
 
29
;    mov  eax,23                 ; wait here for event
30
;    mov  ebx,timeout
31
;    int  0x40
32
    mov eax,11                   ; check for event no wait
33
    int 0x40
34
 
35
    cmp  eax,1                  ; redraw request ?
36
    je   red
37
    cmp  eax,2                  ; key in buffer ?
38
    je   key
39
    cmp  eax,3                  ; button in buffer ?
40
    je   button
41
 
42
    jmp  noclose
43
 
44
  red:                          ; redraw
45
    call draw_window
46
    jmp  still
47
 
48
  key:                          ; key
49
    mov  eax,2                  ; just read it and ignore
50
    int  0x40
51
    jmp  still
52
 
53
  button:                       ; button
54
    mov  eax,17                 ; get id
55
    int  0x40
56
 
57
    cmp  ah,1                   ; button id=1 ?
58
    jne  noclose
59
 
60
    mov  eax,-1                 ; close this program
61
    int  0x40
62
  noclose:
63
 
64
; mov eax,13
65
; mov ebx,20*65536+maxx-25
66
; mov ecx,20*65536+maxy-25
67
; xor edx,edx
68
; int 0x40
69
 
70
 mov edi,screen_buf
71
 mov ecx,maxx*maxy*3/4
72
 xor eax,eax
73
 cld
74
 rep stosd
75
 
76
 
77
 call calc_deg
78
 mov [z],0
79
 mov [sin_counter],0
80
 finit
81
oopz:
82
 mov [x],0
83
 push [z]
84
 call calc_sin_variable
85
oop:
86
  push [x]
87
;  call getcol  ;(x,z)
88
  call fun                       ; calculates y and y1
89
;  call rotateY
90
  mov eax,[sin_variable]
91
  add eax,[vector_x]                     ;  vector_x
92
  add [x],eax
93
  mov eax,[vector_y]
94
  add [y],eax                     ;  vector_y
95
  add [y1],eax
96
  call point_perspective
97
  call draw_point_3d
98
 pop [x]
99
 inc [x]
100
 mov eax,[x]
101
 cmp eax,[loop_counter]
102
 jne oop
103
 inc [sin_counter]
104
 pop [z]
105
 inc [z]
106
 cmp [z],200
107
 jne oopz
108
 
109
 mov eax,7
110
 mov ebx,screen_buf
111
 mov ecx,maxx*65536+maxy
112
 mov edx,20*65536+20
113
 int 0x40
114
 
115
 call set_elipse_dim
116
 call set_vectors
117
 
118
jmp still
119
;-----------------++++++PROCEDURES
120
getcol:
121
 mov eax,[x_resolution]
122
 mul [z]
123
 add eax,[x]
124
 mov ebx,eax
125
 mov eax,35
126
 int 0x40
127
 mov [col],eax
128
ret
129
 
130
set_vectors:
131
 cmp [vector_x],55
132
 jne vec1
133
 mov [vector_dir_x],1
134
 vec1:
135
 cmp [vector_x],250
136
 jne vec2
137
 mov [vector_dir_x],0
138
 vec2:
139
 cmp [vector_dir_x],1
140
 jne vec3
141
 inc [vector_x]
142
 jmp end_x
143
 vec3:
144
 dec [vector_x]
145
 end_x:
146
 cmp [vector_y],195
147
 jne vec4
148
 mov [vector_dir_y],1
149
 vec4:
150
 cmp [vector_y],205
151
 jne vec5
152
 mov [vector_dir_y],0
153
 vec5:
154
 cmp [vector_dir_y],1
155
 jne vec6
156
 inc [vector_y]
157
 ret
158
 vec6:
159
 dec [vector_y]
160
ret
161
set_elipse_dim:
162
 cmp [b],60
163
 jne go11
164
 mov [elipse_dir],0
165
 go11:
166
 cmp [b],10
167
 jne go12
168
 mov [elipse_dir],1
169
 go12:
170
 cmp [elipse_dir],1
171
 jne go13
172
 inc [b]
173
 dec [a]
174
 mov eax,[a]
175
 mov [xo],eax
176
 shl eax,1
177
 inc eax
178
 mov [loop_counter],eax
179
 ret
180
 go13:
181
 dec [b]
182
 inc [a]
183
 mov eax,[a]
184
 mov [xo],eax
185
 shl eax,1
186
 inc eax
187
 mov [loop_counter],eax
188
ret
189
 
190
calc_deg:
191
 cmp [deg_counter], 360
192
 jne go_deg
193
 mov [deg_counter],0
194
 go_deg:
195
 fldpi
196
 fidiv [deg_div]
197
 fimul [deg_counter]
198
 fstp [current_deg]
199
; fsincos
200
; fstp [cosbeta]
201
; fstp [sinbeta]
202
 inc [deg_counter]
203
 ret
204
 
205
;rotateY:
206
; mov eax,[z]
207
; sub eax,[zoo]
208
; mov [subz],eax
209
; mov eax,[x]
210
; sub eax,[xoo]
211
; mov [subx],eax
212
;
213
; fld [sinbeta]
214
; fimul [subz]
215
; fchs
216
; fld [cosbeta]
217
; fimul[subx]
218
; faddp
219
; fiadd [xoo]
220
; fistp [x]
221
 
222
; fld [sinbeta]
223
; fimul [subx]
224
; fld [cosbeta]
225
; fimul [subz]
226
; faddp
227
; fiadd [zoo]
228
; fistp [z]
229
; finit
230
 
231
; ret
232
 
233
point_perspective:
234
  mov eax,[x]
235
  sub eax,[xobs]
236
  mov [xobssub],eax
237
  mov eax,[z]
238
  sub eax,[zobs]
239
  mov [zobssub],eax
240
 
241
  mov eax,[y]
242
  sub eax,[yobs]
243
  mov [yobssub],eax
244
  mov eax,[y1]
245
  sub eax,[yobs]
246
  mov [y1obssub],eax
247
 
248
  finit
249
  fild [xobssub]
250
  fidiv [zobssub]
251
  fimul [zobs]
252
  fchs
253
  fiadd [xobs]
254
  fistp [x]
255
  fild [yobssub]
256
  fidiv [zobssub]
257
  fimul [zobs]
258
  fchs
259
  fiadd [yobs]
260
  fistp [y]
261
 
262
;  mov eax,[xobssub]
263
; idiv [zobssub]
264
;; mov eax,edx
265
; imul [zobs]
266
; neg eax
267
;  add eax,[xobs]
268
;  mov [x],eax
269
;  mov eax,[yobssub]
270
;  idiv [zobssub]
271
;;  mov eax,edx
272
;  imul [zobs]
273
;  neg eax
274
;  add eax,[yobs]
275
;  mov [y],eax
276
 
277
  fild [y1obssub]
278
  fidiv [zobssub]
279
  fimul [zobs]
280
  fchs
281
  fiadd [yobs]
282
  fistp [y1]
283
ret
284
calc_sin_variable:
285
                     ;calculate sinus variable
286
 fldpi
287
 fidiv [sin_gran]
288
 fimul [sin_counter]
289
 fadd  [current_deg]
290
 fsin
291
 fimul [sin_mul]
292
 fistp [sin_variable]
293
ret
294
 
295
fun:
296
; finit
297
 fild [x]
298
 fisub [xo]
299
; fchs
300
; faddp
301
 fild [a]
302
 fdivp st1,st
303
 fmul st,st0
304
 fchs
305
 fld1
306
 faddp
307
 fsqrt
308
 fimul [b]
309
 fld st
310
 fchs
311
 fiadd [yo]
312
 fistp [y]
313
 fiadd [yo]
314
 fistp [y1]
315
ret
316
draw_point_3d:
317
 mov eax,[z]
318
 imul [sq]
319
 shr eax,10
320
 mov ebx,eax
321
 neg eax
322
 push eax
323
 add eax,[y]
324
 mov [y],eax
325
 pop eax
326
 add eax,[y1]
327
 mov [y1],eax
328
 mov eax,ebx
329
 add eax,[x]
330
 mov [x],eax
331
 ;mov eax,1
332
 ;mov ebx,[x]
333
 ;mov ecx,[y]
334
 ;mov edx,[col]
335
 ;int 0x40
336
 ;mov ecx,[y1]
337
 ;int 0x40
338
 mov eax,maxx
339
 mul [y]
340
 add eax,[x]
341
 mov ebx,eax
342
 shl ebx,1
343
 add eax,ebx
344
 add eax,screen_buf
345
 mov ebx,[col]
346
 or [eax],ebx
347
 mov eax,maxx
348
 mul [y1]
349
 add eax,[x]
350
 mov ebx,eax
351
 shl ebx,1
352
 add eax,ebx
353
 add eax,screen_buf
354
 mov ebx,[col]
355
 or [eax],ebx
356
ret
357
 
358
;   *********************************************
359
;   *******  WINDOW DEFINITIONS AND DRAW ********
360
;   *********************************************
361
draw_window:
362
 
363
    mov  eax,12                    ; function 12:tell os about windowdraw
364
    mov  ebx,1                     ; 1, start of draw
365
    int  0x40
366
                                   ; DRAW WINDOW
367
    mov  eax,0                     ; function 0 : define and draw window
368
    mov  ebx,100*65536+maxx+25         ; [x start] *65536 + [x size]
369
    mov  ecx,100*65536+maxy+25         ; [y start] *65536 + [y size]
370
    mov  edx,0x04000000            ; color of work area RRGGBB,8->color gl
371
    mov  esi,0x805080d0            ; color of grab bar  RRGGBB,8->color gl
372
    mov  edi,0x005080d0            ; color of frames    RRGGBB
373
    int  0x40
374
                                   ; WINDOW LABEL
375
    mov  eax,4                     ; function 4 : write text to window
376
    mov  ebx,8*65536+8             ; [x start] *65536 + [y start]
377
    mov  ecx,0x10ddeeff            ; font 1 & color ( 0xF0RRGGBB )
378
    mov  edx,labelt                ; pointer to text beginning
379
    mov  esi,labellen-labelt       ; text length
380
    int  0x40
381
 
382
    mov  eax,12                    ; function 12:tell os about windowdraw
383
    mov  ebx,2                     ; 2, end of draw
384
    int  0x40
385
 
386
    ret
387
 
388
x_resolution dd 800
389
vector_x dd 200
390
vector_y dd 200
391
vector_dir_x db 1
392
vector_dir_y db 1
393
elipse_dir db 1
394
 
395
deg_counter dd ?   ; rotation variables
396
deg_div dd 20
397
current_deg dd ?
398
;cosbeta dd ?
399
;sinbeta dd ?
400
;zoo dd 100            ; rotation axle
401
;xoo dd 40
402
;yoo dd 20
403
;subx dd ?
404
;suby dd ?
405
;subz dd ?
406
 
407
xobs dd maxx/2    ; 320     observer variables
408
yobs dd maxy/2    ; 175
409
zobs dd -200
410
xobssub dd ?
411
yobssub dd ?
412
y1obssub dd ?
413
zobssub dd ?
414
 
415
sin_variable dd ?
416
sin_mul dd 60
417
sin_gran dd 30
418
sin_counter dd  0
419
sq dd 724          ; round( (sqrt2)/2*1024 )
420
z dd ?
421
x dd ?
422
y dd ?
423
y1 dd ?
424
xo dd 70           ; center point  , (loop counter-1)/2
425
yo dd 20
426
a dd 70            ; vertical half-axle
427
b dd 20            ; horizontal half-axle
428
loop_counter dd 141 ; axle granularity
429
col dd 0x00ffffff
430
 
431
labelt:
432
     db   ' 3D SHAKING WAVED SPIRAL'
433
labellen:
434
screen_buf:
435
 
436
I_END:
437