TEXT
Implement RelString
'-------------------------------------
'relString
'-------------------------------------
LOCAL FN relString(@word1&,@word2&)
` move.l ^word1&,a0
` move.l ^word2&,a1
` moveq #0,d0
` move.b (a0)+,d0
` swap d0
` move.b (a1)+,d0
` dc.w $A050
END FN
Results are...
_sortsBefore = -1 ' { first string < second string }
_sortsEqual = 0 ' { first string = second string }
_sortsAfter = 1 ' { first string > second string }
To watch for case or diacritical marks, you must change the trap. Here is an example of a case sensetive version.
'-------------------------------------
'relString
'-------------------------------------
LOCAL FN relStringCaseSen(@word1&,@word2&)
` move.l ^word1&,a0
` move.l ^word2&,a1
` moveq #0,d0
` move.b (a0)+,d0
` swap d0
` move.b (a1)+,d0
` dc.w $A450
END FN
The trick is this...
If it's a straight compare, use $A050
If you want case sensetivity, add $400 ($A450)
If you want diacritical sensitivity, add $200 ($A250)
If you want both, add $400 and $200 ($650)
the relString trap puts its result in register D0. We could extract that result and put it in a variable...
` move.w d0,^sortResult
Then return the result from the function
END FN = sortResult
This would tell FB to put the result back in D0...
` move.w ^sortResult,d0 ; this happens behind the scenes
` ; you don't actually see it
The final effect is that you took a result out of d0, put it in a variable and FB put it back in d0. (Ring around the register) Since I knew that the result was in d0 and I knew that END FN without an equal sign would not affect the register, I just let it return to the calling routine.
The calling routine _always_ expects the result to be in d0.
|