searchstring.z80 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ;SearchString is used by inString and Lbl
  2. searchstring_routine:
  3. ;Inputs:
  4. ; HL points to the string to search
  5. ; BC size of the string to search
  6. ; DE points to string to find
  7. ; IX is the size of the string to find
  8. ;Outputs:
  9. ; c flag set if there was a match, nc if no match was found
  10. ; HL points to the match if there was one
  11. ; DE is preserved
  12. ;Destroys:
  13. ; A,BC
  14. ;First, we'll do BC-IX -> BC, and make sure it isn't negative
  15. push hl
  16. ld h,b
  17. ld l,c
  18. push ix
  19. pop bc
  20. dec bc
  21. ;Save the size of the string to find
  22. ld (TempWord1),bc
  23. or a
  24. sbc hl,bc
  25. ld b,h
  26. ld c,l
  27. pop hl
  28. ret z
  29. ccf
  30. ret nc ;This means the input was smaller than the string to search for!
  31. jr searchstring_begin
  32. searchstring_match:
  33. dec hl
  34. scf
  35. ret
  36. _:
  37. ;at this point, we have a match
  38. ;now we need to compare the strings
  39. push hl
  40. push de
  41. push bc
  42. call +_
  43. pop bc
  44. pop de
  45. pop hl
  46. jr z,searchstring_match ;we found our match!
  47. ld a,b
  48. or c
  49. jr z,searchstring_nomatch+1
  50. searchstring_begin:
  51. ld a,(de)
  52. cpir
  53. jr z,-_
  54. searchstring_nomatch:
  55. xor a
  56. ld h,a
  57. ld l,a
  58. ret
  59. _:
  60. ld bc,(TempWord1)
  61. _:
  62. inc de
  63. ld a,(de)
  64. cpi
  65. ret nz
  66. jp pe,-_
  67. ret