// ProgramFile.cpp: implementation of the CProgramFile class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "ProgramFile.h" #include "serialport.h" #include ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CProgramFile::CProgramFile() { } CProgramFile::~CProgramFile() { } bool CProgramFile::Send(CSerialPort& port) { bool bSuccess; m_pPort=&port; // // Kick off the send thread. This returns control to SendThread // on a different thread. // bSuccess=CTransferrableFile::StartSend(); return bSuccess; } bool CProgramFile::SetupRegisters() { bool bSuccess; TCHAR string[256]; CHAR asciiString[256]; // // set PC // _stprintf(string, TEXT("sr epc %08x\r"), m_PCValue); #ifdef _UNICODE int maxLength=256; // // convert line to unicode // ::WideCharToMultiByte(CP_ACP, 0, string, -1, asciiString, maxLength, NULL, NULL); #else strcpy(asciiString, string); #endif bSuccess=CTransferrableFile::WaitForString(*m_pPort, ">>"); if (!bSuccess) { return false; } bSuccess=CTransferrableFile::WriteString(*m_pPort, asciiString); if (!bSuccess) { return false; } // // Set GP // _stprintf(string, TEXT("sr gp %08x\r"), m_GPValue); #ifdef _UNICODE // // convert line to unicode // ::WideCharToMultiByte(CP_ACP, 0, string, -1, asciiString, maxLength, NULL, NULL); #else strcpy(asciiString, string); #endif bSuccess=CTransferrableFile::WaitForString(*m_pPort, ">>"); if (!bSuccess) { return false; } bSuccess=CTransferrableFile::WriteString(*m_pPort, asciiString); if (!bSuccess) { return false; } // // Set SP // _stprintf(string, TEXT("sr sp %08x\r"), m_SPValue); #ifdef _UNICODE // // convert line to unicode // ::WideCharToMultiByte(CP_ACP, 0, string, -1, asciiString, maxLength, NULL, NULL); #else strcpy(asciiString, string); #endif bSuccess=CTransferrableFile::WaitForString(*m_pPort, ">>"); if (!bSuccess) { return false; } bSuccess=CTransferrableFile::WriteString(*m_pPort, asciiString); if (!bSuccess) { return false; } bSuccess=CTransferrableFile::WaitForString(*m_pPort, ">>"); return bSuccess; } CProgramFile::programType CProgramFile::FindType(TCHAR* filename) { char buffer[8]; BOOL bReadSuccess; DWORD bytesRead; HANDLE hFile; hFile=::CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile==INVALID_HANDLE_VALUE) { // // error opening file // return fileNotFound; } bReadSuccess=::ReadFile(hFile, buffer, 8, &bytesRead, NULL); ::CloseHandle(hFile); if (!bReadSuccess) { return unknown; } if (strncmp(buffer, "PS-X EXE", 8)==0) { return psxExe; } if ((buffer[0]==(MIPSELMAGIC & 0xff)) && (buffer[1]==(MIPSELMAGIC >> 8))) { return aOutExe; } return unknown; }