Subversion Repositories Kolibri OS

Rev

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

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