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

📄 cirrus.c

📁 linux 下svgalib编的一个界面程序示例
💻 C
📖 第 1 页 / 共 4 页
字号:
	}/* Macros for memory-mapped I/O BitBLT register access. *//* MMIO addresses (offset from 0xb8000). */#define MMIOBACKGROUNDCOLOR	0x00#define MMIOFOREGROUNDCOLOR	0x04#define MMIOWIDTH		0x08#define MMIOHEIGHT		0x0A#define MMIODESTPITCH		0x0C#define MMIOSRCPITCH		0x0E#define MMIODESTADDR		0x10#define MMIOSRCADDR		0x14#define MMIOBLTWRITEMASK	0x17#define MMIOBLTMODE		0x18#define MMIOROP			0x1A#define MMIOBLTSTATUS		0x40#define MMIOSETDESTADDR(addr) \  *(unsigned int *)(MMIO_POINTER + MMIODESTADDR) = addr;#define MMIOSETSRCADDR(addr) \  *(unsigned int *)(MMIO_POINTER + MMIOSRCADDR) = addr;/* Pitch: the 5426 goes up to 4095, the 5434 can do 8191. */#define MMIOSETDESTPITCH(pitch) \  *(unsigned short *)(MMIO_POINTER + MMIODESTPITCH) = pitch;#define MMIOSETSRCPITCH(pitch) \  *(unsigned short *)(MMIO_POINTER + MMIOSRCPITCH) = pitch;/* Width: the 5426 goes up to 2048, the 5434 can do 8192. */#define MMIOSETWIDTH(width) \  *(unsigned short *)(MMIO_POINTER + MMIOWIDTH) = (width) - 1;/* Height: the 5426 goes up to 1024, the 5434 can do 2048. */#define MMIOSETHEIGHT(height) \  *(unsigned short *)(MMIO_POINTER + MMIOHEIGHT) = (height) - 1;#define MMIOSETBLTMODE(m) \  *(unsigned char *)(MMIO_POINTER + MMIOBLTMODE) = m;#define MMIOSETBLTWRITEMASK(m) \  *(unsigned char *)(MMIO_POINTER + MMIOBLTWRITEMASK) = m;#define MMIOSETROP(rop) \  *(unsigned char *)(MMIO_POINTER + MMIOROP) = rop;#define MMIOSTARTBLT() \  *(unsigned char *)(MMIO_POINTER + MMIOBLTSTATUS) |= 0x02;#define MMIOBLTBUSY(s) \  s = *(volatile unsigned char *)(MMIO_POINTER + MMIOBLTSTATUS) & 1;#define MMIOSETBACKGROUNDCOLOR(c) \  *(unsigned char *)(MMIO_POINTER + MMIOBACKGROUNDCOLOR) = c;#define MMIOSETFOREGROUNDCOLOR(c) \  *(unsigned char *)(MMIO_POINTER + MMIOFOREGROUNDCOLOR) = c;#define MMIOSETBACKGROUNDCOLOR16(c) \  *(unsigned short *)(MMIO_POINTER + MMIOBACKGROUNDCOLOR) = c;#define MMIOSETFOREGROUNDCOLOR16(c) \  *(unsigned short *)(MMIO_POINTER + MMIOFOREGROUNDCOLOR) = c;#define MMIOSETBACKGROUNDCOLOR32(c) \  *(unsigned int *)(MMIO_POINTER + MMIOBACKGROUNDCOLOR) = c;#define MMIOSETFOREGROUNDCOLOR32(c) \  *(unsigned int *)(MMIO_POINTER + MMIOFOREGROUNDCOLOR) = c;#define MMIOWAITUNTILFINISHED() \	for (;;) { \		int busy; \		MMIOBLTBUSY(busy); \		if (!busy) \			break; \	}static int cirrus_pattern_address;	/* Pattern with 1's (8 bytes) */static int cirrus_bitblt_pixelwidth;/* Foreground color is not preserved on 5420/2/4/6/8. */static int cirrus_accel_foreground_color;void __svgalib_cirrusaccel_init(AccelSpecs * accelspecs, int bpp, int width_in_pixels){    /* [Setup accelerator screen pitch] */    /* [Prepare any required off-screen space] */    if (cirrus_chiptype < CLGD5426)	/* No BitBLT engine. */	return;    if (bpp == 8)	cirrus_bitblt_pixelwidth = 0;    if (bpp == 16)	cirrus_bitblt_pixelwidth = PIXELWIDTH16;    if (bpp == 32)	cirrus_bitblt_pixelwidth = PIXELWIDTH32;    SETSRCPITCH(__svgalib_accel_screenpitchinbytes);    SETDESTPITCH(__svgalib_accel_screenpitchinbytes);    SETROP(0x0D);    cirrus_pattern_address = cirrus_memory * 1024 - 8;    (*__svgalib_driverspecs->__svgalib_setpage) (cirrus_pattern_address / 65536);    gr_writel(0xffffffff, cirrus_pattern_address & 0xffff);    gr_writel(0xffffffff, (cirrus_pattern_address & 0xffff) + 4);    (*__svgalib_driverspecs->__svgalib_setpage) (0);    if (cirrus_chiptype >= CLGD5429)	/* Enable memory-mapped I/O. */	__svgalib_outSR(0x17, __svgalib_inSR(0x17) | 0x04);}/* * Note: The foreground color register must always be reset to 0 * on the 542x to avoid problems in normal framebuffer operation. * This is not the case on chips that support memory-mapped I/O. *//* * These are two auxilliary functions to program the foreground * color depending on the current depth. */static void set_foreground_color(int fg){    if (__svgalib_accel_bytesperpixel == 1) {	SETFOREGROUNDCOLOR(fg);	return;    }    if (__svgalib_accel_bytesperpixel == 2) {	SETFOREGROUNDCOLOR16(fg);	return;    }    SETFOREGROUNDCOLOR32(fg);}static void mmio_set_foreground_color(int fg){    if (__svgalib_accel_bytesperpixel == 1) {	MMIOSETFOREGROUNDCOLOR(fg);	return;    }    if (__svgalib_accel_bytesperpixel == 2) {	MMIOSETFOREGROUNDCOLOR16(fg);	return;    }    MMIOSETFOREGROUNDCOLOR32(fg);}#define FINISHBACKGROUNDBLITS() \	if (__svgalib_accel_mode & BLITS_IN_BACKGROUND) \		WAITUNTILFINISHED();#define MMIOFINISHBACKGROUNDBLITS() \	if (__svgalib_accel_mode & BLITS_IN_BACKGROUND) \		MMIOWAITUNTILFINISHED();void __svgalib_cirrusaccel_FillBox(int x, int y, int width, int height){    int destaddr;    destaddr = BLTBYTEADDRESS(x, y);    width *= __svgalib_accel_bytesperpixel;    FINISHBACKGROUNDBLITS();    SETSRCADDR(cirrus_pattern_address);    SETDESTADDR(destaddr);    SETWIDTH(width);    SETHEIGHT(height);    set_foreground_color(cirrus_accel_foreground_color);    SETBLTMODE(COLOREXPAND | PATTERNCOPY | cirrus_bitblt_pixelwidth);    STARTBLT();    WAITUNTILFINISHED();    /* Can't easily run in background because foreground color has */    /* to be restored. */    SETFOREGROUNDCOLOR(0x00);}void __svgalib_cirrusaccel_mmio_FillBox(int x, int y, int width, int height){    int destaddr;    destaddr = BLTBYTEADDRESS(x, y);    width *= __svgalib_accel_bytesperpixel;    MMIOFINISHBACKGROUNDBLITS();    MMIOSETSRCADDR(cirrus_pattern_address);    MMIOSETDESTADDR(destaddr);    MMIOSETWIDTH(width);    MMIOSETHEIGHT(height);    MMIOSETBLTMODE(COLOREXPAND | PATTERNCOPY | cirrus_bitblt_pixelwidth);    MMIOSTARTBLT();    if (!(__svgalib_accel_mode & BLITS_IN_BACKGROUND))	MMIOWAITUNTILFINISHED();}void __svgalib_cirrusaccel_ScreenCopy(int x1, int y1, int x2, int y2, int width,			    int height){    int srcaddr, destaddr, dir;    width *= __svgalib_accel_bytesperpixel;    srcaddr = BLTBYTEADDRESS(x1, y1);    destaddr = BLTBYTEADDRESS(x2, y2);    dir = FORWARDS;    if ((y1 < y2 || (y1 == y2 && x1 < x2))	&& y1 + height > y2) {	srcaddr += (height - 1) * __svgalib_accel_screenpitchinbytes + width - 1;	destaddr += (height - 1) * __svgalib_accel_screenpitchinbytes + width - 1;	dir = BACKWARDS;    }    FINISHBACKGROUNDBLITS();    SETSRCADDR(srcaddr);    SETDESTADDR(destaddr);    SETWIDTH(width);    SETHEIGHT(height);    SETBLTMODE(dir);    STARTBLT();    if (!(__svgalib_accel_mode & BLITS_IN_BACKGROUND))	WAITUNTILFINISHED();}void __svgalib_cirrusaccel_mmio_ScreenCopy(int x1, int y1, int x2, int y2, int width,				 int height){    int srcaddr, destaddr, dir;    width *= __svgalib_accel_bytesperpixel;    srcaddr = BLTBYTEADDRESS(x1, y1);    destaddr = BLTBYTEADDRESS(x2, y2);    dir = FORWARDS;    if ((y1 < y2 || (y1 == y2 && x1 < x2))	&& y1 + height > y2) {	srcaddr += (height - 1) * __svgalib_accel_screenpitchinbytes + width - 1;	destaddr += (height - 1) * __svgalib_accel_screenpitchinbytes + width - 1;	dir = BACKWARDS;    }    MMIOFINISHBACKGROUNDBLITS();    MMIOSETSRCADDR(srcaddr);    MMIOSETDESTADDR(destaddr);    MMIOSETWIDTH(width);    MMIOSETHEIGHT(height);    MMIOSETBLTMODE(dir);    MMIOSTARTBLT();    if (!(__svgalib_accel_mode & BLITS_IN_BACKGROUND))	MMIOWAITUNTILFINISHED();}void __svgalib_cirrusaccel_SetFGColor(int fg){    cirrus_accel_foreground_color = fg;}void __svgalib_cirrusaccel_mmio_SetFGColor(int fg){    MMIOFINISHBACKGROUNDBLITS();    mmio_set_foreground_color(fg);}static unsigned char cirrus_rop_map[] ={    0x0D,			/* ROP_COPY */    0x6D,			/* ROP_OR */    0x05,			/* ROP_AND */    0x59,			/* ROP_XOR */    0x0B			/* ROP_INVERT */};void __svgalib_cirrusaccel_SetRasterOp(int rop){    FINISHBACKGROUNDBLITS();    SETROP(cirrus_rop_map[rop]);}void __svgalib_cirrusaccel_mmio_SetRasterOp(int rop){    MMIOFINISHBACKGROUNDBLITS();    MMIOSETROP(cirrus_rop_map[rop]);}void __svgalib_cirrusaccel_SetTransparency(int mode, int color){    FINISHBACKGROUNDBLITS();    if (mode == DISABLE_TRANSPARENCY_COLOR) {	/* Disable. */	SETTRANSPARENCYCOLORMASK16(0xFFFF);	return;    }    if (mode == ENABLE_TRANSPARENCY_COLOR) {	if (__svgalib_accel_bytesperpixel == 1)	    color += color << 8;	SETTRANSPARENCYCOLORMASK16(0x0000);	SETTRANSPARENCYCOLOR16(color);	return;    }    if (mode == DISABLE_BITMAP_TRANSPARENCY) {	__svgalib_accel_bitmaptransparency = 0;	return;    }    /* mode == ENABLE_BITMAP_TRANSPARENCY */    __svgalib_accel_bitmaptransparency = 1;}void __svgalib_cirrusaccel_Sync(void){    WAITUNTILFINISHED();}void __svgalib_cirrusaccel_mmio_Sync(void){    MMIOWAITUNTILFINISHED();}/* * Set up accelerator interface for pixels of size bpp and scanline width * of width_in_pixels. */static void init_acceleration_specs_for_mode(AccelSpecs * accelspecs, int bpp,					     int width_in_pixels){    accelspecs->operations = 0;    accelspecs->ropOperations = 0;    accelspecs->transparencyOperations = 0;    accelspecs->ropModes = 0;    accelspecs->transparencyModes = 0;    accelspecs->flags = ACCELERATE_ANY_LINEWIDTH;    if (cirrus_chiptype >= CLGD5426) {	accelspecs->operations |= ACCELFLAG_SETMODE | ACCELFLAG_SYNC;	if (bpp == 8 || bpp == 16) {	    /* BitBLT engine available. */	    accelspecs->operations |=		ACCELFLAG_FILLBOX | ACCELFLAG_SETFGCOLOR |		ACCELFLAG_SCREENCOPY |		ACCELFLAG_SETRASTEROP |		ACCELFLAG_SETTRANSPARENCY;	    accelspecs->ropOperations =		ACCELFLAG_FILLBOX | ACCELFLAG_SCREENCOPY;	    accelspecs->transparencyOperations =		ACCELFLAG_SCREENCOPY;    	    accelspecs->ropModes |= (1<<ROP_COPY) |		(1<<ROP_OR) | (1<<ROP_AND) | (1<<ROP_XOR) | (1<<ROP_INVERT);	    accelspecs->transparencyModes |=	 	(1<<ENABLE_TRANSPARENCY_COLOR) | (1<<ENABLE_BITMAP_TRANSPARENCY);	}	if (bpp == 24) {	    /* Depth-independent BitBLT functions. */	    accelspecs->operations |=		ACCELFLAG_SCREENCOPY;	    accelspecs->ropOperations =		ACCELFLAG_SCREENCOPY;    	    accelspecs->ropModes |= (1<<ROP_COPY) |		(1<<ROP_OR) | (1<<ROP_AND) | (1<<ROP_XOR) | (1<<ROP_INVERT);	}    }    if (cirrus_chiptype >= CLGD5429)	if (bpp == 8 || bpp == 16) {	    /* Newer chips don't have true color-compare. */	    accelspecs->operations &= ~ACCELFLAG_SETTRANSPARENCY;	    accelspecs->transparencyOperations = 0;    	    accelspecs->ropModes = 0;    	    accelspecs->transparencyModes = 0;	}    if (cirrus_chiptype >= CLGD5434)	if (bpp == 32) {	    /* BitBLT engine available for 32bpp. */	    accelspecs->operations |=		ACCELFLAG_FILLBOX | ACCELFLAG_SETFGCOLOR |		ACCELFLAG_SCREENCOPY |		ACCELFLAG_SETRASTEROP |		ACCELFLAG_SETTRANSPARENCY;	    accelspecs->ropOperations =		ACCELFLAG_FILLBOX | ACCELFLAG_SCREENCOPY;    	    accelspecs->ropModes |= (1<<ROP_COPY) |		(1<<ROP_OR) | (1<<ROP_AND) | (1<<ROP_XOR) | (1<<ROP_INVERT);	}#if 0				/* Full potential. */    /* 5420 */    if (bpp == 8)	/* Color-expand (extended write modes). */	accelspecs->operations =	    ACCELFLAG_FILLBOX | ACCELFLAG_SETFGCOLOR | ACCELFLAG_DRAWHLINE |	    ACCELFLAG_DRAWHLINELIST;    if (cirrus_chiptype >= CLGD5422)	if (bpp == 16)	    /* Also for 16bpp. */	    accelspecs->operations =		ACCELFLAG_FILLBOX | ACCELFLAG_SETFGCOLOR |		ACCELFLAG_DRAWHLINE | ACCELFLAG_DRAWHLINELIST;    if (cirrus_chiptype >= CLGD5426 && cirrus_memory >= 1024) {	if (bpp == 8 || bpp == 16) {	    /* BitBLT engine available. */	    accelspecs->operations |=		ACCELFLAG_SCREENCOPY | ACCELFLAG_PUTIMAGE |		ACCELFLAG_SETBGCOLOR | ACCELFLAG_SETRASTEROP |		ACCELFLAG_SETTRANSPARENCY |		ACCELFLAG_PUTIMAGE | ACCELFLAG_PUTBITMAP		ACCELFLAG_SCREENCOPYBITMAP;	    accelspecs->ropOperations =		ACCELFLAG_FILLBOX | ACCELFLAG_SCREENCOPY |		ACCELFLAG_PUTIMAGE;	    accelspecs->transparencyOperations =		ACCELFLAG_SCREENCOPY | ACCELFLAG_PUTIMAGE |		ACCELFLAG_PUTBITMAP;    	    accelspecs->ropModes |= (1<<ROP_COPY) |		(1<<ROP_OR) | (1<<ROP_AND) | (1<<ROP_XOR) | (1<<ROP_INVERT);	    accelspecs->transparencyModes |=	 	(1<<ENABLE_TRANSPARENCY_COLOR) | (1<<ENABLE_BITMAP_TRANSPARENCY);	}	if (bpp == 24) {	    /* Depth-independent BitBLT functions. */	    accelspecs->operations |=		ACCELFLAG_SCREENCOPY | ACCELFLAG_PUTIMAGE;	    accelspecs->ropOperations =		ACCELFLAG_SCREENCOPY | ACCELFLAG_PUTIMAGE;    	    accelspecs->ropModes |= (1<<ROP_COPY) |		(1<<ROP_OR) | (1<<ROP_AND) | (1<<ROP_XOR) | (1<<ROP_INVERT);	    /*	     * Possible additions: FILLBOX in bands, and	     * weird PutBitmap with color 0x000000 (trippling	     * bits with 8bpp operation).	     */	}    }    if (cirrus_chiptype >= CLGD5429)	if (bpp == 8 || bpp == 16) {	    /* Newer chips don't have true color-compare. */	    accelspecs->transparencyOperations = ACCELFLAG_BITMAP;	}    if (cirrus_chiptype >= CLGD5434)	if (bpp == 32) {	    /* BitBLT engine available for 32bpp. */	    accelspecs->operations |=		ACCELFLAG_SCREENCOPY | ACCELFLAG_PUTIMAGE |		ACCELFLAG_SETBGCOLOR | ACCELFLAG_SETRASTEROP |		ACCELFLAG_SETTRANSPARENCY |		ACCELFLAG_PUTIMAGE | ACCELFLAG_PUTBITMAP		ACCELFLAG_SCREENCOPYBITMAP |		ACCELFLAG_DRAWHLINE | ACCELFLAG_DRAWHLINELIST;	    accelspecs->ropOperations =		ACCELFLAG_FILLBOX |		ACCELFLAG_SCREENCOPY | ACCELFLAG_PUTIMAGE;	    accelspecs->transparencyOperations =		ACCELFLAG_PUTBITMAP;    	    accelspecs->ropModes |= (1<<ROP_COPY) |		(1<<ROP_OR) | (1<<ROP_AND) | (1<<ROP_XOR) | (1<<ROP_INVERT);	    accelspecs->transparencyModes |=	 	(1<<ENABLE_TRANSPARENCY_COLOR) | (1<<ENABLE_BITMAP_TRANSPARENCY);	}#endif    /* Set the function pointers; availability is handled by flags. */    accelspecs->FillBox = __svgalib_cirrusaccel_FillBox;    accelspecs->ScreenCopy = __svgalib_cirrusaccel_ScreenCopy;    accelspecs->SetFGColor = __svgalib_cirrusaccel_SetFGColor;    accelspecs->SetTransparency = __svgalib_cirrusaccel_SetTransparency;    accelspecs->SetRasterOp = __svgalib_cirrusaccel_SetRasterOp;    accelspecs->Sync = __svgalib_cirrusaccel_Sync;    if (cirrus_chiptype >= CLGD5429) {	accelspecs->FillBox = __svgalib_cirrusaccel_mmio_FillBox;	accelspecs->ScreenCopy = __svgalib_cirrusaccel_mmio_ScreenCopy;	accelspecs->SetFGColor = __svgalib_cirrusaccel_mmio_SetFGColor;	/* No mmio-version of SetTransparency. */	accelspecs->SetRasterOp = __svgalib_cirrusaccel_mmio_SetRasterOp;	accelspecs->Sync = __svgalib_cirrusaccel_mmio_Sync;    }}

⌨️ 快捷键说明

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