csa.s 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. .define Csa
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! This subroutine performs the case jump by indexing.
  8. ! The zeropage locations ADDR, ADDR+1 contain the address of
  9. ! the case descriptor which also is the address of the
  10. ! default pointer.
  11. ! The zeropage locations ADDR+2, ADDR+3 contain the address of the
  12. ! indextable which is the casedescriptor + 6.
  13. Csa:
  14. stx ADDR ! address of descriptor (lowbyte)
  15. sta ADDR+1 ! address of descriptor (highbyte)
  16. tay
  17. txa
  18. clc
  19. adc #6
  20. sta ADDR+2 ! address of index table (lowbyte)
  21. tya
  22. adc #0
  23. sta ADDR+3 ! address of index table (highbyte)
  24. jsr Pop ! fetch index
  25. pha ! subtract lowerbound
  26. txa
  27. ldy #2
  28. sec
  29. sbc (ADDR),y
  30. sta ARTH ! lowerbound (lowbyte)
  31. pla
  32. iny
  33. sbc (ADDR),y
  34. sta ARTH+1 ! lowerbound (highbyte)
  35. bmi 1f ! index < lowerbound
  36. ldy #5
  37. lda (ADDR),y
  38. cmp ARTH+1
  39. bcc 1f ! index (highbyte) > upperbound - lowerbound
  40. bne 2f ! index (highbyte) <= upperbound - lowerbound
  41. dey
  42. lda (ADDR),y
  43. cmp ARTH
  44. bcc 1f ! index (lowbyte) > upperbound - lowerbound
  45. 2: asl ARTH
  46. rol ARTH+1 ! index * 2
  47. clc
  48. lda ADDR+2
  49. adc ARTH
  50. sta ADDR+2 ! address of pointer (lowbyte)
  51. lda ADDR+3
  52. adc ARTH+1
  53. sta ADDR+3 ! address of pointer (highbyte)
  54. ldy #0
  55. lda (ADDR+2),y ! jump address (lowbyte)
  56. tax
  57. iny
  58. lda (ADDR+2),y ! jump address (highbyte)
  59. bne 3f
  60. cpx #0
  61. beq 1f
  62. 3: stx ADDR ! pointer <> 0
  63. sta ADDR+1
  64. jmp (ADDR) ! jump to address
  65. 1: ldy #0 ! pointer = 0
  66. lda (ADDR),y ! get default pointer (lowbyte)
  67. tax
  68. iny
  69. lda (ADDR),y ! get default pointer (highbyte)
  70. bne 3b
  71. cpx #0
  72. bne 3b ! default pointer <> 0