Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
1.7KB

  1. ; Whether A is a separator or end-of-string (null or ':')
  2. isSepOrEnd:
  3. or a
  4. ret z
  5. cp ':'
  6. ret z
  7. ; continue to isSep
  8. ; Sets Z is A is ' ' or '\t' (whitespace)
  9. isSep:
  10. cp ' '
  11. ret z
  12. cp 0x09
  13. ret
  14. ; Expect at least one whitespace (0x20, 0x09) at (HL), and then advance HL
  15. ; until a non-whitespace character is met.
  16. ; HL is advanced to the first non-whitespace char.
  17. ; Sets Z on success, unset on failure.
  18. ; Failure is either not having a first whitespace or reaching the end of the
  19. ; string.
  20. ; Sets Z if we found a non-whitespace char, unset if we found the end of string.
  21. rdSep:
  22. ld a, (hl)
  23. call isSep
  24. ret nz ; failure
  25. .loop:
  26. inc hl
  27. ld a, (hl)
  28. call isSep
  29. jr z, .loop
  30. call isSepOrEnd
  31. jp z, .fail ; unexpected EOL. fail
  32. cp a ; ensure Z
  33. ret
  34. .fail:
  35. ; A is zero at this point
  36. inc a ; unset Z
  37. ret
  38. ; Advance HL to the next separator or to the end of string.
  39. toSepOrEnd:
  40. ld a, (hl)
  41. call isSepOrEnd
  42. ret z
  43. inc hl
  44. jr toSepOrEnd
  45. ; Advance HL to the end of the line, that is, either a null terminating char
  46. ; or the ':'.
  47. ; Sets Z if we met a null char, unset if we met a ':'
  48. toEnd:
  49. ld a, (hl)
  50. or a
  51. ret z
  52. cp ':'
  53. jr z, .havesep
  54. inc hl
  55. call skipQuoted
  56. jr toEnd
  57. .havesep:
  58. inc a ; unset Z
  59. ret
  60. ; Read (HL) until the next separator and copy it in (DE)
  61. ; DE is preserved, but HL is advanced to the end of the read word.
  62. rdWord:
  63. push af
  64. push de
  65. .loop:
  66. ld a, (hl)
  67. call isSepOrEnd
  68. jr z, .stop
  69. ld (de), a
  70. inc hl
  71. inc de
  72. jr .loop
  73. .stop:
  74. xor a
  75. ld (de), a
  76. pop de
  77. pop af
  78. ret
  79. ; Read word from HL in SCRATCHPAD and then intepret that word as an expression.
  80. ; Put the result in IX.
  81. ; Z for success.
  82. ; TODO: put result in DE
  83. rdExpr:
  84. ld de, SCRATCHPAD
  85. call rdWord
  86. push hl
  87. ex de, hl
  88. call parseExpr
  89. push de \ pop ix
  90. pop hl
  91. ret