Advertisement
Guest User

Untitled

a guest
Feb 10th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. func1:
  2. ;=====================================
  3. ;  Search Index
  4. ;  Syntax:
  5. ;  $ID(main string, string to search
  6. ;=====================================
  7.     .db "ID",$10
  8.     .dw func1_end-func1_start
  9. func1_start:
  10.     call ParseFullArg
  11.     cp 2Bh
  12.     ret nz
  13.     ld h,b
  14.     ld l,c
  15.     push hl
  16.     call GetGrammerStr
  17.     pop hl
  18.     ex de,hl
  19.     push bc
  20.     push de
  21.     call ParseNextFullArg
  22.     pop de
  23.     ld h,b
  24.     ld l,c
  25.     push de
  26.     push hl
  27.     call GetGrammerStr
  28.     pop hl
  29.     pop de
  30.     ex de,hl
  31.     ld (TempWord1),bc
  32.     pop bc
  33.     push hl ; save initial pointer for math later
  34. searchfirst:
  35.     ld a,(de)
  36.     cpir
  37.     jr z,match
  38.     jp pe,saveSScreen+match-func1_start
  39.     pop hl
  40.     ld bc,65535
  41.     ret ; if no match, set bc to -1 and end
  42. match:
  43.     push bc \ push hl \ push de; save work
  44.     ld bc,(TempWord1) ; load the size of the string to search
  45.     ld a,c
  46.     cp 1
  47.     jr nz,+_ ; takes care of the 1-byte search
  48.     pop de \ pop hl \ pop bc
  49.     jr searchcomplete
  50. _: 
  51.     inc de ; needs to start checking from the second byte
  52.     dec bc ; since first byte is already compared
  53. temploop1
  54.     ld a,(de)
  55.     cpi
  56.     inc de
  57.     jr z,+_
  58.     pop bc \ pop hl \ pop de
  59.     jr searchfirst ; go back when the next letter doesn't match
  60. _: 
  61.     jp pe,saveSScreen+temploop1-func1_start
  62.     pop bc \ pop hl \ pop de ; if I'm here, I found a match
  63. searchcomplete:
  64.     pop de ; initial string pointer is in de
  65.     sbc hl,de
  66.     dec hl ; hl is now the offset.
  67.     ld b,h
  68.     ld c,l
  69.     ret
  70. func1_end:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement