Annotation of hatari/src/misc.c, revision 1.1.1.2

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.