Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
5565 serge 3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
431 serge 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
593 mikedld 8
$Revision: 5984 $
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
5201 serge 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 ?
33 mario79 33
endg
34
 
473 diamond 35
iglobal
2434 Serge 36
;--------------------------------------
37
align 4
5984 serge 38
mouse_speed_factor      dw 1
39
mouse_delay             db 1
40
mouse_doubleclick_delay db 64
473 diamond 41
endg
5201 serge 42
 
2434 Serge 43
;-----------------------------------------------------------------------------
5201 serge 44
 
2434 Serge 45
align 4
33 mario79 46
draw_mouse_under:
5201 serge 47
 
2434 Serge 48
        ; return old picture
49
        cmp     [_display.restore_cursor], 0
50
        je      @F
214 serge 51
 
2434 Serge 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
5201 serge 58
 
59
  @@:
2434 Serge 60
        pushad
61
        xor     ecx, ecx
62
        xor     edx, edx
5201 serge 63
 
64
  mres:
2434 Serge 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
81
        mov     edi, 1 ; force
82
        or      ecx, 0x04000000  ; don't save to mouseunder area
2465 Serge 83
;        call    [putpixel]
84
        call    __sys_putpixel
2434 Serge 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
5201 serge 96
 
2434 Serge 97
;-----------------------------------------------------------------------------
5201 serge 98
 
2434 Serge 99
align 4
33 mario79 100
save_draw_mouse:
2434 Serge 101
        cmp     [_display.move_cursor], 0
102
        je      .no_hw_cursor
103
        pushad
214 serge 104
 
2434 Serge 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
221 serge 111
 
5201 serge 112
;        mov     ecx, [Screen_Max_X]
113
;        inc     ecx
114
;        mul     ecx
2465 Serge 115
        mov     eax, [d_width_calc_area + eax*4]
116
 
5565 serge 117
        add     eax, [_display.win_map]
2434 Serge 118
        movzx   edx, byte [ebx+eax]
119
        shl     edx, 8
120
        mov     esi, [edx+SLOT_BASE+APPDATA.cursor]
221 serge 121
 
2434 Serge 122
        cmp     esi, [current_cursor]
123
        je      .draw
230 serge 124
 
3232 Serge 125
        mov     eax, [TASK_COUNT]
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
@@:
2434 Serge 137
        push    esi
138
        call    [_display.select_cursor]
139
        mov     [current_cursor], esi
140
;--------------------------------------
141
align 4
630 serge 142
.draw:
2434 Serge 143
        stdcall [_display.move_cursor], esi
144
        popad
145
        ret
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
630 serge 156
.no_hw_cursor:
2434 Serge 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
165
;--------------------------------------
166
align 4
119 mario79 167
drm:
2434 Serge 168
        push    eax
169
        push    ebx
170
        push    ecx
171
        push    edx
172
        ; helloworld
173
        push    ecx
5201 serge 174
        add     eax, ecx        ; save picture under mouse
2434 Serge 175
        add     ebx, edx
176
        push    ecx
5596 serge 177
        or      ecx, 0x04000000 ; don't load to mouseunder area
5201 serge 178
        push    eax ebx edx edi
179
        call    [GETPIXEL]
180
        pop     edi edx ebx eax
2434 Serge 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
5596 serge 192
        mov     edi, edx        ; y cycle
193
        shl     edi, 4          ; *16 bytes per row
194
        add     edi, ecx        ; x cycle
2434 Serge 195
        mov     esi, edi
196
        add     edi, esi
5596 serge 197
        add     edi, esi        ; *3
2434 Serge 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
5596 serge 211
        add     eax, ecx        ; we have x coord+cycle
212
        add     ebx, edx        ; and y coord+cycle
2434 Serge 213
        push    ecx
214
        mov     ecx, [MOUSE_COLOR_MEM]
215
        mov     edi, 1 ; force
5596 serge 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
5596 serge 222
        inc     ecx             ; +1 cycle
223
        cmp     ecx, 16         ; if more than 16
2434 Serge 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
5201 serge 232
 
2434 Serge 233
;-----------------------------------------------------------------------------
5201 serge 234
 
2434 Serge 235
align 4
33 mario79 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) )
2434 Serge 244
        push    eax
245
        push    ebx
246
        push    edx
247
        push    ecx
248
        xor     ecx, ecx
5201 serge 249
         ; byte 0
2434 Serge 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
5201 serge 303
 
2434 Serge 304
;-----------------------------------------------------------------------------
5201 serge 305
 
2434 Serge 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
5596 serge 316
        mov     cx, [Y_UNDER]   ; [MOUSE_Y]
33 mario79 317
 
2434 Serge 318
        cmp     ebx, ecx
319
        jb      .no_mouse_area
5596 serge 320
        add     ecx, 23         ; mouse cursor Y size
2434 Serge 321
        cmp     ebx, ecx
322
        ja      .no_mouse_area
323
; offset Y
5201 serge 324
        sub     bx, [Y_UNDER]   ; [MOUSE_Y]
2434 Serge 325
;--------------------------------------
326
; check for X
327
        xor     ecx, ecx
5201 serge 328
        mov     cx, [X_UNDER]   ; [MOUSE_X]
2434 Serge 329
        cmp     eax, ecx
330
        jb      .no_mouse_area
5596 serge 331
        add     ecx, 15         ; mouse cursor X size
2434 Serge 332
        cmp     eax, ecx
333
        ja      .no_mouse_area
334
; offset X
5201 serge 335
        sub     ax, [X_UNDER]   ; [MOUSE_X]
2434 Serge 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
347
        ret
5201 serge 348
 
349
  .no_mouse_area:
2434 Serge 350
        xor     ecx, ecx
351
        pop     ebx eax
352
        ret
5201 serge 353
 
2434 Serge 354
;-----------------------------------------------------------------------------
5201 serge 355
 
2434 Serge 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
5596 serge 365
        mov     ax, [Y_UNDER]   ; [MOUSE_Y]
2434 Serge 366
        cmp     cx, ax
367
        jb      .no_mouse_area
5596 serge 368
        add     ax, 23          ; mouse cursor Y size
2434 Serge 369
        cmp     cx, ax
370
        ja      .no_mouse_area
371
; offset Y
5201 serge 372
        sub     cx, [Y_UNDER]   ; [MOUSE_Y]
2434 Serge 373
        mov     ax, cx
374
        shl     eax, 16
5201 serge 375
 
2434 Serge 376
; check for X
5201 serge 377
        mov     ax, [X_UNDER]   ; [MOUSE_X]
2434 Serge 378
        shr     ecx, 16
379
        cmp     cx, ax
380
        jb      .no_mouse_area
5596 serge 381
        add     ax, 15          ; mouse cursor X size
2434 Serge 382
        cmp     cx, ax
383
        ja      .no_mouse_area
384
; offset X
5201 serge 385
        sub     cx, [X_UNDER]   ; [MOUSE_X]
2434 Serge 386
        mov     ax, cx
5201 serge 387
 
2434 Serge 388
; eax = (offset y) shl 16 + (offset x)
33 mario79 389
 
2434 Serge 390
        pop     ecx
33 mario79 391
 
2434 Serge 392
        push    eax ebx
393
 
394
        mov     ebx, eax
5201 serge 395
        shr     ebx, 16         ; y
396
        and     eax, 0xffff     ; x
2434 Serge 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
5596 serge 409
        movzx   edi, ax         ; y cycle
410
        shl     edi, 4          ; *16 bytes per row
2434 Serge 411
        shr     eax, 16
5596 serge 412
        add     edi, eax        ; x cycle
2434 Serge 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
420
        ret
5201 serge 421
 
422
  .no_mouse_area:
2434 Serge 423
        pop     eax
424
        ret
5201 serge 425
 
2434 Serge 426
;-----------------------------------------------------------------------------
5201 serge 427
 
2434 Serge 428
align 4
33 mario79 429
__sys_draw_pointer:
2434 Serge 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]
2465 Serge 435
        cmp     [redrawmouse_unconditional], 0
436
        je      @f
437
        mov     [redrawmouse_unconditional], 0
438
        jmp     redrawmouse
5201 serge 439
  @@:
2434 Serge 440
        cmp     eax, ecx
441
        jne     redrawmouse
442
        cmp     ebx, edx
443
        je      nodmp
5201 serge 444
 
2434 Serge 445
;--------------------------------------
5201 serge 446
 
2434 Serge 447
align 4
448
redrawmouse:
449
        pushfd
450
        cli
451
        call    draw_mouse_under
452
        call    save_draw_mouse
453
 
2465 Serge 454
;        mov     eax, [_display.select_cursor]
455
;        test    eax, eax
456
;        jz      @f
457
        cmp     [_display.select_cursor], select_cursor
458
        jne     @f
2434 Serge 459
 
460
        xor     eax, eax
461
        mov     esi, [current_cursor]
462
 
463
        mov     ax, [Y_UNDER]
464
        sub     eax, [esi+CURSOR.hot_y]
2987 Serge 465
        mov     [Y_UNDER_subtraction_CUR_hot_y], ax
2434 Serge 466
        add     eax, [cur.h]
2987 Serge 467
        mov     [Y_UNDER_sub_CUR_hot_y_add_curh], ax
2434 Serge 468
 
469
        mov     ax, [X_UNDER]
470
        sub     eax, [esi+CURSOR.hot_x]
2987 Serge 471
        mov     [X_UNDER_subtraction_CUR_hot_x], ax
2434 Serge 472
        add     eax, [cur.w]
2987 Serge 473
        mov     [X_UNDER_sub_CUR_hot_x_add_curh], ax
5201 serge 474
  @@:
2434 Serge 475
        popfd
5201 serge 476
  nodmp:
2434 Serge 477
        popad
478
        ret
5201 serge 479
 
2434 Serge 480
;-----------------------------------------------------------------------------
5201 serge 481
 
2434 Serge 482
align 4
5201 serge 483
proc set_mouse_data stdcall uses edx, BtnState:dword, XMoving:dword, YMoving:dword, VScroll:dword, HScroll:dword
630 serge 484
 
2434 Serge 485
        mov     eax, [BtnState]
5201 serge 486
        and     eax, 0x3FFFFFFF         ; Top 2 bits are used to flag absolute movements
2434 Serge 487
        mov     [BTN_DOWN], eax
5201 serge 488
;--------------------------------------
2434 Serge 489
        mov     eax, [XMoving]
5201 serge 490
        test    [BtnState], 0x80000000
491
        jnz     .absolute_x
5984 serge 492
        test    eax, eax
493
        jz      @f
2434 Serge 494
        call    mouse_acceleration
5201 serge 495
        add     ax, [MOUSE_X]
5984 serge 496
        jns     .check_x
497
        xor     eax, eax
5201 serge 498
        jmp     .set_x
499
 .absolute_x:
500
        mov     edx, [_display.width]
501
        mul     edx
502
        shr     eax, 15
503
 .check_x:
5565 serge 504
        cmp     ax, word[_display.width]
5201 serge 505
        jl      .set_x
5565 serge 506
        mov     ax, word[_display.width]
507
        dec     ax
5201 serge 508
 .set_x:
509
        mov     [MOUSE_X], ax
2434 Serge 510
;--------------------------------------
5984 serge 511
@@:
2434 Serge 512
        mov     eax, [YMoving]
5201 serge 513
        test    [BtnState], 0x40000000
514
        jnz     .absolute_y
5984 serge 515
        test    eax, eax
516
        jz      @f
2434 Serge 517
        neg     eax
518
        call    mouse_acceleration
5201 serge 519
        add     ax, [MOUSE_Y]
5984 serge 520
        jns     .check_y
521
        xor     eax, eax
5201 serge 522
        jmp     .set_y
523
 .absolute_y:
524
        mov     edx, [_display.height]
525
        mul     edx
526
        shr     eax, 15
527
 .check_y:
5565 serge 528
        cmp     ax, word[_display.height]
5201 serge 529
        jl      .set_y
5565 serge 530
        mov     ax, word[_display.height]
531
        dec     ax
5201 serge 532
 .set_y:
533
        mov     [MOUSE_Y], ax
2434 Serge 534
;--------------------------------------
5984 serge 535
@@:
2434 Serge 536
        mov     eax, [VScroll]
5984 serge 537
        test    eax, eax
538
        jz      @f
2434 Serge 539
        add     [MOUSE_SCROLL_V], ax
5984 serge 540
        bts     word [BTN_DOWN], 15
541
@@:
2434 Serge 542
        mov     eax, [HScroll]
5984 serge 543
        test    eax, eax
544
        jz      @f
2434 Serge 545
        add     [MOUSE_SCROLL_H], ax
5984 serge 546
        bts     dword [BTN_DOWN], 23
547
@@:
2434 Serge 548
        mov     [mouse_active], 1
3555 Serge 549
        call    wakeup_osloop
2434 Serge 550
        ret
479 kastigar 551
endp
5201 serge 552
 
2434 Serge 553
;-----------------------------------------------------------------------------
5984 serge 554
; 3 = x^2 /2
555
; 2 = (x+1)^2 /4
556
; 1 = (x+2)^2 /8
2434 Serge 557
align 4
479 kastigar 558
mouse_acceleration:
5984 serge 559
        cmp     [mouse_delay], 0
560
        jz      .end
2434 Serge 561
        push    eax
5984 serge 562
@@:
563
        neg     eax
564
        jl      @b
565
        cmp     [mouse_delay], 3
566
        adc     eax, 0
567
        cmp     [mouse_delay], 2
568
        adc     eax, 0
569
        mul     al
570
        shr     eax, 1
571
        adc     eax, 0
572
        cmp     [mouse_delay], 2
573
        jz      .2
574
        jnc     .3
575
        shr     eax, 1
576
.2:
577
        shr     eax, 1
578
.3:
579
        pop     edx
580
        test    edx, edx
581
        jns     .end
582
        neg     eax
583
.end:
584
        imul    [mouse_speed_factor]
2434 Serge 585
        ret