Subversion Repositories Kolibri OS

Rev

Rev 2022 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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