📄 at91display.c
字号:
s1d13806_base->S1D13806_OnChipReg.OCR_LCDDBA_0 = ( char ) lcd_start_address ; s1d13806_base->S1D13806_OnChipReg.OCR_CRTDBA_2 = ( char ) ( crt_start_address >> 16 ) ; s1d13806_base->S1D13806_OnChipReg.OCR_CRTDBA_1 = ( char ) ( crt_start_address >> 8 ) ; s1d13806_base->S1D13806_OnChipReg.OCR_CRTDBA_0 = ( char ) crt_start_address ; seDisplayBlank(TRUE); if (pBmp->BitsPerPixel <= 8) /* no DAC for 16 Bpp */ { /* Init LUT entries */ RGBQUAD rgbQ; BYTE* pLut = &LUT[0]; for ( i=0; i<__pow(2,(double)pBmp->BitsPerPixel); i++ ) { fread(&rgbQ,1,sizeof(RGBQUAD),f); *pLut++ = rgbQ.rgbRed; *pLut++ = rgbQ.rgbGreen; *pLut++ = rgbQ.rgbBlue; } } fseek(f,pBmp->ImageOffset,SEEK_SET); for (i=pBmp->height-1;i>=0;i--) { disp_src = disp_buf; display_mem = (char*) (s1d13806_display_desc.s1d13806_disp_mem_base_add); display_mem += ((y+i)*display_def_desc.hdw*2); fread((char*)(disp_src) ,1, dataSize,f); for (j=0;j<pBmp->width;j++) { if(pBmp->BitsPerPixel==8) { *(short*)(display_mem+(x+j)*2) = *(short*)disp_src; disp_src+=2; }else if(pBmp->BitsPerPixel==16) { *(short*)(display_mem+(x+j)*2) = *(short*)disp_src; disp_src+=2; }else if(pBmp->BitsPerPixel==24) { unsigned b, g, r; b = (*disp_src++) >>3; g = (*disp_src++) <<3 & 0x07e0; r = (*disp_src++) <<8 & 0xf800; *(short*)(display_mem+(x+j)*2) = (WORD) (b|g|r); } } } free(disp_buf); if (pBmp->BitsPerPixel <= 8) /* no DAC for 16 Bpp */ WriteLut( 0, LUT, (int) __pow(2, (double)pBmp->BitsPerPixel) ); seDisplayBlank(FALSE); fclose(f); return 0;}#if 0void InitModeInfo() { unsigned byte,colordepth; LPCONTROL_INFO lpInfo = &Control; AT91PS_S1D13806_Desc s1d13806_base = (AT91PS_S1D13806_Desc) S1D13806_BASE;/* lpInfo->TotalVmem = seGetAvailableMemorySize();*/ // Crack the active display byte = s1d13806_base->S1D13806_OnChipReg.OCR_DM&0x7;// byte = seReadRegByte(0x1fc) & 0x7; if (byte == 0x00 || byte == 0x01) // No display or LCD only... { lpInfo->Width = ((s1d13806_base->S1D13806_OnChipReg.OCR_LCDHDW+1)*8); lpInfo->Height= ( s1d13806_base->S1D13806_OnChipReg.OCR_LCDVDH) +1; colordepth = s1d13806_base->S1D13806_OnChipReg.OCR_LCDDM; //seReadRegByte(0x40); } else // CRT or CRT+LCD, TV etc... { lpInfo->Width = ((s1d13806_base->S1D13806_OnChipReg.OCR_CRTHDW+1)*8); lpInfo->Height= ( s1d13806_base->S1D13806_OnChipReg.OCR_CRTVDH) +1; colordepth = s1d13806_base->S1D13806_OnChipReg.OCR_CRTDM; //seReadRegByte(0x60); } switch (colordepth & 0x7) { case 3: lpInfo->ColorDepth = 8; break; case 4: lpInfo->ColorDepth = 15; break; case 5: lpInfo->ColorDepth = 16; break; default: } switch (lpInfo->ColorDepth) { case 8: s1d13806_base->S1D13806_OnChipReg.OCR_BBLTC=0; //seWriteRegByte(0x101, 0x00); //8BPP blit lpInfo->BytesPerPixel = 1; break; case 15: case 16: s1d13806_base->S1D13806_OnChipReg.OCR_BBLTC=1;//seWriteRegByte(0x101, 0x01); //15/16BPP blit lpInfo->BytesPerPixel = 2; break; } lpInfo->Stride = lpInfo->BytesPerPixel * lpInfo->Width; s1d13806_base->S1D13806_OnChipReg.OCR_LCDMAO = lpInfo->Stride/2;//seWriteRegWord(0x46,lpInfo->Stride/2); s1d13806_base->S1D13806_OnChipReg.OCR_CRTMAO = lpInfo->Stride/2;//seWriteRegWord(0x66,lpInfo->Stride/2); }//---------------------------------------------------------------------------// WaitForBltEnd()//---------------------------------------------------------------------------//// Purpose: //// Returns: // ////---------------------------------------------------------------------------static void WaitForBltEnd(void) { WORD tmp; AT91PS_S1D13806_Desc s1d13806_base = (AT91PS_S1D13806_Desc) S1D13806_BASE; // wait until the Blt Engine is idle and Command Queue is empty while( s1d13806_base->S1D13806_OnChipReg.OCR_BBLTC&0x80); //while (seReadRegByte(0x100) & 0x80); // When MCLK != BUSCLK, the BLT will not start unless the BLT region // is read to help get the internal clocking state synchronized. tmp = *((volatile WORD*)(0x100000 + s1d13806_display_desc.s1d13806_disp_mem_base_add));// tmp = *((volatile WORD*)gLinBltAddr); }static void SolidFillBlt(LPBLT_INFO lpBlt) { WORD BytesPerPixel; DWORD dstAddr; AT91PS_S1D13806_Desc s1d13806_base = (AT91PS_S1D13806_Desc) S1D13806_BASE; if (lpBlt->DstWidth == 0 || lpBlt->DstHeight == 0) return; BytesPerPixel = Control.BytesPerPixel; // wait for any pending blits to end WaitForBltEnd(); // set Fill Blt s1d13806_base->S1D13806_OnChipReg.OCR_BBLTO = 0x0c; //seWriteRegByte(0x103, 0x0c); s1d13806_base->S1D13806_OnChipReg.OCR_BBLTMAO = Control.Stride/2 ;//seWriteRegWord(0x10c, Control.Stride/2); dstAddr = lpBlt->DstLeft*BytesPerPixel + lpBlt->DstTop * Control.Stride; s1d13806_base->S1D13806_OnChipReg.OCR_BBLTDSA_0 = dstAddr ; //seWriteRegByte(0x108, dstAddr); s1d13806_base->S1D13806_OnChipReg.OCR_BBLTDSA_1 = dstAddr>>8 ; //seWriteRegByte(0x109, dstAddr>>8); s1d13806_base->S1D13806_OnChipReg.OCR_BBLTDSA_2 = dstAddr>>16 ; // seWriteRegByte(0x10a, dstAddr>>16); s1d13806_base->S1D13806_OnChipReg.OCR_BBLTW =lpBlt->DstWidth-1;//seWriteRegWord(0x110, lpBlt->DstWidth-1); s1d13806_base->S1D13806_OnChipReg.OCR_BBLTH = lpBlt->DstHeight-1;// seWriteRegWord(0x112, lpBlt->DstHeight-1); s1d13806_base->S1D13806_OnChipReg.OCR_BBLTBC = lpBlt->ColorFg;// seWriteRegWord(0x118, lpBlt->ColorFg); // Engage the blt engine. s1d13806_base->S1D13806_OnChipReg.OCR_BBLTC = 0x80 ;//seWriteRegByte(0x100,0x80); }//---------------------------------------------------------------------------// PatternFillBlt()//---------------------------------------------------------------------------//// Purpose: Performs Pattern Fill Blit with ROP or Transparent.//// Source :// PatStart : video memory offset to the start of the pattern.// // Pattern Phase:// lpBlt->PatternX : x - coord of the first pattern pixel // lpBlt->PatternY : y - coord of the first pattern pixel //// Destination rectangle:// lpBlt->DstLeft// lpBlt->DstTop// lpBlt->DstWidth // lpBlt->DstHeight // // Transparent Pattern Fill Blt:// - transparent color in lpBlt->ColorBg// Solid Pattern Fill Blt:// - ROP in lpBlt->ROP// // Note:// Some cases cannot be handled by hardware. // PatStart is assumed to be aligned on 64 byte boundary for 8 Bpp mode,// on 128 boundary for 15/16 Bpp modes//---------------------------------------------------------------------------static void PatternFillBlt(LPBLT_INFO lpBlt,DWORD PatStart) { int BytesPerPixel; DWORD dstAddr; AT91PS_S1D13806_Desc s1d13806_base = (AT91PS_S1D13806_Desc) S1D13806_BASE; if (lpBlt->DstWidth == 0 || lpBlt->DstHeight == 0) return; BytesPerPixel = Control.BytesPerPixel; // eliminate cases we cannot do in hardware if ((lpBlt->Attribute & 1/*Transparent*/) || lpBlt->ROP == 0x0c || lpBlt->ROP == 0x03) { if (lpBlt->DstWidth == 1 || (lpBlt->DstWidth == 2 && BytesPerPixel == 1)) return; } // The pattern is 8pixels*8lines. // Adjust pattern start for x,y start phases // add 8*PhaseY*BytesPerPixel + PhaseX*BytesPerPixel PatStart += lpBlt->PatternY*BytesPerPixel*8 + lpBlt->PatternX*BytesPerPixel; // Wait for any pending blit to end WaitForBltEnd(); // program relevant blt registers s1d13806_base->S1D13806_OnChipReg.OCR_BBLTSSA_0 = PatStart;//seWriteRegByte(0x104,PatStart); s1d13806_base->S1D13806_OnChipReg.OCR_BBLTSSA_1 = PatStart >> 8;//seWriteRegByte(0x105,PatStart >> 8); s1d13806_base->S1D13806_OnChipReg.OCR_BBLTSSA_2 = PatStart >> 16; //seWriteRegByte(0x106,PatStart >> 16); if (lpBlt->Attribute & Transparent) { s1d13806_base->S1D13806_OnChipReg.OCR_BBLTBC = lpBlt->ColorBg;//seWriteRegWord(0x114, lpBlt->ColorBg); s1d13806_base->S1D13806_OnChipReg.OCR_BBLTO = 0x07; //seWriteRegByte(0x103, 0x07); } else { s1d13806_base->S1D13806_OnChipReg.OCR_BBLTRCCE =lpBlt->ROP ; //seWriteRegByte(0x102, lpBlt->ROP); s1d13806_base->S1D13806_OnChipReg.OCR_BBLTO = 0x06; //seWriteRegByte(0x103, 0x06); } s1d13806_base->S1D13806_OnChipReg.OCR_BBLTMAO = Control.Stride/2 ; //seWriteRegWord(0x10c, Control.Stride/2); dstAddr = lpBlt->DstLeft*BytesPerPixel + lpBlt->DstTop * Control.Stride; s1d13806_base->S1D13806_OnChipReg.OCR_BBLTDSA_0 = dstAddr ; //seWriteRegByte(0x108, dstAddr); s1d13806_base->S1D13806_OnChipReg.OCR_BBLTDSA_1 = dstAddr>>8 ; //seWriteRegByte(0x109, dstAddr>>8); s1d13806_base->S1D13806_OnChipReg.OCR_BBLTDSA_2 = dstAddr>>16 ; // seWriteRegByte(0x10a, dstAddr>>16); s1d13806_base->S1D13806_OnChipReg.OCR_BBLTW =lpBlt->DstWidth-1;//seWriteRegWord(0x110, lpBlt->DstWidth-1); s1d13806_base->S1D13806_OnChipReg.OCR_BBLTH = lpBlt->DstHeight-1;// seWriteRegWord(0x112, lpBlt->DstHeight-1); // Engage the blt engine. s1d13806_base->S1D13806_OnChipReg.OCR_BBLTC = 0x80 ;//seWriteRegByte(0x100,0x80);}void DrawRect(int x,int y,int width,int height,DWORD color) { BLT_INFO Blt; Blt.DstWidth = width; Blt.DstHeight = height; Blt.DstTop = y; Blt.DstLeft = x; Blt.Attribute = 0; Blt.ColorFg = color; SolidFillBlt(&Blt); }static WORD rand16(void) { // Bit 15 of MS rand() is always 0. We want full 16 bit range. return ((rand() << 1) | (rand() & 1)); }static void RandomBltValues(LPBLT_INFO lpBlt) { WORD nMaxX = Control.Width; WORD nMaxY = Control.Height; lpBlt->ColorFg = rand16(); lpBlt->ColorBg = rand16(); lpBlt->ROP = rand() & 0xF; lpBlt->PatternX = rand() & 0x7; lpBlt->PatternY = rand() & 0x7; // Make sure the foreground and background colors are different. if ((lpBlt->ColorBg & 0xFF) == (lpBlt->ColorFg & 0xFF)) lpBlt->ColorBg ^= 0xFF; lpBlt->Attribute = rand() & Transparent; // // Dst location and size. // do { lpBlt->DstTop = (WORD)(rand() % nMaxY-10); } while (lpBlt->DstTop >= nMaxY - 1); do { lpBlt->DstLeft = (WORD)(rand() & 0x07FF); } while (lpBlt->DstLeft +8 >= nMaxX - 1); do { lpBlt->DstWidth = (WORD)(rand() % nMaxX); if (!lpBlt->DstWidth) lpBlt->DstWidth++; //width cannot be 0 } while (lpBlt->DstLeft + lpBlt->DstWidth >= nMaxX); do { lpBlt->DstHeight = (WORD)(rand() & 0x1FF); if (!lpBlt->DstHeight) lpBlt->DstHeight++; //height cannot be 0 } while (lpBlt->DstTop + lpBlt->DstHeight >= nMaxY-2); }DWORD rotl(DWORD data,int n){ return data<<n;}DWORD CreateRandomPattern(LPBLT_INFO lpBlt) { int i; DWORD PatternAddress; WORD pattern[8*8]; DWORD data = rand16(); // generate the 8x8 pattern for (i = 0; i < (8*8*Control.BytesPerPixel)/2 ;i++) { pattern[i] = (WORD)data; data = rotl(data,1); } // for transparent fills, paste in transparent pixels if (lpBlt->Attribute & Transparent) { data = rand16(); if (Control.BytesPerPixel == 2) { WORD *ptrw = (WORD*)pattern; // paste in randomly transparent pixels for (i = 0; i < 36; i++, data >>= 1, ptrw++) { if (i == 32) data = lpBlt->ColorFg; if (data & 1) *ptrw = (WORD)lpBlt->ColorBg; } } else { BYTE *ptrb = (BYTE*)pattern; // paste in randomly transparent pixels for (i = 0; i < 36; i++, data >>= 1, ptrb++) { if (i == 32) data = lpBlt->ColorFg; if (data & 1) *ptrb = (BYTE)lpBlt->ColorBg; } } } // Copy the pattern in the video memory. Here we place it in the // first 128 byte aligned address in the offscreen memory. // PatternAddress = (gOffscreenOffset+127) & 0xffffff80L; PatternAddress = ( Control.Height * Control.Stride+127) & 0xffffff80L; memcpy((DWORD*)( s1d13806_display_desc.s1d13806_disp_mem_base_add+PatternAddress),pattern,(8*8*Control.BytesPerPixel)); return PatternAddress; }//---------------------------------------------------------------------------//// Demonstrate Pattern Fill Blt.////--------------------------------------------------------------------------- void ShowPatternFillBlt(void) { BLT_INFO Blt; DWORD pattaddress; int count = 100;// ClearVideoMemory(); while (count--) { RandomBltValues(&Blt); // eliminate cases hardware cannot handle if ((Blt.Attribute & Transparent) || Blt.ROP == 0x0c || Blt.ROP == 0x03) { if (Blt.DstWidth == 1 || (Blt.DstWidth == 2 && Control.BytesPerPixel == 1)) continue; } pattaddress = CreateRandomPattern(&Blt); PatternFillBlt(&Blt,pattaddress); } }#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -