var KB : module

    imports (var BIOS, byteregs)
    exports (ReadKeyboard, KeyboardStatus)

    {	Computer Systems Research Institute
	University of Toronto

	Module: MS-DOS BIOS Keyboard Interface  V1.10
	Author:	James R. Cordy
	Date:	9 May 1984  (Rev 4 Dec 1985) }

    { Copyright 1984, 1985  The University of Toronto }


    { BIOS Registers }
    var inregs : REGS := ZEROREGS
    var outregs : REGS
    var outflags : FLAGS


    procedure ReadKeyboard (var scanPlusAscii : SignedInt) =
	imports (var BIOS, var inregs, var outregs, byteregs, var outflags)
	begin
	    byteregs (inregs) (AHREG) := KBREADCHAR
	    outflags := BIOS.int86 (outregs, inregs, KBDSR)
	    scanPlusAscii := outregs (AXREG)
	end ReadKeyboard

    function KeyboardStatus returns st : SignedInt =
	{ This function will unavoidably get 'function imports var' warnings }
	imports (var BIOS, var inregs, var outregs, byteregs, var outflags)
	begin
	    byteregs (inregs) (AHREG) := KBSTATUS
	    outflags := BIOS.int86 (outregs, inregs, KBDSR)
	    if ZFLAG not in outflags then
		return (outregs (AXREG))
	    end if
	    return (-1)
	end KeyboardStatus
end module
