Subversion Repositories Kolibri OS

Rev

Rev 5351 | Rev 5851 | 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: 5363 $
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
2288 clevermous 42
endg
5154 hidnplayr 43
 
2430 mario79 44
;-----------------------------------------------------------------------------
5154 hidnplayr 45
 
2430 mario79 46
align 4
2288 clevermous 47
draw_mouse_under:
5154 hidnplayr 48
 
2288 clevermous 49
        ; return old picture
50
        cmp     [_display.restore_cursor], 0
51
        je      @F
52
 
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
5154 hidnplayr 59
 
60
  @@:
2288 clevermous 61
        pushad
62
        xor     ecx, ecx
63
        xor     edx, edx
5154 hidnplayr 64
 
65
  mres:
2288 clevermous 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
2430 mario79 82
        mov     edi, 1 ; force
83
        or      ecx, 0x04000000  ; don't save to mouseunder area
2453 mario79 84
;        call    [putpixel]
85
        call    __sys_putpixel
2288 clevermous 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
5154 hidnplayr 97
 
2430 mario79 98
;-----------------------------------------------------------------------------
5154 hidnplayr 99
 
2430 mario79 100
align 4
2288 clevermous 101
save_draw_mouse:
102
        cmp     [_display.move_cursor], 0
103
        je      .no_hw_cursor
104
        pushad
105
 
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
112
 
2446 mario79 113
;        mov     ecx, [Screen_Max_X]
114
;        inc     ecx
115
;        mul     ecx
116
        mov     eax, [d_width_calc_area + eax*4]
117
 
5351 serge 118
        add     eax, [_display.win_map]
2288 clevermous 119
        movzx   edx, byte [ebx+eax]
120
        shl     edx, 8
121
        mov     esi, [edx+SLOT_BASE+APPDATA.cursor]
122
 
123
        cmp     esi, [current_cursor]
124
        je      .draw
125
 
3069 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
@@:
2288 clevermous 138
        push    esi
139
        call    [_display.select_cursor]
140
        mov     [current_cursor], esi
2430 mario79 141
;--------------------------------------
142
align 4
2288 clevermous 143
.draw:
144
        stdcall [_display.move_cursor], esi
145
        popad
146
        ret
2430 mario79 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
2288 clevermous 157
.no_hw_cursor:
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
2430 mario79 166
;--------------------------------------
167
align 4
2288 clevermous 168
drm:
169
        push    eax
170
        push    ebx
171
        push    ecx
172
        push    edx
173
        ; helloworld
174
        push    ecx
5154 hidnplayr 175
        add     eax, ecx        ; save picture under mouse
2288 clevermous 176
        add     ebx, edx
177
        push    ecx
5154 hidnplayr 178
        or      ecx, 0x04000000 ; don't load to mouseunder area
179
        push    eax ebx edx edi
180
        call    [GETPIXEL]
181
        pop     edi edx ebx eax
2288 clevermous 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]
2430 mario79 190
        and     ebx, 0xffffff
2288 clevermous 191
        mov     [eax], ebx
192
        pop     ecx
5154 hidnplayr 193
        mov     edi, edx        ; y cycle
194
        shl     edi, 4          ; *16 bytes per row
195
        add     edi, ecx        ; x cycle
2288 clevermous 196
        mov     esi, edi
197
        add     edi, esi
5154 hidnplayr 198
        add     edi, esi        ; *3
2288 clevermous 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
2430 mario79 205
        and     ecx, 0xffffff
2288 clevermous 206
        mov     [MOUSE_COLOR_MEM], ecx
207
        pop     ecx
208
        pop     edx
209
        pop     ecx
210
        pop     ebx
211
        pop     eax
5154 hidnplayr 212
        add     eax, ecx        ; we have x coord+cycle
213
        add     ebx, edx        ; and y coord+cycle
2288 clevermous 214
        push    ecx
215
        mov     ecx, [MOUSE_COLOR_MEM]
2430 mario79 216
        mov     edi, 1 ; force
5154 hidnplayr 217
        or      ecx, 0x04000000 ; don't save to mouseunder area
2453 mario79 218
;        call    [putpixel]
219
        call    __sys_putpixel
2288 clevermous 220
        pop     ecx
221
        mov     ebx, [esp+0]    ; pure y coord again
222
        mov     eax, [esp+4]    ; and x
5154 hidnplayr 223
        inc     ecx             ; +1 cycle
224
        cmp     ecx, 16         ; if more than 16
2288 clevermous 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
5154 hidnplayr 233
 
2430 mario79 234
;-----------------------------------------------------------------------------
5154 hidnplayr 235
 
2430 mario79 236
align 4
2288 clevermous 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) )
245
        push    eax
246
        push    ebx
247
        push    edx
248
        push    ecx
249
        xor     ecx, ecx
5154 hidnplayr 250
         ; byte 0
2288 clevermous 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
5154 hidnplayr 304
 
2430 mario79 305
;-----------------------------------------------------------------------------
5154 hidnplayr 306
 
2430 mario79 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
5154 hidnplayr 317
        mov     cx, [Y_UNDER]   ; [MOUSE_Y]
2288 clevermous 318
 
2430 mario79 319
        cmp     ebx, ecx
320
        jb      .no_mouse_area
5154 hidnplayr 321
        add     ecx, 23         ; mouse cursor Y size
2430 mario79 322
        cmp     ebx, ecx
323
        ja      .no_mouse_area
324
; offset Y
5154 hidnplayr 325
        sub     bx, [Y_UNDER]   ; [MOUSE_Y]
2430 mario79 326
;--------------------------------------
327
; check for X
328
        xor     ecx, ecx
5154 hidnplayr 329
        mov     cx, [X_UNDER]   ; [MOUSE_X]
2288 clevermous 330
        cmp     eax, ecx
2430 mario79 331
        jb      .no_mouse_area
5154 hidnplayr 332
        add     ecx, 15         ; mouse cursor X size
2288 clevermous 333
        cmp     eax, ecx
2430 mario79 334
        ja      .no_mouse_area
335
; offset X
5154 hidnplayr 336
        sub     ax, [X_UNDER]   ; [MOUSE_X]
2430 mario79 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
2288 clevermous 348
        ret
5154 hidnplayr 349
 
350
  .no_mouse_area:
2430 mario79 351
        xor     ecx, ecx
352
        pop     ebx eax
353
        ret
5154 hidnplayr 354
 
2430 mario79 355
;-----------------------------------------------------------------------------
5154 hidnplayr 356
 
2430 mario79 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
5154 hidnplayr 366
        mov     ax, [Y_UNDER]   ; [MOUSE_Y]
2430 mario79 367
        cmp     cx, ax
368
        jb      .no_mouse_area
5154 hidnplayr 369
        add     ax, 23          ; mouse cursor Y size
2430 mario79 370
        cmp     cx, ax
371
        ja      .no_mouse_area
372
; offset Y
5154 hidnplayr 373
        sub     cx, [Y_UNDER]   ; [MOUSE_Y]
2430 mario79 374
        mov     ax, cx
375
        shl     eax, 16
5154 hidnplayr 376
 
2430 mario79 377
; check for X
5154 hidnplayr 378
        mov     ax, [X_UNDER]   ; [MOUSE_X]
2430 mario79 379
        shr     ecx, 16
380
        cmp     cx, ax
381
        jb      .no_mouse_area
5154 hidnplayr 382
        add     ax, 15          ; mouse cursor X size
2430 mario79 383
        cmp     cx, ax
384
        ja      .no_mouse_area
385
; offset X
5154 hidnplayr 386
        sub     cx, [X_UNDER]   ; [MOUSE_X]
2430 mario79 387
        mov     ax, cx
5154 hidnplayr 388
 
2430 mario79 389
; eax = (offset y) shl 16 + (offset x)
2288 clevermous 390
 
2430 mario79 391
        pop     ecx
392
 
393
        push    eax ebx
394
 
395
        mov     ebx, eax
5154 hidnplayr 396
        shr     ebx, 16         ; y
397
        and     eax, 0xffff     ; x
2430 mario79 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
5154 hidnplayr 410
        movzx   edi, ax         ; y cycle
411
        shl     edi, 4          ; *16 bytes per row
2430 mario79 412
        shr     eax, 16
5154 hidnplayr 413
        add     edi, eax        ; x cycle
2430 mario79 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
2288 clevermous 421
        ret
5154 hidnplayr 422
 
423
  .no_mouse_area:
2288 clevermous 424
        pop     eax
425
        ret
5154 hidnplayr 426
 
2430 mario79 427
;-----------------------------------------------------------------------------
5154 hidnplayr 428
 
2430 mario79 429
align 4
430
__sys_draw_pointer:
2288 clevermous 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]
2450 mario79 436
        cmp     [redrawmouse_unconditional], 0
437
        je      @f
438
        mov     [redrawmouse_unconditional], 0
439
        jmp     redrawmouse
5154 hidnplayr 440
  @@:
2288 clevermous 441
        cmp     eax, ecx
442
        jne     redrawmouse
443
        cmp     ebx, edx
2430 mario79 444
        je      nodmp
5154 hidnplayr 445
 
2430 mario79 446
;--------------------------------------
5154 hidnplayr 447
 
2430 mario79 448
align 4
2288 clevermous 449
redrawmouse:
450
        pushfd
451
        cli
452
        call    draw_mouse_under
453
        call    save_draw_mouse
2430 mario79 454
 
2448 mario79 455
;        mov     eax, [_display.select_cursor]
456
;        test    eax, eax
457
;        jz      @f
458
        cmp     [_display.select_cursor], select_cursor
459
        jne     @f
2430 mario79 460
 
461
        xor     eax, eax
462
        mov     esi, [current_cursor]
463
 
464
        mov     ax, [Y_UNDER]
465
        sub     eax, [esi+CURSOR.hot_y]
2575 mario79 466
        mov     [Y_UNDER_subtraction_CUR_hot_y], ax
2430 mario79 467
        add     eax, [cur.h]
2575 mario79 468
        mov     [Y_UNDER_sub_CUR_hot_y_add_curh], ax
2430 mario79 469
 
470
        mov     ax, [X_UNDER]
471
        sub     eax, [esi+CURSOR.hot_x]
2575 mario79 472
        mov     [X_UNDER_subtraction_CUR_hot_x], ax
2430 mario79 473
        add     eax, [cur.w]
2575 mario79 474
        mov     [X_UNDER_sub_CUR_hot_x_add_curh], ax
5154 hidnplayr 475
  @@:
2288 clevermous 476
        popfd
5154 hidnplayr 477
  nodmp:
2288 clevermous 478
        popad
479
        ret
5154 hidnplayr 480
 
2430 mario79 481
;-----------------------------------------------------------------------------
5154 hidnplayr 482
 
2430 mario79 483
align 4
4592 hidnplayr 484
proc set_mouse_data stdcall uses edx, BtnState:dword, XMoving:dword, YMoving:dword, VScroll:dword, HScroll:dword
2288 clevermous 485
 
486
        mov     eax, [BtnState]
5154 hidnplayr 487
        and     eax, 0x3FFFFFFF         ; Top 2 bits are used to flag absolute movements
2288 clevermous 488
        mov     [BTN_DOWN], eax
4592 hidnplayr 489
;--------------------------------------
2288 clevermous 490
        mov     eax, [XMoving]
4529 hidnplayr 491
        test    [BtnState], 0x80000000
4592 hidnplayr 492
        jnz     .absolute_x
2288 clevermous 493
        call    mouse_acceleration
4592 hidnplayr 494
        add     ax, [MOUSE_X]
2288 clevermous 495
        cmp     ax, 0
4592 hidnplayr 496
        jge     .check_x
2288 clevermous 497
        mov     eax, 0
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
;--------------------------------------
2288 clevermous 511
        mov     eax, [YMoving]
4529 hidnplayr 512
        test    [BtnState], 0x40000000
4592 hidnplayr 513
        jnz     .absolute_y
2288 clevermous 514
        neg     eax
515
        call    mouse_acceleration
4592 hidnplayr 516
        add     ax, [MOUSE_Y]
2288 clevermous 517
        cmp     ax, 0
4592 hidnplayr 518
        jge     .check_y
2288 clevermous 519
        mov     ax, 0
4592 hidnplayr 520
        jmp     .set_y
521
 .absolute_y:
522
        mov     edx, [_display.height]
523
        mul     edx
524
        shr     eax, 15
525
 .check_y:
5350 serge 526
        cmp     ax, word[_display.height]
4592 hidnplayr 527
        jl      .set_y
5350 serge 528
        mov     ax, word[_display.height]
529
        dec     ax
4592 hidnplayr 530
 .set_y:
531
        mov     [MOUSE_Y], ax
2430 mario79 532
;--------------------------------------
2288 clevermous 533
        mov     eax, [VScroll]
534
        add     [MOUSE_SCROLL_V], ax
535
 
536
        mov     eax, [HScroll]
537
        add     [MOUSE_SCROLL_H], ax
538
 
539
        mov     [mouse_active], 1
540
        mov     eax, [timer_ticks]
541
        mov     [mouse_timer_ticks], eax
3534 clevermous 542
        call    wakeup_osloop
2288 clevermous 543
        ret
544
endp
5154 hidnplayr 545
 
2430 mario79 546
;-----------------------------------------------------------------------------
5154 hidnplayr 547
 
2430 mario79 548
align 4
2288 clevermous 549
mouse_acceleration:
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
5154 hidnplayr 559
  @@:
2288 clevermous 560
        ret