Subversion Repositories Kolibri OS

Rev

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