Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
221 serge 1
 
2
LOAD_FROM_MEM   equ 1
3
LOAD_INDIRECT   equ 2
4
LOAD_SYSTEM     equ 3
5
6
 
224 serge 7
  .biSize          dd ? ; DWORD
8
  .biWidth         dd ? ; LONG
9
  .biHeight        dd ? ; LONG
10
  .biPlanes        dw ? ; WORD
11
  .biBitCount      dw ? ; WORD
12
  .biCompression   dd ? ; DWORD
13
  .biSizeImage     dd ? ; DWORD
14
  .biXPelsPerMeter dd ? ; LONG
15
  .biYPelsPerMeter dd ? ; LONG
16
  .biClrUsed       dd ? ; DWORD
17
  .biClrImportant  dd ? ; DWORD
18
}
19
20
 
21
  BI BITMAPINFOHEADER
22
end virtual
23
24
 
221 serge 25
proc vesa_init_cursor stdcall, dst:dword, src:dword
26
           locals
27
             rBase    dd ?
28
             pQuad    dd ?
29
             pBits    dd ?
30
             pAnd     dd ?
31
             width    dd ?
32
             height   dd ?
33
             counter  dd ?
34
           endl
35
36
 
37
           add esi,[esi+18]
224 serge 38
           mov eax,esi
39
221 serge 40
 
224 serge 41
           je .img_24
42
.img_4:
43
           add eax, [esi]
221 serge 44
           mov [pQuad],eax
45
           add eax,64
46
           mov [pBits],eax
47
           add eax, 0x200
48
           mov [pAnd],eax
49
           mov eax,[esi+4]
50
           mov [width],eax
51
           mov ebx,[esi+8]
52
           shr ebx,1
53
           mov [height],ebx
54
55
 
56
           add edi, 32*31*4
57
           mov [rBase],edi
58
59
 
60
           mov ebx, [pBits]
61
.l1:
62
           mov eax, [esi]
63
           bswap eax
64
           mov [counter], 16
65
@@:
66
           xor edx, edx
67
           shl eax,1
68
           setc dl
69
           dec edx
70
71
 
72
           and ecx, 0xF0
73
           shr ecx, 2
74
           add ecx, [pQuad]
75
           mov ecx, [ecx]
76
           and ecx, edx
77
           and edx, 0xFF000000
78
           or edx, ecx
79
           mov [edi], edx
80
81
 
82
           shl eax,1
83
           setc dl
84
           dec edx
85
86
 
87
           and ecx, 0x0F
88
           shl ecx, 2
89
           add ecx, [pQuad]
90
           mov ecx, [ecx]
91
           and ecx, edx
92
           and edx, 0xFF000000
93
           or edx, ecx
94
           mov [edi+4], edx
95
96
 
97
           add edi, 8
98
           dec [counter]
99
           jnz @B
100
101
 
102
           mov edi,[rBase]
103
           sub edi,128
104
           mov [rBase],edi
105
           sub [height],1
106
           jnz .l1
107
           ret
108
.img_24:
224 serge 109
           add eax, [esi]
110
           mov [pQuad],eax
111
           add eax, 0xC00
112
           mov [pAnd],eax
113
           mov eax,[esi+BI.biWidth]
114
           mov [width],eax
115
           mov ebx,[esi+BI.biHeight]
116
           shr ebx,1
117
           mov [height],ebx
118
119
 
120
           add edi, 32*31*4
121
           mov [rBase],edi
122
123
 
124
           mov ebx, [pQuad]
125
.row_24:
126
           mov eax, [esi]
127
           bswap eax
128
           mov [counter], 32
129
@@:
130
           xor edx, edx
131
           shl eax,1
132
           setc dl
133
           dec edx
134
135
 
136
           and ecx, 0x00FFFFFF
137
           and ecx, edx
138
           and edx, 0xFF000000
139
           or edx, ecx
140
           mov [edi], edx
141
           add ebx, 3
142
           add edi, 4
143
           dec [counter]
144
           jnz @B
145
146
 
147
           mov edi,[rBase]
148
           sub edi,128
149
           mov [rBase],edi
150
           sub [height],1
151
           jnz .row_24
152
           ret
153
endp
221 serge 154
155
 
156
proc alloc_cursor
157
158
 
159
           cli
160
           mov ebx, [cursor_start]
161
           mov ecx, [cursor_end]
162
.l1:
163
           bsf eax,[ebx];
164
           jnz .found
165
           add ebx,4
166
           cmp ebx, ecx
167
           jb .l1
168
           popfd
169
           xor eax,eax
170
           ret
171
.found:
172
           btr [ebx], eax
173
           popfd
227 serge 174
175
 
221 serge 176
           sub ebx, cursor_map
177
           shl ebx, 3
178
           add eax,ebx
179
           shl eax,3
180
           lea eax,[cursors+eax+eax*2]
181
227 serge 182
 
183
           mov [eax+CURSOR.magic], 'CURS'
184
           mov [eax+CURSOR.size],  CURSOR_SIZE
185
           mov [eax+CURSOR.pid], ebx
186
           mov [eax+CURSOR.hot_x], ebx
187
           mov [eax+CURSOR.hot_y], ebx
188
           ret
221 serge 189
endp
190
191
 
192
proc set_cursor stdcall, hcursor:dword
227 serge 193
           mov eax, [hcursor]
194
           mov ebx, [CURRENT_TASK]
195
           shl ebx, 8
196
           xchg eax, [ebx+PROC_BASE+APPDATA.cursor]
197
           ret
198
endp
199
221 serge 200
 
227 serge 201
202
 
203
           test eax, eax
221 serge 204
           jz .fail
205
206
 
227 serge 207
           mov [edi+CURSOR.base], eax
208
221 serge 209
 
227 serge 210
           mov ebx, [flags]
211
           cmp bx, LOAD_INDIRECT
212
           je .indirect
213
221 serge 214
 
227 serge 215
           movzx edx, word [esi+12]
216
           mov [edi+CURSOR.hot_x], ecx
217
           mov [edi+CURSOR.hot_y], edx
218
221 serge 219
 
227 serge 220
           mov eax, [hcursor]
221
.fail:
221 serge 222
           ret
223
.indirect:
227 serge 224
           shr ebx, 16
225
           movzx ecx, bh
226
           movzx edx, bl
227
           mov [eax+CURSOR.hot_x], ecx
228
           mov [eax+CURSOR.hot_y], edx
229
221 serge 230
 
227 serge 231
           mov ecx, 1024
232
           cld
233
           rep movsd
234
           ret
221 serge 235
endp
236
237
 
238
proc load_cursor stdcall, src:dword, flags:dword
239
           locals
240
             handle  dd ?
241
           endl
242
243
 
227 serge 244
           mov [handle], eax
245
           cmp word [flags], LOAD_FROM_FILE
246
           jne @F
247
221 serge 248
 
249
           test eax, eax
250
           jz .exit
251
           mov [src], eax
252
@@:
227 serge 253
           call alloc_cursor
254
           test eax, eax
221 serge 255
           jz .fail
256
257
 
227 serge 258
           mov [handle], eax
221 serge 259
.fail:
227 serge 260
           cmp word [flags], LOAD_FROM_FILE
261
           jne .exit
262
           stdcall kernel_free, [src]
221 serge 263
.exit:
227 serge 264
           mov eax, [handle]
221 serge 265
           ret
266
endp
267
268
 
269
proc init_cursors
270
           movzx eax, byte [ScreenBPP]
271
           mov ebx, [SCR_BYTES_PER_LINE]
272
           cmp eax, 32
273
           jne @F
274
           sub ebx, 128
275
           jmp .init
276
@@:
277
           cmp eax, 24
278
           jne .fail
279
           sub ebx, 96
280
.init:
281
           mov [cur_def_interl], ebx
282
283
 
284
           mov edi, cursors
285
           mov ecx, CURSOR_SIZE*16
286
           cld
287
           rep stosd
288
289
 
290
           mov [cursor_map], eax
291
           mov [cursor_map+4], eax
292
           mov edx, cursor_map
293
           mov [cursor_start], edx
294
           add edx, 4
295
           mov [cursor_end], edx
296
297
 
227 serge 298
           test eax, eax
299
           jz .sw_mouse
300
301
 
221 serge 302
           mov [def_cursor], eax
303
           ret
227 serge 304
.sw_mouse:
305
           mov [create_cursor], vesa_cursor
306
221 serge 307
 
227 serge 308
           mov [def_cursor], eax
309
310
 
221 serge 311
           mov edx, [SCR_Y_SIZE]
312
           inc ecx
313
           inc edx
314
           mov [scr_width], ecx
315
           mov [scr_height], edx
316
317
 
318
           cmp ebx, 32
319
           jne @F
320
321
 
322
           mov dword [hw_restore], restore_32
323
           ret
324
@@:
325
           mov dword [set_hw_cursor], cursor_24
326
           mov dword [hw_restore], restore_24
327
           ret
328
.fail:
329
           xor eax, eax
330
           mov dword [set_hw_cursor], eax
331
           mov dword [hw_restore], eax
332
           ret
333
endp
334
335
 
336
proc restore_24 stdcall, x:dword, y:dword
337
           locals
338
             w  dd ?
339
           endl
340
341
 
342
           mov edx, [cur_saved_h]
343
           mov ebx, [cur_saved_interl]
344
345
 
346
@@:
347
           mov ecx, [cur_saved_w]
348
           lea ecx, [ecx+ecx*2]
349
           rep movsb
350
           add edi, ebx
351
           dec edx
352
           jnz @B
353
           ret
354
endp
355
356
 
357
proc restore_32 stdcall, x:dword, y:dword
358
           locals
359
             w  dd ?
360
           endl
361
362
 
363
           mov edx, [cur_saved_h]
364
           mov ebx, [cur_saved_interl]
365
366
 
367
@@:
368
           mov ecx, [cur_saved_w]
369
           rep movsd
370
           add edi, ebx
371
           dec edx
372
           jnz @B
373
           ret
374
endp
375
376
 
377
proc cursor_24 stdcall, hcursor:dword, x:dword, y:dword
378
           locals
379
             w      dd ?
380
             h      dd ?
381
             st     dd ?
382
             _dx     dd ?
383
             _dy     dd ?
384
           endl
385
386
 
387
           mov ecx, [x]
388
           mov eax, [y]
389
           mov ebx, [BytesPerScanLine]
390
391
 
392
           sub ecx, [esi+CURSOR.hot_x]
393
           mov [x], ecx
394
           sets dl
395
           dec edx
396
           and ecx, edx       ;clip x to 0<=x
397
           mov edi, ecx
398
           sub edi, [x]
399
           mov [_dx], edi
400
401
 
402
           sub eax, [esi+CURSOR.hot_y]
403
           mov [y], eax
404
           sets dl
405
           dec edx
406
           and eax, edx       ;clip y to 0<=y
407
           mov edi, eax
408
           sub edi, [y]
409
           mov [_dy], edi
410
411
 
412
           lea esi, [ecx+ecx*2]
413
           add esi, [LFBAddress]
414
           add esi, eax
415
           mov [cur_saved_base],esi
416
417
 
418
           mov edx, [scr_height]
419
           mov eax, 32
420
421
 
422
           cmp edi, eax
423
           jng @F
224 serge 424
           mov edi, eax
425
@@:
426
           sub edi, [_dx]
221 serge 427
428
 
429
           cmp edx, eax
430
           jng @F
224 serge 431
           mov edx, eax
432
@@:
433
           sub edx, [_dy]
221 serge 434
435
 
436
           mov [h], edx
437
           mov [cur_saved_w], edi
438
           mov [cur_saved_h], edx
439
440
 
441
           shl eax, 2       ;lea eax, [eax+eax*2]
224 serge 442
           lea edi, [edi+edi*2]
221 serge 443
           sub ebx, edi
444
           mov [cur_saved_interl], ebx
445
446
 
447
@@:
448
           mov ecx, [w]
449
           lea ecx, [ecx+ecx*2]
450
           rep movsb
451
           add esi, ebx
452
           dec edx
453
           jnz @B
454
455
 
456
           mov edx, eax
457
           mov edi, [cur_saved_base]
458
           mov eax, [_dy]
459
           shl eax, 5
460
           add eax, [_dx]
461
           shl eax, 2
462
463
 
464
           mov esi, [esi+CURSOR.base]
465
           add esi, eax
466
.row:
467
           mov ecx, [w]
468
.pix:
469
           lodsd
470
           test eax, 0xFF000000
471
           jz @F
472
473
 
474
           shr eax, 16
475
           mov [edi+2],al
476
@@:
477
           add edi, 3
478
           dec ecx
479
           jnz .pix
480
481
 
482
           add edi, ebx
483
           dec [h]
484
           jnz .row
485
           ret
486
endp
487
488
 
489
proc cursor_32 stdcall, hcursor:dword, x:dword, y:dword
490
           locals
491
             w      dd ?
492
             h      dd ?
493
             st     dd ?
494
             _dx     dd ?
495
             _dy     dd ?
496
           endl
497
498
 
499
           mov ecx, [x]
500
           mov eax, [y]
501
           mov ebx, [BytesPerScanLine]
502
503
 
504
           sub ecx, [esi+CURSOR.hot_x]
505
           mov [x], ecx
506
           sets dl
507
           dec edx
508
           and ecx, edx       ;clip x to 0<=x
509
           mov edi, ecx
510
           sub edi, [x]
511
           mov [_dx], edi
512
513
 
514
           sub eax, [esi+CURSOR.hot_y]
515
           mov [y], eax
516
           sets dl
517
           dec edx
518
           and eax, edx       ;clip y to 0<=y
519
           mov edi, eax
520
           sub edi, [y]
521
           mov [_dy], edi
522
523
 
524
           lea esi, [eax+ecx*4]
525
           add esi, [LFBAddress]
526
           mov [cur_saved_base],esi
527
528
 
529
           mov edx, [scr_height]
530
           mov eax, 32
531
532
 
533
           cmp edi, eax
534
           jng @F
224 serge 535
           mov edi, eax
536
@@:
537
           sub edi, [_dx]
221 serge 538
539
 
540
           cmp edx, eax
541
           jng @F
224 serge 542
           mov edx, eax
543
@@:
544
           sub edx, [_dy]
221 serge 545
546
 
547
           mov [h], edx
548
           mov [cur_saved_w], edi
549
           mov [cur_saved_h], edx
550
551
 
552
           shl eax, 2
553
           shl edi, 2
554
           sub ebx, edi
555
           mov [cur_saved_interl], ebx
556
557
 
558
@@:
559
           mov ecx, [w]
560
           rep movsd
561
           add esi, ebx
562
           dec edx
563
           jnz @B
564
565
 
566
           mov edx, eax
567
           mov edi, [cur_saved_base]
568
           mov eax, [_dy]
569
           shl eax, 5
570
           add eax, [_dx]
571
           shl eax, 2
572
573
 
574
           mov esi, [esi+CURSOR.base]
575
           add esi, eax
576
.row:
577
           mov ecx, [w]
578
.pix:
579
           lodsd
580
           test eax, 0xFF000000
581
           jz @F
582
           mov [edi], eax
583
@@:
584
           add edi, 4
585
           dec ecx
586
           jnz .pix
587
           add esi, edx
588
           add edi, ebx
589
           dec [h]
590
           jnz .row
591
           ret
592
endp
593
594
 
595
def_arrow:
596
  file 'arrow.cur'
597
>
598