|
|
1.1 ! root 1: /* ! 2: Hatari ! 3: ! 4: Misc functions ! 5: */ ! 6: ! 7: #include "main.h" ! 8: #include "debug.h" ! 9: #include "errlog.h" ! 10: #include "file.h" ! 11: #include "m68000.h" ! 12: #include "memAlloc.h" ! 13: #include "misc.h" ! 14: ! 15: long RandomNum; ! 16: ! 17: //----------------------------------------------------------------------- ! 18: /* ! 19: Fill end of string out with spaces ! 20: */ ! 21: void Misc_PadStringWithSpaces(char *pszString,int nChars) ! 22: { ! 23: int i; ! 24: ! 25: for(i=nChars; i>=(int)strlen(pszString); i--) { ! 26: pszString[i] = ' '; ! 27: } ! 28: pszString[nChars] = '\0'; ! 29: } ! 30: ! 31: //----------------------------------------------------------------------- ! 32: /* ! 33: Remove any spaces from string ! 34: */ ! 35: void Misc_RemoveSpacesFromString(char *pszSrcString, char *pszDestString) ! 36: { ! 37: int i=0,j=0; ! 38: ! 39: // Copy string ! 40: while(pszSrcString[i]!='\0') { ! 41: if (pszSrcString[i]!=' ') { // Copy character if not a white-space ! 42: pszDestString[j] = pszSrcString[i]; ! 43: j++; ! 44: } ! 45: i++; ! 46: } ! 47: ! 48: pszDestString[j] = '\0'; // Term ! 49: } ! 50: ! 51: //----------------------------------------------------------------------- ! 52: /* ! 53: Remove 'white-space' from beginning of text string ! 54: */ ! 55: void Misc_RemoveWhiteSpace(char *pszString,int Length) ! 56: { ! 57: while( (*pszString==' ') || (*pszString=='\t') ) { ! 58: // Copy line left one character ! 59: memmove(pszString,pszString+1,Length-1); ! 60: } ! 61: } ! 62: ! 63: //----------------------------------------------------------------------- ! 64: /* ! 65: Find working directory, and store to 'szWorkingDir' ! 66: */ ! 67: void Misc_FindWorkingDirectory(void) ! 68: { ! 69: /* FIXME!!!!*/ ! 70: /* ! 71: char szSrcDrive[_MAX_DRIVE],szSrcDir[_MAX_DIR],szSrcName[_MAX_FNAME],szSrcExt[_MAX_EXT]; ! 72: ! 73: // Find name of '.exe' ! 74: GetModuleFileName(NULL,szWorkingDir,MAX_FILENAME_LENGTH); ! 75: _splitpath(szWorkingDir,szSrcDrive,szSrcDir,szSrcName,szSrcExt); ! 76: _makepath(szWorkingDir,szSrcDrive,szSrcDir,"",""); ! 77: // And remove trailing backslash ! 78: if (strlen(szWorkingDir)>0) { ! 79: if (szWorkingDir[strlen(szWorkingDir)-1]=='/') ! 80: szWorkingDir[strlen(szWorkingDir)-1]='\0'; ! 81: } ! 82: */ ! 83: } ! 84: ! 85: //----------------------------------------------------------------------- ! 86: /* ! 87: Limit integer between min/max range ! 88: */ ! 89: int Misc_LimitInt(int Value, int MinRange, int MaxRange) ! 90: { ! 91: if (Value<MinRange) ! 92: Value = MinRange; ! 93: else if (Value>MaxRange) ! 94: Value = MaxRange; ! 95: ! 96: return(Value); ! 97: } ! 98: ! 99: //----------------------------------------------------------------------- ! 100: /* ! 101: Convert value to 2-digit BCD ! 102: */ ! 103: unsigned char Misc_ConvertToBCD(unsigned short int Value) ! 104: { ! 105: return( ((Value&0xf0)>>4)*10 + (Value&0x0f) ); ! 106: } ! 107: ! 108: //----------------------------------------------------------------------- ! 109: /* ! 110: See own random number(must be !=0) ! 111: */ ! 112: void Misc_SeedRandom(unsigned long Seed) ! 113: { ! 114: RandomNum = Seed; ! 115: } ! 116: ! 117: //----------------------------------------------------------------------- ! 118: /* ! 119: Get mext random number ! 120: */ ! 121: long Misc_NextLongRand(long Seed) ! 122: { ! 123: unsigned long Lo, Hi; ! 124: ! 125: Lo = 16807 * (long)(Seed & 0xffff); ! 126: Hi = 16807 * (long)((unsigned long)Seed >> 16); ! 127: Lo += (Hi & 0x7fff) << 16; ! 128: if (Lo > 2147483647L) { ! 129: Lo &= 2147483647L; ! 130: ++Lo; ! 131: } ! 132: Lo += Hi >> 15; ! 133: if (Lo > 2147483647L) { ! 134: Lo &= 2147483647L; ! 135: ++Lo; ! 136: } ! 137: return((long)Lo); ! 138: } ! 139: ! 140: //----------------------------------------------------------------------- ! 141: /* ! 142: Get own random number ! 143: */ ! 144: long Misc_GetRandom(void) ! 145: { ! 146: RandomNum = Misc_NextLongRand(RandomNum); ! 147: return(RandomNum); ! 148: } ! 149: ! 150: //----------------------------------------------------------------------- ! 151: /* ! 152: Convert Time/Date to DOS format ! 153: */ ! 154: /* ! 155: void Misc_TimeDataToDos(FILETIME *pFileTime, WORD *pFatDate, WORD *pFatTime) ! 156: { ! 157: // Convert FILETIME to DOS format(same as GemDOS format) ! 158: if (FileTimeToDosDateTime(pFileTime,pFatDate,pFatTime)) ! 159: return; ! 160: ! 161: // Ooops, date/time outside range so just NULL ! 162: *pFatDate = *pFatTime = 0; ! 163: } ! 164: */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.