Example #1
0
u32 sal_VideoInit(u32 bpp, u32 color, u32 refreshRate)
{
	SDL_ShowCursor(0);

	if (mScreen)
	{
		if (mBpp == bpp)
		{
			return SAL_OK;
		}
		SDL_VideoQuit();
		mScreen=NULL;
	}
	
	mBpp=bpp;
	mRefreshRate=refreshRate;

	//Set up the screen
	mScreen = SDL_SetVideoMode( SAL_SCREEN_WIDTH, SAL_SCREEN_HEIGHT, bpp, SDL_HWSURFACE | SDL_DOUBLEBUF);

    	//If there was an error in setting up the screen
    	if( mScreen == NULL )
    	{
		sal_LastErrorSet("SDL_SetVideoMode failed");        	
		return SAL_ERROR;
    	}

    	// lock surface if needed 
	if (SDL_MUSTLOCK(mScreen)) 
	{ 
		if (SDL_LockSurface(mScreen) < 0) 
		{ 
			sal_LastErrorSet("unable to lock surface"); 
			return SAL_ERROR;
		} 
	}

	sal_VideoClear(color);
   
	sal_VideoFlip(1);
   
	return SAL_OK;
}
Example #2
0
    bool8_32 S9xDeinitUpdate (int Width, int Height, bool8_32)
    {
        if(mInMenu) return TRUE;

        // After returning from the menu, clear the background of 3 frames.
        // This prevents remnants of the menu from appearing.
        if (mFramesCleared < 3)
        {
            sal_VideoClear(0);
            mFramesCleared++;
        }

        // If the height changed from 224 to 239, or from 239 to 224,
        // possibly change the resolution.
        bool PAL = !!(Memory.FillRAM[0x2133] & 4);
        if (PAL != LastPAL)
        {
            sal_VideoSetPAL(mMenuOptions.fullScreen, PAL);
            LastPAL = PAL;
        }

        switch (mMenuOptions.fullScreen)
        {
        case 0: /* No scaling */
        case 3: /* Hardware scaling */
        {
            u32 h = PAL ? SNES_HEIGHT_EXTENDED : SNES_HEIGHT;
            u32 y, pitch = sal_VideoGetPitch();
            u8 *src = (u8*) IntermediateScreen, *dst = (u8*) sal_VideoGetBuffer()
                      + ((sal_VideoGetWidth() - SNES_WIDTH) / 2) * sizeof(u16)
                      + ((sal_VideoGetHeight() - h) / 2) * pitch;
            for (y = 0; y < h; y++)
            {
                memcpy(dst, src, SNES_WIDTH * sizeof(u16));
                src += SNES_WIDTH * sizeof(u16);
                dst += pitch;
            }
            break;
        }

        case 1: /* Fast software scaling */
            if (PAL) {
                upscale_256x240_to_320x240((uint32_t*) sal_VideoGetBuffer(), (uint32_t*) IntermediateScreen, SNES_WIDTH);
            } else {
                upscale_p((uint32_t*) sal_VideoGetBuffer(), (uint32_t*) IntermediateScreen, SNES_WIDTH);
            }
            break;

        case 2: /* Smooth software scaling */
            if (PAL) {
                upscale_256x240_to_320x240_bilinearish((uint32_t*) sal_VideoGetBuffer() + 160, (uint32_t*) IntermediateScreen, SNES_WIDTH);
            } else {
                upscale_256x224_to_320x240_bilinearish((uint32_t*) sal_VideoGetBuffer() + 160, (uint32_t*) IntermediateScreen, SNES_WIDTH);
            }
            break;
        }

        u32 newTimer;
        if (mMenuOptions.showFps)
        {
            mFps++;
            newTimer=sal_TimerRead();
            if(newTimer-mLastTimer>Memory.ROMFramesPerSecond)
            {
                mLastTimer=newTimer;
                sprintf(mFpsDisplay,"%2d/%2d", mFps, Memory.ROMFramesPerSecond);
                mFps=0;
            }

            sal_VideoDrawRect(0,0,5*8,8,SAL_RGB(0,0,0));
            sal_VideoPrint(0,0,mFpsDisplay,SAL_RGB(31,31,31));
        }

        if(mVolumeDisplayTimer>0)
        {
            sal_VideoDrawRect(100,0,8*8,8,SAL_RGB(0,0,0));
            sal_VideoPrint(100,0,mVolumeDisplay,SAL_RGB(31,31,31));
        }

        if(mQuickStateTimer>0)
        {
            sal_VideoDrawRect(200,0,8*8,8,SAL_RGB(0,0,0));
            sal_VideoPrint(200,0,mQuickStateDisplay,SAL_RGB(31,31,31));
        }

        sal_VideoFlip(0);
    }
Example #3
0
int mainEntry(int argc, char* argv[])
{
	int ref = 0;

	s32 event=EVENT_NONE;

	sal_Init();
	sal_VideoInit(16,SAL_RGB(0,0,0),Memory.ROMFramesPerSecond);

	mRomName[0]=0;
	if (argc >= 2) 
 		strcpy(mRomName, argv[1]); // Record ROM name

	MenuInit(sal_DirectoryGetHome(), &mMenuOptions);


	if(SnesInit() == SAL_ERROR)
	{
		sal_Reset();
		return 0;
	}

	while(1)
	{
		mInMenu=1;
		event=MenuRun(mRomName);
		mInMenu=0;

		if(event==EVENT_LOAD_ROM)
		{
			if(mTempState) free(mTempState);
			mTempState=NULL;
			if(SnesRomLoad() == SAL_ERROR) 
			{
				MenuMessageBox("Failed to load rom",mRomName,"Press any button to continue", MENU_MESSAGE_BOX_MODE_PAUSE);
				sal_Reset();
		    		return 0;
			}
			else
			{
				event=EVENT_RUN_ROM;
		  	}
		}

		if(event==EVENT_RESET_ROM)
		{
			S9xReset();
			event=EVENT_RUN_ROM;
		}

		if(event==EVENT_RUN_ROM)
		{
			if(mMenuOptions.fullScreen)
			{
				sal_VideoSetScaling(SNES_WIDTH,SNES_HEIGHT);
			}

			if(mMenuOptions.transparency)	Settings.Transparency = TRUE;
			else Settings.Transparency = FALSE;

			sal_AudioSetVolume(mMenuOptions.volume,mMenuOptions.volume);
			sal_CpuSpeedSet(mMenuOptions.cpuSpeed);	
			sal_VideoClear(0);
			sal_VideoFlip(1);
			sal_VideoClear(0);
			sal_VideoFlip(1);
			if(mMenuOptions.soundEnabled) 	
				RunSound();
			else	RunNoSound();

			event=EVENT_NONE;
		}

		if(event==EVENT_EXIT_APP) break;	
	}

	if(mTempState) free(mTempState);
	mTempState=NULL;
	
	S9xGraphicsDeinit();
	S9xDeinitAPU();
	Memory.Deinit();

	free(GFX.SubZBuffer);
	free(GFX.ZBuffer);
	free(GFX.SubScreen);
	GFX.SubZBuffer=NULL;
	GFX.ZBuffer=NULL;
	GFX.SubScreen=NULL;

	sal_Reset();
  	return 0;
}