Subversion Repositories Kolibri OS

Rev

Rev 109 | Rev 205 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;
  2. ; EYES FOR MENUET
  3. ;
  4. ; Written by Nikita Lesnikov (nlo_one@mail.ru)
  5. ;
  6. ; Position of "eyes" is fixed. To close "eyes" just click on them.
  7. ;
  8. ; NOTE: quite big timeout is used to disable blinking when redrawing.
  9. ; If "eyes" blink on your system, enlarge the TIMEOUT. If not, you can
  10. ; decrease it due to more realistic movement.
  11. ;
  12.  
  13. TIMEOUT equ 5
  14.  
  15. ; EXECUTABLE HEADER
  16.  
  17. use32
  18.  
  19.   org 0x0
  20.   db "MENUET01"
  21.   dd 0x01
  22.   dd ENTRANCE
  23.   dd I_END
  24.   dd 0x3000
  25.   dd 0x3000
  26.   dd 0x0
  27.   dd 0x0
  28.  
  29. include 'macros.inc'
  30. ENTRANCE: ; start of code
  31.  
  32. ; ==== main ====
  33. prepare_eyes:
  34.  
  35. mov esi,imagedata    ; transform grayscale to putimage format
  36. mov edi,skindata
  37. mov ecx,30
  38. transform_loop:
  39. push ecx
  40. mov  ecx,30
  41. lp1:
  42. lodsb
  43. stosb
  44. stosb
  45. stosb
  46. loop lp1
  47. sub esi,30
  48. mov  ecx,30
  49. lp2:
  50. lodsb
  51. stosb
  52. stosb
  53. stosb
  54. loop lp2
  55. pop  ecx
  56. loop transform_loop
  57.  
  58. mov eax,14           ; calculating screen position
  59. int 0x40
  60. shr eax,1
  61. mov ax,59
  62. sub eax,30*65536
  63. mov [win_ebx],eax
  64. mov [win_ecx],dword 10*65536+44
  65.  
  66. mov esi,imagedata    ; calculate shape reference area
  67. mov edi,winref
  68. mov ecx,900          ; disable drag bar
  69. mov al,0
  70. rep stosb
  71.  
  72. mov ecx,30           ; calculate circles for eyes
  73. shape_loop:
  74. push ecx
  75.  
  76. call copy_line       ; duplicate (we have two eyes :)
  77. sub  esi,30
  78. call copy_line
  79.  
  80. pop  ecx
  81. loop shape_loop
  82.  
  83. ; -====- shape -====-
  84.  
  85. shape_window:
  86.  
  87. mov eax,50                   ; set up shape reference area
  88. xor ebx,ebx
  89. mov ecx,winref
  90. int 0x40
  91.  
  92. call draw_window
  93.  
  94. still:
  95.  
  96. call draw_eyes                   ; draw those funny "eyes"
  97.  
  98. _wait:
  99. mov eax,23                       ; wait for event with timeout
  100. mov ebx,TIMEOUT
  101. int 0x40
  102.         dec     eax
  103.         jz      redraw
  104.         dec     eax
  105.         jz      key
  106.         dec     eax
  107.         jnz     still
  108. button:
  109.         or      eax, -1
  110.         int     0x40
  111. key:
  112.         mov     al, 2
  113.         int     0x40
  114.         jmp     still
  115. redraw:
  116.         call    draw_window
  117.         call    redraw_eyes
  118.         jmp     _wait
  119.  
  120. ; -====- redrawing -====-
  121.  
  122. draw_eyes:                   ; check mousepos to disable blinking
  123.  
  124. mov eax,37
  125. xor ebx,ebx
  126. int 0x40
  127. cmp dword [mouse],eax
  128. jne redraw_ok
  129. ret
  130. redraw_ok:
  131. mov [mouse],eax
  132.  
  133. redraw_eyes:
  134. mov eax,7
  135. mov ebx,skindata
  136. mov ecx,60*65536+30
  137. mov edx,15
  138. int 0x40
  139.  
  140. mov eax,15
  141. mov ebx,30
  142. call draw_eye_point
  143. add eax,30
  144. call draw_eye_point
  145. ret
  146.  
  147. draw_window:
  148.  
  149. mov eax,12
  150. mov ebx,1
  151. int 0x40
  152.  
  153. xor eax,eax                  ; define window
  154. mov ebx,[win_ebx]
  155. mov ecx,[win_ecx]
  156. xor edx,edx
  157. xor esi,esi
  158. xor edi,edi
  159. int 0x40
  160.  
  161. mov eax,8                    ; define closebutton
  162. mov ebx,60
  163. mov ecx,45
  164. mov edx,1
  165. int 0x40
  166.  
  167. mov eax,12
  168. mov ebx,2
  169. int 0x40
  170.  
  171. ret
  172.  
  173. draw_eye_point:          ; draw eye point (EAX=X, EBX=Y)
  174. pusha
  175.  
  176.         movzx   ecx, word [mouse+2] ; ecx = mousex, esi = mousey
  177.         movzx   esi, word [mouse]
  178.  
  179. ; ===> calculate position
  180.  
  181. push eax
  182. push ebx
  183. mov byte [sign1],0
  184. mov edx, [win_ebx]
  185. shr edx,16
  186. add eax,edx
  187. sub ecx,eax                 ; ECX=ECX-EAX (signed) , ECX=|ECX|
  188. jnc abs_ok_1
  189. neg ecx
  190. mov byte [sign1],1
  191. abs_ok_1:
  192.         push    ecx         ; save x distance
  193. mov byte [sign2],0
  194. mov edx,[win_ecx]
  195. shr edx,16
  196. add ebx,edx
  197. sub esi,ebx                 ; EDX=EDX-EBX (signed) , EDX=|EDX|
  198. jnc abs_ok_2
  199. neg esi
  200. mov byte [sign2],1
  201. abs_ok_2:
  202. mov [temp2],esi
  203.  
  204. ; ESI = ECX*ECX+ESI*ESI
  205.         imul    ecx, ecx
  206.         imul    esi, esi
  207.         add     esi, ecx
  208.  
  209. xor  ecx,ecx                 ; EDX=SQRT(EBX)
  210. xor  edx,edx
  211. mov  eax,1
  212. sqrt_loop:
  213. ; in this moment ecx=edx*edx, eax=1+2*edx
  214. add  ecx,eax
  215. inc  eax
  216. inc  eax
  217. inc  edx
  218. cmp  ecx,esi
  219. jbe  sqrt_loop
  220. dec  edx
  221. mov  eax,edx                   ; EDX=EDX/7
  222. mov  dl,7
  223. div  dl
  224. and  eax,0xFF
  225. mov  edx,eax                   ; EDX ? 0 : EDX=1
  226. jnz  nozeroflag1
  227. inc  edx
  228. nozeroflag1:
  229.  
  230.         pop     eax             ; EAX = x distance
  231.                                 ; ECX=EAX/EDX
  232. div  dl
  233. movzx ecx,al
  234. pop  ebx
  235. pop  eax
  236.  
  237.         cmp     byte [sign1], 0
  238.         jz      @f
  239.         neg     ecx
  240. @@:
  241.         add     eax, ecx
  242.  
  243. push eax                      ; ESI=[temp2]/EDX
  244. mov  eax,[temp2]
  245. div  dl
  246. movzx esi,al
  247. pop  eax
  248.  
  249.         cmp     byte [sign2], 0
  250.         jz      @f
  251.         neg     esi
  252. @@:
  253.         add     ebx, esi
  254.  
  255. ; <===
  256.  
  257. ; draw point
  258.         lea     ecx, [ebx-2]
  259.         lea     ebx, [eax-2]
  260. shl ecx,16
  261. add ecx,4
  262. shl ebx,16
  263. add ebx,4
  264. mov eax,13
  265. xor edx,edx
  266. int 0x40
  267.  
  268. popa
  269. ret
  270.  
  271. ; -====- working on images and window -====-
  272.  
  273. copy_line:       ; copy single line to shape reference area
  274. mov ecx,30
  275. cpl_loop:
  276. lodsb
  277. ; input is image: 0xFF = white pixel, 0 = black pixel
  278. ; output is membership boolean: 0 = pixel no, 1 = pixel ok
  279. inc eax
  280. stosb
  281. loop cpl_loop
  282. ret
  283.  
  284. ; DATA
  285.  
  286. ; environment
  287.  
  288. win_ebx  dd     0x0
  289. win_ecx  dd     0x0
  290. mouse    dd     0xFFFFFFFF
  291.  
  292. EYES_END: ; end of code
  293. imagedata:
  294. ; texture is 900 bytes starting from 25th
  295. file "eyes.raw":25,900
  296. I_END:
  297.  
  298. ; temporary storage for math routines
  299.  
  300. sign1   db      ?
  301. sign2   db      ?
  302. align 4
  303. temp2   dd      ?
  304.  
  305. skindata rb     60*30*3
  306. winref  rb      45*60
  307.