Subversion Repositories Kolibri OS

Rev

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

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