Rev 2455 | Rev 3069 | 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: 2575 $ |
||
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 | |||
127 | push esi |
||
128 | call [_display.select_cursor] |
||
129 | mov [current_cursor], esi |
||
2430 | mario79 | 130 | ;-------------------------------------- |
131 | align 4 |
||
2288 | clevermous | 132 | .draw: |
133 | stdcall [_display.move_cursor], esi |
||
134 | popad |
||
135 | ret |
||
2430 | mario79 | 136 | ;-------------------------------------- |
137 | ;align 4 |
||
138 | ;.fail: |
||
139 | ; mov ecx, [def_cursor] |
||
140 | ; mov [edx+SLOT_BASE+APPDATA.cursor], ecx |
||
141 | ; stdcall [_display.move_cursor], ecx ; stdcall: [esp]=ebx,eax |
||
142 | ; popad |
||
143 | ; ret |
||
144 | ;-------------------------------------- |
||
145 | align 4 |
||
2288 | clevermous | 146 | .no_hw_cursor: |
147 | pushad |
||
148 | ; save & draw |
||
149 | mov [X_UNDER], ax |
||
150 | mov [Y_UNDER], bx |
||
151 | push eax |
||
152 | push ebx |
||
153 | mov ecx, 0 |
||
154 | mov edx, 0 |
||
2430 | mario79 | 155 | ;-------------------------------------- |
156 | align 4 |
||
2288 | clevermous | 157 | drm: |
158 | push eax |
||
159 | push ebx |
||
160 | push ecx |
||
161 | push edx |
||
162 | ; helloworld |
||
163 | push ecx |
||
164 | add eax, ecx; save picture under mouse |
||
165 | add ebx, edx |
||
166 | push ecx |
||
2430 | mario79 | 167 | or ecx, 0x04000000 ; don't load to mouseunder area |
2288 | clevermous | 168 | call getpixel |
169 | mov [COLOR_TEMP], ecx |
||
170 | pop ecx |
||
171 | mov eax, edx |
||
172 | shl eax, 6 |
||
173 | shl ecx, 2 |
||
174 | add eax, ecx |
||
175 | add eax, mouseunder |
||
176 | mov ebx, [COLOR_TEMP] |
||
2430 | mario79 | 177 | and ebx, 0xffffff |
2288 | clevermous | 178 | mov [eax], ebx |
179 | pop ecx |
||
180 | mov edi, edx ; y cycle |
||
181 | shl edi, 4 ; *16 bytes per row |
||
182 | add edi, ecx ; x cycle |
||
183 | mov esi, edi |
||
184 | add edi, esi |
||
185 | add edi, esi ; *3 |
||
186 | add edi, [MOUSE_PICTURE] ; we have our str address |
||
187 | mov esi, edi |
||
188 | add esi, 16*24*3 |
||
189 | push ecx |
||
190 | mov ecx, [COLOR_TEMP] |
||
191 | call combine_colors |
||
2430 | mario79 | 192 | and ecx, 0xffffff |
2288 | clevermous | 193 | mov [MOUSE_COLOR_MEM], ecx |
194 | pop ecx |
||
195 | pop edx |
||
196 | pop ecx |
||
197 | pop ebx |
||
198 | pop eax |
||
199 | add eax, ecx ; we have x coord+cycle |
||
200 | add ebx, edx ; and y coord+cycle |
||
201 | push ecx |
||
202 | mov ecx, [MOUSE_COLOR_MEM] |
||
2430 | mario79 | 203 | mov edi, 1 ; force |
204 | or ecx, 0x04000000 ; don't save to mouseunder area |
||
2453 | mario79 | 205 | ; call [putpixel] |
206 | call __sys_putpixel |
||
2288 | clevermous | 207 | pop ecx |
208 | mov ebx, [esp+0] ; pure y coord again |
||
209 | mov eax, [esp+4] ; and x |
||
210 | inc ecx ; +1 cycle |
||
211 | cmp ecx, 16 ; if more than 16 |
||
212 | jnz drm |
||
213 | xor ecx, ecx |
||
214 | inc edx |
||
215 | cmp edx, 24 |
||
216 | jnz drm |
||
217 | add esp, 8 |
||
218 | popad |
||
219 | ret |
||
2430 | mario79 | 220 | ;----------------------------------------------------------------------------- |
221 | align 4 |
||
2288 | clevermous | 222 | combine_colors: |
223 | ; in |
||
224 | ; ecx - color ( 00 RR GG BB ) |
||
225 | ; edi - ref to new color byte |
||
226 | ; esi - ref to alpha byte |
||
227 | ; |
||
228 | ; out |
||
229 | ; ecx - new color ( roughly (ecx*[esi]>>8)+([edi]*[esi]>>8) ) |
||
230 | push eax |
||
231 | push ebx |
||
232 | push edx |
||
233 | push ecx |
||
234 | xor ecx, ecx |
||
235 | ; byte 2 |
||
236 | mov eax, 0xff |
||
237 | sub al, [esi+0] |
||
238 | mov ebx, [esp] |
||
239 | shr ebx, 16 |
||
240 | and ebx, 0xff |
||
241 | mul ebx |
||
242 | shr eax, 8 |
||
243 | add ecx, eax |
||
244 | xor eax, eax |
||
245 | xor ebx, ebx |
||
246 | mov al, [edi+0] |
||
247 | mov bl, [esi+0] |
||
248 | mul ebx |
||
249 | shr eax, 8 |
||
250 | add ecx, eax |
||
251 | shl ecx, 8 |
||
252 | ; byte 1 |
||
253 | mov eax, 0xff |
||
254 | sub al, [esi+1] |
||
255 | mov ebx, [esp] |
||
256 | shr ebx, 8 |
||
257 | and ebx, 0xff |
||
258 | mul ebx |
||
259 | shr eax, 8 |
||
260 | add ecx, eax |
||
261 | xor eax, eax |
||
262 | xor ebx, ebx |
||
263 | mov al, [edi+1] |
||
264 | mov bl, [esi+1] |
||
265 | mul ebx |
||
266 | shr eax, 8 |
||
267 | add ecx, eax |
||
268 | shl ecx, 8 |
||
269 | ; byte 2 |
||
270 | mov eax, 0xff |
||
271 | sub al, [esi+2] |
||
272 | mov ebx, [esp] |
||
273 | and ebx, 0xff |
||
274 | mul ebx |
||
275 | shr eax, 8 |
||
276 | add ecx, eax |
||
277 | xor eax, eax |
||
278 | xor ebx, ebx |
||
279 | mov al, [edi+2] |
||
280 | mov bl, [esi+2] |
||
281 | mul ebx |
||
282 | shr eax, 8 |
||
283 | add ecx, eax |
||
284 | pop eax |
||
285 | pop edx |
||
286 | pop ebx |
||
287 | pop eax |
||
288 | ret |
||
2430 | mario79 | 289 | ;----------------------------------------------------------------------------- |
290 | align 4 |
||
291 | check_mouse_area_for_getpixel: |
||
292 | ; in: |
||
293 | ; eax = x |
||
294 | ; ebx = y |
||
295 | ; out: |
||
296 | ; ecx = new color |
||
297 | push eax ebx |
||
298 | ; check for Y |
||
299 | xor ecx, ecx |
||
300 | mov cx, [Y_UNDER] ; [MOUSE_Y] |
||
2288 | clevermous | 301 | |
2430 | mario79 | 302 | cmp ebx, ecx |
303 | jb .no_mouse_area |
||
304 | add ecx, 23 ; mouse cursor Y size |
||
305 | cmp ebx, ecx |
||
306 | ja .no_mouse_area |
||
307 | ; offset Y |
||
308 | sub bx, [Y_UNDER] ;[MOUSE_Y] |
||
309 | ;-------------------------------------- |
||
310 | ; check for X |
||
311 | xor ecx, ecx |
||
312 | mov cx, [X_UNDER] ;[MOUSE_X] |
||
2288 | clevermous | 313 | cmp eax, ecx |
2430 | mario79 | 314 | jb .no_mouse_area |
315 | add ecx, 15 ; mouse cursor X size |
||
2288 | clevermous | 316 | cmp eax, ecx |
2430 | mario79 | 317 | ja .no_mouse_area |
318 | ; offset X |
||
319 | sub ax, [X_UNDER] ;[MOUSE_X] |
||
320 | ;-------------------------------------- |
||
321 | ; eax = offset x |
||
322 | ; ebx = offset y |
||
323 | shl ebx, 6 ;y |
||
324 | shl eax, 2 ;x |
||
325 | add eax, ebx |
||
326 | add eax, mouseunder |
||
327 | mov ecx, [eax] |
||
328 | and ecx, 0xffffff |
||
329 | or ecx, 0xff000000 |
||
330 | pop ebx eax |
||
2288 | clevermous | 331 | ret |
2430 | mario79 | 332 | ;-------------------------------------- |
333 | align 4 |
||
334 | .no_mouse_area: |
||
335 | xor ecx, ecx |
||
336 | pop ebx eax |
||
337 | ret |
||
338 | ;----------------------------------------------------------------------------- |
||
339 | align 4 |
||
340 | check_mouse_area_for_putpixel: |
||
341 | ; in: |
||
342 | ; ecx = x shl 16 + y |
||
343 | ; eax = color |
||
344 | ; out: |
||
345 | ; eax = new color |
||
346 | push eax |
||
347 | ; check for Y |
||
348 | mov ax, [Y_UNDER] ; [MOUSE_Y] |
||
349 | cmp cx, ax |
||
350 | jb .no_mouse_area |
||
351 | add ax, 23 ; mouse cursor Y size |
||
352 | cmp cx, ax |
||
353 | ja .no_mouse_area |
||
354 | ; offset Y |
||
355 | sub cx, [Y_UNDER] ;[MOUSE_Y] |
||
356 | mov ax, cx |
||
357 | shl eax, 16 |
||
358 | ;-------------------------------------- |
||
359 | ; check for X |
||
360 | mov ax, [X_UNDER] ;[MOUSE_X] |
||
361 | shr ecx, 16 |
||
362 | cmp cx, ax |
||
363 | jb .no_mouse_area |
||
364 | add ax, 15 ; mouse cursor X size |
||
365 | cmp cx, ax |
||
366 | ja .no_mouse_area |
||
367 | ; offset X |
||
368 | sub cx, [X_UNDER] ;[MOUSE_X] |
||
369 | mov ax, cx |
||
370 | ;-------------------------------------- |
||
371 | ; eax = (offset y) shl 16 + (offset x) |
||
2288 | clevermous | 372 | |
2430 | mario79 | 373 | pop ecx |
374 | |||
375 | push eax ebx |
||
376 | |||
377 | mov ebx, eax |
||
378 | shr ebx, 16 ;y |
||
379 | and eax, 0xffff ;x |
||
380 | |||
381 | shl ebx, 6 |
||
382 | shl eax, 2 |
||
383 | add eax, ebx |
||
384 | add eax, mouseunder |
||
385 | and ecx, 0xFFFFFF |
||
386 | mov [eax], ecx |
||
387 | |||
388 | pop ebx eax |
||
389 | |||
390 | push esi edi |
||
391 | rol eax, 16 |
||
392 | movzx edi, ax ; y cycle |
||
393 | shl edi, 4 ; *16 bytes per row |
||
394 | shr eax, 16 |
||
395 | add edi, eax ; x cycle |
||
396 | lea edi, [edi*3] |
||
397 | add edi, [MOUSE_PICTURE] ; we have our str address |
||
398 | mov esi, edi |
||
399 | add esi, 16*24*3 |
||
400 | call combine_colors |
||
401 | pop edi esi |
||
402 | ;-------------------------------------- |
||
403 | align 4 |
||
404 | .end: |
||
405 | mov eax, ecx |
||
2288 | clevermous | 406 | ret |
2430 | mario79 | 407 | ;-------------------------------------- |
408 | align 4 |
||
409 | .no_mouse_area: |
||
2288 | clevermous | 410 | pop eax |
411 | ret |
||
2430 | mario79 | 412 | ;----------------------------------------------------------------------------- |
413 | align 4 |
||
414 | __sys_draw_pointer: |
||
2288 | clevermous | 415 | pushad |
416 | movzx ecx, word [X_UNDER] |
||
417 | movzx edx, word [Y_UNDER] |
||
418 | movzx ebx, word [MOUSE_Y] |
||
419 | movzx eax, word [MOUSE_X] |
||
2450 | mario79 | 420 | cmp [redrawmouse_unconditional], 0 |
421 | je @f |
||
422 | mov [redrawmouse_unconditional], 0 |
||
423 | jmp redrawmouse |
||
424 | ;-------------------------------------- |
||
425 | align 4 |
||
426 | @@: |
||
2288 | clevermous | 427 | cmp eax, ecx |
428 | jne redrawmouse |
||
429 | cmp ebx, edx |
||
2430 | mario79 | 430 | je nodmp |
431 | ;-------------------------------------- |
||
432 | align 4 |
||
2288 | clevermous | 433 | redrawmouse: |
434 | pushfd |
||
435 | cli |
||
436 | call draw_mouse_under |
||
437 | call save_draw_mouse |
||
2430 | mario79 | 438 | |
2448 | mario79 | 439 | ; mov eax, [_display.select_cursor] |
440 | ; test eax, eax |
||
441 | ; jz @f |
||
442 | cmp [_display.select_cursor], select_cursor |
||
443 | jne @f |
||
2430 | mario79 | 444 | |
445 | xor eax, eax |
||
446 | mov esi, [current_cursor] |
||
447 | |||
448 | mov ax, [Y_UNDER] |
||
449 | sub eax, [esi+CURSOR.hot_y] |
||
2575 | mario79 | 450 | mov [Y_UNDER_subtraction_CUR_hot_y], ax |
2430 | mario79 | 451 | add eax, [cur.h] |
2575 | mario79 | 452 | mov [Y_UNDER_sub_CUR_hot_y_add_curh], ax |
2430 | mario79 | 453 | |
454 | mov ax, [X_UNDER] |
||
455 | sub eax, [esi+CURSOR.hot_x] |
||
2575 | mario79 | 456 | mov [X_UNDER_subtraction_CUR_hot_x], ax |
2430 | mario79 | 457 | add eax, [cur.w] |
2575 | mario79 | 458 | mov [X_UNDER_sub_CUR_hot_x_add_curh], ax |
2430 | mario79 | 459 | ;-------------------------------------- |
460 | align 4 |
||
461 | @@: |
||
2288 | clevermous | 462 | popfd |
2430 | mario79 | 463 | ;-------------------------------------- |
464 | align 4 |
||
2288 | clevermous | 465 | nodmp: |
466 | popad |
||
467 | ret |
||
2430 | mario79 | 468 | ;----------------------------------------------------------------------------- |
469 | align 4 |
||
2288 | clevermous | 470 | proc set_mouse_data stdcall, BtnState:dword, XMoving:dword, YMoving:dword, VScroll:dword, HScroll:dword |
471 | |||
472 | mov eax, [BtnState] |
||
473 | mov [BTN_DOWN], eax |
||
474 | |||
475 | mov eax, [XMoving] |
||
476 | call mouse_acceleration |
||
477 | add ax, [MOUSE_X];[XCoordinate] |
||
478 | cmp ax, 0 |
||
479 | jge @@M1 |
||
480 | mov eax, 0 |
||
481 | jmp @@M2 |
||
2430 | mario79 | 482 | ;-------------------------------------- |
483 | align 4 |
||
2288 | clevermous | 484 | @@M1: |
485 | cmp ax, [Screen_Max_X];ScreenLength |
||
486 | jl @@M2 |
||
487 | mov ax, [Screen_Max_X];ScreenLength-1 |
||
2430 | mario79 | 488 | ;-------------------------------------- |
489 | align 4 |
||
2288 | clevermous | 490 | @@M2: |
491 | mov [MOUSE_X], ax;[XCoordinate] |
||
492 | |||
493 | mov eax, [YMoving] |
||
494 | neg eax |
||
495 | call mouse_acceleration |
||
496 | |||
497 | add ax, [MOUSE_Y];[YCoordinate] |
||
498 | cmp ax, 0 |
||
499 | jge @@M3 |
||
500 | mov ax, 0 |
||
501 | jmp @@M4 |
||
2430 | mario79 | 502 | ;-------------------------------------- |
503 | align 4 |
||
2288 | clevermous | 504 | @@M3: |
505 | cmp ax, [Screen_Max_Y];ScreenHeigth |
||
506 | jl @@M4 |
||
507 | mov ax, [Screen_Max_Y];ScreenHeigth-1 |
||
2430 | mario79 | 508 | ;-------------------------------------- |
509 | align 4 |
||
2288 | clevermous | 510 | @@M4: |
511 | mov [MOUSE_Y], ax;[YCoordinate] |
||
512 | |||
513 | mov eax, [VScroll] |
||
514 | add [MOUSE_SCROLL_V], ax |
||
515 | |||
516 | mov eax, [HScroll] |
||
517 | add [MOUSE_SCROLL_H], ax |
||
518 | |||
519 | mov [mouse_active], 1 |
||
520 | mov eax, [timer_ticks] |
||
521 | mov [mouse_timer_ticks], eax |
||
522 | ret |
||
523 | endp |
||
2430 | mario79 | 524 | ;----------------------------------------------------------------------------- |
525 | align 4 |
||
2288 | clevermous | 526 | mouse_acceleration: |
527 | push eax |
||
528 | mov eax, [timer_ticks] |
||
529 | sub eax, [mouse_timer_ticks] |
||
530 | cmp eax, [mouse_delay] |
||
531 | pop eax |
||
532 | ja @f |
||
533 | ;push edx |
||
534 | imul eax, [mouse_speed_factor] |
||
535 | ;pop edx |
||
2430 | mario79 | 536 | ;-------------------------------------- |
537 | align 4 |
||
2288 | clevermous | 538 | @@: |
539 | ret |
||
2430 | mario79 | 540 | ;----------------------------------------------------------------------------- |