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

📄 gfx.cpp

📁 SFC游戏模拟器 snes9x 1.43 的原代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
						}					}					else					{						if (!(Tile & (V_FLIP | H_FLIP)))						{							// Normal, unflipped							(*DrawHiResClippedTilePtr) (Tile + t1 + (Quot & 1),								s, 0, Count, VirtAlign, Lines);						}						else							if (Tile & H_FLIP)							{								if (Tile & V_FLIP)								{									// H & V flip									(*DrawHiResClippedTilePtr) (Tile + t2 + 1 - (Quot & 1),										s, 0, Count, VirtAlign, Lines);								}								else								{									// H flip only									(*DrawHiResClippedTilePtr) (Tile + t1 + 1 - (Quot & 1),										s, 0, Count, VirtAlign, Lines);								}							}							else							{								// V flip only								(*DrawHiResClippedTilePtr) (Tile + t2 + (Quot & 1),									s, 0, Count, VirtAlign, Lines);							}					}				}	}    }    GFX.Pitch = IPPU.DoubleHeightPixels ? GFX.RealPitch * 2 : GFX.RealPitch;    GFX.PPL = IPPU.DoubleHeightPixels ? GFX.PPLx2 : (GFX.PPLx2 >> 1);}void DrawBackground (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2){    GFX.PixSize = 1;	    BG.TileSize = BGSizes [PPU.BG[bg].BGSize];    BG.BitShift = BitShifts[BGMode][bg];    BG.TileShift = TileShifts[BGMode][bg];    BG.TileAddress = PPU.BG[bg].NameBase << 1;    BG.NameSelect = 0;    BG.Buffer = IPPU.TileCache [Depths [BGMode][bg]];    BG.Buffered = IPPU.TileCached [Depths [BGMode][bg]];    BG.PaletteShift = PaletteShifts[BGMode][bg];    BG.PaletteMask = PaletteMasks[BGMode][bg];    BG.DirectColourMode = (BGMode == 3 || BGMode == 4) && bg == 0 &&		(GFX.r2130 & 1);	    if (PPU.BGMosaic [bg] && PPU.Mosaic > 1)    {		DrawBackgroundMosaic (BGMode, bg, Z1, Z2);		return;		    }    switch (BGMode)    {    case 2:    case 4: // Used by Puzzle Bobble        DrawBackgroundOffset (BGMode, bg, Z1, Z2);		return;		    case 5:    case 6: // XXX: is also offset per tile.		if (Settings.SupportHiRes)		{			DrawBackgroundMode5 (BGMode, bg, Z1, Z2);			return;		}		break;    }    CHECK_SOUND();	    uint32 Tile;    uint16 *SC0;    uint16 *SC1;    uint16 *SC2;    uint16 *SC3;    uint32 Width;    uint8 depths [2] = {Z1, Z2};        if (BGMode == 0)		BG.StartPalette = bg << 5;    else BG.StartPalette = 0;	    SC0 = (uint16 *) &Memory.VRAM[PPU.BG[bg].SCBase << 1];	    if (PPU.BG[bg].SCSize & 1)		SC1 = SC0 + 1024;    else		SC1 = SC0;		if(SC1>=(unsigned short*)(Memory.VRAM+0x10000))		SC1=(uint16*)&Memory.VRAM[((uint8*)SC1-&Memory.VRAM[0])%0x10000];	    if (PPU.BG[bg].SCSize & 2)		SC2 = SC1 + 1024;    else		SC2 = SC0;		if(((uint8*)SC2-Memory.VRAM)>=0x10000)		SC2-=0x08000;	    if (PPU.BG[bg].SCSize & 1)		SC3 = SC2 + 1024;    else		SC3 = SC2;    	if(((uint8*)SC3-Memory.VRAM)>=0x10000)		SC3-=0x08000;		    int Lines;    int OffsetMask;    int OffsetShift;	    if (BG.TileSize == 16)    {		OffsetMask = 0x3ff;		OffsetShift = 4;    }    else    {		OffsetMask = 0x1ff;		OffsetShift = 3;    }	    for (uint32 Y = GFX.StartY; Y <= GFX.EndY; Y += Lines)    {		uint32 VOffset = LineData [Y].BG[bg].VOffset;		uint32 HOffset = LineData [Y].BG[bg].HOffset;		int VirtAlign = (Y + VOffset) & 7;				for (Lines = 1; Lines < 8 - VirtAlign; Lines++)			if ((VOffset != LineData [Y + Lines].BG[bg].VOffset) ||				(HOffset != LineData [Y + Lines].BG[bg].HOffset))				break;						if (Y + Lines > GFX.EndY)				Lines = GFX.EndY + 1 - Y;						VirtAlign <<= 3;						uint32 ScreenLine = (VOffset + Y) >> OffsetShift;			uint32 t1;			uint32 t2;			if (((VOffset + Y) & 15) > 7)			{				t1 = 16;				t2 = 0;			}			else			{				t1 = 0;				t2 = 16;			}			uint16 *b1;			uint16 *b2;						if (ScreenLine & 0x20)				b1 = SC2, b2 = SC3;			else				b1 = SC0, b2 = SC1;						b1 += (ScreenLine & 0x1f) << 5;			b2 += (ScreenLine & 0x1f) << 5;						int clipcount = GFX.pCurrentClip->Count [bg];			if (!clipcount)				clipcount = 1;			for (int clip = 0; clip < clipcount; clip++)			{				uint32 Left;				uint32 Right;								if (!GFX.pCurrentClip->Count [bg])				{					Left = 0;					Right = 256;				}				else				{					Left = GFX.pCurrentClip->Left [clip][bg];					Right = GFX.pCurrentClip->Right [clip][bg];										if (Right <= Left)						continue;				}								uint32 s = Left * GFX.PixSize + Y * GFX.PPL;				uint32 HPos = (HOffset + Left) & OffsetMask;								uint32 Quot = HPos >> 3;				uint32 Count = 0;								uint16 *t;				if (BG.TileSize == 8)				{					if (Quot > 31)						t = b2 + (Quot & 0x1f);					else						t = b1 + Quot;				}				else				{					if (Quot > 63)						t = b2 + ((Quot >> 1) & 0x1f);					else						t = b1 + (Quot >> 1);				}								Width = Right - Left;				// Left hand edge clipped tile				if (HPos & 7)				{					uint32 Offset = (HPos & 7);					Count = 8 - Offset;					if (Count > Width)						Count = Width;					s -= Offset * GFX.PixSize;					Tile = READ_2BYTES(t);					GFX.Z1 = GFX.Z2 = depths [(Tile & 0x2000) >> 13];										if (BG.TileSize == 8)					{						(*DrawClippedTilePtr) (Tile, s, Offset, Count, VirtAlign,							Lines);					}					else					{						if (!(Tile & (V_FLIP | H_FLIP)))						{							// Normal, unflipped							(*DrawClippedTilePtr) (Tile + t1 + (Quot & 1),								s, Offset, Count, VirtAlign, Lines);						}						else							if (Tile & H_FLIP)							{								if (Tile & V_FLIP)								{									// H & V flip									(*DrawClippedTilePtr) (Tile + t2 + 1 - (Quot & 1),										s, Offset, Count, VirtAlign, Lines);								}								else								{									// H flip only									(*DrawClippedTilePtr) (Tile + t1 + 1 - (Quot & 1),										s, Offset, Count, VirtAlign, Lines);								}							}							else							{								// V flip only								(*DrawClippedTilePtr) (Tile + t2 + (Quot & 1), s, 									Offset, Count, VirtAlign, Lines);							}					}										if (BG.TileSize == 8)					{						t++;						if (Quot == 31)							t = b2;						else if (Quot == 63)							t = b1;					}					else					{						t += Quot & 1;						if (Quot == 63)							t = b2;						else if (Quot == 127)							t = b1;					}					Quot++;					s += 8 * GFX.PixSize;				}								// Middle, unclipped tiles				Count = Width - Count;				int Middle = Count >> 3;				Count &= 7;				for (int C = Middle; C > 0; s += 8 * GFX.PixSize, Quot++, C--)				{					Tile = READ_2BYTES(t);					GFX.Z1 = GFX.Z2 = depths [(Tile & 0x2000) >> 13];										if (BG.TileSize != 8)					{						if (Tile & H_FLIP)						{							// Horizontal flip, but what about vertical flip ?							if (Tile & V_FLIP)							{								// Both horzontal & vertical flip								(*DrawTilePtr) (Tile + t2 + 1 - (Quot & 1), s, 									VirtAlign, Lines);							}							else							{								// Horizontal flip only								(*DrawTilePtr) (Tile + t1 + 1 - (Quot & 1), s, 									VirtAlign, Lines);							}						}						else						{							// No horizontal flip, but is there a vertical flip ?							if (Tile & V_FLIP)							{								// Vertical flip only								(*DrawTilePtr) (Tile + t2 + (Quot & 1), s,									VirtAlign, Lines);							}							else							{								// Normal unflipped								(*DrawTilePtr) (Tile + t1 + (Quot & 1), s,									VirtAlign, Lines);							}						}					}					else					{						(*DrawTilePtr) (Tile, s, VirtAlign, Lines);					}										if (BG.TileSize == 8)					{						t++;						if (Quot == 31)							t = b2;						else							if (Quot == 63)								t = b1;					}					else					{						t += Quot & 1;						if (Quot == 63)							t = b2;						else							if (Quot == 127)								t = b1;					}				}				// Right-hand edge clipped tiles				if (Count)				{					Tile = READ_2BYTES(t);					GFX.Z1 = GFX.Z2 = depths [(Tile & 0x2000) >> 13];										if (BG.TileSize == 8)						(*DrawClippedTilePtr) (Tile, s, 0, Count, VirtAlign, 						Lines);					else					{						if (!(Tile & (V_FLIP | H_FLIP)))						{							// Normal, unflipped							(*DrawClippedTilePtr) (Tile + t1 + (Quot & 1), s, 0, 								Count, VirtAlign, Lines);						}						else if (Tile & H_FLIP)						{							if (Tile & V_FLIP)							{								// H & V flip								(*DrawClippedTilePtr) (Tile + t2 + 1 - (Quot & 1),									s, 0, Count, VirtAlign, 									Lines);							}							else							{								// H flip only								(*DrawClippedTilePtr) (Tile + t1 + 1 - (Quot & 1),									s, 0, Count, VirtAlign,									Lines);							}						}						else						{							// V flip only							(*DrawClippedTilePtr) (Tile + t2 + (Quot & 1),								s, 0, Count, VirtAlign, 								Lines);						}					}				}		}    }}#define RENDER_BACKGROUND_MODE7(TYPE,FUNC) \    CHECK_SOUND(); \\    uint8 *VRAM1 = Memory.VRAM + 1; \    if (GFX.r2130 & 1) \    { \	if (IPPU.DirectColourMapsNeedRebuild) \	    S9xBuildDirectColourMaps (); \	GFX.ScreenColors = DirectColourMaps [0]; \    } \    else \	GFX.ScreenColors = IPPU.ScreenColors; \\    int aa, cc; \    int dir; \    int startx, endx; \    uint32 Left = 0; \    uint32 Right = 256; \    uint32 ClipCount = GFX.pCurrentClip->Count [bg]; \\    if (!ClipCount) \	ClipCount = 1; \\    Screen += GFX.StartY * GFX.Pitch; \    uint8 *Depth = GFX.DB + GFX.StartY * GFX.PPL; \    struct SLineMatrixData *l = &LineMatrixData [GFX.StartY]; \\    for (uint32 Line = GFX.StartY; Line <= GFX.EndY; Line++, Screen += GFX.Pitch, Depth += GFX.PPL, l++) \    { \	int yy; \\	int32 HOffset = ((int32) LineData [Line].BG[0].HOffset << M7) >> M7; \	int32 VOffset = ((int32) LineData [Line].BG[0].VOffset << M7) >> M7; \\	int32 CentreX = ((int32) l->CentreX << M7) >> M7; \	int32 CentreY = ((int32) l->CentreY << M7) >> M7; \\	if (PPU.Mode7VFlip) \	    yy = 255 - (int) Line; \	else \	    yy = Line; \\    yy += CLIP_10_BIT_SIGNED(VOffset - CentreY); \\  int BB = l->MatrixB * yy + (CentreX << 8); \	int DD = l->MatrixD * yy + (CentreY << 8); \\	for (uint32 clip = 0; clip < ClipCount; clip++) \	{ \	    if (GFX.pCurrentClip->Count [bg]) \	    { \		Left = GFX.pCurrentClip->Left [clip][bg]; \		Right = GFX.pCurrentClip->Right [clip][bg]; \		if (Right <= Left) \		    continue; \	    } \	    TYPE *p = (TYPE *) Screen + Left; \	    uint8 *d = Depth + Left; \\	    if (PPU.Mode7HFlip) \	    { \		startx = Right - 1; \		endx = Left - 1; \		dir = -1; \		aa = -l->MatrixA; \		cc = -l->MatrixC; \	    } \	    else \	    { \		startx = Left; \		endx = Right; \		dir = 1; \		aa = l->MatrixA; \		cc = l->MatrixC; \	    } \\	int xx = startx + CLIP_10_BIT_SIGNED(HOffset - CentreX); \	    int AA = l->MatrixA * xx; \	    int CC = l->MatrixC * xx; \\	    if (!PPU.Mode7Repeat) \	    { \		for (int x = startx; x != endx; x += dir, AA += aa, CC += cc, p++, d++) \		{ \		    int X = ((AA + BB) >> 8) & 0x3ff; \		    int Y = ((CC + DD) >> 8) & 0x3ff; \		    uint8 *TileData = VRAM1 + (Memory.VRAM[((Y & ~7) << 5) + ((X >> 2) & ~1)] << 7); \		    uint32 b = *(TileData + ((Y & 7) << 4) + ((X & 7) << 1)); \		    GFX.Z1 = Mode7Depths [(b & GFX.Mode7PriorityMask) >> 7]; \		    if (GFX.Z1 > *d && (b & GFX.Mode7Mask) ) \		    { \			*p = (FUNC); \			*d = GFX.Z1; \		    } \		} \	    } \	    else \	    { \		for (int x = startx; x != endx; x += dir, AA += aa, CC += cc, p++, d++) \		{ \		    int X = ((AA + BB) >> 8); \		    int Y = ((CC + DD) >> 8); \\		    if (((X | Y) & ~0x3ff) == 0) \		    { \			uint8 *TileData = VRAM1 + (Memory.VRAM[((Y & ~7) << 5) + ((X >> 2) & ~1)] << 7); \			uint32 b = *(TileData + ((Y & 7) << 4) + ((X & 7) << 1)); \			GFX.Z1 = Mode7Depths [(b & GFX.Mode7PriorityMask) >> 7]; \			if (GFX.Z1 > *d && (b & GFX.Mode7Mask) ) \			{ \			    *p = (FUNC); \			    *d = GFX.Z1; \			} \		    } \		    else \		    { \			if (PPU.Mode7Repeat == 3) \			{ \			    X = (x + HOffset) & 7; \			    Y = (yy + CentreY) & 7; \			    uint32 b = *(VRAM1 + ((Y & 7) << 4) + ((X & 7) << 1)); \			    GFX.Z1 = Mode7Depths [(b & GFX.Mode7PriorityMask) >> 7]; \			    if (GFX.Z1 > *d && (b & GFX.Mode7Mask) ) \			    { \				*p = (FUNC); \				*d = GFX.Z1; \			    } \			} \		    } \		} \	    } \	} \    }void DrawBGMode7Background (uint8 *Screen, int bg){    RENDER_BACKGROUND_MODE7 (uint8, (uint8) 

⌨️ 快捷键说明

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