home *** CD-ROM | disk | FTP | other *** search
- page 58,132
-
- ; kbd.asm
- ; contains: getkey(), gfkbhit(), kbfetch(), kbshift(),breakchk(),enhkbd()
- ;
- ;
- ; The Greenleaf Comm Library
- ;
- ; Copyright (C) 1984-90 Greenleaf Software Inc. All Rights Reserved.
- ;
- ;
- include model.h
- include prologue.h
- name kbd
-
- ;; AUTHOR:
- ; "" 21-OCT-1984 09:22:58.57
- ;
- ;; MODIFICATIONS:
- ; "" 12-JAN-1989 16:23:45.90
- ; Removed translate table for getkey()
- ;;;
-
- dseg kbd
-
- kstfunc db 1 ;keyboard status function #
- sstfunc db 2 ;shift status function #
- kinfunc db 0 ;input function #
- trapptr dw offset trfunc
-
- i23off dw 0
- i23seg dw 0
- dos_handler db 0ffh ;keeps track of last breakchk() value
- ;SET. When 0FFH it means vector has
- ;not yet been re-directed. If
- ;it == 0 then don't abort, if == 1
- ;abort.
-
- endds
-
- pseg getkey
-
- ;==>-- unsigned getkey(void)
- ;
- ;; ARGUMENTS:
- ; (none)
- ;
- ;; DESCRIPTION:
- ; Get keyboard code without echo.
- ;
- ;; SIDE EFFECTS:
- ; none
- ;
- ;; RETURNS:
- ; 8-bit standard ASCII code (0x00-0x7f) or predefined extended code
- ; per ibmkeys.h
- ;
- ;; AUTHOR:
- ;
- ;; MODIFICATIONS:
- ; David Nienhiser 12-JAN-1989 16:27:24.22
- ; Removed translate table for getkey()
- ;;;
- cproc getkey
- call [trapptr]
- mov ah,kinfunc
- int 16h ;rom bios keyboard input
- or ax,ax ;is it Ctrl-Break ?
- jz short gtkyex ;if so return ax=0 for control break
-
- cmp al,0e0h ;from second set of keys?
- jnz noaltk
- xor al,al
- noaltk: or al,al ;is it extended ?
- jz gtkyex ;return it if so
- xor ah,ah ;else return character in AL, clear AH
- gtkyex:
- call doschk
- cproce
-
- ;==>-- bool gfkbhit(void)
- ;
- ;; ARGUMENTS:
- ; (none)
- ;
- ;; DESCRIPTION:
- ; Test keyboard for activity via ROM-BIOS and return result
- ;
- ;; SIDE EFFECTS:
- ; (none)
- ;
- ;; RETURNS:
- ; TRUE (1) if keyboard code available, else FALSE (0)
- ;
- ;; AUTHOR:
- ;
- ;; MODIFICATIONS:
- ;
- ;;;
- cproc gfkbhit
- call [trapptr]
- mov ah,kstfunc
- int 16h ;rom-bios get keyboard status
- mov ax,1
- jnz havcod
- xor ax,ax ;say no keyboard activity
- havcod: cmp kstfunc,11h
- jz skpchk ;if new style skip next call
- call doschk
- skpchk:
- cproce ; or return code in AL/AH
-
- ;==>-- unsigned kbfetch(void)
- ;
- ;; ARGUMENTS:
- ; (none)
- ;
- ;; DESCRIPTION:
- ; One character is fetched from the keyboard FIFO buffer via
- ; ROM-BIOS. If the buffer is empty, this routine waits until
- ; a key is struck.
- ;
- ;; SIDE EFFECTS:
- ; (none)
- ;
- ;; RETURNS:
- ; ASCII code (low-byte), Keyboard Scan Code (high byte)
- ;
- ;; AUTHOR:
- ;
- ;; MODIFICATIONS:
- ;
- ;;;
- cproc kbfetch
- call [trapptr]
- mov ah,kinfunc
- int 16h ;rom bios keyboard input
- call doschk
- cproce
-
- ;==>-- unsigned kbshift(void)
- ;
- ;; ARGUMENTS:
- ; (none)
- ;
- ;; DESCRIPTION:
- ; Get current status of keyboard shift keys via ROM-BIOS.
- ;
- ;; SIDE EFFECTS:
- ; (none)
- ;
- ;; RETURNS:
- ; status of keyboard shift keys.
- ;
- ;; AUTHOR:
- ; David Nienhiser 25-MAR-1987 09:44:45.84
- ;
- ;; MODIFICATIONS:
- ;
- ;;;
- cproc kbshift
- call [trapptr]
- mov ah,sstfunc
- int 16h
- cproce
-
- ;==>-- int breakchk(control)
- ;
- ;; ARGUMENTS:
- ; (int) control - OFF(0),ON(1),or (2)
- ; ON = do not install ctrl break handler
- ; OFF = install ctrl-break handler so user
- ; program will not exit with ctrl-break
- ; 2 = Return current state (ON/OFF)
- ;
- ;; DESCRIPTION:
- ; Control/Status of control break function.
- ;
- ;; SIDE EFFECTS:
- ; If called with OFF as a parameter the control break handler
- ; in this file will be installed.
- ;
- ;; RETURNS:
- ; 1 if control break is ON, else 0
- ;
- ;; AUTHOR:
- ;
- ;; MODIFICATIONS:
- ;
- ;;;
- cproc breakchk
- mov ax,@ab[bp] ;see what user wants 0..2
- cmp al,0 ;Install handler?
- je break_install
- cmp al,1 ;Remove handler?
- je break_remove
- cmp al,2 ;Return status?
- je break_status
- or ax,-1 ;else return error
- jmp short bcxit
-
- break_status:
- mov ax,3300h ;yes,check
- int 21h
- xor ah,ah ;return AL
- mov al,dl
- jmp short bcxit
-
- break_remove:
- cmp dos_handler,0 ;See if I have the break handler
- jne bc1_ok ;Jump if I don't, he can keep it
- call unseti23 ;Give the handler back
- mov dl,1 ;set the command so DOS BREAK=ON
- jmp short bc1_ok ;and exit
-
- break_install:
- cmp dos_handler,0 ;see if vector has been re-directed
- je bc1_ok
- call seti23 ;if not re-direct to our code!
- mov dl,0 ;set the command so DOS BREAK=OFF
-
- bc1_ok:
- push dx
- mov ax,3301h
- int 21h
- pop ax ;saved as dx
- bcxit:
- cproce
-
- ;==>-- int enhkbd(void)
- ;
- ;; ARGUMENTS:
- ; (none)
- ;
- ;; DESCRIPTION:
- ; Determines if enhanced keyboard is installed.
- ;
- ;; SIDE EFFECTS:
- ; (none)
- ;
- ;; RETURNS:
- ; 1 = Enhanced keyboard is installed, 0 = Not installed
- ;
- ;; AUTHOR:
- ; David Nienhiser 25-MAR-1987 10:03:02.90
- ;
- ;; MODIFICATIONS:
- ;
- ;;;
- cproc enhkbd
- call enkbck
- cproce
-
- ;==>-- void _disenk(void)
- ;
- ;; ARGUMENTS:
- ; (none)
- ;
- ;; DESCRIPTION:
- ; Disables check/adjustment for enhanced keyboard
- ;
- ;; SIDE EFFECTS:
- ; enhanced keyboard will not be detected, must be called before
- ; any other keyboard functions.
- ;
- ;; RETURNS:
- ; (void)
- ;
- ;; AUTHOR:
- ; David Nienhiser 25-MAR-1987 10:04:48.48
- ;
- ;; MODIFICATIONS:
- ;
- ;;;
- cproc _disenk
- mov trapptr,offset trfret
- cproce
-
- ;==>-- doschk is a procedure used only by functions in this file
- ; it makes a dos call to give dos an oppurtunity to terminate
- ; the current program.
- ;
- doschk proc near
- cmp byte ptr dos_handler,0
- je doscex
- push ax
- mov ah,0bh ;check keyboard status via DOS
- int 21h ;this gives dos an oppurtunity to exit
- pop ax
- doscex: ret
- doschk endp
-
- ;==>-- INT 23 (control break) HANDLER
- ;
- ; Interrupt 23h is re-directed to here if breakchk(0||1) is called
- ;
- ;
- i23hnd proc far
- iret
- i23hnd endp
-
- ;==>-- Save current int 23h & Re-direct interrupt 23 to the i23hnd
- ;
- seti23 proc near
- push ax ;ah has something
- push ds
- push es
- mov ax,3523h ;get vector to es:bx
- int 21h
- mov i23off,bx
- mov i23seg,es
- mov ax,cs
- mov ds,ax
- mov dx,offset i23hnd
- mov ax,2523h ;set interrupt #23h
- int 21h
- pop es
- pop ds
- pop ax
- mov dos_handler,0
- ret
- seti23 endp
-
- unseti23 proc near
- push ds
- mov dx,i23off
- mov ax,i23seg
- mov ds,ax
- mov ax,2523h
- int 21h
- pop ds
- mov dos_handler,0ffH
- ret
- unseti23 endp
-
- enkbck proc near
- push ds
- mov ax,40h
- mov ds,ax
- mov bx,96h
- mov bl,[bx]
- pop ds
- xor ax,ax ;assume not installed
- and bl,10h
- jz enot
- inc ax
- enot: ret
- enkbck endp
-
- trfunc proc near
- mov trapptr,offset trfret
- call enkbck
- or ax,ax ;if enhanced kbd not installed skip
- jz trfret
- mov ah,10h
- or kstfunc,ah
- or sstfunc,ah
- or kinfunc,ah
- trfret: ret
- trfunc endp
- endps
- end
-