Subversion Repositories Kolibri OS

Rev

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

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