Subversion Repositories Kolibri OS

Rev

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