Exemple #1
0
void GsResetGraph(short int mode, short int interlace, short int omode, short int ffmode)
{
	GsGParam_t *pGParams;

	switch(mode){
		case GS_INIT_RESET:
			GsDmaInit();	//It seems like the Sony developers reset the GIF DMA channel with their libdma library, but a lot of homebrew GS libraries will do this on their own.

			pGParams=GsGetGParam();
			GS_SET_CSR_reset(1);
			pGParams->ffmode=ffmode;
			pGParams->interlace=interlace;
			pGParams->omode=omode;
			pGParams->version=GS_GET_CSR_gs_rev_number>>16;

			GsPutIMR(0xFF00);

			SetGsCrt(interlace&1, omode&0xFF, ffmode&1);
			GsSetCRTCSettings(CRTC_SETTINGS_DEFAULT1, 0x80);
			break;
		case GS_INIT_DRAW_RESET:
			GS_SET_CSR_flush(1);
			break;
	/*	There is a mode 5 present in the Sony sceGsResetGraph, but is not documented. It seems to change the video mode without resetting anything. */
	}
}
Exemple #2
0
void gsKit_remove_hsync_handler(int callback_id)
{
	DIntr();
	// Mask HSync interrupt
	GsPutIMR(GsGetIMR() | 0x0400);
	DisableIntc(INTC_GS);
	RemoveIntcHandler(INTC_GS, callback_id);
	EIntr();
}
Exemple #3
0
void gsKit_remove_vsync_handler(int callback_id)
{
	DIntr();
	// Mask VSync interrupt
	GsPutIMR(GsGetIMR() | 0x0800);
	DisableIntc(INTC_VBLANK_S);
	RemoveIntcHandler(INTC_VBLANK_S, callback_id);
	EIntr();
}
Exemple #4
0
int gsKit_add_hsync_handler(int (*hsync_callback)())
{
	int callback_id;

	DIntr();
	callback_id = AddIntcHandler(INTC_GS, hsync_callback, 0);
	EnableIntc(INTC_GS);
	// Unmask HSync interrupt
	GsPutIMR(GsGetIMR() & ~0x0400);
	EIntr();

	return callback_id;
}
Exemple #5
0
int gsKit_add_vsync_handler(int (*vsync_callback)())
{
	int callback_id;

	DIntr();
	callback_id = AddIntcHandler(INTC_VBLANK_S, vsync_callback, 0);
	EnableIntc(INTC_VBLANK_S);
	// Unmask VSync interrupt
	GsPutIMR(GsGetIMR() & ~0x0800);
	EIntr();

	return callback_id;
}
Exemple #6
0
void
gsInit(void)
{
	struct GsState *g = gsCurState;
	int addr0, addr1;

	g->visibleFb = 0;
	g->activeFb = 1;
	printf("%d %d\n", g->fbAddr[0], g->fbAddr[1]);
	addr0 = g->fbAddr[g->visibleFb]/4/2048;
	addr1 = g->fbAddr[g->activeFb]/4/2048;

	GS_RESET();
	__asm__("sync.p; nop");
	SET_REG64(GS_CSR, 0);
	GsPutIMR(0xff00);
	SetGsCrt(g->interlaced, g->mode, g->field);

	SET_REG64(GS_PMODE, MAKE_GS_PMODE(0, 1, 0, 1, 0, 0xFF));
	SET_REG64(GS_DISPFB2, MAKE_GS_DISPFB(addr0, g->width/64, g->psm, 0, 0));
	SET_REG64(GS_DISPFB1, MAKE_GS_DISPFB(addr0, g->width/64, g->psm, 0, 0));
	SET_REG64(GS_DISPLAY2, MAKE_GS_DISPLAY(g->startx, g->starty,
	                                       g->magh, g->magv,
	                                       g->dw-1, g->dh-1));
	SET_REG64(GS_DISPLAY1, MAKE_GS_DISPLAY(g->startx, g->starty,
	                                       g->magh, g->magv,
	                                       g->dw-1, g->dh-1));
	SET_REG64(GS_BGCOLOR, MAKE_GS_BGCOLOR(100, 100, 100));

	GIF_BEGIN_PACKET(gifDmaBuf);
	GIF_TAG(gifDmaBuf, 7, 1, 0, 0, 0, 1, 0x0e);
	GIF_DATA_AD(gifDmaBuf, GS_PRMODECONT, MAKE_GS_PRMODECONT(1));
	GIF_DATA_AD(gifDmaBuf, GS_FRAME_1,
	            MAKE_GS_FRAME(addr1, g->width/64, g->psm, 0));
	GIF_DATA_AD(gifDmaBuf, GS_ZBUF_1,
	            MAKE_GS_ZBUF(g->zbAddr/4/2048, g->zpsm, 0));
	GIF_DATA_AD(gifDmaBuf, GS_XYOFFSET_1,
	            MAKE_GS_XYOFFSET(g->xoff, g->yoff));
	GIF_DATA_AD(gifDmaBuf, GS_SCISSOR_1,
	            MAKE_GS_SCISSOR(0, g->xmax, 0, g->ymax));
	GIF_DATA_AD(gifDmaBuf, GS_TEST_1,
	            MAKE_GS_TEST(0, 0, 0, 0, 0, 0, g->ztest, g->zfunc));
	GIF_DATA_AD(gifDmaBuf, GS_COLCLAMP, MAKE_GS_COLCLAMP(1));
	GIF_SEND_PACKET(gifDmaBuf);
}
Exemple #7
0
void gsKit_init_screen(GSGLOBAL *gsGlobal)
{
    u64	*p_data;
    u64	*p_store;
    int	size = 18;

    if((gsGlobal->Dithering == GS_SETTING_ON) &&
            ((gsGlobal->PSM == GS_PSM_CT16) || (gsGlobal->PSM == GS_PSM_CT16S)))
        size = 19;

    gsKit_set_buffer_attributes(gsGlobal);

#ifdef DEBUG
    printf("Screen Mode:\n");
    printf("------------\n");
    printf("Width : %d\n", gsGlobal->Width);
    printf("Height: %d\n", gsGlobal->Height);
    printf("StartX: %d\n", gsGlobal->StartX);
    printf("StartY: %d\n", gsGlobal->StartY);
    printf("MagH  : %d\n", gsGlobal->MagH);
    printf("MagV  : %d\n", gsGlobal->MagV);
    printf("DW    : %d\n", gsGlobal->DW);
    printf("DH    : %d\n", gsGlobal->DH);
#endif

    GS_RESET();

    __asm__("sync.p; nop;");

    *GS_CSR = 0x00000000; // Clean CSR registers

    GsPutIMR(0x0000F700); // Unmasks all of the GS interrupts

    SetGsCrt(gsGlobal->Interlace, gsGlobal->Mode, gsGlobal->Field);

    gsGlobal->FirstFrame = GS_SETTING_ON;

    if(gsGlobal->ZBuffering == GS_SETTING_OFF)
    {
        gsGlobal->Test->ZTE = GS_SETTING_ON;
        gsGlobal->Test->ZTST = 1;
    }

    DIntr(); // disable interrupts

    GS_SET_PMODE(	0,		// Read Circuit 1
                    1,		// Read Circuit 2
                    0,		// Use ALP Register for Alpha Blending
                    1,		// Alpha Value of Read Circuit 2 for Output Selection
                    0,		// Blend Alpha with output of Read Circuit 2
                    0x80);		// Alpha Value = 1.0

    GS_SET_DISPFB1(	0,			// Frame Buffer Base Pointer (Address/2048)
                    gsGlobal->Width / 64,	// Buffer Width (Address/64)
                    gsGlobal->PSM,		// Pixel Storage Format
                    0,			// Upper Left X in Buffer
                    0);

    GS_SET_DISPFB2(	0,			// Frame Buffer Base Pointer (Address/2048)
                    gsGlobal->Width / 64,	// Buffer Width (Address/64)
                    gsGlobal->PSM,		// Pixel Storage Format
                    0,			// Upper Left X in Buffer
                    0);			// Upper Left Y in Buffer

    GS_SET_DISPLAY1(gsGlobal->StartX,		// X position in the display area (in VCK unit
                    gsGlobal->StartY,		// Y position in the display area (in Raster u
                    gsGlobal->MagH,			// Horizontal Magnification
                    gsGlobal->MagV,			// Vertical Magnification
                    gsGlobal->DW - 1,	// Display area width
                    gsGlobal->DH - 1);		// Display area height

    GS_SET_DISPLAY2(gsGlobal->StartX,		// X position in the display area (in VCK units)
                    gsGlobal->StartY,		// Y position in the display area (in Raster units)
                    gsGlobal->MagH,			// Horizontal Magnification
                    gsGlobal->MagV,			// Vertical Magnification
                    gsGlobal->DW - 1,	// Display area width
                    gsGlobal->DH - 1);		// Display area height

    GS_SET_BGCOLOR(	gsGlobal->BGColor->Red,		// Red
                    gsGlobal->BGColor->Green,	// Green
                    gsGlobal->BGColor->Blue);	// Blue

    EIntr(); //enable interrupts

    gsGlobal->CurrentPointer = 0; // reset vram pointer too

    // Context 1
    gsGlobal->ScreenBuffer[0] = gsKit_vram_alloc( gsGlobal, gsKit_texture_size(gsGlobal->Width, gsGlobal->Height, gsGlobal->PSM), GSKIT_ALLOC_SYSBUFFER );

    if(gsGlobal->DoubleBuffering == GS_SETTING_OFF)
    {
        gsGlobal->ScreenBuffer[1] = gsGlobal->ScreenBuffer[0];
    }
    else
        // Context 2
        gsGlobal->ScreenBuffer[1] = gsKit_vram_alloc( gsGlobal, gsKit_texture_size(gsGlobal->Width, gsGlobal->Height, gsGlobal->PSM), GSKIT_ALLOC_SYSBUFFER );


    if(gsGlobal->ZBuffering == GS_SETTING_ON)
        gsGlobal->ZBuffer = gsKit_vram_alloc( gsGlobal, gsKit_texture_size(gsGlobal->Width, gsGlobal->Height, gsGlobal->PSMZ), GSKIT_ALLOC_SYSBUFFER ); // Z Buffer

    gsGlobal->TexturePointer = gsGlobal->CurrentPointer; // first useable address for textures

    p_data = p_store = (u64 *)gsGlobal->dma_misc;

    *p_data++ = GIF_TAG( size - 1, 1, 0, 0, 0, 1 );
    *p_data++ = GIF_AD;

    *p_data++ = 1;
    *p_data++ = GS_PRMODECONT;

    *p_data++ = GS_SETREG_FRAME_1( gsGlobal->ScreenBuffer[0], gsGlobal->Width / 64, gsGlobal->PSM, 0 );
    *p_data++ = GS_FRAME_1;

    *p_data++ = GS_SETREG_XYOFFSET_1( gsGlobal->OffsetX,
                                      gsGlobal->OffsetY);
    *p_data++ = GS_XYOFFSET_1;

    *p_data++ = GS_SETREG_SCISSOR_1( 0, gsGlobal->Width - 1, 0, gsGlobal->Height - 1 );
    *p_data++ = GS_SCISSOR_1;

    *p_data++ = GS_SETREG_TEST( gsGlobal->Test->ATE, gsGlobal->Test->ATST,
                                gsGlobal->Test->AREF, gsGlobal->Test->AFAIL,
                                gsGlobal->Test->DATE, gsGlobal->Test->DATM,
                                gsGlobal->Test->ZTE, gsGlobal->Test->ZTST );

    *p_data++ = GS_TEST_1;

    *p_data++ = GS_SETREG_CLAMP(gsGlobal->Clamp->WMS, gsGlobal->Clamp->WMT,
                                gsGlobal->Clamp->MINU, gsGlobal->Clamp->MAXU,
                                gsGlobal->Clamp->MINV, gsGlobal->Clamp->MAXV);

    *p_data++ = GS_CLAMP_1;

    if(gsGlobal->ZBuffering == GS_SETTING_ON)
    {
        if((gsGlobal->PSM == GS_PSM_CT16) && (gsGlobal->PSMZ != GS_PSMZ_16))
            gsGlobal->PSMZ = GS_PSMZ_16; // seems only non-S 16-bit z depth works with this mode
        if((gsGlobal->PSM != GS_PSM_CT16) && (gsGlobal->PSMZ == GS_PSMZ_16))
            gsGlobal->PSMZ = GS_PSMZ_16S; // other depths don't seem to work with 16-bit non-S z depth

        *p_data++ = GS_SETREG_ZBUF_1( gsGlobal->ZBuffer / 8192, gsGlobal->PSMZ, 0 );
        *p_data++ = GS_ZBUF_1;
    }
    if(gsGlobal->ZBuffering == GS_SETTING_OFF)
    {
        *p_data++ = GS_SETREG_ZBUF_1( NULL, gsGlobal->PSM, 1 );
        *p_data++ = GS_ZBUF_1;
    }

    *p_data++ = GS_SETREG_COLCLAMP( 255 );
    *p_data++ = GS_COLCLAMP;

    *p_data++ = GS_SETREG_FRAME_1( gsGlobal->ScreenBuffer[1], gsGlobal->Width / 64, gsGlobal->PSM, 0 );
    *p_data++ = GS_FRAME_2;

    *p_data++ = GS_SETREG_XYOFFSET_1( gsGlobal->OffsetX,
                                      gsGlobal->OffsetY);
    *p_data++ = GS_XYOFFSET_2;

    *p_data++ = GS_SETREG_SCISSOR_1( 0, gsGlobal->Width - 1, 0, gsGlobal->Height - 1);
    *p_data++ = GS_SCISSOR_2;

    *p_data++ = GS_SETREG_TEST( gsGlobal->Test->ATE, gsGlobal->Test->ATST,
                                gsGlobal->Test->AREF, gsGlobal->Test->AFAIL,
                                gsGlobal->Test->DATE, gsGlobal->Test->DATM,
                                gsGlobal->Test->ZTE, gsGlobal->Test->ZTST );

    *p_data++ = GS_TEST_2;

    *p_data++ = GS_SETREG_CLAMP(gsGlobal->Clamp->WMS, gsGlobal->Clamp->WMT,
                                gsGlobal->Clamp->MINU, gsGlobal->Clamp->MAXU,
                                gsGlobal->Clamp->MINV, gsGlobal->Clamp->MAXV);

    *p_data++ = GS_CLAMP_2;

    if(gsGlobal->ZBuffering == GS_SETTING_ON)
    {
        *p_data++ = GS_SETREG_ZBUF_1( gsGlobal->ZBuffer / 8192, gsGlobal->PSMZ, 0 );
        *p_data++ = GS_ZBUF_2;
    }
    if(gsGlobal->ZBuffering == GS_SETTING_OFF)
    {
        *p_data++ = GS_SETREG_ZBUF_1( NULL, gsGlobal->PSM, 1 );
        *p_data++ = GS_ZBUF_2;
    }

    *p_data++ = GS_BLEND_BACK2FRONT;
    *p_data++ = GS_ALPHA_1;

    *p_data++ = GS_BLEND_BACK2FRONT;
    *p_data++ = GS_ALPHA_2;

    *p_data++ = GS_SETREG_DIMX(gsGlobal->DitherMatrix[0],gsGlobal->DitherMatrix[1],
                               gsGlobal->DitherMatrix[2],gsGlobal->DitherMatrix[3],gsGlobal->DitherMatrix[4],
                               gsGlobal->DitherMatrix[5],gsGlobal->DitherMatrix[6],gsGlobal->DitherMatrix[7],
                               gsGlobal->DitherMatrix[8],gsGlobal->DitherMatrix[9],gsGlobal->DitherMatrix[10],
                               gsGlobal->DitherMatrix[11],gsGlobal->DitherMatrix[12],gsGlobal->DitherMatrix[13],
                               gsGlobal->DitherMatrix[14],gsGlobal->DitherMatrix[15]); // 4x4 dither matrix

    *p_data++ = GS_DIMX;

    if((gsGlobal->Dithering == GS_SETTING_ON) && ((gsGlobal->PSM == GS_PSM_CT16) || (gsGlobal->PSM == GS_PSM_CT16S))) {
        *p_data++ = 1;
        *p_data++ = GS_DTHE;
    }

    dmaKit_send_ucab(DMA_CHANNEL_GIF, p_store, size);
    dmaKit_wait_fast();

    // do a single frame here to get rid whatever needs to be done during the first frame

    gsKit_clear(gsGlobal, GS_SETREG_RGBAQ(0x00,0x00,0x00,0x00,0x00)); // clear the screen

    gsKit_queue_exec(gsGlobal);

    gsKit_sync_flip(gsGlobal);

    gsKit_queue_reset(gsGlobal->Os_Queue);
}