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

📄 printinstrtostring.cpp

📁 nes游戏模拟器
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	// Depending on the opcode of the instruction, different addressing
	// modes apply. This means that different strings must be printed
	// depending on the addressing mode.
	switch (byOpcode)
	{
		case 0x86:
			return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
		case 0x8E:
			return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
		case 0x96:
			return (1 + PrintAddrMode_ZeroPageY(strDest, strInstrName, wPC));
		default:
			return 0;
	}
} // end PrintSTX()


//------------------------------------------------------------------------------
// Name: PrintSTY()
// Desc: Prints the STY instruction to a string and returns the number
//       of bytes for the entire instruction.
//------------------------------------------------------------------------------
BYTE PrintSTY(LPSTR strDest, WORD wPC, BYTE byOpcode)
{
	LPSTR strInstrName = "STY"; // Name of the instruction being printed.

	// Depending on the opcode of the instruction, different addressing
	// modes apply. This means that different strings must be printed
	// depending on the addressing mode.
	switch (byOpcode)
	{
		case 0x84:
			return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
		case 0x8C:
			return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
		case 0x94:
			return (1 + PrintAddrMode_ZeroPageX(strDest, strInstrName, wPC));
		default:
			return 0;
	}
} // end PrintSTY()


//------------------------------------------------------------------------------
// Name: PrintTAX()
// Desc: Prints the TAX instruction to a string and returns the number
//       of bytes for the entire instruction.
//------------------------------------------------------------------------------
BYTE PrintTAX(LPSTR strDest, WORD wPC, BYTE byOpcode)
{
	LPSTR strInstrName = "TAX"; // Name of the instruction being printed.

	return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
} // end PrintTAX()


//------------------------------------------------------------------------------
// Name: PrintTAY()
// Desc: Prints the SEI instruction to a string and returns the number
//       of bytes for the entire instruction.
//------------------------------------------------------------------------------
BYTE PrintTAY(LPSTR strDest, WORD wPC, BYTE byOpcode)
{
	LPSTR strInstrName = "TAY"; // Name of the instruction being printed.

	return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
} // end PrintTAY()


//------------------------------------------------------------------------------
// Name: PrintTSX()
// Desc: Prints the TSX instruction to a string and returns the number
//       of bytes for the entire instruction.
//------------------------------------------------------------------------------
BYTE PrintTSX(LPSTR strDest, WORD wPC, BYTE byOpcode)
{
	LPSTR strInstrName = "TSX"; // Name of the instruction being printed.

	return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
} // end PrintTSX()


//------------------------------------------------------------------------------
// Name: PrintTXA()
// Desc: Prints the TXA instruction to a string and returns the number
//       of bytes for the entire instruction.
//------------------------------------------------------------------------------
BYTE PrintTXA(LPSTR strDest, WORD wPC, BYTE byOpcode)
{
	LPSTR strInstrName = "TXA"; // Name of the instruction being printed.

	return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
} // end PrintTXA()


//------------------------------------------------------------------------------
// Name: PrintTXS()
// Desc: Prints the TXS instruction to a string and returns the number
//       of bytes for the entire instruction.
//------------------------------------------------------------------------------
BYTE PrintTXS(LPSTR strDest, WORD wPC, BYTE byOpcode)
{
	LPSTR strInstrName = "TXS"; // Name of the instruction being printed.

	return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
} // end PrintTXS()


//------------------------------------------------------------------------------
// Name: PrintTYA()
// Desc: Prints the TYA instruction to a string and returns the number
//       of bytes for the entire instruction.
//------------------------------------------------------------------------------
BYTE PrintTYA(LPSTR strDest, WORD wPC, BYTE byOpcode)
{
	LPSTR strInstrName = "TYA"; // Name of the instruction being printed.

	return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
} // end PrintTYA()


//------------------------------------------------------------------------------
// Name: PrintUNDEF()
// Desc: Prints the UNDEF instruction to a string and returns the number
//       of bytes for the entire instruction.
//------------------------------------------------------------------------------
BYTE PrintUNDEF(LPSTR strDest, WORD wPC, BYTE byOpcode)
{
	LPSTR strInstrName = "???"; // Name of the instruction being printed.

	return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
} // end PrintUNDEF()

//------------------------------------------------------------------------------
// Name: PrintInstrToString()
// Desc: Gets the opcode of the instruction from memory and prints the
//       appropirate instruction to the string passed to the function.
//       This function returns the number of bytes the entire instruction
//       occupies. The string format is:
//       "PC\0MachineCode\0Instruction\0MemoryContents\0"
//
//       Each individual part can be accessed by their associated constants
//       in PrintInstreToString.h
//
//       This way the strings can be easily printed separately 
//       becuase of the null terminating characters.
//------------------------------------------------------------------------------
BYTE PrintInstrToString(LPSTR strInstr, WORD wPC)
{
	BYTE byOpcode = GetMemoryByte(wPC); // The opcode of our instruction.

	// Print the beginning of the string.
	// This is the same for every instruction.
	sprintf(strInstr, "%04X: %02X", wPC, byOpcode);
	strInstr[5] = '\0';

	// Whatever the instruction is, print it to the string.
	switch (byOpcode)
	{
		case 0x69: 
		case 0x65: 
		case 0x75: 
		case 0x6D: 
		case 0x7D: 
		case 0x79:
		case 0x61: 
		case 0x71:
			return PrintADC(&strInstr[8], wPC, byOpcode);

		case 0x21:
		case 0x25:
		case 0x29:
		case 0x2D:
		case 0x31:
		case 0x35:
		case 0x39:
		case 0x3D:
			return PrintAND(&strInstr[8], wPC, byOpcode);

		case 0x06:
		case 0x0A:
		case 0x0E:
		case 0x16:
		case 0x1E:
			return PrintASL(&strInstr[8], wPC, byOpcode);

		case 0x90:
			return PrintBCC(&strInstr[8], wPC, byOpcode);

		case 0xB0:
			return PrintBCS(&strInstr[8], wPC, byOpcode);

		case 0xF0:
			return PrintBEQ(&strInstr[8], wPC, byOpcode);

		case 0x24:
		case 0x2C:
			return PrintBIT(&strInstr[8], wPC, byOpcode);

		case 0x30:
			return PrintBMI(&strInstr[8], wPC, byOpcode);

		case 0xD0:
			return PrintBNE(&strInstr[8], wPC, byOpcode);

		case 0x10:
			return PrintBPL(&strInstr[8], wPC, byOpcode);

		case 0x00:
			return PrintBRK(&strInstr[8], wPC, byOpcode);

		case 0x50:
			return PrintBVC(&strInstr[8], wPC, byOpcode);

		case 0x70:
			return PrintBVS(&strInstr[8], wPC, byOpcode);

		case 0x18:
			return PrintCLC(&strInstr[8], wPC, byOpcode);

		case 0xD8:
			return PrintCLD(&strInstr[8], wPC, byOpcode);

		case 0x58:
			return PrintCLI(&strInstr[8], wPC, byOpcode);

		case 0xB8:
			return PrintCLV(&strInstr[8], wPC, byOpcode);

		case 0xC9:
		case 0xC5:
		case 0xD5:
		case 0xCD:
		case 0xDD:
		case 0xD9:
		case 0xC1:
		case 0xD1:
			return PrintCMP(&strInstr[8], wPC, byOpcode);

		case 0xE0:
		case 0xE4:
		case 0xEC:
			return PrintCPX(&strInstr[8], wPC, byOpcode);

		case 0xC0:
		case 0xC4:
		case 0xCC:
			return PrintCPY(&strInstr[8], wPC, byOpcode);

		case 0xC6:
		case 0xD6:
		case 0xCE:
		case 0xDE:
			return PrintDEC(&strInstr[8], wPC, byOpcode);

		case 0xCA:
			return PrintDEX(&strInstr[8], wPC, byOpcode);

		case 0x88:
			return PrintDEY(&strInstr[8], wPC, byOpcode);

		case 0x49:
		case 0x45:
		case 0x55:
		case 0x4D:
		case 0x5D:
		case 0x59:
		case 0x41:
		case 0x51:
			return PrintEOR(&strInstr[8], wPC, byOpcode);

		case 0xE6:
		case 0xF6:
		case 0xEE:
		case 0xFE:
			return PrintINC(&strInstr[8], wPC, byOpcode);

		case 0xE8:
			return PrintINX(&strInstr[8], wPC, byOpcode);

		case 0xC8:
			return PrintINY(&strInstr[8], wPC, byOpcode);

		case 0x4C:
		case 0x6C:
			return PrintJMP(&strInstr[8], wPC, byOpcode);

		case 0x20:
			return PrintJSR(&strInstr[8], wPC, byOpcode);

		case 0xA9:
		case 0xA5:
		case 0xB5:
		case 0xAD:
		case 0xBD:
		case 0xB9:
		case 0xA1:
		case 0xB1:
			return PrintLDA(&strInstr[8], wPC, byOpcode);

		case 0xA2:
		case 0xA6:
		case 0xB6:
		case 0xAE:
		case 0xBE:
			return PrintLDX(&strInstr[8], wPC, byOpcode);

		case 0xA0:
		case 0xA4:
		case 0xB4:
		case 0xAC:
		case 0xBC:
			return PrintLDY(&strInstr[8], wPC, byOpcode);

		case 0x4A:
		case 0x46:
		case 0x56:
		case 0x4E:
		case 0x5E:
			return PrintLSR(&strInstr[8], wPC, byOpcode);

		case 0xEA:
			return PrintNOP(&strInstr[8], wPC, byOpcode);

		case 0x09:
		case 0x05:
		case 0x15:
		case 0x0D:
		case 0x1D:
		case 0x19:
		case 0x01:
		case 0x11:
			return PrintORA(&strInstr[8], wPC, byOpcode);

		case 0x48:
			return PrintPHA(&strInstr[8], wPC, byOpcode);

		case 0x08:
			return PrintPHP(&strInstr[8], wPC, byOpcode);

		case 0x68:
			return PrintPLA(&strInstr[8], wPC, byOpcode);

		case 0x28:
			return PrintPLP(&strInstr[8], wPC, byOpcode);

		case 0x2A:
		case 0x26:
		case 0x36:
		case 0x2E:
		case 0x3E:
			return PrintROL(&strInstr[8], wPC, byOpcode);

		case 0x6A:
		case 0x66:
		case 0x76:
		case 0x6E:
		case 0x7E:
			return PrintROR(&strInstr[8], wPC, byOpcode);

		case 0x40:
			return PrintRTI(&strInstr[8], wPC, byOpcode);

		case 0x60:
			return PrintRTS(&strInstr[8], wPC, byOpcode);

		case 0xE9:
		case 0xE5:
		case 0xF5:
		case 0xED:
		case 0xFD:
		case 0xF9:
		case 0xE1:
		case 0xF1:
			return PrintSBC(&strInstr[8], wPC, byOpcode);

		case 0x38:
			return PrintSEC(&strInstr[8], wPC, byOpcode);

		case 0xF8:
			return PrintSED(&strInstr[8], wPC, byOpcode);

		case 0x78:
			return PrintSEI(&strInstr[8], wPC, byOpcode);

		case 0x85:
		case 0x95:
		case 0x8D:
		case 0x9D:
		case 0x99:
		case 0x81:
		case 0x91:
			return PrintSTA(&strInstr[8], wPC, byOpcode);

		case 0x86:
		case 0x96:
		case 0x8E:
			return PrintSTX(&strInstr[8], wPC, byOpcode);

		case 0x84:
		case 0x94:
		case 0x8C:
			return PrintSTY(&strInstr[8], wPC, byOpcode);

		case 0xAA:
			return PrintTAX(&strInstr[8], wPC, byOpcode);

		case 0xA8:
			return PrintTAY(&strInstr[8], wPC, byOpcode);

		case 0xBA:
			return PrintTSX(&strInstr[8], wPC, byOpcode);

		case 0x8A:
			return PrintTXA(&strInstr[8], wPC, byOpcode);

		case 0x9A:
			return PrintTXS(&strInstr[8], wPC, byOpcode);

		case 0x98:
			return PrintTYA(&strInstr[8], wPC, byOpcode);

		default:
			return PrintUNDEF(&strInstr[8], wPC, byOpcode);
	}
} // end PrintInstrToString()

⌨️ 快捷键说明

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