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

📄 ppu.cpp

📁 著名SFC模拟器Snes9x的源代码。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	PPU.ClipWindow2Inside[B] = TRUE;    }    PPU.ClipCounts[4] = 0;    PPU.ClipCounts[5] = 0;    PPU.ClipWindowOverlapLogic[4] = PPU.ClipWindowOverlapLogic[5] = CLIP_OR;    PPU.ClipWindow1Enable[4] = PPU.ClipWindow1Enable[5] = FALSE;    PPU.ClipWindow2Enable[4] = PPU.ClipWindow2Enable[5] = FALSE;    PPU.ClipWindow1Inside[4] = PPU.ClipWindow1Inside[5] = TRUE;    PPU.ClipWindow2Inside[4] = PPU.ClipWindow2Inside[5] = TRUE;        PPU.CGFLIP = 0;    int c;    for (c = 0; c < 256; c++)    {	PPU.CGDATA [c] = ((c & 7) << 2) | (((c >> 3) & 7) << 7) |			 (((c >> 6) & 3) << 13);	IPPU.Red [c] = PPU.CGDATA [c] & 0x1f;	IPPU.Green [c] = (PPU.CGDATA [c] >> 5) & 0x1f;	IPPU.Blue [c] = (PPU.CGDATA [c] >> 10) & 0x1f;    }    PPU.FirstSprite = 0;    PPU.LastSprite = 127;    for (int Sprite = 0; Sprite < 128; Sprite++)    {	PPU.OBJ[Sprite].HPos = 0;	PPU.OBJ[Sprite].VPos = 0;	PPU.OBJ[Sprite].VFlip = 0;	PPU.OBJ[Sprite].HFlip = 0;	PPU.OBJ[Sprite].Priority = 0;	PPU.OBJ[Sprite].Palette = 0;	PPU.OBJ[Sprite].Name = 0;	PPU.OBJ[Sprite].Size = 0;    }    PPU.OAMPriorityRotation = 0;    PPU.OAMFlip = 0;    PPU.OAMTileAddress = 0;    PPU.OAMAddr = 0;    PPU.IRQVBeamPos = 0;    PPU.IRQHBeamPos = 0;    PPU.VBeamPosLatched = 0;    PPU.HBeamPosLatched = 0;    PPU.HBeamFlip = 0;    PPU.VBeamFlip = 0;    PPU.HVBeamCounterLatched = 0;    PPU.MatrixA = PPU.MatrixB = PPU.MatrixC = PPU.MatrixD = 0;    PPU.CentreX = PPU.CentreY = 0;    PPU.Joypad1ButtonReadPos = 0;    PPU.Joypad2ButtonReadPos = 0;    PPU.Joypad3ButtonReadPos = 0;    PPU.CGADD = 0;    PPU.FixedColourRed = PPU.FixedColourGreen = PPU.FixedColourBlue = 0;    PPU.SavedOAMAddr = 0;    PPU.ScreenHeight = SNES_HEIGHT;    PPU.WRAM = 0;    PPU.BG_Forced = 0;    PPU.ForcedBlanking = TRUE;    PPU.OBJThroughMain = FALSE;    PPU.OBJThroughSub = FALSE;    PPU.OBJSizeSelect = 0;    PPU.OBJNameSelect = 0;    PPU.OBJNameBase = 0;    PPU.OBJAddition = FALSE;    PPU.OAMReadFlip = 0;    ZeroMemory (PPU.OAMData, 512 + 32);        PPU.VTimerEnabled = FALSE;    PPU.HTimerEnabled = FALSE;    PPU.HTimerPosition = Settings.H_Max + 1;    PPU.Mosaic = 0;    PPU.BGMosaic [0] = PPU.BGMosaic [1] = FALSE;    PPU.BGMosaic [2] = PPU.BGMosaic [3] = FALSE;    PPU.Mode7HFlip = FALSE;    PPU.Mode7VFlip = FALSE;    PPU.Mode7Repeat = 0;    PPU.Window1Left = 1;    PPU.Window1Right = 0;    PPU.Window2Left = 1;    PPU.Window2Right = 0;    PPU.RecomputeClipWindows = TRUE;    PPU.CGFLIPRead = 0;    PPU.Need16x8Mulitply = FALSE;    PPU.MouseSpeed[0] = PPU.MouseSpeed[1] = 0;    IPPU.ColorsChanged = TRUE;    IPPU.HDMA = 0;    IPPU.HDMAStarted = FALSE;    IPPU.MaxBrightness = 0;    IPPU.LatchedBlanking = 0;    IPPU.OBJChanged = TRUE;    IPPU.RenderThisFrame = TRUE;    IPPU.DirectColourMapsNeedRebuild = TRUE;    IPPU.FrameCount = 0;    IPPU.RenderedFramesCount = 0;    IPPU.DisplayedRenderedFrameCount = 0;    IPPU.SkippedFrames = 0;    IPPU.FrameSkip = 0;    ZeroMemory (IPPU.TileCached [TILE_2BIT], MAX_2BIT_TILES);    ZeroMemory (IPPU.TileCached [TILE_4BIT], MAX_4BIT_TILES);    ZeroMemory (IPPU.TileCached [TILE_8BIT], MAX_8BIT_TILES);    IPPU.FirstVRAMRead = FALSE;    IPPU.LatchedInterlace = FALSE;    IPPU.DoubleWidthPixels = FALSE;    IPPU.RenderedScreenHeight = SNES_WIDTH;    IPPU.RenderedScreenWidth = SNES_HEIGHT;    IPPU.XB = NULL;    for (c = 0; c < 256; c++)	IPPU.ScreenColors [c] = c;    S9xFixColourBrightness ();    IPPU.PreviousLine = IPPU.CurrentLine = 0;    IPPU.Joypads[0] = IPPU.Joypads[1] = IPPU.Joypads[2] = 0;    IPPU.Joypads[3] = IPPU.Joypads[4] = 0;    IPPU.SuperScope = 0;    IPPU.Mouse[0] = IPPU.Mouse[1] = 0;    IPPU.PrevMouseX[0] = IPPU.PrevMouseX[1] = 256 / 2;    IPPU.PrevMouseY[0] = IPPU.PrevMouseY[1] = 224 / 2;    if (Settings.ControllerOption == 0)	IPPU.Controller = SNES_MAX_CONTROLLER_OPTIONS - 1;    else	IPPU.Controller = Settings.ControllerOption - 1;    S9xNextController ();    for (c = 0; c < 2; c++)	memset (&IPPU.Clip [c], 0, sizeof (struct ClipData));    if (Settings.MouseMaster)    {	S9xProcessMouse (0);	S9xProcessMouse (1);    }    for (c = 0; c < 0x8000; c += 0x100)	memset (&Memory.FillRAM [c], c >> 8, 0x100);    ZeroMemory (&Memory.FillRAM [0x2100], 0x100);    ZeroMemory (&Memory.FillRAM [0x4200], 0x100);    ZeroMemory (&Memory.FillRAM [0x4000], 0x100);}void S9xProcessMouse (int which1){    int x, y;    uint32 buttons;        if ((IPPU.Controller == SNES_MOUSE || IPPU.Controller == SNES_MOUSE_SWAPPED) &&	S9xReadMousePosition (which1, x, y, buttons))    {	int delta_x, delta_y;#define MOUSE_SIGNATURE 0x1	IPPU.Mouse [which1] = MOUSE_SIGNATURE | 			      (PPU.MouseSpeed [which1] << 4) |		              ((buttons & 1) << 6) | ((buttons & 2) << 6);	delta_x = x - IPPU.PrevMouseX[which1];	delta_y = y - IPPU.PrevMouseY[which1];	if (delta_x > 63)	{	    delta_x = 63;	    IPPU.PrevMouseX[which1] += 63;	}	else	if (delta_x < -63)	{	    delta_x = -63;	    IPPU.PrevMouseX[which1] -= 63;	}	else	    IPPU.PrevMouseX[which1] = x;	if (delta_y > 63)	{	    delta_y = 63;	    IPPU.PrevMouseY[which1] += 63;	}	else	if (delta_y < -63)	{	    delta_y = -63;	    IPPU.PrevMouseY[which1] -= 63;	}	else	    IPPU.PrevMouseY[which1] = y;	if (delta_x < 0)	{	    delta_x = -delta_x;	    IPPU.Mouse [which1] |= (delta_x | 0x80) << 16;	}	else	    IPPU.Mouse [which1] |= delta_x << 16;	if (delta_y < 0)	{	    delta_y = -delta_y;	    IPPU.Mouse [which1] |= (delta_y | 0x80) << 24;	}	else	    IPPU.Mouse [which1] |= delta_y << 24;	if (IPPU.Controller == SNES_MOUSE_SWAPPED)	    IPPU.Joypads [0] = IPPU.Mouse [which1];	else	    IPPU.Joypads [1] = IPPU.Mouse [which1];    }}void ProcessSuperScope (){    int x, y;    uint32 buttons;        if (IPPU.Controller == SNES_SUPERSCOPE &&	S9xReadSuperScopePosition (x, y, buttons))    {#define SUPERSCOPE_SIGNATURE 0x00ff	uint32 scope;		scope = SUPERSCOPE_SIGNATURE | ((buttons & 1) << (7 + 8)) |		((buttons & 2) << (5 + 8)) | ((buttons & 4) << (3 + 8)) |		((buttons & 8) << (1 + 8));	if (x > 255)	    x = 255;	if (x < 0)	    x = 0;	if (y > PPU.ScreenHeight - 1)	    y = PPU.ScreenHeight - 1;	if (y < 0)	    y = 0;	PPU.VBeamPosLatched = (uint16) (y + 1);	PPU.HBeamPosLatched = (uint16) x;	PPU.HVBeamCounterLatched = TRUE;	Memory.FillRAM [0x213F] |= 0x40;	IPPU.Joypads [1] = scope;    }}void S9xNextController (){    switch (IPPU.Controller)    {    case SNES_MULTIPLAYER5:	IPPU.Controller = SNES_JOYPAD;	break;    case SNES_JOYPAD:	if (Settings.MouseMaster)	{	    IPPU.Controller = SNES_MOUSE_SWAPPED;	    break;	}    case SNES_MOUSE_SWAPPED:	if (Settings.MouseMaster)	{	    IPPU.Controller = SNES_MOUSE;	    break;	}    case SNES_MOUSE:	if (Settings.SuperScopeMaster)	{	    IPPU.Controller = SNES_SUPERSCOPE;	    break;	}    case SNES_SUPERSCOPE:	if (Settings.MultiPlayer5Master)	{	    IPPU.Controller = SNES_MULTIPLAYER5;	    break;	}    default:	IPPU.Controller = SNES_JOYPAD;	break;    }}void S9xUpdateJoypads (){    int i;    for (i = 0; i < 5; i++)    {	IPPU.Joypads [i] = S9xReadJoypad (i);	if (IPPU.Joypads [i] & SNES_LEFT_MASK)	    IPPU.Joypads [i] &= ~SNES_RIGHT_MASK;	if (IPPU.Joypads [i] & SNES_UP_MASK)	    IPPU.Joypads [i] &= ~SNES_DOWN_MASK;    }    // Read mouse position if enabled    if (Settings.MouseMaster)    {	for (i = 0; i < 2; i++)	    S9xProcessMouse (i);    }    // Read SuperScope if enabled    if (Settings.SuperScopeMaster)	ProcessSuperScope ();    if (Memory.FillRAM [0x4200] & 1)    {	PPU.Joypad1ButtonReadPos = 16;	if (Memory.FillRAM [0x4201] & 0x80)	{	    PPU.Joypad2ButtonReadPos = 16;	    PPU.Joypad3ButtonReadPos = 0;	}	else	{	    PPU.Joypad2ButtonReadPos = 0;	    PPU.Joypad3ButtonReadPos = 16;	}	int ind = Settings.SwapJoypads ? 1 : 0;	Memory.FillRAM [0x4218] = (uint8) IPPU.Joypads [ind];	Memory.FillRAM [0x4219] = (uint8) (IPPU.Joypads [ind] >> 8);	Memory.FillRAM [0x421a] = (uint8) IPPU.Joypads [ind ^ 1];	Memory.FillRAM [0x421b] = (uint8) (IPPU.Joypads [ind ^ 1] >> 8);	if (Memory.FillRAM [0x4201] & 0x80)	{	    Memory.FillRAM [0x421c] = (uint8) IPPU.Joypads [ind];	    Memory.FillRAM [0x421d] = (uint8) (IPPU.Joypads [ind] >> 8);	    Memory.FillRAM [0x421e] = (uint8) IPPU.Joypads [2];	    Memory.FillRAM [0x421f] = (uint8) (IPPU.Joypads [2] >> 8);	}	else	{	    Memory.FillRAM [0x421c] = (uint8) IPPU.Joypads [3];	    Memory.FillRAM [0x421d] = (uint8) (IPPU.Joypads [3] >> 8);	    Memory.FillRAM [0x421e] = (uint8) IPPU.Joypads [4];	    Memory.FillRAM [0x421f] = (uint8) (IPPU.Joypads [4] >> 8);	}    }}#ifndef ZSNES_FXvoid S9xSuperFXExec (){#if 1    if (Settings.SuperFX)    {	if ((Memory.FillRAM [0x3000 + GSU_SFR] & FLG_G) &&	    (Memory.FillRAM [0x3000 + GSU_SCMR] & 0x18) == 0x18)	{	    if (!Settings.WinterGold)		FxEmulate (~0);	    else		FxEmulate ((Memory.FillRAM [0x3000 + GSU_CLSR] & 1) ? 700 : 350);	    int GSUStatus = Memory.FillRAM [0x3000 + GSU_SFR] |			    (Memory.FillRAM [0x3000 + GSU_SFR + 1] << 8);	    if ((GSUStatus & (FLG_G | FLG_IRQ)) == FLG_IRQ)	    {		// Trigger a GSU IRQ.		S9xSetIRQ (GSU_IRQ_SOURCE);	    }	}    }#else    uint32 tmp =  (Memory.FillRAM[0x3034] << 16) + *(uint16 *) &Memory.FillRAM [0x301e];#if 0    if (tmp == 0x018428)    {	*(uint16 *) &SRAM [0x0064] = 0xbc00;	*(uint16 *) &SRAM [0x002c] = 0x8000;    }#endif    if (tmp == -1)//0x018428) //0x01bfc3) //0x09edaf) //-1) //0x57edaf)    {	while (Memory.FillRAM [0x3030] & 0x20)	{	    int i;	    int32 vError;	    uint8 avReg[0x40];	    char tmp[128];	    uint8 vPipe;	    uint8 vColr;	    uint8 vPor;	    FxPipeString (tmp);	    /* Make the string 32 chars long */	    if(strlen(tmp) < 32) { memset(&tmp[strlen(tmp)],' ',32-strlen(tmp)); tmp[32] = 0; }	    /* Copy registers (so we can see if any changed) */	    vColr = FxGetColorRegister();	    vPor = FxGetPlotOptionRegister();	    memcpy(avReg,SuperFX.pvRegisters,0x40);	    /* Print the pipe string */	    printf(tmp);	    /* Execute the instruction in the pipe */	    vPipe = FxPipe();	    vError = FxEmulate(1);	    /* Check if any registers changed (and print them if they did) */	    for(i=0; i<16; i++)	    {		uint32 a = 0;		uint32 r1 = ((uint32)avReg[i*2]) | (((uint32)avReg[(i*2)+1])<<8);		uint32 r2 = (uint32)(SuperFX.pvRegisters[i*2]) | (((uint32)SuperFX.pvRegisters[(i*2)+1])<<8);		if(i==15)		    a = OPCODE_BYTES(vPipe);		if(((r1+a)&0xffff) != r2)		    printf(" r%d=$%04x",i,r2);	    }	    {		/* Check SFR */		uint32 r1 = ((uint32)avReg[0x30]) | (((uint32)avReg[0x31])<<8);		uint32 r2 = (uint32)(SuperFX.pvRegisters[0x30]) | (((uint32)SuperFX.pvRegisters[0x31])<<8);		if((r1&(1<<1)) != (r2&(1<<1)))		    printf(" Z=%d",(uint32)(!!(r2&(1<<1))));		if((r1&(1<<2)) != (r2&(1<<2)))		    printf(" CY=%d",(uint32)(!!(r2&(1<<2))));		if((r1&(1<<3)) != (r2&(1<<3)))		    printf(" S=%d",(uint32)(!!(r2&(1<<3))));		if((r1&(1<<4)) != (r2&(1<<4)))		    printf(" OV=%d",(uint32)(!!(r2&(1<<4))));		if((r1&(1<<5)) != (r2&(1<<5)))		    printf(" G=%d",(uint32)(!!(r2&(1<<5))));		if((r1&(1<<6)) != (r2&(1<<6)))		    printf(" R=%d",(uint32)(!!(r2&(1<<6))));		if((r1&(1<<8)) != (r2&(1<<8)))		    printf(" ALT1=%d",(uint32)(!!(r2&(1<<8))));		if((r1&(1<<9)) != (r2&(1<<9)))		    printf(" ALT2=%d",(uint32)(!!(r2&(1<<9))));		if((r1&(1<<10)) != (r2&(1<<10)))		    printf(" IL=%d",(uint32)(!!(r2&(1<<10))));		if((r1&(1<<11)) != (r2&(1<<11)))		    printf(" IH=%d",(uint32)(!!(r2&(1<<11))));		if((r1&(1<<12)) != (r2&(1<<12)))		    printf(" B=%d",(uint32)(!!(r2&(1<<12))));		if((r1&(1<<15)) != (r2&(1<<15)))		    printf(" IRQ=%d",(uint32)(!!(r2&(1<<15))));	    }	    {		/* Check PBR */		uint32 r1 = ((uint32)avReg[0x34]);		uint32 r2 = (uint32)(SuperFX.pvRegisters[0x34]);		if(r1 != r2)		    printf(" PBR=$%02x",r2);	    }	    {		/* Check ROMBR */		uint32 r1 = ((uint32)avReg[0x36]);		uint32 r2 = (uint32)(SuperFX.pvRegisters[0x36]);		if(r1 != r2)		    printf(" ROMBR=$%02x",r2);	    }	    {		/* Check RAMBR */		uint32 r1 = ((uint32)avReg[0x3c]);		uint32 r2 = (uint32)(SuperFX.pvRegisters[0x3c]);		if(r1 != r2)		    printf(" RAMBR=$%02x",r2);	    }	    {		/* Check CBR */		uint32 r1 = ((uint32)avReg[0x3e]) | (((uint32)avReg[0x3f])<<8);		uint32 r2 = (uint32)(SuperFX.pvRegisters[0x3e]) | (((uint32)SuperFX.pvRegisters[0x3f])<<8);		if(r1 != r2)		    printf(" CBR=$%04x",r2);	    }	    {		/* Check COLR */		if(vColr != FxGetColorRegister())		    printf(" COLR=$%02x",FxGetColorRegister());	    }	    {		/* Check POR */		if(vPor != FxGetPlotOptionRegister())		    printf(" POR=$%02x",FxGetPlotOptionRegister());	    }	    printf ("\n");	}	S9xExit ();    }    else    {	uint32 t = (Memory.FillRAM [0x3034] << 16) +		   (Memory.FillRAM [0x301f] << 8) +		   (Memory.FillRAM [0x301e] << 0);printf ("%06x: %d\n", t, FxEmulate (2000000));//	FxEmulate (2000000);    }#if 0    if (!(CPU.Flags & TRACE_FLAG))    {	static int z = 1;	if (z == 0)	{	    extern FILE *trace;	    CPU.Flags |= TRACE_FLAG;	    trace = fopen ("trace.log", "wb");	}	else	z--;    }#endif    Memory.FillRAM [0x3030] &= ~0x20;    if (Memory.FillRAM [0x3031] & 0x80)    {	S9xSetIRQ (GSU_IRQ_SOURCE);    }#endif}#endif

⌨️ 快捷键说明

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