  ; ------------------
  MOUSECOMMAND_RESET                    EQU     0xFF  ; The reset command
  MOUSECOMMAND_RESEND                   EQU     0xFE  ; Resend the last packet
  MOUSECOMMAND_SETDEFAULTS              EQU     0xF6  ; Set default values
  MOUSECOMMAND_DISABLE_DATAREPORTING    EQU     0xF5  ; Disable data reporting
  MOUSECOMMAND_ENABLE_DATAREPORTING     EQU     0xF4  ; Enable data reporting
  MOUSECOMMAND_SET_SAMPLERATE           EQU     0xF3  ; Set the sample rate
  MOUSECOMMAND_GET_DEVICEID             EQU     0xF2  ; Get the device's ID
  MOUSECOMMAND_SET_REMOTEMODE           EQU     0xF0  ; Enter Remote Mode
  MOUSECOMMAND_SET_WRAPMODE             EQU     0xEE  ; Enter Wrap Mode
  MOUSECOMMAND_RESET_WRAPMODE           EQU     0xEC  ; Enter the previous Mode before Wrap
  MOUSECOMMAND_READ_DATA                EQU     0xEB  ; Read Movement Packet
  MOUSECOMMAND_SET_STREAMMODE           EQU     0xEA  ; Enter Stream Mode
  MOUSECOMMAND_STATUS_REQUEST           EQU     0xE9  ; Request 3 byte status packet
  MOUSECOMMAND_SET_RESOLUTION           EQU     0xE8  ; Set Mouse's resolution (count/mm)
  MOUSECOMMAND_SET_SCALING2             EQU     0xE7  ; Enable 2:1 scaling
  MOUSECOMMAND_SET_SCALING1             EQU     0xE6  ; Enable 1:1 scaling
  ; ------------------
  ; Keyboard commands should be sent to Port 0x60 with __KeyboardSendGetCommand
  KBDCOMMAND_RESET                      EQU     0xFF  ; Reset the keyboard
  KBDCOMMAND_RESEND                     EQU     0xFE  ; Resend the last packet
  KBDCOMMAND_SET_KEYTYPEMAKE            EQU     0xFD  ; Disable break codes and typematic
  KBDCOMMAND_SET_KEYTYPE_MAKEBREAK      EQU     0xFC  ; Disable typematic repeat
  KBDCOMMAND_SET_KEYTYPE_TYPEMATIC      EQU     0xFB  ; Disable break codes
  KBDCOMMAND_SET_ALLKEYS_TYPEMATICMKBR  EQU     0xFA  ; Set all keys to default
  KBDCOMMAND_SET_ALLKEYS_MAKE           EQU     0xF9  ; Apply 0xFD to all keys
  KBDCOMMAND_SET_ALLKEYS_MAKEBREAK      EQU     0xF8  ; Apply 0xFC to all keys
  KBDCOMMAND_SET_ALLKEYS_TYPEMATIC      EQU     0xF7  ; Apply 0xFB to all keys
  KBDCOMMAND_SET_DEFAULT                EQU     0xF6  ; Load all default values
  KBDCOMMAND_DISABLE                    EQU     0xF5  ; Disable the keyboard
  KBDCOMMAND_ENABLE                     EQU     0xF4  ; Enable the keyboard
  KBDCOMMAND_SET_TYPEMATIC_RATEDELAY    EQU     0xF3  ; Set Typematic Rate/Delay
  KBDCOMMAND_READID                     EQU     0xF2  ; Read Keyboard's ID
  KBDCOMMAND_SET_SCANCODESET            EQU     0xF0  ; Set Scan Code Set
  KBDCOMMAND_ECHO                       EQU     0xEE  ; Echo the keyboard
  KBDCOMMAND_SETRESET_LEDS              EQU     0xED  ; Set LEDs on keyboard
  ; ------------------
  ; Onboard commands should be sent to Port 0x64 with __KeyboardSendCommand
  KBDCOMMAND_ONBOARD_GETCOMMANDBYTE     EQU     0x20  ; Get command byte at 0x60
  KBDCOMMAND_ONBOARD_SETCOMMANDBYTE     EQU     0x60  ; Set command byte on 0x60
  KBDCOMMAND_ONBOARD_TESTPASSWORD       EQU     0xA4  ; Test the password (PS/2)
  KBDCOMMAND_ONBOARD_TRANSMITPASSWORD   EQU     0xA5  ; Transmit the password (PS/2)
  KBDCOMMAND_ONBOARD_PASSWORDMATCH      EQU     0xA6  ; Password Match
  KBDCOMMAND_ONBOARD_DISABLEMOUSE       EQU     0xA7  ; Disable Mouse Device (PS/2)
  KBDCOMMAND_ONBOARD_ENABLEMOUSE        EQU     0xA8  ; Enable Mouse Device (PS/2)
  KBDCOMMAND_ONBOARD_TESTMOUSE          EQU     0xA9  ; Test Mouse Device
  KBDCOMMAND_ONBOARD_INITSELFTEST       EQU     0xAA  ; Initialize Self-Test
  KBDCOMMAND_ONBOARD_TESTINTERFACE      EQU     0xAB  ; Keyboard Test Interface
  KBDCOMMAND_ONBOARD_DIAGNOSTIC         EQU     0xAC  ; Diagnostic tool (Not on PS/2)
  KBDCOMMAND_ONBOARD_DISABLE            EQU     0xAD  ; Disable Keyboard
  KBDCOMMAND_ONBOARD_ENABLE             EQU     0xAE  ; Enable Keyboard
  KBDCOMMAND_ONBOARD_WRITETOMOUSE       EQU     0xD4  ; Writ to the mouse device (PS/2)
  ; ------------------
  ; Command Byte's Bit Positions
  COMMANDBYTE_KEYBOARD_INTERRUPT        EQU     0x01  ; Keyboard Interrupts Enabled
  COMMANDBYTE_MOUSE_INTERRUPT           EQU     0x02  ; Mouse Interrupts Enabled
  COMMANDBYTE_SYSTEMFLAG                EQU     0x04  ; System Flag
  COMMANDBYTE_OVERRIDE                  EQU     0x08  ; PC/AT Inhibit Override
  COMMANDBYTE_KBDDISABLE                EQU     0x10  ; Keyboard Disable
  COMMANDBYTE_KBDENABLE                 EQU     0x20  ; PC/AT Keyboard Enable - PS/2 Mouse Disable
  COMMANDBYTE_COMPATIBILITYMODE         EQU     0x40  ; PC Compatibility Mode
  COMMANDBYTE_MUSTBEZERO                EQU     0x80  ; Alwasy Zero, Reserved
  COMMANDBYTE_BOTH_INTERRUPTS           EQU     COMMANDBYTE_MOUSE_INTERRUPT | \
                                                COMMANDBYTE_KEYBOARD_INTERRUPT 
; --------------------------------------------------
  __SetUpMouse:
    ; void __SetUpMouse (void)
    PUSH    EAX                                                                   ; Push the accumulator onto the stack
    INVOKE  __KeyboardSendCommand , KBDCOMMAND_ONBOARD_ENABLEMOUSE                ; Enable the PS/2 Mouse
    INVOKE  __KeyboardGetCommandByte                                              ; Read the command byte
    OR      EAX , COMMANDBYTE_BOTH_INTERRUPTS                                     ; Enable Keyboard/Mouse interrupts
    INVOKE  __KeyboardSetCommandByte , EAX                                        ; Enable the interrupts now
    INVOKE  __MouseSendGetData , MOUSECOMMAND_DISABLE_DATAREPORTING , 0x01        ; Disable data reporting in mouse
    INVOKE  __MouseSendGetData , MOUSECOMMAND_SET_STREAMMODE , 0x01               ; Enter Stream Mode
    INVOKE  __MouseSendGetData , MOUSECOMMAND_ENABLE_DATAREPORTING , 0x01         ; Enable data reporting now
    POP     EAX                                                                   ; Restore the accumulator
    RET                                                                           ; Return to the callin procedure
; --------------------------------------------------
  __MouseSendGetData:
    ; DWORD __MouseSendGetData (DWORD Command, DWORD NumberOfBytesToGet)
    ; Description:  Sends the [Command] parameter to the PS/2 mouse using the Keyboard's
    ;               Microcontroller at port 0x64. The [NumberOfBytesToGet] parameter should
    ;               be the number of bytes you expect from the command to be returned. Normally
    ;               this parameter should be set to 0x01 but for commands such as
    ;               MOUSECOMMAND_READ_DATA, this parameter will differ.
    PUSH    ECX
    PUSH    EBP                                       ; Push the base pointer onto the stack
    MOV     EBP , ESP                                 ; Move the stack pointer to the base pointer
    MOV     EAX , DWORD PTR [EBP + 0x10]              ; Move the [NumberOfBytesToGet] parameter to the EAX register
    TEST    EAX , EAX                                 ; See if there are zero number of bytes to be read
    JZ      .EP                                       ; Jump to the end of the procedure if yes
    MOV     ECX , EAX                                 ; The [NumberOfBytesToGet] is now in the ECX register
    MOV     EAX , DWORD PTR [EBP + 0x0C]              ; EAX now holds the [Command] parameter
    AND     EAX , 0x000000FF                          ; Command should be one byte 
    SHL     EAX , 0x00000008                          ; Move the Byte Command to the AH register
    .WaitInput:                                       ; Wait for keyboard's input line to be empty
      IN      AL , 0x64                               ; Read the keyboard's status byte
      TEST    AL , 0x02                               ; See if the keyboard's input line is empty yet
      JNZ     .WaitInput                              ; Keep checking if not
    MOV     AL , 0xD4                                 ; Write to PS/2 Mouse Device Command
    OUT     0x64 , AL                                 ; Send the command to keyboard's microcontroller
    SHR     EAX , 0x08                                ; Move the command to AL now
    OUT     0x60 , AL                                 ; Write the command to port 0x60
    XOR     EAX , EAX                                 ; Clear the result for now
    .WaitOutput:                                      ; Wait for the result to be ready
      IN      AL , 0x64                               ; Read the keyboard's status byte
      TEST    AL , 0x01                               ; See if the output line is full yet (Data ready?)
      JZ      .WaitOutput                             ; Keep checking if not
    IN      AL , 0x60                                 ; Read the data into AL now
    ROL     EAX , 0x00000008                          ; Rotate the last read byte to the right (Shuffle)s
    DEC     ECX                                       ; Decrement the counter
    JNZ     .WaitOutput                               ; Keep reading bytes if [NumberOfBytesToGet] is not zero yet
    .EP:                                              ; End of the procedure
      POP     EBP                                     ; Restore the base pointer
      POP     ECX                                     ; Restore the count register
    RET     0x08                                      ; Return to the calling procedure
                                                      ; And sweep 1 parameter off the stack
; --------------------------------------------------
  __KeyboardSendGetCommand:
    ; DWORD __KeyboardSendGetCommand (DWORD Command, DWORD NumberOfBytesToGet)
    ; Sends and receives commands to and from Port 0x60
    PUSH    ECX                                       ; Push the count register onto the stack
    PUSH    EBP                                       ; Push the base pointer onto the stack
    MOV     EBP , ESP                                 ; Move the stack pointer to the base pointer
    MOV     EAX , DWORD PTR [EBP + 0x10]              ; EAX holds the value of [NumberOfBytesToGet] parameter
    TEST    EAX , EAX                                 ; See if this value is zero
    JZ      .EP                                       ; Jump to the end of the procedure if yes (Nothing to read)
    MOV     ECX , EAX                                 ; ECX now holds the value of [NumberOfBytesToGet] parameter
    MOV     EAX , DWORD PTR [EBP + 0x0C]              ; EAX holds the value of the [Command] parameter
    AND     EAX , 0x000000FF                          ; Parameters shouldn't be more than 1 byte long
    SHL     EAX , 0x00000008                          ; Get the [Command] parameter in the AH register
    .WaitInput1:                                      ; Wait for the Keyboard's onboard controller input line to be free
      IN      AL , 0x64                               ; Read the Status Byte in the AL register
      TEST    AL , 0x02                               ; See if the Input Line is free yet
      JNZ     .WaitInput1                             ; Keep checking if not
    SHR     EAX , 0x00000008                          ; Get the [Command] parameter in the AL register now
    OUT     0x60 , AL                                 ; Send the command to the keyboard microcontoller
    .WaitOutput:                                      ; Wait for a result to be ready at port 0x60
      IN      AL , 0x64                               ; Read the status byte of the Onboard Microcontoller
      TEST    AL , 0x01                               ; See if a result is ready yet
      JZ      .WaitOutput                             ; Keep checking if not
    IN      AL , 0x60                                 ; Read the byte from the keyboard's microcontroller
    ROL     EAX , 0x00000008                          ; Rotate the byte to the left, 8 bits (Shuffle)
    DEC     ECX                                       ; Decrement the counter
    JNZ     .WaitOutput                               ; Keep reading if [NumberOfBytesToGet] is not zero yet
    .EP:                                              ; End of the procedure
      POP     EBP                                     ; Restore the base pointer
      POP     ECX                                     ; Restore the count register
    RET     0x08                                      ; Return to the calling procedure
                                                      ; And sweep 2 parameters off the stack
; --------------------------------------------------
  __KeyboardSendCommand:
    ; void __KeyboardSendCommand (DWORD Command)
    ; ; Sends command to Port 0x64
    PUSH    EAX                                       ; Push the accumulator onto the stack
    PUSH    EBP                                       ; Push the base pointer onto the stack
    MOV     EBP , ESP                                 ; Move the stack pointer to the base pointer
    .WaitInput:                                       ; Wait for the Keyboard's onboard controller's input line to be free
      IN      AL , 0x64                               ; Read the status byte from the Keyboard's onboard controller
      TEST    AL , 0x02                               ; See if the input line is free yet
      JNZ     .WaitInput                              ; Keep checking if not
    MOV     EAX , DWORD PTR [EBP + 0x0C]              ; EAX now holds the value of the [Command] parameter
    OUT     0x64 , AL                                 ; Send the [Command] parameter to the Keyboard's Onboard Controller
    POP     EBP                                       ; Restore the base pointer
    POP     EAX                                       ; Restore the accumulator
    RET     0x04                                      ; Return to the calling procedure
                                                      ; And sweep 1 parameter off the stack
; --------------------------------------------------
  __KeyboardSetCommandByte:
    ; void __KeyboardSetCommandByte (DWORD CommandByte)
    PUSH    EAX                                       ; Push the accumulator onto the stack
    PUSH    EBP                                       ; Push the base pointer onto the stack
    MOV     EBP , ESP                                 ; Move the stack pointer to the base pointer
    .WaitInput1:                                      ; Wait for the Input Line of Keyboard's Onboard Controller to be free
      IN      AL , 0x64                               ; Read the status byte of the Keyboard's Onboard Controller
      TEST    AL , 0x02                               ; See if the Input Line is free yet
      JNZ     .WaitInput1                             ; Keep checking if not
    MOV     AL , KBDCOMMAND_ONBOARD_SETCOMMANDBYTE    ; Need to set the Command Byte of the Keyboard
    OUT     0x64 , AL                                 ; Tell the Keyboard Onboard Controller about this
    .WaitInput2:                                      ; Wait for the Input Line to be free again
      IN      AL , 0x64                               ; Read the status byte once more
      TEST    AL , 0x02                               ; Check and see if the Input Line is free yet
      JNZ     .WaitInput2                             ; Keep checking if not
    MOV     EAX , DWORD PTR [EBP + 0x0C]              ; EAX now holds the value of the [CommandByte] parameter
    OUT     0x60 , AL                                 ; Put the command in the Keyboard's Microcontroller
    POP     EBP                                       ; Restore the base pointer
    POP     EAX                                       ; Restore the accumulator
    RET     0x04                                      ; Return to the calling procedure
                                                      ; And sweep 1 parameter off the stack
; --------------------------------------------------
  __KeyboardGetCommandByte:
    ; DWORD __KeyboardGetCommandByte (void)
    XOR     EAX , EAX                                 ; Clear the content of the result of the function temporarily
    .WaitInput1:                                      ; Wait for the Input Line of Keyboard's Onboard Controller to be free
      IN      AL , 0x64                               ; Read the status byte of the Keyboard's Onboard Controller
      TEST    AL , 0x02                               ; See if the Input Line is free yet
      JNZ     .WaitInput1                             ; Keep checking if not
    MOV     AL , KBDCOMMAND_ONBOARD_GETCOMMANDBYTE    ; Need to get the command byte from the Keyboard's Microcontroller
    OUT     0x64 , AL                                 ; Tell the Onboard Controller about this command
    .WaitInput2:                                      ; Wait for the Input Line to be free again
      IN      AL , 0x64                               ; Read the Status Byte of the Onboard Controller
      TEST    AL , 0x02                               ; See if the Input Line is free yet
      JNZ     .WaitInput2                             ; Keep checking if not
    IN      AL , 0x60                                 ; Read the Command Byte from the Keyboard's Microcontroller now
    RET                                               ; Return to the calling procedure
; --------------------------------------------------