home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT7 / SCANCODE.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-08-29  |  6.8 KB  |  154 lines

  1. ;
  2. ;       Program Scancode ( Chapter 7 )
  3. ;
  4.     page    55,132
  5. .model  small
  6. .stack  512
  7. .data
  8. CR      equ     0Dh             ; The Carriage return code
  9. LF      equ     0Ah             ; The Line feed code
  10. TAB     equ     09h             ; The TAB code
  11. BELL    equ     07h             ; The BELL code
  12. EscScan equ     01h             ; The Scan code for ESC key
  13. KbdPort equ     60h             ; PPI 8225A port A
  14. EndMsg  equ     24h             ; Dollar sign - end of message for DOS service
  15. NewHand dd      NewInt9         ; Reference to the new handler for int 09
  16. FuncN   db      0               ; Function number for interrupt 16h
  17. BegMsg  db      CR,LF,LF,BELL,TAB
  18.     db      'SCAN CODES BROWSER   (INT 09h)      Version 2.0   19.05.1992'
  19.     db      CR,LF,TAB
  20.     db      '    Copyright (C) 1992,  V.B.Maljugin, Russia, Voronezh'
  21.     db      CR,LF,EndMsg
  22. Kbd83   db      CR,LF,TAB,TAB, 'You have a standard 83-key keyboard',EndMsg
  23. Kbd101  db      CR,LF,TAB,TAB,'You have an enhanced 101/102 keyboard',EndMsg
  24. InsMsg  db      CR,LF,CR,LF,TAB
  25.     db      'An additional handler for interrupt 09h will be called'
  26.     db      CR,LF,TAB,'    through the function '
  27. TFuncN  dw      '00'                    ; Text representation for FuncN
  28.     db      'h of BIOS interrupt 16h.'
  29.     db      CR,LF,TAB,TAB,'All the codes above 0F9h will be ignored.',CR,LF
  30.     db      CR,LF,TAB,'Press ESC to exit or any other key to '
  31.     db      'determine its scan code',CR,LF,LF,EndMsg
  32. FinMsg  db      CR,LF,LF,BELL,TAB,TAB
  33.     db      'SCAN  CODES  BROWSER  -  End  of  job.'
  34.     db      CR,LF,EndMsg
  35. .code
  36.  
  37. OldDS   dw      ?
  38. LinePos db      0
  39. Before9 db      0
  40. Con16   db      16
  41. OutByte db      'xx ',EndMsg
  42. CrLf    db      CR,LF,EndMsg
  43. HexTab  db      '0','1','2','3','4','5','6','7'
  44.     db      '8','9','A','B','C','D','E','F'
  45.  
  46. NewInt9 proc    far                     ; Additional handler for INT 9
  47.     push    ax
  48.     push    bx
  49.     push    dx
  50.     push    ds
  51.     in      al,KbdPort              ; Read scan code from keyboard port
  52.     push    ax                      ; Push this SCAN CODE for processing
  53.     pushf                           ; This is needed for interrupt call
  54.     db      9Ah                     ; OpCode for FAR CALL
  55. Off9    dw      ?                       ; Offset address for standard handler
  56. Seg9    dw      ?                       ; Segment address for standard handler
  57.     pop     ax                      ; AL contains the scan code
  58.     cli                             ; to avoid keyboard buffer ovrflow
  59. ;       in      al,KbdPort              ; Read scan code from keyboard port     
  60.     mov     ah,0                    ; AX now in range 0 - 255
  61.     cmp     al,0FAh                 ; "dirty" code obtained?
  62.     jb      ProcScan                ; if not, process
  63.     jmp     NotShow                 ; skip extra codes
  64. ProcScan:
  65.     div     Con16                   ; AL - first hex digit, AH - second
  66.     mov     bh,0                    ; Clear high part of BX
  67.     push    cs                      ; After this CS and DS are equal to
  68.     pop     ds                      ;    address internal area of handler
  69.     mov     bl,al                   ; Take the first hex digit
  70.     mov     al,HexTab[bx]           ; Take the corresponding character
  71.     mov     OutByte[0],al           ; Place it into output string
  72.     mov     bl,ah                   ; Take the second hex digit
  73.     mov     al,HexTab[bx]           ; Take the corresponding character
  74.     mov     OutByte[1],al           ; Place it into output string
  75.     lea     dx,cs:OutByte           ; Addres of scan code text into DX
  76.     mov     ah,09                   ; Function 09h - output text string
  77.     int     21h                     ; Dos service call
  78.     inc     LinePos                 ; Increase counter of bytes output
  79.     cmp     LinePos,24              ; 24 code per line are valid
  80.     jb      NotSkip                 ; If less than 24, don't skip line
  81.     mov     LinePos,0               ; Clear counter of codes in line
  82.     lea     dx,CrLf                 ; Addres of LineFeed code into DX
  83.     int     21h                     ; Dos service call
  84. NotSkip:
  85. NotShow:
  86.     pop     ds
  87.     pop     dx
  88.     pop     bx
  89.     pop     ax
  90.     iret
  91. NewInt9 endp
  92. .startup
  93.  
  94.     mov     OldDS,ds
  95.     lea     dx,BegMsg               ; Addres of start message into DX
  96.     mov     ah,09                   ; Function 09h - output text string
  97.     int     21h                     ; Dos service call
  98.  
  99.     mov     ax,40h                  ; 40h - segment address for BIOS area
  100.     mov     es,ax                   ; Place this address into ES
  101.     test    byte ptr es:[96h],10h   ; Bit 4 - 101-key keyboard indicator
  102.     jnz     Pres101                 ; If enhanced keyboard is present
  103.     lea     dx,Kbd83                ; Addres of message into DX
  104.     mov     ah,09                   ; Function 09h - output text string
  105.     int     21h                     ; Dos service call
  106.     jmp     PrtInstr                ; To print the initial message
  107.  
  108. Pres101:
  109.     lea     dx,Kbd101               ; Addres of start message into DX
  110.     mov     ah,09                   ; Function 09h - output text string
  111.     int     21h                     ; Dos service call
  112.     mov     FuncN,10h               ; 10h - Read From Enhanced Keyboard
  113.     mov     TFuncN,'01'             ; Text '01' because TFuncN is a word!
  114.  
  115. PrtInstr:
  116.     lea     dx,InsMsg               ; Addres of message into DX
  117.     mov     ah,09                   ; Function 09h - output text string
  118.     int     21h                     ; Dos service call
  119.  
  120.     mov     ah,35h                  ; Function 35h - Get interrupt vector
  121.     mov     al,09h                  ; Interrupt number is 09h
  122.     int     21h                     ; DOS service call
  123.     mov     Off9,bx                 ; Save offset addres of old handler
  124.     mov     Seg9,es                 ; Save segment address of old handler
  125.     lds     dx,NewHand              ; DS:DX - full addres of new handler
  126.     mov     ah,25h                  ; Function 25h - set interrupt vector
  127.     int     21h                     ; DOS service call
  128.     mov     ds,OldDS
  129.  
  130. NextKey:
  131.     mov     ah,0                    ; Function 00h - read character
  132.     int     16h                     ; BIOS keyboard service
  133.     cmp     ah,EscScan              ; Is the ESC key pressed?
  134.     jne     NextKey                 ; If not - process the next key
  135.  
  136. Finis:
  137.     mov     dx,Off9                 ; Offset address for old handler
  138.     mov     ds,Seg9                 ; Segment address for old handler
  139.     mov     ax,2509h                ; Set interrupt vector for INT 9
  140.     int     21h                     ; DOS service call
  141.  
  142.     mov     ah,0Ch                  ; Function 0Ch - clear keyboard buffer
  143.     int     21h                     ; Dos service call
  144.  
  145.     mov     ds,OldDS
  146.     lea     dx,FinMsg               ; Addres of message into DX
  147.     mov     ah,09                   ; Function 09h - output text string
  148.     int     21h                     ; Dos service call
  149.  
  150.     mov     ax,4C00h                ; Function 4Ch - terminate process
  151.     int     21h                     ; DOS service call
  152.  
  153.     end
  154.