Update: the old code had a bug if the EXE was made resident using the HOT_RES keyword (thanks to Jan Bredenbeek for pointing it out), updated code below.
Today I’ve had a short discussion about creating a QDOS executable that can both be LRESPRed (to install a thing) and EXecuted (to, erm, execute it). One important detail is that LRESPR must only work in the main BASIC, as otherwise the system will crash once the daughter BASIC is terminated. There are several ways to do it, but I’d like to share mine:
base bra.s start
; Trick: on an EXE call a6 must point to either a BRA ($60) or JMP ($4E).
; both have bit 6 set ($40). On Basic a6 points to the MSB of sb_buffb.
; Bit 6 will never be set as long as QLs have less than 1GB of RAM :-)
beq.s lrespr ; Definitely LRESPR
cmp.w #$4afb,6(a6) ; This check is somewhat optional...
beq.s job_start ; but in case QLs ever have >1GB... :)
tst.l d1 ; Job ID = main BASIC
; LRESPRed from daughter SBASIC/MultiBasic
; LRESPred from main BASIC
; EXECed as normal job