ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/current/Global/Functions.pas
(Generate patch)

Comparing:
oup/rewrite/Global/Functions.pas (file contents), Revision 97 by alloc, Mon Jan 22 23:05:45 2007 UTC vs.
oup/current/Global/Functions.pas (file contents), Revision 113 by alloc, Sun Feb 25 17:20:22 2007 UTC

# Line 5 | Line 5 | interface
5   uses TypeDefs, Classes;
6  
7   function BoolToStr(bool: Boolean): String;
8 function HexToLong(hex: String): LongWord;
8   function Decode_Int(buffer: TByteData): LongWord;
9   function Encode_Int(input: LongWord): TByteData;
10   function Decode_Float(buffer: TByteData): Single;
11   function Encode_Float(input: Single): TByteData;
12 + function IntToBin(Value: Byte): String;
13   function DataToBin(Data: TByteData): String;
14   function BinToInt(bin: String): Byte;
15 + function MakeDatLink(FileID: Integer): Integer;
16  
17   function StringSmaller(string1, string2: String): Boolean;
18  
# Line 38 | Line 39 | type
39  
40  
41  
41
42   function BoolToStr(bool: Boolean): String;
43   begin
44    if bool then
# Line 48 | Line 48 | begin
48   end;
49  
50  
51
52
53 function HexToLong(hex: String): LongWord;
54
55  function NormalizeHexString(var hex: String): Boolean;
56  var
57    i: Byte;
58  begin
59    Result := True;
60    if hex[1] = '$' then
61    begin
62      for i := 1 to Length(hex) - 1 do
63        hex[i] := hex[i + 1];
64      SetLength(hex, Length(hex) - 1);
65    end;
66    if (hex[1] = '0') and (UpCase(hex[2]) = 'X') then
67    begin
68      for i := 1 to Length(hex) - 2 do
69        hex[i] := hex[i + 2];
70      SetLength(hex, Length(hex) - 2);
71    end;
72    if Length(hex) = 0 then
73      Result := False;
74  end;
75
76 begin
77  if NormalizeHexString(hex) then
78  begin
79    Result := StrToInt(hex);
80 {
81    hex    := UpperCase(hex);
82    Result := 0;
83    for i := 1 to Length(hex) do
84    begin
85      Result := Result shl 4;
86      case hex[i] of
87        '0'..'9':
88          Result := Result + Ord(hex[i]) - 48;
89        'A'..'F':
90          Result := Result + Ord(hex[i]) - 55;
91        else
92          Result := 0;
93          Exit;
94      end;
95    end;
96 }
97  end
98  else
99  begin
100    Result := 0;
101  end;
102 end;
103
104
105
106
51   function Decode_Int(buffer: TByteData): LongWord;
52   begin
53    Result := buffer[0] + buffer[1] * 256 + buffer[2] * 256 * 256 + buffer[3] * 256 * 256 * 256;
54   end;
55  
56  
113
114
57   function Encode_Int(input: LongWord): TByteData;
58   begin
59    SetLength(Result, 4);
# Line 125 | Line 67 | begin
67   end;
68  
69  
128
129
70   function Decode_Float(buffer: TByteData): Single;
71   var
72    _valueswitcher: TValueSwitcher;
# Line 138 | Line 78 | begin
78   end;
79  
80  
141
142
81   function Encode_Float(input: Single): TByteData;
82   var
83    _valueswitcher: TValueSwitcher;
# Line 149 | Line 87 | begin
87   end;
88  
89  
90 + function IntToBin(Value: Byte): String;
91 + var
92 +  i: Byte;
93 + begin
94 +  Result := '';
95 +  for i := 7 downto 0 do
96 +    Result := Result + IntToStr((Value shr i) and $01);
97 + end;
98  
99  
100   function DataToBin(Data: TByteData): String;
# Line 172 | Line 118 | begin
118   end;
119  
120  
175
176
121   function BinToInt(bin: String): Byte;
122   var
123    Add: Integer;
# Line 194 | Line 138 | begin
138   end;
139  
140  
141 + function MakeDatLink(FileID: Integer): Integer;
142 + begin
143 +  Result := FileID * 256 + 1;
144 + end;
145 +
146  
147  
148   function FormatNumber(Value: LongWord; Width: Byte; leadingzeros: Char): String;
# Line 227 | Line 176 | end;
176   function CreateHexString(Data: TByteData; HexOnly: Boolean): String;
177   var
178    string_build, ascii_version: String;
179 <  i: LongWord;
179 >  i: Integer;
180   begin
181    string_build  := '';
182    ascii_version := '';
# Line 260 | Line 209 | end;
209  
210   function DecodeHexString(hex: String): TByteData;
211   var
212 <  i: LongWord;
212 >  i: Integer;
213   begin
214    SetLength(Result, Length(hex) div 2);
215    for i := 0 to Length(Result) do

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)