Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2288 clevermous 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
9715 Doczom 3
;; Copyright (C) KolibriOS team 2004-2022. All rights reserved. ;;
2288 clevermous 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
8
$Revision: 9848 $
9
 
10
 
7136 dunkaist 11
LOAD_FROM_FILE  = 0
12
LOAD_FROM_MEM   = 1
13
LOAD_INDIRECT   = 2
14
LOAD_SYSTEM     = 3
2288 clevermous 15
 
2384 hidnplayr 16
struct  BITMAPINFOHEADER
17
        Size                    dd ?
18
        Width                   dd ?
19
        Height                  dd ?
20
        Planes                  dw ?
21
        BitCount                dw ?
22
        Compression             dd ?
23
        SizeImage               dd ?
24
        XPelsPerMeter           dd ?
25
        YPelsPerMeter           dd ?
26
        ClrUsed                 dd ?
27
        ClrImportant            dd ?
28
ends
2430 mario79 29
;------------------------------------------------------------------------------
2288 clevermous 30
align 4
31
proc init_cursor stdcall, dst:dword, src:dword
32
           locals
33
             rBase    dd ?
34
             pQuad    dd ?
35
             pBits    dd ?
36
             pAnd     dd ?
37
             width    dd ?
38
             height   dd ?
39
             counter  dd ?
40
           endl
41
 
42
        mov     esi, [src]
43
        add     esi, [esi+18]
44
        mov     eax, esi
45
 
9715 Doczom 46
        cmp     [esi + BITMAPINFOHEADER.BitCount], 24
2288 clevermous 47
        je      .img_24
9715 Doczom 48
        cmp     [esi + BITMAPINFOHEADER.BitCount], 8
2288 clevermous 49
        je      .img_8
9715 Doczom 50
        cmp     [esi + BITMAPINFOHEADER.BitCount], 4
2288 clevermous 51
        je      .img_4
2430 mario79 52
;--------------------------------------
53
align 4
2288 clevermous 54
.img_2:
55
        add     eax, [esi]
56
        mov     [pQuad], eax
57
        add     eax, 8
58
        mov     [pBits], eax
59
        add     eax, 128
60
        mov     [pAnd], eax
61
        mov     eax, [esi+4]
62
        mov     [width], eax
63
        mov     ebx, [esi+8]
64
        shr     ebx, 1
65
        mov     [height], ebx
66
 
67
        mov     edi, [dst]
68
        add     edi, 32*31*4
69
        mov     [rBase], edi
70
 
71
        mov     esi, [pQuad]
2430 mario79 72
;--------------------------------------
73
align 4
2288 clevermous 74
.l21:
75
        mov     ebx, [pBits]
76
        mov     ebx, [ebx]
77
        bswap   ebx
78
        mov     eax, [pAnd]
79
        mov     eax, [eax]
80
        bswap   eax
81
        mov     [counter], 32
2430 mario79 82
;--------------------------------------
83
align 4
2288 clevermous 84
@@:
85
        xor     edx, edx
86
        shl     eax, 1
87
        setc    dl
88
        dec     edx
89
 
90
        xor     ecx, ecx
91
        shl     ebx, 1
92
        setc    cl
9715 Doczom 93
        mov     ecx, [esi + ecx*4]
2288 clevermous 94
        and     ecx, edx
95
        and     edx, 0xFF000000
96
        or      edx, ecx
97
        mov     [edi], edx
98
 
99
        add     edi, 4
100
        dec     [counter]
101
        jnz     @B
102
 
103
        add     [pBits], 4
104
        add     [pAnd], 4
105
        mov     edi, [rBase]
106
        sub     edi, 128
107
        mov     [rBase], edi
108
        sub     [height], 1
109
        jnz     .l21
110
        ret
2430 mario79 111
;--------------------------------------
112
align 4
2288 clevermous 113
.img_4:
114
        add     eax, [esi]
115
        mov     [pQuad], eax
116
        add     eax, 64
117
        mov     [pBits], eax
118
        add     eax, 0x200
119
        mov     [pAnd], eax
120
        mov     eax, [esi+4]
121
        mov     [width], eax
122
        mov     ebx, [esi+8]
123
        shr     ebx, 1
124
        mov     [height], ebx
125
 
126
        mov     edi, [dst]
127
        add     edi, 32*31*4
128
        mov     [rBase], edi
129
 
130
        mov     esi, [pQuad]
131
        mov     ebx, [pBits]
2430 mario79 132
;--------------------------------------
133
align 4
2288 clevermous 134
.l4:
135
        mov     eax, [pAnd]
136
        mov     eax, [eax]
137
        bswap   eax
138
        mov     [counter], 16
2430 mario79 139
;--------------------------------------
140
align 4
2288 clevermous 141
@@:
142
        xor     edx, edx
143
        shl     eax, 1
144
        setc    dl
145
        dec     edx
146
 
147
        movzx   ecx, byte [ebx]
148
        and     cl, 0xF0
149
        shr     ecx, 2
9715 Doczom 150
        mov     ecx, [esi + ecx]
2288 clevermous 151
        and     ecx, edx
152
        and     edx, 0xFF000000
153
        or      edx, ecx
154
        mov     [edi], edx
155
 
156
        xor     edx, edx
157
        shl     eax, 1
158
        setc    dl
159
        dec     edx
160
 
161
        movzx   ecx, byte [ebx]
162
        and     cl, 0x0F
9715 Doczom 163
        mov     ecx, [esi + ecx*4]
2288 clevermous 164
        and     ecx, edx
165
        and     edx, 0xFF000000
166
        or      edx, ecx
167
        mov     [edi+4], edx
168
 
169
        inc     ebx
170
        add     edi, 8
171
        dec     [counter]
172
        jnz     @B
173
 
174
        add     [pAnd], 4
175
        mov     edi, [rBase]
176
        sub     edi, 128
177
        mov     [rBase], edi
178
        sub     [height], 1
179
        jnz     .l4
180
        ret
2430 mario79 181
;--------------------------------------
182
align 4
2288 clevermous 183
.img_8:
184
        add     eax, [esi]
185
        mov     [pQuad], eax
186
        add     eax, 1024
187
        mov     [pBits], eax
188
        add     eax, 1024
189
        mov     [pAnd], eax
190
        mov     eax, [esi+4]
191
        mov     [width], eax
192
        mov     ebx, [esi+8]
193
        shr     ebx, 1
194
        mov     [height], ebx
195
 
196
        mov     edi, [dst]
197
        add     edi, 32*31*4
198
        mov     [rBase], edi
199
 
200
        mov     esi, [pQuad]
201
        mov     ebx, [pBits]
2430 mario79 202
;--------------------------------------
203
align 4
2288 clevermous 204
.l81:
205
        mov     eax, [pAnd]
206
        mov     eax, [eax]
207
        bswap   eax
208
        mov     [counter], 32
2430 mario79 209
;--------------------------------------
210
align 4
2288 clevermous 211
@@:
212
        xor     edx, edx
213
        shl     eax, 1
214
        setc    dl
215
        dec     edx
216
 
217
        movzx   ecx, byte [ebx]
9715 Doczom 218
        mov     ecx, [esi + ecx*4]
2288 clevermous 219
        and     ecx, edx
220
        and     edx, 0xFF000000
221
        or      edx, ecx
222
        mov     [edi], edx
223
 
224
        inc     ebx
225
        add     edi, 4
226
        dec     [counter]
227
        jnz     @B
228
 
229
        add     [pAnd], 4
230
        mov     edi, [rBase]
231
        sub     edi, 128
232
        mov     [rBase], edi
233
        sub     [height], 1
234
        jnz     .l81
235
        ret
2430 mario79 236
;--------------------------------------
237
align 4
2288 clevermous 238
.img_24:
239
        add     eax, [esi]
240
        mov     [pQuad], eax
241
        add     eax, 0xC00
242
        mov     [pAnd], eax
9715 Doczom 243
        mov     eax, [esi + BITMAPINFOHEADER.Width]
2288 clevermous 244
        mov     [width], eax
9715 Doczom 245
        mov     ebx, [esi + BITMAPINFOHEADER.Height]
2288 clevermous 246
        shr     ebx, 1
247
        mov     [height], ebx
248
 
249
        mov     edi, [dst]
250
        add     edi, 32*31*4
251
        mov     [rBase], edi
252
 
253
        mov     esi, [pAnd]
254
        mov     ebx, [pQuad]
2430 mario79 255
;--------------------------------------
256
align 4
2288 clevermous 257
.row_24:
258
        mov     eax, [esi]
259
        bswap   eax
260
        mov     [counter], 32
2430 mario79 261
;--------------------------------------
262
align 4
2288 clevermous 263
@@:
264
        xor     edx, edx
265
        shl     eax, 1
266
        setc    dl
267
        dec     edx
268
 
269
        mov     ecx, [ebx]
270
        and     ecx, 0x00FFFFFF
271
        and     ecx, edx
272
        and     edx, 0xFF000000
273
        or      edx, ecx
274
        mov     [edi], edx
275
        add     ebx, 3
276
        add     edi, 4
277
        dec     [counter]
278
        jnz     @B
279
 
280
        add     esi, 4
281
        mov     edi, [rBase]
282
        sub     edi, 128
283
        mov     [rBase], edi
284
        sub     [height], 1
285
        jnz     .row_24
286
        ret
287
endp
2430 mario79 288
;------------------------------------------------------------------------------
2288 clevermous 289
align 4
290
proc set_cursor stdcall, hcursor:dword
291
        mov     eax, [hcursor]
9715 Doczom 292
        cmp     [eax + CURSOR.magic], 'CURS'
2288 clevermous 293
        jne     .fail
294
;           cmp [eax+CURSOR.size], CURSOR_SIZE
295
;           jne .fail
296
        mov     ebx, [current_slot]
9715 Doczom 297
        xchg    eax, [ebx + APPDATA.cursor]
4507 lev 298
        jmp     .end
2430 mario79 299
;--------------------------------------
300
align 4
2288 clevermous 301
.fail:
302
        mov     eax, [def_cursor]
303
        mov     ebx, [current_slot]
9715 Doczom 304
        xchg    eax, [ebx + APPDATA.cursor]
4507 lev 305
align 4
306
.end:
307
        mov     [redrawmouse_unconditional], 1
5350 serge 308
        call    __sys_draw_pointer
2288 clevermous 309
        ret
310
endp
2430 mario79 311
;------------------------------------------------------------------------------
312
align 4
2288 clevermous 313
; param
314
;  eax= pid
315
;  ebx= src
316
;  ecx= flags
317
 
318
create_cursor:
319
.src     equ esp
320
.flags   equ esp+4
321
.hcursor equ esp+8
322
 
323
        sub     esp, 4         ;space for .hcursor
324
        push    ecx
325
        push    ebx
326
 
327
        mov     ebx, eax
2384 hidnplayr 328
        mov     eax, sizeof.CURSOR
2288 clevermous 329
        call    create_kernel_object
330
        test    eax, eax
331
        jz      .fail
332
 
333
        mov     [.hcursor], eax
334
 
335
        xor     ebx, ebx
9715 Doczom 336
        mov     [eax + CURSOR.magic], 'CURS'
337
        mov     [eax + CURSOR.destroy], destroy_cursor
338
        mov     [eax + CURSOR.hot_x], ebx
339
        mov     [eax + CURSOR.hot_y], ebx
2288 clevermous 340
 
341
        stdcall kernel_alloc, 0x1000
342
        test    eax, eax
343
        jz      .fail
344
 
345
        mov     edi, [.hcursor]
9715 Doczom 346
        mov     [edi + CURSOR.base], eax
2288 clevermous 347
 
348
        mov     esi, [.src]
349
        mov     ebx, [.flags]
350
        cmp     bx, LOAD_INDIRECT
351
        je      .indirect
352
 
353
        movzx   ecx, word [esi+10]
354
        movzx   edx, word [esi+12]
9715 Doczom 355
        mov     [edi + CURSOR.hot_x], ecx
356
        mov     [edi + CURSOR.hot_y], edx
2288 clevermous 357
 
358
        stdcall init_cursor, eax, esi
359
 
2473 Serge 360
align 4
361
.add_cursor:
2337 Serge 362
        mov     ecx, [.hcursor]
9715 Doczom 363
        lea     ecx, [ecx + CURSOR.list_next]
2288 clevermous 364
        lea     edx, [_display.cr_list.next]
365
 
366
        pushfd
367
        cli
2337 Serge 368
        list_add ecx, edx   ;list_add_tail(new, head)
2288 clevermous 369
        popfd
370
 
371
        mov     eax, [.hcursor]
372
        cmp     [_display.init_cursor], 0
373
        je      .fail
374
 
375
        push    eax
376
        call    [_display.init_cursor]
377
        add     esp, 4
378
 
379
        mov     eax, [.hcursor]
2430 mario79 380
;--------------------------------------
381
align 4
2288 clevermous 382
.fail:
383
        add     esp, 12
384
        ret
2430 mario79 385
;--------------------------------------
386
align 4
2288 clevermous 387
.indirect:
388
        shr     ebx, 16
389
        movzx   ecx, bh
390
        movzx   edx, bl
9715 Doczom 391
        mov     [edi + CURSOR.hot_x], ecx
392
        mov     [edi + CURSOR.hot_y], edx
2288 clevermous 393
 
394
        xchg    edi, eax
395
        mov     ecx, 1024
396
        cld
397
        rep movsd
2473 Serge 398
        jmp     .add_cursor
2430 mario79 399
;------------------------------------------------------------------------------
2288 clevermous 400
align 4
401
proc load_cursor stdcall, src:dword, flags:dword
402
           locals
403
             handle  dd ?
404
           endl
405
 
406
        xor     eax, eax
407
        cmp     [create_cursor], eax
408
        je      .fail2
409
 
410
        mov     [handle], eax
411
        cmp     word [flags], LOAD_FROM_FILE
412
        jne     @F
413
 
414
        stdcall load_file, [src]
415
        test    eax, eax
416
        jz      .fail
417
        mov     [src], eax
2430 mario79 418
;--------------------------------------
419
align 4
2288 clevermous 420
@@:
421
        push    ebx
422
        push    esi
423
        push    edi
424
 
9828 Doczom 425
        mov     eax, [current_slot]
426
        mov     eax, [eax + APPDATA.tid]
2288 clevermous 427
        mov     ebx, [src]
428
        mov     ecx, [flags]
429
        call    create_cursor    ;eax, ebx, ecx
430
        mov     [handle], eax
431
 
432
        cmp     word [flags], LOAD_FROM_FILE
433
        jne     .exit
434
        stdcall kernel_free, [src]
2430 mario79 435
;--------------------------------------
436
align 4
2288 clevermous 437
.exit:
438
        pop     edi
439
        pop     esi
440
        pop     ebx
2430 mario79 441
;--------------------------------------
442
align 4
2288 clevermous 443
.fail:
444
        mov     eax, [handle]
2430 mario79 445
;--------------------------------------
446
align 4
2288 clevermous 447
.fail2:
448
        ret
449
endp
2430 mario79 450
;------------------------------------------------------------------------------
2288 clevermous 451
align 4
452
proc delete_cursor stdcall, hcursor:dword
453
 
3069 serge 454
;        DEBUGF 1,'K : delete_cursor %x\n', [hcursor]
455
 
2288 clevermous 456
        mov     esi, [hcursor]
3069 serge 457
 
9715 Doczom 458
        cmp     [esi + CURSOR.magic], 'CURS'
2288 clevermous 459
        jne     .fail
460
 
9828 Doczom 461
        mov     ebx, [current_slot]
462
        mov     ebx, [ebx + APPDATA.tid]
463
        cmp     ebx, [esi + CURSOR.pid]
2288 clevermous 464
        jne     .fail
465
 
466
        mov     ebx, [current_slot]
9715 Doczom 467
        cmp     esi, [ebx + APPDATA.cursor]
2288 clevermous 468
        jne     @F
469
        mov     eax, [def_cursor]
9715 Doczom 470
        mov     [ebx + APPDATA.cursor], eax
2430 mario79 471
;--------------------------------------
472
align 4
2288 clevermous 473
@@:
474
        mov     eax, [hcursor]
9715 Doczom 475
        call    [eax + APPOBJ.destroy]
2430 mario79 476
;--------------------------------------
477
align 4
2288 clevermous 478
.fail:
479
        ret
480
endp
2430 mario79 481
;------------------------------------------------------------------------------
482
align 4
2288 clevermous 483
; param
484
;  eax= cursor
485
destroy_cursor:
486
 
487
        push    eax
9715 Doczom 488
        stdcall kernel_free, [eax + CURSOR.base]
2337 Serge 489
 
490
        mov     eax, [esp]
9715 Doczom 491
        lea     eax, [eax + CURSOR.list_next]
2337 Serge 492
 
493
        pushfd
494
        cli
495
        list_del eax
496
        popfd
497
 
2288 clevermous 498
        pop     eax
499
        call    destroy_kernel_object
500
        ret
2430 mario79 501
;------------------------------------------------------------------------------
2288 clevermous 502
align 4
503
select_cursor:
9828 Doczom 504
        mov     eax, [esp + 4]
2288 clevermous 505
        mov     [_display.cursor], eax
506
        ret     4
2430 mario79 507
;------------------------------------------------------------------------------
2288 clevermous 508
align 4
509
proc restore_24 stdcall, x:dword, y:dword
510
 
511
        push    ebx
512
 
513
        mov     ebx, [cur_saved_base]
514
        mov     edx, [cur.h]
515
        test    edx, edx
516
        jz      .ret
517
 
518
        push    esi
519
        push    edi
520
 
521
        mov     esi, cur_saved_data
522
        mov     ecx, [cur.w]
9828 Doczom 523
        lea     ecx, [ecx + ecx*2]
2288 clevermous 524
        push    ecx
2430 mario79 525
;--------------------------------------
526
align 4
2288 clevermous 527
@@:
528
        mov     edi, ebx
5351 serge 529
        add     ebx, [_display.lfb_pitch]
2288 clevermous 530
 
531
        mov     ecx, [esp]
532
        rep movsb
533
        dec     edx
534
        jnz     @B
535
 
536
        pop     ecx
537
        pop     edi
538
        pop     esi
2430 mario79 539
;--------------------------------------
540
align 4
2288 clevermous 541
.ret:
542
        pop     ebx
543
        ret
544
endp
2430 mario79 545
;------------------------------------------------------------------------------
2288 clevermous 546
align 4
547
proc restore_32 stdcall, x:dword, y:dword
548
 
549
        push    ebx
550
 
551
        mov     ebx, [cur_saved_base]
552
        mov     edx, [cur.h]
553
        test    edx, edx
554
        jz      .ret
555
 
556
        push    esi
557
        push    edi
558
 
559
        mov     esi, cur_saved_data
2430 mario79 560
;--------------------------------------
561
align 4
2288 clevermous 562
@@:
563
        mov     edi, ebx
5351 serge 564
        add     ebx, [_display.lfb_pitch]
2288 clevermous 565
 
566
        mov     ecx, [cur.w]
567
        rep movsd
568
        dec     edx
569
        jnz     @B
570
 
571
        pop     edi
6127 serge 572
        pop     esi
573
 
2430 mario79 574
;--------------------------------------
575
align 4
2288 clevermous 576
.ret:
577
        pop     ebx
578
        ret
579
endp
2430 mario79 580
;------------------------------------------------------------------------------
2288 clevermous 581
align 4
5154 hidnplayr 582
proc restore_16 stdcall, x:dword, y:dword
583
 
584
        push    ebx
585
 
586
        mov     ebx, [cur_saved_base]
587
        mov     edx, [cur.h]
588
        test    edx, edx
589
        jz      .ret
590
 
591
        push    esi
592
        push    edi
593
 
594
        mov     esi, cur_saved_data
595
;--------------------------------------
596
align 4
597
@@:
598
        mov     edi, ebx
5351 serge 599
        add     ebx, [_display.lfb_pitch]
5154 hidnplayr 600
 
601
        mov     ecx, [cur.w]
602
        rep movsw
603
        dec     edx
604
        jnz     @B
605
 
606
        pop     edi
6127 serge 607
        pop     esi
608
 
5154 hidnplayr 609
;--------------------------------------
610
align 4
611
.ret:
612
        pop     ebx
613
        ret
614
endp
615
;------------------------------------------------------------------------------
616
align 4
2288 clevermous 617
proc move_cursor_24 stdcall, hcursor:dword, x:dword, y:dword
618
           locals
619
             h      dd ?
620
             _dx     dd ?
621
             _dy     dd ?
622
           endl
623
 
624
        mov     esi, [hcursor]
625
        mov     ecx, [x]
626
        mov     eax, [y]
2446 mario79 627
;        mov     ebx, [BytesPerScanLine]
2288 clevermous 628
 
629
        xor     edx, edx
9715 Doczom 630
        sub     ecx, [esi + CURSOR.hot_x]
631
        lea     ebx, [ecx + 32-1]
2288 clevermous 632
        mov     [x], ecx
633
        sets    dl
634
        dec     edx
635
        and     ecx, edx      ;clip x to 0<=x
636
        mov     [cur.left], ecx
637
        mov     edi, ecx
638
        sub     edi, [x]
639
        mov     [_dx], edi
640
 
641
        xor     edx, edx
9715 Doczom 642
        sub     eax, [esi + CURSOR.hot_y]
2288 clevermous 643
        lea     edi, [eax+32-1]
644
        mov     [y], eax
645
        sets    dl
646
        dec     edx
647
        and     eax, edx      ;clip y to 0<=y
648
        mov     [cur.top], eax
649
        mov     edx, eax
650
        sub     edx, [y]
651
        mov     [_dy], edx
652
 
2446 mario79 653
;        mul     dword [BytesPerScanLine]
9715 Doczom 654
        mov     eax, [BPSLine_calc_area + eax*4]
655
        lea     edx, [LFB_BASE + ecx*3]
2288 clevermous 656
        add     edx, eax
657
        mov     [cur_saved_base], edx
658
 
5350 serge 659
        cmp     ebx, [_display.width]
660
        jb      @F
661
        mov     ebx, [_display.width]
2430 mario79 662
;--------------------------------------
663
align 4
2288 clevermous 664
@@:
5350 serge 665
        cmp     edi, [_display.height]
666
        jb      @F
667
        mov     edi, [_display.height]
2430 mario79 668
;--------------------------------------
669
align 4
2288 clevermous 670
@@:
671
 
672
        sub     ebx, [x]
673
        sub     edi, [y]
2576 mario79 674
        sub     ebx, [_dx]
675
        sub     edi, [_dy]
2288 clevermous 676
 
677
        mov     [cur.w], ebx
678
        mov     [cur.h], edi
679
        mov     [h], edi
680
 
681
        mov     eax, edi
682
        mov     edi, cur_saved_data
2430 mario79 683
;--------------------------------------
684
align 4
2288 clevermous 685
@@:
686
        mov     esi, edx
5351 serge 687
        add     edx, [_display.lfb_pitch]
2288 clevermous 688
        mov     ecx, [cur.w]
9715 Doczom 689
        lea     ecx, [ecx + ecx*2]
2288 clevermous 690
        rep movsb
691
        dec     eax
692
        jnz     @B
693
 
694
;draw cursor
695
        mov     ebx, [cur_saved_base]
696
        mov     eax, [_dy]
697
        shl     eax, 5
698
        add     eax, [_dx]
699
 
700
        mov     esi, [hcursor]
9715 Doczom 701
        mov     esi, [esi + CURSOR.base]
702
        lea     edx, [esi + eax*4]
2430 mario79 703
;--------------------------------------
704
align 4
2288 clevermous 705
.row:
706
        mov     ecx, [cur.w]
707
        mov     esi, edx
708
        mov     edi, ebx
709
        add     edx, 32*4
5351 serge 710
        add     ebx, [_display.lfb_pitch]
2430 mario79 711
;--------------------------------------
712
align 4
2288 clevermous 713
.pix:
714
        lodsd
715
        test    eax, 0xFF000000
716
        jz      @F
717
        mov     [edi], ax
718
        shr     eax, 16
719
        mov     [edi+2], al
2430 mario79 720
;--------------------------------------
721
align 4
2288 clevermous 722
@@:
723
        add     edi, 3
724
        dec     ecx
725
        jnz     .pix
726
 
727
        dec     [h]
728
        jnz     .row
729
        ret
730
endp
2430 mario79 731
;------------------------------------------------------------------------------
2288 clevermous 732
align 4
733
proc move_cursor_32 stdcall, hcursor:dword, x:dword, y:dword
734
           locals
735
             h      dd ?
736
             _dx     dd ?
737
             _dy     dd ?
738
           endl
739
 
740
        mov     esi, [hcursor]
741
        mov     ecx, [x]
742
        mov     eax, [y]
743
 
744
        xor     edx, edx
9715 Doczom 745
        sub     ecx, [esi + CURSOR.hot_x]
2288 clevermous 746
        lea     ebx, [ecx+32-1]
747
        mov     [x], ecx
748
        sets    dl
749
        dec     edx
750
        and     ecx, edx      ;clip x to 0<=x
751
        mov     [cur.left], ecx
752
        mov     edi, ecx
753
        sub     edi, [x]
754
        mov     [_dx], edi
755
 
756
        xor     edx, edx
9715 Doczom 757
        sub     eax, [esi + CURSOR.hot_y]
2288 clevermous 758
        lea     edi, [eax+32-1]
759
        mov     [y], eax
760
        sets    dl
761
        dec     edx
762
        and     eax, edx      ;clip y to 0<=y
763
        mov     [cur.top], eax
764
        mov     edx, eax
765
        sub     edx, [y]
766
        mov     [_dy], edx
767
 
2446 mario79 768
;        mul     dword [BytesPerScanLine]
2480 mario79 769
        mov     eax, [BPSLine_calc_area+eax*4]
9715 Doczom 770
        lea     edx, [LFB_BASE + eax + ecx*4]
2288 clevermous 771
        mov     [cur_saved_base], edx
772
 
5350 serge 773
        cmp     ebx, [_display.width]
774
        jb      @F
775
        mov     ebx, [_display.width]
2430 mario79 776
;--------------------------------------
777
align 4
2288 clevermous 778
@@:
5350 serge 779
        cmp     edi, [_display.height]
780
        jb      @F
781
        mov     edi, [_display.height]
2430 mario79 782
;--------------------------------------
783
align 4
2288 clevermous 784
@@:
785
        sub     ebx, [x]
786
        sub     edi, [y]
2576 mario79 787
        sub     ebx, [_dx]
788
        sub     edi, [_dy]
2288 clevermous 789
 
790
        mov     [cur.w], ebx
791
        mov     [cur.h], edi
792
        mov     [h], edi
793
 
794
        mov     eax, edi
795
        mov     edi, cur_saved_data
2430 mario79 796
;--------------------------------------
797
align 4
2288 clevermous 798
@@:
799
        mov     esi, edx
5351 serge 800
        add     edx, [_display.lfb_pitch]
2288 clevermous 801
        mov     ecx, [cur.w]
802
        rep movsd
803
        dec     eax
804
        jnz     @B
805
 
806
;draw cursor
807
        mov     ebx, [cur_saved_base]
808
        mov     eax, [_dy]
809
        shl     eax, 5
810
        add     eax, [_dx]
811
 
812
        mov     esi, [hcursor]
9715 Doczom 813
        mov     esi, [esi + CURSOR.base]
2288 clevermous 814
        lea     edx, [esi+eax*4]
2430 mario79 815
;--------------------------------------
816
align 4
2288 clevermous 817
.row:
818
        mov     ecx, [cur.w]
819
        mov     esi, edx
820
        mov     edi, ebx
821
        add     edx, 32*4
5351 serge 822
        add     ebx, [_display.lfb_pitch]
2430 mario79 823
;--------------------------------------
824
align 4
2288 clevermous 825
.pix:
826
        lodsd
827
        test    eax, 0xFF000000
828
        jz      @F
829
        mov     [edi], eax
2430 mario79 830
;--------------------------------------
831
align 4
2288 clevermous 832
@@:
833
        add     edi, 4
834
        dec     ecx
835
        jnz     .pix
836
 
837
        dec     [h]
838
        jnz     .row
839
        ret
840
endp
2430 mario79 841
;------------------------------------------------------------------------------
842
align 4
5154 hidnplayr 843
proc move_cursor_16 stdcall, hcursor:dword, x:dword, y:dword
844
           locals
845
             h      dd ?
846
             _dx     dd ?
847
             _dy     dd ?
848
           endl
849
 
850
        mov     esi, [hcursor]
851
        mov     ecx, [x]
852
        mov     eax, [y]
853
 
854
        xor     edx, edx
9715 Doczom 855
        sub     ecx, [esi + CURSOR.hot_x]
856
        lea     ebx, [ecx + 32-1]
5154 hidnplayr 857
        mov     [x], ecx
858
        sets    dl
859
        dec     edx
860
        and     ecx, edx      ;clip x to 0<=x
861
        mov     [cur.left], ecx
862
        mov     edi, ecx
863
        sub     edi, [x]
864
        mov     [_dx], edi
865
 
866
        xor     edx, edx
9715 Doczom 867
        sub     eax, [esi + CURSOR.hot_y]
868
        lea     edi, [eax + 32-1]
5154 hidnplayr 869
        mov     [y], eax
870
        sets    dl
871
        dec     edx
872
        and     eax, edx      ;clip y to 0<=y
873
        mov     [cur.top], eax
874
        mov     edx, eax
875
        sub     edx, [y]
876
        mov     [_dy], edx
877
 
878
;        mul     dword [BytesPerScanLine]
9715 Doczom 879
        mov     eax, [BPSLine_calc_area + eax*4]
880
        lea     edx, [LFB_BASE + eax + ecx*2]
5154 hidnplayr 881
        mov     [cur_saved_base], edx
882
 
5350 serge 883
        cmp     ebx, [_display.width]
884
        jb      @F
885
        mov     ebx, [_display.width]
5154 hidnplayr 886
;--------------------------------------
887
align 4
888
@@:
5350 serge 889
        cmp     edi, [_display.height]
890
        jb      @F
891
        mov     edi, [_display.height]
5154 hidnplayr 892
;--------------------------------------
893
align 4
894
@@:
895
        sub     ebx, [x]
896
        sub     edi, [y]
897
        sub     ebx, [_dx]
898
        sub     edi, [_dy]
899
 
900
        mov     [cur.w], ebx
901
        mov     [cur.h], edi
902
        mov     [h], edi
903
 
904
        mov     eax, edi
905
        mov     edi, cur_saved_data
906
;--------------------------------------
907
align 4
908
@@:
909
        mov     esi, edx
5351 serge 910
        add     edx, [_display.lfb_pitch]
5154 hidnplayr 911
        mov     ecx, [cur.w]
912
 
913
        rep movsw
914
        dec     eax
915
        jnz     @B
916
 
917
;draw cursor
918
        mov     ebx, [cur_saved_base]
919
        mov     eax, [_dy]
920
        shl     eax, 5
921
        add     eax, [_dx]
922
 
923
        mov     esi, [hcursor]
9715 Doczom 924
        mov     esi, [esi + CURSOR.base]
925
        lea     edx, [esi + eax*4]
5154 hidnplayr 926
;--------------------------------------
927
align 4
928
.row:
929
        mov     ecx, [cur.w]
930
        mov     esi, edx
931
        mov     edi, ebx
932
        add     edx, 32*4
5351 serge 933
        add     ebx, [_display.lfb_pitch]
5154 hidnplayr 934
;--------------------------------------
935
align 4
936
.pix:
937
        lodsd
938
        test    eax, 0xFF000000
939
        jz      @F
940
; convert to 16 bpp and store to real LFB
941
        and     eax, 00000000111110001111110011111000b
942
        shr     ah, 2
943
        shr     ax, 3
944
        ror     eax, 8
945
        add     al, ah
946
        rol     eax, 8
947
        mov     [edi], ax
948
;--------------------------------------
949
align 4
950
@@:
951
        add     edi, 2
952
        dec     ecx
953
        jnz     .pix
954
 
955
        dec     [h]
956
        jnz     .row
957
        ret
958
endp
959
;------------------------------------------------------------------------------
960
align 4
2430 mario79 961
check_mouse_area_for_getpixel_new:
962
; in:
963
; eax = x
964
; ebx = y
965
; out:
966
; ecx = new color
967
;--------------------------------------
968
; check for Y
969
        cmp     bx, [Y_UNDER_subtraction_CUR_hot_y]
970
        jb      .no_mouse_area
2288 clevermous 971
 
2430 mario79 972
        cmp     bx, [Y_UNDER_sub_CUR_hot_y_add_curh]
973
        jae     .no_mouse_area
974
;--------------------------------------
975
; check for X
976
        cmp     ax, [X_UNDER_subtraction_CUR_hot_x]
977
        jb      .no_mouse_area
2288 clevermous 978
 
2430 mario79 979
        cmp     ax, [X_UNDER_sub_CUR_hot_x_add_curh]
980
        jae     .no_mouse_area
981
;--------------------------------------
982
        push    eax ebx
983
; offset X
2575 mario79 984
        movzx   ecx, word [X_UNDER_subtraction_CUR_hot_x]
2430 mario79 985
        sub     eax, ecx        ; x1
986
; offset Y
2575 mario79 987
        movzx   ecx, word [Y_UNDER_subtraction_CUR_hot_y]
2430 mario79 988
        sub     ebx, ecx        ; y1
989
;--------------------------------------
990
; ebx = offset y
991
; eax = offset x
992
        imul    ebx, [cur.w]     ;y
993
        add     eax, ebx
994
        mov     ebx, eax
995
        shl     eax, 2
5154 hidnplayr 996
        cmp     byte [_display.bits_per_pixel], 32
2430 mario79 997
        je      @f
998
        sub     eax, ebx
5154 hidnplayr 999
        cmp     byte [_display.bits_per_pixel], 24
1000
        je      @f
1001
        sub     eax, ebx
7510 hidnplayr 1002
        add     eax, cur_saved_data
1003
        mov     ecx, [eax]
1004
        shl     ecx, 3
1005
        ror     ecx, 8
1006
        shl     cx, 2
1007
        ror     ecx, 8
1008
        shl     cl, 3
1009
        rol     ecx, 16
1010
        or      ecx, 0xff000000
1011
        pop     ebx eax
1012
        ret
1013
 
2430 mario79 1014
;--------------------------------------
2288 clevermous 1015
align 4
2430 mario79 1016
@@:
1017
        add     eax, cur_saved_data
1018
        mov     ecx, [eax]
7510 hidnplayr 1019
        or      ecx, 0xff000000
2430 mario79 1020
        pop     ebx eax
1021
        ret
1022
;--------------------------------------
1023
align 4
1024
.no_mouse_area:
1025
        xor     ecx, ecx
1026
        ret
1027
;-----------------------------------------------------------------------------
1028
align 4
1029
check_mouse_area_for_putpixel_new:
1030
; in:
1031
; ecx = x shl 16 + y
1032
; eax = color
1033
; out:
1034
; eax = new color
1035
;--------------------------------------
1036
; check for Y
1037
        cmp     cx, [Y_UNDER_sub_CUR_hot_y_add_curh]
1038
        jae     .no_mouse_area
1039
 
2575 mario79 1040
        sub     cx, [Y_UNDER_subtraction_CUR_hot_y]
1041
        jb      .no_mouse_area
1042
 
2430 mario79 1043
        rol     ecx, 16
1044
;--------------------------------------
1045
; check for X
2575 mario79 1046
        cmp     cx, [X_UNDER_sub_CUR_hot_x_add_curh]
1047
        jae     .no_mouse_area
1048
 
1049
        sub     cx, [X_UNDER_subtraction_CUR_hot_x]
2430 mario79 1050
        jb      .no_mouse_area
1051
 
2575 mario79 1052
        ror     ecx, 16
2430 mario79 1053
;--------------------------------------
1054
align 4
1055
.1:
1056
        push    eax
1057
;--------------------------------------
1058
; ecx = (offset x) shl 16 + (offset y)
1059
        push    ebx
1060
        mov     ebx, ecx
1061
        shr     ebx, 16        ; x
1062
        and     ecx, 0xffff    ; y
2575 mario79 1063
 
1064
        cmp     ecx, [cur.h]
1065
        jae     @f
1066
 
1067
        cmp     ebx, [cur.w]
1068
        jb      .ok
1069
;--------------------------------------
1070
align 4
1071
@@:
1072
;        DEBUGF  1, "K : SHIT HAPPENS: %x %x \n", ecx,ebx
1073
        pop     ebx
1074
        jmp     .sh   ; SORRY! SHIT HAPPENS!
1075
;--------------------------------------
1076
align 4
1077
.ok:
2430 mario79 1078
; ecx = offset y
1079
; ebx = offset x
1080
        push    ebx ecx
1081
        imul    ecx, [cur.w]    ;y
1082
        add     ecx, ebx
1083
        mov     ebx, ecx
1084
        shl     ecx, 2
5154 hidnplayr 1085
        cmp     byte [_display.bits_per_pixel], 16
1086
        je      .16
1087
        cmp     byte [_display.bits_per_pixel], 24
2430 mario79 1088
        je      .24
1089
        and     eax, 0xFFFFFF
1090
        mov     [ecx + cur_saved_data], eax   ;store new color  to
1091
        jmp     @f
1092
;--------------------------------------
1093
align 4
5154 hidnplayr 1094
.16:
1095
        sub     ecx, ebx
1096
        sub     ecx, ebx
1097
; convert to 16 bpp and store to real LFB
1098
        and     eax, 00000000111110001111110011111000b
1099
        shr     ah, 2
1100
        shr     ax, 3
1101
        ror     eax, 8
1102
        add     al, ah
1103
        rol     eax, 8
1104
        mov     [ecx + cur_saved_data], ax      ;store new color  to
1105
        jmp     @f
1106
;--------------------------------------
1107
align 4
2430 mario79 1108
.24:
1109
        sub     ecx, ebx
1110
        mov     [ecx + cur_saved_data], ax      ;store new color  to
1111
        shr     eax, 16
1112
        mov     [ecx + cur_saved_data + 2], al  ;store new color  to
1113
;--------------------------------------
1114
align 4
1115
@@:
1116
        pop     ecx ebx
1117
 
1118
        shl     ecx, 5
1119
        add     ecx, ebx
1120
 
1121
        mov     eax, [current_cursor]
9715 Doczom 1122
        mov     eax, [eax + CURSOR.base]
1123
        lea     eax, [eax + ecx*4]
2430 mario79 1124
        mov     eax, [eax]
1125
 
1126
        pop     ebx
1127
 
1128
        test    eax, 0xFF000000
1129
        jz      @f
1130
 
2652 mario79 1131
        add     esp, 4
2430 mario79 1132
        ret
1133
;--------------------------------------
1134
align 4
2575 mario79 1135
.sh:
1136
        mov     ecx, -1
1137
;--------------------------------------
1138
align 4
2430 mario79 1139
@@:
1140
        pop     eax
1141
;--------------------------------------
1142
align 4
1143
.no_mouse_area:
1144
        ret
1145
;------------------------------------------------------------------------------
1146
align 4
2288 clevermous 1147
get_display:
1148
        mov     eax, _display
1149
        ret
2430 mario79 1150
;------------------------------------------------------------------------------
2288 clevermous 1151
align 4
1152
init_display:
1153
        xor     eax, eax
1154
        mov     edi, _display
1155
 
9715 Doczom 1156
        mov     [edi + display_t.init_cursor], eax
1157
        mov     [edi + display_t.select_cursor], eax
1158
        mov     [edi + display_t.show_cursor], eax
1159
        mov     [edi + display_t.move_cursor], eax
1160
        mov     [edi + display_t.restore_cursor], eax
2288 clevermous 1161
 
9715 Doczom 1162
        lea     ecx, [edi + display_t.cr_list.next]
1163
        mov     [edi + display_t.cr_list.next], ecx
1164
        mov     [edi + display_t.cr_list.prev], ecx
2288 clevermous 1165
 
8284 dunkaist 1166
if ~defined UEFI
2288 clevermous 1167
        cmp     [SCR_MODE], word 0x13
1168
        jbe     .fail
1169
 
1170
        test    word [SCR_MODE], 0x4000
1171
        jz      .fail
8284 dunkaist 1172
end if
2288 clevermous 1173
        mov     ebx, restore_32
1174
        mov     ecx, move_cursor_32
3537 Serge 1175
        mov     edx, Vesa20_putpixel32_new
5154 hidnplayr 1176
        mov     eax, [_display.bits_per_pixel]
3537 Serge 1177
        cmp     al, 32
5154 hidnplayr 1178
        jne     .not_32bpp
2288 clevermous 1179
 
3537 Serge 1180
.set:
2288 clevermous 1181
        mov     [_display.select_cursor], select_cursor
1182
        mov     [_display.move_cursor], ecx
1183
        mov     [_display.restore_cursor], ebx
2430 mario79 1184
        mov     [_display.check_mouse], check_mouse_area_for_putpixel_new
1185
        mov     [_display.check_m_pixel], check_mouse_area_for_getpixel_new
2288 clevermous 1186
 
2436 mario79 1187
        cmp     [PUTPIXEL], dword VGA_putpixel
1188
        je      @f
3537 Serge 1189
        mov     [PUTPIXEL], edx
2436 mario79 1190
@@:
9848 rgimad 1191
        stdcall load_cursor, def_hresize, dword LOAD_FROM_MEM
1192
        mov     [def_cursor_hresize], eax
1193
        stdcall load_cursor, def_vresize, dword LOAD_FROM_MEM
1194
        mov     [def_cursor_vresize], eax
1195
        stdcall load_cursor, def_dresize1, dword LOAD_FROM_MEM
1196
        mov     [def_cursor_dresize1], eax
1197
        stdcall load_cursor, def_dresize2, dword LOAD_FROM_MEM
1198
        mov     [def_cursor_dresize2], eax
1199
 
2497 mario79 1200
        stdcall load_cursor, clock_arrow, dword LOAD_FROM_MEM
1201
        mov     [def_cursor_clock], eax
2288 clevermous 1202
        stdcall load_cursor, def_arrow, dword LOAD_FROM_MEM
1203
        mov     [def_cursor], eax
1204
        ret
3537 Serge 1205
 
5154 hidnplayr 1206
.not_32bpp:
1207
        cmp     al, 24
1208
        jne     .not_24bpp
1209
 
3537 Serge 1210
        mov     ebx, restore_24
1211
        mov     ecx, move_cursor_24
1212
        mov     edx, Vesa20_putpixel24_new
5154 hidnplayr 1213
        jmp     .set
3537 Serge 1214
 
5154 hidnplayr 1215
.not_24bpp:
1216
        cmp     al, 16
1217
        jne     .not_16bpp
1218
        mov     ebx, restore_16
1219
        mov     ecx, move_cursor_16
1220
        mov     edx, Vesa20_putpixel16_new
1221
        jmp     .set
1222
 
1223
.not_16bpp:
1224
;        cmp     al, 15
1225
;        jne     .fail
1226
;        mov     ebx, restore_15
1227
;        mov     ecx, move_cursor_15
1228
;        mov     edx, Vesa20_putpixel15_new
1229
;        jmp     .set
1230
 
2288 clevermous 1231
.fail:
1232
        xor     eax, eax
1233
        mov     [_display.select_cursor], eax
1234
        mov     [_display.move_cursor], eax
1235
        ret
2430 mario79 1236
;------------------------------------------------------------------------------
2288 clevermous 1237
align 4
1238
def_arrow:
1239
  file 'arrow.cur'
2430 mario79 1240
;------------------------------------------------------------------------------
2497 mario79 1241
align 4
9848 rgimad 1242
def_hresize:
1243
  file 'hresize.cur'
1244
;------------------------------------------------------------------------------
1245
align 4
1246
def_vresize:
1247
  file 'vresize.cur'
1248
;------------------------------------------------------------------------------
1249
align 4
1250
def_dresize1:
1251
  file 'dresize1.cur'
1252
;------------------------------------------------------------------------------
1253
align 4
1254
def_dresize2:
1255
  file 'dresize2.cur'
1256
;------------------------------------------------------------------------------
1257
align 4
2497 mario79 1258
clock_arrow:
1259
  file 'arrow_clock.cur'
1260
;------------------------------------------------------------------------------
2288 clevermous 1261