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

📄 graphics.c.svn-base

📁 psp播放器PPA源码,在MSYS/CYGWIN环境下编译(GNU-C)
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
#include <stdio.h>#include <stdlib.h>#include <malloc.h>#include <string.h>#include <pspdisplay.h>#include <psputils.h>#include <pspgu.h>#include "mem64.h"#include "graphics.h"#include "framebuffer.h"#include "texture_subdivision.h"#include "m33sdk.h"#define IS_ALPHA(color) (((color)&0xff000000)==0xff000000?0:1)#ifndef PSP_FRAMEBUFFER_SIZE#define PSP_FRAMEBUFFER_SIZE 557056#endif#ifndef PSP_TVOUT_BUFFER_SIZE#define PSP_TVOUT_BUFFER_SIZE 1572864#endif#ifndef PSP_TVOUT_PSPLCD_BUFFER_SIZE#define PSP_TVOUT_PSPLCD_BUFFER_SIZE 835584#endif#ifndef PSP_TVOUT_480P_BUFFER_SIZE#define PSP_TVOUT_480P_BUFFER_SIZE 1474560#endif#ifndef PSP_TVOUT_480P_LINE_SIZE#define PSP_TVOUT_480P_LINE_SIZE 3072#endif#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))struct vertex_struct	{	short texture_x;	short texture_y;	float vertex_x;	float vertex_y;	float vertex_z;	};typedef void (*BlitImageToScreen)(int, int, int, int, Image*, int, int);typedef void (*BlitAlphaImageToScreen)(int, int, int, int, Image*, int, int);typedef void (*CopyVramToExtraMemory)();typedef void (*FlipScreen)();void blitImageToScreenWithoutTVOut(int sx, int sy, int width, int height, Image* source, int dx, int dy);void blitImageToScreenPSP(int sx, int sy, int width, int height, Image* source, int dx, int dy);void blitImageToScreenTVOut(int sx, int sy, int width, int height, Image* source, int dx, int dy);void blitAlphaImageToScreenWithoutTVOut(int sx, int sy, int width, int height, Image* source, int dx, int dy);void blitAlphaImageToScreenPSP(int sx, int sy, int width, int height, Image* source, int dx, int dy);void blitAlphaImageToScreenTVOut(int sx, int sy, int width, int height, Image* source, int dx, int dy);void copyVramToExtraMemoryPSP();void copyVramToExtraMemoryTVOutInterlace();void copyVramToExtraMemoryTVOutProgressive();void flipScreenWithoutTVOutSupported();void flipScreenWithTVOutSupported();unsigned int __attribute__((aligned(16))) list[262144];static int pspType = 0;static int videoMode = 0;static int tvAspectRatio = 0; //0=16:9; 1=4:3static int tvOverScanLeft;static int tvOverScanTop;static int tvOverScanRight;static int tvOverScanBottom;static int tvWidth;static int tvHeight;static int tvLeft;static int tvTop;static int displayBufferNumber;static int initialized = 0;static void* frameBuffer[2];static BlitImageToScreen pBlitImageToScreen = blitImageToScreenWithoutTVOut;static BlitAlphaImageToScreen pBlitAlphaImageToScreen = blitAlphaImageToScreenWithoutTVOut;static CopyVramToExtraMemory pCopyVramToExtraMemory = copyVramToExtraMemoryPSP;static FlipScreen pFlipScreen = flipScreenWithoutTVOutSupported;static int getNextPower2(int width){	int b = width;	int n;	for (n = 0; b != 0; n++) b >>= 1;	b = 1 << n;	if (b == 2 * width) b >>= 1;	return b;}static void drawLine(int x0, int y0, int x1, int y1, int color, Color* destination, int width){	int dy = y1 - y0;	int dx = x1 - x0;	int stepx, stepy;		if (dy < 0) { dy = -dy;  stepy = -width; } else { stepy = width; }	if (dx < 0) { dx = -dx;  stepx = -1; } else { stepx = 1; }	dy <<= 1;	dx <<= 1;		y0 *= width;	y1 *= width;	destination[x0+y0] = color;	if (dx > dy) {		int fraction = dy - (dx >> 1);		while (x0 != x1) {			if (fraction >= 0) {				y0 += stepy;				fraction -= dx;			}			x0 += stepx;			fraction += dy;			destination[x0+y0] = color;		}	} else {		int fraction = dx - (dy >> 1);		while (y0 != y1) {			if (fraction >= 0) {				x0 += stepx;				fraction -= dy;			}			y0 += stepy;			fraction += dx;			destination[x0+y0] = color;		}	}}void guStart(){	sceGuStart(GU_DIRECT, list);}static void guSetupPSPLCD() {	guStart();	sceGuDrawBuffer(GU_PSM_8888, 0, PSP_TVOUT_TEXTURE_WIDTH);	sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, 0, PSP_TVOUT_TEXTURE_WIDTH);	sceGuOffset(2048 - (PSP_SCREEN_WIDTH >> 1), 2048 - (PSP_SCREEN_HEIGHT >> 1));	sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);	sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);	sceGuEnable(GU_SCISSOR_TEST);	sceGuDisable(GU_CULL_FACE);	sceGuDisable(GU_DEPTH_TEST);	// Disable Z-compare	sceGuDepthMask(GU_TRUE);		// Disable Z-writes	sceGuDisable(GU_COLOR_TEST);	sceGuDisable(GU_ALPHA_TEST);	sceGuDisable(GU_LIGHTING);	sceGuEnable(GU_TEXTURE_2D);	sceGuClearColor(0);	sceGuClear(GU_COLOR_BUFFER_BIT);	sceGuFinish();	sceGuSync(0, 0);		memset(frameBuffer[0], 0, PSP_TVOUT_BUFFER_SIZE);	memset(frameBuffer[1], 0, PSP_TVOUT_BUFFER_SIZE);		sceDisplayWaitVblankStart();	sceDisplaySetFrameBuf(frameBuffer[displayBufferNumber], PSP_TVOUT_TEXTURE_WIDTH, PSP_DISPLAY_PIXEL_FORMAT_8888, PSP_DISPLAY_SETBUF_IMMEDIATE);}static void guSetupTVOut() {	guStart();	sceGuDrawBuffer(GU_PSM_8888, 0, PSP_TVOUT_TEXTURE_WIDTH);	sceGuDispBuffer(PSP_TVOUT_WIDTH, PSP_TVOUT_HEIGHT, 0, PSP_TVOUT_TEXTURE_WIDTH);	sceGuOffset(2048 - (PSP_TVOUT_WIDTH >> 1), 2048 - (PSP_TVOUT_HEIGHT >> 1));	sceGuViewport(2048, 2048, PSP_TVOUT_WIDTH, PSP_TVOUT_HEIGHT);	sceGuScissor(0, 0, PSP_TVOUT_WIDTH, PSP_TVOUT_HEIGHT);	sceGuEnable(GU_SCISSOR_TEST);	sceGuDisable(GU_CULL_FACE);	sceGuDisable(GU_DEPTH_TEST);	// Disable Z-compare	sceGuDepthMask(GU_TRUE);		// Disable Z-writes	sceGuDisable(GU_COLOR_TEST);	sceGuDisable(GU_ALPHA_TEST);	sceGuDisable(GU_LIGHTING);	sceGuEnable(GU_TEXTURE_2D);	sceGuClearColor(0);	sceGuClear(GU_COLOR_BUFFER_BIT);	sceGuFinish();	sceGuSync(0, 0);		memset(frameBuffer[0], 0, PSP_TVOUT_BUFFER_SIZE);	memset(frameBuffer[1], 0, PSP_TVOUT_BUFFER_SIZE);		sceDisplayWaitVblankStart();	sceDisplaySetFrameBuf(frameBuffer[displayBufferNumber], PSP_TVOUT_TEXTURE_WIDTH, PSP_DISPLAY_PIXEL_FORMAT_8888, PSP_DISPLAY_SETBUF_IMMEDIATE);}static void guDrawSprite(struct texture_subdivision_struct *t){	struct vertex_struct *v = sceGuGetMemory(2 * sizeof(struct vertex_struct));	v[0].texture_x = t->output_texture_x_start;	v[0].texture_y = t->output_texture_y_start;	v[0].vertex_x  = (int) t->output_vertex_x_start;	v[0].vertex_y  = t->output_vertex_y_start;	v[0].vertex_z  = 0.0;	v[1].texture_x = t->output_texture_x_end;	v[1].texture_y = t->output_texture_y_end;	v[1].vertex_x  = (int) t->output_vertex_x_end;	v[1].vertex_y  = t->output_vertex_y_end;	v[1].vertex_z  = 0.0;	sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, v);}void setGraphicsTVAspectRatio(int ar) {	tvAspectRatio = ar;}void setGraphicsTVOverScan(int left, int top, int right, int bottom) {	tvOverScanLeft = left;	tvOverScanTop = top;	tvOverScanRight = right;	tvOverScanBottom = bottom;}void setGraphicsTVOutScreen() {	tvWidth = 720 - tvOverScanLeft - tvOverScanRight;	tvHeight = 480 - tvOverScanTop - tvOverScanBottom;	tvLeft = tvOverScanLeft;	tvTop = tvOverScanTop;	if( tvAspectRatio == 1) {		tvTop += (tvHeight/8);		tvHeight = tvHeight * 3 / 4;	}}void setGraphicsVideoMode(int mode) {	if ( initialized && m33IsTVOutSupported(pspType) && (videoMode != mode) ) {		if ( mode == 0 ) {			guSetupPSPLCD();			pBlitImageToScreen = blitImageToScreenPSP;			pBlitAlphaImageToScreen = blitAlphaImageToScreenPSP;			pCopyVramToExtraMemory = copyVramToExtraMemoryPSP;		}		else if ( mode == 1 ) {			guSetupTVOut();			pBlitImageToScreen = blitImageToScreenTVOut;			pBlitAlphaImageToScreen = blitAlphaImageToScreenTVOut;			pCopyVramToExtraMemory = copyVramToExtraMemoryTVOutInterlace;		}		else if ( mode == 2 ) {			guSetupTVOut();			pBlitImageToScreen = blitImageToScreenTVOut;			pBlitAlphaImageToScreen = blitAlphaImageToScreenTVOut;			pCopyVramToExtraMemory = copyVramToExtraMemoryTVOutInterlace;		}		else if ( mode == 3 ) {			guSetupTVOut();			pBlitImageToScreen = blitImageToScreenTVOut;			pBlitAlphaImageToScreen = blitAlphaImageToScreenTVOut;			pCopyVramToExtraMemory = copyVramToExtraMemoryTVOutProgressive;		}		videoMode = mode;	}}void initGraphicsWithTVoutSupported() {	displayBufferNumber = 0;	frameBuffer[0] = (void*)0x0a000000;	frameBuffer[1] = (void*)(0x0a000000 + PSP_TVOUT_BUFFER_SIZE);		guSetupPSPLCD();		pBlitImageToScreen = blitImageToScreenPSP;	pBlitAlphaImageToScreen = blitAlphaImageToScreenPSP;	pCopyVramToExtraMemory = copyVramToExtraMemoryPSP;	videoMode = 0;	initialized = 1;}	void initGraphicsWithoutTVoutSupported() {	displayBufferNumber = 0;	frameBuffer[0] = (void*)(0x44000000 + PSP_FRAMEBUFFER_SIZE);	frameBuffer[1] = (void*)(0x44000000 + 2*PSP_FRAMEBUFFER_SIZE);			guStart();	sceGuDrawBuffer(GU_PSM_8888, 0, PSP_SCREEN_TEXTURE_WIDTH);	sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, 0, PSP_SCREEN_TEXTURE_WIDTH);	sceGuOffset(2048 - (PSP_SCREEN_WIDTH >> 1), 2048 - (PSP_SCREEN_HEIGHT >> 1));	sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);	sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);	sceGuEnable(GU_SCISSOR_TEST);	sceGuDisable(GU_CULL_FACE);	sceGuDisable(GU_DEPTH_TEST);	// Disable Z-compare	sceGuDepthMask(GU_TRUE);		// Disable Z-writes	sceGuDisable(GU_COLOR_TEST);	sceGuDisable(GU_ALPHA_TEST);	sceGuDisable(GU_LIGHTING);

⌨️ 快捷键说明

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