Rev 4529 | Rev 5154 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2288 | clevermous | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
2455 | mario79 | 3 | ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; |
2288 | clevermous | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
8 | $Revision: 4592 $ |
||
9 | |||
10 | |||
11 | ; check mouse |
||
12 | ; |
||
13 | ; |
||
14 | ; FB00 -> FB0F mouse memory 00 chunk count - FB0A-B x - FB0C-D y |
||
15 | ; FB10 -> FB17 mouse color mem |
||
16 | ; FB21 x move |
||
17 | ; FB22 y move |
||
18 | ; FB30 color temp |
||
19 | ; FB28 high bits temp |
||
20 | ; FB4A -> FB4D FB4A-B x-under - FB4C-D y-under |
||
21 | ; FC00 -> FCFE com1/ps2 buffer |
||
22 | ; FCFF com1/ps2 buffer count starting from FC00 |
||
23 | |||
24 | uglobal |
||
2430 | mario79 | 25 | ;-------------------------------------- |
26 | align 4 |
||
2288 | clevermous | 27 | mousecount dd 0x0 |
28 | mousedata dd 0x0 |
||
2575 | mario79 | 29 | Y_UNDER_sub_CUR_hot_y_add_curh: |
30 | dw 0 |
||
2430 | mario79 | 31 | Y_UNDER_subtraction_CUR_hot_y: |
2575 | mario79 | 32 | dw 0 |
33 | X_UNDER_sub_CUR_hot_x_add_curh: |
||
34 | dw 0 |
||
2430 | mario79 | 35 | X_UNDER_subtraction_CUR_hot_x: |
2575 | mario79 | 36 | dw 0 |
2288 | clevermous | 37 | endg |
38 | |||
39 | iglobal |
||
2430 | mario79 | 40 | ;-------------------------------------- |
41 | align 4 |
||
2288 | clevermous | 42 | mouse_delay dd 10 |
43 | mouse_speed_factor: |
||
44 | dd 3 |
||
45 | mouse_timer_ticks dd 0 |
||
46 | endg |
||
2430 | mario79 | 47 | ;----------------------------------------------------------------------------- |
48 | align 4 |
||
2288 | clevermous | 49 | draw_mouse_under: |
50 | ; return old picture |
||
51 | cmp [_display.restore_cursor], 0 |
||
52 | je @F |
||
53 | |||
54 | pushad |
||
55 | movzx eax, word [X_UNDER] |
||
56 | movzx ebx, word [Y_UNDER] |
||
57 | stdcall [_display.restore_cursor], eax, ebx |
||
58 | popad |
||
59 | ret |
||
2430 | mario79 | 60 | ;-------------------------------------- |
61 | align 4 |
||
2288 | clevermous | 62 | @@: |
63 | pushad |
||
64 | xor ecx, ecx |
||
65 | xor edx, edx |
||
2430 | mario79 | 66 | ;-------------------------------------- |
67 | align 4 |
||
2288 | clevermous | 68 | mres: |
69 | movzx eax, word [X_UNDER] |
||
70 | movzx ebx, word [Y_UNDER] |
||
71 | add eax, ecx |
||
72 | add ebx, edx |
||
73 | push ecx |
||
74 | push edx |
||
75 | push eax |
||
76 | push ebx |
||
77 | mov eax, edx |
||
78 | shl eax, 6 |
||
79 | shl ecx, 2 |
||
80 | add eax, ecx |
||
81 | add eax, mouseunder |
||
82 | mov ecx, [eax] |
||
83 | pop ebx |
||
84 | pop eax |
||
2430 | mario79 | 85 | mov edi, 1 ; force |
86 | or ecx, 0x04000000 ; don't save to mouseunder area |
||
2453 | mario79 | 87 | ; call [putpixel] |
88 | call __sys_putpixel |
||
2288 | clevermous | 89 | pop edx |
90 | pop ecx |
||
91 | inc ecx |
||
92 | cmp ecx, 16 |
||
93 | jnz mres |
||
94 | xor ecx, ecx |
||
95 | inc edx |
||
96 | cmp edx, 24 |
||
97 | jnz mres |
||
98 | popad |
||
99 | ret |
||
2430 | mario79 | 100 | ;----------------------------------------------------------------------------- |
101 | align 4 |
||
2288 | clevermous | 102 | save_draw_mouse: |
103 | cmp [_display.move_cursor], 0 |
||
104 | je .no_hw_cursor |
||
105 | pushad |
||
106 | |||
107 | mov [X_UNDER], ax |
||
108 | mov [Y_UNDER], bx |
||
109 | movzx eax, word [MOUSE_Y] |
||
110 | movzx ebx, word [MOUSE_X] |
||
111 | push eax |
||
112 | push ebx |
||
113 | |||
2446 | mario79 | 114 | ; mov ecx, [Screen_Max_X] |
115 | ; inc ecx |
||
116 | ; mul ecx |
||
117 | mov eax, [d_width_calc_area + eax*4] |
||
118 | |||
2288 | clevermous | 119 | add eax, [_WinMapAddress] |
120 | movzx edx, byte [ebx+eax] |
||
121 | shl edx, 8 |
||
122 | mov esi, [edx+SLOT_BASE+APPDATA.cursor] |
||
123 | |||
124 | cmp esi, [current_cursor] |
||
125 | je .draw |
||
126 | |||
3069 | serge | 127 | mov eax, [TASK_COUNT] |
128 | movzx eax, word [WIN_POS+eax*2] |
||
129 | shl eax, 8 |
||
130 | |||
131 | cmp eax, edx |
||
132 | je @F |
||
133 | |||
134 | mov esi, [def_cursor] |
||
135 | cmp esi, [current_cursor] |
||
136 | je .draw |
||
137 | |||
138 | @@: |
||
2288 | clevermous | 139 | push esi |
140 | call [_display.select_cursor] |
||
141 | mov [current_cursor], esi |
||
2430 | mario79 | 142 | ;-------------------------------------- |
143 | align 4 |
||
2288 | clevermous | 144 | .draw: |
145 | stdcall [_display.move_cursor], esi |
||
146 | popad |
||
147 | ret |
||
2430 | mario79 | 148 | ;-------------------------------------- |
149 | ;align 4 |
||
150 | ;.fail: |
||
151 | ; mov ecx, [def_cursor] |
||
152 | ; mov [edx+SLOT_BASE+APPDATA.cursor], ecx |
||
153 | ; stdcall [_display.move_cursor], ecx ; stdcall: [esp]=ebx,eax |
||
154 | ; popad |
||
155 | ; ret |
||
156 | ;-------------------------------------- |
||
157 | align 4 |
||
2288 | clevermous | 158 | .no_hw_cursor: |
159 | pushad |
||
160 | ; save & draw |
||
161 | mov [X_UNDER], ax |
||
162 | mov [Y_UNDER], bx |
||
163 | push eax |
||
164 | push ebx |
||
165 | mov ecx, 0 |
||
166 | mov edx, 0 |
||
2430 | mario79 | 167 | ;-------------------------------------- |
168 | align 4 |
||
2288 | clevermous | 169 | drm: |
170 | push eax |
||
171 | push ebx |
||
172 | push ecx |
||
173 | push edx |
||
174 | ; helloworld |
||
175 | push ecx |
||
176 | add eax, ecx; save picture under mouse |
||
177 | add ebx, edx |
||
178 | push ecx |
||
2430 | mario79 | 179 | or ecx, 0x04000000 ; don't load to mouseunder area |
2288 | clevermous | 180 | call getpixel |
181 | mov [COLOR_TEMP], ecx |
||
182 | pop ecx |
||
183 | mov eax, edx |
||
184 | shl eax, 6 |
||
185 | shl ecx, 2 |
||
186 | add eax, ecx |
||
187 | add eax, mouseunder |
||
188 | mov ebx, [COLOR_TEMP] |
||
2430 | mario79 | 189 | and ebx, 0xffffff |
2288 | clevermous | 190 | mov [eax], ebx |
191 | pop ecx |
||
192 | mov edi, edx ; y cycle |
||
193 | shl edi, 4 ; *16 bytes per row |
||
194 | add edi, ecx ; x cycle |
||
195 | mov esi, edi |
||
196 | add edi, esi |
||
197 | add edi, esi ; *3 |
||
198 | add edi, [MOUSE_PICTURE] ; we have our str address |
||
199 | mov esi, edi |
||
200 | add esi, 16*24*3 |
||
201 | push ecx |
||
202 | mov ecx, [COLOR_TEMP] |
||
203 | call combine_colors |
||
2430 | mario79 | 204 | and ecx, 0xffffff |
2288 | clevermous | 205 | mov [MOUSE_COLOR_MEM], ecx |
206 | pop ecx |
||
207 | pop edx |
||
208 | pop ecx |
||
209 | pop ebx |
||
210 | pop eax |
||
211 | add eax, ecx ; we have x coord+cycle |
||
212 | add ebx, edx ; and y coord+cycle |
||
213 | push ecx |
||
214 | mov ecx, [MOUSE_COLOR_MEM] |
||
2430 | mario79 | 215 | mov edi, 1 ; force |
216 | or ecx, 0x04000000 ; don't save to mouseunder area |
||
2453 | mario79 | 217 | ; call [putpixel] |
218 | call __sys_putpixel |
||
2288 | clevermous | 219 | pop ecx |
220 | mov ebx, [esp+0] ; pure y coord again |
||
221 | mov eax, [esp+4] ; and x |
||
222 | inc ecx ; +1 cycle |
||
223 | cmp ecx, 16 ; if more than 16 |
||
224 | jnz drm |
||
225 | xor ecx, ecx |
||
226 | inc edx |
||
227 | cmp edx, 24 |
||
228 | jnz drm |
||
229 | add esp, 8 |
||
230 | popad |
||
231 | ret |
||
2430 | mario79 | 232 | ;----------------------------------------------------------------------------- |
233 | align 4 |
||
2288 | clevermous | 234 | combine_colors: |
235 | ; in |
||
236 | ; ecx - color ( 00 RR GG BB ) |
||
237 | ; edi - ref to new color byte |
||
238 | ; esi - ref to alpha byte |
||
239 | ; |
||
240 | ; out |
||
241 | ; ecx - new color ( roughly (ecx*[esi]>>8)+([edi]*[esi]>>8) ) |
||
242 | push eax |
||
243 | push ebx |
||
244 | push edx |
||
245 | push ecx |
||
246 | xor ecx, ecx |
||
247 | ; byte 2 |
||
248 | mov eax, 0xff |
||
249 | sub al, [esi+0] |
||
250 | mov ebx, [esp] |
||
251 | shr ebx, 16 |
||
252 | and ebx, 0xff |
||
253 | mul ebx |
||
254 | shr eax, 8 |
||
255 | add ecx, eax |
||
256 | xor eax, eax |
||
257 | xor ebx, ebx |
||
258 | mov al, [edi+0] |
||
259 | mov bl, [esi+0] |
||
260 | mul ebx |
||
261 | shr eax, 8 |
||
262 | add ecx, eax |
||
263 | shl ecx, 8 |
||
264 | ; byte 1 |
||
265 | mov eax, 0xff |
||
266 | sub al, [esi+1] |
||
267 | mov ebx, [esp] |
||
268 | shr ebx, 8 |
||
269 | and ebx, 0xff |
||
270 | mul ebx |
||
271 | shr eax, 8 |
||
272 | add ecx, eax |
||
273 | xor eax, eax |
||
274 | xor ebx, ebx |
||
275 | mov al, [edi+1] |
||
276 | mov bl, [esi+1] |
||
277 | mul ebx |
||
278 | shr eax, 8 |
||
279 | add ecx, eax |
||
280 | shl ecx, 8 |
||
281 | ; byte 2 |
||
282 | mov eax, 0xff |
||
283 | sub al, [esi+2] |
||
284 | mov ebx, [esp] |
||
285 | and ebx, 0xff |
||
286 | mul ebx |
||
287 | shr eax, 8 |
||
288 | add ecx, eax |
||
289 | xor eax, eax |
||
290 | xor ebx, ebx |
||
291 | mov al, [edi+2] |
||
292 | mov bl, [esi+2] |
||
293 | mul ebx |
||
294 | shr eax, 8 |
||
295 | add ecx, eax |
||
296 | pop eax |
||
297 | pop edx |
||
298 | pop ebx |
||
299 | pop eax |
||
300 | ret |
||
2430 | mario79 | 301 | ;----------------------------------------------------------------------------- |
302 | align 4 |
||
303 | check_mouse_area_for_getpixel: |
||
304 | ; in: |
||
305 | ; eax = x |
||
306 | ; ebx = y |
||
307 | ; out: |
||
308 | ; ecx = new color |
||
309 | push eax ebx |
||
310 | ; check for Y |
||
311 | xor ecx, ecx |
||
312 | mov cx, [Y_UNDER] ; [MOUSE_Y] |
||
2288 | clevermous | 313 | |
2430 | mario79 | 314 | cmp ebx, ecx |
315 | jb .no_mouse_area |
||
316 | add ecx, 23 ; mouse cursor Y size |
||
317 | cmp ebx, ecx |
||
318 | ja .no_mouse_area |
||
319 | ; offset Y |
||
320 | sub bx, [Y_UNDER] ;[MOUSE_Y] |
||
321 | ;-------------------------------------- |
||
322 | ; check for X |
||
323 | xor ecx, ecx |
||
324 | mov cx, [X_UNDER] ;[MOUSE_X] |
||
2288 | clevermous | 325 | cmp eax, ecx |
2430 | mario79 | 326 | jb .no_mouse_area |
327 | add ecx, 15 ; mouse cursor X size |
||
2288 | clevermous | 328 | cmp eax, ecx |
2430 | mario79 | 329 | ja .no_mouse_area |
330 | ; offset X |
||
331 | sub ax, [X_UNDER] ;[MOUSE_X] |
||
332 | ;-------------------------------------- |
||
333 | ; eax = offset x |
||
334 | ; ebx = offset y |
||
335 | shl ebx, 6 ;y |
||
336 | shl eax, 2 ;x |
||
337 | add eax, ebx |
||
338 | add eax, mouseunder |
||
339 | mov ecx, [eax] |
||
340 | and ecx, 0xffffff |
||
341 | or ecx, 0xff000000 |
||
342 | pop ebx eax |
||
2288 | clevermous | 343 | ret |
2430 | mario79 | 344 | ;-------------------------------------- |
345 | align 4 |
||
346 | .no_mouse_area: |
||
347 | xor ecx, ecx |
||
348 | pop ebx eax |
||
349 | ret |
||
350 | ;----------------------------------------------------------------------------- |
||
351 | align 4 |
||
352 | check_mouse_area_for_putpixel: |
||
353 | ; in: |
||
354 | ; ecx = x shl 16 + y |
||
355 | ; eax = color |
||
356 | ; out: |
||
357 | ; eax = new color |
||
358 | push eax |
||
359 | ; check for Y |
||
360 | mov ax, [Y_UNDER] ; [MOUSE_Y] |
||
361 | cmp cx, ax |
||
362 | jb .no_mouse_area |
||
363 | add ax, 23 ; mouse cursor Y size |
||
364 | cmp cx, ax |
||
365 | ja .no_mouse_area |
||
366 | ; offset Y |
||
367 | sub cx, [Y_UNDER] ;[MOUSE_Y] |
||
368 | mov ax, cx |
||
369 | shl eax, 16 |
||
370 | ;-------------------------------------- |
||
371 | ; check for X |
||
372 | mov ax, [X_UNDER] ;[MOUSE_X] |
||
373 | shr ecx, 16 |
||
374 | cmp cx, ax |
||
375 | jb .no_mouse_area |
||
376 | add ax, 15 ; mouse cursor X size |
||
377 | cmp cx, ax |
||
378 | ja .no_mouse_area |
||
379 | ; offset X |
||
380 | sub cx, [X_UNDER] ;[MOUSE_X] |
||
381 | mov ax, cx |
||
382 | ;-------------------------------------- |
||
383 | ; eax = (offset y) shl 16 + (offset x) |
||
2288 | clevermous | 384 | |
2430 | mario79 | 385 | pop ecx |
386 | |||
387 | push eax ebx |
||
388 | |||
389 | mov ebx, eax |
||
390 | shr ebx, 16 ;y |
||
391 | and eax, 0xffff ;x |
||
392 | |||
393 | shl ebx, 6 |
||
394 | shl eax, 2 |
||
395 | add eax, ebx |
||
396 | add eax, mouseunder |
||
397 | and ecx, 0xFFFFFF |
||
398 | mov [eax], ecx |
||
399 | |||
400 | pop ebx eax |
||
401 | |||
402 | push esi edi |
||
403 | rol eax, 16 |
||
404 | movzx edi, ax ; y cycle |
||
405 | shl edi, 4 ; *16 bytes per row |
||
406 | shr eax, 16 |
||
407 | add edi, eax ; x cycle |
||
408 | lea edi, [edi*3] |
||
409 | add edi, [MOUSE_PICTURE] ; we have our str address |
||
410 | mov esi, edi |
||
411 | add esi, 16*24*3 |
||
412 | call combine_colors |
||
413 | pop edi esi |
||
414 | ;-------------------------------------- |
||
415 | align 4 |
||
416 | .end: |
||
417 | mov eax, ecx |
||
2288 | clevermous | 418 | ret |
2430 | mario79 | 419 | ;-------------------------------------- |
420 | align 4 |
||
421 | .no_mouse_area: |
||
2288 | clevermous | 422 | pop eax |
423 | ret |
||
2430 | mario79 | 424 | ;----------------------------------------------------------------------------- |
425 | align 4 |
||
426 | __sys_draw_pointer: |
||
2288 | clevermous | 427 | pushad |
428 | movzx ecx, word [X_UNDER] |
||
429 | movzx edx, word [Y_UNDER] |
||
430 | movzx ebx, word [MOUSE_Y] |
||
431 | movzx eax, word [MOUSE_X] |
||
2450 | mario79 | 432 | cmp [redrawmouse_unconditional], 0 |
433 | je @f |
||
434 | mov [redrawmouse_unconditional], 0 |
||
435 | jmp redrawmouse |
||
436 | ;-------------------------------------- |
||
437 | align 4 |
||
438 | @@: |
||
2288 | clevermous | 439 | cmp eax, ecx |
440 | jne redrawmouse |
||
441 | cmp ebx, edx |
||
2430 | mario79 | 442 | je nodmp |
443 | ;-------------------------------------- |
||
444 | align 4 |
||
2288 | clevermous | 445 | redrawmouse: |
446 | pushfd |
||
447 | cli |
||
448 | call draw_mouse_under |
||
449 | call save_draw_mouse |
||
2430 | mario79 | 450 | |
2448 | mario79 | 451 | ; mov eax, [_display.select_cursor] |
452 | ; test eax, eax |
||
453 | ; jz @f |
||
454 | cmp [_display.select_cursor], select_cursor |
||
455 | jne @f |
||
2430 | mario79 | 456 | |
457 | xor eax, eax |
||
458 | mov esi, [current_cursor] |
||
459 | |||
460 | mov ax, [Y_UNDER] |
||
461 | sub eax, [esi+CURSOR.hot_y] |
||
2575 | mario79 | 462 | mov [Y_UNDER_subtraction_CUR_hot_y], ax |
2430 | mario79 | 463 | add eax, [cur.h] |
2575 | mario79 | 464 | mov [Y_UNDER_sub_CUR_hot_y_add_curh], ax |
2430 | mario79 | 465 | |
466 | mov ax, [X_UNDER] |
||
467 | sub eax, [esi+CURSOR.hot_x] |
||
2575 | mario79 | 468 | mov [X_UNDER_subtraction_CUR_hot_x], ax |
2430 | mario79 | 469 | add eax, [cur.w] |
2575 | mario79 | 470 | mov [X_UNDER_sub_CUR_hot_x_add_curh], ax |
2430 | mario79 | 471 | ;-------------------------------------- |
472 | align 4 |
||
473 | @@: |
||
2288 | clevermous | 474 | popfd |
2430 | mario79 | 475 | ;-------------------------------------- |
476 | align 4 |
||
2288 | clevermous | 477 | nodmp: |
478 | popad |
||
479 | ret |
||
2430 | mario79 | 480 | ;----------------------------------------------------------------------------- |
481 | align 4 |
||
4592 | hidnplayr | 482 | proc set_mouse_data stdcall uses edx, BtnState:dword, XMoving:dword, YMoving:dword, VScroll:dword, HScroll:dword |
2288 | clevermous | 483 | |
484 | mov eax, [BtnState] |
||
4529 | hidnplayr | 485 | and eax, 0x3FFFFFFF ; Top 2 bits are used to flag absolute movements |
2288 | clevermous | 486 | mov [BTN_DOWN], eax |
4592 | hidnplayr | 487 | ;-------------------------------------- |
2288 | clevermous | 488 | mov eax, [XMoving] |
4529 | hidnplayr | 489 | test [BtnState], 0x80000000 |
4592 | hidnplayr | 490 | jnz .absolute_x |
2288 | clevermous | 491 | call mouse_acceleration |
4592 | hidnplayr | 492 | add ax, [MOUSE_X] |
2288 | clevermous | 493 | cmp ax, 0 |
4592 | hidnplayr | 494 | jge .check_x |
2288 | clevermous | 495 | mov eax, 0 |
4592 | hidnplayr | 496 | jmp .set_x |
497 | .absolute_x: |
||
498 | mov edx, [_display.width] |
||
499 | mul edx |
||
500 | shr eax, 15 |
||
501 | .check_x: |
||
502 | cmp ax, word[Screen_Max_X] |
||
503 | jl .set_x |
||
504 | mov ax, word[Screen_Max_X] |
||
505 | .set_x: |
||
506 | mov [MOUSE_X], ax |
||
2430 | mario79 | 507 | ;-------------------------------------- |
2288 | clevermous | 508 | mov eax, [YMoving] |
4529 | hidnplayr | 509 | test [BtnState], 0x40000000 |
4592 | hidnplayr | 510 | jnz .absolute_y |
2288 | clevermous | 511 | neg eax |
512 | call mouse_acceleration |
||
4592 | hidnplayr | 513 | add ax, [MOUSE_Y] |
2288 | clevermous | 514 | cmp ax, 0 |
4592 | hidnplayr | 515 | jge .check_y |
2288 | clevermous | 516 | mov ax, 0 |
4592 | hidnplayr | 517 | jmp .set_y |
518 | .absolute_y: |
||
519 | mov edx, [_display.height] |
||
520 | mul edx |
||
521 | shr eax, 15 |
||
522 | .check_y: |
||
523 | cmp ax, word[Screen_Max_Y] |
||
524 | jl .set_y |
||
525 | mov ax, word[Screen_Max_Y] |
||
526 | .set_y: |
||
527 | mov [MOUSE_Y], ax |
||
2430 | mario79 | 528 | ;-------------------------------------- |
2288 | clevermous | 529 | mov eax, [VScroll] |
530 | add [MOUSE_SCROLL_V], ax |
||
531 | |||
532 | mov eax, [HScroll] |
||
533 | add [MOUSE_SCROLL_H], ax |
||
534 | |||
535 | mov [mouse_active], 1 |
||
536 | mov eax, [timer_ticks] |
||
537 | mov [mouse_timer_ticks], eax |
||
3534 | clevermous | 538 | call wakeup_osloop |
2288 | clevermous | 539 | ret |
540 | endp |
||
2430 | mario79 | 541 | ;----------------------------------------------------------------------------- |
542 | align 4 |
||
2288 | clevermous | 543 | mouse_acceleration: |
544 | push eax |
||
545 | mov eax, [timer_ticks] |
||
546 | sub eax, [mouse_timer_ticks] |
||
547 | cmp eax, [mouse_delay] |
||
548 | pop eax |
||
549 | ja @f |
||
550 | ;push edx |
||
551 | imul eax, [mouse_speed_factor] |
||
552 | ;pop edx |
||
2430 | mario79 | 553 | ;-------------------------------------- |
554 | align 4 |
||
2288 | clevermous | 555 | @@: |
556 | ret |
||
2430 | mario79 | 557 | ;----------------------------------------------------------------------------- |