REM *************************************
REM * Small module to provide a section *
REM * of shared WorkSpace between two   *
REM * applications.                     *
REM *                                   *
REM * Note: This module is purely for   *
REM *       example purposes only.      *
REM *       Any SWI chunks used         *
REM *       should not be used in       *
REM *       release products but        *
REM *       should be allocated to you  *
REM *       by Acorn.                   *
REM *************************************

DIM org &1000
PC = 15
LR = 13
OverFlowFlag = &10000000

FOR a% = 0 TO 2 STEP 2
P% = org
[ OPT a%

; this is the header for the module

.CodeStart
        EQUD    0               ; no app start code
        EQUD    0               ; no init code
        EQUD    0               ; no final code
        EQUD    0               ; no service call code
        EQUD    titlestring-CodeStart
        EQUD    helpstring-CodeStart
        EQUD    0               ; no keywords table
        EQUD    &42380          ; SWI chunk base
        EQUD    swihandler-CodeStart
        EQUD    switable-CodeStart
        EQUD    0               ; no decoding code

; this is the title string

.titlestring
        EQUS    "ShareMod"
        EQUD    0
        ALIGN

; this is the help string

.helpstring
        EQUS    "ShareMod"
        EQUS    "   0.01 (13 Jan 1992) - example module"
        EQUD    0
        ALIGN

; this is the SWI decoding table

.switable
        EQUS    "Share"
        EQUB    0
        EQUS    "ShareAddress"
        EQUB    0
        ALIGN

; This is the SWI handler code.
; At the moment we only have one SWI but
; I have left room for future expansion!
;
; Entry   R11   SWI number (0-63)
;         R12   Private word (we don't use this)
;         R13   stack
;         R14   flags of the SWI caller

.swihandler
        CMP     R11,#(EndJumpTable - JumpTable)/4
        ADDCC   PC,PC,R11, LSL #2       ; dispatch if in range
        B       UnKnownSWI

.JumpTable
        B       ShareAddress
.EndJumpTable

.UnKnownSWI
        ADR     R0,ErrMessage
        ORRS    PC,R14, #OverFlowFlag
.ErrMessage
        EQUD    &1E6
        EQUS    "Unknown ShareMod operation"+CHR$(0)
        ALIGN

; ShareAddress SWI code
;
; Entry   None
; Exit    R0   address of workspace

.ShareAddress
        ADR     R0,ShareModWorkSpace
        MOVS    PC,R14
.ShareModWorkSpace
        EQUS    STRING$(255,CHR$(0))
]
NEXT a%
file$ = "$.UserBASIC.ShareMod"
SYS"OS_File",&A,file$,&FFA,,org,P%
END
