Subversion Repositories Kolibri OS

Rev

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