; Copyright 1999 Pace Micro Technology plc
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;     http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
; support.s for OmniClient Access(+) Protocol

        GET     Hdr:ListOpts
        GET     Hdr:Macros
        GET     Hdr:System
        GET     Hdr:ResourceFS
        GET     Hdr:ModHand

        AREA    |support$$code|, CODE, READONLY

        EXPORT  |suicide|

        EXPORT  flag_set_
        EXPORT  flag_clr_
        EXPORT  flag_setclr_

        EXPORT  bounce_cb

; Register a transient callback

|suicide|
        Push    "lr"
        MOV     r1, r0                  ; save module_title address (called as r12)
        ADR     r0, suicide_cb
        SWI     XOS_AddCallBack
        Pull    "pc"

|suicide_cb|
        Push    "r0-r1, lr"
        MOV     r0, #ModHandReason_Delete
        MOV     r1, r12
        SWI     XOS_Module
        Pull    "r0-r1, pc"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; r0 bits, r1 ptr

flag_set_
        PHPSEI  ip, r3
        LDR     r3, [r1]
        ORR     r0, r3, r0
        STR     r0, [r1]
        B       flag_done

; r0 bits, r1 ptr

flag_clr_
        PHPSEI  ip, r3
        LDR     r3, [r1]
        BIC     r0, r3, r0
        STR     r0, [r1]
        B       flag_done

; r0 set, r1 clr, r2 ptr

flag_setclr_
        PHPSEI  ip, r3
        LDR     r3, [r2]
        ORR     r0, r0, r3
        BIC     r0, r0, r1
        STR     r0, [r2]
flag_done
        MOV     r0, r3
        PLP     ip
        MOV     pc, lr

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        IMPORT  callback_veneer
bounce_cb
        Push    "r0-r12, lr"
        BL      callback_veneer
        Pull    "r0-r12, pc"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        END
