Beispiel #1
0
Sprite::Sprite(const char* filename,int startW,int startH,int endW,int endH)
{
    TextureManager::Instance()->LoadTexture(filename);
    imageName = filename;

    Image* img = TextureManager::Instance()->GetImage(filename);

    //generate wertices
    vertices = (TexturesPSPVertex*)memalign(16, 4 * sizeof(TexturesPSPVertex) );

    width = endW;
    height = endH;

    float hstart = (float)startH / (float)img->power2Height;
    float wstart = (float)startW / (float)img->power2Width;
    float hPercent = (float)(startH + endH) / (float)img->power2Height;
    float wPercent = (float)(startW + endW) / (float)img->power2Width;

    if( vertices )
    {
        vertices[0] = getVertex(wstart,hstart,-width/2,-height/2,0.0f);
        vertices[1] = getVertex(wstart,hPercent,-width/2, height/2,0.0f);
        vertices[2] = getVertex(wPercent,hstart,width/2,-height/2,0.0f);
        vertices[3] = getVertex(wPercent,hPercent,width/2, height/2,0.0f);
    }

    //sceKernelDcacheWritebackInvalidateAll();
    sceKernelDcacheWritebackInvalidateRange(vertices, 4 * sizeof(TexturesPSPVertex));
}
Beispiel #2
0
void __pspgl_buffer_unmap(struct pspgl_buffer *data, GLenum access)
{
	assert(data->mapped > 0);

	if (--data->mapped > 0)
		return;

	switch(access) {
	case GL_READ_ONLY_ARB:
		/* do nothing; no dirty cache lines */
		break;

	case GL_READ_WRITE_ARB:
		sceKernelDcacheWritebackInvalidateRange(data->base, data->size);
		break;

	case GL_WRITE_ONLY_ARB:
		/* do nothing; all uncached */
		break;

	default:
		return;
	}

	if (access != GL_READ_ONLY_ARB)
		data->generation++;
}
Beispiel #3
0
int sub_00000A98(u8 *packet, u32 packet_size)
{
	/* remove access flags */
	u32 io_base = 0x00200000;
	u32 packet_addr = REAL_ADDRESS(packet);

	/* check if in kernel memory (or lower) */
	if (packet_addr < 0x04800000)
	{
		/* ensure not below bottom 80 KB (0x04000000 -> 0x04014000)  */
		if (data_addr >= 0x00014000) // +80KB?
		{
			/* error? */
			return packet;
		}
		
		/* set base */
		io_base = 0x00400000;
	}
	
	/* copy data to kermit io */
	u32 kermit_addr = KERMIT_ADDRESS(PHYSICAL_ADDRESS(packet), io_base);
	
	/* copy the data, and flush the cache back to RAM */
	memmove(kermit_addr, packet, packet_size);
	sceKernelDcacheWritebackInvalidateRange(kermit_addr, packet_size);
	
	/* return address to kermit memory */
	return kermit_addr;
}
Beispiel #4
0
Sprite::Sprite(const char* filename)
{
    TextureManager::Instance()->LoadTexture(filename);
    imageName = filename;

    Image* img = TextureManager::Instance()->GetImage(filename);

    //generate wertices
    vertices = (TexturesPSPVertex*)memalign(16, 4 * sizeof(TexturesPSPVertex) );

    width = img->Width;
    height = img->Height;

    float hPercent = (float)img->Height / (float)img->power2Height;
    float wPercent = (float)img->Width / (float)img->power2Width;

    if( vertices )
    {
        vertices[0] = getVertex(0.0f,0.0f,-img->Width/2,-img->Height/2,0.0f);
        vertices[1] = getVertex(0.0f,hPercent,-img->Width/2, img->Height/2,0.0f);
        vertices[2] = getVertex(wPercent,0.0f,img->Width/2,-img->Height/2,0.0f);
        vertices[3] = getVertex(wPercent,hPercent,img->Width/2, img->Height/2,0.0f);
    }

    sceKernelDcacheWritebackInvalidateRange(vertices, 4 * sizeof(TexturesPSPVertex));
}
Beispiel #5
0
void *__pspgl_uncached(void *p, size_t size)
{
	assert(((unsigned long)p & (CACHELINE_SIZE-1)) == 0);
	assert((size & (CACHELINE_SIZE-1)) == 0);

	sceKernelDcacheWritebackInvalidateRange(p, size);

	return (void *)((unsigned long)p | 0x40000000);
}
Beispiel #6
0
/**
 * Remember you have to export the hooker function if using syscall hook
 */
int hook_import_bynid(SceModule *pMod, char *library, unsigned int nid, void *func, int syscall)
{
    PspModuleImport *pImp;
    void *stubTab;
    int stubLen;
    int i = 0;

    if(pMod == NULL)
        return -1;

    stubTab = pMod->stub_top;
    stubLen = pMod->stub_size;

    while(i<stubLen) {
        pImp = (PspModuleImport*)(stubTab+i);

        if((pImp->name) && (strcmp(pImp->name, library) == 0)) {
            int j;

            for(j=0; j<pImp->funcCount; j++) {
                if(pImp->fnids[j] == nid) {
                    void *addr = (void*)(&pImp->funcs[j*2]);

                    if(syscall) {
                        u32 syscall_num;

                        syscall_num = sctrlKernelQuerySystemCall(func);

                        if(syscall_num == (u32)-1) {
                            printk("%s: cannot find syscall in %s_%08X\n", __func__, library, nid);

                            return -1;
                        }

                        _sw(0x03E00008, (u32)addr);
                        _sw(MAKE_SYSCALL(syscall_num), (u32)(addr + 4));
                    } else {
                        _sw(MAKE_JUMP(func), (u32)addr);
                        _sw(NOP, (u32)(addr + 4));
                    }

                    sceKernelDcacheWritebackInvalidateRange(addr, 8);
                    sceKernelIcacheInvalidateRange(addr, 8);
                }
            }
        }

        i += (pImp->entLen * 4);
    }

    return 0;
}
Beispiel #7
0
void api_hook_import_syscall(unsigned int address, void * function) {
    //valid address
    if (address) {
        //asm jr $ra
        *(unsigned int *) (address) = 0x03E00008;

        //asm syscall #
        *(unsigned int *) (address + 4) = (((sceKernelQuerySystemCall(function)) << 6) | 12);

        //flush cache
        sceKernelDcacheWritebackInvalidateRange((const void *) address, 8);
        sceKernelIcacheInvalidateRange((const void *) address, 8);
    }
}
Beispiel #8
0
void api_hook_import(unsigned int address, void * function) {
    //valid address
    if (address) {
        //asm jmp
        *(unsigned int *) (address) = 0x08000000 | ((unsigned int) function & 0x0FFFFFFF) >> 2;

        //asm nop
        *(unsigned int *) (address + 4) = 0;

        //flush cache
        sceKernelDcacheWritebackInvalidateRange((const void *) address, 8);
        sceKernelIcacheInvalidateRange((const void *) address, 8);
    }
}
Beispiel #9
0
void doScanAudioData() {
	sceKernelDcacheWritebackInvalidateRange(audioData, 16384);

	int blankStart = -1;
	int blankEnd = -1;
	for (size_t j = 0; j < 4096; ++j) {
		if (audioData[j] == 0xCDCDCDCD && blankStart == -1) {
			blankStart = (int)j;
		} else if (audioData[j] != 0xCDCDCDCD && blankStart != -1) {
			blankEnd = (int)j;
			break;
		}
	}
	checkpoint("   -> Audio data blank start=%d, end=%d", blankStart, blankEnd);
}
Beispiel #10
0
/**
 * Remember you have to export the hooker function if using syscall hook
 */
int hook_import_bynid(SceModule *pMod, char *library, unsigned int nid, void *func)
{
	PspModuleImport *pImp;
	void *stubTab;
	int stubLen;
	int i = 0;

	if(pMod == NULL)
		return -1;

	stubTab = pMod->stub_top;
	stubLen = pMod->stub_size;

	while(i<stubLen) {
		pImp = (PspModuleImport*)(stubTab+i);

		if((pImp->name) && (strcmp(pImp->name, library) == 0)) {
			int j;

			for(j=0; j<pImp->funcCount; j++) {
				if(pImp->fnids[j] == nid) {
					void *addr = (void*)(&pImp->funcs[j*2]);
					if(func == NULL) {
						_sw(0x03E00008, (u32)addr);
						_sw(NOP, (u32)(addr + 4));
					} else {
						// Partition Check
						SceModule2 * mod = (SceModule2 *)pMod;
						if(((mod->text_addr & 0x80000000) && (((uint32_t)func) & 0x80000000)) || ((mod->text_addr & 0x80000000) == 0 && (((uint32_t)func) & 0x80000000) == 0))
						{
							REDIRECT_FUNCTION(func, addr);
						} else {
							_sw(0x03E00008, (u32)addr);
							_sw(MAKE_SYSCALL(sctrlKernelQuerySystemCall(func)), (u32)(addr + 4));
						}
					}

					sceKernelDcacheWritebackInvalidateRange(addr, 8);
					sceKernelIcacheInvalidateRange(addr, 8);
				}
			}
		}

		i += (pImp->entLen * 4);
	}

	return 0;
}
Beispiel #11
0
/* Patch out the exception handler setup call for apps which come after us ;P */
int psplinkPatchException(void)
{
	unsigned int *addr;
	int intc;

	intc = pspSdkDisableInterrupts();
	addr = libsFindExportAddrByNid(refer_module_by_name("sceExceptionManager", NULL), "ExceptionManagerForKernel", 0x565C0B0E);
	if(addr)
	{
		*addr = (unsigned int) RegisterExceptionDummy;
		sceKernelDcacheWritebackInvalidateRange(addr, 4);
		sceKernelIcacheInvalidateRange(addr, 4);
	}
	pspSdkEnableInterrupts(intc);

	return 0;
}
Beispiel #12
0
static int commitSelectedChar(HexEditor* prHex) {
    AsciiColumn* prCol = NULL;
    SceChar8 value = (SceChar8)0;
    SceChar8* pcDest = NULL;
    SceUInt32 offset = 0;

    if (prHex == NULL) {
        return HEXEDITOR_MEMORY;
    }
    prCol = &(prHex->rEditRow.rAscii);
    value = asciicolumn_commit(prCol);
    offset = getSelectedByteOffset(prHex);
    pcDest = (SceChar8*)offset;
    *pcDest = value;
    sceKernelDcacheWritebackInvalidateRange(pcDest, 1);
    sceKernelIcacheInvalidateRange(pcDest, 1);
    prHex->editing = 0;
    prHex->dirty = 1;
    return HEXEDITOR_SUCCESS;
}
Beispiel #13
0
int libsPatchFunction(SceUID uid, const char *library, unsigned int nid, u16 retval)
{
	unsigned int* addr;
	int intc;
	int ret = 0;

	intc = pspSdkDisableInterrupts();
	addr = (unsigned int *) libsFindExportByNid(uid, library, nid);
	if(addr)
	{
		addr[0] = 0x03E00008;
		addr[1] = 0x24020000 | (unsigned int) retval;
		sceKernelDcacheWritebackInvalidateRange(addr, 8);
		sceKernelIcacheInvalidateRange(addr, 8);
		ret = 1;
	}
	pspSdkEnableInterrupts(intc);

	return ret;
}
		void  SkyLight::UpdateLightSource(float sun_angle)
		{
			float r = 670.0f;
			float shift = 325;
			//float textureScale = 1.0f / stepScale;

			int i = 0;

			skyVertices[i].x = vfpu_sinf((sun_angle/180)*PI)*r;// * stepScale;
			skyVertices[i].y = vfpu_cosf(((sun_angle)/180)*PI)*-r;// * stepScale;
			skyVertices[i].z = -250;// * stepScale;
			skyVertices[i].u = 0.f;// * textureScale;
			skyVertices[i].v = 0.f;// * textureScale;
			i++;

			// (x, y - 1, z)
			skyVertices[i].x = vfpu_sinf(((sun_angle-45)/180)*PI)*r;// * stepScale;
			skyVertices[i].y = vfpu_cosf(((sun_angle-45)/180)*PI)*-r;// * stepScale;
			skyVertices[i].z = -250;// * stepScale;
			skyVertices[i].u = 0.f;// * textureScale;
			skyVertices[i].v = 1.f;// * textureScale;
			i++;

			// (x + 1, y, z)
			skyVertices[i].x = vfpu_sinf((sun_angle/180)*PI)*r;// * stepScale;
			skyVertices[i].y = vfpu_cosf((sun_angle/180)*PI)*-r;// * stepScale;
			skyVertices[i].z = 250;// * stepScale;
			skyVertices[i].u = 1.f;// * textureScale;
			skyVertices[i].v = 0.f;// * textureScale;
			i++;

			// (x + 1, y - 1, z)
			skyVertices[i].x = vfpu_sinf(((sun_angle-45)/180)*PI)*r;// * stepScale;
			skyVertices[i].y = vfpu_cosf(((sun_angle-45)/180)*PI)*-r;// * stepScale;
			skyVertices[i].z = 250;// * stepScale;
			skyVertices[i].u = 1.f;// * textureScale;
			skyVertices[i].v = 1.f;// * textureScale;

			sceKernelDcacheWritebackInvalidateRange(skyVertices,4 * sizeof(CraftPSPVertex));
		}
Beispiel #15
0
void testMemcpy(const char *title, int (*memcpyFunc)(void *d, const void *s, unsigned int sz)) {
	char temp[256];

	snprintf(temp, sizeof(temp), "%s normal operation:", title);
	memset(dataDest, 0, sizeof(dataDest));
	checkpointNext(temp);
	checkpoint("  Source: %s", dataSource);
	checkpoint("  Before copy: %s", dataDest);

	// Warning: sceDmacMemcpy bypasses the CPU cache.
	sceKernelDcacheWritebackInvalidateRange(dataDest, sizeof(dataDest));
	memcpyFunc(dataDest, dataSource, sizeof(dataSource));

	checkpoint("  After copy: %s", dataDest);
	
	snprintf(temp, sizeof(temp), "%s errors:", title);
	checkpoint(temp);
	checkpoint("  Normal: %08x", memcpyFunc(dataDest, dataSource, 4));
	checkpoint("  NULL, 0 length: %08x", memcpyFunc(0, 0, 0));
	checkpoint("  NULL, with length: %08x", memcpyFunc(0, 0, 4));
	checkpoint("  0 length: %08x", memcpyFunc(dataDest, dataSource, 0));
	// Crashes.
	//checkpoint("  Same ptr: %08x", memcpyFunc(dataDest, dataDest, 4));
}
Beispiel #16
0
/*
@@@@@@@@@@@@@@@@@@@@@
RE_RenderScene

Draw a 3D view into a part of the window, then return
to 2D drawing.

Rendering a scene may require multiple views to be rendered
to handle mirrors,
@@@@@@@@@@@@@@@@@@@@@
*/
void RE_RenderScene( const refdef_t *fd )
{
	viewParms_t		parms;
	int				startTime;

	if ( !tr.registered )
	{
		return;
	}
	GLimp_LogComment( "====== RE_RenderScene =====\n" );

	if ( r_norefresh->integer ) {
		return;
	}

	startTime = ri.Milliseconds();

	if (!tr.world && !( fd->rdflags & RDF_NOWORLDMODEL ) )
	{
		ri.Error (ERR_DROP, "R_RenderScene: NULL worldmodel");
	}
#if 1
	Com_Memcpy( tr.refdef.text, fd->text, sizeof( tr.refdef.text ) );
#else
	sceKernelDcacheWritebackInvalidateRange(tr.refdef.text, sizeof( tr.refdef.text ));
    sceKernelDcacheWritebackInvalidateRange(fd->text,       sizeof( tr.refdef.text ));

	sceDmacMemcpy(tr.refdef.text, fd->text,       sizeof( tr.refdef.text )); //vfpu memcpy

    sceKernelDcacheWritebackInvalidateRange(tr.refdef.text, sizeof( tr.refdef.text ));
#endif
	tr.refdef.x = fd->x;
	tr.refdef.y = fd->y;
	tr.refdef.width = fd->width;
	tr.refdef.height = fd->height;
	tr.refdef.fov_x = fd->fov_x;
	tr.refdef.fov_y = fd->fov_y;

	VectorCopy( fd->vieworg, tr.refdef.vieworg );
	VectorCopy( fd->viewaxis[0], tr.refdef.viewaxis[0] );
	VectorCopy( fd->viewaxis[1], tr.refdef.viewaxis[1] );
	VectorCopy( fd->viewaxis[2], tr.refdef.viewaxis[2] );

	tr.refdef.time = fd->time;
	tr.refdef.rdflags = fd->rdflags;

	// copy the areamask data over and note if it has changed, which
	// will force a reset of the visible leafs even if the view hasn't moved
	tr.refdef.areamaskModified = qfalse;
	if ( ! (tr.refdef.rdflags & RDF_NOWORLDMODEL) ) 
      {
		int		areaDiff;
		int		i;

		// compare the area bits
		areaDiff = 0;
		for (i = 0 ; i < MAX_MAP_AREA_BYTES/4 ; i++) {
			areaDiff |= ((int *)tr.refdef.areamask)[i] ^ ((int *)fd->areamask)[i];
			((int *)tr.refdef.areamask)[i] = ((int *)fd->areamask)[i];
		}

		if ( areaDiff ) {
			// a door just opened or something
			tr.refdef.areamaskModified = qtrue;
		}
	}

	// derived info

	tr.refdef.floatTime = tr.refdef.time * 0.001f;

	tr.refdef.numDrawSurfs = r_firstSceneDrawSurf;
	tr.refdef.drawSurfs = backEndData[tr.smpFrame]->drawSurfs;

	tr.refdef.num_entities = r_numentities - r_firstSceneEntity;
	tr.refdef.entities = &backEndData[tr.smpFrame]->entities[r_firstSceneEntity];

	tr.refdef.num_dlights = r_numdlights - r_firstSceneDlight;
	tr.refdef.dlights = &backEndData[tr.smpFrame]->dlights[r_firstSceneDlight];

	tr.refdef.numPolys = r_numpolys - r_firstScenePoly;
	tr.refdef.polys = &backEndData[tr.smpFrame]->polys[r_firstScenePoly];

	// turn off dynamic lighting globally by clearing all the
	// dlights if it needs to be disabled or if vertex lighting is enabled
	if ( r_dynamiclight->integer == 0 ||
		 r_vertexLight->integer == 1 ||
		 glConfig.hardwareType == GLHW_PERMEDIA2 ) {
		tr.refdef.num_dlights = 0;
	}

	// a single frame may have multiple scenes draw inside it --
	// a 3D game view, 3D status bar renderings, 3D menus, etc.
	// They need to be distinguished by the light flare code, because
	// the visibility state for a given surface may be different in
	// each scene / view.
	tr.frameSceneNum++;
	tr.sceneCount++;

	// setup view parms for the initial view
	//
	// set up viewport
	// The refdef takes 0-at-the-top y coordinates, so
	// convert to GL's 0-at-the-bottom space
	//
	Com_Memset( &parms, 0, sizeof( parms ) );
	parms.viewportX = tr.refdef.x;
	parms.viewportY = glConfig.vidHeight - ( tr.refdef.y + tr.refdef.height );
	parms.viewportWidth = tr.refdef.width;
	parms.viewportHeight = tr.refdef.height;
	parms.isPortal = qfalse;

	parms.fovX = tr.refdef.fov_x;
	parms.fovY = tr.refdef.fov_y;

	VectorCopy( fd->vieworg, parms.por.origin );
	VectorCopy( fd->viewaxis[0], parms.por.axis[0] );
	VectorCopy( fd->viewaxis[1], parms.por.axis[1] );
	VectorCopy( fd->viewaxis[2], parms.por.axis[2] );

	VectorCopy( fd->vieworg, parms.pvsOrigin );

	R_RenderView( &parms );

	// the next scene rendered in this frame will tack on after this one
	r_firstSceneDrawSurf = tr.refdef.numDrawSurfs;
	r_firstSceneEntity = r_numentities;
	r_firstSceneDlight = r_numdlights;
	r_firstScenePoly = r_numpolys;

	tr.frontEndMsec += ri.Milliseconds() - startTime;
}
Beispiel #17
0
void RE_AddPolyToScene( qhandle_t hShader, int numVerts, const polyVert_t *verts, int numPolys ) {
	srfPoly_t	*poly;
	int			i, j;
	int			fogIndex;
	fog_t		*fog;
	vec3_t		bounds[2];

	if ( !tr.registered ) {
		return;
	}

	if ( !hShader ) {
		ri.Printf( PRINT_WARNING, "WARNING: RE_AddPolyToScene: NULL poly shader\n");
		return;
	}

	for ( j = 0; j < numPolys; j++ )
	{
		if ( r_numpolyverts + numVerts > max_polyverts || r_numpolys >= max_polys )
		{
      /*
      NOTE TTimo this was initially a PRINT_WARNING
      but it happens a lot with high fighting scenes and particles
      since we don't plan on changing the const and making for room for those effects
      simply cut this message to developer only
      */
			ri.Printf( PRINT_DEVELOPER, "WARNING: RE_AddPolyToScene: r_max_polys or r_max_polyverts reached\n");
			return;
		}

		poly = &backEndData[tr.smpFrame]->polys[r_numpolys];
		poly->surfaceType = SF_POLY;
		poly->hShader = hShader;
		poly->numVerts = numVerts;
		poly->verts = &backEndData[tr.smpFrame]->polyVerts[r_numpolyverts];
#if 1
		Com_Memcpy( poly->verts, &verts[numVerts*j], numVerts * sizeof( *verts ) );
#else
		sceKernelDcacheWritebackInvalidateRange(poly->verts,              numVerts * sizeof( *verts ));
	    sceKernelDcacheWritebackInvalidateRange(&verts[numVerts*j],       numVerts * sizeof( *verts ));
		sceDmacMemcpy(poly->verts, &verts[numVerts*j],                    numVerts * sizeof( *verts )); //vfpu memcpy
	    sceKernelDcacheWritebackInvalidateRange(poly->verts,              numVerts * sizeof( *verts ));
#endif
		if ( glConfig.hardwareType == GLHW_RAGEPRO )
		{
			poly->verts->modulate[0] = 255;
			poly->verts->modulate[1] = 255;
			poly->verts->modulate[2] = 255;
			poly->verts->modulate[3] = 255;
		}
		// done.
		r_numpolys++;
		r_numpolyverts += numVerts;

		// if no world is loaded
		if ( tr.world == NULL )
		{
			fogIndex = 0;
		}
		// see if it is in a fog volume
		else if ( tr.world->numfogs == 1 )
		{
			fogIndex = 0;
		}
		else
		{
			// find which fog volume the poly is in
			VectorCopy( poly->verts[0].xyz, bounds[0] );
			VectorCopy( poly->verts[0].xyz, bounds[1] );
			for ( i = 1 ; i < poly->numVerts ; i++ )
			{
				AddPointToBounds( poly->verts[i].xyz, bounds[0], bounds[1] );
			}
			for ( fogIndex = 1 ; fogIndex < tr.world->numfogs ; fogIndex++ )
			{
				fog = &tr.world->fogs[fogIndex]; 
				if ( bounds[1][0] >= fog->bounds[0][0]
					&& bounds[1][1] >= fog->bounds[0][1]
					&& bounds[1][2] >= fog->bounds[0][2]
					&& bounds[0][0] <= fog->bounds[1][0]
					&& bounds[0][1] <= fog->bounds[1][1]
					&& bounds[0][2] <= fog->bounds[1][2] )
					{
					break;
				}
			}
			if ( fogIndex == tr.world->numfogs ) {
				fogIndex = 0;
			}
		}
		poly->fogIndex = fogIndex;
	}
}
Beispiel #18
0
static GLboolean __pspgl_buffer_init(struct pspgl_buffer *buf,
				     GLsizeiptr size, GLenum usage)
{
	void *p = NULL;
	int try_hard = 0;

	size = ROUNDUP(size, CACHELINE_SIZE);

	buf->base = NULL;
	buf->size = size;

	switch(usage) {
	case GL_STATIC_COPY_ARB:	/* must be in edram */
	case GL_DYNAMIC_COPY_ARB:
	case GL_STREAM_COPY_ARB:
		/* We'll try hard to get vidmem, but it doesn't matter
		   if we fail because the buffer will be moved into
		   vidmem when needed. */
		try_hard = 1;
		/* FALLTHROUGH */

	case GL_STATIC_DRAW_ARB:	/* nice to have in edram */
	case GL_STATIC_READ_ARB:
	case GL_DYNAMIC_READ_ARB:
		if (__pspgl_vidmem_alloc(buf))
			p = buf->base;
		else if (try_hard) {
			/* Work hard to get the memory... */

			/* If there just isn't enough space, evict some buffers */
			if (__pspgl_vidmem_avail() < size)
				evict_vidmem(size);

			/* Try again after some evicitions */
			if (__pspgl_vidmem_alloc(buf))
				p = buf->base;
			else if (__pspgl_vidmem_compact()) {
				__pspgl_moved_textures();

				/* and one last time before giving up */
				if (__pspgl_vidmem_alloc(buf))
					p = buf->base;
			}
		}
		break;

	case GL_DYNAMIC_DRAW_ARB:	/* prefer in system memory */
	case GL_STREAM_READ_ARB:
	case GL_STREAM_DRAW_ARB:
		/* fallthrough to allocation */
		break;

	default:
		GLERROR(GL_INVALID_ENUM);
		return GL_FALSE;
	}

	if (p == NULL) {
		p = memalign(CACHELINE_SIZE, size);

		if (p == NULL)
			return GL_FALSE;
	}

  	/* put cache into appropriate unmapped state */
	sceKernelDcacheWritebackInvalidateRange(p, size);

	buf->refcount = 1;
	buf->mapped = 0;
	buf->flags = 0;
	buf->generation = 0;

	buf->pin_prevp = NULL;
	buf->pin_next = NULL;

	buf->list_prev = NULL;
	buf->list_next = NULL;

	buf->base = p;
	buf->size = size;

	buffer_insert_tail(buf);

	return GL_TRUE;
}
Beispiel #19
0
OSL_FONT *oslLoadFont(OSL_FONTINFO *fi)
{
	OSL_FONT *f;
	int i, x, y;
	int imageFormat;
	const int pixelplanewidth[4]={3, 2, 2, 1};

	f = (OSL_FONT*)malloc(sizeof(OSL_FONT));
	if (!f)
		return NULL;
	memset(f, 0, sizeof(OSL_FONT));					//<-- STAS: Initialize the OSL_FONT structure

    f->fontType = OSL_FONT_OFT;

	//Liste des tailles
	f->charWidths = (u8*)malloc(256*sizeof(char));
	if (!f->charWidths)		{
		free(f);
		return NULL;
	}
	if (fi->charWidths)		{
		//Réutilise les tailles fournies
		for (i=0;i<256;i++)
			f->charWidths[i] = fi->charWidths[i];
//		f->charWidths = fi->charWidths;
		f->isCharWidthConstant = 0;
	}
	else		{
		//Remplit la table avec les mêmes tailles
		for (i=0;i<256;i++)
			f->charWidths[i] = fi->charWidth;
		f->isCharWidthConstant = 1;
		f->charWidth = fi->charWidth;				//<-- STAS: Initialize f->charWidth somehow...
	}
	//Position des caractères (pour les fontes non proportionnelles)
	f->charPositions = (u16*)malloc(256*sizeof(short));
	if (!f->charPositions)		{
		free(f->charWidths);
		free(f);
		return NULL;
	}
	f->addedSpace = fi->addedSpace;
	x = y = 0;
	for (i=0;i<256;i++)
	{
		if (x + f->charWidths[i] + f->addedSpace >= OSL_TEXT_TEXWIDTH)			{
			//Prochaine ligne
			x = 0;
			y ++;
		}
		f->charPositions[i] = x + (y<<OSL_TEXT_TEXDECAL);
		x += f->charWidths[i] + f->addedSpace;
	}

	//16x16 caractères
	f->img = oslCreateImage(512, (y+1)*fi->charHeight, OSL_IN_RAM, OSL_PF_4BIT);
	//4 bit texture format
	imageFormat = 4;
	if (!f->img)		{
		free(f->charPositions);
		free(f->charWidths);
		free(f);
		return NULL;
	}
	//La palette
	f->img->palette = oslCreatePalette(16, OSL_PF_8888);
	if (!f->img->palette)		{
		oslDeleteImage(f->img);					//<-- STAS: It would beter to do it before free(f) :-)
		free(f->charPositions);
		free(f->charWidths);
		free(f);
		return NULL;
	}

	if (fi->paletteCount)		{
		for (i=0;i<oslMin(fi->paletteCount,f->img->palette->nElements);i++)		//<-- STAS: check i against oslMin(...) !
			((unsigned long*)f->img->palette->data)[i] = fi->paletteData[i];
	}
	else	{
		((unsigned long*)f->img->palette->data)[0] = RGBA(255,255,255, 0);
		((unsigned long*)f->img->palette->data)[1] = RGBA(255,255,255, 255);
	}

	//Vide directement le cache
	sceKernelDcacheWritebackInvalidateRange(f->img->palette->data, 16*4);

	f->charHeight = fi->charHeight;
	memset(f->img->data, 0, f->img->totalSize);
	//Dessine les caractères sur le buffer
	for (i=0;i<256;i++)		{
		oslDrawChar1BitToImage(f->img, OSL_TEXT_CHARPOSXY(f, i),
			f->charWidths[i] + f->addedSpace, f->charHeight, fi->lineWidth << pixelplanewidth[fi->pixelFormat - 1],
			fi->pixelFormat, imageFormat, (u8*)fi->fontdata+i*fi->lineWidth*fi->charHeight);
	}
	//Pareil, vide direct le cache
	sceKernelDcacheWritebackInvalidateRange(f->img->data, f->img->totalSize);
	return f;
}
Beispiel #20
0
void prepScanAudioData() {
	memset(audioData, 0xCD, 16384);
	sceKernelDcacheWritebackInvalidateRange(audioData, 16384);
}