⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vd_lcdframebuffer.c

📁 X-scale 27x 平台
💻 C
字号:
//
// Copyright (c) Chrontel Inc.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Chrontel end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

Module Name:  
   vd_LcdFrameBuffer.c
   
Abstract:  

Revision:
   12/11/02  Roger Yu. Created File     

Notes: 
--*/
#include "chrontel.h"
#include "lcd.h"


//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
// NOTE: MUST also reserved in config.bib file
//\\/\\/\\//\\/\\//\\//\\//\\//\\//\\//\\//
#define CH_LCD_MEMORY_PHYADR PHYADR_LCD_FRAME_MEMORY_ORIG

#define CH_LCD_MEMORY_SIZE   0x130000     // 2 640x480x16 pages plus DMA

//--
volatile LCD_PALETTE  *v_pPaletteBuffer=NULL;

PBYTE virtFlatFrameBuffer=NULL;
PBYTE physFlatFrameBuffer=NULL;

volatile LCD_FRAME_DESCRIPTOR	*frameDescriptorCh0=NULL;
volatile LCD_FRAME_DESCRIPTOR	*frameDescriptorCh1=NULL;
volatile LCD_FRAME_DESCRIPTOR	*frameDescriptorPalette=NULL;

// change lcdFramePages to 1 if need save memory, (DDRAW may want more video pages)
unsigned lcdFramePages=2;
unsigned lcdFramePageSize;
unsigned lcdPaletteSize =0x20;
unsigned lcdFrameBitsPerPixel=4;

//++++++++++++++++++++++++++++++++++++++++++++++++++++
static PBYTE physFlatPalette=NULL;
static PBYTE virtLcdDmaDesc = NULL;
static PBYTE lcdPhysDmaDesc;

//++++
static PBYTE pb_v_pPaletteBuffer=NULL;
static PBYTE pb_virtFlatFrameBuffer=NULL;
static PBYTE pb_virtLcdDmaDesc = NULL;
//++++

//pointers for all memory (palette, frame buffer, DMA descriptor)
static PBYTE virtLcdmemory=NULL;
static PBYTE physLcdmemory=NULL;


/*
    // LCD Palette Size (8bpp:200h/4bpp:20h/1bpp:4h )
#define PHYADR_LCD_PALETTE_SIZE 0x20
    // LCD Palette Buffer (200h bytes)

#define PHYADR_LCD_PALETTE_BUFFER (PHYADR_LCD_FRAME_MEMORY_ORIG)

// For 1024x768x2=0x180000, 2 frame need 0x300000 plus 30h for LCD DMA scriptor
//     800x600x2=0xEA600
//     640x480x2=0x96000 
#define PHYADR_LCD_FRAME_BUFFER_SIZE  0x96000
#define PHYADR_LCD_FRAME_BUFFER  (PHYADR_LCD_PALETTE_BUFFER + PHYADR_LCD_PALETTE_SIZE)

    // LCD DMA Descriptor PhyAddr
#define PHYADR_LCD_DMADESC      (PHYADR_LCD_FRAME_BUFFER+PHYADR_LCD_FRAME_BUFFER_SIZE)
*/


void CleanupLcdMemory();

int AllocLcdMemory(int sx, int sy, int bpp)
{
	unsigned bs;


	// If not enough for 2 pages then set as 1 page
	if (CH_LCD_MEMORY_SIZE < (sx*sy*4)) lcdFramePages =1;

	switch (bpp) {
		case 8:
			lcdPaletteSize=0x200; bs=1; 
            lcdFrameBitsPerPixel =3;
			break;
		case 16:
            lcdFrameBitsPerPixel =4;
		default:
			lcdPaletteSize=0x20; bs=2;
	}
	// calsulate need frame buffer size

	lcdFramePageSize = bs*sx*sy; 
	bs = lcdFramePageSize*lcdFramePages;

	physLcdmemory = (PBYTE)CH_LCD_MEMORY_PHYADR;
    virtLcdmemory = (PBYTE)VirtualAllocCopy(CH_LCD_MEMORY_SIZE, &pb_v_pPaletteBuffer, (PVOID)physLcdmemory);
		
	if (NULL==virtLcdmemory) return -1;

    // we DO NOT need map physical memory to virtual memory.
//    physLcdmemory = physLcdmemory;
    physFlatPalette = physLcdmemory;
    physFlatFrameBuffer = physLcdmemory + lcdPaletteSize;
    lcdPhysDmaDesc = physFlatFrameBuffer + bs;

    v_pPaletteBuffer = (volatile LCD_PALETTE  *)virtLcdmemory;
	virtFlatFrameBuffer = virtLcdmemory + lcdPaletteSize;
	virtLcdDmaDesc = virtFlatFrameBuffer + bs;

    
// set up the DMA descriptor
    frameDescriptorPalette = (LCD_FRAME_DESCRIPTOR *)virtLcdDmaDesc;
    frameDescriptorCh0 = (LCD_FRAME_DESCRIPTOR *)(virtLcdDmaDesc + 2*sizeof(LCD_FRAME_DESCRIPTOR));
    frameDescriptorCh1 = (LCD_FRAME_DESCRIPTOR *)(virtLcdDmaDesc + 1*sizeof(LCD_FRAME_DESCRIPTOR));

    return 0;  // success
}

void CleanupLcdMemory()
{

//@@@Note:
// Since the virtual address is included when we allocate physical frame memory,
// here we DO NOT do the VirtualFree operation.

	if (virtLcdmemory) VirtualFree((PVOID)v_pPaletteBuffer, 0, MEM_RELEASE);
	virtLcdmemory = NULL;

	v_pPaletteBuffer = NULL;
	virtFlatFrameBuffer = NULL;
	virtLcdDmaDesc = NULL;
    frameDescriptorCh0 = NULL;
    frameDescriptorCh1 = NULL;
    frameDescriptorPalette = NULL;

	return;

}


void SetDmaDescriptor(int dual_panel, int page, unsigned sx, unsigned sy, int dbl_line)
{
	if (frameDescriptorCh0) {
		unsigned ps;
		ps = page*lcdFramePageSize + (unsigned)physFlatFrameBuffer;
        
		frameDescriptorCh1->FDADR = (unsigned int)(lcdPhysDmaDesc + 1*sizeof(LCD_FRAME_DESCRIPTOR));
		frameDescriptorCh1->FIDR = frameDescriptorCh1->FDADR;   // 0;
		frameDescriptorCh1->FSADR = (unsigned)(ps + (lcdFramePageSize>>1));
		frameDescriptorCh1->LDCMD = (lcdFramePageSize>>1);

		if (lcdFrameBitsPerPixel <4) 
			frameDescriptorCh0->FDADR = (unsigned int)(lcdPhysDmaDesc);
		else frameDescriptorCh0->FDADR = (unsigned int)(lcdPhysDmaDesc + 2*sizeof(LCD_FRAME_DESCRIPTOR));

		frameDescriptorCh0->FSADR = (unsigned int)ps;
		frameDescriptorCh0->FIDR =  (unsigned int)(lcdPhysDmaDesc + 2*sizeof(LCD_FRAME_DESCRIPTOR));   // 0;
		if (dual_panel) frameDescriptorCh0->LDCMD = (lcdFramePageSize>>1);
		else     frameDescriptorCh0->LDCMD = lcdFramePageSize;

		frameDescriptorPalette->FDADR = (unsigned int)(lcdPhysDmaDesc + 2*sizeof(LCD_FRAME_DESCRIPTOR));
		frameDescriptorPalette->FSADR = (unsigned)physFlatPalette;
		frameDescriptorPalette->FIDR = (unsigned int)(lcdPhysDmaDesc);   // 0;
		frameDescriptorPalette->LDCMD = LCD_Pal + lcdPaletteSize;

		if ((!dual_panel) && (dbl_line)) {  // we will double vertical lines if required)
	       ULONG pad;
		   ULONG psad;
		   volatile LCD_FRAME_DESCRIPTOR *p;
		   unsigned i;

		   pad = (ULONG)(lcdPhysDmaDesc + 2*sizeof(LCD_FRAME_DESCRIPTOR));
		   psad = (ULONG)physFlatFrameBuffer;
           p=frameDescriptorCh0 = (LCD_FRAME_DESCRIPTOR *)(virtLcdDmaDesc + 2*sizeof(LCD_FRAME_DESCRIPTOR));

		   if (lcdFrameBitsPerPixel ==4) sx = sx*2; // 16bit color=2Bytes; 8bit color=1Byte !!!
		   for (i=0; i<sy; i++) {
			   p->FDADR = pad + sizeof(LCD_FRAME_DESCRIPTOR);
			   p->FIDR = pad;
			   p->FSADR = psad;
			   p->LDCMD = sx;  
			   p++;
			   pad+= sizeof(LCD_FRAME_DESCRIPTOR);
//			   psad += 320*2;
			   if (i==(sy-1)) p->FDADR = frameDescriptorCh0->FIDR;
			   else p->FDADR = pad + sizeof(LCD_FRAME_DESCRIPTOR);
			   p->FIDR = pad;
			   p->FSADR = psad;
			   p->LDCMD = sx;
			   p++;
			   pad+= sizeof(LCD_FRAME_DESCRIPTOR);
 		       psad += sx;
		   }

		   if (lcdFrameBitsPerPixel <4) {
			   pad = frameDescriptorCh0->FDADR;
               frameDescriptorCh0->FDADR = (unsigned int)(lcdPhysDmaDesc);
			   frameDescriptorPalette->FDADR = pad;
		   }

		}
	}
	return;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -