; Copyright 2002 Tematic Ltd
;
; 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.
;
; > $.Source.VduGrafV
;
; ARTHUR OPERATING SYSTEM - Vdu Drivers
; =======================
;
; Vdu driver code - Default GraphicsV claimant
;
; Author K J Bracey
; Date   30.8.02
;

        MACRO
        GVEntry $name
        ASSERT  . - MOSGraphicsV_Table = GraphicsV_$name * 4
        B       GV_$name
        MEND

MOSGraphicsV ROUT
        ; We only care about VSync events, and only for the current driver
        LDR     WsPtr, [WsPtr, #CurrentGraphicsVDriver]
        ADD     WsPtr, WsPtr, #GraphicsV_VSync :SHL: 8
        TEQ     r4, WsPtr, ROR #8
        MOVNE   pc, lr
; Switch to interrupt mode to process this.
        LDR     WsPtr, =ZeroPage+OsbyteVars
        MRS     r4, CPSR
        Push    "lr"
        MSR     CPSR_c, #I32_bit + IRQ32_mode
        Push    "r4, lr"
        Push    "pc"
        B       VsyncIRQ_ExtEntry
        NOP
        Pull    "r4, lr"
        MSR     CPSR_c, r4
        MOV     r4, #0
        Pull    "pc"

CallGraphicsV
        Push    "r10,r12,lr"
        MOV     r10, #GraphicsV
        BL      CallVector
        Pull    "r10,r12,pc"

; Corrupts R9-R11
; returns EQ if acceleration valid
CheckAcceleration
        ASSERT  Log2BPP = Log2BPC +4
        ADD     R9, WsPtr, #Log2BPC
        LDMIA   R9, {R9, R10}                   ; R9 = Log2BPC; R10 = Log2BPP
        LDR     R11, [WsPtr, #VduSprite]
        TEQ     R9, R10                         ; BPC must equal BPP
        TEQEQ   R11, #0                         ; Must not be redirected
        MOV     PC, R14

        END