Bill Drummond

04-03-2009, 03:19 PM

I trying to port this pascal code to Spin

function ELFHash(const Str : String) : Int64;

var

i : integer;

x : Cardinal;

begin

Result := 0;

for i := 1 to Length(Str) do

begin

Result := (Result shl 4) + Ord(Str[i]);

x := Result and $F0000000;

if (x <> 0) then

begin

Result := Result xor (x shr 24);

end;

Result := Result and (not x);

end;

end;

This doesn't work..

''***************************************

''* From Keyboard Demo v1.0 *

''* Author: Chip Gracey *

''* Copyright (c) 2006 Parallax, Inc. *

''* See end of file for terms of use. *

''***************************************

CON

_clkmode = xtal1 + pll16x

_xinfreq = 5_000_000

VAR

byte j

long x

OBJ

term : "tv_terminal"

kb : "keyboard"

PUB start | i

'start the tv terminal

term.start(12)

term.str(string("HashCode Demo...",13))

'start the keyboard

kb.start(26, 27)

term.Hex(Hash(String("DIR")),8)

term.out(13)

term.Hex(Hash(String("TYPE")),8)

term.out(13)

term.Hex(Hash(String("MOUNT")),8)

term.out(13)

term.Hex(Hash(String("UNMOUNT")),8)

term.out(13)

PUB Hash(string_ptr) : Result

result := 0

repeat strsize(string_ptr)

Result := (Result << 4) + byte[string_ptr++]

x := Result and $F0_00_00_00

if (x <> 0)

Result := Result ^ (x >> 24)

Result := result & (not x)

{{

Here is a windows program

function ELFHash(const Str : String) : Int64;

var

i : integer;

x : Cardinal;

begin

Result := 0;

for i := 1 to Length(Str) do

begin

Result := (Result shl 4) + Ord(Str[i]);

x := Result and $F0000000;

if (x <> 0) then

begin

Result := Result xor (x shr 24);

end;

Result := Result and (not x);

end;

end;

This doesn't work..

''***************************************

''* From Keyboard Demo v1.0 *

''* Author: Chip Gracey *

''* Copyright (c) 2006 Parallax, Inc. *

''* See end of file for terms of use. *

''***************************************

CON

_clkmode = xtal1 + pll16x

_xinfreq = 5_000_000

VAR

byte j

long x

OBJ

term : "tv_terminal"

kb : "keyboard"

PUB start | i

'start the tv terminal

term.start(12)

term.str(string("HashCode Demo...",13))

'start the keyboard

kb.start(26, 27)

term.Hex(Hash(String("DIR")),8)

term.out(13)

term.Hex(Hash(String("TYPE")),8)

term.out(13)

term.Hex(Hash(String("MOUNT")),8)

term.out(13)

term.Hex(Hash(String("UNMOUNT")),8)

term.out(13)

PUB Hash(string_ptr) : Result

result := 0

repeat strsize(string_ptr)

Result := (Result << 4) + byte[string_ptr++]

x := Result and $F0_00_00_00

if (x <> 0)

Result := Result ^ (x >> 24)

Result := result & (not x)

{{

Here is a windows program