csb.s 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. .define .csb
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! Table lookup 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. .csb: pop h !hl = pointer to descriptor
  14. pop d !de = case index
  15. push b !save localbase
  16. mov c,m !bc = default pointer
  17. inx h
  18. mov b,m
  19. inx h
  20. push b !save default on stack
  21. mov c,m !bc = number of entries
  22. inx h
  23. mov b,m
  24. inx h
  25. !loop: try to find the case index in the descriptor
  26. 1: mov a,b
  27. ora c
  28. jz 4f !done, index not found
  29. mov a,m !do we have the right index?
  30. inx h
  31. cmp e
  32. jnz 2f !no
  33. mov a,m
  34. inx h
  35. cmp d
  36. jnz 3f !no
  37. mov a,m
  38. inx h
  39. mov h,m
  40. mov l,a
  41. pop psw !remove default pointer
  42. jmp 5f
  43. 2: inx h !skip high byte of index
  44. 3: inx h !skip jump address
  45. inx h
  46. dcx b
  47. jmp 1b
  48. 4: pop h !take default exit
  49. 5: pop b !restore localbase
  50. mov a,l !jump address is zero?
  51. ora h
  52. cz ecase !trap
  53. pchl !jump!!!!