Subversion Repositories Kolibri OS

Rev

Details | 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
214 serge 7
 
8
format MS COFF
9
 
10
include 'proc32.inc'
281 serge 11
include 'imports.inc'
214 serge 12
 
465 serge 13
API_VERSION     equ 0x01000100
214 serge 14
 
465 serge 15
DEBUG           equ 1
214 serge 16
 
465 serge 17
VID_ATI         equ 0x1002
18
 
227 serge 19
LOAD_FROM_FILE  equ 0
20
LOAD_FROM_MEM   equ 1
21
LOAD_INDIRECT   equ 2
22
LOAD_SYSTEM     equ 3
23
 
465 serge 24
SRV_GETVERSION  equ 0
233 serge 25
 
227 serge 26
struc BITMAPINFOHEADER {
27
  .biSize          dd ? ; DWORD
28
  .biWidth         dd ? ; LONG
29
  .biHeight        dd ? ; LONG
30
  .biPlanes        dw ? ; WORD
31
  .biBitCount      dw ? ; WORD
32
  .biCompression   dd ? ; DWORD
33
  .biSizeImage     dd ? ; DWORD
34
  .biXPelsPerMeter dd ? ; LONG
35
  .biYPelsPerMeter dd ? ; LONG
36
  .biClrUsed       dd ? ; DWORD
37
  .biClrImportant  dd ? ; DWORD
38
}
39
 
40
virtual at 0
41
  BI BITMAPINFOHEADER
42
end virtual
43
 
44
struc CURSOR
281 serge 45
{;common object header
46
   .magic       dd ?   ;'CURS'
47
   .destroy     dd ?   ;internal destructor
48
   .fd          dd ?   ;next object in list
49
   .bk          dd ?   ;prev object in list
50
   .pid         dd ?   ;owner id
51
 
52
 ;cursor data
53
   .base        dd ?   ;allocated memory
54
   .hot_x       dd ?   ;hotspot coords
227 serge 55
   .hot_y       dd ?
56
}
57
virtual at 0
58
  CURSOR CURSOR
59
end virtual
60
 
281 serge 61
CURSOR_SIZE     equ 32
227 serge 62
 
214 serge 63
R8500       equ 0x514C  ;R200
64
R9000       equ 0x4966  ;RV250
65
R9200       equ 0x5961  ;RV280
558 heavyiron 66
R9200SE     equ 0x5964  ;RV280
214 serge 67
R9500       equ 0x4144  ;R300
68
R9500P      equ 0x4E45  ;R300
69
R9550       equ 0x4153  ;RV350
70
R9600       equ 0x4150  ;RV350
71
R9600XT     equ 0x4152  ;RV360
72
R9700P      equ 0x4E44  ;R300
73
R9800       equ 0x4E49  ;R350
74
R9800P      equ 0x4E48  ;R350
75
R9800XT     equ 0x4E4A  ;R360
76
 
465 serge 77
OS_BASE         equ 0x80000000
78
SLOT_BASE       equ (OS_BASE+0x0080000)
214 serge 79
 
80
PG_SW        equ 0x003
81
PG_NOCACHE   equ 0x018
82
 
83
struc IOCTL
84
{  .handle           dd ?
85
   .io_code          dd ?
86
   .input            dd ?
87
   .inp_size         dd ?
88
   .output           dd ?
89
   .out_size         dd ?
90
}
91
 
92
virtual at 0
93
  IOCTL IOCTL
94
end virtual
95
 
378 serge 96
;MMIO                   equ 0F9000000h
97
RD_RB3D_CNTL            equ 1c3ch
214 serge 98
 
99
RD_MEM_CNTL                equ 0140h
100
RD_CRTC_GEN_CNTL           equ 0050h
101
RD_CRTC_CUR_EN             equ 10000h
102
RD_DISPLAY_BASE_ADDR       equ 023ch
103
RD_DEFAULT_OFFSET          equ 16e0h
104
CUR_HORZ_VERT_OFF          equ 0268h
105
CUR_HORZ_VERT_POSN         equ 0264h
106
CUR_OFFSET                 equ 0260h
107
RD_RB3D_CNTL               equ 1c3ch
108
RD_RBBM_STATUS             equ 0e40h
109
RD_RBBM_FIFOCNT_MASK       equ 007fh
110
RD_RBBM_ACTIVE             equ 80000000h
111
RD_TIMEOUT                 equ 2000000
112
 
113
RD_DP_GUI_MASTER_CNTL      equ 0146ch
114
RD_DP_BRUSH_BKGD_CLR       equ 01478h
115
RD_DP_BRUSH_FRGD_CLR       equ 0147ch
116
RD_DP_SRC_BKGD_CLR         equ 015dch
117
RD_DP_SRC_FRGD_CLR         equ 015d8h
118
RD_DP_CNTL                 equ 016c0h
119
RD_DP_DATATYPE             equ 016c4h
120
RD_DP_WRITE_MASK           equ 016cch
121
RD_DP_SRC_SOURCE_MEMORY    equ (2 shl 24)
122
RD_DP_SRC_SOURCE_HOST_DATA equ (3 shl 24)
123
RD_DEFAULT_SC_BOTTOM_RIGHT equ 16e8h
124
RD_GMC_BRUSH_SOLID_COLOR   equ (13 shl 4)
125
RD_DEFAULT_SC_RIGHT_MAX    equ 1fffh
126
RD_DEFAULT_SC_BOTTOM_MAX   equ 1fff0000h
127
RD_GMC_DST_DATATYPE_SHIFT  equ 8
128
 
129
RD_ROP3_S                  equ 00cc0000h
130
RD_ROP3_P                  equ 00f00000h
131
 
132
RD_RB2D_DSTCACHE_MODE      equ 03428h
133
RD_RB2D_DSTCACHE_CTLSTAT   equ 0342ch
134
RD_RB2D_DC_FLUSH_ALL       equ 000fh
135
RD_RB2D_DC_BUSY            equ 80000000h
136
 
137
RD_GMC_BRUSH_SOLID_COLOR   equ 000000D0h
138
RD_GMC_SRC_DATATYPE_COLOR  equ (3 shl 12)
139
RD_GMC_CLR_CMP_CNTL_DIS    equ (1 shl 28)
140
RD_GMC_WR_MSK_DIS          equ (1 shl 30)
141
 
142
cmdSolidFill               equ 73f036d0h
143
 
144
RD_DST_PITCH_OFFSET        equ 142ch
145
RD_SRC_PITCH_OFFSET        equ 1428h
146
 
147
RD_DST_X_LEFT_TO_RIGHT     equ 1
148
RD_DST_Y_TOP_TO_BOTTOM     equ 2
149
RD_DST_Y_X                 equ 1438h
150
RD_DST_WIDTH_HEIGHT        equ 1598h
151
RD_DST_LINE_START          equ 1600h
152
RD_DST_LINE_END            equ 1604h
153
R300_MEM_NUM_CHANNELS_MASK equ 0003h
154
 
155
macro rdr op1, op2
156
{
157
     mov edi, [ati_io]
158
     mov op1, [edi+op2]
159
}
160
 
161
macro wrr dest, src
162
{
163
     mov edi, [ati_io]
164
     mov dword [edi+dest], src
165
}
166
 
167
 
168
public START
169
public service_proc
227 serge 170
public version
214 serge 171
 
172
CURSOR_IMAGE_OFFSET  equ 0x00500000
173
 
174
DRV_ENTRY equ 1
175
DRV_EXIT  equ -1
176
 
177
section '.flat' code readable align 16
178
 
179
proc START stdcall, state:dword
180
 
227 serge 181
           cmp [state], 1
182
           jne .exit
183
 
214 serge 184
     if DEBUG
185
           mov esi, msgInit
186
           call SysMsgBoardStr
187
     end if
188
 
189
           call detect_ati
227 serge 190
           test eax, eax
214 serge 191
           jz .fail
192
 
193
           call init_ati
194
           test eax, eax
195
           jz .fail
196
 
281 serge 197
           or eax, -1
227 serge 198
           mov [cursor_map], eax
199
           mov [cursor_map+4], eax
200
           mov edx, cursor_map
201
           mov [cursor_start], edx
281 serge 202
           add edx, 8
227 serge 203
           mov [cursor_end], edx
204
 
214 serge 205
           stdcall RegService, sz_ati_srv, service_proc
206
           test eax, eax
207
           jz .fail
227 serge 208
           mov dword [SetHwCursor], drvCursorPos ;enable hardware cursor
209
           mov dword [HwCursorRestore], drv_restore
210
           mov dword [HwCursorCreate], ati_cursor
211
           ret
214 serge 212
.fail:
213
     if DEBUG
227 serge 214
           mov esi, msgFail
214 serge 215
           call SysMsgBoardStr
216
     end if
217
 
218
.exit:
219
           xor eax, eax
227 serge 220
;           mov ebx, SetHwCursor
221
;           mov dword [ebx], eax    ;force disable hardware cursor
214 serge 222
           ret
223
endp
224
 
225
handle     equ  IOCTL.handle
226
io_code    equ  IOCTL.io_code
227
input      equ  IOCTL.input
228
inp_size   equ  IOCTL.inp_size
229
output     equ  IOCTL.output
230
out_size   equ  IOCTL.out_size
231
 
232
align 4
233
proc service_proc stdcall, ioctl:dword
234
 
465 serge 235
           mov ebx, [ioctl]
236
           cmp [ebx+io_code], SRV_GETVERSION
233 serge 237
           jne .fail
214 serge 238
 
465 serge 239
           mov eax, [ebx+output]
240
           cmp [ebx+out_size], 4
241
           jne .fail
242
           mov [eax], dword API_VERSION
243
           xor eax, eax
244
           ret
233 serge 245
.fail:
378 serge 246
           or eax, -1
233 serge 247
           ret
214 serge 248
endp
249
 
250
restore   handle
251
restore   io_code
252
restore   input
253
restore   inp_size
254
restore   output
255
restore   out_size
256
 
257
align 4
258
proc detect_ati
227 serge 259
           locals
260
             last_bus dd ?
261
           endl
214 serge 262
 
227 serge 263
           xor eax, eax
264
           mov [bus], eax
265
           inc eax
214 serge 266
           call PciApi
227 serge 267
           cmp eax, -1
214 serge 268
           je .err
269
 
227 serge 270
           mov [last_bus], eax
214 serge 271
 
272
.next_bus:
227 serge 273
           and [devfn], 0
214 serge 274
.next_dev:
275
           stdcall PciRead32, [bus], [devfn], dword 0
227 serge 276
           test eax, eax
277
           jz .next
278
           cmp eax, -1
279
           je .next
214 serge 280
 
227 serge 281
           mov edi, devices
214 serge 282
@@:
227 serge 283
           mov ebx, [edi]
284
           test ebx, ebx
285
           jz .next
214 serge 286
 
227 serge 287
           cmp eax, ebx
288
           je .found
214 serge 289
           add edi, 4
227 serge 290
           jmp @B
214 serge 291
 
227 serge 292
.next:
293
           inc [devfn]
294
           cmp [devfn], 256
295
           jb  .next_dev
296
           mov eax, [bus]
297
           inc eax
298
           mov [bus], eax
299
           cmp eax, [last_bus]
300
           jna .next_bus
301
           xor eax, eax
302
           ret
214 serge 303
.found:
227 serge 304
           xor eax, eax
214 serge 305
           inc eax
227 serge 306
           ret
214 serge 307
.err:
308
           xor eax, eax
309
           ret
310
endp
311
 
312
align 4
313
proc init_ati
314
 
315
           stdcall AllocKernelSpace, dword 0x10000
316
           test eax, eax
317
           jz .fail
318
 
319
           mov [ati_io], eax
320
 
321
           stdcall PciRead32, [bus], [devfn], dword 0x18
322
           and eax, 0xFFFF0000
323
           mov esi, eax
324
 
325
           mov edi, [ati_io]
326
           mov edx, 16
327
@@:
328
           stdcall MapPage,edi,esi,PG_SW+PG_NOCACHE
227 serge 329
           add edi, 0x1000
214 serge 330
           add esi, 0x1000
331
           dec edx
332
           jnz @B
333
 
334
           mov edi, [ati_io]
335
           mov dword [edi+RD_RB3D_CNTL], 0
336
           call engRestore
337
 
338
           mov edi, [ati_io]
339
           mov eax, [edi+0x50]
340
           mov ebx,3
341
           shl ebx,20
342
           not ebx
343
           and eax,ebx
344
           mov ebx, 2
345
           shl ebx,20
346
           or eax, ebx
347
           mov [edi+0x50], eax
348
 
349
           call drvShowCursor
350
           xor eax, eax
351
           inc eax
352
.fail:
353
           ret
354
endp
355
 
356
align 4
227 serge 357
drv_restore:
358
           ret 8
359
 
360
align 4
214 serge 361
drvShowCursor:
362
           mov edi, [ati_io]
363
 
364
           mov eax, [edi+RD_CRTC_GEN_CNTL]
365
           bts eax,16
366
           mov [edi+RD_CRTC_GEN_CNTL], eax
367
           ret
368
 
369
align 4
227 serge 370
proc drvCursorPos stdcall, hcursor:dword, x:dword, y:dword
233 serge 371
           pushfd
372
           cli
227 serge 373
 
233 serge 374
           xor eax, eax
375
           xor edx, edx
376
           mov esi, [hcursor]
377
           mov ebx, [x]
378
           mov ecx, [y]
214 serge 379
 
233 serge 380
           sub ebx, [esi+CURSOR.hot_x]
381
           jnc @F
382
           neg ebx
383
           mov eax, ebx
214 serge 384
           shl eax, 16
233 serge 385
           xor ebx, ebx
386
@@:
387
           sub ecx, [esi+CURSOR.hot_y]
388
           jnc @F
389
           neg ecx
390
           mov ax, cx
391
           mov edx, ecx
392
           xor ecx, ecx
393
@@:
394
           or eax, 0x80000000
395
           wrr CUR_HORZ_VERT_OFF, eax
214 serge 396
 
233 serge 397
           shl ebx, 16
398
           mov bx, cx
399
           or ebx, 0x80000000
400
           wrr CUR_HORZ_VERT_POSN, ebx
401
 
402
           shl edx, 8
403
           add edx, [esi+CURSOR.base]
404
           sub edx, LFBAddress
405
           wrr CUR_OFFSET, edx
406
           popfd
227 serge 407
           ret
408
endp
214 serge 409
 
410
align 4
227 serge 411
proc video_alloc
412
 
413
           pushfd
414
           cli
415
           mov ebx, [cursor_start]
416
           mov ecx, [cursor_end]
417
.l1:
418
           bsf eax,[ebx];
419
           jnz .found
420
           add ebx,4
421
           cmp ebx, ecx
422
           jb .l1
423
           popfd
424
           xor eax,eax
425
           ret
426
.found:
427
           btr [ebx], eax
428
           popfd
429
 
430
           mov [cursor_start],ebx
431
           sub ebx, cursor_map
254 serge 432
           lea eax,[eax+ebx*8]
227 serge 433
 
434
           shl eax,14
435
           add eax, LFBAddress+CURSOR_IMAGE_OFFSET
436
           ret
437
endp
438
 
439
align 4
233 serge 440
video_free:
441
           pushfd
442
           cli
443
           sub eax, LFBAddress+CURSOR_IMAGE_OFFSET
444
           shr eax, 14
445
           mov ebx, cursor_map
446
           bts [ebx], eax
447
           shr eax, 3
448
           and eax, not 3
449
           add eax, ebx
450
           cmp [cursor_start], eax
451
           ja @f
452
           popfd
453
           ret
454
@@:
455
           mov [cursor_start], eax
456
           popfd
457
           ret
458
 
281 serge 459
; param
460
;  eax= pid
461
;  ebx= src
462
;  ecx= flags
463
 
233 serge 464
align 4
281 serge 465
ati_cursor:
466
.src     equ esp
467
.flags   equ esp+4
468
.hcursor equ esp+8
227 serge 469
 
281 serge 470
           sub esp, 4          ;space for .hcursor
471
           push ecx
472
           push ebx
227 serge 473
 
281 serge 474
           mov ebx, eax
475
           mov eax, CURSOR_SIZE
476
           call CreateObject
477
           test eax, eax
478
           jz .fail
479
 
480
           mov [.hcursor],eax
481
 
482
           xor ebx, ebx
483
           mov [eax+CURSOR.magic], 'CURS'
484
           mov [eax+CURSOR.destroy], destroy_cursor
485
           mov [eax+CURSOR.hot_x], ebx
486
           mov [eax+CURSOR.hot_y], ebx
487
 
488
           call video_alloc
489
           mov edi, [.hcursor]
227 serge 490
           mov [edi+CURSOR.base], eax
491
 
281 serge 492
           mov esi, [.src]
493
           mov ebx, [.flags]
227 serge 494
           cmp bx, LOAD_INDIRECT
495
           je .indirect
496
 
497
           movzx ecx, word [esi+10]
498
           movzx edx, word [esi+12]
499
           mov [edi+CURSOR.hot_x], ecx
500
           mov [edi+CURSOR.hot_y], edx
501
 
502
           stdcall ati_init_cursor, eax, esi
281 serge 503
           mov eax, [.hcursor]
227 serge 504
.fail:
281 serge 505
           add esp, 12
227 serge 506
           ret
507
.indirect:
508
           shr ebx, 16
509
           movzx ecx, bh
510
           movzx edx, bl
233 serge 511
           mov [edi+CURSOR.hot_x], ecx
512
           mov [edi+CURSOR.hot_y], edx
227 serge 513
 
281 serge 514
           mov edi, eax
515
           mov ebx, eax
227 serge 516
           mov ecx, 64*64
517
           xor eax,eax
281 serge 518
           cld
227 serge 519
           rep stosd
281 serge 520
           mov edi, ebx
227 serge 521
 
281 serge 522
           mov esi, [.src]
227 serge 523
           mov ebx, 32
524
           cld
525
@@:
526
           mov ecx, 32
527
           rep movsd
528
           add edi, 128
529
           dec ebx
530
           jnz @B
281 serge 531
           mov eax, [.hcursor]
532
           add esp, 12
227 serge 533
           ret
534
 
535
align 4
281 serge 536
destroy_cursor:
537
 
538
           push eax
539
           mov eax, [eax+CURSOR.base]
540
           call video_free
541
           pop eax
542
 
543
           call DestroyObject
544
           ret
545
 
546
align 4
227 serge 547
proc ati_init_cursor stdcall, dst:dword, src:dword
214 serge 548
           locals
549
             rBase    dd ?
550
             pQuad    dd ?
551
             pBits    dd ?
552
             pAnd     dd ?
553
             width    dd ?
554
             height   dd ?
555
             counter  dd ?
556
           endl
557
 
227 serge 558
           mov esi, [src]
559
           add esi,[esi+18]
560
           mov eax,esi
214 serge 561
 
227 serge 562
           cmp [esi+BI.biBitCount], 24
563
           je .img_24
233 serge 564
           cmp [esi+BI.biBitCount], 8
565
           je .img_8
566
           cmp [esi+BI.biBitCount], 4
567
           je .img_4
568
 
569
.img_2:
570
           add eax, [esi]
571
           mov [pQuad],eax
572
           add eax,8
573
           mov [pBits],eax
574
           add eax, 128
575
           mov [pAnd],eax
576
           mov eax,[esi+4]
577
           mov [width],eax
578
           mov ebx,[esi+8]
579
           shr ebx,1
580
           mov [height],ebx
581
 
582
           mov edi, pCursor
583
           add edi, 32*31*4
584
           mov [rBase],edi
585
 
586
           mov esi,[pQuad]
587
.l21:
588
           mov ebx, [pBits]
589
           mov ebx, [ebx]
590
           bswap ebx
591
           mov eax, [pAnd]
592
           mov eax, [eax]
593
           bswap eax
594
           mov [counter], 32
595
@@:
596
           xor edx, edx
597
           shl eax,1
598
           setc dl
599
           dec edx
600
 
601
           xor ecx, ecx
602
           shl ebx,1
603
           setc cl
604
           mov ecx, [esi+ecx*4]
605
           and ecx, edx
606
           and edx, 0xFF000000
607
           or edx, ecx
608
           mov [edi], edx
609
 
610
           add edi, 4
611
           dec [counter]
612
           jnz @B
613
 
614
           add [pBits], 4
615
           add [pAnd], 4
616
           mov edi,[rBase]
617
           sub edi,128
618
           mov [rBase],edi
619
           sub [height],1
620
           jnz .l21
621
           jmp .copy
227 serge 622
.img_4:
214 serge 623
           add eax, [esi]
624
           mov [pQuad],eax
625
           add eax,64
626
           mov [pBits],eax
627
           add eax, 0x200
628
           mov [pAnd],eax
629
           mov eax,[esi+4]
630
           mov [width],eax
631
           mov ebx,[esi+8]
632
           shr ebx,1
633
           mov [height],ebx
634
 
635
           mov edi, pCursor
636
           add edi, 32*31*4
637
           mov [rBase],edi
638
 
233 serge 639
           mov esi,[pQuad]
214 serge 640
           mov ebx, [pBits]
233 serge 641
.l4:
642
           mov eax, [pAnd]
643
           mov eax, [eax]
214 serge 644
           bswap eax
645
           mov [counter], 16
646
@@:
647
           xor edx, edx
648
           shl eax,1
649
           setc dl
650
           dec edx
651
 
233 serge 652
           movzx ecx, byte [ebx]
653
           and cl, 0xF0
214 serge 654
           shr ecx, 2
233 serge 655
           mov ecx, [esi+ecx]
214 serge 656
           and ecx, edx
657
           and edx, 0xFF000000
658
           or edx, ecx
659
           mov [edi], edx
660
 
661
           xor edx, edx
662
           shl eax,1
663
           setc dl
664
           dec edx
665
 
233 serge 666
           movzx ecx, byte [ebx]
667
           and cl, 0x0F
668
           mov ecx, [esi+ecx*4]
214 serge 669
           and ecx, edx
670
           and edx, 0xFF000000
671
           or edx, ecx
672
           mov [edi+4], edx
673
 
674
           inc ebx
675
           add edi, 8
676
           dec [counter]
677
           jnz @B
678
 
233 serge 679
           add [pAnd], 4
214 serge 680
           mov edi,[rBase]
681
           sub edi,128
682
           mov [rBase],edi
683
           sub [height],1
233 serge 684
           jnz .l4
227 serge 685
           jmp .copy
233 serge 686
.img_8:
687
           add eax, [esi]
688
           mov [pQuad],eax
689
           add eax,1024
690
           mov [pBits],eax
691
           add eax, 1024
692
           mov [pAnd],eax
693
           mov eax,[esi+4]
694
           mov [width],eax
695
           mov ebx,[esi+8]
696
           shr ebx,1
697
           mov [height],ebx
214 serge 698
 
233 serge 699
           mov edi, pCursor
700
           add edi, 32*31*4
701
           mov [rBase],edi
702
 
703
           mov esi,[pQuad]
704
           mov ebx, [pBits]
705
.l81:
706
           mov eax, [pAnd]
707
           mov eax, [eax]
708
           bswap eax
709
           mov [counter], 32
710
@@:
711
           xor edx, edx
712
           shl eax,1
713
           setc dl
714
           dec edx
715
 
716
           movzx ecx,  byte [ebx]
717
           mov ecx, [esi+ecx*4]
718
           and ecx, edx
719
           and edx, 0xFF000000
720
           or edx, ecx
721
           mov [edi], edx
722
 
723
           inc ebx
724
           add edi, 4
725
           dec [counter]
726
           jnz @B
727
 
728
           add [pAnd], 4
729
           mov edi,[rBase]
730
           sub edi,128
731
           mov [rBase],edi
732
           sub [height],1
733
           jnz .l81
734
           jmp .copy
227 serge 735
.img_24:
736
           add eax, [esi]
737
           mov [pQuad],eax
738
           add eax, 0xC00
739
           mov [pAnd],eax
740
           mov eax,[esi+BI.biWidth]
741
           mov [width],eax
742
           mov ebx,[esi+BI.biHeight]
743
           shr ebx,1
744
           mov [height],ebx
745
 
746
           mov edi, pCursor
747
           add edi, 32*31*4
748
           mov [rBase],edi
749
 
750
           mov esi,[pAnd]
751
           mov ebx, [pQuad]
752
.row_24:
753
           mov eax, [esi]
754
           bswap eax
755
           mov [counter], 32
756
@@:
757
           xor edx, edx
758
           shl eax,1
759
           setc dl
760
           dec edx
761
 
762
           mov ecx, [ebx]
763
           and ecx, 0x00FFFFFF
764
           and ecx, edx
765
           and edx, 0xFF000000
766
           or edx, ecx
767
           mov [edi], edx
768
           add ebx, 3
769
           add edi, 4
770
           dec [counter]
771
           jnz @B
772
 
773
           add esi, 4
774
           mov edi,[rBase]
775
           sub edi,128
776
           mov [rBase],edi
777
           sub [height],1
778
           jnz .row_24
779
.copy:
780
           mov edi, [dst]
214 serge 781
           mov ecx, 64*64
782
           xor eax,eax
783
           rep stosd
784
 
785
           mov esi, pCursor
227 serge 786
           mov edi, [dst]
214 serge 787
           mov ebx, 32
227 serge 788
           cld
789
@@:
214 serge 790
           mov ecx, 32
227 serge 791
           rep movsd
214 serge 792
           add edi, 128
227 serge 793
           dec ebx
794
           jnz @B
214 serge 795
           ret
796
endp
797
 
798
align 4
799
proc engFlush
800
 
801
           mov edi, [ati_io]
802
 
803
           mov eax, [edi+RD_RB2D_DSTCACHE_CTLSTAT]
804
           or eax,RD_RB2D_DC_FLUSH_ALL
805
           mov [edi+RD_RB2D_DSTCACHE_CTLSTAT],eax
806
 
807
           mov ecx, RD_TIMEOUT
808
@@:
809
           mov eax,[edi+RD_RB2D_DSTCACHE_CTLSTAT]
810
           and eax, RD_RB2D_DC_BUSY
811
           jz .exit
812
 
813
           sub ecx,1
814
           jnz @B
815
.exit:
816
           ret
817
endp
818
 
819
align 4
820
engWaitForFifo:
821
cnt equ bp+8
822
           push ebp
823
           mov ebp, esp
824
 
825
           mov edi, [ati_io]
826
 
827
           mov ecx, RD_TIMEOUT
828
@@:
829
           mov eax, [edi+RD_RBBM_STATUS]
830
           and eax, RD_RBBM_FIFOCNT_MASK
831
           cmp eax, [ebp+8]
832
           jae .exit
833
 
834
           sub ecx,1
835
           jmp @B
836
 
837
.exit:
838
           leave
839
           ret 4
840
 
841
align 4
842
proc engWaitForIdle
843
 
227 serge 844
           push dword 64
845
           call engWaitForFifo
214 serge 846
 
227 serge 847
           mov edi, [ati_io]
848
           mov ecx ,RD_TIMEOUT
214 serge 849
@@:
227 serge 850
           mov eax, [edi+RD_RBBM_STATUS]
851
           and eax,RD_RBBM_ACTIVE
852
           jz .exit
214 serge 853
 
227 serge 854
           sub ecx,1
855
           jnz @B
214 serge 856
.exit:
227 serge 857
           call engFlush
858
           ret
214 serge 859
endp
860
 
861
align 4
862
proc engRestore
863
 
864
;             push dword 1
865
;             call engWaitForFifo
866
 
867
;             mov dword  [MMIO+RD_RB2D_DSTCACHE_MODE], 0
868
 
227 serge 869
           push dword 3
870
           call engWaitForFifo
214 serge 871
 
872
           mov edi, [ati_io]
873
 
874
           mov eax, [edi+RD_DISPLAY_BASE_ADDR]
875
           shr eax, 10d
876
           or eax,(64d shl 22d)
877
           mov [edi+RD_DEFAULT_OFFSET],eax
878
           mov [edi+RD_SRC_PITCH_OFFSET],eax
879
           mov [edi+RD_DST_PITCH_OFFSET],eax
880
 
881
           push dword 1
882
           call engWaitForFifo
883
 
884
           mov edi, [ati_io]
885
           mov eax, [edi+RD_DP_DATATYPE]
886
           btr eax, 29d
887
           mov [edi+RD_DP_DATATYPE],eax
888
 
889
           push dword 1
890
           call engWaitForFifo
891
 
892
           mov edi, [ati_io]
893
           mov dword [edi+RD_DEFAULT_SC_BOTTOM_RIGHT],\
894
                     (RD_DEFAULT_SC_RIGHT_MAX or RD_DEFAULT_SC_BOTTOM_MAX)
895
 
896
           push dword 1
897
           call engWaitForFifo
898
 
899
           mov edi, [ati_io]
900
           mov dword [edi+RD_DP_GUI_MASTER_CNTL],\
901
                     (RD_GMC_BRUSH_SOLID_COLOR or \
902
                      RD_GMC_SRC_DATATYPE_COLOR or \
903
                     (6 shl RD_GMC_DST_DATATYPE_SHIFT) or \
904
                      RD_GMC_CLR_CMP_CNTL_DIS or \
905
                      RD_ROP3_P or \
906
                      RD_GMC_WR_MSK_DIS)
907
 
908
 
909
           push dword 7
910
           call engWaitForFifo
911
 
912
           mov edi, [ati_io]
913
 
914
           mov dword [edi+RD_DST_LINE_START],0
915
           mov dword [edi+RD_DST_LINE_END], 0
916
           mov dword [edi+RD_DP_BRUSH_FRGD_CLR], 808000ffh
917
           mov dword [edi+RD_DP_BRUSH_BKGD_CLR], 002020ffh
918
           mov dword [edi+RD_DP_SRC_FRGD_CLR],   808000ffh
919
           mov dword [edi+RD_DP_SRC_BKGD_CLR],   004000ffh
920
           mov dword [edi+RD_DP_WRITE_MASK],0ffffffffh
921
 
922
           call engWaitForIdle
923
 
924
           ret
925
endp
926
 
927
align 4
928
engSetupSolidFill:
929
           push ebp
930
           mov ebp, esp
931
 
932
           push dword 3
933
           call engWaitForFifo
934
 
935
           wrr RD_DP_GUI_MASTER_CNTL, cmdSolidFill
936
 
937
           mov eax, [ebp+8]
938
           wrr RD_DP_BRUSH_FRGD_CLR,eax
939
 
940
           mov edi, [ati_io]
941
           mov dword [edi+RD_DP_CNTL],(RD_DST_X_LEFT_TO_RIGHT or RD_DST_Y_TOP_TO_BOTTOM)
942
           leave
943
           ret 4
944
 
945
 
946
align 4
947
drvSolidFill:
948
;x:word,y:word,w:word,h:word,color:dword
949
            push ebp
950
            mov ebp, esp
951
x equ ebp+8
952
y equ ebp+12
953
w equ ebp+16
954
h equ ebp+20
955
color equ ebp+24
956
 
227 serge 957
           push dword [ebp+24]
958
           call engSetupSolidFill
214 serge 959
 
227 serge 960
           push dword 2
961
           call engWaitForFifo
214 serge 962
 
227 serge 963
           mov edi, [ati_io]
214 serge 964
 
227 serge 965
           mov eax, [y]
966
           mov ebx, [x]
967
           shl eax,16
968
           or eax, ebx
214 serge 969
 
227 serge 970
           mov ecx,  [w]
971
           mov edx,  [h]
972
           shl ecx,16
973
           or ecx, edx
974
           mov [edi+RD_DST_Y_X], eax
975
           mov [edi+RD_DST_WIDTH_HEIGHT], ecx
976
           call engFlush
977
           leave
978
           ret 20
214 serge 979
 
980
align 4
981
devices dd (R8500   shl 16)+VID_ATI
982
        dd (R9000   shl 16)+VID_ATI
983
        dd (R9200   shl 16)+VID_ATI
558 heavyiron 984
        dd (R9200SE shl 16)+VID_ATI
214 serge 985
        dd (R9500   shl 16)+VID_ATI
986
        dd (R9500P  shl 16)+VID_ATI
987
        dd (R9550   shl 16)+VID_ATI
988
        dd (R9600   shl 16)+VID_ATI
989
        dd (R9600XT shl 16)+VID_ATI
990
        dd (R9700P  shl 16)+VID_ATI
991
        dd (R9800   shl 16)+VID_ATI
992
        dd (R9800P  shl 16)+VID_ATI
993
        dd (R9800XT shl 16)+VID_ATI
994
        dd 0    ;terminator
995
 
465 serge 996
version      dd (5 shl 16) or (API_VERSION and 0xFFFF)
214 serge 997
 
227 serge 998
sz_ati_srv   db 'HWCURSOR',0
214 serge 999
 
1000
msgInit      db 'detect hardware...',13,10,0
1001
msgPCI       db 'PCI accsess not supported',13,10,0
1002
msgFail      db 'device not found',13,10,0
233 serge 1003
msg_neg      db 'neg ecx',13,10,0
1004
buff         db 8 dup(0)
1005
             db 13,10, 0
214 serge 1006
 
1007
section '.data' data readable writable align 16
1008
 
1009
pCursor  db 4096 dup(?)
1010
 
227 serge 1011
cursor_map     rd 2
1012
cursor_start   rd 1
1013
cursor_end     rd 1
214 serge 1014
 
227 serge 1015
bus            dd ?
1016
devfn          dd ?
1017
ati_io         dd ?
214 serge 1018