Tastatur Eingabe lesen



  • Hallo,
    ich habe folgendes hier gefunden: http://www.computer-engineering.org/ps2keyboard/

    Reading keyboard input: 
    
    When the 8042 recieves a valid scan code from the keyboard, it is converted to its set 1 equivalent.  The converted scan code is then placed in the input buffer, the IBF (Input Buffer Full) flag is set, and IRQ 1 is asserted.  Furthermore, when any byte is received from the keyboard, the 8042 inhibits further reception (by pulling the "Clock" line low), so no other scan codes will be received until the input buffer is emptied. 
    
    If enabled, IRQ 1 will activate the keyboard driver, pointed to by interrupt vector 0x09.  The driver reads the scan code from port 0x60, which causes the 8042 to de-assert IRQ 1 and reset the IBF flag.  The scan code is then processed by the driver, which responds to special key combinations and updates an area of the system RAM reserved for keyboard input. 
    
    If you don't want to patch into interrupt 0x09, you may poll the keyboard controller for input.  This is accomplished by disabling the 8042's IBF Interrupt and polling the IBF flag.  This flag is set (1) when data is available in the input buffer, and is cleared (0) when data is read from the input buffer.  Reading the input buffer is accomplished by reading from port 0x60, and the IBF flag is at port 0x64, bit 1.  The following assembly code illustrates this: 
    
    kbRead: 
    WaitLoop:    in     al, 64h     ; Read Status byte 
                 and    al, 10b     ; Test IBF flag (Status<1>) 
                 jz     WaitLoop    ; Wait for IBF = 1 
                 in     al, 60h     ; Read input buffer 
    
    Writing to keyboard: 
    
    When you write to the 8042's output buffer (via port 0x60), the controller sets the OBF ("Output Buffer Full") flag and processes the data.  The 8042 will send this data to the keyboard and wait for a response.  If the keyboard does not accept or generate a response within a given amount of time, the appropriate timeout flag will be set (see Status register definition for more info.)  If an incorrect parity bit is read, the 8042 will send the "Resend" (0xFE) command to the keyboard.  If the keyboard continues to send erroneous bytes, the "Parity Error" flag is set in the Status register.  If no errors occur, the response byte is placed in the input buffer, the IBF ("Input Buffer Full") flag is set, and IRQ 1 is activated, signaling the keyboard driver. 
    
    The following assembly code shows how to write to the output buffer.  (Remember, after you write to the output buffer, you should use int 9h or poll port 64h to get the keyboard's response.) 
    
    kbWrite: 
    WaitLoop:    in     al, 64h     ; Read Status byte 
                 and    al, 01b     ; Test OBF flag (Status<0>) 
                 jnz    WaitLoop    ; Wait for OBF = 0 
                 out    60h, cl     ; Write data to output buffer
    

    kbRead:
    WaitLoop: in al, 64h ; Read Status byte
    and al, 10b ; Test IBF flag (Status<1>)
    jz WaitLoop ; Wait for IBF = 1
    in al, 60h ; Read input buffer

    Wie kann ich hier jetzt den input buffer ausgeben?

    Um Text einzulesen kannst ich bisher nur die Funktion:

    mov ah,7h
    int 21h

    und

    mov ah,01h
    int 21h



  • Dafür kannst du die Funktionen des INT 0x10 benutzen.
    (INT 0x21 setzt DOS als OS voraus)



  • int10 schrieb:

    Dafür kannst du die Funktionen des INT 0x10 benutzen.
    (INT 0x21 setzt DOS als OS voraus)

    Du meinst wahrscheinlich den BIOS Interrupt 0x16. Hinter 0x10 steckt das Grafik-System. Vorteil dieser Funktionen ist, sie sind einfach zu benutzen, im RealMode sofort verfuegbar, und bieten eine Uebersetzung der Scancodes in ASCII.
    Nachteil: BIOS-Funktionen und laeuft eben nur im RealMode.

    Fuer weitere Details zur Tastaturhardware empfehle ich auch einen Blick in Erhards OS-Entwicklungsforum. => http://www.c-plusplus.net/forum/f62


Anmelden zum Antworten