Subversion Repositories Kolibri OS

Rev

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