Subversion Repositories Kolibri OS

Rev

Rev 9848 | Details | Compare with Previous | Last modification | View Log | RSS feed

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