Subversion Repositories Kolibri OS

Rev

Rev 133 | Rev 485 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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