Annotation of frontvm/hardware/misc.c, revision 1.1

1.1     ! root        1: /*
        !             2:   Hatari - misc.c
        !             3: 
        !             4:   This file is distributed under the GNU Public License, version 2 or at
        !             5:   your option any later version. Read the file gpl.txt for details.
        !             6: 
        !             7:   Misc functions
        !             8: */
        !             9: 
        !            10: #include <ctype.h>
        !            11: 
        !            12: #include "main.h"
        !            13: #include "file.h"
        !            14: #include "memAlloc.h"
        !            15: #include "misc.h"
        !            16: 
        !            17: long RandomNum;
        !            18: 
        !            19: 
        !            20: /*-----------------------------------------------------------------------*/
        !            21: /*
        !            22:   Fill end of string out with spaces
        !            23: */
        !            24: void Misc_PadStringWithSpaces(char *pszString,int nChars)
        !            25: {
        !            26:   int i;
        !            27: 
        !            28:   for(i=nChars; i>=(int)strlen(pszString); i--) {
        !            29:     pszString[i] = ' ';
        !            30:   }
        !            31:   pszString[nChars] = '\0';
        !            32: }
        !            33: 
        !            34: 
        !            35: /*-----------------------------------------------------------------------*/
        !            36: /*
        !            37:   Remove any spaces from string
        !            38: */
        !            39: void Misc_RemoveSpacesFromString(char *pszSrcString, char *pszDestString)
        !            40: {
        !            41:   int i=0,j=0;
        !            42: 
        !            43:   /* Copy string */
        !            44:   while(pszSrcString[i]!='\0') {
        !            45:     if (pszSrcString[i]!=' ') {  /* Copy character if not a white-space */
        !            46:       pszDestString[j] = pszSrcString[i];
        !            47:       j++;
        !            48:     }
        !            49:     i++;
        !            50:   }
        !            51: 
        !            52:   pszDestString[j] = '\0';      /* Term */
        !            53: }
        !            54: 
        !            55: 
        !            56: /*-----------------------------------------------------------------------*/
        !            57: /*
        !            58:   Remove 'white-space' from beginning of text string
        !            59: */
        !            60: void Misc_RemoveWhiteSpace(char *pszString,int Length)
        !            61: {
        !            62:   while( (*pszString==' ') || (*pszString=='\t') ) {
        !            63:     /* Copy line left one character */
        !            64:     memmove(pszString,pszString+1,Length-1);
        !            65:   }
        !            66: }
        !            67: 
        !            68: 
        !            69: /*-----------------------------------------------------------------------*/
        !            70: /*
        !            71:    Convert a string to uppercase.
        !            72: */
        !            73: void Misc_strupr(char *pString)
        !            74: {
        !            75:   while(*pString)
        !            76:   {
        !            77:     *pString = toupper(*pString);
        !            78:     pString++;
        !            79:   }
        !            80: }
        !            81: 
        !            82: 
        !            83: /*-----------------------------------------------------------------------*/
        !            84: /*
        !            85:   Find working directory, and store to 'szWorkingDir'
        !            86:   Note: I'm not sure if this function is still usefull in Hatari - Thothy
        !            87: */
        !            88: void Misc_FindWorkingDirectory(char *prgname)
        !            89: {
        !            90:   char szSrcDir[256], szSrcName[128], szSrcExt[32];
        !            91: 
        !            92:   /* Find name of program */
        !            93:   strncpy(szWorkingDir, prgname, MAX_FILENAME_LENGTH);
        !            94:   File_splitpath(szWorkingDir, szSrcDir, szSrcName, szSrcExt);
        !            95:   File_makepath(szWorkingDir, szSrcDir, "", "");
        !            96:   /* And remove trailing backslash */
        !            97:   if (strlen(szWorkingDir)>0) {
        !            98:     if (szWorkingDir[strlen(szWorkingDir)-1]=='/')
        !            99:       szWorkingDir[strlen(szWorkingDir)-1]='\0';
        !           100:   }
        !           101: 
        !           102: }
        !           103: 
        !           104: 
        !           105: /*-----------------------------------------------------------------------*/
        !           106: /*
        !           107:   Limit integer between min/max range
        !           108: */
        !           109: int Misc_LimitInt(int Value, int MinRange, int MaxRange)
        !           110: {
        !           111:   if (Value<MinRange)
        !           112:     Value = MinRange;
        !           113:   else if (Value>MaxRange)
        !           114:     Value = MaxRange;
        !           115: 
        !           116:   return(Value);
        !           117: }
        !           118: 
        !           119: 
        !           120: /*-----------------------------------------------------------------------*/
        !           121: /*
        !           122:   Convert value to 2-digit BCD
        !           123: */
        !           124: unsigned char Misc_ConvertToBCD(unsigned short int Value)
        !           125: {
        !           126:   return (((Value/10))<<4) | (Value%10);
        !           127: }
        !           128: 
        !           129: 
        !           130: /*-----------------------------------------------------------------------*/
        !           131: /*
        !           132:   See own random number(must be !=0)
        !           133: */
        !           134: void Misc_SeedRandom(unsigned long Seed)
        !           135: {
        !           136:   RandomNum = Seed;
        !           137: }
        !           138: 
        !           139: 
        !           140: /*-----------------------------------------------------------------------*/
        !           141: /*
        !           142:   Get mext random number
        !           143: */
        !           144: long Misc_NextLongRand(long Seed)
        !           145: {
        !           146:   unsigned long Lo, Hi;
        !           147: 
        !           148:   Lo = 16807 * (long)(Seed & 0xffff);
        !           149:   Hi = 16807 * (long)((unsigned long)Seed >> 16);
        !           150:   Lo += (Hi & 0x7fff) << 16;
        !           151:   if (Lo > 2147483647L) {
        !           152:     Lo &= 2147483647L;
        !           153:     ++Lo;
        !           154:   }
        !           155:   Lo += Hi >> 15;
        !           156:   if (Lo > 2147483647L) {
        !           157:     Lo &= 2147483647L;
        !           158:     ++Lo;
        !           159:   }
        !           160:   return((long)Lo);
        !           161: }
        !           162: 
        !           163: 
        !           164: /*-----------------------------------------------------------------------*/
        !           165: /*
        !           166:   Get own random number
        !           167: */
        !           168: long Misc_GetRandom(void)
        !           169: {
        !           170:   RandomNum = Misc_NextLongRand(RandomNum);
        !           171:   return(RandomNum);
        !           172: }
        !           173: 

unix.superglobalmegacorp.com

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