On second look, I thought something was missing from the last update. With this one, I hope this feature has become a bit more useful.
I added an optional expression parameter to either #SP or #SP1. This allows automatic addition of an arbitrary number to the SP offset. This means, you can keep your offset labels clean from messy add-on constants at any time, such as when stack size is altered within a routine or when calling subroutines that access the parent routine's stack.
Although #SP1 is effectively the same as #SP with parameter 1, the two have different purposes. #SP with offset should be used to adjust for stack changes or subroutine nesting whereas #SP1 is meant to take care of zero-based vs. one-based symbolic (or numeric) offsets. So, for zero-based offsets you should be using #SP1 with whatever offset is required for taking care of stack size changes.
For this to work even easier, an extra internal symbol was necessary (
P) which returns the currently effective offset (same for either #SP or #SP1 mode). You can use it to adjust the SP processing relative to a previous condition, so you don't have to keep a mental count of where things should be.
#PUSH and #PULL will save/restore this offset, also.
(Should you find any errors, I expect to hear from you.)
Example code follows:
;*******************************************************************************
; Example usage for #SP and #SP1 with optional offset
;*******************************************************************************
; Use #SP for one-based offsets (normal)
; Use #SP1 for zero-based offsets (same as if with X indexed mode)
; Optional offset is separate from #SP1 offset (added on top of it)
org *
?A equ 0 ;zero-based offsets
#sp1 ;(SP1 does not change :SP offset)
psha
tsx ;HX -> stacked data
lda ?A,sp
lda ?A,x
call Sub ;near or far (MMU) subroutine
pula
bra *
;*******************************************************************************
#sp1 :ab ;Adjust SP offset for RTS/RTC
Sub lda ?A,sp ;lda ?A+2,sp OR lda ?A+3,sp (MMU)
bsr SubSub ;yet another (local) subroutine
rtc
;*******************************************************************************
#sp1 :sp+2 ;Adjust SP offset for RTS (+2)
SubSub lda ?A,sp ;lda ?A+4,sp
#sp1 :sp+1 ;account for stacked A (+1)
psha
inc ?A,sp ;inc ?A+5,sp
lda ?A,sp ;lda ?A+5,sp
cmpa #3
blo ?SubSub.AOK
lda #3
sta ?A,sp ;sta ?A+5,sp
?SubSub.AOK pula
#sp1 :sp-1
lsl ?A,sp ;lsl ?A+4,sp
rts
;*******************************************************************************
#sp ;restore normal SP processing
;(no offset, no auto-increment)