; Copyright 1996 Acorn Computers 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.
;
; > $.Hdr.KeyWS

; ***********************************
; ***    C h a n g e   L i s t    ***
; ***********************************

; Date       Name  Description
; ----       ----  -----------
; 06-Feb-91  TMD   Added LastLED
; 09-Mar-92  TMD   Added JustGotKbID
; 24-Feb-93  SMC   Reorganised for new keyboard/mouse interfaces
; 19-Jul-93  JSR   Changed conditional from A1Keyboard to Keyboard_Type = "A1A500"

; Keyboard variables

          GBLS  keyprefix
keyprefix SETS  "Key$"

        ^       0, R11

CurrKey         #       1               ; current key in two key rollover
OldKey          #       1               ; old key in two key rollover
KbId            #       1
LastKbId        #       1
AutoRepeatCount #       1
Debouncing      #       1               ; NZ => do delay next, Z => do repeat
MouseButtons    #       1               ; bit0=R, bit1=C, bit2=L
PendingAltType  #       1               ; 1 => A, 2 => SA, 3 => CA, 4 => CSA
ModulesOK       #       1               ; bit0=1 => modules are initialised
                                        ; bit1=1 => we have offered service
LastLED         #       1               ; last request for LED change, so we don't send repeated ones
MouseType       #       1               ; current pointer device type

 [ Keyboard_Type = "A1A500"
JustGotKbId     #       1
RequestMouse    #       1
RequestLED      #       1
RequestSPD      #       1
RequestKbId     #       1
SPDRec          #       1               ; number to be received
ResetState      #       1               ; next thing to go in reset handshake
KeyRow          #       1               ; half received key up or down
Reply           #       1               ; next reply to be sent (&FF if nowt)
KbIdHalf        #       1
MouseCount      #       1               ; 0 => X next, 1 => Y next
MouseDelta      #       2               ; delta X,Y
 ]

                # 3 :AND: (- :INDEX: @)

InkeyCounter    #       4
MouseX          #       4
MouseY          #       4
SoftKeyPtr      #       4
MouseXMult      #       4
MouseYMult      #       4
KeyVec          #       4

 [ Keyboard_Type = "A1A500"
SPDinput        #       4
SPDoutput       #       4
  [ AssemblePointerV
MouseXCount     #       4
MouseYCount     #       4
  ]
 ]

MouseBounds     #       16
MouseBoundLCol  *       MouseBounds+0
MouseBoundBRow  *       MouseBounds+4
MouseBoundRCol  *       MouseBounds+8
MouseBoundTRow  *       MouseBounds+12

KeysDown        #       20              ; bitmap of all down keys

SoftKeyName     #       3 + :LEN:(keyprefix)    ; up to 2 digits + terminator

SoftKeyExpand   #       255             ; current key expansion

        ASSERT  (:INDEX: @) < KeyWorkSpaceSize
UserKeyWorkSpaceSize *  KeyWorkSpaceSize-(:INDEX: @)
UserKeyWorkSpace #      UserKeyWorkSpaceSize


; PMF -> VDU communication stuff put in here because both VDU and PMF
; 'GET' this file

        GBLA    ExtEntries
ExtEntries SETA 0

        MACRO
        AddExtEntry $EntryName
Index_$EntryName * ExtEntries
        [ AssemblingArthur
Value_$ExtEntries * $EntryName
        |
        [ DoingVdu
Value_$ExtEntries * $EntryName
        ]
        ]
ExtEntries SETA ExtEntries +1
        MEND

        MACRO
$Table  OutputExternals
$Table
        LCLA    count
count   SETA    0
        WHILE   count < ExtEntries
        &       Value_$count - $Table -4
count   SETA    count + 1
        WEND
        MEND

        MACRO
        ByteToNosbod $EntryName
        [ AssemblingArthur
        VDWS    WsPtr
        BL      $EntryName
        |
        MOV     R0, #Index_$EntryName
        BL      ByteToNosbod
        ]
        MEND

        AddExtEntry     DoReadPOSVPOSI
        AddExtEntry     DoReadPOSVPOSO
        AddExtEntry     DoOSBYTE87
        AddExtEntry     DoResetFont
        AddExtEntry     DoReadFont
        AddExtEntry     DoReadVDUStatus
        AddExtEntry     DoReadVDUVariable
        AddExtEntry     DoReadPalette
        AddExtEntry     DoSetPalette
        AddExtEntry     DoPointerStuff
        AddExtEntry     DoSetScreenStart
        AddExtEntry     DoSetDriverBank
        AddExtEntry     DoSetDisplayBank
        AddExtEntry     DoOsbyte163_242
        AddExtEntry     DoOsWord13

        END