Subversion Repositories Kolibri OS

Rev

Rev 2987 | Rev 3555 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2465 Serge 3
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
431 serge 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
593 mikedld 8
$Revision: 3232 $
9
 
10
 
33 mario79 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
2434 Serge 25
;--------------------------------------
26
align 4
33 mario79 27
  mousecount  dd  0x0
28
  mousedata   dd  0x0
2987 Serge 29
Y_UNDER_sub_CUR_hot_y_add_curh:
30
        dw 0
2434 Serge 31
Y_UNDER_subtraction_CUR_hot_y:
2987 Serge 32
        dw 0
33
X_UNDER_sub_CUR_hot_x_add_curh:
34
        dw 0
2434 Serge 35
X_UNDER_subtraction_CUR_hot_x:
2987 Serge 36
        dw 0
33 mario79 37
endg
38
 
473 diamond 39
iglobal
2434 Serge 40
;--------------------------------------
41
align 4
42
mouse_delay        dd 10
43
mouse_speed_factor:
44
                    dd 3
479 kastigar 45
mouse_timer_ticks  dd 0
473 diamond 46
endg
2434 Serge 47
;-----------------------------------------------------------------------------
48
align 4
33 mario79 49
draw_mouse_under:
2434 Serge 50
        ; return old picture
51
        cmp     [_display.restore_cursor], 0
52
        je      @F
214 serge 53
 
2434 Serge 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
60
;--------------------------------------
61
align 4
214 serge 62
@@:
2434 Serge 63
        pushad
64
        xor     ecx, ecx
65
        xor     edx, edx
66
;--------------------------------------
67
align 4
119 mario79 68
mres:
2434 Serge 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
85
        mov     edi, 1 ; force
86
        or      ecx, 0x04000000  ; don't save to mouseunder area
2465 Serge 87
;        call    [putpixel]
88
        call    __sys_putpixel
2434 Serge 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
100
;-----------------------------------------------------------------------------
101
align 4
33 mario79 102
save_draw_mouse:
2434 Serge 103
        cmp     [_display.move_cursor], 0
104
        je      .no_hw_cursor
105
        pushad
214 serge 106
 
2434 Serge 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
221 serge 113
 
2465 Serge 114
;        mov     ecx, [Screen_Max_X]
115
;        inc     ecx
116
;        mul     ecx
117
        mov     eax, [d_width_calc_area + eax*4]
118
 
2434 Serge 119
        add     eax, [_WinMapAddress]
120
        movzx   edx, byte [ebx+eax]
121
        shl     edx, 8
122
        mov     esi, [edx+SLOT_BASE+APPDATA.cursor]
221 serge 123
 
2434 Serge 124
        cmp     esi, [current_cursor]
125
        je      .draw
230 serge 126
 
3232 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
@@:
2434 Serge 139
        push    esi
140
        call    [_display.select_cursor]
141
        mov     [current_cursor], esi
142
;--------------------------------------
143
align 4
630 serge 144
.draw:
2434 Serge 145
        stdcall [_display.move_cursor], esi
146
        popad
147
        ret
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
630 serge 158
.no_hw_cursor:
2434 Serge 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
167
;--------------------------------------
168
align 4
119 mario79 169
drm:
2434 Serge 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
179
        or      ecx, 0x04000000  ; don't load to mouseunder area
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]
189
        and     ebx, 0xffffff
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
204
        and     ecx, 0xffffff
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]
215
        mov     edi, 1 ; force
216
        or      ecx, 0x04000000  ; don't save to mouseunder area
2465 Serge 217
;        call    [putpixel]
218
        call    __sys_putpixel
2434 Serge 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
232
;-----------------------------------------------------------------------------
233
align 4
33 mario79 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) )
2434 Serge 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
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]
33 mario79 313
 
2434 Serge 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]
325
        cmp     eax, ecx
326
        jb      .no_mouse_area
327
        add     ecx, 15  ; mouse cursor X size
328
        cmp     eax, ecx
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
343
        ret
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)
33 mario79 384
 
2434 Serge 385
        pop     ecx
33 mario79 386
 
2434 Serge 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
418
        ret
419
;--------------------------------------
420
align 4
421
.no_mouse_area:
422
        pop     eax
423
        ret
424
;-----------------------------------------------------------------------------
425
align 4
33 mario79 426
__sys_draw_pointer:
2434 Serge 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]
2465 Serge 432
        cmp     [redrawmouse_unconditional], 0
433
        je      @f
434
        mov     [redrawmouse_unconditional], 0
435
        jmp     redrawmouse
436
;--------------------------------------
437
align 4
438
@@:
2434 Serge 439
        cmp     eax, ecx
440
        jne     redrawmouse
441
        cmp     ebx, edx
442
        je      nodmp
443
;--------------------------------------
444
align 4
445
redrawmouse:
446
        pushfd
447
        cli
448
        call    draw_mouse_under
449
        call    save_draw_mouse
450
 
2465 Serge 451
;        mov     eax, [_display.select_cursor]
452
;        test    eax, eax
453
;        jz      @f
454
        cmp     [_display.select_cursor], select_cursor
455
        jne     @f
2434 Serge 456
 
457
        xor     eax, eax
458
        mov     esi, [current_cursor]
459
 
460
        mov     ax, [Y_UNDER]
461
        sub     eax, [esi+CURSOR.hot_y]
2987 Serge 462
        mov     [Y_UNDER_subtraction_CUR_hot_y], ax
2434 Serge 463
        add     eax, [cur.h]
2987 Serge 464
        mov     [Y_UNDER_sub_CUR_hot_y_add_curh], ax
2434 Serge 465
 
466
        mov     ax, [X_UNDER]
467
        sub     eax, [esi+CURSOR.hot_x]
2987 Serge 468
        mov     [X_UNDER_subtraction_CUR_hot_x], ax
2434 Serge 469
        add     eax, [cur.w]
2987 Serge 470
        mov     [X_UNDER_sub_CUR_hot_x_add_curh], ax
2434 Serge 471
;--------------------------------------
472
align 4
119 mario79 473
@@:
2434 Serge 474
        popfd
475
;--------------------------------------
476
align 4
119 mario79 477
nodmp:
2434 Serge 478
        popad
479
        ret
480
;-----------------------------------------------------------------------------
481
align 4
479 kastigar 482
proc set_mouse_data stdcall, BtnState:dword, XMoving:dword, YMoving:dword, VScroll:dword, HScroll:dword
630 serge 483
 
2434 Serge 484
        mov     eax, [BtnState]
485
        mov     [BTN_DOWN], eax
479 kastigar 486
 
2434 Serge 487
        mov     eax, [XMoving]
488
        call    mouse_acceleration
489
        add     ax, [MOUSE_X];[XCoordinate]
490
        cmp     ax, 0
491
        jge     @@M1
492
        mov     eax, 0
493
        jmp     @@M2
494
;--------------------------------------
495
align 4
479 kastigar 496
@@M1:
2434 Serge 497
        cmp     ax, [Screen_Max_X];ScreenLength
498
        jl      @@M2
499
        mov     ax, [Screen_Max_X];ScreenLength-1
500
;--------------------------------------
501
align 4
479 kastigar 502
@@M2:
2434 Serge 503
        mov     [MOUSE_X], ax;[XCoordinate]
479 kastigar 504
 
2434 Serge 505
        mov     eax, [YMoving]
506
        neg     eax
507
        call    mouse_acceleration
479 kastigar 508
 
2434 Serge 509
        add     ax, [MOUSE_Y];[YCoordinate]
510
        cmp     ax, 0
511
        jge     @@M3
512
        mov     ax, 0
513
        jmp     @@M4
514
;--------------------------------------
515
align 4
479 kastigar 516
@@M3:
2434 Serge 517
        cmp     ax, [Screen_Max_Y];ScreenHeigth
518
        jl      @@M4
519
        mov     ax, [Screen_Max_Y];ScreenHeigth-1
520
;--------------------------------------
521
align 4
479 kastigar 522
@@M4:
2434 Serge 523
        mov     [MOUSE_Y], ax;[YCoordinate]
479 kastigar 524
 
2434 Serge 525
        mov     eax, [VScroll]
526
        add     [MOUSE_SCROLL_V], ax
630 serge 527
 
2434 Serge 528
        mov     eax, [HScroll]
529
        add     [MOUSE_SCROLL_H], ax
479 kastigar 530
 
2434 Serge 531
        mov     [mouse_active], 1
532
        mov     eax, [timer_ticks]
533
        mov     [mouse_timer_ticks], eax
534
        ret
479 kastigar 535
endp
2434 Serge 536
;-----------------------------------------------------------------------------
537
align 4
479 kastigar 538
mouse_acceleration:
2434 Serge 539
        push    eax
540
        mov     eax, [timer_ticks]
541
        sub     eax, [mouse_timer_ticks]
542
        cmp     eax, [mouse_delay]
543
        pop     eax
544
        ja      @f
545
        ;push  edx
546
        imul    eax, [mouse_speed_factor]
547
        ;pop   edx
548
;--------------------------------------
549
align 4
479 kastigar 550
@@:
2434 Serge 551
        ret
552
;-----------------------------------------------------------------------------