csb.s 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. .define Csb
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! This subroutine performs the case jump by searching the table.
  8. ! The zeropage locations ADDR, ADDR+1 contain the address of the
  9. ! case descriptor, which also is the address of the default pointer.
  10. ! The zeropage locations ADDR+2, ADDR+3 are used to address the jump
  11. ! pointers.
  12. Csb:
  13. stx ADDR ! address of descriptor (lowbyte)
  14. sta ADDR+1 ! address of descriptor (highbyte)
  15. stx ADDR+2
  16. sta ADDR+3
  17. ldy #2
  18. lda (ADDR),y ! number of entries (lowbyte)
  19. pha
  20. jsr Pop
  21. stx ARTH ! index (lowbyte)
  22. sta ARTH+1 ! index (highbyte)
  23. pla
  24. tax
  25. inx
  26. 2: clc
  27. lda #4
  28. adc ADDR+2
  29. sta ADDR+2 ! pointer (lowbyte)
  30. bcc 1f
  31. lda #0
  32. adc ADDR+3
  33. sta ADDR+3 ! pointer (highbyte)
  34. 1: ldy #0
  35. lda (ADDR+2),y
  36. cmp ARTH
  37. bne 3f ! pointer (lowbyte) <> index (lowbyte)
  38. iny
  39. lda (ADDR+2),y
  40. cmp ARTH+1
  41. bne 3f ! pointer (highbyte) <> index (highbyte)
  42. iny
  43. lda (ADDR+2),y ! jump address (lowbyte)
  44. tax
  45. iny
  46. lda (ADDR+2),y ! jump address (highbyte)
  47. jmp 4f
  48. 3: dex
  49. bne 2b
  50. 5: ldy #0
  51. lda (ADDR),y ! default pointer (lowbyte)
  52. tax
  53. iny
  54. lda (ADDR),y ! default pointer (highbyte)
  55. beq 1f
  56. 4: bne 1f ! pointer (lowbyte) <> 0
  57. cpx #0
  58. bne 1f ! pointer (highbyte) <> 0
  59. beq 5b ! get default pointer
  60. 1: stx ADDR
  61. sta ADDR+1
  62. jmp (ADDR) ! jump