void Viewport3D::ApplyRotationMatrix(const MR_2DCoordinate & pSrc, MR_2DCoordinate & pDest) const { MR_3DCoordinate lPos; lPos.mX = pSrc.mX - mPosition.mX; lPos.mY = pSrc.mY - mPosition.mY; pDest.mX = (MR_Int32) Int64ShraMod32(Int32x32To64(lPos.mX, mRotationMatrix[0][0]) + Int32x32To64(lPos.mY, mRotationMatrix[0][1]), MR_TRIGO_SHIFT); pDest.mY = (MR_Int32) Int64ShraMod32(Int32x32To64(lPos.mX, mRotationMatrix[1][0]) + Int32x32To64(lPos.mY, mRotationMatrix[1][1]), MR_TRIGO_SHIFT); }
int MulDiv64(int nNumber, __int64 nNumerator, __int64 nDenominator) { // ok, a complete implementation would handle negatives too, // but this method is probably not generally useful. while (nNumerator > INT32_MAX || nDenominator > INT32_MAX) { nNumerator = Int64ShraMod32(nNumerator, 1); nDenominator = Int64ShraMod32(nDenominator, 1); } return MulDiv(nNumber, (int)nNumerator, (int)nDenominator); }
void Viewport3D::ApplyPositionMatrix(const PositionMatrix & pMatrix, const MR_3DCoordinate & pSrc, MR_3DCoordinate & pDest) const { MR_2DCoordinate lPos; lPos.mX = (MR_Int32) Int64ShraMod32(Int32x32To64(pSrc.mX, pMatrix.mRotation[0][0]) + Int32x32To64(pSrc.mY, pMatrix.mRotation[0][1]), MR_TRIGO_SHIFT) + pMatrix.mDisplacement.mX; lPos.mY = (MR_Int32) Int64ShraMod32(Int32x32To64(pSrc.mX, pMatrix.mRotation[1][0]) + Int32x32To64(pSrc.mY, pMatrix.mRotation[1][1]), MR_TRIGO_SHIFT) + pMatrix.mDisplacement.mY; ApplyRotationMatrix(lPos, pDest); pDest.mZ = pSrc.mZ + pMatrix.mDisplacement.mZ - mPosition.mZ; }
void VSetPartitionDiskUsage_r(register struct DiskPartition64 *dp) { ULARGE_INTEGER free_user, total, free_total; int ufree, tot, tfree; if (!GetDiskFreeSpaceEx (VPartitionPath(dp), &free_user, &total, &free_total)) { printf("Failed to get disk space info for %s, error = %d\n", dp->name, GetLastError()); return; } /* Convert to 1K units. */ ufree = (int)Int64ShraMod32(free_user.QuadPart, 10); tot = (int)Int64ShraMod32(total.QuadPart, 10); tfree = (int)Int64ShraMod32(free_total.QuadPart, 10); dp->minFree = tfree - ufree; /* only used in VPrintDiskStats_r */ dp->totalUsable = tot; dp->free = tfree; }
static void GetLocalClockOffset(const struct NTP_Packet *pnp, HOSTTIME *phtofs, HOSTTIME *lpdelay) { HOSTTIME T1, T2, T3, T4; NTPTimeToHostTime(&pnp->originate_timestamp, &T1); NTPTimeToHostTime(&pnp->receive_timestamp, &T2); NTPTimeToHostTime(&pnp->transmit_timestamp, &T3); T4 = T1 + (m_dwTickCountOnRecv - m_dwTickCountOnSend) * HOSTTIME_TICK / 1000; *lpdelay = (T4 - T1) - (T3 - T2); *phtofs = Int64ShraMod32((T2 - T1) + (T3 - T4), 1); }
BOOL BuildDrivesReport( IN HWND hWnd, IN UINT iDetailLevel ) /*++ Routine Description: Formats and adds DrivesData to the report buffer. Arguments: hWnd - Main window handle iDetailLevel - summary or complete details? Return Value: BOOL - TRUE if report is build successfully, FALSE otherwise. --*/ { TCHAR LogicalDrives[ MAX_PATH ], OutputBuffer[MAX_PATH], szBuffer[MAX_PATH], szBuffer2[MAX_PATH]; LPTSTR Drive; DWORD Chars; BOOL Success; UINT OldErrorMode; DRIVE_INFO di; LARGE_INTEGER LargeInt; TCHAR szTotalBytes [ 64 ], szFreeBytes [ 64 ]; if(_fIsRemote){ return(TRUE); } AddLineToReport( 1, RFO_SKIPLINE, NULL, NULL ); AddLineToReport( 0, RFO_SINGLELINE, (LPTSTR) GetString( IDS_DRIVES_REPORT ), NULL ); AddLineToReport( 0, RFO_SEPARATOR, NULL, NULL ); // // Retrieve the logical drive strings from the system. // Chars = GetLogicalDriveStrings( sizeof( LogicalDrives ), LogicalDrives ); DbgAssert(( Chars != 0 ) && ( Chars <= sizeof( LogicalDrives ))); Drive = LogicalDrives; // // Disable pop-ups (especially if there is no media in the // removable drives.) // OldErrorMode = SetErrorMode( SEM_FAILCRITICALERRORS ); while( *Drive ) { TCHAR VolumeNameBuffer[512]; TCHAR FileSystemNameBuffer[512]; TCHAR DriveLetter[3]; TCHAR szKB[64]; DriveLetter[ 0 ] = Drive [ 0 ]; DriveLetter[ 1 ] = Drive [ 1 ]; DriveLetter[ 2 ] = TEXT( '\\'); ZeroMemory( &di, sizeof(DRIVE_INFO)); // // Skip floppies // if ((Drive[0] == 'A') || (Drive[0] == 'B')) { Drive += _tcslen( Drive ) + 1; continue; } // // GetDrive info // _tcsncpy( di.DriveLetter, Drive, 4 ); GetDriveInfo( &di ); // // Skip empty drives // if (di.Clusters == 0) { Drive += _tcslen( Drive ) + 1; continue; } // // skip unknown types // if (( di.DriveType < DRIVE_REMOVABLE) || ( di.DriveType > DRIVE_CDROM )){ Drive += _tcslen( Drive ) + 1; continue; } // // Display summary information // lstrcpy(szBuffer, GetString( IDS_DRV_BASE + di.DriveType ) ); lstrcpy(szBuffer2, GetString( IDS_TOTAL_MB ) ); // // Calculate the total and free bytes (Use LargeInteger routines for large drives ( > 4G ) // LargeInt.QuadPart = UInt32x32To64( di.FreeClusters, (di.SectorsPerCluster * di.BytesPerSector) ); LargeInt.QuadPart = Int64ShraMod32(LargeInt.QuadPart, 10); lstrcpy( szFreeBytes, FormatLargeInteger( &LargeInt, FALSE )); LargeInt.QuadPart = UInt32x32To64( di.Clusters, (di.SectorsPerCluster * di.BytesPerSector) ); LargeInt.QuadPart = Int64ShraMod32(LargeInt.QuadPart, 10); lstrcpy( szTotalBytes, FormatLargeInteger( &LargeInt, FALSE )); lstrcpy( szKB, GetString( IDS_KB ) ); if (di.DriveType == DRIVE_REMOTE) { wsprintf(OutputBuffer, L"%.2s (%s - %s) %s %s %s %s %s, %s %s %s", di.DriveLetter, szBuffer, di.FileSystemNameBuffer, di.RemoteNameBuffer, di.VolumeNameBuffer, szBuffer2, szTotalBytes, szKB, GetString( IDS_FREE_MB ), szFreeBytes, szKB); AddLineToReport(0,RFO_SINGLELINE,OutputBuffer,NULL); } else { wsprintf(OutputBuffer, L"%s (%s - %s) %s %s %s %s, %s %s %s", di.DriveLetter, szBuffer, di.FileSystemNameBuffer, di.VolumeNameBuffer, szBuffer2, szTotalBytes, szKB, GetString( IDS_FREE_MB ), szFreeBytes, szKB); AddLineToReport(0,RFO_SINGLELINE,OutputBuffer,NULL); } // // If we are making a detailed report, display additional info // if (iDetailLevel == IDC_COMPLETE_REPORT) { wsprintf( szBuffer, L"%X - %X", HIWORD( di.VolumeSerialNumber ), LOWORD( di.VolumeSerialNumber )); AddLineToReport( SINGLE_INDENT, RFO_RPTLINE, (LPTSTR) GetString( IDS_DRIVE_SERIAL_NUM ), szBuffer ); wsprintf(szBuffer, L"%d", di.BytesPerSector); AddLineToReport( SINGLE_INDENT, RFO_RPTLINE, (LPTSTR) GetString( IDS_BYTES_PER_CLUSTER ), szBuffer ); wsprintf(szBuffer, L"%d", di.SectorsPerCluster); AddLineToReport( SINGLE_INDENT, RFO_RPTLINE, (LPTSTR) GetString( IDS_SECTORS_PER_CLUSTER ), szBuffer ); wsprintf(szBuffer, L"%d", di.MaximumComponentLength); AddLineToReport( SINGLE_INDENT, RFO_RPTLINE, (LPTSTR) GetString( IDS_CHARS_IN_FILENAME ), szBuffer ); } // // Examine the next logical drive. // Drive += _tcslen( Drive ) + 1; } // // Restore error mode // SetErrorMode (OldErrorMode); return TRUE; }
/*********************************************** Open Opens data file for reading or writing PARAM: type - UTM_OM_READING, UTM_OM_WRITING or UTM_OM_APPEND RETURN: -1 if error ************************************************/ int CUT_MapFileDataSource::Open(OpenMsgType type) { // Save opening type m_OpenType = type; // If something is already opened - close it Close(); // Create/Open map file if((m_hFile = CreateFile(m_szFileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, (type == UTM_OM_READING) ? OPEN_EXISTING : OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) return -1; // If size is not set - try to get the file size if(m_lnSize.HighPart == 0 && m_lnSize.LowPart == 0) { m_lnSize.LowPart = GetFileSize(m_hFile, (ULONG *)&m_lnSize.HighPart); if(m_lnSize.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR) return -1; } // Initialize Actual Size if(type == UTM_OM_WRITING) { m_lnActualSize.HighPart = 0; m_lnActualSize.LowPart = 0; } else if(type == UTM_OM_APPEND) { m_lnActualSize.LowPart = GetFileSize(m_hFile, (ULONG *)&m_lnActualSize.HighPart); if(m_lnActualSize.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR) return -1; // Size can't be less then file size when adding if(m_lnActualSize.LowPart < m_lnSize.LowPart) m_lnSize.HighPart = m_lnActualSize.LowPart; if(m_lnActualSize.HighPart < m_lnSize.HighPart) m_lnSize.HighPart = m_lnActualSize.HighPart; } else m_lnActualSize.QuadPart = m_lnSize.QuadPart; // Initialize increment value. Size divided by 8 ( or shifted by 3) m_lnIncrement.QuadPart = max(Int64ShraMod32(m_lnSize.QuadPart, 3), 4096); // If file is opened in append mode - increase it size if(type == UTM_OM_APPEND || (type == UTM_OM_WRITING && m_lnSize.HighPart == 0 && m_lnSize.LowPart == 0 )) m_lnSize.QuadPart += m_lnIncrement.QuadPart; // Set file size if(SetFilePointer(m_hFile, m_lnSize.LowPart, (long *)&m_lnSize.HighPart, FILE_BEGIN ) == 0xFFFFFFFF && GetLastError() != NO_ERROR) return -1; if(!SetEndOfFile(m_hFile)) return -1; // Create file mapping if((m_hMapFile = CreateFileMapping(m_hFile, NULL, (type == UTM_OM_READING) ? PAGE_READONLY : PAGE_READWRITE, m_lnSize.HighPart, m_lnSize.LowPart, NULL)) == NULL || GetLastError() == ERROR_ALREADY_EXISTS) return -1; // Map view of file if((m_lpMapAddress = (LPSTR)MapViewOfFile(m_hMapFile, (type == UTM_OM_READING) ? FILE_MAP_READ : FILE_MAP_WRITE, 0, 0, 0)) == NULL) return -1; // Initialize position if(type == UTM_OM_APPEND) m_lnPosition.QuadPart = m_lnActualSize.QuadPart; else { m_lnPosition.HighPart = 0; m_lnPosition.LowPart = 0; } return UTE_SUCCESS; }