Subversion Repositories Kolibri OS

Rev

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