2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
5 Desc: vesa "hardware" functions
10 #define DEBUG 1 /* no SysBase */
11 #include <aros/asmcall.h>
12 #include <aros/debug.h>
13 #include <aros/macros.h>
14 #include <aros/bootloader.h>
16 #include <proto/bootloader.h>
17 #include <proto/oop.h>
18 #include <utility/hooks.h>
19 #include <utility/tagitem.h>
24 #include "vesagfxclass.h"
30 extern struct ExecBase
*SysBase
;
31 OOP_AttrBase HiddPCIDeviceAttrBase
;
32 static void Find_PCI_Card(struct HWData
*sd
);
34 unsigned char cursorPalette
[] =
41 BOOL
initVesaGfxHW(struct HWData
*data
)
43 struct BootLoaderBase
*BootLoaderBase
;
47 if ((BootLoaderBase
= OpenResource("bootloader.resource")))
49 D(bug("[Vesa] Init: Bootloader.resource opened\n"));
50 if ((vi
= (struct VesaInfo
*)GetBootInfo(BL_Video
)))
52 D(bug("[Vesa] Init: Got Vesa structure from resource\n"));
53 if (vi
->ModeNumber
== 3)
55 D(bug("[Vesa] Init: Textmode was specified. Aborting\n"));
59 /* Disable on-screen debug output to avoid trashing graphics */
62 data
->width
= vi
->XSize
; data
->height
= vi
->YSize
;
63 data
->bitsperpixel
= data
->depth
= vi
->BitsPerPixel
;
64 data
->bytesperline
= vi
->BytesPerLine
;
65 data
->redmask
= vi
->Masks
[VI_Red
];
66 data
->greenmask
= vi
->Masks
[VI_Green
];
67 data
->bluemask
= vi
->Masks
[VI_Blue
];
68 data
->redshift
= vi
->Shifts
[VI_Red
];
69 data
->greenshift
= vi
->Shifts
[VI_Green
];
70 data
->blueshift
= vi
->Shifts
[VI_Blue
];
71 data
->framebuffer
= vi
->FrameBuffer
;
72 data
->palettewidth
= vi
->PaletteWidth
;
74 if (!data
->framebuffer
)
76 if (!data
->framebuffer
) {
77 D(bug("[Vesa] HwInit: Framebuffer not found\n"));
83 data
->bytesperpixel
= 4;
85 else if (data
->depth
> 16)
87 data
->bytesperpixel
= 3;
89 else if (data
->depth
> 8)
91 data
->bytesperpixel
= 2;
95 data
->bytesperpixel
= 1;
99 col
= (1 << data
->depth
) - 7;
100 for (i
= 0; i
< 9; i
++)
101 data
->DAC
[col
*3+i
] = cursorPalette
[i
];
102 DACLoad(data
, col
, 3);
104 D(bug("[Vesa] HwInit: Clearing framebuffer at 0x%08x size %d KB\n",data
->framebuffer
, vi
->FrameBufferSize
));
105 memset(data
->framebuffer
, 0, vi
->FrameBufferSize
* 1024);
106 D(bug("[Vesa] HwInit: Linear framebuffer at 0x%08x\n",data
->framebuffer
));
107 D(bug("[Vesa] HwInit: Screenmode %dx%dx%d\n",data
->width
,data
->height
,data
->depth
));
108 D(bug("[Vesa] HwInit: Masks R %08x<<%2d G %08x<<%2d B %08x<<%2d\n",
109 data
->redmask
, data
->redshift
,
110 data
->greenmask
, data
->greenshift
,
111 data
->bluemask
, data
->blueshift
));
112 D(bug("[Vesa] HwInit: PaletteWidth %d\n", data
->palettewidth
));
113 D(bug("[vesa] HwInit: BytesPerPixel %d\n", data
->bytesperpixel
));
118 bug("[Vesa] HwInit: No Vesa information from the bootloader. Failing\n");
124 void vesaRefreshArea(struct BitmapData
*data
, LONG x1
, LONG y1
, LONG x2
, LONG y2
)
127 ULONG srcmod
, dstmod
;
130 x1
*= data
->bytesperpix
;
131 x2
*= data
->bytesperpix
; x2
+= data
->bytesperpix
- 1;
138 srcmod
= (data
->bytesperline
- w
);
139 dstmod
= (data
->data
->bytesperline
- w
);
141 src
= data
->VideoData
+ y1
* data
->bytesperline
+ x1
;
142 dst
= data
->data
->framebuffer
+ y1
* data
->data
->bytesperline
+ x1
;
144 for(y
= 0; y
< h
; y
++)
146 for(x
= 0; x
< w
/ 4; x
++)
148 *((ULONG
*)dst
) = *((ULONG
*)src
);
149 dst
+= sizeof(ULONG
);
150 src
+= sizeof(ULONG
);
159 AROS_UFH3(void, Enumerator
,
160 AROS_UFHA(struct Hook
*, hook
, A0
),
161 AROS_UFHA(OOP_Object
*, pciDevice
, A2
),
162 AROS_UFHA(APTR
, message
, A1
))
170 struct pHidd_PCIDriver_MapPCI mappci
,*msg
= &mappci
;
171 struct HWData
*sd
= hook
->h_Data
;
173 D(bug("[VESA] Enumerator: Found device\n"));
175 OOP_GetAttr(pciDevice
, aHidd_PCIDevice_Driver
, (IPTR
*)&driver
);
176 OOP_GetAttr(pciDevice
, aHidd_PCIDevice_VendorID
, &Vendor
);
177 OOP_GetAttr(pciDevice
, aHidd_PCIDevice_Base0
, (IPTR
*)&buf
);
178 OOP_GetAttr(pciDevice
, aHidd_PCIDevice_Size0
, &size
);
180 /* BIOS of S3 video cards may forget to set up linear framebuffer start address.
181 Here we do this manually.
182 This thing was looked up in x.org S3 driver source code. Applicable to all S3 cards. */
183 if (Vendor
== PCI_VENDOR_S3
) {
184 outb(0x59, vgaIOBase
+ 4);
185 outb((IPTR
)buf
>> 24, vgaIOBase
+ 5);
186 outb(0x5A, vgaIOBase
+ 4);
187 outb((IPTR
)buf
>> 16, vgaIOBase
+ 5);
190 mappci
.mID
= OOP_GetMethodID(IID_Hidd_PCIDriver
, moHidd_PCIDriver_MapPCI
);
191 mappci
.PCIAddress
= buf
;
192 mappci
.Length
= size
;
193 sd
->framebuffer
= (APTR
)OOP_DoMethod(driver
, (OOP_Msg
)msg
);
195 D(bug("[VESA] Got framebuffer @ %x (size=%x)\n", sd
->framebuffer
, size
));
201 static void Find_PCI_Card(struct HWData
*sd
)
205 D(bug("[VESA] Find_PCI_Card\n"));
207 if (HiddPCIDeviceAttrBase
)
209 pci
= OOP_NewObject(NULL
, CLID_Hidd_PCI
, NULL
);
211 D(bug("[VESA] Creating PCI object\n"));
215 struct Hook FindHook
= {
216 h_Entry
: (IPTR (*)())Enumerator
,
220 struct TagItem Requirements
[] = {
221 { tHidd_PCI_Interface
, 0x00 },
222 { tHidd_PCI_Class
, 0x03 },
223 { tHidd_PCI_SubClass
, 0x00 },
227 struct pHidd_PCI_EnumDevices enummsg
= {
228 mID
: OOP_GetMethodID(IID_Hidd_PCI
, moHidd_PCI_EnumDevices
),
230 requirements
: (struct TagItem
*)&Requirements
,
232 D(bug("[VESA] Calling search Hook\n"));
233 OOP_DoMethod(pci
, (OOP_Msg
)msg
);
234 OOP_DisposeObject(pci
);
243 void DACLoad(struct HWData
*restore
, unsigned char first
, int num
)
249 for (i
=0; i
<num
*3; i
++)
251 outb(restore
->DAC
[n
++], 0x3C9);