|
|
1.1 root 1: /*
1.1.1.4 root 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.
1.1 root 6:
7: Misc functions
8: */
1.1.1.7 ! root 9: const char Misc_rcsid[] = "Hatari $Id: misc.c,v 1.12 2006/02/12 21:35:17 eerot Exp $";
1.1.1.4 root 10:
11: #include <ctype.h>
1.1 root 12:
13: #include "main.h"
14: #include "misc.h"
15:
1.1.1.5 root 16:
17: static long RandomNum;
1.1 root 18:
1.1.1.2 root 19:
20: /*-----------------------------------------------------------------------*/
1.1 root 21: /*
22: Remove 'white-space' from beginning of text string
23: */
24: void Misc_RemoveWhiteSpace(char *pszString,int Length)
25: {
26: while( (*pszString==' ') || (*pszString=='\t') ) {
1.1.1.2 root 27: /* Copy line left one character */
1.1 root 28: memmove(pszString,pszString+1,Length-1);
29: }
30: }
31:
1.1.1.2 root 32:
33: /*-----------------------------------------------------------------------*/
1.1 root 34: /*
1.1.1.4 root 35: Convert a string to uppercase.
36: */
37: void Misc_strupr(char *pString)
38: {
39: while(*pString)
40: {
41: *pString = toupper(*pString);
42: pString++;
43: }
44: }
45:
46:
47: /*-----------------------------------------------------------------------*/
48: /*
1.1 root 49: Limit integer between min/max range
50: */
51: int Misc_LimitInt(int Value, int MinRange, int MaxRange)
52: {
53: if (Value<MinRange)
54: Value = MinRange;
55: else if (Value>MaxRange)
56: Value = MaxRange;
57:
58: return(Value);
59: }
60:
1.1.1.2 root 61:
62: /*-----------------------------------------------------------------------*/
1.1 root 63: /*
64: Convert value to 2-digit BCD
65: */
66: unsigned char Misc_ConvertToBCD(unsigned short int Value)
67: {
1.1.1.4 root 68: return (((Value/10))<<4) | (Value%10);
1.1 root 69: }
70:
1.1.1.2 root 71:
72: /*-----------------------------------------------------------------------*/
1.1 root 73: /*
1.1.1.7 ! root 74: Seed own random number (must be !=0)
1.1 root 75: */
76: void Misc_SeedRandom(unsigned long Seed)
77: {
78: RandomNum = Seed;
79: }
80:
1.1.1.2 root 81:
82: /*-----------------------------------------------------------------------*/
1.1 root 83: /*
1.1.1.7 ! root 84: Get next random number
1.1 root 85: */
1.1.1.5 root 86: static long Misc_NextLongRand(long Seed)
1.1 root 87: {
88: unsigned long Lo, Hi;
89:
90: Lo = 16807 * (long)(Seed & 0xffff);
91: Hi = 16807 * (long)((unsigned long)Seed >> 16);
92: Lo += (Hi & 0x7fff) << 16;
93: if (Lo > 2147483647L) {
94: Lo &= 2147483647L;
95: ++Lo;
96: }
97: Lo += Hi >> 15;
98: if (Lo > 2147483647L) {
99: Lo &= 2147483647L;
100: ++Lo;
101: }
102: return((long)Lo);
103: }
104:
1.1.1.2 root 105:
106: /*-----------------------------------------------------------------------*/
1.1 root 107: /*
108: Get own random number
109: */
110: long Misc_GetRandom(void)
111: {
112: RandomNum = Misc_NextLongRand(RandomNum);
113: return(RandomNum);
114: }
115:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.