📄 rinit.c
字号:
int dPru = dPr - (dY<<1); // amount to increment decision if up is chosen
int P = dPr - dY; // decision variable start value
for (; dY>=0; dY--) // process each point in the line one at a time (just use dY)
{
outpix(Ax, Ay, Color); // plot the pixel
if (P > 0) // is the pixel going up AND right?
{
Ax+=Xincr; // increment dependent variable
Ay+=Yincr; // increment independent variable
P+=dPru; // increment decision (for up)
}
else // is the pixel just going up?
{
Ay+=Yincr; // increment independent variable
P+=dPr; // increment decision (for right)
}
}
}
}
/*Just call neccessary number of lines... to make the code easier*/
void fillbar(int Ax, int Ay, int Bx, int By, unsigned long Color)
{
while (Ay < By)
{
line(Ax,Ay,Bx,Ay,Color);Ay++;
}
}
void drawbar(int Ax, int Ay, int Bx, int By, unsigned long Color)
{
line(Ax,Ay,Bx,Ay,Color);
line(Ax,By,Bx,By,Color);
line(Ax,Ay,Ax,By,Color);
line(Bx,Ay,Bx,By,Color);
}
void outchar (char ch, int x, int y, unsigned long color)
{
int i,j;
for (i=0; i < 16; i++) //height=16
{
for (j=0;j<8; j++) //width=8
if (font_ega8x16[(int)ch*16+i] & (0x80 >> j)) //taking character from table and put current mask
outpix(x+j,y+i,color); //put pixel if not zero
}
}
void outtext (int x, int y, unsigned long color, char *text)
{
int xc,yc;
xc = x*8; //width=8
yc = y*16; //height=16
while (*text) //zero-terminated string
{
outchar (*text++,xc,yc,color);
xc += 8;
}
}
/**********************************************************************************************/
/*IO Access functions*/
/**********************************************************************************************/
void OutIORegs(unsigned int index, unsigned long data)
{
io_outdword(defaultdev->io_base + index, data);
}
unsigned long InpIORegs(unsigned int index)
{
return io_indword(defaultdev->io_base + index);
}
void MaskIORegs(unsigned int index, unsigned long andmask, unsigned long ormask)
{
unsigned long temp;
temp=io_indword(defaultdev->io_base + index);
temp&=andmask;temp|=ormask;
io_outdword(defaultdev->io_base + index,temp);
}
/**********************************************************************************************/
/*PLL registers through IO Access functions*/
/**********************************************************************************************/
void ProgPLLDword(unsigned short index, unsigned long data)
{
io_outdword(defaultdev->io_base + CLOCK_CNTL_INDEX,(index & 0x3f) | pllWR_EN);
io_outdword(defaultdev->io_base + CLOCK_CNTL_DATA,data);
io_outdword(defaultdev->io_base + CLOCK_CNTL_INDEX, 0);
}
unsigned long pll_read(unsigned int index)
{
io_outdword(defaultdev->io_base + CLOCK_CNTL_INDEX, index);
return (io_indword(defaultdev->io_base + CLOCK_CNTL_DATA));
}
//Parameter "offset" is an offset of mask inside of dword
void MaskPLLByte(unsigned short index, unsigned char offset,
unsigned char andmask, unsigned char ormask)
{
unsigned long and_mask=(((unsigned long)andmask) << (offset * 8)) | ~((unsigned long)0xff << (offset*8));
unsigned long or_mask=(unsigned long)ormask << (offset * 8);
io_outdword(defaultdev->io_base + CLOCK_CNTL_INDEX,(index & 0x3f) | pllWR_EN);
MaskIORegs(CLOCK_CNTL_DATA,and_mask,or_mask);
io_outdword(defaultdev->io_base + + CLOCK_CNTL_INDEX, 0);
}
/**********************************************************************************************/
/*Memory mapped registers through IO Access functions*/
/**********************************************************************************************/
void OutIndexRegs(unsigned int index, unsigned long data)
{
io_outdword(defaultdev->io_base + ioMM_INDEX,index);
io_outdword(defaultdev->io_base + ioMM_DATA,data);
}
unsigned long InpIndexRegs(unsigned int index)
{
io_outdword(defaultdev->io_base + ioMM_INDEX,index);
return io_indword(defaultdev->io_base + ioMM_DATA);
}
void MaskIndexRegs(unsigned int index, unsigned long andmask, unsigned long ormask)
{
unsigned long temp;
io_outdword(defaultdev->io_base + ioMM_INDEX,index);
temp = io_indword(defaultdev->io_base + ioMM_DATA);
temp = (temp & andmask) | ormask;
io_outdword(defaultdev->io_base + ioMM_DATA,temp);
}
/**********************************************************************************************/
/*Function looks for all supported ATI adapters */
int get_pci_location(void)
{
unsigned int bus;
unsigned int dev;
unsigned int func;
unsigned short temp;
int number_of_devices=0;
int i;
unsigned short* supported;
unsigned short bus_dev_fnc;
unsigned short device_id;
defaultdev=device; //default device is a first found device
for (bus = 0; bus <= 255; bus++) //bus number= 0..255
for (dev = 0; dev < 32; dev++) //device number=0..31
for (func = 0; func < 8; func++) //function number=0..7
{
bus_dev_fnc=(bus << 8) | (dev << 3) | func;
temp = pci_inword(bus_dev_fnc, PCI_VENDOR_ID); //reading vendor ID
if (temp == ATI_VENDOR_ID) // if ATI
{
device_id=(pci_inword(bus_dev_fnc, PCI_DEVICE_ID)); //rading device ID
supported=ati_device_ids; //looking through table of supported devices
do
{
if (device_id == *supported) // if supported device - store parameters
{
device[number_of_devices].busdevfnc=bus_dev_fnc;
device[number_of_devices].config=pci_inword(bus_dev_fnc, PCI_CONFIG);
device[number_of_devices].ID = device_id;
device[number_of_devices].memory_base=pci_indword(bus_dev_fnc, PCI_MEM_BASE) & 0xfffffff0;
if (device[number_of_devices].memory_base == 0)
{
printf("\nNo memory mapped to ATI board 0x%x", device_id);
break;
}
device[number_of_devices].io_base=pci_inword(bus_dev_fnc, PCI_IO_BASE) & 0xfffc;
if (device[number_of_devices].io_base == 0)
{
printf("\nNo memory mapped to ATI board 0x%x", device_id);
break;
}
device[number_of_devices].revision=pci_inword(bus_dev_fnc, PCI_REVISION);
number_of_devices++;
break;
}
} while (supported++);
break;
}
}
return(number_of_devices);
}
///////////////////////////////////////////////////////////////////////////////
//Timer fucntions
///////////////////////////////////////////////////////////////////////////////
#define TICKS_ADJUSTMENT 8 //Makes big delays a little more precise
unsigned short ReadTimer0(void)
{
unsigned short TimerValue;
io_outbyte(TIMER_CHANNEL_MODE,6);
TimerValue=io_inbyte(TIMER_CHANNEL_COUNTER);
TimerValue|=io_inbyte(TIMER_CHANNEL_COUNTER)<<8;
return TimerValue;
}
// Timer0 overflows every 55 ms and it counts down at speed of 1.1932 MHz
// How to convert from Microseconds to ticks: ticks=2*1.1932*microseconds.
///////////////////////////////////////////////////////////////////////////////
void delay_ns(unsigned long Microseconds)
{
//32 ms is approximately 76 ticks
unsigned long LoopCount = ((Microseconds*4)>>5); //divide by 32
unsigned short StartTime, Now, diff;
if(LoopCount)
{
do
{
StartTime=ReadTimer0();
while(1)
{
Now = ReadTimer0();
if ( StartTime>=Now )
diff = StartTime - Now;
else
diff = StartTime + (0xFFFF-Now);
if( diff >= (76-TICKS_ADJUSTMENT) )
{
break;
}
}
}
while(--LoopCount!=0);
}
//Process the Rest (& small delays)
//Ticks=rest (microseconds) *2
StartTime=ReadTimer0();
while(1)
{
Now = ReadTimer0();
if ( StartTime>=Now )
diff = StartTime - Now;
else
diff = StartTime + (0xFFFF-Now);
if( diff >= (Microseconds%32<<1) )
{
break;
}
}
}
///////////////////////////////////////////////////////////////////////////////
/*Checking if pointer is valid*/
void general_validate(struct tables_info* table)
{
unsigned char * pointer=*table->pointer;
if (*(pointer-1) > MAX_REVISION) //Checking table's revision
{
printf("\nWrong revision of %s !\n",table->description);
pointer = NULL;
return;
}
if (pointer < (buffer + MIN_TABLE_POINTER_ALLOWED)) // and dislocation
{
printf("\nWrong pointer to %s !\n",table->description);
pointer = NULL;
return;
}
}
/* Looking for tables which do not have pointers in ROM header: */
/* such as ASIC init table 3 and 4. It's known that they are begining after definite */
/* table ends (parent_table). Currently ASIC Init table N3 starts after */
/* ASIC Init table N2 and ASIC Init table N4 starts after ASIC Init table N3*/
unsigned char* look_for_add_init_table (unsigned char** parent_table)
{
unsigned char* table = *parent_table;
if (table != NULL)
{
while (*(unsigned short*)table != 0) // Goes though the parent table
{ // It must be one of the ASIC init tables
if (table[1] & 0x40) table += 10;
else if (table[1] & 0x80) table += 4;
else table += 6;
}
return(table+2); // end of the parent table
}
// sends message if parent table == NULL
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -