mirror of
https://github.com/nathanriggs/AppleIIAsm-Collection.git
synced 2024-11-28 03:52:10 +00:00
82d0e74c1a
some minor bugfixes, directory shuffling, added demo and utility disks
79 lines
2.1 KiB
Plaintext
79 lines
2.1 KiB
Plaintext
SUBPOS
|
|
PLA
|
|
STA RETADR
|
|
PLA
|
|
STA RETADR+1
|
|
PLA
|
|
STA ADDR2
|
|
PLA
|
|
STA ADDR2+1
|
|
PLA
|
|
STA ADDR1
|
|
PLA
|
|
STA ADDR1+1
|
|
LDA RETADR+1
|
|
PHA
|
|
LDA RETADR
|
|
PHA
|
|
:POS
|
|
LDY #0
|
|
LDA (ADDR1),Y ; GET LENGTH OF STRING
|
|
BEQ :NOTFND ; EXIT IF LENGTH = 0
|
|
STA :SLEN
|
|
LDA (ADDR2),Y ; GET SUBSTR LENGTH
|
|
BEQ :NOTFND ; EXIT IF SUB LENGTH = 0
|
|
STA :SUBLEN
|
|
LDA :SUBLEN
|
|
CMP :SLEN
|
|
BEQ :LENOK
|
|
BCS :NOTFND ; CANNOT FIND SUBSTR IF
|
|
:LENOK
|
|
LDA #1
|
|
STA :SINDEX ; START LOOKING AT FIRST
|
|
; CHARACTER OF STRING
|
|
LDA :SLEN ; CONT UNTIL REMAINING STR
|
|
; TOO SHORT
|
|
SEC ; COUNT=STR LEN - SUB LEN+1
|
|
SBC :SUBLEN
|
|
STA :SCOUNT
|
|
INC :SCOUNT
|
|
:SLP1
|
|
LDA :SINDEX
|
|
STA :SIDX ; START STR AT INDEX
|
|
LDA #1
|
|
STA :SUBIDX ; START SUB IND AT 1
|
|
:CMPLP
|
|
LDY :SIDX
|
|
LDA (ADDR1),Y ; GET NEXT CHAR FROM STR
|
|
LDY :SUBIDX
|
|
CMP (ADDR2),Y ; COMPARE TO NEXT SUB CHAR
|
|
BNE :SLP2 ; BR IF SUB NOT HERE
|
|
LDY :SUBIDX
|
|
CPY :SUBLEN ; TEST IF WE ARE DONE
|
|
BEQ :FOUND ; BR IF ALL CHARS WERE EQUAL
|
|
INY ; ELSE INC TO NEXT CHAR
|
|
STY :SUBIDX
|
|
INC :SIDX
|
|
JMP :CMPLP ; CONTINUE
|
|
:SLP2
|
|
INC :SINDEX ; INCREMENT INDEX
|
|
DEC :SCOUNT ; DEC COUNT
|
|
BNE :SLP1 ; BR IF NOT DONE
|
|
BEQ :NOTFND ; ELSE EXIT TO NOT FOUND
|
|
:FOUND
|
|
LDA :SINDEX ; FOUND, A = STARTING IDX
|
|
JMP :EXIT
|
|
:NOTFND
|
|
LDA #0 ; SUB NOT FOUND, A=0
|
|
:EXIT
|
|
STA RETURN
|
|
LDY #1
|
|
STY RETLEN
|
|
RTS
|
|
:SLEN DS 1
|
|
:SUBLEN DS 1
|
|
:SINDEX DS 1
|
|
:SUBIDX DS 1
|
|
:SCOUNT DS 1
|
|
:SIDX DS 1
|