home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / emulate / systems / apple / keyboard.asm < prev    next >
Assembly Source File  |  1990-04-02  |  61KB  |  1,640 lines

  1.     Page    58,132
  2.     Title    KEYBOARD.ASM    Apple Emulator Keyboard Routines
  3. ;******************************************************************************
  4. ;
  5. ;   Name:    KEYBOARD.ASM    Apple Emulator Keyboard Routines
  6. ;
  7. ;   Group:    Emulator
  8. ;
  9. ;   Revision:    1.00
  10. ;
  11. ;   Date:    January 30, 1988
  12. ;
  13. ;   Author:    Randy W. Spurlock
  14. ;
  15. ;******************************************************************************
  16. ;
  17. ;  Module Functional Description:
  18. ;
  19. ;        This module contains all the code for the Apple keyboard
  20. ;    routines.
  21. ;
  22. ;******************************************************************************
  23. ;
  24. ;  Changes:
  25. ;
  26. ;    DATE     REVISION                DESCRIPTION
  27. ;  --------   --------    -------------------------------------------------------
  28. ;   1/30/88    1.00    Original
  29. ;
  30. ;******************************************************************************
  31.     Page
  32. ;
  33. ;  Public Declarations
  34. ;
  35.     Public    Keyboard_Input        ; Keyboard input routine
  36.     Public    Clear_Keyboard        ; Clear keyboard strobe routine
  37.     Public    Key_Int         ; Keyboard interrupt routine
  38.     Public    Set_LED         ; Set keyboard LED routine
  39.     Public    Flush_Keyboard        ; Flush keyboard routine
  40.     Public    Get_Key         ; Get keyboard scan code routine
  41.     Public    Key_Reset        ; Keyboard reset routine
  42.     Public    Key_Status        ; Keyboard status byte
  43.     Public    Last_Key        ; Last actual keyboard code
  44.     Public    Last_Scan        ; Last keyboard scan code
  45. ;
  46. ;  External Declarations
  47. ;
  48.     Extrn    Update_Toggle:Near    ; Update mode toggle routine      (EGA)
  49.     Extrn    System_Reset:Near    ; System reset routine        (APPLE)
  50.     Extrn    System_Request:Near    ; System request routine    (APPLE)
  51.     Extrn    Joystick_Fast:Near    ; Joystick fast mode routine (JOYSTICK)
  52.     Extrn    Joystick_Flight:Near    ; Joystick flight routine    (JOYSTICK)
  53.     Extrn    Joystick_Center:Near    ; Joystick center routine    (JOYSTICK)
  54.     Extrn    Joystick_Reset:Near    ; Joystick reset routine     (JOYSTICK)
  55.     Extrn    Joystick_Mode:Near    ; Joystick mode routine      (JOYSTICK)
  56.     Extrn    Joystick_Type:Near    ; Joystick type routine      (JOYSTICK)
  57.     Extrn    Joystick_Dummy:Near    ; Joystick dummy routine     (JOYSTICK)
  58.     Extrn    Joy_Up_Left:Near    ; Joystick up/left routine   (JOYSTICK)
  59.     Extrn    Joy_Up:Near        ; Joystick up routine         (JOYSTICK)
  60.     Extrn    Joy_Up_Right:Near    ; Joystick up/right routine  (JOYSTICK)
  61.     Extrn    Joy_Left:Near        ; Joystick left routine      (JOYSTICK)
  62.     Extrn    Joy_Center:Near     ; Joystick center routine    (JOYSTICK)
  63.     Extrn    Joy_Right:Near        ; Joystick right routine     (JOYSTICK)
  64.     Extrn    Joy_Down_Left:Near    ; Joystick down/left routine (JOYSTICK)
  65.     Extrn    Joy_Down:Near        ; Joystick down routine      (JOYSTICK)
  66.     Extrn    Joy_Down_Right:Near    ; Joystick down/right routine(JOYSTICK)
  67.     Extrn    Joy_X_Res_Inc:Near    ; Joystick X resolution inc. (JOYSTICK)
  68.     Extrn    Joy_X_Res_Dec:Near    ; Joystick X resolution dec. (JOYSTICK)
  69.     Extrn    Joy_Y_Res_Inc:Near    ; Joystick Y resolution inc. (JOYSTICK)
  70.     Extrn    Joy_Y_Res_Dec:Near    ; Joystick Y resolution dec. (JOYSTICK)
  71.     Extrn    Joy_X_Cen_Inc:Near    ; Joystick X center increment(JOYSTICK)
  72.     Extrn    Joy_X_Cen_Dec:Near    ; Joystick X center decrement(JOYSTICK)
  73.     Extrn    Joy_Y_Cen_Inc:Near    ; Joystick Y center increment(JOYSTICK)
  74.     Extrn    Joy_Y_Cen_Dec:Near    ; Joystick Y center decrement(JOYSTICK)
  75.     Extrn    Joy_Button_1:Near    ; Joystick button one         (JOYSTICK)
  76.     Extrn    Joy_Button_2:Near    ; Joystick button two         (JOYSTICK)
  77.     Extrn    System_Flag:Byte    ; Apple emulator system flag byte(DATA)
  78. ;
  79. ;  LOCAL Equates
  80. ;
  81. DATA_PORT    Equ    60h        ; Keyboard data port address (60h)
  82. COMMAND_PORT    Equ    64h        ; Keyboard command port address (64h)
  83. OUTPUT_FULL    Equ    01h        ; Output buffer full flag bit
  84. INPUT_EMPTY    Equ    02h        ; Input buffer empty flag bit
  85. KEY_CODE    Equ    7Fh        ; Keyboard scan code mask value
  86. KEY_MASK    Equ    07h        ; Keyboard status mask value
  87. KEY_SHIFT    Equ    03h        ; Keyboard shift value
  88. LED_MASK    Equ    0E0h        ; Keyboard status LED mask value
  89. LED_SHIFT    Equ    05h        ; Keyboard status LED shift value
  90. INT_PORT    Equ    20h        ; Interrupt controller port
  91. INT_ACK     Equ    20h        ; Interrupt acknowledge value
  92. KEY_DOWN    Equ    80h        ; Key held down flag bit
  93. KEY_STROBE    Equ    80h        ; Key has been pressed flag bit
  94. TAB        Equ    09h        ; Tab key translated code value
  95. UP_ARROW    Equ    0Bh        ; Up arrow translated code value
  96. LEFT_ARROW    Equ    08h        ; Left arrow translated code value
  97. RIGHT_ARROW    Equ    15h        ; Right arrow translated code value
  98. DOWN_ARROW    Equ    0Ah        ; Down arrow translated code value
  99. DEL_CODE    Equ    7Fh        ; DEL key translated code value
  100. DISABLE_KEY    Equ    0ADh        ; Disable keyboard function code
  101. ENABLE_KEY    Equ    0AEh        ; Enable keyboard function code
  102. LED_SET     Equ    0EDh        ; Set keyboard LED's function code
  103. TIME_OUT    Equ    0FFFFh        ; 8042 time out counter value
  104. Key_Data    Equ    0C000h        ; Keyboard data storage byte
  105. Any_Key     Equ    0C010h        ; Any key down storage byte
  106. Key_LED     Equ    0097h        ; BIOS keyboard LED status byte (40:97h)
  107. ;
  108. ;  Define any include files needed
  109. ;
  110.     Include     Macros.inc    ; Include the macro definitions
  111.     Include     Equates.inc    ; Include the equate definitions
  112.     .286c                ; Include 80286 instructions
  113.     Page
  114. ;
  115. ;  Define the emulator code segment
  116. ;
  117. Emulate Segment Word Public 'EMULATE'   ; Emulator code segment
  118.     Assume    cs:Emulate, ds:Nothing, es:Nothing
  119.     Subttl    Keyboard_Input    Keyboard Input Routine
  120.     Page    +
  121. ;******************************************************************************
  122. ;
  123. ;    Keyboard_Input()
  124. ;
  125. ;        Read the keyboard data byte (C000h)
  126. ;        Return to the caller
  127. ;
  128. ;    Registers on Entry:
  129. ;
  130. ;        None
  131. ;
  132. ;    Registers on Exit:
  133. ;
  134. ;        AL    - Keyboard data
  135. ;
  136. ;******************************************************************************
  137.         Even            ; Force procedure to even address
  138. Keyboard_Input    Proc    Near        ; Keyboard input procedure
  139.     mov    al,ds:[Key_Data]    ; Read the keyboard data byte
  140.     ret                ; Return to the caller
  141. Keyboard_Input    Endp            ; End of the Keyboard_Input procedure
  142.     Subttl    Clear_Keyboard    Clear Keyboard Strobe Routine
  143.     Page    +
  144. ;******************************************************************************
  145. ;
  146. ;    Clear_Keyboard()
  147. ;
  148. ;        Clear the keyboard strobe (C000h)
  149. ;        Clear the any key down flag (C010h)
  150. ;        Return to the caller
  151. ;
  152. ;    Registers on Entry:
  153. ;
  154. ;        None
  155. ;
  156. ;    Registers on Exit:
  157. ;
  158. ;        None
  159. ;
  160. ;******************************************************************************
  161.         Even            ; Force procedure to even address
  162. Clear_Keyboard    Proc    Near        ; Clear keyboard input procedure
  163.     and    ds:[Key_Data],Not KEY_STROBE
  164.     and    ds:[Any_Key],Not KEY_DOWN
  165.     ret                ; Return to the caller
  166. Clear_Keyboard    Endp            ; End of the Clear_Keyboard procedure
  167.     Subttl    Key_Int     Keyboard Interrupt Routine
  168.     Page    +
  169. ;******************************************************************************
  170. ;
  171. ;    Key_Int()
  172. ;
  173. ;        Save the required registers
  174. ;        Get the key from the input port (60h)
  175. ;        Translate scan code into keyboard code value
  176. ;        If special keyboard scan code
  177. ;            Call correct routine to handle scan code
  178. ;        Else this is a standard keyboard scan code
  179. ;            If this is a make code
  180. ;                    Set the keyboard strobe bit
  181. ;                    Save as last keyboard code
  182. ;                If keyboard not in input mode
  183. ;                    Set the any key down flag bit
  184. ;                    Save the keyboard data value
  185. ;                Endif
  186. ;            Endif
  187. ;        Endif
  188. ;        Save the last scan code value
  189. ;        Acknowledge the interrupt controller
  190. ;        Restore the required registers
  191. ;        Return to the caller (Interrupt return)
  192. ;
  193. ;    Registers on Entry:
  194. ;
  195. ;        None
  196. ;
  197. ;    Registers on Exit:
  198. ;
  199. ;        None
  200. ;
  201. ;******************************************************************************
  202.         Even            ; Force procedure to even address
  203. Key_Int     Proc    Near        ; Keyboard interrupt procedure
  204.     Save    ax,bx,cx        ; Save the required registers
  205.     in    al,DATA_PORT        ; Get the keyboard scan code
  206.     mov    ah,al            ; Save scan code value in AH
  207.     and    al,KEY_CODE        ; Mask off all but keyboard scan code
  208.     mov    bl,al            ; Move scan code into BL register
  209.     xor    bh,bh            ; Convert scan code to full word
  210.     mov    cl,cs:[Key_Status]    ; Get the keyboard status value
  211.     mov    ch,cl            ; Get a copy of the keyboard status
  212.     and    ch,cs:[bx+Caps_Table]    ; Mask with the caps table entry
  213.     rol    ch,1            ; Shift caps status to shifted bit
  214.     xor    cl,ch            ; Set shift status to correct state
  215.     and    cx,KEY_MASK        ; Mask off all but desired bits
  216.     shl    bx,KEY_SHIFT        ; Convert scan code to table index
  217.     add    bx,cx            ; Compute actual table entry
  218.     mov    bl,cs:[bx+Key_Translate]; Translate the keyboard scan code
  219.     or    bl,bl            ; Set the status bits correctly
  220.     js    Special_Key        ; Jump if this is a special key
  221.     or    ah,ah            ; Check for a make/break code
  222.     js    Key_Break        ; Jump if this is a break code
  223. Key_Make:
  224.     or    bl,KEY_STROBE        ; Set the keyboard strobe bit
  225.     mov    cs:[Last_Key],bl    ; Save last actual keyboard code
  226.     test    cs:[System_Flag],INPUT    ; Check for keyboard in input mode
  227.     jnz    Key_Done        ; Jump if NOT in normal keyboard mode
  228.     or    Byte Ptr ds:[Any_Key],KEY_DOWN
  229.     mov    ds:[Key_Data],bl    ; Save keyboard data for 65C02
  230.     jmp    Short Key_Done        ; Go return to the caller
  231. Key_Break:
  232.     and    Byte Ptr ds:[Any_Key],Not KEY_DOWN
  233.     jmp    Short Key_Done        ; Go return to the caller
  234. Special_Key:
  235.     shl    bl,1            ; Convert key code to table index
  236.     xor    bh,bh            ; Convert table index to full word
  237.     call    cs:[bx + Key_Table]    ; Call the correct key routine
  238. Key_Done:
  239.     mov    al,INT_ACK        ; Get interrupt acknowledge value
  240.     out    INT_PORT,al        ; Send acknowledgement to controller
  241.     mov    cs:[Last_Scan],ah    ; Save the last scan code value
  242.     Restore ax,bx,cx        ; Restore the required registers
  243.     iret                ; Return to the caller (Interrupt)
  244. Key_Int     Endp            ; End of the Key_Int procedure
  245.     Subttl    Flush_Keyboard    Flush Keyboard Routine
  246.     Page    +
  247. ;******************************************************************************
  248. ;
  249. ;    Flush_Keyboard()
  250. ;
  251. ;        Clear the keyboard strobe
  252. ;        Return to the caller
  253. ;
  254. ;    Registers on Entry:
  255. ;
  256. ;        None
  257. ;
  258. ;    Registers on Exit:
  259. ;
  260. ;        None
  261. ;
  262. ;******************************************************************************
  263.         Even            ; Force procedure to even address
  264. Flush_Keyboard    Proc    Near        ; Flush keyboard input procedure
  265.     and    Byte Ptr cs:[Last_Key],Not KEY_STROBE
  266.     ret                ; Return to the caller
  267. Flush_Keyboard    Endp            ; End of the Flush_Keyboard procedure
  268.     Subttl    Get_Key     Get Keyboard Scan Code Routine
  269.     Page    +
  270. ;******************************************************************************
  271. ;
  272. ;    Get_Key()
  273. ;
  274. ;        While no keyboard strobe
  275. ;            Wait for keyboard strobe
  276. ;        EndWhile
  277. ;        Clear the keyboard strobe
  278. ;        Get the keyboard scan code
  279. ;        Return to the caller
  280. ;
  281. ;    Registers on Entry:
  282. ;
  283. ;        None
  284. ;
  285. ;    Registers on Exit:
  286. ;
  287. ;        AL    - Keyboard scan code
  288. ;
  289. ;******************************************************************************
  290.         Even            ; Force procedure to even address
  291. Get_Key     Proc    Near        ; Clear keyboard input procedure
  292.     test    cs:[Last_Key],KEY_STROBE; Check for a keyboard strobe
  293.     jz    Get_Key         ; Jump if no key is available
  294.     and    Byte Ptr cs:[Last_Key],Not KEY_STROBE
  295.     mov    al,cs:[Last_Key]    ; Get the last actual key scan code
  296.     ret                ; Return to the caller
  297. Get_Key     Endp            ; End of the Get_Key procedure
  298.     Subttl    Illegal_Key    Illegal Scan Code Routine
  299.     Page    +
  300. ;******************************************************************************
  301. ;
  302. ;    Illegal_Key(Scan_Code)
  303. ;
  304. ;        Get the last scan code value (No scan code change)
  305. ;        Return to the caller
  306. ;
  307. ;    Registers on Entry:
  308. ;
  309. ;        AL    - Scan code value
  310. ;        AH    - Original scan code
  311. ;
  312. ;    Registers on Exit:
  313. ;
  314. ;        None
  315. ;
  316. ;******************************************************************************
  317.         Even            ; Force procedure to even address
  318. Illegal_Key    Proc    Near        ; Illegal scan code procedure
  319.     mov    ah,cs:[Last_Scan]    ; Get last scan code for key save
  320.     ret                ; Return to the caller
  321. Illegal_Key    Endp            ; End of the Illegal_Key procedure
  322.     Subttl    Control_Key    Control Key Routine
  323.     Page    +
  324. ;******************************************************************************
  325. ;
  326. ;    Control_Key(Scan_Code)
  327. ;
  328. ;        If this is a make code
  329. ;            Set the control bit in the keyboard status
  330. ;        Else this is a break code
  331. ;            Clear the control bit in the keyboard status
  332. ;        Endif
  333. ;        Return to the caller
  334. ;
  335. ;    Registers on Entry:
  336. ;
  337. ;        AL    - Control key scan code
  338. ;        AH    - Original scan code
  339. ;
  340. ;    Registers on Exit:
  341. ;
  342. ;        None
  343. ;
  344. ;******************************************************************************
  345.         Even            ; Force procedure to even address
  346. Control_Key    Proc    Near        ; Control key procedure
  347.     or    ah,ah            ; Check for a make or break code
  348.     js    Control_Break        ; Jump if this is a break code
  349. Control_Make:
  350.     or    Byte Ptr cs:[Key_Status],CTRLED
  351.     jmp    Short Control_Done    ; Go return to the caller
  352. Control_Break:
  353.     and    Byte Ptr cs:[Key_Status],Not CTRLED
  354. Control_Done:
  355.     ret                ; Return to the caller
  356. Control_Key    Endp            ; End of the Control_Key procedure
  357.     Subttl    Tab_Key     Tab Key Routine
  358.     Page    +
  359. ;******************************************************************************
  360. ;
  361. ;    Tab_Key(Scan_Code)
  362. ;
  363. ;        If NOT in joystick mode
  364. ;            If this is a make code
  365. ;                Get the tab key code
  366. ;                Set the any key down flag bit
  367. ;                Set the keyboard strobe bit
  368. ;                Save the keyboard data value
  369. ;            Endif
  370. ;        Else in the joystick mode
  371. ;            Call the joystick button 1 routine
  372. ;        Endif
  373. ;        Return to the caller
  374. ;
  375. ;    Registers on Entry:
  376. ;
  377. ;        AL    - Tab key scan code
  378. ;        AH    - Original scan code
  379. ;
  380. ;    Registers on Exit:
  381. ;
  382. ;        None
  383. ;
  384. ;******************************************************************************
  385.         Even            ; Force procedure to even address
  386. Tab_Key     Proc    Near        ; Tab key procedure
  387.     test    Byte Ptr cs:[Key_Status],JOY_MODE
  388.     jnz    Do_Button        ; Jump if this is joystick mode
  389.     or    ah,ah            ; Check for a make or break code
  390.     js    Tab_Done        ; Jump if this is a break code
  391.     mov    bl,TAB            ; Get the tab translated code
  392.     or    Byte Ptr ds:[Any_Key],KEY_DOWN
  393.     or    bl,KEY_STROBE        ; Set the keyboard strobe bit
  394.     mov    ds:[Key_Data],bl    ; Save the keyboard data value
  395.     jmp    Short Tab_Done        ; Go return to the caller
  396. Do_Button:
  397.     call    Joy_Button_1        ; Call the joystick button 1 routine
  398. Tab_Done:
  399.     ret                ; Return to the caller
  400. Tab_Key     Endp            ; End of the Tab_Key procedure
  401.     Subttl    Alt_Key     Alternate Key Routine
  402.     Page    +
  403. ;******************************************************************************
  404. ;
  405. ;    Alt_Key(Scan_Code)
  406. ;
  407. ;        If this is a make code
  408. ;            Set the alternate bit in the keyboard status
  409. ;        Else this is a break code
  410. ;            Clear the alternate bit in the keyboard status
  411. ;        Endif
  412. ;        If in joystick mode
  413. ;            Call the joystick button 2 routine
  414. ;        Endif
  415. ;        Return to the caller
  416. ;
  417. ;    Registers on Entry:
  418. ;
  419. ;        AL    - Control key scan code
  420. ;        AH    - Original scan code
  421. ;
  422. ;    Registers on Exit:
  423. ;
  424. ;        None
  425. ;
  426. ;******************************************************************************
  427.         Even            ; Force procedure to even address
  428. Alt_Key     Proc    Near        ; Alternate key procedure
  429.     or    ah,ah            ; Check for a make or break code
  430.     js    Alt_Break        ; Jump if this is a break code
  431. Alt_Make:
  432.     or    Byte Ptr cs:[Key_Status],ALTED
  433.     jmp    Short Alt_Test        ; Go check for joystick mode
  434. Alt_Break:
  435.     and    Byte Ptr cs:[Key_Status],Not ALTED
  436. Alt_Test:
  437.     test    Byte Ptr cs:[Key_Status],JOY_MODE
  438.     jz    Alt_Done        ; Jump if this is NOT joystick mode
  439.     call    Joy_Button_2        ; Call the joystick button 2 routine
  440. Alt_Done:
  441.     ret                ; Return to the caller
  442. Alt_Key     Endp            ; End of the Alt_Key procedure
  443.     Subttl    Shift_Key    Shift Key Routine
  444.     Page    +
  445. ;******************************************************************************
  446. ;
  447. ;    Shift_Key(Scan_Code)
  448. ;
  449. ;        If this is a make code
  450. ;            Set the shift bit in the keyboard status
  451. ;        Else this is a break code
  452. ;            Clear the shift bit in the keyboard status
  453. ;        Endif
  454. ;        Return to the caller
  455. ;
  456. ;    Registers on Entry:
  457. ;
  458. ;        AL    - Shift key scan code
  459. ;        AH    - Original scan code
  460. ;
  461. ;    Registers on Exit:
  462. ;
  463. ;        None
  464. ;
  465. ;******************************************************************************
  466.         Even            ; Force procedure to even address
  467. Shift_Key    Proc    Near        ; Shift key procedure
  468.     or    ah,ah            ; Check for a make or break code
  469.     js    Shift_Break        ; Jump if this is a break code
  470. Shift_Make:
  471.     or    Byte Ptr cs:[Key_Status],SHIFTED
  472.     jmp    Short Shift_Done    ; Go return to the caller
  473. Shift_Break:
  474.     and    Byte Ptr cs:[Key_Status],Not SHIFTED
  475. Shift_Done:
  476.     ret                ; Return to the caller
  477. Shift_Key    Endp            ; End of the Shift_Key procedure
  478.     Subttl    Caps_Lock    Caps Lock Key Routine
  479.     Page    +
  480. ;******************************************************************************
  481. ;
  482. ;    Caps_Lock(Scan_Code)
  483. ;
  484. ;        If the last scan code does NOT match (NOT a repeat)
  485. ;            If this is a make code
  486. ;                Toggle the caps lock status bit
  487. ;            Endif
  488. ;        Endif
  489. ;        Call routine to update the LED status
  490. ;        Return to the caller
  491. ;
  492. ;    Registers on Entry:
  493. ;
  494. ;        AL    - Caps lock key scan code
  495. ;        AH    - Original scan code
  496. ;
  497. ;    Registers on Exit:
  498. ;
  499. ;        None
  500. ;
  501. ;******************************************************************************
  502.         Even            ; Force procedure to even address
  503. Caps_Lock    Proc    Near        ; Caps lock key procedure
  504.     cmp    ah,cs:[Last_Scan]    ; Check for a repeat scan code
  505.     je    Caps_Done        ; Jump if this key is repeating
  506.     or    ah,ah            ; Check for a make or break code
  507.     js    Caps_Done        ; Jump if this is a break code
  508.     xor    Byte Ptr cs:[Key_Status],CAPS_LOCKED
  509. Caps_Done:
  510.     call    Set_LED         ; Update the keyboard LED status
  511.     ret                ; Return to the caller
  512. Caps_Lock    Endp            ; End of the Caps_Lock procedure
  513.     Subttl    Home_Key    Home Key Routine
  514.     Page    +
  515. ;******************************************************************************
  516. ;
  517. ;    Home_Key(Scan_Code)
  518. ;
  519. ;        If in joystick mode
  520. ;            Call the joystick up/left routine
  521. ;        Endif
  522. ;        Return to the caller
  523. ;
  524. ;    Registers on Entry:
  525. ;
  526. ;        AL    - Home key scan code
  527. ;        AH    - Original scan code
  528. ;
  529. ;    Registers on Exit:
  530. ;
  531. ;        None
  532. ;
  533. ;******************************************************************************
  534.         Even            ; Force procedure to even address
  535. Home_Key    Proc    Near        ; Home key procedure
  536.     test    Byte Ptr cs:[Key_Status],JOY_MODE
  537.     jz    Home_Done        ; Jump if this is NOT joystick mode
  538.     call    Joy_Up_Left        ; Call the joystick up/left routine
  539. Home_Done:
  540.     ret                ; Return to the caller
  541. Home_Key    Endp            ; End of the Home_Key procedure
  542.     Subttl    Up_Key        Up Key Routine
  543.     Page    +
  544. ;******************************************************************************
  545. ;
  546. ;    Up_Key(Scan_Code)
  547. ;
  548. ;        If NOT in joystick mode
  549. ;            If this is a make code
  550. ;                Get the up arrow key code
  551. ;                Set the any key down flag bit
  552. ;                Set the keyboard strobe bit
  553. ;                Save the keyboard data value
  554. ;            Endif
  555. ;        Else in the joystick mode
  556. ;            Call the joystick up routine
  557. ;        Endif
  558. ;        Return to the caller
  559. ;
  560. ;    Registers on Entry:
  561. ;
  562. ;        AL    - Up key scan code
  563. ;        AH    - Original scan code
  564. ;
  565. ;    Registers on Exit:
  566. ;
  567. ;        None
  568. ;
  569. ;******************************************************************************
  570.         Even            ; Force procedure to even address
  571. Up_Key        Proc    Near        ; Up key procedure
  572.     test    Byte Ptr cs:[Key_Status],JOY_MODE
  573.     jnz    Do_Up            ; Jump if this is joystick mode
  574.     or    ah,ah            ; Check for a make or break code
  575.     js    Up_Done         ; Jump if this is a break code
  576.     mov    bl,UP_ARROW        ; Get the up arrow translated code
  577.     or    Byte Ptr ds:[Any_Key],KEY_DOWN
  578.     or    bl,KEY_STROBE        ; Set the keyboard strobe bit
  579.     mov    ds:[Key_Data],bl    ; Save the keyboard data value
  580.     jmp    Short Up_Done        ; Go return to the caller
  581. Do_Up:
  582.     call    Joy_Up            ; Call the joystick up routine
  583. Up_Done:
  584.     ret                ; Return to the caller
  585. Up_Key        Endp            ; End of the Up_Key procedure
  586.     Subttl    PgUp_Key    PgUp Key Routine
  587.     Page    +
  588. ;******************************************************************************
  589. ;
  590. ;    PgUp_Key(Scan_Code)
  591. ;
  592. ;        If in joystick mode
  593. ;            Call the joystick up/right routine
  594. ;        Endif
  595. ;        Return to the caller
  596. ;
  597. ;    Registers on Entry:
  598. ;
  599. ;        AL    - PgUp key scan code
  600. ;        AH    - Original scan code
  601. ;
  602. ;    Registers on Exit:
  603. ;
  604. ;        None
  605. ;
  606. ;******************************************************************************
  607.         Even            ; Force procedure to even address
  608. PgUp_Key    Proc    Near        ; PgUp key procedure
  609.     test    Byte Ptr cs:[Key_Status],JOY_MODE
  610.     jz    PgUp_Done        ; Jump if this is NOT joystick mode
  611.     call    Joy_Up_Right        ; Call the joystick up/right routine
  612. PgUp_Done:
  613.     ret                ; Return to the caller
  614. PgUp_Key    Endp            ; End of the PgUp_Key procedure
  615.     Subttl    Left_Key    Left Key Routine
  616.     Page    +
  617. ;******************************************************************************
  618. ;
  619. ;    Left_Key(Scan_Code)
  620. ;
  621. ;        If NOT in joystick mode
  622. ;            If this is a make code
  623. ;                Get the left arrow key code
  624. ;                Set the any key down flag bit
  625. ;                Set the keyboard strobe bit
  626. ;                Save the keyboard data value
  627. ;            Endif
  628. ;        Else in the joystick mode
  629. ;            Call the joystick left routine
  630. ;        Endif
  631. ;        Return to the caller
  632. ;
  633. ;    Registers on Entry:
  634. ;
  635. ;        AL    - Left key scan code
  636. ;        AH    - Original scan code
  637. ;
  638. ;    Registers on Exit:
  639. ;
  640. ;        None
  641. ;
  642. ;******************************************************************************
  643.         Even            ; Force procedure to even address
  644. Left_Key    Proc    Near        ; Left key procedure
  645.     test    Byte Ptr cs:[Key_Status],JOY_MODE
  646.     jnz    Do_Left         ; Jump if this is joystick mode
  647.     or    ah,ah            ; Check for a make or break code
  648.     js    Left_Done        ; Jump if this is a break code
  649.     mov    bl,LEFT_ARROW        ; Get the left arrow translated code
  650.     or    Byte Ptr ds:[Any_Key],KEY_DOWN
  651.     or    bl,KEY_STROBE        ; Set the keyboard strobe bit
  652.     mov    ds:[Key_Data],bl    ; Save the keyboard data value
  653.     jmp    Short Left_Done     ; Go return to the caller
  654. Do_Left:
  655.     call    Joy_Left        ; Call the joystick left routine
  656. Left_Done:
  657.     ret                ; Return to the caller
  658. Left_Key    Endp            ; End of the Left_Key procedure
  659.     Subttl    Center_Key    Center Key Routine
  660.     Page    +
  661. ;******************************************************************************
  662. ;
  663. ;    Center_Key(Scan_Code)
  664. ;
  665. ;        If in joystick mode
  666. ;            Call the joystick center routine
  667. ;        Endif
  668. ;        Return to the caller
  669. ;
  670. ;    Registers on Entry:
  671. ;
  672. ;        AL    - Center key scan code (Pad 5)
  673. ;        AH    - Original scan code
  674. ;
  675. ;    Registers on Exit:
  676. ;
  677. ;        None
  678. ;
  679. ;******************************************************************************
  680.         Even            ; Force procedure to even address
  681. Center_Key    Proc    Near        ; Center key procedure
  682.     test    Byte Ptr cs:[Key_Status],JOY_MODE
  683.     jz    Center_Done        ; Jump if this is NOT joystick mode
  684.     call    Joy_Center        ; Call the joystick center routine
  685. Center_Done:
  686.     ret                ; Return to the caller
  687. Center_Key    Endp            ; End of the Center_Key procedure
  688.     Subttl    Right_Key    Right Key Routine
  689.     Page    +
  690. ;******************************************************************************
  691. ;
  692. ;    Right_Key(Scan_Code)
  693. ;
  694. ;        If NOT in joystick mode
  695. ;            If this is a make code
  696. ;                Get the right arrow key code
  697. ;                Set the any key down flag bit
  698. ;                Set the keyboard strobe bit
  699. ;                Save the keyboard data value
  700. ;            Endif
  701. ;        Else in the joystick mode
  702. ;            Call the joystick right routine
  703. ;        Endif
  704. ;        Return to the caller
  705. ;
  706. ;    Registers on Entry:
  707. ;
  708. ;        AL    - Right key scan code
  709. ;        AH    - Original scan code
  710. ;
  711. ;    Registers on Exit:
  712. ;
  713. ;        None
  714. ;
  715. ;******************************************************************************
  716.         Even            ; Force procedure to even address
  717. Right_Key    Proc    Near        ; Right key procedure
  718.     test    Byte Ptr cs:[Key_Status],JOY_MODE
  719.     jnz    Do_Right        ; Jump if this is joystick mode
  720.     or    ah,ah            ; Check for a make or break code
  721.     js    Right_Done        ; Jump if this is a break code
  722.     mov    bl,RIGHT_ARROW        ; Get the right arrow translated code
  723.     or    Byte Ptr ds:[Any_Key],KEY_DOWN
  724.     or    bl,KEY_STROBE        ; Set the keyboard strobe bit
  725.     mov    ds:[Key_Data],bl    ; Save the keyboard data value
  726.     jmp    Short Right_Done    ; Go return to the caller
  727. Do_Right:
  728.     call    Joy_Right        ; Call the joystick right routine
  729. Right_Done:
  730.     ret                ; Return to the caller
  731. Right_Key    Endp            ; End of the Right_Key procedure
  732.     Subttl    End_Key     End Key Routine
  733.     Page    +
  734. ;******************************************************************************
  735. ;
  736. ;    End_Key(Scan_Code)
  737. ;
  738. ;        If in joystick mode
  739. ;            Call the joystick down/left routine
  740. ;        Endif
  741. ;        Return to the caller
  742. ;
  743. ;    Registers on Entry:
  744. ;
  745. ;        AL    - End key scan code
  746. ;        AH    - Original scan code
  747. ;
  748. ;    Registers on Exit:
  749. ;
  750. ;        None
  751. ;
  752. ;******************************************************************************
  753.         Even            ; Force procedure to even address
  754. End_Key     Proc    Near        ; End key procedure
  755.     test    Byte Ptr cs:[Key_Status],JOY_MODE
  756.     jz    End_Done        ; Jump if this is NOT joystick mode
  757.     call    Joy_Down_Left        ; Call the joystick down/left routine
  758. End_Done:
  759.     ret                ; Return to the caller
  760. End_Key     Endp            ; End of the End_Key procedure
  761.     Subttl    Down_Key    Down Key Routine
  762.     Page    +
  763. ;******************************************************************************
  764. ;
  765. ;    Down_Key(Scan_Code)
  766. ;
  767. ;        If NOT in joystick mode
  768. ;            If this is a make code
  769. ;                Get the down arrow key code
  770. ;                Set the any key down flag bit
  771. ;                Set the keyboard strobe bit
  772. ;                Save the keyboard data value
  773. ;            Endif
  774. ;        Else in the joystick mode
  775. ;            Call the joystick down routine
  776. ;        Endif
  777. ;        Return to the caller
  778. ;
  779. ;    Registers on Entry:
  780. ;
  781. ;        AL    - Down key scan code
  782. ;        AH    - Original scan code
  783. ;
  784. ;    Registers on Exit:
  785. ;
  786. ;        None
  787. ;
  788. ;******************************************************************************
  789.         Even            ; Force procedure to even address
  790. Down_Key    Proc    Near        ; Down key procedure
  791.     test    Byte Ptr cs:[Key_Status],JOY_MODE
  792.     jnz    Do_Down         ; Jump if this is joystick mode
  793.     or    ah,ah            ; Check for a make or break code
  794.     js    Down_Done        ; Jump if this is a break code
  795.     mov    bl,DOWN_ARROW        ; Get the down arrow translated code
  796.     or    Byte Ptr ds:[Any_Key],KEY_DOWN
  797.     or    bl,KEY_STROBE        ; Set the keyboard strobe bit
  798.     mov    ds:[Key_Data],bl    ; Save the keyboard data value
  799.     jmp    Short Down_Done     ; Go return to the caller
  800. Do_Down:
  801.     call    Joy_Down        ; Call the joystick down routine
  802. Down_Done:
  803.     ret                ; Return to the caller
  804. Down_Key    Endp            ; End of the Down_Key procedure
  805.     Subttl    PgDn_Key    PgDn Key Routine
  806.     Page    +
  807. ;******************************************************************************
  808. ;
  809. ;    PgDn_Key(Scan_Code)
  810. ;
  811. ;        If in joystick mode
  812. ;            Call the joystick down/right routine
  813. ;        Endif
  814. ;        Return to the caller
  815. ;
  816. ;    Registers on Entry:
  817. ;
  818. ;        AL    - PgDn key scan code
  819. ;        AH    - Original scan code
  820. ;
  821. ;    Registers on Exit:
  822. ;
  823. ;        None
  824. ;
  825. ;******************************************************************************
  826.         Even            ; Force procedure to even address
  827. PgDn_Key    Proc    Near        ; PgDn key procedure
  828.     test    Byte Ptr cs:[Key_Status],JOY_MODE
  829.     jz    PgDn_Done        ; Jump if this is NOT joystick mode
  830.     call    Joy_Down_Right        ; Call the joystick down/right routine
  831. PgDn_Done:
  832.     ret                ; Return to the caller
  833. PgDn_Key    Endp            ; End of the PgDn_Key procedure
  834.     Subttl    Ins_Key     Ins Key Routine
  835.     Page    +
  836. ;******************************************************************************
  837. ;
  838. ;    Ins_Key(Scan_Code)
  839. ;
  840. ;        If in joystick mode
  841. ;            If Ctrl key is down
  842. ;                Call joystick X resolution increase routine
  843. ;            Else
  844. ;                If Alt key is down
  845. ;                    Call joystick X center increase routine
  846. ;                Endif for Alt key
  847. ;            Endif for Ctrl key
  848. ;        Endif for joystick mode
  849. ;        Return to the caller
  850. ;
  851. ;    Registers on Entry:
  852. ;
  853. ;        AL    - Ins key scan code
  854. ;        AH    - Original scan code
  855. ;
  856. ;    Registers on Exit:
  857. ;
  858. ;        None
  859. ;
  860. ;******************************************************************************
  861.         Even            ; Force procedure to even address
  862. Ins_Key     Proc    Near        ; Ins key procedure
  863.     test    Byte Ptr cs:[Key_Status],JOY_MODE
  864.     jz    Ins_Done        ; Jump if this is NOT joystick mode
  865. Ctrl_Ins_Check:
  866.     test    Byte Ptr cs:[Key_Status],CTRLED
  867.     jz    Alt_Ins_Check        ; Jump if ctrl key NOT down
  868.     call    Joy_X_Res_Inc        ; Call joystick X res. inc. routine
  869.     jmp    Short Ins_Done        ; Go return to the caller
  870. Alt_Ins_Check:
  871.     test    Byte Ptr cs:[Key_Status],ALTED
  872.     jz    Ins_Done        ; Jump if alt key NOT down
  873.     call    Joy_X_Cen_Inc        ; Call joystick X center inc. routine
  874. Ins_Done:
  875.     ret                ; Return to the caller
  876. Ins_Key     Endp            ; End of the Ins_Key procedure
  877.     Subttl    Del_Key     Del Key Routine
  878.     Page    +
  879. ;******************************************************************************
  880. ;
  881. ;    Del_Key(Scan_Code)
  882. ;
  883. ;        If NOT in joystick mode
  884. ;            If this is a make code
  885. ;                Get the DEL key code
  886. ;                Set the any key down flag bit
  887. ;                Set the keyboard strobe bit
  888. ;                Save the keyboard data value
  889. ;            Endif
  890. ;        Else in the joystick mode
  891. ;            If Ctrl key is down
  892. ;                Call joystick X resolution decrease routine
  893. ;            Else
  894. ;                If Alt key is down
  895. ;                    Call joystick X center decrease routine
  896. ;                Endif for Alt key
  897. ;            Endif for Ctrl key
  898. ;        Endif for joystick mode
  899. ;        Return to the caller
  900. ;
  901. ;    Registers on Entry:
  902. ;
  903. ;        AL    - Del key scan code
  904. ;        AH    - Original scan code
  905. ;
  906. ;    Registers on Exit:
  907. ;
  908. ;        None
  909. ;
  910. ;******************************************************************************
  911.         Even            ; Force procedure to even address
  912. Del_Key     Proc    Near        ; Del key procedure
  913.     test    Byte Ptr cs:[Key_Status],JOY_MODE
  914.     jnz    Ctrl_Del_Check        ; Jump if this is joystick mode
  915.     or    ah,ah            ; Check for a make or break code
  916.     js    Del_Done        ; Jump if this is a break code
  917.     mov    bl,DEL_CODE        ; Get the DEL key translated code
  918.     or    Byte Ptr ds:[Any_Key],KEY_DOWN
  919.     or    bl,KEY_STROBE        ; Set the keyboard strobe bit
  920.     mov    ds:[Key_Data],bl    ; Save the keyboard data value
  921.     jmp    Short Del_Done        ; Go return to the caller
  922. Ctrl_Del_Check:
  923.     test    Byte Ptr cs:[Key_Status],CTRLED
  924.     jz    Alt_Del_Check        ; Jump if ctrl key NOT down
  925.     call    Joy_X_Res_Dec        ; Call joystick X res. dec. routine
  926.     jmp    Short Del_Done        ; Go return to the caller
  927. Alt_Del_Check:
  928.     test    Byte Ptr cs:[Key_Status],ALTED
  929.     jz    Del_Done        ; Jump if alt key NOT down
  930.     call    Joy_X_Cen_Dec        ; Call joystick X center dec. routine
  931. Del_Done:
  932.     ret                ; Return to the caller
  933. Del_Key     Endp            ; End of the Del_Key procedure
  934.     Subttl    Pad_Plus    Pad Plus Key Routine
  935.     Page    +
  936. ;******************************************************************************
  937. ;
  938. ;    Pad_Plus(Scan_Code)
  939. ;
  940. ;        If in joystick mode
  941. ;            If Ctrl key is down
  942. ;                Call joystick Y resolution increase routine
  943. ;            Else
  944. ;                If Alt key is down
  945. ;                    Call joystick Y center increase routine
  946. ;                Endif for Alt key
  947. ;            Endif for Ctrl key
  948. ;        Endif for joystick mode
  949. ;        Return to the caller
  950. ;
  951. ;    Registers on Entry:
  952. ;
  953. ;        AL    - Pad plus key scan code
  954. ;        AH    - Original scan code
  955. ;
  956. ;    Registers on Exit:
  957. ;
  958. ;        None
  959. ;
  960. ;******************************************************************************
  961.         Even            ; Force procedure to even address
  962. Pad_Plus    Proc    Near        ; Pad plus key procedure
  963.     test    Byte Ptr cs:[Key_Status],JOY_MODE
  964.     jz    Plus_Done        ; Jump if this is NOT joystick mode
  965. Ctrl_Plus_Check:
  966.     test    Byte Ptr cs:[Key_Status],CTRLED
  967.     jz    Alt_Plus_Check        ; Jump if ctrl key NOT down
  968.     call    Joy_Y_Res_Inc        ; Call joystick Y res. inc. routine
  969.     jmp    Short Plus_Done     ; Go return to the caller
  970. Alt_Plus_Check:
  971.     test    Byte Ptr cs:[Key_Status],ALTED
  972.     jz    Plus_Done        ; Jump if alt key NOT down
  973.     call    Joy_Y_Cen_Inc        ; Call joystick Y center inc. routine
  974. Plus_Done:
  975.     ret                ; Return to the caller
  976. Pad_Plus    Endp            ; End of the Pad_Plus procedure
  977.     Subttl    Pad_Minus    Pad Minus Key Routine
  978.     Page    +
  979. ;******************************************************************************
  980. ;
  981. ;    Pad_Minus(Scan_Code)
  982. ;
  983. ;        If in joystick mode
  984. ;            If Ctrl key is down
  985. ;                Call joystick Y resolution decrease routine
  986. ;            Else
  987. ;                If Alt key is down
  988. ;                    Call joystick Y center decrease routine
  989. ;                Endif for Alt key
  990. ;            Endif for Ctrl key
  991. ;        Endif for joystick mode
  992. ;        Return to the caller
  993. ;
  994. ;    Registers on Entry:
  995. ;
  996. ;        AL    - Pad minus key scan code
  997. ;        AH    - Original scan code
  998. ;
  999. ;    Registers on Exit:
  1000. ;
  1001. ;        None
  1002. ;
  1003. ;******************************************************************************
  1004.         Even            ; Force procedure to even address
  1005. Pad_Minus    Proc    Near        ; Pad minus key procedure
  1006.     test    Byte Ptr cs:[Key_Status],JOY_MODE
  1007.     jz    Minus_Done        ; Jump if this is NOT joystick mode
  1008. Ctrl_Minus_Check:
  1009.     test    Byte Ptr cs:[Key_Status],CTRLED
  1010.     jz    Alt_Minus_Check     ; Jump if ctrl key NOT down
  1011.     call    Joy_Y_Res_Dec        ; Call joystick Y res. dec. routine
  1012.     jmp    Short Minus_Done    ; Go return to the caller
  1013. Alt_Minus_Check:
  1014.     test    Byte Ptr cs:[Key_Status],ALTED
  1015.     jz    Minus_Done        ; Jump if alt key NOT down
  1016.     call    Joy_Y_Cen_Dec        ; Call joystick Y center dec. routine
  1017. Minus_Done:
  1018.     ret                ; Return to the caller
  1019. Pad_Minus    Endp            ; End of the Pad_Minus procedure
  1020.     Subttl    Num_Lock    Num Lock Key Routine
  1021.     Page    +
  1022. ;******************************************************************************
  1023. ;
  1024. ;    Num_Lock(Scan_Code)
  1025. ;
  1026. ;        Save the required registers
  1027. ;        If the last scan code does NOT match (NOT a repeat)
  1028. ;            If this is a make code
  1029. ;                If neither shift/ctrl/alt keys are down
  1030. ;                    Toggle the joystick mode bit
  1031. ;                Endif
  1032. ;                If this is joystick mode
  1033. ;                    Call correct joystick routine
  1034. ;                Endif for joystick mode
  1035. ;            Endif this is a break code
  1036. ;        Endif this key is repeating
  1037. ;        Call routine to update the LED status
  1038. ;        Restore the required registers
  1039. ;        Return to the caller
  1040. ;
  1041. ;    Registers on Entry:
  1042. ;
  1043. ;        AL    - Num lock key scan code
  1044. ;        AH    - Original scan code
  1045. ;
  1046. ;    Registers on Exit:
  1047. ;
  1048. ;        None
  1049. ;
  1050. ;******************************************************************************
  1051.         Even            ; Force procedure to even address
  1052. Num_Lock    Proc    Near        ; Num lock key procedure
  1053.     Save    bx            ; Save the required registers
  1054.     cmp    ah,cs:[Last_Scan]    ; Check for a repeat scan code
  1055.     je    Num_Done        ; Jump if this key is repeating
  1056.     or    ah,ah            ; Check for a make or break code
  1057.     js    Num_Done        ; Jump if this is a break code
  1058.     xor    bh,bh            ; Setup to get keyboard status
  1059.     mov    bl,cs:[Key_Status]    ; Get the keyboard status byte
  1060.     and    bl,KEY_MASK        ; Save only the desired bits
  1061.     jnz    Joy_Test        ; Jump if other status bits present
  1062.     xor    Byte Ptr cs:[Key_Status],JOY_MODE
  1063. Joy_Test:
  1064.     test    Byte Ptr cs:[Key_Status],JOY_MODE
  1065.     jz    Num_Done        ; Jump if NOT in joystick mode
  1066.     shl    bx,1            ; Convert status bits to table index
  1067.     call    cs:[bx + Joy_Table]    ; Call the correct joystick routine
  1068. Num_Done:
  1069.     call    Set_LED         ; Update the keyboard LED status
  1070.     Restore bx            ; Restore the required registers
  1071.     ret                ; Return to the caller
  1072. Num_Lock    Endp            ; End of the Num_Lock procedure
  1073.     Subttl    Set_LED     Set keyboard LED routine
  1074.     Page    +
  1075. ;******************************************************************************
  1076. ;
  1077. ;    Set_LED()
  1078. ;
  1079. ;        Save the required registers
  1080. ;        Wait for 8042 input buffer empty
  1081. ;        Disable the keyboard for LED update
  1082. ;        Send the set LED command to 8042
  1083. ;        Wait for ACK from the 8042
  1084. ;        Wait for 8042 input buffer empty
  1085. ;        Get the keyboard status byte
  1086. ;        Mask off all but the LED status bits
  1087. ;        Toggle scroll lock status to correct state
  1088. ;        Send the new LED status bits to 8042
  1089. ;        Wait for ACK from the 8042
  1090. ;        Wait for 8042 input buffer empty
  1091. ;        Enable the keyboard after LED update
  1092. ;        Restore the required registers
  1093. ;        Return to the caller
  1094. ;
  1095. ;    Registers on Entry:
  1096. ;
  1097. ;        None
  1098. ;
  1099. ;    Registers on Exit:
  1100. ;
  1101. ;        None
  1102. ;
  1103. ;******************************************************************************
  1104.         Even            ; Force procedure to even address
  1105. Set_LED     Proc    Near        ; Set keyboard LED procedure
  1106.     Save    ax            ; Save the required registers
  1107.     call    Wait_Input        ; Call routine to wait for buffer empty
  1108.     jc    Set_Exit        ; Jump if buffer never empty
  1109.     mov    al,DISABLE_KEY        ; Get disable keyboard function code
  1110.     out    COMMAND_PORT,al     ; Disable the keyboard
  1111.     call    Wait_Output        ; Wait for output buffer full
  1112.     jc    Skip_Input        ; Jump if nothing waiting
  1113.     in    al,DATA_PORT        ; Read any key that might be there
  1114. Skip_Input:
  1115.     call    Wait_Input        ; Wait for input buffer to go empty
  1116.     jc    Set_Enable        ; Jump if buffer never empty
  1117.     mov    al,LED_SET        ; Get set LED function code
  1118.     out    DATA_PORT,al        ; Send the set LED function code
  1119.     call    Wait_Output        ; Wait for output buffer full
  1120.     jc    Set_Enable        ; Jump if buffer never full
  1121.     in    al,DATA_PORT        ; Get the ACK byte received
  1122.     call    Wait_Input        ; Wait for input buffer empty
  1123.     jc    Set_Enable        ; Jump if buffer never empty
  1124.     mov    al,cs:[Key_Status]    ; Get the current keyboard status
  1125.     and    al,LED_MASK        ; Mask off all but the LED indicators
  1126.     xor    al,SCROLL_LOCKED    ; Toggle scroll lock to correct state
  1127.     shr    al,LED_SHIFT        ; Shift bits into the correct position
  1128.     out    DATA_PORT,al        ; Output the new LED status byte
  1129.     call    Wait_Output        ; Wait for output buffer to fill
  1130.     jc    Set_Enable        ; Jump if buffer never full
  1131.     in    al,DATA_PORT        ; Get the ACK byte from the buffer
  1132.     call    Wait_Input        ; Wait for the input buffer to go empty
  1133. Set_Enable:
  1134.     mov    al,ENABLE_KEY        ; Get enable keyboard function code
  1135.     out    COMMAND_PORT,al     ; Enable the keyboard
  1136. Set_Exit:
  1137.     Restore ax            ; Restore the required registers
  1138.     ret                ; Return to the caller
  1139. Set_LED     Endp            ; End of the Set_LED procedure
  1140.     Subttl    Wait_Input    Wait for Input Buffer Empty routine
  1141.     Page    +
  1142. ;******************************************************************************
  1143. ;
  1144. ;    Wait_Input()
  1145. ;
  1146. ;        Save the required registers
  1147. ;        Get counter limit value
  1148. ;        While counter > 0 and input buffer full
  1149. ;            Wait till input buffer is empty
  1150. ;            Decrement counter value
  1151. ;            If counter is zero
  1152. ;                Set carry flag indicating never empty
  1153. ;            Endif
  1154. ;        Endwhile
  1155. ;        Restore the required registers
  1156. ;        Return to the caller
  1157. ;
  1158. ;    Registers on Entry:
  1159. ;
  1160. ;        None
  1161. ;
  1162. ;    Registers on Exit:
  1163. ;
  1164. ;        AL    - Destroyed
  1165. ;
  1166. ;******************************************************************************
  1167.         Even            ; Force procedure to even address
  1168. Wait_Input    Proc    Near        ; Wait for input buffer empty procedure
  1169.     Save    cx            ; Save the required registers
  1170.     mov    cx,TIME_OUT        ; Get the time out counter value
  1171. Input_Loop:
  1172.     in    al,COMMAND_PORT     ; Read the 8042 status
  1173.     test    al,INPUT_EMPTY        ; Check for input buffer empty
  1174.     jz    Input_Exit        ; Jump if input buffer is empty
  1175.     loop    Input_Loop        ; Loop until time out is expired
  1176.     stc                ; Set carry flag indicating time out
  1177. Input_Exit:
  1178.     Restore cx            ; Restore the required registers
  1179.     ret                ; Return to the caller
  1180. Wait_Input    Endp            ; End of the Wait_Input procedure
  1181.     Subttl    Wait_Output    Wait for Output Buffer Full routine
  1182.     Page    +
  1183. ;******************************************************************************
  1184. ;
  1185. ;    Wait_Output()
  1186. ;
  1187. ;        Save the required registers
  1188. ;        Get counter limit value
  1189. ;        While counter > 0 and output buffer empty
  1190. ;            Wait till output buffer is full
  1191. ;            Decrement counter value
  1192. ;            If counter is zero
  1193. ;                Set carry flag indicating never full
  1194. ;            Endif
  1195. ;        Endwhile
  1196. ;        Restore the required registers
  1197. ;        Return to the caller
  1198. ;
  1199. ;    Registers on Entry:
  1200. ;
  1201. ;        None
  1202. ;
  1203. ;    Registers on Exit:
  1204. ;
  1205. ;        AL    - Destroyed
  1206. ;
  1207. ;******************************************************************************
  1208.         Even            ; Force procedure to even address
  1209. Wait_Output    Proc    Near        ; Wait for output buffer full procedure
  1210.     Save    cx            ; Save the required registers
  1211.     mov    cx,TIME_OUT        ; Get the time out counter value
  1212. Output_Loop:
  1213.     in    al,COMMAND_PORT     ; Read the 8042 status
  1214.     test    al,OUTPUT_FULL        ; Check for output buffer full
  1215.     jz    Output_Exit        ; Jump if output buffer is full
  1216.     loop    Output_Loop        ; Loop until time out is expired
  1217.     stc                ; Set carry flag indicating time out
  1218. Output_Exit:
  1219.     Restore cx            ; Restore the required registers
  1220.     ret                ; Return to the caller
  1221. Wait_Output    Endp            ; End of the Wait_Output procedure
  1222.     Subttl    Key_Reset    Keyboard Reset routine
  1223.     Page    +
  1224. ;******************************************************************************
  1225. ;
  1226. ;    Key_Reset()
  1227. ;
  1228. ;        Save the required registers
  1229. ;        Wait for 8042 input buffer empty
  1230. ;        Disable the keyboard for LED update
  1231. ;        Send the set LED command to 8042
  1232. ;        Wait for ACK from the 8042
  1233. ;        Wait for 8042 input buffer empty
  1234. ;        Get the keyboard shift status (BIOS)
  1235. ;        Mask off all but the LED status bits
  1236. ;        Toggle scroll lock status to correct state
  1237. ;        Send the new LED status bits to 8042
  1238. ;        Wait for ACK from the 8042
  1239. ;        Wait for 8042 input buffer empty
  1240. ;        Enable the keyboard after LED update
  1241. ;        Restore the required registers
  1242. ;        Return to the caller
  1243. ;
  1244. ;    Registers on Entry:
  1245. ;
  1246. ;        None
  1247. ;
  1248. ;    Registers on Exit:
  1249. ;
  1250. ;        None
  1251. ;
  1252. ;******************************************************************************
  1253.         Even            ; Force procedure to even address
  1254. Key_Reset    Proc    Near        ; Keyboard reset procedure
  1255.     Save    ax            ; Save the required registers
  1256.     call    Wait_Input        ; Call routine to wait for buffer empty
  1257.     jc    Reset_Exit        ; Jump if buffer never empty
  1258.     mov    al,DISABLE_KEY        ; Get disable keyboard function code
  1259.     out    COMMAND_PORT,al     ; Disable the keyboard
  1260.     call    Wait_Output        ; Wait for output buffer full
  1261.     jc    Input_Skip        ; Jump if nothing waiting
  1262.     in    al,DATA_PORT        ; Read any key that might be there
  1263. Input_Skip:
  1264.     call    Wait_Input        ; Wait for input buffer to go empty
  1265.     jc    Reset_Enable        ; Jump if buffer never empty
  1266.     mov    al,LED_SET        ; Get set LED function code
  1267.     out    DATA_PORT,al        ; Send the set LED function code
  1268.     call    Wait_Output        ; Wait for output buffer full
  1269.     jc    Reset_Enable        ; Jump if buffer never full
  1270.     in    al,DATA_PORT        ; Get the ACK byte received
  1271.     call    Wait_Input        ; Wait for input buffer empty
  1272.     jc    Reset_Enable        ; Jump if buffer never empty
  1273.     mov    ah,SHIFT_STATUS     ; Get shift status function code
  1274.     int    KEYBOARD        ; Get the shift/lock status byte
  1275.     shl    al,1            ; Shift LED status bits into position
  1276.     and    al,LED_MASK        ; Mask off all but the LED indicators
  1277.     shr    al,LED_SHIFT        ; Shift bits into the correct position
  1278.     out    DATA_PORT,al        ; Output the new LED status byte
  1279.     call    Wait_Output        ; Wait for output buffer to fill
  1280.     jc    Reset_Enable        ; Jump if buffer never full
  1281.     in    al,DATA_PORT        ; Get the ACK byte from the buffer
  1282.     call    Wait_Input        ; Wait for the input buffer to go empty
  1283. Reset_Enable:
  1284.     mov    al,ENABLE_KEY        ; Get enable keyboard function code
  1285.     out    COMMAND_PORT,al     ; Enable the keyboard
  1286. Reset_Exit:
  1287.     Restore ax            ; Restore the required registers
  1288.     ret                ; Return to the caller
  1289. Key_Reset    Endp            ; End of the Key_Reset procedure
  1290. ;******************************************************************************
  1291. ;
  1292. ;    Define the keyboard translation table
  1293. ;
  1294. ;    None, Shift, Ctrl, Ctrl/Shift, Alt, Alt/Shift, Alt/Ctrl, Alt/Ctrl/Shift
  1295. ;
  1296. ;******************************************************************************
  1297. Key_Translate    Equ    This Byte    ; Keyboard translation table
  1298.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 00h - Illegal
  1299.     Db    1Bh,1Bh,1Bh,1Bh,80h,80h,80h,80h ; Scan Code 01h - Escape key
  1300.     Db    31h,21h,31h,21h,80h,80h,80h,80h ; Scan Code 02h - Keyboard 1
  1301.     Db    32h,40h,00h,00h,80h,80h,80h,80h ; Scan Code 03h - Keyboard 2
  1302.     Db    33h,23h,33h,23h,80h,80h,80h,80h ; Scan Code 04h - Keyboard 3
  1303.     Db    34h,24h,34h,24h,80h,80h,80h,80h ; Scan Code 05h - Keyboard 4
  1304.     Db    35h,25h,35h,25h,80h,80h,80h,80h ; Scan Code 06h - Keyboard 5
  1305.     Db    36h,5Eh,1Eh,1Eh,80h,80h,80h,80h ; Scan Code 07h - Keyboard 6
  1306.     Db    37h,26h,37h,26h,80h,80h,80h,80h ; Scan Code 08h - Keyboard 7
  1307.     Db    38h,2Ah,38h,2Ah,80h,80h,80h,80h ; Scan Code 09h - Keyboard 8
  1308.     Db    39h,28h,39h,28h,80h,80h,80h,80h ; Scan Code 0Ah - Keyboard 9
  1309.     Db    30h,29h,30h,29h,80h,80h,80h,80h ; Scan Code 0Bh - Keyboard 0
  1310.     Db    2Dh,5Fh,1Fh,1Fh,80h,80h,80h,80h ; Scan Code 0Ch - Keyboard minus
  1311.     Db    3Dh,2Bh,3Dh,2Bh,80h,80h,80h,80h ; Scan Code 0Dh - Equal sign
  1312.     Db    08h,08h,08h,08h,80h,80h,80h,80h ; Scan Code 0Eh - Backspace
  1313.     Db    82h,82h,82h,82h,80h,80h,80h,80h ; Scan Code 0Fh - Tab
  1314.     Db    71h,51h,11h,11h,80h,80h,80h,80h ; Scan Code 10h - Letter Q
  1315.     Db    77h,57h,17h,17h,80h,80h,80h,80h ; Scan Code 11h - Letter W
  1316.     Db    65h,45h,05h,05h,80h,80h,80h,80h ; Scan Code 12h - Letter E
  1317.     Db    72h,52h,12h,12h,80h,80h,80h,80h ; Scan Code 13h - Letter R
  1318.     Db    74h,54h,14h,14h,80h,80h,80h,80h ; Scan Code 14h - Letter T
  1319.     Db    79h,59h,19h,19h,80h,80h,80h,80h ; Scan Code 15h - Letter Y
  1320.     Db    75h,55h,15h,15h,80h,80h,80h,80h ; Scan Code 16h - Letter U
  1321.     Db    69h,49h,09h,09h,80h,80h,80h,80h ; Scan Code 17h - Letter I
  1322.     Db    6Fh,4Fh,0Fh,0Fh,80h,80h,80h,80h ; Scan Code 18h - Letter O
  1323.     Db    70h,50h,10h,10h,80h,80h,80h,80h ; Scan Code 19h - Letter P
  1324.     Db    5Bh,7Bh,1Bh,1Bh,80h,80h,80h,80h ; Scan Code 1Ah - Left bracket
  1325.     Db    5Dh,7Dh,1Dh,1Dh,80h,80h,80h,80h ; Scan Code 1Bh - Right bracket
  1326.     Db    0Dh,0Dh,0Dh,0Dh,80h,80h,80h,80h ; Scan Code 1Ch - Enter
  1327.     Db    81h,81h,81h,81h,81h,81h,81h,81h ; Scan Code 1Dh - Ctrl
  1328.     Db    61h,41h,01h,01h,80h,80h,80h,80h ; Scan Code 1Eh - Letter A
  1329.     Db    73h,53h,13h,13h,80h,80h,80h,80h ; Scan Code 1Fh - Letter S
  1330.     Db    64h,44h,04h,04h,80h,80h,80h,80h ; Scan Code 20h - Letter D
  1331.     Db    66h,46h,06h,06h,80h,80h,80h,80h ; Scan Code 21h - Letter F
  1332.     Db    67h,47h,07h,07h,80h,80h,80h,80h ; Scan Code 22h - Letter G
  1333.     Db    68h,48h,08h,08h,80h,80h,80h,80h ; Scan Code 23h - Letter H
  1334.     Db    6Ah,4Ah,0Ah,0Ah,80h,80h,80h,80h ; Scan Code 24h - Letter J
  1335.     Db    6Bh,4Bh,0Bh,0Bh,80h,80h,80h,80h ; Scan Code 25h - Letter K
  1336.     Db    6Ch,4Ch,0Ch,0Ch,80h,80h,80h,80h ; Scan Code 26h - Letter L
  1337.     Db    3Bh,3Ah,3Bh,3Ah,80h,80h,80h,80h ; Scan Code 27h - Semi-colon
  1338.     Db    27h,22h,27h,22h,80h,80h,80h,80h ; Scan Code 28h - Single quote
  1339.     Db    60h,7Eh,60h,7Eh,80h,80h,80h,80h ; Scan Code 29h - Accent mark
  1340.     Db    84h,84h,84h,84h,84h,84h,84h,84h ; Scan Code 2Ah - Left shift
  1341.     Db    5Ch,7Ch,1Ch,1Ch,80h,80h,80h,80h ; Scan Code 2Bh - Backslash
  1342.     Db    7Ah,5Ah,1Ah,1Ah,80h,80h,80h,80h ; Scan Code 2Ch - Letter Z
  1343.     Db    78h,58h,18h,18h,80h,80h,80h,80h ; Scan Code 2Dh - Letter X
  1344.     Db    63h,43h,03h,03h,80h,80h,80h,80h ; Scan Code 2Eh - Letter C
  1345.     Db    76h,56h,16h,16h,80h,80h,80h,80h ; Scan Code 2Fh - Letter V
  1346.     Db    62h,42h,02h,02h,80h,80h,80h,80h ; Scan Code 30h - Letter B
  1347.     Db    6Eh,4Eh,0Eh,0Eh,80h,80h,80h,80h ; Scan Code 31h - Letter N
  1348.     Db    6Dh,4Dh,0Dh,0Dh,80h,80h,80h,80h ; Scan Code 32h - Letter M
  1349.     Db    2Ch,3Ch,2Ch,3Ch,80h,80h,80h,80h ; Scan Code 33h - Comma
  1350.     Db    2Eh,3Eh,2Eh,3Eh,80h,80h,80h,80h ; Scan Code 34h - Period
  1351.     Db    2Fh,3Fh,2Fh,3Fh,80h,80h,80h,80h ; Scan Code 35h - Slash
  1352.     Db    84h,84h,84h,84h,84h,84h,84h,84h ; Scan Code 36h - Right shift
  1353.     Db    87h,87h,87h,87h,87h,87h,87h,87h ; Scan Code 37h - Prtsc
  1354.     Db    83h,83h,83h,83h,83h,83h,83h,83h ; Scan Code 38h - Alt
  1355.     Db    20h,20h,20h,20h,80h,80h,80h,80h ; Scan Code 39h - Space bar
  1356.     Db    85h,85h,85h,85h,85h,85h,85h,85h ; Scan Code 3Ah - Caps lock
  1357.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 3Bh - Function 1
  1358.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 3Ch - Function 2
  1359.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 3Dh - Function 3
  1360.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 3Eh - Function 4
  1361.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 3Fh - Function 5
  1362.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 40h - Function 6
  1363.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 41h - Function 7
  1364.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 42h - Function 8
  1365.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 43h - Function 9
  1366.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 44h - Function 10
  1367.     Db    88h,88h,88h,88h,88h,88h,88h,88h ; Scan Code 45h - Numlock
  1368.     Db    96h,96h,86h,86h,80h,80h,80h,80h ; Scan Code 46h - Scroll lock
  1369.     Db    89h,89h,89h,89h,80h,80h,80h,80h ; Scan Code 47h - Home
  1370.     Db    8Ah,8Ah,8Ah,8Ah,80h,80h,80h,80h ; Scan Code 48h - Up arrow
  1371.     Db    8Bh,8Bh,8Bh,8Bh,80h,80h,80h,80h ; Scan Code 49h - PgUp
  1372.     Db    95h,95h,95h,95h,95h,95h,80h,80h ; Scan Code 4Ah - Pad minus
  1373.     Db    8Ch,8Ch,8Ch,8Ch,80h,80h,80h,80h ; Scan Code 4Bh - Left arrow
  1374.     Db    8Dh,8Dh,8Dh,8Dh,80h,80h,80h,80h ; Scan Code 4Ch - Pad 5
  1375.     Db    8Eh,8Eh,8Eh,8Eh,80h,80h,80h,80h ; Scan Code 4Dh - Right
  1376.     Db    94h,94h,94h,94h,94h,94h,80h,80h ; Scan Code 4Eh - Pad plus
  1377.     Db    8Fh,8Fh,8Fh,8Fh,80h,80h,80h,80h ; Scan Code 4Fh - End
  1378.     Db    90h,90h,90h,90h,80h,80h,80h,80h ; Scan Code 50h - Down arrow
  1379.     Db    91h,91h,91h,91h,80h,80h,80h,80h ; Scan Code 51h - PgDn
  1380.     Db    92h,92h,92h,92h,92h,92h,80h,80h ; Scan Code 52h - Ins
  1381.     Db    93h,93h,93h,93h,93h,93h,80h,80h ; Scan Code 53h - Del
  1382.     Db    87h,87h,87h,87h,87h,87h,87h,87h ; Scan Code 54h - System request
  1383.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 55h - Illegal
  1384.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 56h - Illegal
  1385.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 57h - Illegal
  1386.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 58h - Illegal
  1387.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 59h - Illegal
  1388.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 5Ah - Illegal
  1389.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 5Bh - Illegal
  1390.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 5Ch - Illegal
  1391.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 5Dh - Illegal
  1392.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 5Eh - Illegal
  1393.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 5Fh - Illegal
  1394.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 60h - Illegal
  1395.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 61h - Illegal
  1396.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 62h - Illegal
  1397.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 63h - Illegal
  1398.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 64h - Illegal
  1399.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 65h - Illegal
  1400.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 66h - Illegal
  1401.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 67h - Illegal
  1402.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 68h - Illegal
  1403.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 69h - Illegal
  1404.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 6Ah - Illegal
  1405.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 6Bh - Illegal
  1406.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 6Ch - Illegal
  1407.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 6Dh - Illegal
  1408.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 6Eh - Illegal
  1409.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 6Fh - Illegal
  1410.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 70h - Illegal
  1411.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 71h - Illegal
  1412.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 72h - Illegal
  1413.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 73h - Illegal
  1414.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 74h - Illegal
  1415.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 75h - Illegal
  1416.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 76h - Illegal
  1417.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 77h - Illegal
  1418.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 78h - Illegal
  1419.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 79h - Illegal
  1420.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 7Ah - Illegal
  1421.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 7Bh - Illegal
  1422.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 7Ch - Illegal
  1423.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 7Dh - Illegal
  1424.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 7Eh - Illegal
  1425.     Db    80h,80h,80h,80h,80h,80h,80h,80h ; Scan Code 7Fh - Illegal
  1426. ;******************************************************************************
  1427. ;
  1428. ;    Define the keyboard caps lock table
  1429. ;
  1430. ;******************************************************************************
  1431. Caps_Table    Equ    This Byte    ; Keyboard caps lock table
  1432.     Db    NOT_AFFECTED        ; Scan Code 00h - Non-Shifted key
  1433.     Db    NOT_AFFECTED        ; Scan Code 01h - Non-Shifted key
  1434.     Db    NOT_AFFECTED        ; Scan Code 02h - Non-Shifted key
  1435.     Db    NOT_AFFECTED        ; Scan Code 03h - Non-Shifted key
  1436.     Db    NOT_AFFECTED        ; Scan Code 04h - Non-Shifted key
  1437.     Db    NOT_AFFECTED        ; Scan Code 05h - Non-Shifted key
  1438.     Db    NOT_AFFECTED        ; Scan Code 06h - Non-Shifted key
  1439.     Db    NOT_AFFECTED        ; Scan Code 07h - Non-Shifted key
  1440.     Db    NOT_AFFECTED        ; Scan Code 08h - Non-Shifted key
  1441.     Db    NOT_AFFECTED        ; Scan Code 09h - Non-Shifted key
  1442.     Db    NOT_AFFECTED        ; Scan Code 0Ah - Non-Shifted key
  1443.     Db    NOT_AFFECTED        ; Scan Code 0Bh - Non-Shifted key
  1444.     Db    NOT_AFFECTED        ; Scan Code 0Ch - Non-Shifted key
  1445.     Db    NOT_AFFECTED        ; Scan Code 0Dh - Non-Shifted key
  1446.     Db    NOT_AFFECTED        ; Scan Code 0Eh - Non-Shifted key
  1447.     Db    NOT_AFFECTED        ; Scan Code 0Fh - Non-Shifted key
  1448.     Db    AFFECTED        ; Scan Code 10h - Shifted Key
  1449.     Db    AFFECTED        ; Scan Code 11h - Shifted Key
  1450.     Db    AFFECTED        ; Scan Code 12h - Shifted Key
  1451.     Db    AFFECTED        ; Scan Code 13h - Shifted Key
  1452.     Db    AFFECTED        ; Scan Code 14h - Shifted Key
  1453.     Db    AFFECTED        ; Scan Code 15h - Shifted Key
  1454.     Db    AFFECTED        ; Scan Code 16h - Shifted Key
  1455.     Db    AFFECTED        ; Scan Code 17h - Shifted Key
  1456.     Db    AFFECTED        ; Scan Code 18h - Shifted Key
  1457.     Db    AFFECTED        ; Scan Code 19h - Shifted Key
  1458.     Db    NOT_AFFECTED        ; Scan Code 1Ah - Non-Shifted key
  1459.     Db    NOT_AFFECTED        ; Scan Code 1Bh - Non-Shifted key
  1460.     Db    NOT_AFFECTED        ; Scan Code 1Ch - Non-Shifted key
  1461.     Db    NOT_AFFECTED        ; Scan Code 1Dh - Non-Shifted key
  1462.     Db    AFFECTED        ; Scan Code 1Eh - Shifted Key
  1463.     Db    AFFECTED        ; Scan Code 1Fh - Shifted Key
  1464.     Db    AFFECTED        ; Scan Code 20h - Shifted Key
  1465.     Db    AFFECTED        ; Scan Code 21h - Shifted Key
  1466.     Db    AFFECTED        ; Scan Code 22h - Shifted Key
  1467.     Db    AFFECTED        ; Scan Code 23h - Shifted Key
  1468.     Db    AFFECTED        ; Scan Code 24h - Shifted Key
  1469.     Db    AFFECTED        ; Scan Code 25h - Shifted Key
  1470.     Db    AFFECTED        ; Scan Code 26h - Shifted Key
  1471.     Db    NOT_AFFECTED        ; Scan Code 27h - Non-Shifted key
  1472.     Db    NOT_AFFECTED        ; Scan Code 28h - Non-Shifted key
  1473.     Db    NOT_AFFECTED        ; Scan Code 29h - Non-Shifted key
  1474.     Db    NOT_AFFECTED        ; Scan Code 2Ah - Non-Shifted key
  1475.     Db    NOT_AFFECTED        ; Scan Code 2Bh - Non-Shifted key
  1476.     Db    AFFECTED        ; Scan Code 2Ch - Shifted Key
  1477.     Db    AFFECTED        ; Scan Code 2Dh - Shifted Key
  1478.     Db    AFFECTED        ; Scan Code 2Eh - Shifted Key
  1479.     Db    AFFECTED        ; Scan Code 2Fh - Shifted Key
  1480.     Db    AFFECTED        ; Scan Code 30h - Shifted Key
  1481.     Db    AFFECTED        ; Scan Code 31h - Shifted Key
  1482.     Db    AFFECTED        ; Scan Code 32h - Shifted Key
  1483.     Db    NOT_AFFECTED        ; Scan Code 33h - Non-Shifted key
  1484.     Db    NOT_AFFECTED        ; Scan Code 34h - Non-Shifted key
  1485.     Db    NOT_AFFECTED        ; Scan Code 35h - Non-Shifted key
  1486.     Db    NOT_AFFECTED        ; Scan Code 36h - Non-Shifted key
  1487.     Db    NOT_AFFECTED        ; Scan Code 37h - Non-Shifted key
  1488.     Db    NOT_AFFECTED        ; Scan Code 38h - Non-Shifted key
  1489.     Db    NOT_AFFECTED        ; Scan Code 39h - Non-Shifted key
  1490.     Db    NOT_AFFECTED        ; Scan Code 3Ah - Non-Shifted key
  1491.     Db    NOT_AFFECTED        ; Scan Code 3Bh - Non-Shifted key
  1492.     Db    NOT_AFFECTED        ; Scan Code 3Ch - Non-Shifted key
  1493.     Db    NOT_AFFECTED        ; Scan Code 3Dh - Non-Shifted key
  1494.     Db    NOT_AFFECTED        ; Scan Code 3Eh - Non-Shifted key
  1495.     Db    NOT_AFFECTED        ; Scan Code 3Fh - Non-Shifted key
  1496.     Db    NOT_AFFECTED        ; Scan Code 40h - Non-Shifted key
  1497.     Db    NOT_AFFECTED        ; Scan Code 41h - Non-Shifted key
  1498.     Db    NOT_AFFECTED        ; Scan Code 42h - Non-Shifted key
  1499.     Db    NOT_AFFECTED        ; Scan Code 43h - Non-Shifted key
  1500.     Db    NOT_AFFECTED        ; Scan Code 44h - Non-Shifted key
  1501.     Db    NOT_AFFECTED        ; Scan Code 45h - Non-Shifted key
  1502.     Db    NOT_AFFECTED        ; Scan Code 46h - Non-Shifted key
  1503.     Db    NOT_AFFECTED        ; Scan Code 47h - Non-Shifted key
  1504.     Db    NOT_AFFECTED        ; Scan Code 48h - Non-Shifted key
  1505.     Db    NOT_AFFECTED        ; Scan Code 49h - Non-Shifted key
  1506.     Db    NOT_AFFECTED        ; Scan Code 4Ah - Non-Shifted key
  1507.     Db    NOT_AFFECTED        ; Scan Code 4Bh - Non-Shifted key
  1508.     Db    NOT_AFFECTED        ; Scan Code 4Ch - Non-Shifted key
  1509.     Db    NOT_AFFECTED        ; Scan Code 4Dh - Non-Shifted key
  1510.     Db    NOT_AFFECTED        ; Scan Code 4Eh - Non-Shifted key
  1511.     Db    NOT_AFFECTED        ; Scan Code 4Fh - Non-Shifted key
  1512.     Db    NOT_AFFECTED        ; Scan Code 50h - Non-Shifted key
  1513.     Db    NOT_AFFECTED        ; Scan Code 51h - Non-Shifted key
  1514.     Db    NOT_AFFECTED        ; Scan Code 52h - Non-Shifted key
  1515.     Db    NOT_AFFECTED        ; Scan Code 53h - Non-Shifted key
  1516.     Db    NOT_AFFECTED        ; Scan Code 54h - Non-Shifted key
  1517.     Db    NOT_AFFECTED        ; Scan Code 55h - Non-Shifted key
  1518.     Db    NOT_AFFECTED        ; Scan Code 56h - Non-Shifted key
  1519.     Db    NOT_AFFECTED        ; Scan Code 57h - Non-Shifted key
  1520.     Db    NOT_AFFECTED        ; Scan Code 58h - Non-Shifted key
  1521.     Db    NOT_AFFECTED        ; Scan Code 59h - Non-Shifted key
  1522.     Db    NOT_AFFECTED        ; Scan Code 5Ah - Non-Shifted key
  1523.     Db    NOT_AFFECTED        ; Scan Code 5Bh - Non-Shifted key
  1524.     Db    NOT_AFFECTED        ; Scan Code 5Ch - Non-Shifted key
  1525.     Db    NOT_AFFECTED        ; Scan Code 5Dh - Non-Shifted key
  1526.     Db    NOT_AFFECTED        ; Scan Code 5Eh - Non-Shifted key
  1527.     Db    NOT_AFFECTED        ; Scan Code 5Fh - Non-Shifted key
  1528.     Db    NOT_AFFECTED        ; Scan Code 60h - Non-Shifted key
  1529.     Db    NOT_AFFECTED        ; Scan Code 61h - Non-Shifted key
  1530.     Db    NOT_AFFECTED        ; Scan Code 62h - Non-Shifted key
  1531.     Db    NOT_AFFECTED        ; Scan Code 63h - Non-Shifted key
  1532.     Db    NOT_AFFECTED        ; Scan Code 64h - Non-Shifted key
  1533.     Db    NOT_AFFECTED        ; Scan Code 65h - Non-Shifted key
  1534.     Db    NOT_AFFECTED        ; Scan Code 66h - Non-Shifted key
  1535.     Db    NOT_AFFECTED        ; Scan Code 67h - Non-Shifted key
  1536.     Db    NOT_AFFECTED        ; Scan Code 68h - Non-Shifted key
  1537.     Db    NOT_AFFECTED        ; Scan Code 69h - Non-Shifted key
  1538.     Db    NOT_AFFECTED        ; Scan Code 6Ah - Non-Shifted key
  1539.     Db    NOT_AFFECTED        ; Scan Code 6Bh - Non-Shifted key
  1540.     Db    NOT_AFFECTED        ; Scan Code 6Ch - Non-Shifted key
  1541.     Db    NOT_AFFECTED        ; Scan Code 6Dh - Non-Shifted key
  1542.     Db    NOT_AFFECTED        ; Scan Code 6Eh - Non-Shifted key
  1543.     Db    NOT_AFFECTED        ; Scan Code 6Fh - Non-Shifted key
  1544.     Db    NOT_AFFECTED        ; Scan Code 70h - Non-Shifted key
  1545.     Db    NOT_AFFECTED        ; Scan Code 71h - Non-Shifted key
  1546.     Db    NOT_AFFECTED        ; Scan Code 72h - Non-Shifted key
  1547.     Db    NOT_AFFECTED        ; Scan Code 73h - Non-Shifted key
  1548.     Db    NOT_AFFECTED        ; Scan Code 74h - Non-Shifted key
  1549.     Db    NOT_AFFECTED        ; Scan Code 75h - Non-Shifted key
  1550.     Db    NOT_AFFECTED        ; Scan Code 76h - Non-Shifted key
  1551.     Db    NOT_AFFECTED        ; Scan Code 77h - Non-Shifted key
  1552.     Db    NOT_AFFECTED        ; Scan Code 78h - Non-Shifted key
  1553.     Db    NOT_AFFECTED        ; Scan Code 79h - Non-Shifted key
  1554.     Db    NOT_AFFECTED        ; Scan Code 7Ah - Non-Shifted key
  1555.     Db    NOT_AFFECTED        ; Scan Code 7Bh - Non-Shifted key
  1556.     Db    NOT_AFFECTED        ; Scan Code 7Ch - Non-Shifted key
  1557.     Db    NOT_AFFECTED        ; Scan Code 7Dh - Non-Shifted key
  1558.     Db    NOT_AFFECTED        ; Scan Code 7Eh - Non-Shifted key
  1559.     Db    NOT_AFFECTED        ; Scan Code 7Fh - Non-Shifted key
  1560. ;******************************************************************************
  1561. ;
  1562. ;    Define the special keys table
  1563. ;
  1564. ;******************************************************************************
  1565. Key_Table    Equ    This Word    ; Special key table
  1566.     Dw    Illegal_Key        ; Code 00 - Illegal scan code
  1567.     Dw    Control_Key        ; Code 01 - Control key
  1568.     Dw    Tab_Key         ; Code 02 - Tab key (Button 1)
  1569.     Dw    Alt_Key         ; Code 03 - Alternate key (Button 2)
  1570.     Dw    Shift_Key        ; Code 04 - Shift key was pressed
  1571.     Dw    Caps_Lock        ; Code 05 - Caps lock was pressed
  1572.     Dw    System_Reset        ; Code 06 - Ctrl. Scroll lock (Reset)
  1573.     Dw    System_Request        ; Code 07 - System Request (Break)
  1574.     Dw    Num_Lock        ; Code 08 - Num lock (Joystick Mode)
  1575.     Dw    Home_Key        ; Code 09 - Home key (Joystick up/left)
  1576.     Dw    Up_Key            ; Code 0A - Up arrow (Joystick up)
  1577.     Dw    PgUp_Key        ; Code 0B - PgUp key (Joystick up/right)
  1578.     Dw    Left_Key        ; Code 0C - Left arrow (Joystick left)
  1579.     Dw    Center_Key        ; Code 0D - Center key (Joystick center)
  1580.     Dw    Right_Key        ; Code 0E - Right arrow (Joystick right)
  1581.     Dw    End_Key         ; Code 0F - End key (Joystick down/left)
  1582.     Dw    Down_Key        ; Code 10 - Down arrow (Joystick down)
  1583.     Dw    PgDn_Key        ; Code 11 - PgDn key (Joy. down/right)
  1584.     Dw    Ins_Key         ; Code 12 - Ins. key (Joy X inc.)
  1585.     Dw    Del_Key         ; Code 13 - Del. key (Joy X dec.)
  1586.     Dw    Pad_Plus        ; Code 14 - Pad plus (Joy Y inc.)
  1587.     Dw    Pad_Minus        ; Code 15 - Pad minus (Joy Y dec.)
  1588.     Dw    Update_Toggle        ; Code 16 - Scroll lock (Update type)
  1589. ;******************************************************************************
  1590. ;
  1591. ;    Define the joystick call table
  1592. ;
  1593. ;    Numlock +
  1594. ;
  1595. ;    None, Shift, Ctrl, Ctrl/Shift, Alt, Alt/Shift, Alt/Ctrl, Alt/Ctrl/Shift
  1596. ;
  1597. ;******************************************************************************
  1598. Joy_Table    Equ    This Word
  1599.     Dw    Joystick_Mode        ; Numlock + None
  1600.     Dw    Joystick_Type        ; Numlock + Shift
  1601.     Dw    Joystick_Flight     ; Numlock + Ctrl
  1602.     Dw    Joystick_Dummy        ; Numlock + Ctrl/Shift
  1603.     Dw    Joystick_Center     ; Numlock + Alt
  1604.     Dw    Joystick_Dummy        ; Numlock + Alt/Shift
  1605.     Dw    Joystick_Fast        ; Numlock + Alt/Ctrl
  1606.     Dw    Joystick_Reset        ; Numlock + Alt/Ctrl/Shift
  1607. ;******************************************************************************
  1608. ;
  1609. ;    Define the keyboard status byte
  1610. ;
  1611. ;    -----------------
  1612. ;    |7|6|5|4|3|2|1|0|
  1613. ;    -----------------
  1614. ;     | | | | | | | |
  1615. ;     | | | | | | | -------> Shift key status (0 = Up, 1 = Down)
  1616. ;     | | | | | | ---------> Ctrl key status  (0 = Up, 1 = Down)
  1617. ;     | | | | | -----------> Alt key status (0 = Up, 1 = Down)
  1618. ;     | | | | -------------> ***** Reserved *****
  1619. ;     | | | ---------------> ***** Reserved *****
  1620. ;     | | -----------------> Scroll lock key status (1 = Locked)
  1621. ;     | -------------------> Num lock key status (1 = Locked)
  1622. ;     ---------------------> Caps lock key status (1 = Locked)
  1623. ;
  1624. ;******************************************************************************
  1625. Key_Status    Db    SCROLL_LOCKED + CAPS_LOCKED
  1626. ;******************************************************************************
  1627. ;
  1628. ;    Define any other keyboard variables
  1629. ;
  1630. ;******************************************************************************
  1631. Last_Key    Db    ?        ; Last actual keyboard code
  1632. Last_Scan    Db    ?        ; Last actual keyboard scan code
  1633. ;******************************************************************************
  1634. ;
  1635. ;    Define the end of the Emulator Code Segment
  1636. ;
  1637. ;******************************************************************************
  1638. Emulate Ends
  1639.     End                ; End of the Keyboard module
  1640.