I'm trying to create a switch statement as below, which works well until something crosses a page. The switch destination is auto generated, which is why its in another file. 'structure, x' holds the offset (the case switch). In the case below, it will be either $00, $02, $04 or $06.
Is there anyway to ensure that the returnAddr isn't at $xx00? (Does that actually matter here?) And that the switchlist doesn't cross a boundary?
lda #>returnAddr
pha
lda #<returnAddr-1
pha
; store where we want to go
lda switchlist+1
pha
lda switchlist
clc
adc structure, x
pha
rts ; make call to the proc in the switchlist
returnAddr:
; ...
rts
and in another file I have (where case_x are function labels)
switchlist:
.word case_1
.word case_2
.word case_3
.word case_4