home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT10 / SCANCODD.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  5.6 KB  |  151 lines

  1. ;
  2. ;       Program ScanCodD ( Chapter 10 )
  3. ;
  4.     page    55,132
  5. .model  small
  6. .stack
  7. .data
  8. CR      equ     00Dh            ; Carriage return code
  9. LF      equ     00Ah            ; Line feed code
  10. EscScan equ     001h            ; Scan code for ESC key
  11. KbdPort equ     060h            ; PPI 9225 port A
  12. EndMsg  equ     024h            ; Dollar sign - enf of message for DOS service
  13. NewHand dd      NewInt9         ; Reference to the new handler for int 09
  14. ScanCod db      0
  15. BegMsg  db      CR,LF,LF
  16.     db      '   SCAN CODES BROWSER 3.0 ', CR,CR,LF
  17.     db      'Interrupt 09h handler totally replaced',CR,LF
  18.     db      EndMsg
  19. Kbd83   db      CR,LF,'You have a standard 83-key keyboard',CR,LF,EndMsg
  20. Kbd101  db      CR,LF,'You have an enhanced 101/102 keyboard',CR,LF,EndMsg
  21. InsMsg  db      CR,LF,'Press ESC to exit else',CR,LF
  22.     db      'Press and relese any other key',CR,LF,LF,EndMsg
  23. FinMsg  db      CR,LF,'       Job terminated',CR,LF
  24.     db      ' Standard value of interrupt vector 09h '
  25.     db      'has been restored.', CR,LF, EndMsg
  26.  
  27. .code
  28. OutB    proc    near uses AX
  29.     cmp     al,0Ah          ; Is it decimal digit ( 0 - 9)?
  30.     jb      NoCorr          ; No correction - first 10 hex digit are dec
  31.     cmp     al,10h          ; Is it hexadecimal digit ( A - F )?
  32.     jb      HexCyph         ; If so correct for character representation
  33.     mov     al,' '          ; If not, replace it with blank
  34.     jmp     OutScr          ;   and output
  35. HexCyph:add     al,07h          ; This transform hex digits A - F
  36. NoCorr: add     al,30h          ; Convert integer to character
  37. OutScr: mov     ah,0Eh          ; Function 0Eh - write character
  38.     int     10h             ; BIOS video service
  39.     inc     NumL
  40.     cmp     NumL,60
  41.     jl      NoNewL
  42.     mov     al,CR
  43.     int     10h
  44.     mov     al,LF
  45.     int     10h
  46.     mov     NumL,0
  47. NoNewL: ret
  48. NumL    dw      0
  49. OutB    endp
  50.  
  51. PrtByte proc    near uses AX DX
  52.     mov     ah,0            ; Clear high part of AX
  53.     mov     dx,0010h        ; Divider into BX
  54.     div     dl              ; AL - result, AH - remainder
  55.     mov     dx,ax           ; Save results
  56.     call    OutB
  57.     mov     al,dh
  58.     call    OutB
  59.     mov     al,' '          ; Character to be printed is a blank
  60.     call    OutB
  61.     ret                     ; Return to the caller
  62. PrtByte endp
  63.  
  64. EndInt  proc    near
  65.     in      al,61h          ; read Port B
  66.     or      al,80h          ; set bit 7 to 1
  67.     out     61h,al          ; output to port B
  68.     jmp     $+2             ; delay (needed for fast PC)
  69.     and     al, not 80h     ; clear bit 7
  70.     out     61h,al          ; output to port B
  71.     mov     al,20h          ; EOI code into AL
  72.     out     20h,al          ; signal EOI
  73.     ret
  74. EndInt  endp    
  75.  
  76.  
  77. NewInt9 proc    near
  78.     mov     SaveAX,ax
  79. ContKey:pushf                   ; save original flags
  80.     in      al,60h          ; read scan code
  81.     cmp     al,EscScan      ; ESC pressed?
  82.     je      Fin             ; if so, return
  83.     call    PrtByte         ; output scan code
  84.     Call    EndInt
  85.     sti                     ; allow interrupts
  86.     popf                    ; restore original flags
  87.     iret
  88. Fin:    Call    EndInt
  89.     mov     ax,SaveAX
  90.     popf
  91. Jmp9    db      0EAh            ; opcode for JMP FAR
  92. OldInt9 dw      ?,?             ; Address of old handler for interrupt 09h
  93. SaveAX  dw      ?       
  94. NewInt9 endp
  95.  
  96. .startup
  97.     lea     dx,BegMsg       ; Addres of start message into DX
  98.     mov     ah,09           ; Function 09h - output text string
  99.     int     21h             ; Dos service call
  100.  
  101.     mov     ax,40h          ; 40h - segment address for BIOS data area
  102.     mov     es,ax           ; Place this address into ES
  103.     test    byte ptr es:[96h],10h   ; Bit 4 - 101-key keyboard indicator
  104.     jnz     Pres101
  105.     lea     dx,Kbd83        ; Addres of start message into DX
  106.     mov     ah,09           ; Function 09h - output text string
  107.     int     21h             ; Dos service call
  108.     jmp     PrtInstr
  109.  
  110. Pres101:
  111.     lea     dx,Kbd101       ; Addres of start message into DX
  112.     mov     ah,09           ; Function 09h - output text string
  113.     int     21h             ; Dos service call
  114.  
  115. PrtInstr:
  116.     lea     dx,InsMsg       ; Addres of start 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     OldInt9[0],bx         ; Save offset addres of old handler
  124.     mov     OldInt9[2],es         ; Save segment address of old handler
  125.     push    ds              ; DS will contain the segment of new handler
  126.     lds     dx,NewHand      ; Full addres of new handler into DS:DX
  127.     mov     ah,25h          ; Function 25h - set interrupt vector
  128.     int     21h             ; DOS service call
  129.     pop     ds              ; Restore the data segment register
  130.  
  131. NextKey:mov     ah,0Ch          ; Function 0Ch - clear the keyboard buffer
  132.     int     21h             ; Dos service call
  133.     mov     ah,0            ; Function 00h - read character from keyboard
  134.     int     16h             ; BIOS keyboard service
  135.     cmp     ah,EscScan      ; Is the ESC key pressed?
  136.     jne     NextKey         ; If not - process the next key
  137.  
  138. Finis:  lea     dx,FinMsg       ; Addres of start message into DX
  139.     mov     ah,09           ; Function 09h - output text string
  140.     int     21h             ; Dos service call
  141.  
  142.     mov     dx,OldInt9[0]   ; Offset address for old handler into DX
  143.     mov     ds,OldInt9[2]   ; Segment address for old handler into DS
  144.     mov     ax,2509h        ; Set interrupt vector for INT 9
  145.     int     21h             ; DOS service call
  146.     
  147.     mov     ax,4C00h        ; Function 4Ch - terminate process
  148.     int     21h             ; DOS service call
  149.  
  150.     end
  151.