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

📄 nvrambuild.cpp

📁 The PCI Local bus concept was developed to break the PC data I/O bottleneck and clearly opens the d
💻 CPP
📖 第 1 页 / 共 3 页
字号:
}

BEGIN_EVENTSINK_MAP(CNVRAMBuild, CDialog)
    //{{AFX_EVENTSINK_MAP(CNVRAMBuild)
	ON_EVENT(CNVRAMBuild, IDC_GRID1, -601 /* DblClick */, OnDblClickGrid1, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CNVRAMBuild::OnDblClickGrid1() 
{
	// TODO: Add your control notification handler code here
	short col;
	short row;
	char sztemp[64];
	char sztemp2[32];
	CString zsString;
	char * szPtr;
	int i,j;

	if( 1 == 1 ) {
//	if( !grid_overhead_flag ) {
		col = m_GridControl.GetCol();
		row = m_GridControl.GetRow();

//		if( col == 1 || col == 0 ) {
//			if( row > pMain->Format_BreakDown_Count )
//				gbl_field_index = -1;
//			else
//				gbl_field_index = row;
//		}

//		if( row > 0 && row <= gbl_cur_row ) {
		if( row > 0 ) {
			if( col > 1 || col < num_cols - 1 ) {
//				m_GridControl.SetCol( 1 );
				zsString = m_GridControl.GetText();
				szPtr = zsString.GetBuffer( 64 );
				i = 0;
				while( szPtr[i] == ' ' )	// Remove leading blanks
					i++;
				j = 0;
				while( szPtr[i] != '=' && szPtr[i] != ',' && szPtr[i] != 0 ) {
					sztemp2[j] = szPtr[i];
					i++;
					j++;
				}
				sztemp2[j] = 0;

				m_Edit_DATA.SetWindowText( sztemp2 );

				i = ((row - 1) * num_cols) + (col - 1);

				switch( num_base ) {
				case 10:
					sprintf( sztemp, "%d", i );
					break;
				case 2:
				case 16:
				default:
					sprintf( sztemp, "%x", i );
					break;
				}
				m_Edit_ADDRESS.SetWindowText( sztemp );


			}	
			if( col == 2 || col == 0 ) {
				m_GridControl.SetCol( 2 );
				zsString = m_GridControl.GetText();
				szPtr = zsString.GetBuffer( 64 );
				i = 0;
				while( szPtr[i] == ' ' )	// Remove leading blanks
					i++;
//				strcpy( sztemp, &szPtr[i] );
//				m_Edit_CONSTANT.SetWindowText( sztemp );
			}
		}

		m_GridControl.SetRow( row );
		m_GridControl.SetCol( col );

		//gbl_cur_col = col;
		//gbl_cur_row = row;

	}		
	

}

void CNVRAMBuild::OnButtonZeroData() 
{
	// TODO: Add your control notification handler code here

	ZeroData();

	SetupDataGrid();
	DrawDataValues();

}

void CNVRAMBuild::OnButtonUpdateData() 
{
	// TODO: Add your control notification handler code here
	int addr,data;
	int tbase;

	m_Edit_ADDRESS.GetWindowText( (LPSTR) &sztemp2, sizeof( sztemp2 ) - 1 ); 

	m_Edit_DATA.GetWindowText( (LPSTR) &sztemp3, sizeof( sztemp3 ) - 1 ); 
	
	tbase = num_base;

	if( strlen( sztemp2 ) ) {
		switch( num_base ) {
		case 2:
			tbase = 16;
		case 16:
		case 10:
			addr = pMain->ConvertStringToNumber( tbase, (char *) &sztemp2 );
			break;
		default:
			return;
		}
		if( strlen( sztemp3 ) ) {
			switch( num_base ) {
			case 2:
			case 16:
			case 10:
				data = pMain->ConvertStringToNumber( num_base, (char *) &sztemp3 );
				break;
			default:
				return;
			}

			data_bytes[addr] = data;

			data_dirty = TRUE;

			SetupDataGrid();
			DrawDataValues();

		}
	}

}

void CNVRAMBuild::OnButtonWriteNvram() 
{
	// TODO: Add your control notification handler code here

	int i;

	DisableAll();

	for( i=0 ; i < num_data_bytes ; i++ ) {
		wdata_bytes[i] = data_bytes[i];
	}


	WriteData();
	ReadData();
	if( !CompareData() )	// Error flag == FALSE means good write
		data_dirty = FALSE;

	SetupDataGrid();
	DrawDataValues();

	EnableAll();
	
}

void CNVRAMBuild::OnButtonLoadFile() 
{
	// TODO: Add your control notification handler code here
	int i;

	offset_data_bytes = 0;

	m_Edit_CURRENT_FILE_NAME.GetWindowText( (char *)&sztemp, sizeof( sztemp ) );
	if( strlen( sztemp ) == 0 ) {
		OnButtonBrowse();
		return;
	}

	if( !m_Check_READ_MERGE.GetCheck() ) {
		i = m_Combo_NVRAM_TYPE.GetCurSel();
		num_data_bytes = NVRAM_Size[i];

		for( i=0 ; i < num_data_bytes ; i++ )
			data_bytes[i] = 0;
	}

	if( m_Check_READ_INTEL_HEX.GetCheck() ) {
		ReadIntelHexFile();
	}
	else {
		ReadFile();
	}

	SetupDataGrid();
	DrawDataValues();
	
}

void CNVRAMBuild::OnButtonWriteFile() 
{
	// TODO: Add your control notification handler code here

	m_Edit_CURRENT_FILE_NAME_WRITE.GetWindowText( (char *)&sztemp, sizeof( sztemp ) );
	if( strlen( sztemp ) == 0 ) {
		OnButtonBrowseWrite();
		return;
	}

	if( m_Check_WRITE_INTEL_HEX.GetCheck() ) {
		SaveIntelHexFile();
	}
	else {
		SaveFile();
	}
	
}

void CNVRAMBuild::OnButtonBrowseWrite() 
{
	// TODO: Add your control notification handler code here
	char FileName[1024];
	bool ret;

	pSaveRestore = NULL;

	pSaveRestore = new CSaveRestore;

	strcpy( pSaveRestore->szFileName, "" );

	if( m_Check_READ_INTEL_HEX.GetCheck() )
		ret = pSaveRestore->WIN_GetBrowseFileName( (char *)&FileName, 1, 1 );
	else
		ret = pSaveRestore->WIN_GetBrowseFileName( (char *)&FileName, 0, 1 );

	delete pSaveRestore;

	if( ret ) {
		m_Edit_CURRENT_FILE_NAME_WRITE.SetWindowText( (char *)&FileName );
		offset_data_bytes = 0;

		if( m_Check_WRITE_INTEL_HEX.GetCheck() ) {
			SaveIntelHexFile();
		}
		else {
			SaveFile();
		}

	}
	
}

void CNVRAMBuild::OnButtonWriteToNvram() 
{
	// TODO: Add your control notification handler code here
	UINT32 addr,data;
	UINT32 ret;
	int tbase;

	if( cur_board < 0 )
		return;

	m_Edit_ADDRESS.GetWindowText( (LPSTR) &sztemp2, sizeof( sztemp2 ) - 1 ); 

	m_Edit_DATA.GetWindowText( (LPSTR) &sztemp3, sizeof( sztemp3 ) - 1 ); 
	
	tbase = num_base;

	if( strlen( sztemp2 ) ) {
		switch( num_base ) {
		case 2:
			tbase = 16;
		case 16:
		case 10:
			addr = pMain->ConvertStringToNumber( tbase, (char *) &sztemp2 );
			break;
		default:
			return;
		}
		if( strlen( sztemp3 ) ) {
			switch( num_base ) {
			case 2:
			case 16:
			case 10:
				data = pMain->ConvertStringToNumber( num_base, (char *) &sztemp3 );
				break;
			default:
				return;
			}

			ret = Sample_WriteNVRAM( cur_board, (UINT32) addr, (UINT32 *)&data );
			TestError( ret );
		}
	}
	
}

void CNVRAMBuild::OnButtonReadFromNvram() 
{
	// TODO: Add your control notification handler code here
	UINT32 addr,data;
	UINT32 ret;
	int tbase;

	if( cur_board < 0 )
		return;

	m_Edit_ADDRESS.GetWindowText( (LPSTR) &sztemp2, sizeof( sztemp2 ) - 1 ); 
	
	tbase = num_base;

	if( strlen( sztemp2 ) ) {
		switch( num_base ) {
		case 2:
			tbase = 16;
		case 16:
		case 10:
			addr = pMain->ConvertStringToNumber( tbase, (char *) &sztemp2 );
			break;
		default:
			return;
		}

		ret = Sample_ReadNVRAM( cur_board, (UINT32) addr, (UINT32 *)&data );
		TestError( ret );
		if( ret == e_Err_NoError ) {
			switch( num_base ) {
			case 2:
			case 16:
			case 10:
				pMain->ConvertNumberToString( data, 0, num_base, (char *)sztemp3 );
				break;
			default:
				return;
			}
			m_Edit_DATA.SetWindowText( (LPSTR) &sztemp3 ); 
		}		
	}
	
}

void CNVRAMBuild::OnButtonChecksumGridData() 
{
	// TODO: Add your control notification handler code here
	UINT8 checksum;
	UINT16 count;
	char errstring[1024];

	if( (count=Get_Init_Size( (UINT8 *)&data_bytes, (UINT32) num_data_bytes, (char *)&errstring )) != 0 ) {
		// Clear the checkum location
		data_bytes[count-1] = 0;

		// Compute the checksum
		checksum = Checksum( (UINT8 *)&data_bytes, (UINT16) count );

		// store the checksum
		data_bytes[count-1] = 0 - checksum;

		data_dirty = TRUE;

		// Re-draw the grid data to show checksum
		SetupDataGrid();
		DrawDataValues();

	}
	else {
		strcpy( sztemp,"** Error ** - " );
		strcat( sztemp, errstring );
		MessageBox( sztemp,gheading,MB_OK );
	}

}

#define MAX_IMAGE_SIZE  (0x10000L / 512L)

UINT16 CNVRAMBuild::Get_Init_Size( UINT8 *buffer, UINT32 buffsize, char *errstring )
/*
	Check out validity of PCI header and data structures, and return
	the initialization code size.

	Entry:	buffer - pointer to rom image
			buffsize - #bytes in the image (actual image size)
			errstring - place to put errors (must have at least 128 chars avail)
	Return:	<> is the initialization code size.
			0 means error and errstring updated
*/
{
	UINT16 pci_data_structure, pci_image_length, init_size;

	if ( (buffer[0] != 0x55) || (buffer[1] != 0xAA) )
	{
		sprintf( errstring, "PCI Header must start with $55,AA\n(Locations 0x00,0x01).\n" );
		return 0;
	}

//	pci_data_structure = *(UINT16 *)(&buffer[0x18]);
	pci_data_structure = buffer[0x18] | (buffer[0x19] << 8);

	if ( pci_data_structure & 3 )
	{
		sprintf( errstring, "PCI Data Structure pointer must be DWORD-aligned\n(Location 0x18,0x19).\n" );
		return 0;
	}
	// Check for "PCIR" at the start of the PCI data structure...
	if ( (buffer[pci_data_structure] != 'P') ||
		 (buffer[pci_data_structure + 1] != 'C') ||
		 (buffer[pci_data_structure + 2] != 'I') ||
		 (buffer[pci_data_structure + 3] != 'R') )
	{
		sprintf( errstring, "PCI Data Structure does not start with \"PCIR\"\n(Location pointed to by 0x18,0x19 = %04x).\n",pci_data_structure );
		return 0;
	}

//	pci_image_length = *(UINT16 *)(&buffer[pci_data_structure + 0x10]);
	pci_image_length = buffer[pci_data_structure + 0x10] | (buffer[pci_data_structure + 0x11] << 8);

	if ( pci_image_length > MAX_IMAGE_SIZE )
	{
		sprintf( errstring, "Cannot handle >64k ROM Image Length (from PCI Data Structure)\n(Location pointed to by 0x18,0x19, plus 0x10 = %04x).\n",pci_image_length );
		return 0;
	}

	pci_image_length *= 512;

	// get init size...
	init_size = buffer[2];
	if ( init_size > MAX_IMAGE_SIZE )
	{
		sprintf( errstring, "Cannot handle >64k ROM (indicated by PCI Data Structure initialization code size)\n(Location 0x02).\n" );
		return 0;
	}

	init_size *= 512;

	if ( pci_image_length < init_size )
	{
		sprintf( errstring, "ROM Image Length (from PCI Data Structure) is smaller than\n" \
							"initialization code size (from ROM Header)\n(Location pointed to by 0x18,0x19, plus 0x10 = %04x, Init Size = %x).\n",pci_image_length, init_size );
		return 0;
	}

	if ( buffsize < init_size )
	{
		sprintf( errstring, "Input file size is smaller than initialization code size (from ROM Header)\n(Location 0x02 * 512 = %x, Buffer Size = %x).\n", init_size, buffsize );
		return 0;
	}

	if ( buffsize < pci_image_length )
	{
		sprintf( errstring, "Input file size is smaller ROM Image Length (from PCI Data Structure)\n(Location pointed to by 0x18,0x19, plus 0x10 = %04x, Buffer Size = %x).\n", pci_image_length, buffsize );
		return 0;
	}

	if ( init_size == 0 )
	{
		sprintf( errstring, "Code Initialization size (from ROM Header) is 0\n(Location 0x02 * 512 = %x).\n", init_size );
		return 0;
	}

	return init_size;
}

UINT8 CNVRAMBuild::Checksum(UINT8 *data, UINT16 len)
/*
	Return:	byte checksum of "len" bytes starting at "data"
*/
{
	UINT16 i;
	UINT8 ch = 0;

	for( i = 0; i < len; i++) 
		ch += data[i];
	return ch;
}

void CNVRAMBuild::OnButtonPciParameters() 
{
	// TODO: Add your control notification handler code here
	m_Button_PCI_PARAMETERS.EnableWindow(FALSE);

	// Create the dialog box
	pStdPCIParams = new CStdPCIParams;

	// Display the dialog box as modeless
	pStdPCIParams->Create(IDD_DIALOG_PCI_PARAMETERS, GetDesktopWindow() );

	// Initialize the newly-created object - this _must_ be done first!
	pStdPCIParams->Initialize(this, pMain, cur_board, (char *)&data_bytes );

	pStdPCIParams->ShowWindow(SW_SHOW);
	//MessageBox( "This function is not yet implemented!","", MB_OK | MB_ICONSTOP );	
	
}

BOOL CNVRAMBuild::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class

	// Note: This test stops the Enter key from killing the 
	// application. It causes nothing to happen. There must be a better way!
	if( pMsg->message == 256 && pMsg->wParam == 13 ) {
		return FALSE;
	}
	
	return CDialog::PreTranslateMessage(pMsg);
}

void CNVRAMBuild::OnButtonPlusOne() 
{
	// TODO: Add your control notification handler code here
	int i,base;
	
	base = 0;
	if( m_Check_ADDR_AS_BASE.GetCheck() ) {
		m_Edit_ADDRESS.GetWindowText( (LPSTR) &sztemp, sizeof( sztemp ) - 1 ); 
		base = pMain->ConvertStringToNumber( num_base, (char *) &sztemp );
	}
	
	for( i=MAX_DATA_BUFFER-1 ; i >= base ; i-- )
		data_bytes[i+1] = data_bytes[i];
	data_bytes[base] = 0xff;

	data_dirty = TRUE;

	SetupDataGrid();
	DrawDataValues();

}

void CNVRAMBuild::OnButtonMinusOne() 
{
	// TODO: Add your control notification handler code here
	int i,base;
	
	base = 0;
	if( m_Check_ADDR_AS_BASE.GetCheck() ) {
		m_Edit_ADDRESS.GetWindowText( (LPSTR) &sztemp, sizeof( sztemp ) - 1 ); 
		base = pMain->ConvertStringToNumber( num_base, (char *) &sztemp );
	}

	for( i=base ; i < MAX_DATA_BUFFER-1 ; i++ )
		data_bytes[i] = data_bytes[i+1];
	data_bytes[MAX_DATA_BUFFER] = 0xff;

	data_dirty = TRUE;

	SetupDataGrid();
	DrawDataValues();
	
}

⌨️ 快捷键说明

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