Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2465 Serge 3
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
431 serge 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
593 mikedld 8
$Revision: 2465 $
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
33 mario79 27
  mousecount  dd  0x0
28
  mousedata   dd  0x0
2434 Serge 29
Y_UNDER_subtraction_CUR_hot_y:
30
        dd 0
31
X_UNDER_subtraction_CUR_hot_x:
32
        dd 0
33
Y_UNDER_sub_CUR_hot_y_add_curh:
34
        dd 0
35
X_UNDER_sub_CUR_hot_x_add_curh:
36
        dd 0
33 mario79 37
endg
38
 
473 diamond 39
iglobal
2434 Serge 40
;--------------------------------------
41
align 4
42
mouse_delay        dd 10
43
mouse_speed_factor:
44
                    dd 3
479 kastigar 45
mouse_timer_ticks  dd 0
473 diamond 46
endg
2434 Serge 47
;-----------------------------------------------------------------------------
48
align 4
33 mario79 49
draw_mouse_under:
2434 Serge 50
        ; return old picture
51
        cmp     [_display.restore_cursor], 0
52
        je      @F
214 serge 53
 
2434 Serge 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
214 serge 62
@@:
2434 Serge 63
        pushad
64
        xor     ecx, ecx
65
        xor     edx, edx
66
;--------------------------------------
67
align 4
119 mario79 68
mres:
2434 Serge 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
2465 Serge 87
;        call    [putpixel]
88
        call    __sys_putpixel
2434 Serge 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
33 mario79 102
save_draw_mouse:
2434 Serge 103
        cmp     [_display.move_cursor], 0
104
        je      .no_hw_cursor
105
        pushad
214 serge 106
 
2434 Serge 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
221 serge 113
 
2465 Serge 114
;        mov     ecx, [Screen_Max_X]
115
;        inc     ecx
116
;        mul     ecx
117
        mov     eax, [d_width_calc_area + eax*4]
118
 
2434 Serge 119
        add     eax, [_WinMapAddress]
120
        movzx   edx, byte [ebx+eax]
121
        shl     edx, 8
122
        mov     esi, [edx+SLOT_BASE+APPDATA.cursor]
221 serge 123
 
2434 Serge 124
        cmp     esi, [current_cursor]
125
        je      .draw
230 serge 126
 
2434 Serge 127
        push    esi
128
        call    [_display.select_cursor]
129
        mov     [current_cursor], esi
130
;--------------------------------------
131
align 4
630 serge 132
.draw:
2434 Serge 133
        stdcall [_display.move_cursor], esi
134
        popad
135
        ret
136
;--------------------------------------
137
;align 4
138
;.fail:
139
;        mov     ecx, [def_cursor]
140
;        mov     [edx+SLOT_BASE+APPDATA.cursor], ecx
141
;        stdcall [_display.move_cursor], ecx        ; stdcall: [esp]=ebx,eax
142
;        popad
143
;        ret
144
;--------------------------------------
145
align 4
630 serge 146
.no_hw_cursor:
2434 Serge 147
        pushad
148
        ; save & draw
149
        mov     [X_UNDER], ax
150
        mov     [Y_UNDER], bx
151
        push    eax
152
        push    ebx
153
        mov     ecx, 0
154
        mov     edx, 0
155
;--------------------------------------
156
align 4
119 mario79 157
drm:
2434 Serge 158
        push    eax
159
        push    ebx
160
        push    ecx
161
        push    edx
162
        ; helloworld
163
        push    ecx
164
        add     eax, ecx; save picture under mouse
165
        add     ebx, edx
166
        push    ecx
167
        or      ecx, 0x04000000  ; don't load to mouseunder area
168
        call    getpixel
169
        mov     [COLOR_TEMP], ecx
170
        pop     ecx
171
        mov     eax, edx
172
        shl     eax, 6
173
        shl     ecx, 2
174
        add     eax, ecx
175
        add     eax, mouseunder
176
        mov     ebx, [COLOR_TEMP]
177
        and     ebx, 0xffffff
178
        mov     [eax], ebx
179
        pop     ecx
180
        mov     edi, edx     ; y cycle
181
        shl     edi, 4     ; *16 bytes per row
182
        add     edi, ecx     ; x cycle
183
        mov     esi, edi
184
        add     edi, esi
185
        add     edi, esi      ; *3
186
        add     edi, [MOUSE_PICTURE]    ; we have our str address
187
        mov     esi, edi
188
        add     esi, 16*24*3
189
        push    ecx
190
        mov     ecx, [COLOR_TEMP]
191
        call    combine_colors
192
        and     ecx, 0xffffff
193
        mov     [MOUSE_COLOR_MEM], ecx
194
        pop     ecx
195
        pop     edx
196
        pop     ecx
197
        pop     ebx
198
        pop     eax
199
        add     eax, ecx     ; we have x coord+cycle
200
        add     ebx, edx     ; and y coord+cycle
201
        push    ecx
202
        mov     ecx, [MOUSE_COLOR_MEM]
203
        mov     edi, 1 ; force
204
        or      ecx, 0x04000000  ; don't save to mouseunder area
2465 Serge 205
;        call    [putpixel]
206
        call    __sys_putpixel
2434 Serge 207
        pop     ecx
208
        mov     ebx, [esp+0]    ; pure y coord again
209
        mov     eax, [esp+4]    ; and x
210
        inc     ecx         ; +1 cycle
211
        cmp     ecx, 16     ; if more than 16
212
        jnz     drm
213
        xor     ecx, ecx
214
        inc     edx
215
        cmp     edx, 24
216
        jnz     drm
217
        add     esp, 8
218
        popad
219
        ret
220
;-----------------------------------------------------------------------------
221
align 4
33 mario79 222
combine_colors:
223
      ; in
224
      ; ecx - color ( 00 RR GG BB )
225
      ; edi - ref to new color byte
226
      ; esi - ref to alpha byte
227
      ;
228
      ; out
229
      ; ecx - new color ( roughly (ecx*[esi]>>8)+([edi]*[esi]>>8) )
2434 Serge 230
        push    eax
231
        push    ebx
232
        push    edx
233
        push    ecx
234
        xor     ecx, ecx
235
         ; byte 2
236
        mov     eax, 0xff
237
        sub     al, [esi+0]
238
        mov     ebx, [esp]
239
        shr     ebx, 16
240
        and     ebx, 0xff
241
        mul     ebx
242
        shr     eax, 8
243
        add     ecx, eax
244
        xor     eax, eax
245
        xor     ebx, ebx
246
        mov     al, [edi+0]
247
        mov     bl, [esi+0]
248
        mul     ebx
249
        shr     eax, 8
250
        add     ecx, eax
251
        shl     ecx, 8
252
         ; byte 1
253
        mov     eax, 0xff
254
        sub     al, [esi+1]
255
        mov     ebx, [esp]
256
        shr     ebx, 8
257
        and     ebx, 0xff
258
        mul     ebx
259
        shr     eax, 8
260
        add     ecx, eax
261
        xor     eax, eax
262
        xor     ebx, ebx
263
        mov     al, [edi+1]
264
        mov     bl, [esi+1]
265
        mul     ebx
266
        shr     eax, 8
267
        add     ecx, eax
268
        shl     ecx, 8
269
         ; byte 2
270
        mov     eax, 0xff
271
        sub     al, [esi+2]
272
        mov     ebx, [esp]
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+2]
280
        mov     bl, [esi+2]
281
        mul     ebx
282
        shr     eax, 8
283
        add     ecx, eax
284
        pop     eax
285
        pop     edx
286
        pop     ebx
287
        pop     eax
288
        ret
289
;-----------------------------------------------------------------------------
290
align 4
291
check_mouse_area_for_getpixel:
292
; in:
293
; eax = x
294
; ebx = y
295
; out:
296
; ecx = new color
297
        push    eax ebx
298
; check for Y
299
        xor     ecx, ecx
300
        mov     cx, [Y_UNDER]  ; [MOUSE_Y]
33 mario79 301
 
2434 Serge 302
        cmp     ebx, ecx
303
        jb      .no_mouse_area
304
        add     ecx, 23  ; mouse cursor Y size
305
        cmp     ebx, ecx
306
        ja      .no_mouse_area
307
; offset Y
308
        sub     bx, [Y_UNDER]  ;[MOUSE_Y]
309
;--------------------------------------
310
; check for X
311
        xor     ecx, ecx
312
        mov     cx, [X_UNDER]  ;[MOUSE_X]
313
        cmp     eax, ecx
314
        jb      .no_mouse_area
315
        add     ecx, 15  ; mouse cursor X size
316
        cmp     eax, ecx
317
        ja      .no_mouse_area
318
; offset X
319
        sub     ax, [X_UNDER]  ;[MOUSE_X]
320
;--------------------------------------
321
; eax = offset x
322
; ebx = offset y
323
        shl     ebx, 6  ;y
324
        shl     eax, 2  ;x
325
        add     eax, ebx
326
        add     eax, mouseunder
327
        mov     ecx, [eax]
328
        and     ecx, 0xffffff
329
        or      ecx, 0xff000000
330
        pop     ebx eax
331
        ret
332
;--------------------------------------
333
align 4
334
.no_mouse_area:
335
        xor     ecx, ecx
336
        pop     ebx eax
337
        ret
338
;-----------------------------------------------------------------------------
339
align 4
340
check_mouse_area_for_putpixel:
341
; in:
342
; ecx = x shl 16 + y
343
; eax = color
344
; out:
345
; eax = new color
346
        push    eax
347
; check for Y
348
        mov     ax, [Y_UNDER]  ; [MOUSE_Y]
349
        cmp     cx, ax
350
        jb      .no_mouse_area
351
        add     ax, 23  ; mouse cursor Y size
352
        cmp     cx, ax
353
        ja      .no_mouse_area
354
; offset Y
355
        sub     cx, [Y_UNDER]  ;[MOUSE_Y]
356
        mov     ax, cx
357
        shl     eax, 16
358
;--------------------------------------
359
; check for X
360
        mov     ax, [X_UNDER]  ;[MOUSE_X]
361
        shr     ecx, 16
362
        cmp     cx, ax
363
        jb      .no_mouse_area
364
        add     ax, 15  ; mouse cursor X size
365
        cmp     cx, ax
366
        ja      .no_mouse_area
367
; offset X
368
        sub     cx, [X_UNDER]  ;[MOUSE_X]
369
        mov     ax, cx
370
;--------------------------------------
371
; eax = (offset y) shl 16 + (offset x)
33 mario79 372
 
2434 Serge 373
        pop     ecx
33 mario79 374
 
2434 Serge 375
        push    eax ebx
376
 
377
        mov     ebx, eax
378
        shr     ebx, 16        ;y
379
        and     eax, 0xffff    ;x
380
 
381
        shl     ebx, 6
382
        shl     eax, 2
383
        add     eax, ebx
384
        add     eax, mouseunder
385
        and     ecx, 0xFFFFFF
386
        mov     [eax], ecx
387
 
388
        pop     ebx eax
389
 
390
        push    esi edi
391
        rol     eax, 16
392
        movzx   edi, ax     ; y cycle
393
        shl     edi, 4     ; *16 bytes per row
394
        shr     eax, 16
395
        add     edi, eax     ; x cycle
396
        lea     edi, [edi*3]
397
        add     edi, [MOUSE_PICTURE]    ; we have our str address
398
        mov     esi, edi
399
        add     esi, 16*24*3
400
        call    combine_colors
401
        pop     edi esi
402
;--------------------------------------
403
align 4
404
.end:
405
        mov     eax, ecx
406
        ret
407
;--------------------------------------
408
align 4
409
.no_mouse_area:
410
        pop     eax
411
        ret
412
;-----------------------------------------------------------------------------
413
align 4
33 mario79 414
__sys_draw_pointer:
2434 Serge 415
        pushad
416
        movzx   ecx, word [X_UNDER]
417
        movzx   edx, word [Y_UNDER]
418
        movzx   ebx, word [MOUSE_Y]
419
        movzx   eax, word [MOUSE_X]
2465 Serge 420
        cmp     [redrawmouse_unconditional], 0
421
        je      @f
422
        mov     [redrawmouse_unconditional], 0
423
        jmp     redrawmouse
424
;--------------------------------------
425
align 4
426
@@:
2434 Serge 427
        cmp     eax, ecx
428
        jne     redrawmouse
429
        cmp     ebx, edx
430
        je      nodmp
431
;--------------------------------------
432
align 4
433
redrawmouse:
434
        pushfd
435
        cli
436
        call    draw_mouse_under
437
        call    save_draw_mouse
438
 
2465 Serge 439
;        mov     eax, [_display.select_cursor]
440
;        test    eax, eax
441
;        jz      @f
442
        cmp     [_display.select_cursor], select_cursor
443
        jne     @f
2434 Serge 444
 
445
        xor     eax, eax
446
        mov     esi, [current_cursor]
447
 
448
        mov     ax, [Y_UNDER]
449
        sub     eax, [esi+CURSOR.hot_y]
450
        mov     [Y_UNDER_subtraction_CUR_hot_y], eax
451
        add     eax, [cur.h]
452
        mov     [Y_UNDER_sub_CUR_hot_y_add_curh], eax
453
 
454
        mov     ax, [X_UNDER]
455
        sub     eax, [esi+CURSOR.hot_x]
456
        mov     [X_UNDER_subtraction_CUR_hot_x], eax
457
        add     eax, [cur.w]
458
        mov     [X_UNDER_sub_CUR_hot_x_add_curh], eax
459
;--------------------------------------
460
align 4
119 mario79 461
@@:
2434 Serge 462
        popfd
463
;--------------------------------------
464
align 4
119 mario79 465
nodmp:
2434 Serge 466
        popad
467
        ret
468
;-----------------------------------------------------------------------------
469
align 4
479 kastigar 470
proc set_mouse_data stdcall, BtnState:dword, XMoving:dword, YMoving:dword, VScroll:dword, HScroll:dword
630 serge 471
 
2434 Serge 472
        mov     eax, [BtnState]
473
        mov     [BTN_DOWN], eax
479 kastigar 474
 
2434 Serge 475
        mov     eax, [XMoving]
476
        call    mouse_acceleration
477
        add     ax, [MOUSE_X];[XCoordinate]
478
        cmp     ax, 0
479
        jge     @@M1
480
        mov     eax, 0
481
        jmp     @@M2
482
;--------------------------------------
483
align 4
479 kastigar 484
@@M1:
2434 Serge 485
        cmp     ax, [Screen_Max_X];ScreenLength
486
        jl      @@M2
487
        mov     ax, [Screen_Max_X];ScreenLength-1
488
;--------------------------------------
489
align 4
479 kastigar 490
@@M2:
2434 Serge 491
        mov     [MOUSE_X], ax;[XCoordinate]
479 kastigar 492
 
2434 Serge 493
        mov     eax, [YMoving]
494
        neg     eax
495
        call    mouse_acceleration
479 kastigar 496
 
2434 Serge 497
        add     ax, [MOUSE_Y];[YCoordinate]
498
        cmp     ax, 0
499
        jge     @@M3
500
        mov     ax, 0
501
        jmp     @@M4
502
;--------------------------------------
503
align 4
479 kastigar 504
@@M3:
2434 Serge 505
        cmp     ax, [Screen_Max_Y];ScreenHeigth
506
        jl      @@M4
507
        mov     ax, [Screen_Max_Y];ScreenHeigth-1
508
;--------------------------------------
509
align 4
479 kastigar 510
@@M4:
2434 Serge 511
        mov     [MOUSE_Y], ax;[YCoordinate]
479 kastigar 512
 
2434 Serge 513
        mov     eax, [VScroll]
514
        add     [MOUSE_SCROLL_V], ax
630 serge 515
 
2434 Serge 516
        mov     eax, [HScroll]
517
        add     [MOUSE_SCROLL_H], ax
479 kastigar 518
 
2434 Serge 519
        mov     [mouse_active], 1
520
        mov     eax, [timer_ticks]
521
        mov     [mouse_timer_ticks], eax
522
        ret
479 kastigar 523
endp
2434 Serge 524
;-----------------------------------------------------------------------------
525
align 4
479 kastigar 526
mouse_acceleration:
2434 Serge 527
        push    eax
528
        mov     eax, [timer_ticks]
529
        sub     eax, [mouse_timer_ticks]
530
        cmp     eax, [mouse_delay]
531
        pop     eax
532
        ja      @f
533
        ;push  edx
534
        imul    eax, [mouse_speed_factor]
535
        ;pop   edx
536
;--------------------------------------
537
align 4
479 kastigar 538
@@:
2434 Serge 539
        ret
540
;-----------------------------------------------------------------------------