csb.s 934 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. .define .csb
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! this is not a subroutine, but just a
  8. ! piece of code that computes the jump-
  9. ! address and jumps to it.
  10. ! traps if resulting address is zero
  11. .csb:
  12. pop hl ! pointer to descriptor
  13. pop de ! case index
  14. ld c,(hl) ! bc := default offset
  15. inc hl
  16. ld b,(hl)
  17. inc hl
  18. push bc ! save default on stack
  19. ld c,(hl) ! bc := #entries
  20. inc hl
  21. ld b,(hl)
  22. inc hl
  23. 1:
  24. ! loop, try to find the case index
  25. ! in the descriptor
  26. ld a,b
  27. or c
  28. jr z,noteq ! done, index not found
  29. ld a,(hl) ! is de=(hl) ?
  30. inc hl
  31. cp e
  32. jr nz,2f ! no
  33. ld a,(hl)
  34. inc hl
  35. cp d
  36. jr nz,3f ! no
  37. ld a,(hl) ! yes, get jump address
  38. inc hl
  39. ld h,(hl)
  40. ld l,a
  41. pop af ! remove default
  42. jr 4f
  43. 2:
  44. inc hl ! skip high byte of index
  45. 3:
  46. inc hl ! skip jump address
  47. inc hl
  48. dec bc
  49. jr 1b
  50. noteq:
  51. pop hl ! take default exit
  52. 4:
  53. ld a,l ! jump address is zero?
  54. or h
  55. jr z,.trp.z ! yes, trap
  56. jp (hl)