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

📄 seta010.cpp

📁 SFC游戏模拟器 snes9x 1.43 的原代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				int Pos, Offset;				Offset = 0;				for (Pos = 0; Pos < Positions; Pos++) 				{					Places[Pos] = ST010_WORD(0x0040 + Offset);					Offset += 2;				}				ST010_SortDrivers(Positions, Places, (uint16*) (SRAM + 0x0080));				Offset = 0;				for (Pos = 0; Pos < Positions; Pos++)				{					SRAM[0x0040 + Offset]=(uint8)(Places[Pos]);					SRAM[0x0041 + Offset]=(uint8)(Places[Pos] >> 8);					Offset += 2;				}#endif							break;							}		// Two Dimensional Coordinate Scale		//		// Input		//   0x0000-0x0001 : X0 (signed)		//   0x0002-0x0003 : Y0 (signed)		//   0x0004-0x0005 : Multiplier (signed)		// Output		//   0x0010-0x0013 : X1 (signed)		//   0x0014-0x0017 : Y1 (signed)		//		case 0x03:			{#ifdef FAST_LSB_WORD_ACCESS				ST010_Scale(*(short*)&Memory.SRAM[0x0004], *(short*)&Memory.SRAM[0x0000], *(short*)&Memory.SRAM[0x0002],					(int&) Memory.SRAM[0x0010], (int&) Memory.SRAM[0x0014]);#else				int x1, y1;				ST010_Scale(ST010_WORD(0x0004), ST010_WORD(0x0000), ST010_WORD(0x0002), x1, y1);				Memory.SRAM[0x0010]=(uint8)(x1);				Memory.SRAM[0x0011]=(uint8)(x1 >> 8);				Memory.SRAM[0x0012]=(uint8)(x1 >> 16);				Memory.SRAM[0x0013]=(uint8)(x1 >> 24);				Memory.SRAM[0x0014]=(uint8)(y1);				Memory.SRAM[0x0015]=(uint8)(y1 >> 8);				Memory.SRAM[0x0016]=(uint8)(y1 >> 16);				Memory.SRAM[0x0017]=(uint8)(y1 >> 24);#endif				break;			}		// 16-bit Multiplication		//		// Input		//   0x0000-0x0001 : Multiplcand (signed)		//   0x0002-0x0003 : Multiplier (signed)		// Output		//   0x0010-0x0013 : Product (signed)		//		case 0x06:			{#ifdef FAST_LSB_WORD_ACCESS				ST010_Multiply(*(short*)&Memory.SRAM[0x0000], *(short*)&Memory.SRAM[0x0002], (int&) Memory.SRAM[0x0010]);#else				int Product;				ST010_Multiply(ST010_WORD(0x0000), ST010_WORD(0x0002), Product);				Memory.SRAM[0x0010]=(uint8)(Product);				Memory.SRAM[0x0011]=(uint8)(Product >> 8);				Memory.SRAM[0x0012]=(uint8)(Product >> 16);				Memory.SRAM[0x0013]=(uint8)(Product >> 24);#endif				break;			}		// Mode 7 Raster Data Calculation		//		// Input		//   0x0000-0x0001 : Angle (signed)		// Output		//   0x00f0-0x024f : Mode 7 Matrix A		//   0x0250-0x03af : Mode 7 Matrix B		//   0x03b0-0x050f : Mode 7 Matrix C		//   0x0510-0x066f : Mode 7 Matrix D		//		case 0x07:			{				int16 data;				int32 offset = 0;				int16 Theta = ST010_WORD(0x0000);				for (int32 line = 0; line < 176; line++)				{					// Calculate Mode 7 Matrix A/D data					data = ST010_M7Scale[line] * ST010_Cos(Theta) >> 15;									Memory.SRAM[0x00f0 + offset]=(uint8)(data);					Memory.SRAM[0x00f1 + offset]=(uint8)(data >> 8);					Memory.SRAM[0x0510 + offset]=(uint8)(data);					Memory.SRAM[0x0511 + offset]=(uint8)(data >> 8); 					// Calculate Mode 7 Matrix B/C data					data = ST010_M7Scale[line] * ST010_Sin(Theta) >> 15;  					Memory.SRAM[0x0250 + offset]=(uint8)(data);					Memory.SRAM[0x0251 + offset]=(uint8)(data >> 8);							if (data) data = ~data;				 					Memory.SRAM[0x03b0 + offset]=(uint8)(data);					Memory.SRAM[0x03b1 + offset]=(uint8)(data >> 8);							offset += 2;				}				// Shift Angle for use with Lookup table				Memory.SRAM[0x00] = Memory.SRAM[0x01];				Memory.SRAM[0x01] = 0x00;				break;			}		// Two dimensional Coordinate Rotation		//		// Input		//   0x0000-0x0001 : X0 (signed)		//   0x0002-0x0003 : Y0 (signed)		//   0x0004-0x0005 : Angle (signed)		// Output		//   0x0010-0x0011 : X1 (signed)		//   0x0012-0x0013 : Y1 (signed)		//		case 0x08:			{#ifdef FAST_LSB_WORD_ACCESS				ST010_Rotate(*(short*)&Memory.SRAM[0x0004], *(short*)&Memory.SRAM[0x0000], *(short*)&Memory.SRAM[0x0002],					(short&) Memory.SRAM[0x0010], (short&) Memory.SRAM[0x0012]);#else				short x1, y1;				ST010_Rotate(ST010_WORD(0x0004), ST010_WORD(0x0000), ST010_WORD(0x0002), x1, y1);				Memory.SRAM[0x0010]=(uint8)(x1);				Memory.SRAM[0x0011]=(uint8)(x1 >> 8);				Memory.SRAM[0x0012]=(uint8)(y1);				Memory.SRAM[0x0013]=(uint8)(y1 >> 8);#endif				break;			}		// Input		//   0x0000-0x0001 : DX (signed)		//   0x0002-0x0003 : DY (signed)		// Output		//   0x0010-0x0011 : Angle (signed)		//		case 0x01:			{				Memory.SRAM[0x0006] = Memory.SRAM[0x0002];				Memory.SRAM[0x0007] = Memory.SRAM[0x0003];#ifdef FAST_LSB_WORD_ACCESS				ST010_OP01(*(short*)&Memory.SRAM[0x0000], *(short*)&Memory.SRAM[0x0002],					(short&) Memory.SRAM[0x0000], (short&) Memory.SRAM[0x0002],					(short&) Memory.SRAM[0x0004], (short&) Memory.SRAM[0x0010]);#else				short x1, y1, Quadrant, Theta;				ST010_OP01(ST010_WORD(0x0000), ST010_WORD(0x0002), x1, y1, Quadrant, Theta);				Memory.SRAM[0x0000]=(uint8)(x1);				Memory.SRAM[0x0001]=(uint8)(x1 >> 8);				Memory.SRAM[0x0002]=(uint8)(y1);				Memory.SRAM[0x0003]=(uint8)(y1 >> 8);				Memory.SRAM[0x0004]=(uint8)(Quadrant);				Memory.SRAM[0x0005]=(uint8)(Quadrant >> 8);				Memory.SRAM[0x0010]=(uint8)(Theta);				Memory.SRAM[0x0011]=(uint8)(Theta >> 8);#endif				break;		}		// calculate the vector length of (x,y)		case 0x04:			{				int16 square, x,y;#ifdef FAST_LSB_WORD_ACCESS				x=*((int16*)Memory.SRAM);				y=*((int16*)&Memory.SRAM[2]);#else				x=Memory.SRAM[0]|(Memory.SRAM[1]<<8);				y=Memory.SRAM[2]|(Memory.SRAM[3]<<8);#endif				square=(int16)sqrt((double)(y*y+x*x));				//SETA_Distance( x,y,square );#ifdef FAST_LSB_WORD_ACCESS				*((int16*)&Memory.SRAM[0x10])=square;#else				Memory.SRAM[0x10]=(uint8)(square);				Memory.SRAM[0x11]=(uint8)(square>>8);#endif				break;			}		// calculate AI orientation based on specific guidelines		case 0x05:			{				int dx,dy;				int16 a1,b1,c1;				uint16 o1;				bool wrap=false;				// target (x,y) coordinates				int16 ypos_max = ST010_WORD(0x00C0);				int16 xpos_max = ST010_WORD(0x00C2);				// current coordinates and direction				int32 ypos = SRAM[0xC4]|(SRAM[0xC5]<<8)|(SRAM[0xC6]<<16)|(SRAM[0xC7]<<24);				int32 xpos = SRAM[0xC8]|(SRAM[0xC9]<<8)|(SRAM[0xCA]<<16)|(SRAM[0xCB]<<24);				uint16 rot = SRAM[0xCC]|(SRAM[0xCD]<<8);				// physics				uint16 speed = ST010_WORD(0x00D4);				uint16 accel = ST010_WORD(0x00D6);				uint16 speed_max = ST010_WORD(0x00D8);				// special condition acknowledgment				int16 system = ST010_WORD(0x00DA);				int16 flags = ST010_WORD(0x00DC);				// new target coordinates				int16 ypos_new = ST010_WORD(0x00DE);				int16 xpos_new = ST010_WORD(0x00E0);				// mask upper bit				xpos_new &= 0x7FFF;				// get the current distance				dx = xpos_max-(xpos>>16);				dy = ypos_max-(ypos>>16);				// quirk: clear and move in9				SRAM[0xD2]=0xFF;				SRAM[0xD3]=0xFF;				SRAM[0xDA]=0;				SRAM[0xDB]=0;				// grab the target angle				ST010_OP01(dy,dx,a1,b1,c1,(int16 &)o1);				// check for wrapping				//if((o1<0x6000 && rot>0xA000) ||					// (rot<0x6000 && o1>0xA000))				//if(o1<rot)				if(abs(o1-rot)>0x8000)				{					o1+=0x8000;					rot+=0x8000;					wrap=true;				}				//o1=0x0000;				//rot=0xFF00;				uint16 old_speed;				old_speed = speed;				// special case				if(abs(o1-rot)==0x8000)				{					speed = 0x100;				}				// slow down for sharp curves				else if(abs(o1-rot)>=0x1000)				{					uint32 slow = abs(o1-rot);					slow >>= 4;	// scaling					speed -= slow;				}				// otherwise accelerate				else				{					speed += accel;					if(speed > speed_max)					{						// clip speed						speed = speed_max;					}				}				// prevent negative/positive overflow				if(abs(old_speed-speed)>0x8000) {					if(old_speed<speed) speed=0;					else speed=0xff00;				}				// adjust direction by so many degrees				// be careful of negative adjustments				if( (o1>rot && (o1-rot)>0x80) ||						(o1<rot && (rot-o1)>=0x80) )				{					if(o1<rot) rot-=0x280;					else if(o1>rot) rot+=0x280;				}				// turn off wrapping				if(wrap) rot-=0x8000;				// now check the distances (store for later)				dx = (xpos_max<<16)-xpos;				dy = (ypos_max<<16)-ypos;				dx>>=16;				dy>>=16;				// if we're in so many units of the target, signal it				if( ( system && (dy<=6 && dy>=-8) && (dx<=126 && dx>=-128)) ||						(!system && (dx<=6 && dx>=-8) && (dy<=126 && dy>=-128)) )				{					// announce our new destination and flag it					xpos_max = xpos_new&0x7FFF;					ypos_max = ypos_new;					flags |= 0x08;				}				// update position				xpos -= (ST010_Cos(rot) * 0x400 >> 15) * (speed >> 8) << 1;				ypos -= (ST010_Sin(rot) * 0x400 >> 15) * (speed >> 8) << 1;				// quirk: mask upper byte				xpos &= 0x1FFFFFFF;				ypos &= 0x1FFFFFFF;				SRAM[0x00C0]=(uint8)(ypos_max);				SRAM[0x00C1]=(uint8)(ypos_max >> 8);				SRAM[0x00C2]=(uint8)(xpos_max);				SRAM[0x00C3]=(uint8)(xpos_max >> 8);				SRAM[0x00C4]=(uint8)(ypos);				SRAM[0x00C5]=(uint8)(ypos >> 8);				SRAM[0x00C6]=(uint8)(ypos >> 16);				SRAM[0x00C7]=(uint8)(ypos >> 24);				SRAM[0x00C8]=(uint8)(xpos);				SRAM[0x00C9]=(uint8)(xpos >> 8);				SRAM[0x00CA]=(uint8)(xpos >> 16);				SRAM[0x00CB]=(uint8)(xpos >> 24);				SRAM[0x00CC]=(uint8)(rot);				SRAM[0x00CD]=(uint8)(rot >> 8);				SRAM[0x00D4]=(uint8)(speed);				SRAM[0x00D5]=(uint8)(speed >> 8);				SRAM[0x00DC]=(uint8)(flags);				SRAM[0x00DD]=(uint8)(flags >> 8);				break;			}		default:			printf("Unknown Op\n");			break;		}		// lower signal: op processed		ST010.op_reg=0;		ST010.execute=0;	}}

⌨️ 快捷键说明

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