Subversion Repositories Kolibri OS

Rev

Rev 1728 | 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.  
  9. TIMEOUT equ 3
  10.  
  11. ; EXECUTABLE HEADER
  12.  
  13. use32
  14.  
  15.   org 0x0
  16.   db "MENUET01"
  17.   dd 0x01
  18.   dd ENTRANCE
  19.   dd EYES_END
  20.   dd 0x3000
  21.   dd 0x3000
  22.   dd 0x0
  23.   dd 0x0
  24.  
  25. include '..\..\..\macros.inc'
  26. ENTRANCE: ; start of code
  27.  
  28. ; ==== main ====
  29.  
  30. call prepare_eyes
  31.  
  32. call shape_window
  33.  
  34. still:
  35.  
  36. call draw_eyes                   ; draw those funny "eyes"
  37.  
  38. mcall 23,TIMEOUT                 ; wait for event with timeout
  39.  
  40. cmp eax,1                        ; redraw ?
  41. jnz  no_draw
  42. call redraw_overlap
  43. no_draw:
  44.  
  45. cmp eax,2                        ; key ?
  46. jz  key
  47.  
  48. cmp eax,3                        ; button ?
  49. jz  button
  50.  
  51. jmp still                        ; loop
  52.  
  53. ; EVENTS
  54.  
  55. key:
  56. mcall 2          ; just read and ignore
  57. jmp still
  58.  
  59. button:          ; analyze button
  60. mcall -1         ; exit
  61. jmp still
  62.  
  63. ; -====- declarations -====-
  64.  
  65. imagedata equ EYES_END
  66. skindata  equ EYES_END+925
  67. winref    equ EYES_END+6325
  68.  
  69. ; -====- shape -====-
  70.  
  71. shape_window:
  72.  
  73. mov eax,50                   ; set up shape reference area
  74. mov ebx,0
  75. mov ecx,winref
  76. mcall
  77.  
  78. ret
  79.  
  80. ; -====- redrawing -====-
  81.  
  82. draw_eyes:                   ; check mousepos to disable blinking
  83.  
  84. mov eax,37
  85. xor ebx,ebx
  86. mcall
  87. cmp dword [mouse],eax
  88. jne redraw_ok
  89. ret
  90. redraw_ok:
  91. mov [mouse],eax
  92.  
  93. redraw_overlap:              ; label for redraw event (without checkmouse)
  94.  
  95. mcall 12,1
  96.  
  97. xor eax,eax                  ; define window
  98. mov ebx,[win_ebx]
  99. mov ecx,[win_ecx]
  100. mov edx,0x11000000           ; do not draw window, just define its area
  101. xor esi,esi
  102. xor edi,edi
  103. mcall
  104.  
  105. mcall 8,60,45,1+0x40000000 ; define closebutton
  106.  
  107. mov ebx,skindata
  108. mcall 7,,60*65536+30,15
  109.  
  110. mov eax,15
  111. mov ebx,30
  112. call draw_eye_point
  113. add eax,30
  114. call draw_eye_point
  115.  
  116. mcall 12,2
  117.  
  118. ret
  119.  
  120. draw_eye_point:          ; draw eye point (EAX=X, EBX=Y)
  121. pusha
  122.  
  123. mov ecx, [mouse]    ; ecx = mousex, edx = mousey
  124. mov edx,ecx
  125. shr ecx,16
  126. and edx,0xFFFF
  127.  
  128. ; ===> calculate position
  129.  
  130. push eax
  131. push ebx
  132. mov byte [sign1],0
  133. mov esi, [win_ebx]
  134. shr esi,16
  135. add eax,esi
  136. sub ecx,eax                 ; ECX=ECX-EAX (signed) , ECX=|ECX|
  137. jnc abs_ok_1
  138. neg ecx
  139. mov byte [sign1],1
  140. abs_ok_1:
  141. mov [temp1],ecx
  142. mov byte [sign2],0
  143. mov esi,[win_ecx]
  144. shr esi,16
  145. add ebx,esi
  146. sub edx,ebx                 ; EDX=EDX-EBX (signed) , EDX=|EDX|
  147. jnc abs_ok_2
  148. neg edx
  149. mov byte [sign2],1
  150. abs_ok_2:
  151. mov [temp2],edx
  152. pop ebx
  153. pop eax
  154.  
  155. push eax                    ; ECX*=ECX
  156. push edx
  157. xor eax,eax
  158. xor edx,edx
  159. mov ax,cx
  160. mul cx
  161. shl edx,16
  162. or  eax,edx
  163. mov ecx,eax
  164. pop edx
  165. pop eax
  166.  
  167. push eax                    ; EDX*=EDX
  168. push ecx
  169. mov  ecx,edx
  170. xor  eax,eax
  171. xor  edx,edx
  172. mov  ax,cx
  173. mul  cx
  174. shl  edx,16
  175. or   eax,edx
  176. mov  edx,eax
  177. pop  ecx
  178. pop  eax
  179.  
  180. push ebx
  181. push ecx
  182. push edx
  183. push eax
  184. mov  ebx,ecx                 ; EBX=ECX+EDX
  185. add  ebx,edx
  186. xor  edi,edi                 ; ESI=SQRT(EBX)
  187. mov  ecx,edi
  188. mov  edx,edi
  189. inc  edi
  190. mov  eax,edi
  191. inc  edi
  192. sqrt_loop:
  193. add  ecx,eax
  194. add  eax,edi
  195. inc  edx
  196. cmp  ecx,ebx
  197. jbe  sqrt_loop
  198. dec  edx
  199. mov  esi,edx
  200. mov  ax,si                   ; ESI=ESI/7
  201. mov  dl,7
  202. div  dl
  203. and  ax,0xFF
  204. mov  si,ax                   ; ESI ? 0 : ESI=1
  205. jnz  nozeroflag1
  206. mov  si,1
  207. nozeroflag1:
  208.  
  209. pop eax
  210. pop edx
  211. pop ecx
  212. pop ebx
  213.  
  214. push eax                     ; ECX=[temp1]/ESI
  215. push edx
  216. mov  eax,[temp1]
  217. mov  dx,si
  218. div  dl
  219. mov  cl,al
  220. and  ecx,0xFF
  221. pop  edx
  222. pop  eax
  223.  
  224. cmp  byte [sign1],1
  225. je   subtract_1
  226. add  eax,ecx                  ; EAX=EAX+ECX
  227. jmp  calc_ok_1
  228. subtract_1:
  229. sub  eax,ecx                  ; EAX=EAX-ECX
  230. calc_ok_1:
  231.  
  232. push eax                      ; EDX=[temp2]/ESI
  233. push ecx
  234. mov  eax,[temp2]
  235. mov  dx,si
  236. div  dl
  237. mov  dl,al
  238. and  dx,0xFF
  239. pop  ecx
  240. pop  eax
  241.  
  242. cmp  byte [sign2],1
  243. je   subtract_2
  244. add  ebx,edx                  ; EBX=EBX+EDX
  245. jmp  calc_ok_2
  246. subtract_2:
  247. sub  ebx,edx                  ; EBX=EBX-EDX
  248. calc_ok_2:
  249.  
  250. ; <===
  251.  
  252. mov ecx,ebx         ; draw point
  253. mov ebx,eax
  254. mov eax,13
  255. dec ecx
  256. dec ecx
  257. dec ebx
  258. dec ebx
  259. shl ecx,16
  260. add ecx,4
  261. shl ebx,16
  262. add ebx,4
  263. mov eax,13
  264. xor edx,edx
  265. mcall
  266.  
  267. popa
  268. ret
  269.  
  270. ; -====- working on images and window -====-
  271.  
  272. prepare_eyes:
  273.  
  274. ;mov eax,6            ; load EYES.RAW
  275. ;mov ebx,graphix
  276. ;mov ecx,0x00000000
  277. ;mov edx,0xFFFFFFFF
  278. ;mov esi,imagedata
  279. ;mcall
  280. ;cmp eax,0xFFFFFFFF
  281. ;jnz filefound
  282.  
  283. ;mov eax,-1           ; file not exists...
  284. ;mcall
  285.  
  286. ;filefound:
  287. mov esi,imagedata+25 ; transform grayscale to putimage format
  288. mov edi,skindata
  289. mov ecx,30
  290. transform_loop:
  291. push ecx
  292. mov  ecx,30
  293. lp1:
  294. lodsb
  295. stosb
  296. stosb
  297. stosb
  298. loop lp1
  299. sub esi,30
  300. mov  ecx,30
  301. lp2:
  302. lodsb
  303. stosb
  304. stosb
  305. stosb
  306. loop lp2
  307. pop  ecx
  308. loop transform_loop
  309.  
  310. mov eax,14           ; calculating screen position
  311. mcall
  312. shr eax,1
  313. mov ax,59
  314. sub eax,30*65536
  315. mov [win_ebx],eax
  316. mov [win_ecx],dword 10*65536+44
  317.  
  318. mov esi,imagedata+25 ; calculate shape reference area
  319. mov edi,winref
  320. mov ecx,900          ; disable drag bar
  321. mov al,0
  322. rep stosb
  323.  
  324. mov ecx,30           ; calculate circles for eyes
  325. shape_loop:
  326. push ecx
  327.  
  328. call copy_line       ; duplicate (we have two eyes :)
  329. sub  esi,30
  330. call copy_line
  331.  
  332. pop  ecx
  333. loop shape_loop
  334.  
  335. ret
  336.  
  337. copy_line:       ; copy single line to shape reference area
  338. mov ecx,30
  339. cpl_loop:
  340. lodsb
  341. cmp al,0xFF
  342. jnz  set_one
  343. mov al,0
  344. jmp cpl_ok
  345. set_one:
  346. mov al,1
  347. cpl_ok:
  348. stosb
  349. loop cpl_loop
  350. ret
  351.  
  352. ; DATA
  353.  
  354. ; environment
  355.  
  356. win_ebx  dd     0x0
  357. win_ecx  dd     0x0
  358. mouse    dd     0xFFFFFFFF
  359. ;graphix  db     "EYES.RAW    "
  360.  
  361. ; temporary storage for math routines
  362.  
  363. temp1    dd     0
  364. temp2    dd     0
  365. sign1    db     0
  366. sign2    db     0
  367.  
  368. EYES_END: ; end of code
  369. file "eyes.raw"
  370.