Subversion Repositories Kolibri OS

Rev

Rev 1728 | 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
 
7648 leency 9
TIMEOUT equ 3
31 halyavin 10
 
11
; EXECUTABLE HEADER
12
 
13
use32
14
 
15
  org 0x0
16
  db "MENUET01"
17
  dd 0x01
18
  dd ENTRANCE
205 heavyiron 19
  dd EYES_END
31 halyavin 20
  dd 0x3000
21
  dd 0x3000
22
  dd 0x0
23
  dd 0x0
24
 
485 heavyiron 25
include '..\..\..\macros.inc'
31 halyavin 26
ENTRANCE: ; start of code
27
 
28
; ==== main ====
29
 
205 heavyiron 30
call prepare_eyes
31 halyavin 31
 
205 heavyiron 32
call shape_window
33
 
34
still:
35
 
36
call draw_eyes                   ; draw those funny "eyes"
37
 
7648 leency 38
mcall 23,TIMEOUT                 ; wait for event with timeout
31 halyavin 39
 
205 heavyiron 40
cmp eax,1                        ; redraw ?
41
jnz  no_draw
42
call redraw_overlap
43
no_draw:
31 halyavin 44
 
205 heavyiron 45
cmp eax,2                        ; key ?
46
jz  key
31 halyavin 47
 
205 heavyiron 48
cmp eax,3                        ; button ?
49
jz  button
31 halyavin 50
 
205 heavyiron 51
jmp still                        ; loop
31 halyavin 52
 
205 heavyiron 53
; EVENTS
54
 
55
key:
7648 leency 56
mcall 2          ; just read and ignore
205 heavyiron 57
jmp still
58
 
59
button:          ; analyze button
7648 leency 60
mcall -1         ; exit
205 heavyiron 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
 
133 diamond 69
; -====- shape -====-
31 halyavin 70
 
133 diamond 71
shape_window:
31 halyavin 72
 
133 diamond 73
mov eax,50                   ; set up shape reference area
205 heavyiron 74
mov ebx,0
133 diamond 75
mov ecx,winref
485 heavyiron 76
mcall
31 halyavin 77
 
205 heavyiron 78
ret
31 halyavin 79
 
80
; -====- redrawing -====-
81
 
82
draw_eyes:                   ; check mousepos to disable blinking
83
 
84
mov eax,37
85
xor ebx,ebx
485 heavyiron 86
mcall
31 halyavin 87
cmp dword [mouse],eax
88
jne redraw_ok
89
ret
90
redraw_ok:
91
mov [mouse],eax
92
 
205 heavyiron 93
redraw_overlap:              ; label for redraw event (without checkmouse)
31 halyavin 94
 
7648 leency 95
mcall 12,1
31 halyavin 96
 
97
xor eax,eax                  ; define window
98
mov ebx,[win_ebx]
99
mov ecx,[win_ecx]
7648 leency 100
mov edx,0x11000000           ; do not draw window, just define its area
31 halyavin 101
xor esi,esi
102
xor edi,edi
485 heavyiron 103
mcall
31 halyavin 104
 
7648 leency 105
mcall 8,60,45,1+0x40000000 ; define closebutton
31 halyavin 106
 
205 heavyiron 107
mov ebx,skindata
7648 leency 108
mcall 7,,60*65536+30,15
205 heavyiron 109
 
110
mov eax,15
111
mov ebx,30
112
call draw_eye_point
113
add eax,30
114
call draw_eye_point
115
 
7648 leency 116
mcall 12,2
31 halyavin 117
 
118
ret
119
 
120
draw_eye_point:          ; draw eye point (EAX=X, EBX=Y)
121
pusha
122
 
205 heavyiron 123
mov ecx, [mouse]    ; ecx = mousex, edx = mousey
124
mov edx,ecx
125
shr ecx,16
126
and edx,0xFFFF
31 halyavin 127
 
128
; ===> calculate position
129
 
130
push eax
131
push ebx
132
mov byte [sign1],0
205 heavyiron 133
mov esi, [win_ebx]
134
shr esi,16
135
add eax,esi
31 halyavin 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:
205 heavyiron 141
mov [temp1],ecx
31 halyavin 142
mov byte [sign2],0
205 heavyiron 143
mov esi,[win_ecx]
144
shr esi,16
145
add ebx,esi
146
sub edx,ebx                 ; EDX=EDX-EBX (signed) , EDX=|EDX|
31 halyavin 147
jnc abs_ok_2
205 heavyiron 148
neg edx
31 halyavin 149
mov byte [sign2],1
150
abs_ok_2:
205 heavyiron 151
mov [temp2],edx
152
pop ebx
153
pop eax
31 halyavin 154
 
205 heavyiron 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
31 halyavin 166
 
205 heavyiron 167
push eax                    ; EDX*=EDX
168
push ecx
169
mov  ecx,edx
170
xor  eax,eax
31 halyavin 171
xor  edx,edx
205 heavyiron 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
31 halyavin 192
sqrt_loop:
193
add  ecx,eax
205 heavyiron 194
add  eax,edi
31 halyavin 195
inc  edx
205 heavyiron 196
cmp  ecx,ebx
31 halyavin 197
jbe  sqrt_loop
198
dec  edx
205 heavyiron 199
mov  esi,edx
200
mov  ax,si                   ; ESI=ESI/7
31 halyavin 201
mov  dl,7
202
div  dl
205 heavyiron 203
and  ax,0xFF
204
mov  si,ax                   ; ESI ? 0 : ESI=1
31 halyavin 205
jnz  nozeroflag1
205 heavyiron 206
mov  si,1
31 halyavin 207
nozeroflag1:
208
 
205 heavyiron 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
31 halyavin 218
div  dl
205 heavyiron 219
mov  cl,al
220
and  ecx,0xFF
221
pop  edx
31 halyavin 222
pop  eax
223
 
205 heavyiron 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:
31 halyavin 231
 
205 heavyiron 232
push eax                      ; EDX=[temp2]/ESI
233
push ecx
31 halyavin 234
mov  eax,[temp2]
205 heavyiron 235
mov  dx,si
31 halyavin 236
div  dl
205 heavyiron 237
mov  dl,al
238
and  dx,0xFF
239
pop  ecx
31 halyavin 240
pop  eax
241
 
205 heavyiron 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:
31 halyavin 249
 
250
; <===
251
 
205 heavyiron 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
31 halyavin 259
shl ecx,16
260
add ecx,4
261
shl ebx,16
262
add ebx,4
263
mov eax,13
264
xor edx,edx
485 heavyiron 265
mcall
31 halyavin 266
 
267
popa
268
ret
269
 
270
; -====- working on images and window -====-
271
 
205 heavyiron 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
485 heavyiron 279
;mcall
205 heavyiron 280
;cmp eax,0xFFFFFFFF
281
;jnz filefound
282
 
283
;mov eax,-1           ; file not exists...
485 heavyiron 284
;mcall
205 heavyiron 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
485 heavyiron 311
mcall
205 heavyiron 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
 
31 halyavin 337
copy_line:       ; copy single line to shape reference area
338
mov ecx,30
339
cpl_loop:
340
lodsb
205 heavyiron 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:
31 halyavin 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
205 heavyiron 359
;graphix  db     "EYES.RAW    "
31 halyavin 360
 
361
; temporary storage for math routines
362
 
205 heavyiron 363
temp1    dd     0
364
temp2    dd     0
365
sign1    db     0
366
sign2    db     0
31 halyavin 367
 
205 heavyiron 368
EYES_END: ; end of code
1728 clevermous 369
file "eyes.raw"