ret.s 960 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. .define Ret
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! This subroutine stores the returnvalue in the return area.
  8. ! This area is in zeropage.
  9. ! The size of the object to be returned is in zeropage location
  10. ! RETSIZE.
  11. ! It also restores the localbases and the stackpointer of the
  12. ! invoking procedure.
  13. Ret:
  14. sty RETSIZE ! save returnsize
  15. beq 1f ! the return size is zero
  16. lda #0 ! address of returnvalue area (highbyte)
  17. ldx #RETURN ! address of returnvalue area (lowbyte)
  18. cpy #2
  19. bne 2f
  20. jsr Sti ! store word
  21. jmp 1f
  22. 2: cpy #4
  23. jsr Sdi ! store fourbyte word
  24. 1: ldx LB ! get old stackpointer (lowbyte)
  25. stx SP+2
  26. lda LB+1 ! get old stackpointer (highbyte)
  27. sta SP+1
  28. inc LB
  29. inc LB
  30. bne 1f
  31. inc LB+1
  32. 1: jsr Pop ! get old localbase
  33. stx LB ! localbase (lowbyte)
  34. sta LB+1 ! localbase (highbyte)
  35. pha
  36. sec
  37. txa
  38. sbc #BASE
  39. sta LBl ! second localbase (lowbyte)
  40. pla
  41. sbc #0
  42. sta LBl+1 ! second localbase (highbyte)
  43. rts