Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
425 victor 1
$Revision: 479 $
431 serge 2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3
;;                                                              ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;                                                              ;;
7
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8
 
33 mario79 9
;   check mouse
10
;
11
;
12
;   FB00  ->   FB0F   mouse memory 00 chunk count - FB0A-B x - FB0C-D y
13
;   FB10  ->   FB17   mouse color mem
14
;   FB21              x move
15
;   FB22              y move
16
;   FB30              color temp
17
;   FB28              high bits temp
18
;   FB4A  ->   FB4D   FB4A-B x-under - FB4C-D y-under
19
;   FC00  ->   FCFE   com1/ps2 buffer
20
;   FCFF              com1/ps2 buffer count starting from FC00
21
 
22
uglobal
23
  mousecount  dd  0x0
24
  mousedata   dd  0x0
25
endg
26
 
473 diamond 27
iglobal
479 kastigar 28
mouse_delay        dd 10
29
mouse_speed_factor: dd 3
30
mouse_timer_ticks  dd 0
473 diamond 31
endg
120 mario79 32
 
473 diamond 33
include 'm_com.inc'
33 mario79 34
 
35
 
36
;test_mario79:
37
;        push   esi
38
;        push   eax
39
;        mov    [write_error_to],process_test_m79+43
40
;        movzx  eax,al  ;[DevErrorCode]
41
;        call   writehex
42
;        mov    esi,process_test_m79
43
;        call   sys_msg_board_str
44
;        pop    eax
45
;        pop    esi
46
;        ret
47
;process_test_m79 db 'K : Process - test Mario79 error    00000000',13,10,0
48
 
49
draw_mouse_under:
50
        ; return old picture
214 serge 51
 
52
        cmp [set_hw_cursor], 0
221 serge 53
        jz @F
54
        pushad
381 serge 55
        movzx  eax,word [X_UNDER]
56
        movzx  ebx,word [Y_UNDER]
221 serge 57
        stdcall [hw_restore], eax, ebx
58
        popad
214 serge 59
        ret
60
@@:
33 mario79 61
        pushad
62
        xor    ecx,ecx
63
        xor    edx,edx
64
        align  4
119 mario79 65
mres:
381 serge 66
        movzx  eax,word [X_UNDER]
67
        movzx  ebx,word [Y_UNDER]
33 mario79 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
        call   [putpixel]
84
        pop    edx
85
        pop    ecx
86
        inc    ecx
87
        cmp    ecx, 16
88
        jnz    mres
89
        xor    ecx, ecx
90
        inc    edx
91
        cmp    edx, 24
92
        jnz    mres
93
        popad
94
        ret
95
 
96
save_draw_mouse:
214 serge 97
 
98
        cmp [set_hw_cursor], 0
99
        jz @F
221 serge 100
        pushad
101
 
381 serge 102
        mov    [X_UNDER],ax
103
        mov    [Y_UNDER],bx
104
        movzx  eax,word [MOUSE_Y]
105
        movzx  ebx,word [MOUSE_X]
221 serge 106
        push eax
214 serge 107
        push ebx
221 serge 108
 
381 serge 109
        mov ecx, [ScreenWidth]
221 serge 110
        inc ecx
111
        mul ecx
389 serge 112
 
221 serge 113
        movzx edx, byte [display_data+ebx+eax]
114
        shl edx, 8
380 serge 115
        mov ecx, [edx+SLOT_BASE+APPDATA.cursor]
230 serge 116
 
117
        cmp [ecx+CURSOR.magic], 'CURS'
118
        jne .fail
281 serge 119
;        cmp [ecx+CURSOR.size], CURSOR_SIZE
120
;        jne .fail
230 serge 121
        push ecx
214 serge 122
        call [set_hw_cursor]
221 serge 123
        popad
214 serge 124
        ret
230 serge 125
.fail:
126
        mov ecx, [def_cursor]
380 serge 127
        mov [edx+SLOT_BASE+APPDATA.cursor], ecx
230 serge 128
        push ecx
129
        call [set_hw_cursor]
130
        popad
131
        ret
132
 
214 serge 133
@@:
33 mario79 134
        pushad
135
        ; save & draw
381 serge 136
        mov    [X_UNDER],ax
137
        mov    [Y_UNDER],bx
33 mario79 138
        push   eax
139
        push   ebx
140
        mov    ecx,0
141
        mov    edx,0
142
        align  4
119 mario79 143
drm:
33 mario79 144
        push   eax
145
        push   ebx
146
        push   ecx
147
        push   edx
148
        ; helloworld
149
        push  ecx
150
        add    eax,ecx  ; save picture under mouse
151
        add    ebx,edx
152
        push   ecx
153
        call   getpixel
381 serge 154
        mov    [COLOR_TEMP],ecx
33 mario79 155
        pop    ecx
156
        mov    eax,edx
157
        shl    eax,6
158
        shl    ecx,2
159
        add    eax,ecx
160
        add    eax,mouseunder
381 serge 161
        mov    ebx,[COLOR_TEMP]
33 mario79 162
        mov    [eax],ebx
163
        pop  ecx
164
        mov    edi,edx       ; y cycle
165
        shl    edi,4       ; *16 bytes per row
166
        add    edi,ecx       ; x cycle
167
        mov    esi, edi
168
        add    edi, esi
169
        add    edi, esi       ; *3
381 serge 170
        add    edi,[MOUSE_PICTURE]      ; we have our str address
33 mario79 171
        mov    esi, edi
172
        add    esi, 16*24*3
173
        push   ecx
381 serge 174
        mov    ecx, [COLOR_TEMP]
33 mario79 175
        call   combine_colors
381 serge 176
        mov    [MOUSE_COLOR_MEM], ecx
33 mario79 177
        pop    ecx
178
        pop    edx
179
        pop    ecx
180
        pop    ebx
181
        pop    eax
182
        add    eax,ecx       ; we have x coord+cycle
183
        add    ebx,edx       ; and y coord+cycle
184
        push   ecx
381 serge 185
        mov    ecx, [MOUSE_COLOR_MEM]
33 mario79 186
        mov    edi, 1
187
        call   [putpixel]
188
        pop    ecx
189
        mov    ebx,[esp+0]      ; pure y coord again
190
        mov    eax,[esp+4]      ; and x
191
        inc    ecx          ; +1 cycle
192
        cmp    ecx,16       ; if more than 16
193
        jnz    drm
194
        xor    ecx, ecx
195
        inc    edx
196
        cmp    edx,24
197
        jnz    drm
119 mario79 198
        add   esp,8
33 mario79 199
        popad
200
        ret
201
 
202
 
203
combine_colors:
204
      ; in
205
      ; ecx - color ( 00 RR GG BB )
206
      ; edi - ref to new color byte
207
      ; esi - ref to alpha byte
208
      ;
209
      ; out
210
      ; ecx - new color ( roughly (ecx*[esi]>>8)+([edi]*[esi]>>8) )
211
      push eax
212
      push ebx
213
      push edx
214
      push ecx
215
      xor ecx, ecx
216
         ; byte 2
217
      mov eax, 0xff
218
      sub al, [esi+0]
219
      mov ebx, [esp]
220
      shr ebx, 16
221
      and ebx, 0xff
222
      mul ebx
223
      shr eax, 8
224
      add ecx, eax
119 mario79 225
      xor eax, eax
226
      xor ebx, ebx
227
      mov al, [edi+0]
228
      mov bl, [esi+0]
33 mario79 229
      mul ebx
230
      shr eax, 8
231
      add ecx, eax
232
      shl ecx, 8
233
         ; byte 1
234
      mov eax, 0xff
235
      sub al, [esi+1]
236
      mov ebx, [esp]
237
      shr ebx, 8
238
      and ebx, 0xff
239
      mul ebx
240
      shr eax, 8
241
      add ecx, eax
119 mario79 242
      xor eax, eax
243
      xor ebx, ebx
244
      mov al, [edi+1]
245
      mov bl, [esi+1]
33 mario79 246
      mul ebx
247
      shr eax, 8
248
      add ecx, eax
249
      shl ecx, 8
250
         ; byte 2
251
      mov eax, 0xff
252
      sub al, [esi+2]
253
      mov ebx, [esp]
254
      and ebx, 0xff
255
      mul ebx
256
      shr eax, 8
257
      add ecx, eax
119 mario79 258
      xor eax, eax
259
      xor ebx, ebx
260
      mov al, [edi+2]
261
      mov bl, [esi+2]
33 mario79 262
      mul ebx
263
      shr eax, 8
264
      add ecx, eax
265
      pop eax
266
      pop edx
267
      pop ebx
268
      pop eax
269
      ret
270
 
271
 
272
__sys_disable_mouse:
381 serge 273
      cmp  dword [MOUSE_VISIBLE],dword 0
36 mario79 274
      je    @f
275
      ret
214 serge 276
@@:
33 mario79 277
      pushad
379 serge 278
      cmp  [CURRENT_TASK],dword 1
33 mario79 279
      je   disable_m
379 serge 280
      mov  edx,[CURRENT_TASK]
33 mario79 281
      shl  edx,5
282
      add  edx,window_data
381 serge 283
      movzx  eax, word [MOUSE_X]
284
      movzx  ebx, word [MOUSE_Y]
285
      mov  ecx,[ScreenWidth]
33 mario79 286
      inc  ecx
287
      imul  ecx,ebx
288
      add  ecx,eax
289
      add  ecx, display_data
379 serge 290
      mov   eax, [CURRENT_TASK]
33 mario79 291
      movzx ebx, byte [ecx]
292
      cmp   eax,ebx
293
      je    yes_mouse_disable
294
      movzx ebx, byte [ecx+16]
295
      cmp   eax,ebx
296
      je    yes_mouse_disable
381 serge 297
      mov   ebx,[ScreenWidth]
33 mario79 298
      inc   ebx
299
      imul  ebx,10
300
      add   ecx,ebx
301
      movzx ebx, byte [ecx]
302
      cmp   eax,ebx
303
      je    yes_mouse_disable
304
      movzx ebx, byte [ecx+16]
305
      cmp   eax,ebx
306
      je    yes_mouse_disable
307
      jmp   no_mouse_disable
119 mario79 308
yes_mouse_disable:
379 serge 309
      mov  edx,[CURRENT_TASK]
33 mario79 310
      shl  edx,5
311
      add  edx,window_data
381 serge 312
      movzx  eax, word [MOUSE_X]
313
      movzx  ebx, word [MOUSE_Y]
33 mario79 314
      mov  ecx,[edx+0]   ; mouse inside the area ?
315
      add  eax,14
316
      cmp  eax,ecx
317
      jb   no_mouse_disable
318
      sub  eax,14
319
      add  ecx,[edx+8]
320
      cmp  eax,ecx
321
      jg   no_mouse_disable
322
      mov  ecx,[edx+4]
323
      add  ebx,20
324
      cmp  ebx,ecx
325
      jb   no_mouse_disable
326
      sub  ebx,20
327
      add  ecx,[edx+12]
328
      cmp  ebx,ecx
329
      jg   no_mouse_disable
119 mario79 330
disable_m:
381 serge 331
      cmp  dword [MOUSE_VISIBLE],dword 0
119 mario79 332
      jne  no_mouse_disable
389 serge 333
      pushf
36 mario79 334
      cli
119 mario79 335
      call draw_mouse_under
389 serge 336
      popf
381 serge 337
      mov  [MOUSE_VISIBLE],dword 1
119 mario79 338
no_mouse_disable:
33 mario79 339
      popad
340
      ret
341
 
342
__sys_draw_pointer:
343
        cmp   [mouse_pause],0
344
        je    @f
36 mario79 345
        ret
119 mario79 346
@@:
36 mario79 347
        push   eax
348
        mov     eax,[timer_ticks]
349
        sub     eax,[MouseTickCounter]
350
        cmp     eax,1
351
        ja      @f
352
        pop    eax
353
        ret
119 mario79 354
@@:
36 mario79 355
        mov     eax,[timer_ticks]
356
        mov     [MouseTickCounter],eax
357
        pop     eax
358
        pushad
381 serge 359
        cmp    dword [MOUSE_VISIBLE],dword 0  ; mouse visible ?
33 mario79 360
        je     chms00
381 serge 361
        mov     [MOUSE_VISIBLE], dword 0
362
        movzx  ebx,word [MOUSE_Y]
363
        movzx  eax,word [MOUSE_X]
389 serge 364
        pushfd
36 mario79 365
        cli
33 mario79 366
        call   save_draw_mouse
389 serge 367
        popfd
119 mario79 368
nodmu2:
33 mario79 369
        popad
370
        ret
119 mario79 371
chms00:
381 serge 372
        movzx  ecx,word [X_UNDER]
373
        movzx  edx,word [Y_UNDER]
374
        movzx  ebx,word [MOUSE_Y]
375
        movzx  eax,word [MOUSE_X]
33 mario79 376
        cmp    eax,ecx
377
        jne    redrawmouse
378
        cmp    ebx,edx
379
        jne    redrawmouse
380
        jmp    nodmp
119 mario79 381
redrawmouse:
389 serge 382
        pushfd
36 mario79 383
        cli
33 mario79 384
        call   draw_mouse_under
385
        call   save_draw_mouse
389 serge 386
        popfd
119 mario79 387
nodmp:
33 mario79 388
        popad
389
        ret
119 mario79 390
 
479 kastigar 391
proc set_mouse_data stdcall, BtnState:dword, XMoving:dword, YMoving:dword, VScroll:dword, HScroll:dword
392
 
393
    mov  eax,[BtnState]
394
    mov  [BTN_DOWN],eax
395
 
396
    mov  eax,[XMoving]
397
    call mouse_acceleration
398
    add  ax,[MOUSE_X]    ;[XCoordinate]
399
    cmp  ax,0
400
    jge  @@M1
401
    mov  eax,0
402
    jmp  @@M2
403
@@M1:
404
    cmp  ax,[ScreenWidth]   ;ScreenLength
405
    jl   @@M2
406
    mov  ax,[ScreenWidth]   ;ScreenLength-1
407
 
408
@@M2:
409
    mov  [MOUSE_X],ax     ;[XCoordinate]
410
 
411
    mov  eax,[YMoving]
412
    neg  eax
413
    call mouse_acceleration
414
 
415
    add  ax,[MOUSE_Y]   ;[YCoordinate]
416
    cmp  ax,0
417
    jge  @@M3
418
    mov  ax,0
419
    jmp  @@M4
420
@@M3:
421
    cmp  ax,[ScreenHeight]  ;ScreenHeigth
422
    jl   @@M4
423
    mov  ax,[ScreenHeight] ;ScreenHeigth-1
424
 
425
@@M4:
426
    mov  [MOUSE_Y],ax     ;[YCoordinate]
427
 
428
    mov  eax,[VScroll]
429
    add  [MOUSE_SCROLL_V],ax
430
 
431
    mov  eax,[HScroll]
432
    add  [MOUSE_SCROLL_H],ax
433
 
434
    mov  [mouse_active],1
435
    mov  eax,[timer_ticks]
436
    mov  [mouse_timer_ticks],eax
437
    ret
438
endp
439
 
440
mouse_acceleration:
441
        push  eax
442
        mov   eax,[timer_ticks]
443
        sub   eax,[mouse_timer_ticks]
444
        cmp   eax,[mouse_delay]
445
        pop   eax
446
        ja    @f
447
        ;push  edx
448
        imul  eax,[mouse_speed_factor]
449
        ;pop   edx
450
@@:
451
        ret
452