; 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.
;
; > $.Source.PMF.Def
 MACRO
 Protocol
;
; Protocol constants
;
; 4 bit codes for input commands
;
LEDON * &00
LEDOFF * &10
REQUEST * &20
ACK * &30
SPDDATA * &40 ;Bottom four bits are data to convert
RSTREQ * &80 ;Request for reset
;
; 4 bit input data types
;
; Requests
;
KBID * 0
SPDRESET * 1
MDATA * 2 ;New mouse position, even if it hasn't moved
;
; Acks
;
BYTE * 0
SCAN * 1
MOUSE * 2
ALL * 3
;
; data output
;
; Type         d7 d6 d5 d4 d3 d2 d1 d0 number of bytes
; Reset        1  x  x  x  x  x  x  x  1
; Key up       0  0  1  1  x  x  x  x  2 (row then column)
; Key down     0  0  1  0  x  x  x  x  2 (row then column)
; Mouse change 0  1  x  x  x  x  x  x  2 (X, Y)
; SPD data     0  0  0  0  x  x  x  x  8
; KB Ids       0  0  0  1  x  x  x  x  2 (low nibble then high nibble)
;
; The keyboard type
;
IDTYPE * &10
KBTYPE * 0 ;This is keyboard 0
;
; Key transitions
;
KEYDOWN * &20
KEYUP * &30
;
; Mouse transitions
;
MMOVED * &40
;
; SPD converted data
;
SPDDONE * 0
;
; Reset types
;
HRDRESET * &FF
RST1ACK * &FE
RST2ACK * &FD

; New keyboard protocols

; Keyboard -> ARM

K1mdat  * &00           ; 0xxx xxxx     Mouse data from keyboard
K1kbid  * &80           ; 10xx xxxx     Keyboard ID from keyboard
K1kdda  * &C0           ; 1100 xxxx     Key down data
K1kuda  * &D0           ; 1101 xxxx     Key up data
K1pdat  * &E0           ; 1110 xxxx     SPD data from keyboard (won't happen)
K1rak2  * &FD           ; 1111 1101     Reset acknowledge 2
K1rak1  * &FE           ; 1111 1110     Reset acknowledge 1
K1hrst  * &FF           ; 1111 1111     Hard reset

K1kbidmask * &3F        ; 0011 1111     Valid bits in keyboard id

K1notmousedata * &80

; ARM -> Keyboard

;
; The IOC registers
;
        ^       &04, R12
KARTTx  #       0
KARTRx  #       0

        ^       &20, R12
IRQStatusB #    4
IRQReqB    #    4
IRQMaskB   #    4

        ^       &70, R12
Timer3Low   #   4
Timer3High  #   4
Timer3Go    #   4
Timer3Latch #   4

; Register bits

KARTRxBit   *   &80
KARTTxBit   *   &40
KARTIRQBits *   KARTTxBit :OR: KARTRxBit

K1leds  * &00           ; 0000 0xxx     Set LED states
K1rqid  * &20           ; 0010 0000     Request keyboard id
K1prst  * &21           ; 0010 0001     SPD reset
K1rqmp  * &22           ; 0010 0010     Request mouse position
K1nack  * &30           ; 0011 0000     Acknowledge (keys- mouse-)
K1sack  * &31           ; 0011 0001     Acknowledge (keys+ mouse-)
K1mack  * &32           ; 0011 0010     Acknowledge (keys- mouse+)
K1smak  * &33           ; 0011 0011     Acknowledge (keys+ mouse+)
K1back  * &3F           ; 0011 1111     Byte acknowledge (between 2 data bytes)
K1rqpd  * &40           ; 0100 xxxx     Request SPD data conversion

; Keyboard vector offsets

        ^ 0

KVKeyTran          # 4
KVKeyTranSize      # 4
KVInkeyTran        # 4
KVShiftingList     # 4
KVSpecialList      # 4
KVSpecialCodeTable # 4
KVInit             # 4
KVPendingAltCode   # 4
KVPendingAltSpecial # 4             ; Used only internally

 MEND
 END