2006-01-03 10:43:31 +01:00
|
|
|
;
|
|
|
|
; EYES FOR MENUET
|
|
|
|
;
|
|
|
|
; Written by Nikita Lesnikov (nlo_one@mail.ru)
|
|
|
|
;
|
|
|
|
; Position of "eyes" is fixed. To close "eyes" just click on them.
|
|
|
|
;
|
|
|
|
; NOTE: quite big timeout is used to disable blinking when redrawing.
|
|
|
|
; If "eyes" blink on your system, enlarge the TIMEOUT. If not, you can
|
|
|
|
; decrease it due to more realistic movement.
|
|
|
|
;
|
|
|
|
|
|
|
|
TIMEOUT equ 5
|
|
|
|
|
|
|
|
; EXECUTABLE HEADER
|
|
|
|
|
|
|
|
use32
|
|
|
|
|
|
|
|
org 0x0
|
|
|
|
db "MENUET01"
|
|
|
|
dd 0x01
|
|
|
|
dd ENTRANCE
|
2006-08-21 15:06:02 +02:00
|
|
|
dd I_END
|
2006-01-03 10:43:31 +01:00
|
|
|
dd 0x3000
|
|
|
|
dd 0x3000
|
|
|
|
dd 0x0
|
|
|
|
dd 0x0
|
|
|
|
|
|
|
|
include 'macros.inc'
|
|
|
|
ENTRANCE: ; start of code
|
|
|
|
|
|
|
|
; ==== main ====
|
2006-08-21 15:06:02 +02:00
|
|
|
prepare_eyes:
|
2006-01-03 10:43:31 +01:00
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
mov esi,imagedata ; transform grayscale to putimage format
|
|
|
|
mov edi,skindata
|
|
|
|
mov ecx,30
|
|
|
|
transform_loop:
|
|
|
|
push ecx
|
|
|
|
mov ecx,30
|
|
|
|
lp1:
|
|
|
|
lodsb
|
|
|
|
stosb
|
|
|
|
stosb
|
|
|
|
stosb
|
|
|
|
loop lp1
|
|
|
|
sub esi,30
|
|
|
|
mov ecx,30
|
|
|
|
lp2:
|
|
|
|
lodsb
|
|
|
|
stosb
|
|
|
|
stosb
|
|
|
|
stosb
|
|
|
|
loop lp2
|
|
|
|
pop ecx
|
|
|
|
loop transform_loop
|
2006-01-03 10:43:31 +01:00
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
mov eax,14 ; calculating screen position
|
2006-01-03 10:43:31 +01:00
|
|
|
int 0x40
|
2006-08-21 15:06:02 +02:00
|
|
|
shr eax,1
|
|
|
|
mov ax,59
|
|
|
|
sub eax,30*65536
|
|
|
|
mov [win_ebx],eax
|
|
|
|
mov [win_ecx],dword 10*65536+44
|
2006-01-03 10:43:31 +01:00
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
mov esi,imagedata ; calculate shape reference area
|
|
|
|
mov edi,winref
|
|
|
|
mov ecx,900 ; disable drag bar
|
|
|
|
mov al,0
|
|
|
|
rep stosb
|
2006-01-03 10:43:31 +01:00
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
mov ecx,30 ; calculate circles for eyes
|
|
|
|
shape_loop:
|
|
|
|
push ecx
|
2006-01-03 10:43:31 +01:00
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
call copy_line ; duplicate (we have two eyes :)
|
|
|
|
sub esi,30
|
|
|
|
call copy_line
|
2006-01-03 10:43:31 +01:00
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
pop ecx
|
|
|
|
loop shape_loop
|
2006-01-03 10:43:31 +01:00
|
|
|
|
|
|
|
; -====- shape -====-
|
|
|
|
|
|
|
|
shape_window:
|
|
|
|
|
|
|
|
mov eax,50 ; set up shape reference area
|
2006-08-21 15:06:02 +02:00
|
|
|
xor ebx,ebx
|
2006-01-03 10:43:31 +01:00
|
|
|
mov ecx,winref
|
|
|
|
int 0x40
|
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
call draw_window
|
|
|
|
|
|
|
|
still:
|
|
|
|
|
|
|
|
call draw_eyes ; draw those funny "eyes"
|
|
|
|
|
|
|
|
_wait:
|
|
|
|
mov eax,23 ; wait for event with timeout
|
|
|
|
mov ebx,TIMEOUT
|
|
|
|
int 0x40
|
|
|
|
dec eax
|
|
|
|
jz redraw
|
|
|
|
dec eax
|
|
|
|
jz key
|
|
|
|
dec eax
|
|
|
|
jnz still
|
|
|
|
button:
|
|
|
|
or eax, -1
|
|
|
|
int 0x40
|
|
|
|
key:
|
|
|
|
mov al, 2
|
|
|
|
int 0x40
|
|
|
|
jmp still
|
|
|
|
redraw:
|
|
|
|
call draw_window
|
|
|
|
call redraw_eyes
|
|
|
|
jmp _wait
|
2006-01-03 10:43:31 +01:00
|
|
|
|
|
|
|
; -====- redrawing -====-
|
|
|
|
|
|
|
|
draw_eyes: ; check mousepos to disable blinking
|
|
|
|
|
|
|
|
mov eax,37
|
|
|
|
xor ebx,ebx
|
|
|
|
int 0x40
|
|
|
|
cmp dword [mouse],eax
|
|
|
|
jne redraw_ok
|
|
|
|
ret
|
|
|
|
redraw_ok:
|
|
|
|
mov [mouse],eax
|
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
redraw_eyes:
|
|
|
|
mov eax,7
|
|
|
|
mov ebx,skindata
|
|
|
|
mov ecx,60*65536+30
|
|
|
|
mov edx,15
|
|
|
|
int 0x40
|
|
|
|
|
|
|
|
mov eax,15
|
|
|
|
mov ebx,30
|
|
|
|
call draw_eye_point
|
|
|
|
add eax,30
|
|
|
|
call draw_eye_point
|
|
|
|
ret
|
|
|
|
|
|
|
|
draw_window:
|
2006-01-03 10:43:31 +01:00
|
|
|
|
|
|
|
mov eax,12
|
|
|
|
mov ebx,1
|
|
|
|
int 0x40
|
|
|
|
|
|
|
|
xor eax,eax ; define window
|
|
|
|
mov ebx,[win_ebx]
|
|
|
|
mov ecx,[win_ecx]
|
|
|
|
xor edx,edx
|
|
|
|
xor esi,esi
|
|
|
|
xor edi,edi
|
|
|
|
int 0x40
|
|
|
|
|
|
|
|
mov eax,8 ; define closebutton
|
|
|
|
mov ebx,60
|
|
|
|
mov ecx,45
|
|
|
|
mov edx,1
|
|
|
|
int 0x40
|
|
|
|
|
|
|
|
mov eax,12
|
|
|
|
mov ebx,2
|
|
|
|
int 0x40
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
draw_eye_point: ; draw eye point (EAX=X, EBX=Y)
|
|
|
|
pusha
|
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
movzx ecx, word [mouse+2] ; ecx = mousex, esi = mousey
|
|
|
|
movzx esi, word [mouse]
|
2006-01-03 10:43:31 +01:00
|
|
|
|
|
|
|
; ===> calculate position
|
|
|
|
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
mov byte [sign1],0
|
2006-08-21 15:06:02 +02:00
|
|
|
mov edx, [win_ebx]
|
|
|
|
shr edx,16
|
|
|
|
add eax,edx
|
2006-01-03 10:43:31 +01:00
|
|
|
sub ecx,eax ; ECX=ECX-EAX (signed) , ECX=|ECX|
|
|
|
|
jnc abs_ok_1
|
|
|
|
neg ecx
|
|
|
|
mov byte [sign1],1
|
|
|
|
abs_ok_1:
|
2006-08-21 15:06:02 +02:00
|
|
|
push ecx ; save x distance
|
2006-01-03 10:43:31 +01:00
|
|
|
mov byte [sign2],0
|
2006-08-21 15:06:02 +02:00
|
|
|
mov edx,[win_ecx]
|
|
|
|
shr edx,16
|
|
|
|
add ebx,edx
|
|
|
|
sub esi,ebx ; EDX=EDX-EBX (signed) , EDX=|EDX|
|
2006-01-03 10:43:31 +01:00
|
|
|
jnc abs_ok_2
|
2006-08-21 15:06:02 +02:00
|
|
|
neg esi
|
2006-01-03 10:43:31 +01:00
|
|
|
mov byte [sign2],1
|
|
|
|
abs_ok_2:
|
2006-08-21 15:06:02 +02:00
|
|
|
mov [temp2],esi
|
2006-01-03 10:43:31 +01:00
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
; ESI = ECX*ECX+ESI*ESI
|
|
|
|
imul ecx, ecx
|
|
|
|
imul esi, esi
|
|
|
|
add esi, ecx
|
2006-01-03 10:43:31 +01:00
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
xor ecx,ecx ; EDX=SQRT(EBX)
|
|
|
|
xor edx,edx
|
|
|
|
mov eax,1
|
2006-01-03 10:43:31 +01:00
|
|
|
sqrt_loop:
|
2006-08-21 15:06:02 +02:00
|
|
|
; in this moment ecx=edx*edx, eax=1+2*edx
|
2006-01-03 10:43:31 +01:00
|
|
|
add ecx,eax
|
2006-08-21 15:06:02 +02:00
|
|
|
inc eax
|
|
|
|
inc eax
|
2006-01-03 10:43:31 +01:00
|
|
|
inc edx
|
2006-08-21 15:06:02 +02:00
|
|
|
cmp ecx,esi
|
2006-01-03 10:43:31 +01:00
|
|
|
jbe sqrt_loop
|
|
|
|
dec edx
|
2006-08-21 15:06:02 +02:00
|
|
|
mov eax,edx ; EDX=EDX/7
|
2006-01-03 10:43:31 +01:00
|
|
|
mov dl,7
|
|
|
|
div dl
|
2006-08-21 15:06:02 +02:00
|
|
|
and eax,0xFF
|
|
|
|
mov edx,eax ; EDX ? 0 : EDX=1
|
2006-01-03 10:43:31 +01:00
|
|
|
jnz nozeroflag1
|
2006-08-21 15:06:02 +02:00
|
|
|
inc edx
|
2006-01-03 10:43:31 +01:00
|
|
|
nozeroflag1:
|
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
pop eax ; EAX = x distance
|
|
|
|
; ECX=EAX/EDX
|
2006-01-03 10:43:31 +01:00
|
|
|
div dl
|
2006-08-21 15:06:02 +02:00
|
|
|
movzx ecx,al
|
|
|
|
pop ebx
|
2006-01-03 10:43:31 +01:00
|
|
|
pop eax
|
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
cmp byte [sign1], 0
|
|
|
|
jz @f
|
|
|
|
neg ecx
|
|
|
|
@@:
|
|
|
|
add eax, ecx
|
2006-01-03 10:43:31 +01:00
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
push eax ; ESI=[temp2]/EDX
|
2006-01-03 10:43:31 +01:00
|
|
|
mov eax,[temp2]
|
|
|
|
div dl
|
2006-08-21 15:06:02 +02:00
|
|
|
movzx esi,al
|
2006-01-03 10:43:31 +01:00
|
|
|
pop eax
|
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
cmp byte [sign2], 0
|
|
|
|
jz @f
|
|
|
|
neg esi
|
|
|
|
@@:
|
|
|
|
add ebx, esi
|
2006-01-03 10:43:31 +01:00
|
|
|
|
|
|
|
; <===
|
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
; draw point
|
|
|
|
lea ecx, [ebx-2]
|
|
|
|
lea ebx, [eax-2]
|
2006-01-03 10:43:31 +01:00
|
|
|
shl ecx,16
|
|
|
|
add ecx,4
|
|
|
|
shl ebx,16
|
|
|
|
add ebx,4
|
|
|
|
mov eax,13
|
|
|
|
xor edx,edx
|
|
|
|
int 0x40
|
|
|
|
|
|
|
|
popa
|
|
|
|
ret
|
|
|
|
|
|
|
|
; -====- working on images and window -====-
|
|
|
|
|
|
|
|
copy_line: ; copy single line to shape reference area
|
|
|
|
mov ecx,30
|
|
|
|
cpl_loop:
|
|
|
|
lodsb
|
2006-08-21 15:06:02 +02:00
|
|
|
; input is image: 0xFF = white pixel, 0 = black pixel
|
|
|
|
; output is membership boolean: 0 = pixel no, 1 = pixel ok
|
|
|
|
inc eax
|
2006-01-03 10:43:31 +01:00
|
|
|
stosb
|
|
|
|
loop cpl_loop
|
|
|
|
ret
|
|
|
|
|
|
|
|
; DATA
|
|
|
|
|
|
|
|
; environment
|
|
|
|
|
|
|
|
win_ebx dd 0x0
|
|
|
|
win_ecx dd 0x0
|
|
|
|
mouse dd 0xFFFFFFFF
|
2006-08-21 15:06:02 +02:00
|
|
|
|
|
|
|
EYES_END: ; end of code
|
|
|
|
imagedata:
|
|
|
|
; texture is 900 bytes starting from 25th
|
|
|
|
file "eyes.raw":25,900
|
|
|
|
I_END:
|
2006-01-03 10:43:31 +01:00
|
|
|
|
|
|
|
; temporary storage for math routines
|
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
sign1 db ?
|
|
|
|
sign2 db ?
|
|
|
|
align 4
|
|
|
|
temp2 dd ?
|
2006-01-03 10:43:31 +01:00
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
skindata rb 60*30*3
|
|
|
|
winref rb 45*60
|