Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
129 mikedld 1
;-----------------------------------------------------------------------------
2
;///// PART OF ATi RADEON 9000 DRIVER ////////////////////////////////////////
3
;-----------------------------------------------------------------------------
4
; Copyright (c) 2004, mike.dld
5
; Using BeOS driver - Copyright (c) 2002, Thomas Kurschel
6
;-----------------------------------------------------------------------------
7
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
10
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
11
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
12
; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
13
; DEALINGS IN THE SOFTWARE.
14
;-----------------------------------------------------------------------------
15
 
16
DRIVER_CODE_START:
17
 
18
;-----------------------------------------------------------------------------
19
 
384 mikedld 20
include '../const.inc' ; kernel defines
21
 
129 mikedld 22
include 'normal.inc'
23
include 'clipping.asm'
24
 
25
;-----------------------------------------------------------------------------
26
 
27
struct graph_funcs
28
 draw_line        dd ?
29
 disable_mouse    dd ?
30
 draw_pointer     dd ?
31
 draw_mouse_under dd ?
32
 drawbar          dd ?
33
 putpixel         dd ?
34
 getpixel         dd ?
35
 sys_putimage     dd ?
36
 drawbackground   dd ?
37
 calculatescreen  dd ?
38
 setscreen        dd ?
39
ends
40
 
41
SF graph_funcs
42
 
43
call_cnt dd 0
44
viewport RECT
45
 
46
set_bank dd set_bank1
47
setbnk   dd set_bank0,set_bank1,set_s3_bank,set_bank3
48
 
49
virtual at esi
50
  rr RECT
51
end virtual
52
 
53
virtual at 0x00010008
54
  GF graph_funcs
55
end virtual
56
 
57
;-----------------------------------------------------------------------------
58
 
59
CLIP_RECTS = 0x00720000 ; 0x00780000
60
 
384 mikedld 61
;label bg_BytesPerScanLine dword at 0x600000-16;0x460000-16
129 mikedld 62
;label bg_type   dword at 0x600000-12;0x460000-12
63
;label bg_width  dword at 0x600000-8;0x460000-8
64
;label bg_height dword at 0x600000-4;0x460000-4
65
 
384 mikedld 66
label bg_BytesPerScanLine dword at 0x460000-16
129 mikedld 67
label bg_type   dword at 0x460000-12
68
label bg_width  dword at 0x460000-8
69
label bg_height dword at 0x460000-4
70
 
71
BGT_TILE    = 1
72
BGT_STRETCH = 2
73
 
74
;-----------------------------------------------------------------------------
75
 
76
CRTC_INDX       equ     3D4h
77
 
78
func vm_mike_init
79
begin
80
;       jif     dword[mdrvm],e,0,.exit
81
        mov     eax,[0x00010004]
82
        jif     eax,e,'ENUE',.exit
83
        jif     [call_cnt],a,0,.exit.2
84
        add     eax, 0x00010000
85
        mov     [systlb],eax
86
 
87
;       SHFLOW  'System funcs table offset: 0x%x',eax
88
 
89
;--------------------------------------
90
 
91
        mov     esi,0x00010008
92
        mov     edi,SF
93
        mov     ecx,sizeof.graph_funcs/4
94
        cld
95
        rep     movsd
96
 
384 mikedld 97
;       push    dword[CURRENT_TASK]
98
;       mov     dword[CURRENT_TASK],1
129 mikedld 99
;       call    [SF.disable_mouse]
384 mikedld 100
;       pop     dword[CURRENT_TASK]
129 mikedld 101
 
102
        mov     [viewport.left],0
103
        mov     [viewport.top],0
384 mikedld 104
        m2m     [viewport.right],[ScreenWidth]
105
        m2m     [viewport.bottom],[ScreenHeight]
129 mikedld 106
 
384 mikedld 107
        movzx   eax,byte[GFX_CARD_VENDOR]
108
        cmp     byte[VESA_VER_MAJOR],'2'
129 mikedld 109
        jb      @f
110
        mov     al,0
111
    @@: mov     eax,[setbnk+eax*4]
112
        mov     [set_bank],eax
113
 
384 mikedld 114
        mov     al,[ScreenBPP]
129 mikedld 115
        cmp     al,32
116
        jne     @f
117
 
118
;       SHFLOW  'Driver initialized in 32-bit mode'
119
 
120
        mov     [GF.draw_line],vm_mike_draw_line.32
121
;;      mov     [GF.disable_mouse],vm_mike_disable_mouse.32
122
;;      mov     [GF.draw_pointer],vm_mike_draw_pointer.32
123
        mov     [GF.drawbar],vm_mike_draw_rect.32
124
        mov     [GF.putpixel],vm_mike_put_pixel.32
125
        mov     [GF.getpixel],vm_mike_get_pixel.32
126
        mov     [GF.sys_putimage],vm_mike_put_image.32
127
        mov     [GF.drawbackground],vm_mike_draw_bg.32
128
 
129
        jmp     .exit.2
130
 
131
    @@: cmp     al,24
132
        jne     @f
133
 
134
;       SHFLOW  'Driver initialized in 24-bit mode'
135
 
136
        mov     [GF.draw_line],vm_mike_draw_line.24
137
;       mov     [GF.disable_mouse],vm_mike_disable_mouse.24
138
;       mov     [GF.draw_pointer],vm_mike_draw_pointer.24
139
        mov     [GF.drawbar],vm_mike_draw_rect.24
140
        mov     [GF.putpixel],vm_mike_put_pixel.24
141
        mov     [GF.getpixel],vm_mike_get_pixel.24
142
        mov     [GF.sys_putimage],vm_mike_put_image.24
143
        mov     [GF.drawbackground],vm_mike_draw_bg.24
144
 
145
        jmp     .exit.2
146
 
147
    @@: cmp     al,16
148
        jne     @f
149
 
150
;       SHFLOW  'Driver initialized in 16-bit mode'
151
 
152
        mov     [GF.draw_line],vm_mike_draw_line.16
153
;       mov     [GF.disable_mouse],vm_mike_disable_mouse.16
154
;       mov     [GF.draw_pointer],vm_mike_draw_pointer.16
155
        mov     [GF.drawbar],vm_mike_draw_rect.16
156
        mov     [GF.putpixel],vm_mike_put_pixel.16
157
        mov     [GF.getpixel],vm_mike_get_pixel.16
158
        mov     [GF.sys_putimage],vm_mike_put_image.16
159
        mov     [GF.drawbackground],vm_mike_draw_bg.16
160
 
161
        jmp     .exit.2
162
 
163
    @@: cmp     al,15
164
        jne     @f
165
 
166
;       SHFLOW  'Driver initialized in 15-bit mode'
167
 
168
        mov     [GF.draw_line],vm_mike_draw_line.15
169
;       mov     [GF.disable_mouse],vm_mike_disable_mouse.15
170
;       mov     [GF.draw_pointer],vm_mike_draw_pointer.15
171
        mov     [GF.drawbar],vm_mike_draw_rect.15
172
        mov     [GF.putpixel],vm_mike_put_pixel.15
173
        mov     [GF.getpixel],vm_mike_get_pixel.15
174
        mov     [GF.sys_putimage],vm_mike_put_image.15
175
        mov     [GF.drawbackground],vm_mike_draw_bg.15
176
 
177
        jmp     .exit.2
178
 
179
    @@: cmp     al,8
180
        jne     @f
181
 
182
;       SHFLOW  'Driver initialized in 8-bit mode'
183
 
184
        call    setup_palette_8
185
 
186
        mov     [GF.draw_line],vm_mike_draw_line.08
187
;       mov     [GF.disable_mouse],vm_mike_disable_mouse.08
188
;       mov     [GF.draw_pointer],vm_mike_draw_pointer.08
189
        mov     [GF.drawbar],vm_mike_draw_rect.08
190
        mov     [GF.putpixel],vm_mike_put_pixel.08
191
        mov     [GF.getpixel],vm_mike_get_pixel.08
192
        mov     [GF.sys_putimage],vm_mike_put_image.08
193
        mov     [GF.drawbackground],vm_mike_draw_bg.08
194
 
195
        jmp     .exit.2
196
 
197
    @@: cmp     al,4
198
        jne     .exit
199
 
200
;       SHFLOW  'Driver initialized in 4-bit mode'
201
 
202
        mov     [GF.draw_line],vm_mike_draw_line.04
203
;       mov     [GF.disable_mouse],vm_mike_disable_mouse.04
204
;       mov     [GF.draw_pointer],vm_mike_draw_pointer.04
205
        mov     [GF.drawbar],vm_mike_draw_rect.04
206
        mov     [GF.putpixel],vm_mike_put_pixel.04
207
        mov     [GF.getpixel],vm_mike_get_pixel.04
208
        mov     [GF.sys_putimage],vm_mike_put_image.04
209
        mov     [GF.drawbackground],vm_mike_draw_bg.04
210
 
211
;--------------------------------------
212
 
213
  .exit.2:
214
 
215
        mov     [GF.calculatescreen],vm_mike_calculatescreen
216
        mov     [GF.setscreen],vm_mike_setscreen
217
 
384 mikedld 218
;!      mov     [GF.disable_mouse],vm_dummy
219
;!      mov     [GF.draw_pointer],vm_dummy
220
 
129 mikedld 221
        inc     [call_cnt]
222
        xor     eax,eax
223
  .exit.3:
224
        retn
225
  .exit:
226
        xor     eax,eax
227
        dec     eax
228
        retn
229
endf
230
 
384 mikedld 231
func vm_dummy
232
begin
233
	ret
234
endf
235
 
129 mikedld 236
func vm_mike_calculatescreen
237
begin
238
;       call    [SF.calculatescreen]
239
  .direct:
240
        pushad
241
        cli
384 mikedld 242
        movzx   ecx,word[TASK_COUNT]    ; number of processes
129 mikedld 243
        lea     edi,[CLIP_RECTS+ecx*4+4]
384 mikedld 244
        push    dword[CURRENT_TASK]
129 mikedld 245
        xor     eax,eax
246
  .next_window:
247
        inc     eax
248
        push    ecx ebx eax edi
384 mikedld 249
        mov     [CURRENT_TASK],ax
129 mikedld 250
        call    calc_clipping_rects
251
        pop     edi eax ebx
252
        mov     [CLIP_RECTS+eax*4],edi
253
        mov     [edi],ecx
254
        add     edi,4
255
        shl     ecx,2
256
        rep     movsd
257
        pop     ecx
258
        loop    .next_window
384 mikedld 259
        pop     dword[CURRENT_TASK]
129 mikedld 260
        sti
261
        popad
262
        ret
263
endf
264
 
265
func vm_mike_setscreen
266
begin
267
;       call    [SF.setscreen]
268
        call    vm_mike_calculatescreen.direct
269
        ret
270
endf
271
 
272
func vm_mike_uninit
273
begin
274
;       jif     dword[mdrvm],e,0,.exit
275
        jif     [call_cnt],nz,,.exit.2,dec
276
        mov     esi,SF
277
        mov     edi,GF
278
        mov     ecx,sizeof.graph_funcs/4
279
        rep     movsd
280
  .exit.2:
281
        xor     eax,eax
282
        retn
283
  .exit:
284
        xor     eax,eax
285
        dec     eax
286
        retn
287
endf
288
 
289
;-----------------------------------------------------------------------------
290
 
291
include 'norm_04.inc'
292
include 'norm_08.inc'
293
include 'norm_15.inc'
294
include 'norm_16.inc'
295
include 'norm_24.inc'
296
include 'norm_32.inc'
297
 
298
;-----------------------------------------------------------------------------
299
 
300
func is_intersect_rc
301
begin
302
        jif     ecx,l,[tr.left],.exit
303
        jif     edx,l,[tr.top],.exit
304
        jif     ebx,ge,[tr.bottom],.exit
305
        jif     eax,ge,[tr.right],.exit
306
        clc
307
        ret
308
    .exit:
309
        stc
310
        ret
311
endf
312
 
313
func is_intersect_hln
314
begin
315
        jif     edx,l,[tr.left],.exit
316
        jif     eax,l,[tr.top],.exit
317
        jif     eax,ge,[tr.bottom],.exit
318
        jif     ebx,ge,[tr.right],.exit
319
        clc
320
        ret
321
    .exit:
322
        stc
323
        ret
324
endf
325
 
326
func is_intersect_vln
327
begin
328
        jif     eax,l,[tr.left],.exit
329
        jif     edx,l,[tr.top],.exit
330
        jif     ebx,ge,[tr.bottom],.exit
331
        jif     eax,ge,[tr.right],.exit
332
        clc
333
        ret
334
    .exit:
335
        stc
336
        ret
337
endf
338
 
339
func is_intersect_pt
340
begin
341
        jif     eax,l,[tr.left],.exit
342
        jif     ebx,l,[tr.top],.exit
343
        jif     ebx,ge,[tr.bottom],.exit
344
        jif     eax,ge,[tr.right],.exit
345
        clc
346
        ret
347
    .exit:
348
        stc
349
        ret
350
endf
351
 
352
func get_cursor_rect
353
begin
354
        push    eax
384 mikedld 355
        movsx   eax,word[MOUSE_X]
129 mikedld 356
        mov     [tr.left],eax
357
        add     eax,31
358
        mov     [tr.right],eax
384 mikedld 359
        movsx   eax,word[MOUSE_Y]
129 mikedld 360
        mov     [tr.top],eax
361
        add     eax,31
362
        mov     [tr.bottom],eax
363
        pop     eax
364
        ret
365
endf
366
 
367
;-----------------------------------------------------------------------------
368
 
369
gamma_4_0 = 0x00
370
gamma_4_1 = 0x1F
371
gamma_4_2 = 0x2F
372
gamma_4_3 = 0x3F
373
 
374
align 16
375
palette_8_64  rb 256*3
376
palette_8_256 rb 256*3
377
 
378
rept 4 red:0
379
{
380
\rept 4 green:0
381
\{
382
\\rept 4 blue:0
383
\\{
384
   index = ((red shl 4) or (green shl 2) or blue)*3
385
   store gamma_4_  #red   at palette_8_64+index+0
386
   store gamma_4_ \#green at palette_8_64+index+1
387
   store gamma_4_\\#blue  at palette_8_64+index+2
388
   store gamma_4_  #red  *4+red   at palette_8_256+index+0
389
   store gamma_4_ \#green*4+green at palette_8_256+index+1
390
   store gamma_4_\\#blue *4+blue  at palette_8_256+index+2
391
\\}
392
\}
393
}
394
 
395
;rept 64 clr1:0
396
;{
397
; index = clr1*3+64*3
398
; clr2 = clr*4+(clr shr 4)
399
; store clr1 at palette_8_64 +index
400
; store clr2 at palette_8_256+index
401
; index = index + 64*3 + 1
402
; store clr1 at palette_8_64 +index
403
; store clr2 at palette_8_256+index
404
; index = index + 64*3 + 1
405
; store clr1 at palette_8_64 +index
406
; store clr2 at palette_8_256+index
407
;}
408
 
409
func setup_palette_8
410
begin
411
        mov     edx,0x03C8
412
        xor     al,al
413
        out     dx,al
414
        mov     ecx,256*3
415
        mov     edx,0x03C9
416
        mov     esi,palette_8_64
417
        cld
418
        rep     outsb
419
        ret
420
endf
421
 
422
;-----------------------------------------------------------------------------
423
 
424
func set_bank0
425
begin
426
        mov     ebp,[esp+4*1]
427
        ret
428
endf
429
 
430
 
431
; i810/i815
432
; by Protopopius
433
func set_bank1
434
begin
435
        cli
436
        push    eax edx
437
        mov     eax,[esp+4*3]
438
        mov     ebp,eax
439
        shr     eax,16
440
        sub     al,0x0A
384 mikedld 441
        cmp     al,[BANK_RW]
129 mikedld 442
        je      .exit
384 mikedld 443
        mov     [BANK_RW],al
129 mikedld 444
 
445
        mov     dx,3CEh
446
        mov     ah,al           ; Save value for later use
447
        mov     al,10h          ; Index GR10 (Address Mapping)
448
        out     dx,al           ; Select GR10
449
        inc     dl
450
        mov     al,3            ; Set bits 0 and 1 (Enable linear page mapping)
451
        out     dx,al           ; Write value
452
        dec     dl
453
        mov     al,11h          ; Index GR11 (Page Selector)
454
        out     dx,al           ; Select GR11
455
        inc     dl
456
 
457
        mov     al,ah           ; Write address
458
        out     dx,al           ; Write the value
459
 
460
  .exit:
461
        and     ebp,0x0000FFFF
384 mikedld 462
        add     ebp,VGABasePtr
129 mikedld 463
        pop     edx eax
464
        sti
465
        ret
466
endf
467
 
468
 
469
; S3
470
; by kmeaw
471
func set_bank2
472
begin
473
        cli
474
        push    eax edx ecx
475
        mov     eax,[esp+4*4]
476
        mov     ebp,eax
477
        shr     eax,16
478
        sub     al,0x0A
384 mikedld 479
        cmp     al,[BANK_RW]
129 mikedld 480
        je      .exit
384 mikedld 481
        mov     [BANK_RW],al
129 mikedld 482
 
483
        mov     cl,al
484
        mov     dx,0x3D4
485
        mov     al,0x38
486
        out     dx,al
487
        inc     dx
488
        mov     al,0x48
489
        out     dx,al
490
        dec     dx
491
        mov     al,0x31
492
        out     dx,al
493
        inc     dx
494
        in      al,dx
495
        dec     dx
496
        mov     ah,al
497
        mov     al,0x31
498
        out     dx,ax
499
        mov     al,ah
500
        or      al,9
501
        inc     dx
502
        out     dx,al
503
        dec     dx
504
        mov     al,0x35
505
        out     dx,al
506
        inc     dx
507
        in      al,dx
508
        dec     dx
509
        and     al,0xF0
510
        mov     ch,cl
511
        and     ch,0x0F
512
        or      ch,al
513
        mov     al,0x35
514
        out     dx,al
515
        inc     dx
516
        mov     al,ch
517
        out     dx,ax
518
        dec     dx
519
        mov     al,0x51
520
        out     dx,al
521
        inc     dx
522
        in      al,dx
523
        dec     dx
524
        and     al,0xF3
525
        shr     cl,2
526
        and     cl,0x0C
527
        or      cl,al
528
        mov     al,0x51
529
        out     dx,al
530
        inc     dx
531
        mov     al,cl
532
        out     dx,al
533
        dec     dx
534
        mov     al,0x38
535
        out     dx,al
536
        inc     dx
537
        xor     al,al
538
        out     dx,al
539
 
540
  .exit:
541
        and     ebp,0x0000FFFF
384 mikedld 542
        add     ebp,VGABasePtr
129 mikedld 543
        pop     ecx edx eax
544
        sti
545
        ret
546
endf
547
 
548
 
549
; from http://my.execpc.com/CE/AC/geezer/os/slfb.asm
550
func set_s3_bank
551
begin
552
        cli
553
        push    eax edx
554
        mov     eax,[esp+4*3]
555
        mov     ebp,eax
556
        shr     eax,16
557
        sub     al,0x0A
384 mikedld 558
        cmp     al,[BANK_RW]
129 mikedld 559
        je      .exit
384 mikedld 560
        mov     [BANK_RW],al
129 mikedld 561
 
562
        mov ah,al
563
; grrrr...mode-set locked the S3 registers, so unlock them again
564
; xxx - do this after mode-set
565
        mov dx,CRTC_INDX
566
        mov al,38h
567
        out dx,al
568
        inc edx
569
        mov al,48h
570
        out dx,al
571
        dec edx
572
        mov al,39h
573
        out dx,al
574
        inc edx
575
        mov al,0A5h
576
        out dx,al
577
; now: do the bank-switch
578
        mov dx,CRTC_INDX
579
        mov al,35h
580
        out dx,al
581
        inc edx
582
        in al,dx
583
        and al,0F0h
584
        or al,ah
585
        out dx,al
586
 
587
  .exit:
588
        and     ebp,0x0000FFFF
384 mikedld 589
        add     ebp,VGABasePtr
129 mikedld 590
        pop     edx eax
591
        sti
592
        ret
593
endf
594
 
595
 
596
func set_bank3
597
begin
598
        cli
599
        push    eax edx
600
        mov     eax,[esp+4*3]
601
        mov     ebp,eax
602
        shr     eax,16
603
        sub     al,0x0A
384 mikedld 604
        cmp     al,[BANK_RW]
129 mikedld 605
        je      .exit
384 mikedld 606
        mov     [BANK_RW],al
129 mikedld 607
 
608
        mov     ah,al
609
        mov     dx,0x03D4
610
        mov     al,0x39
611
        out     dx,al
612
        inc     dl
613
        mov     al,0xA5
614
        out     dx,al
615
        dec     dl
616
        mov     al,6Ah
617
        out     dx,al
618
        inc     dl
619
        mov     al,ah
620
        out     dx,al
621
        dec     dl
622
        mov     al,0x39
623
        out     dx,al
624
        inc     dl
625
        mov     al,0x5A
626
        out     dx,al
627
        dec     dl
628
 
629
  .exit:
630
        and     ebp,0x0000FFFF
384 mikedld 631
        add     ebp,VGABasePtr
129 mikedld 632
        pop     edx eax
633
        sti
634
        ret
635
endf
636
 
637
;-----------------------------------------------------------------------------
638
 
639
DRIVER_CODE_END:
640
 
641
diff10 'driver code size',DRIVER_CODE_START,DRIVER_CODE_END
642
 
643
;-----------------------------------------------------------------------------
644
;///// END ///////////////////////////////////////////////////////////////////
645
;-----------------------------------------------------------------------------