Code: Select all
CODE TEXT= ( ADR1 +N ADR2 -- F )
HERE 1+
$BAD JSR
0= NOT IF
' FALSE @ JMP
THEN
' TRUE @ JMP
HERE SWAP!
3 # LDA SETUP JSR
BEGIN
BEGIN
N 2+ LDA N 3 + ORA
0= NOT WHILE
N 4 + )Y LDA N )Y CMP
0= NOT IF
RTS
THEN
N 2+ LDA
0= IF N 3 + DEC THEN
N 2+ DEC
INY
0= UNTIL CS-SWAP
N 5 + INC N 1+ INC
REPEAT
RTS END-CODE
The definition looks a little odd because I wrote it so I could reuse the subroutine portion of TEXT= to define -TEXT , a word from the Uncontrolled Reference Words in the Forth-83 Standard.
I decided to replace TEXT= with -TEXT .
Code: Select all
CODE -TEXT ( ADR1 +N ADR2 -- F )
3 # LDA SETUP JSR
BEGIN
BEGIN
N 2+ LDA N 3 + ORA
0= NOT WHILE
N 4 + )Y LDA N )Y CMP
0= NOT IF
CS IF
' 1 @ JMP
THEN
' TRUE @ JMP
THEN
N 2+ LDA
0= IF N 3 + DEC THEN
N 2+ DEC
INY
0= UNTIL CS-SWAP
N 5 + INC N 1+ INC
REPEAT
' FALSE @ JMP
END-CODE
This version of -TEXT takes an address of a string, a length, and an address of another string. It returns FALSE if the strings are equal. If the strings are not equal it returns TRUE if the first non matching character in the first string has a lower PETSCII (Commodore's version of ASCII) value than the first non matching character in the second string, otherwise it returns ONE . This is a little different from the Standard.
Code: Select all
-TEXT addr1 +n1 addr2 -- n2 "dash-text"
Compare two strings over the length +n1 beginning at addr1
and addr2. Return zero if the strings are equal. If
unequal, return n2, the difference between the last
characters compared: addr1(i) - addr2(i).
The use of -TEXT will require changes to the source in five places in the system loader.