Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func1:
- ;=====================================
- ; Search Index
- ; Syntax:
- ; $ID(main string, string to search
- ;=====================================
- .db "ID",$10
- .dw func1_end-func1_start
- func1_start:
- call ParseFullArg
- cp 2Bh
- ret nz
- ld h,b
- ld l,c
- push hl
- call GetGrammerStr
- pop hl
- ex de,hl
- push bc
- push de
- call ParseNextFullArg
- pop de
- ld h,b
- ld l,c
- push de
- push hl
- call GetGrammerStr
- pop hl
- pop de
- ex de,hl
- ld (TempWord1),bc
- pop bc
- push hl ; save initial pointer for math later
- searchfirst:
- ld a,(de)
- cpir
- jr z,match
- jp pe,saveSScreen+match-func1_start
- pop hl
- ld bc,65535
- ret ; if no match, set bc to -1 and end
- match:
- push bc \ push hl \ push de; save work
- ld bc,(TempWord1) ; load the size of the string to search
- ld a,c
- cp 1
- jr nz,+_ ; takes care of the 1-byte search
- pop de \ pop hl \ pop bc
- jr searchcomplete
- _:
- inc de ; needs to start checking from the second byte
- dec bc ; since first byte is already compared
- temploop1:
- ld a,(de)
- cpi
- inc de
- jr z,+_
- pop bc \ pop hl \ pop de
- jr searchfirst ; go back when the next letter doesn't match
- _:
- jp pe,saveSScreen+temploop1-func1_start
- pop bc \ pop hl \ pop de ; if I'm here, I found a match
- searchcomplete:
- pop de ; initial string pointer is in de
- sbc hl,de
- dec hl ; hl is now the offset.
- ld b,h
- ld c,l
- ret
- func1_end:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement