'---------------------------------------------------------------------------
'                            PS2_KBDEMUL.BAS
'                  (c) 2002-2003 MCS Electronics
'                        PS2 AT Keyboard emulator
' NOTE THAT THE LIBRARY IS AN OPTIONAL ONE and by default is not included !
'---------------------------------------------------------------------------
$regfile = "2313def.dat"
$crystal = 4000000
$baud = 19200

$lib "mcsbyteint.lbx"                   ' use optional lib since we use only bytes


'configure PS2 AT pins
Enable Interrupts                       ' you need to turn on interrupts yourself since an INT is used
Config Atemu = Int1 , Data = Pind.3 , Clock = Pinb.0
'                 ^------------------------ used interrupt
'                              ^----------- pin connected to DATA
'                                       ^-- pin connected to clock
'Note that the DATA must be connected to the used interrupt pin


Waitms 500                              ' optional delay

'rcall _AT_KBD_INIT
Print "Press t for test, and set focus to the editor window"
Dim Key2 As Byte , Key As Byte
Do
    Key2 = Waitkey()                    ' get key from terminal
    Select Case Key2
      Case "t" :
      Waitms 1500
      Sendscankbd Mark                  ' send a scan code
      Case Else
    End Select
Loop
Print Hex(key)

Mark:                                   ' send mark
Data 12 , &H3A , &HF0 , &H3A , &H1C , &HF0 , &H1C , &H2D , &HF0 , &H2D , &H42 , &HF0 , &H42
'    ^ send 12 bytes
'           m                    a                   r                    k