Subversion Repositories Kolibri OS

Rev

Rev 109 | Rev 205 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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