csa.s 1002 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. .define .csa
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! Case jump
  8. ! Expects on stack: address of case descriptor
  9. ! case index
  10. ! This is not a subroutine, but just a piece of code that computes
  11. ! the jump address and jumps to it.
  12. ! Traps if resulting address is zero.
  13. .csa: pop h !hl = address of case descriptor
  14. pop d !de = index
  15. push b !save localbase
  16. mov c,m
  17. inx h
  18. mov b,m
  19. inx h
  20. push b !save default pointer on stack
  21. mov a,e
  22. sub m
  23. inx h
  24. mov c,a
  25. mov a,d
  26. sbb m
  27. inx h
  28. mov b,a !bc = index - lower bound
  29. jc 1f !get default pointer
  30. mov a,m
  31. inx h
  32. sub c
  33. mov a,m
  34. inx h
  35. sbb b
  36. jc 1f !upper-lower should be >= index-lower
  37. dad b
  38. dad b !hl now points to the wanted pointer
  39. mov a,m
  40. inx h
  41. mov h,m
  42. mov l,a !hl = pointer for index
  43. ora h
  44. jz 1f !get default pointer if pointer = 0
  45. pop b !remove default pointer
  46. pop b !localbase
  47. pchl !jump!!!!
  48. 1: pop h !get default pointer
  49. mov a,l
  50. ora h
  51. cz ecase !trap
  52. pop b !restore localbase
  53. pchl !jump!!!!