gto.s 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. .define Gto
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! This subroutine performs the non_local goto.
  8. ! The address of the descriptor is stored in zeropage locations
  9. ! ADDR, ADDR+1.
  10. ! Since there are two stacks (hardware_stack and the real_stack),
  11. ! the stackpointer of the hard_stack is resetted by searching the
  12. ! new localbase in the real_stack while adjusting the hardware_stack.
  13. Gto:
  14. stx ADDR ! address of descripto (lowbyte)
  15. sta ADDR+1 ! address of descriptor (highbyte)
  16. pla ! remove
  17. pla ! __gto return address.
  18. ldy #4
  19. lda (ADDR),y ! new localbase (lowbyte)
  20. sta ARTH
  21. tax
  22. iny
  23. lda (ADDR),y ! new localbase (highbyte)
  24. sta ARTH+1
  25. cmp LB+1
  26. bne 1f
  27. cpx LB
  28. beq 2f ! goto within same procedure
  29. 1: ldy #0
  30. lda (LB),y ! get localbase (lowbyte)
  31. tax
  32. iny
  33. lda (LB),y ! get localbase (highbyte)
  34. cmp ARTH+1
  35. bne 3f
  36. cpx ARTH
  37. beq 2f ! found localbase
  38. 3: stx LB ! temporary save of localbase
  39. sta LB+1
  40. pla ! adjust
  41. pla ! hardware_stack
  42. jmp 1b
  43. 2: sta LB+1 ! store localbase (highbyte)
  44. pha
  45. stx LB ! store localbase (lowbyte)
  46. sec
  47. txa
  48. sbc #BASE
  49. sta LBl ! localbase - 240 (lowbyte)
  50. pla
  51. sbc #0
  52. sta LBl+1 ! localbase - 240 (highbyte)
  53. ldy #3
  54. lda (ADDR),y ! new stackpointer (highbyte)
  55. sta SP+1
  56. dey
  57. lda (ADDR),y ! new stackpointer (lowbyte)
  58. sta SP+2
  59. dey
  60. lda (ADDR),y ! jump address (highbyte)
  61. sta ADDR+3
  62. dey
  63. lda (ADDR),y ! jump address (lowbyte)
  64. sta ADDR+2
  65. jmp (ADDR+2) ! jump to address