|
|
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'
1.1.1.3 ! root 70: Note: I'm not sure if this function is still usefull in Hatari - Thothy
1.1 root 71: */
1.1.1.3 ! root 72: void Misc_FindWorkingDirectory(char *prgname)
1.1 root 73: {
1.1.1.3 ! root 74: char szSrcDir[256], szSrcName[128], szSrcExt[32];
1.1 root 75:
1.1.1.3 ! root 76: /* Find name of program */
! 77: strncpy(szWorkingDir, prgname, MAX_FILENAME_LENGTH);
! 78: File_splitpath(szWorkingDir, szSrcDir, szSrcName, szSrcExt);
! 79: File_makepath(szWorkingDir, szSrcDir, "", "");
! 80: /* And remove trailing backslash */
1.1 root 81: if (strlen(szWorkingDir)>0) {
82: if (szWorkingDir[strlen(szWorkingDir)-1]=='/')
83: szWorkingDir[strlen(szWorkingDir)-1]='\0';
84: }
1.1.1.3 ! root 85:
1.1 root 86: }
87:
1.1.1.2 root 88:
89: /*-----------------------------------------------------------------------*/
1.1 root 90: /*
91: Limit integer between min/max range
92: */
93: int Misc_LimitInt(int Value, int MinRange, int MaxRange)
94: {
95: if (Value<MinRange)
96: Value = MinRange;
97: else if (Value>MaxRange)
98: Value = MaxRange;
99:
100: return(Value);
101: }
102:
1.1.1.2 root 103:
104: /*-----------------------------------------------------------------------*/
1.1 root 105: /*
106: Convert value to 2-digit BCD
107: */
108: unsigned char Misc_ConvertToBCD(unsigned short int Value)
109: {
110: return( ((Value&0xf0)>>4)*10 + (Value&0x0f) );
111: }
112:
1.1.1.2 root 113:
114: /*-----------------------------------------------------------------------*/
1.1 root 115: /*
116: See own random number(must be !=0)
117: */
118: void Misc_SeedRandom(unsigned long Seed)
119: {
120: RandomNum = Seed;
121: }
122:
1.1.1.2 root 123:
124: /*-----------------------------------------------------------------------*/
1.1 root 125: /*
126: Get mext random number
127: */
128: long Misc_NextLongRand(long Seed)
129: {
130: unsigned long Lo, Hi;
131:
132: Lo = 16807 * (long)(Seed & 0xffff);
133: Hi = 16807 * (long)((unsigned long)Seed >> 16);
134: Lo += (Hi & 0x7fff) << 16;
135: if (Lo > 2147483647L) {
136: Lo &= 2147483647L;
137: ++Lo;
138: }
139: Lo += Hi >> 15;
140: if (Lo > 2147483647L) {
141: Lo &= 2147483647L;
142: ++Lo;
143: }
144: return((long)Lo);
145: }
146:
1.1.1.2 root 147:
148: /*-----------------------------------------------------------------------*/
1.1 root 149: /*
150: Get own random number
151: */
152: long Misc_GetRandom(void)
153: {
154: RandomNum = Misc_NextLongRand(RandomNum);
155: return(RandomNum);
156: }
157:
1.1.1.2 root 158:
159: /*-----------------------------------------------------------------------*/
1.1 root 160: /*
161: Convert Time/Date to DOS format
162: */
163: /*
164: void Misc_TimeDataToDos(FILETIME *pFileTime, WORD *pFatDate, WORD *pFatTime)
165: {
166: // Convert FILETIME to DOS format(same as GemDOS format)
167: if (FileTimeToDosDateTime(pFileTime,pFatDate,pFatTime))
168: return;
169:
170: // Ooops, date/time outside range so just NULL
171: *pFatDate = *pFatTime = 0;
172: }
173: */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.