Rev 109 | Rev 485 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
31 | halyavin | 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 |
||
133 | diamond | 23 | dd I_END |
31 | halyavin | 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 ==== |
||
133 | diamond | 33 | prepare_eyes: |
31 | halyavin | 34 | |
133 | diamond | 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 |
||
31 | halyavin | 57 | |
133 | diamond | 58 | mov eax,14 ; calculating screen position |
31 | halyavin | 59 | int 0x40 |
133 | diamond | 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 |
||
31 | halyavin | 65 | |
133 | diamond | 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 |
||
31 | halyavin | 71 | |
133 | diamond | 72 | mov ecx,30 ; calculate circles for eyes |
73 | shape_loop: |
||
74 | push ecx |
||
31 | halyavin | 75 | |
133 | diamond | 76 | call copy_line ; duplicate (we have two eyes :) |
77 | sub esi,30 |
||
78 | call copy_line |
||
31 | halyavin | 79 | |
133 | diamond | 80 | pop ecx |
81 | loop shape_loop |
||
31 | halyavin | 82 | |
133 | diamond | 83 | ; -====- shape -====- |
31 | halyavin | 84 | |
133 | diamond | 85 | shape_window: |
31 | halyavin | 86 | |
133 | diamond | 87 | mov eax,50 ; set up shape reference area |
88 | xor ebx,ebx |
||
89 | mov ecx,winref |
||
31 | halyavin | 90 | int 0x40 |
91 | |||
133 | diamond | 92 | call draw_window |
31 | halyavin | 93 | |
133 | diamond | 94 | still: |
31 | halyavin | 95 | |
133 | diamond | 96 | call draw_eyes ; draw those funny "eyes" |
31 | halyavin | 97 | |
133 | diamond | 98 | _wait: |
99 | mov eax,23 ; wait for event with timeout |
||
100 | mov ebx,TIMEOUT |
||
31 | halyavin | 101 | int 0x40 |
133 | diamond | 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 |
||
31 | halyavin | 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 | diamond | 133 | redraw_eyes: |
134 | mov eax,7 |
||
135 | mov ebx,skindata |
||
136 | mov ecx,60*65536+30 |
||
137 | mov edx,15 |
||
138 | int 0x40 |
||
31 | halyavin | 139 | |
133 | diamond | 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 | |||
31 | halyavin | 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 | |||
133 | diamond | 176 | movzx ecx, word [mouse+2] ; ecx = mousex, esi = mousey |
177 | movzx esi, word [mouse] |
||
31 | halyavin | 178 | |
179 | ; ===> calculate position |
||
180 | |||
181 | push eax |
||
182 | push ebx |
||
183 | mov byte [sign1],0 |
||
133 | diamond | 184 | mov edx, [win_ebx] |
185 | shr edx,16 |
||
186 | add eax,edx |
||
31 | halyavin | 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: |
||
133 | diamond | 192 | push ecx ; save x distance |
31 | halyavin | 193 | mov byte [sign2],0 |
133 | diamond | 194 | mov edx,[win_ecx] |
195 | shr edx,16 |
||
196 | add ebx,edx |
||
197 | sub esi,ebx ; EDX=EDX-EBX (signed) , EDX=|EDX| |
||
31 | halyavin | 198 | jnc abs_ok_2 |
133 | diamond | 199 | neg esi |
31 | halyavin | 200 | mov byte [sign2],1 |
201 | abs_ok_2: |
||
133 | diamond | 202 | mov [temp2],esi |
31 | halyavin | 203 | |
133 | diamond | 204 | ; ESI = ECX*ECX+ESI*ESI |
205 | imul ecx, ecx |
||
206 | imul esi, esi |
||
207 | add esi, ecx |
||
31 | halyavin | 208 | |
133 | diamond | 209 | xor ecx,ecx ; EDX=SQRT(EBX) |
31 | halyavin | 210 | xor edx,edx |
133 | diamond | 211 | mov eax,1 |
31 | halyavin | 212 | sqrt_loop: |
133 | diamond | 213 | ; in this moment ecx=edx*edx, eax=1+2*edx |
31 | halyavin | 214 | add ecx,eax |
133 | diamond | 215 | inc eax |
216 | inc eax |
||
31 | halyavin | 217 | inc edx |
133 | diamond | 218 | cmp ecx,esi |
31 | halyavin | 219 | jbe sqrt_loop |
220 | dec edx |
||
133 | diamond | 221 | mov eax,edx ; EDX=EDX/7 |
31 | halyavin | 222 | mov dl,7 |
223 | div dl |
||
133 | diamond | 224 | and eax,0xFF |
225 | mov edx,eax ; EDX ? 0 : EDX=1 |
||
31 | halyavin | 226 | jnz nozeroflag1 |
133 | diamond | 227 | inc edx |
31 | halyavin | 228 | nozeroflag1: |
229 | |||
133 | diamond | 230 | pop eax ; EAX = x distance |
231 | ; ECX=EAX/EDX |
||
31 | halyavin | 232 | div dl |
133 | diamond | 233 | movzx ecx,al |
234 | pop ebx |
||
31 | halyavin | 235 | pop eax |
236 | |||
133 | diamond | 237 | cmp byte [sign1], 0 |
238 | jz @f |
||
239 | neg ecx |
||
240 | @@: |
||
241 | add eax, ecx |
||
31 | halyavin | 242 | |
133 | diamond | 243 | push eax ; ESI=[temp2]/EDX |
31 | halyavin | 244 | mov eax,[temp2] |
245 | div dl |
||
133 | diamond | 246 | movzx esi,al |
31 | halyavin | 247 | pop eax |
248 | |||
133 | diamond | 249 | cmp byte [sign2], 0 |
250 | jz @f |
||
251 | neg esi |
||
252 | @@: |
||
253 | add ebx, esi |
||
31 | halyavin | 254 | |
255 | ; <=== |
||
256 | |||
133 | diamond | 257 | ; draw point |
258 | lea ecx, [ebx-2] |
||
259 | lea ebx, [eax-2] |
||
31 | halyavin | 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 |
||
133 | diamond | 277 | ; input is image: 0xFF = white pixel, 0 = black pixel |
278 | ; output is membership boolean: 0 = pixel no, 1 = pixel ok |
||
279 | inc eax |
||
31 | halyavin | 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 | |||
133 | diamond | 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 | |||
31 | halyavin | 298 | ; temporary storage for math routines |
299 | |||
133 | diamond | 300 | sign1 db ? |
301 | sign2 db ? |
||
302 | align 4 |
||
303 | temp2 dd ? |
||
31 | halyavin | 304 | |
133 | diamond | 305 | skindata rb 60*30*3 |
306 | winref rb 45*60=== |