sys7.1-doc-wip/OS/Keyboard/KbdInstall.a

219 lines
7.1 KiB
Plaintext

;
; Hacks to match MacOS (most recent first):
;
; <Sys7.1> 8/3/92 Elliot make this change
; 9/2/94 SuperMario ROM source dump (header preserved below)
;
;_________________________________________________________________________________________
;
; File: KbdInstall.a
;
; Contains: Code to ADB keyboard driver and code for installing keyboard driver as
; well as for installing resources KMAP & KCHR.
; This file is the code that is put in the System file's ADBS
; resource ID = 2. The driver in this file overrides the driver in the ROM
; and overrides any patches to the ROM driver. However, this driver
; depends on the ADBProc in the ROM/Patch for the deallocation of the
; keyboard data buffer at the beginning of ADBReinit.
;
; Written by: Joe Fontana, Ed Tecot and Gary G. Davidian
;
; Copyright: © 1986-1992 by Apple Computer, Inc., all rights reserved.
;
; Change History (most recent first):
;
; <2> 12/28/89 dba Used MAIN instead of PROC to get dead code stripping.
; <1.1> 8/28/89 SES Removed references to nFiles.
; <1.0> 11/16/88 CCH Added to EASE.
; 3/2/87 EMT Fixed bug introduced above.
; 2/9/87 EMT Permit KCHR to be overridden Check files of type 'KCAP' for
; KMAPs Use default KMAP (0) as last resort Flush keyboard on
; exit. Dispose of myself on exit.
; 10/14/86 EMT Fix bug related to 6 Oct change above.
; 10/6/86 EMT Data area can be set up by ROM.
; 7/15/86 EMT Updated to use KCHR resource.
; 6/25/86 EMT Created.
;
;_________________________________________________________________________________________
LOAD 'StandardEqu.d'
; Keyboard driver data
KBufCount EQU 2
KBufLen EQU 10 ; 8 bytes + length + inuse
KMAPPtr EQU $00
KeyBits EQU KMAPPtr+4
KCHRPtr EQU KeyBits+(128/8)
DeadKey EQU KCHRPtr+4
KNoADBOp EQU DeadKey+4
KNumBufs EQU KNoADBOp+1
KFirstBuf EQU KNumBufs+1
KbdDSize EQU KFirstBuf+(KBufCount*KBufLen)
str EQU -$100
iopb EQU str-ioFQElSize
KISize EQU iopb
; KMAP offsets
KMid EQU $00
KMtype EQU $01
KMvers EQU KMid+2
KMstart EQU KMvers+2
KMnumEx EQU KMstart+128
KMstEx EQU KMnumEx+2
talkCmd EQU $0C ; Command for Talk R0
keypadNorsi EQU $0E ; Handler ID for Norsi ergonomic keypad
;_________________________________________________________________________________________
;
; Routine: KbdInst
; Arguments: D0.B ADB Address
; D1.B Device Type
; Output: None
; Function: Loads and locks the KMAP and KCHR resources used by the keyboard driver,
; updates the ADB table and installs a new keyboard driver
;
; Side Effects: Trashes A0, A1, D0, D2
;_________________________________________________________________________________________
KbdInst MAIN EXPORT
@Start MOVEM.L D3-D7/A2-A4, -(SP) ; Save the registers
LINK A6, #KISize ; Save space on stack
MOVE.W D0, D2 ; Save the ADB Address
SUB.L #10, SP ; Allocate space on stack
MOVE.L SP, A0 ; Pointer to data area
_GetADBInfo
ADDQ.L #2, SP ; Discard OrigAddr and DeviceType
MOVE.L 4(SP), A1 ; Put the data address in A1
MOVE.L A1, D0 ; See if it is a real address
BNE.S KCHRLoad ; Buffer already allocated by ROM
@AllocBuf MOVE.L #KbdDSize, D0 ; Amount of space needed for new keyboard drvr data
_NewPtr ,SYS,CLEAR ; Get a pointer
MOVE.L A0, A1 ; Save it in A1
MOVE.B #KBufCount, KNumBufs(A1)
KCHRLoad SUBQ.L #4, SP ; Make room for result
MOVE.L #'KCHR', -(SP) ; ResType = KCHR
CLR.W -(SP) ; theID = 0 (for now)
MOVE.W #MapTrue, ROMMapInsert ; Use ROM resource if available
_GetResource
MOVE.L (SP), -(SP) ; Save the handle
BEQ NoKCHR ; Skip if NIL
_DetachResource ; Detach it
MOVE.L (SP)+, A0
_HLock ; Lock it down
MOVE.L (A0), KCHRPtr(A1) ; Dereference and put away
; We didn't find the KMAP in the system file or ROM, try the blessed folder
MOVE.L #'KCAP', D3 ; File type
CLR.W iopb+ioVRefNum(A6) ; The blessed folder
CLR.W iopb+ioFDirIndex(A6) ; Initialize the index
LEA str(A6), A0 ; Get the address of local string
MOVE.L A0, iopb+ioFileName(A6) ; Put in iopb
MOVEQ #0, D4 ; No resource file on first pass
MOVE.W #MapTrue, ROMMapInsert ; Use ROM resource first time
FindKMAP ;
SUBQ.L #4, SP ; Make room for result
MOVE.L #'KMAP', -(SP) ; ResType = KMAP
CLR.W -(SP) ; Clear it out since Device Type is byte
MOVE.B D1, 1(SP) ; theID = DeviceType
_GetResource
MOVE.L (SP), -(SP) ; Save the handle
BNE.S GotKMAP ; Skip if not NIL
ADDQ.L #8, SP ; Clean off the stack
TST.W D4 ; File open?
BEQ.S NextFile ; Nope, go on
MOVE.W D4, -(SP) ; refNum
_CloseResFile ;
NextFile
LEA iopb(A6), A0 ; Point to the block
ADD.W #1, ioFDirIndex(A0) ; Increment the file index
_GetFileInfo ;
BMI.S NoMoreFiles ; That's all of them
CMP.L ioFlUsrWds+fdType(A0), D3 ; Correct type?
BNE.S NextFile ; Nope, try again
SUBQ.L #2, SP ; Make room for result
PEA str(A6) ; fileName
_OpenResFile ;
MOVE.W (SP)+, D4 ; Store the refNum
BRA.S FindKMAP ;
NoMoreFiles
; All is not lost. We can try to find the default KMAP (0)
SUBQ.L #4, SP ; Make room for result
MOVE.L #'KMAP', -(SP) ; ResType = KMAP
CLR.W -(SP) ; theID = 0
MOVE.W #MapTrue, ROMMapInsert ; Use ROM resource if available
_GetResource ;
MOVE.L (SP), -(SP) ; Save the handle
BEQ.S NoKMAP ; Skip if NIL
GotKMAP
; Assumes two copies of the resource handle are on the stack.
_DetachResource ; Detach it
MOVE.L (SP)+, A0
_HLock ; Lock it down
MOVE.L (A0), A0 ; Dereference it
MOVE.L A0, KMAPPtr(A1) ; Put it away
MOVE.B D1, KbdType ; Update KbdType to show this keyboard
MOVE.B D2, KbdLast ; Same with KbdLast
MOVE.W D2, D0 ; ADB Address
MOVE.L A1, 4(SP) ; Replace the data address
MOVE.L SP, A0 ; Pointer to two addresses
_SetADBInfo
TST.W D4 ; File open?
BEQ.S Done ; Nope, go on
MOVE.W D4, -(SP) ; refNum
_CloseResFile ;
BRA.S Done ;
NoKMAP
NoKCHR
ADDQ.L #8, SP ; Discard unused parameters
Done
MOVE.W D2, D0 ; ADB Address
LSL.W #4, D0 ; Put address in high nibble
ADDQ.W #1, D0 ; Flush command
CLR.L -(SP) ; No data address
CLR.L -(SP) ; No completion routine
CLR.L -(SP) ; No buffer
MOVE.L SP, A0 ; Point to the block
_ADBOp ; Flush the keyboard
LEA 12(SP), SP ; Remove parameters from stack
UNLK A6 ;
MOVEM.L (SP)+, D3-D7/A2-A4 ; Restore the registers
LEA KbdInst,A0
_RecoverHandle
_DisposeHandle
RTS ; End KbdInst
;_________________________________________________________________________________________
;_________________________________________________________________________________________
;_________________________________________________________________________________________
END ;End file