?? test_main.c.bak
字號(hào):
}
void Led_Display(int LedStatus)
{
//PC1,PC2,PC3 High available
rPDATC=(rPDATC & 0x1f1) | ((LedStatus & 0x7)<<1);
}
void Pixple(int x, int y)
{
U32 *p =(U32*)0x0c000000 + ((320-x)*256+y-1)/32;
if ((U32)p>0x0c00A800 || (U32)p<0x0c000000) return;
if (y%32)
*p |= (1<<(32-(y%32))); else
*p |= 1;
}
void uPixple(int x, int y)
{
U32 *p =(U32*)0x0c000000+ ((320-x)*256+y-1)/32;
if ((U32)p>0x0c00A800 || (U32)p<0x0c000000) return;
if (y%32)
*p &= ~(1<<(32-(y%32))); else
*p &= ~1;
}
void Intro()
{
U32 *video = (U32*)0x0c000000;
int j=0;
while ((U32)video <0x0c00A800) *video ++=bmpIntro[j++];
}
void ClearIntro()
{
int x,y;
for (x=0;x<160;x++)
{
for (y=0;y<240;y++)
{
uPixple(160-x,y);
uPixple(160+x,y);
}
Delay(50);
}
}
const U8 Mouse[35][2]= {
{0,0},{0,1},{0,2},{0,3},{0,4},{0,5},
{0,6},{0,7},{0,8},{0,9},{0,10},{1,1},
{1,10},{2,2},{2,9},{3,3},{3,8},{3,9},
{3,10},{3,11},{3,12},{3,13},{4,4},{4,14},
{5,5},{5,7},{5,8},{5,9},{5,10},{5,11},
{5,12},{5,13},{6,6},{6,7},{7,7}
};
int mPosX, mPosY;
int moPosX, moPosY;
void DrawMousePointer(int x,int y)
{
int i;
for (i=0;i<35;i++)
uPixple(Mouse[i][0]+moPosX, Mouse[i][1]+moPosY);
moPosX = x;
moPosY = y;
for (i=0;i<35;i++)
Pixple(Mouse[i][0]+x, Mouse[i][1]+y);
}
void Uart_Init(int baud)
{
rUFCON0=0x0; //FIFO disable
rUFCON1=0x0;
rUMCON0=0x0;
rUMCON1=0x0;
rULCON0=0x3; //Normal,No parity,1 stop,8 bit
rUCON0=0x245; //rx=edge,tx=level,disable timeout int.,enable rx error int.,normal,interrupt or polling
rUBRDIV0=( (int)(MCLK/16./baud + 0.5) -1 );
}
int Uart_Getch()
{
while(!(rUTRSTAT0 & 0x1)); //Receive data read
return RdURXH0();
}
void Uart_SendByte(int data)
{
while(!(rUTRSTAT0 & 0x2)); //Wait until THR is empty.
Delay(10);
WrUTXH0(data);
}
void Uart_SendString(char *pt)
{
while(*pt)
Uart_SendByte(*pt++);
}
void Uart_Printf(char *fmt,...)
{
va_list ap;
char string[256];
va_start(ap,fmt);
vsprintf(string,fmt,ap);
Uart_SendString(string);
va_end(ap);
}
void WaitForSCK(unsigned char value)
{
int i=0;
while (((rPDATG>>6) & 0x01) != value && i++<3000);
}
int readbit()
{
int i;
WaitForSCK(0);
i= (rPDATG>>5) & 0x01;
WaitForSCK(1);
return i;
}
int ReadMouse()
{
int i, mb,p=0,v;
rPCONG = 0xD7FF;// 01 01
rPDATG |= 0x60;
rPCONG = 0xC3FF; // 00 00
mb = readbit();
if (mb != 0) return;
mb = 0;
for (i=0;i<8;i++)
{
v = readbit();
mb = mb | ( v << i);
p = p + v;
}
v = readbit();
p = p + v;
if ((p&0x01)==0)
{
rPCONG = 0xD7FF;// 01 01
rPDATG |= 0x60;
return;
}
readbit();
return mb;
}
void writebit(int b)
{
WaitForSCK(0);
if (b)
rPDATG |= 0x20; else
rPDATG &= ~0x20;
WaitForSCK(1);
}
void ToMouse(int value)
{
int i;
int p=1;
rPDATG &= ~0x40; // Request to send/
rPCONG = 0xD7FF; // 01 01
for (i=0;i<100;i++);
rPDATG &= ~0x20;
rPDATG |= 0x40;
rPCONG = 0xC7FF; // 00 01
for (i=0;i<8;i++)
{
writebit(value & 0x01);
p = p + value;
value = value >> 1;
}
writebit(p & 0x01);
writebit(1);
rPCONG = 0xC3FF; // 00 00
WaitForSCK(0);
if (((rPDATG>>5) & 0x01)==1)
{
rPCONG = 0xD7FF;// Release Mouse Line.
rPDATG |= 0x60;
return;
}
WaitForSCK(1);
rPCONG = 0xD7FF;// Release Mouse Line.
rPDATG |= 0x60;
ReadMouse();
}
void ProcessKeyboard()
{
}
void ProcessMouse()
{
int b,x,y;
ToMouse(0xEB);
b = ReadMouse();
x = ReadMouse();
y = ReadMouse();
Uart_Printf("\n\r %x, %x, %x", b, x, y);
if (x>0 && x>120) mPosX = mPosX - (256-x); else
if (x>0 && x<120) mPosX = mPosX + x;
if (y>0 && y>120) mPosY = mPosY + (256-y); else
if (y>0 && y<120) mPosY = mPosY - y;
if (mPosX<1) mPosX = 1;
if (mPosY<1) mPosY = 1;
if (mPosX>319) mPosX = 319;
if (mPosY>239) mPosY = 239;
DrawMousePointer(mPosX, mPosY);
Delay(1000);
}
void WriteBYTE(unsigned char cs, unsigned char adr, unsigned char dat)
{
int add = ((adr&0x01)<<4) | ((adr>>1&0x01)<<5) | ((adr>>2&0x01)<<3) | (cs << 1);
(*(volatile U8 *)(0x4000000+add)) = dat;
}
unsigned char ReadBYTE(unsigned char cs, unsigned char adr)
{
int add = ((adr&0x01)<<4) | ((adr>>1&0x01)<<5) | ((adr>>2&0x01)<<3) | (cs << 1);
return (*(volatile U8 *)(0x4000000+add));
}
unsigned char SetMode(unsigned char DriveNo, unsigned char Mode, unsigned char PwrDown)
{
WriteBYTE(1, 6, 0xA0 + (DriveNo ? 0x10:0x00)); // Select drive
WriteBYTE(1, 2, (PwrDown ? 0x01:0x00)); // Enable automatic power down
switch (Mode) {
case 0: WriteBYTE(1,7, 0xE2); break;
case 1: WriteBYTE(1,7, 0xE3); break;
// NOTE: To recover from sleep, either issue a soft or hardware reset !
// (But not on all drives, f.ex seagate ST3655A it's not nessecary to reset
// but only to go in Idle mode, But on a Conner CFA170A it's nessecary with
// a reset)
case 2: WriteBYTE(1,7, 0xE6); break;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -