I'm still learning about memory and such. The WORD hex values are reversed. 5630 when it should be 3056, etc... How can I fix that so it returns 3056? I'm thinking it's something really obvious but I don't have much experience with this part yet. $5630 will return 22064 in decimal while $3056 returns the proper 12374 in decimal.
Procedure.l HexToMemory(inHex.s)
; Original Code by blueznl:
; Endian swapping routine by Psychophanta: http://forums.purebasic.com/english/viewtopic.php?t=8541
Protected a.l, b.l, p.l, c.l, l.l, d.w
Protected *HoldMemory.l
;
p = @inHex
c = 0
l = Len(inHex)
;
*HoldMemory = AllocateMemory(l * 2)
; Allocate the memory needed.
If Left(inHex,1) = "$" : p = p + 1 : EndIf
;
While c + 1 < l
a = PeekB(p) - 48
If a > 10 : a = a - 7 : EndIf
b = PeekB(p + 1) - 48
If b > 10 : b = b - 7 : EndIf
PokeB(*HoldMemory + q, a * 16 + b)
If q & 1
d = PeekW(*HoldMemory + q - 1)
!ROR word[esp + 24], 8
; inHex.s is [esp]. The next declared variable will be [esp + 4]. Every variable after that
; is base [esp + x] where x is the total size of the previous variables.
PokeW(*HoldMemory + q - 1, d)
EndIf
p = p+2
q = q+1
c = c+2
Wend
;
ProcedureReturn *HoldMemory
; And return the pointer to this string.
EndProcedure
So now it works like I need it to. Thanks a lot, blueznl and Psychophanta!