module_old.z80 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ld a,b
  2. or a
  3. jp nz,ErrPkgNotFound
  4. ex de,hl
  5. ld c,(hl)
  6. inc hl
  7. ld b,(hl)
  8. inc hl
  9. inc b
  10. dec b
  11. jr nz,+_
  12. ld a,c
  13. cp 4
  14. jp c,ErrBadToken
  15. _:
  16. ld c,(hl)
  17. inc hl
  18. ld b,(hl)
  19. inc hl
  20. ld a,b
  21. or c
  22. jp z,ErrBadToken
  23. ld de,(parsePtr)
  24. call binSearch
  25. jp nz,ErrBadToken
  26. ld (parsePtr),de
  27. ld c,(hl)
  28. inc hl
  29. ld b,(hl)
  30. inc hl
  31. ld de,moduleExec
  32. ldir
  33. jp moduleExec
  34. binSearch:
  35. ;HL points to the binLUT
  36. ;BC is the size
  37. ;DE points to the token to find
  38. ld (binLUT),hl
  39. ld (binmax),bc
  40. ld hl,0
  41. ld (binmin),hl
  42. ;binsearchloop:
  43. ld hl,(binmax)
  44. ld bc,(binmin)
  45. or a
  46. sbc hl,bc
  47. ret c
  48. rr h \ rr l
  49. add hl,bc
  50. call bincompare
  51. ret z
  52. jr c,+_ ;means input<compare
  53. ld (binmin),hl
  54. jp binsearchloop
  55. _:
  56. ld (binmax),hl
  57. jp binsearchloop+3
  58. bincompare:
  59. ;z returned if a match, DE needs to point to new parsePtr, HL points to byte after ending byte in teh matched code
  60. ;nz returned if no match, return HL unchanged.
  61. push hl
  62. add hl,hl
  63. ld bc,(binLUT)
  64. add hl,bc
  65. ld a,(hl)
  66. inc hl
  67. ld h,(hl)
  68. ld l,a
  69. add hl,bc
  70. push de
  71. _:
  72. ld a,(de) \ cp (hl)
  73. inc de \ inc hl
  74. jr nz,+_
  75. call isEOT
  76. jr nz,-_
  77. pop af
  78. pop af
  79. cp a
  80. ret
  81. _:
  82. pop de
  83. pop hl
  84. ret
  85. isEOT:
  86. ;End Of Token includes (, ' ', {, [, \n, :
  87. or a \ ret z
  88. cp $3E \ ret z ;:
  89. cp $3F \ ret z ;\n
  90. cp $10 \ ret z ;(
  91. cp $29 \ ret z ;space
  92. cp $3A \ ret ;.