Subversion Repositories Kolibri OS

Rev

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

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