Subversion Repositories Kolibri OS

Rev

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

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