home *** CD-ROM | disk | FTP | other *** search
- ;
- ; Name KBPLACE -- Place one keystroke in keyboard buffer.
- ;
- ; Synopsis ret = kbplace (where, value, scan);
- ;
- ; int ret 0 (KB_OK) if successful, 1 (KB_FULL)
- ; if buffer full, or 2 (KB_PLACE) if
- ; the place specified was neither
- ; the head nor the tail of the queue.
- ;
- ; int where KB_HEAD if keystroke is to be placed
- ; at head of queue, KB_TAIL if at tail.
- ;
- ; char value ASCII value of keystroke (0 if not
- ; an ASCII character).
- ;
- ; char scan Scan code of keystroke.
- ;
- ; Description This function places one keystroke at the head or tail
- ; of the BIOS type-ahead buffer if there is room for it.
- ;
- ; KBPLACE assumes that the BIOS type-ahead buffer is at
- ; the standard location of 0x40:0x1e. It will probably
- ; malfunction if such is not the case.
- ;
- ; The BIOS keyboard buffer is arranged as a circular queue
- ; of fifteen pairs of bytes (plus one pair for overhead).
- ; For extended key sequences the character value is 0 and
- ; the scan code is as described in the IBM Technical
- ; Reference. For ASCII characters, on the other hand, the
- ; first byte of the pair is the ASCII code for the
- ; character and the second is the keystroke's scan code
- ; (if the key was generated by a normal scan code) or 0
- ; (if the key was generated by ALT plus the numeric ASCII
- ; code on the numeric keypad). For instance,
- ;
- ; pressing 'A' generates character 65, scan code 30,
- ;
- ; but
- ;
- ; pressing ALT + 65 generates character 65, scan code 0.
- ;
- ; (Virtually all application programs treat those two
- ; cases identically.)
- ;
- ; Returns ret 0 (KB_OK) if successful, 1 (KB_FULL) if
- ; buffer full, or 2 (KB_PLACE) if the
- ; place specified was neither the
- ; head nor the tail of the queue.
- ;
- ; Version 6.00 (C)Copyright Blaise Computing Inc. 1987,1989
- ;
-
- include beginasm.mac ; Specifies the C compiler
- beginProg kbplace
-
- KB_HEAD equ 0
- KB_TAIL equ 1
-
- where equ word ptr [bp + stkoff + 0] ; Addresses of arguments
- value equ byte ptr [bp + stkoff + 2]
- scan equ byte ptr [bp + stkoff + 4]
-
- buffer_head equ word ptr ds:1ah
- buffer_tail equ word ptr ds:1ch
- kb_buffer equ 1eh
- kb_buffer_end equ 3eh
-
- ; Beginning of actual code
- push bp
- mov bp, sp
- push ds
- pushf ; Save interrupt state.
-
- mov ax, 40h ; Segment address of BIOS data
- mov ds, ax
- assume ds:nothing
-
- cli ; Disable interrupts.
-
- cmp where, KB_HEAD
- jz try_at_head
-
- cmp where, KB_TAIL
- jz try_at_tail
-
- mov ax, 2
- jmp short exit
-
- try_at_head:
- mov bx, buffer_head
- dec bx ; Tentatively step head back.
- dec bx
- cmp bx, kb_buffer
- jae k5h
- ; Went past beginning of buffer,
- mov bx, kb_buffer_end-2; so wrap to end.
- k5h:
- ; Now BX has new head pointer.
- cmp bx, buffer_tail
- je no_room
-
- mov al, value
- mov ah, scan
- mov [bx], ax ; Store value & scan code
- ; at buffer head.
- mov buffer_head, bx ; New head pointer.
-
- jmp short success
-
- try_at_tail:
- mov bx, buffer_tail
- mov cx, bx
- inc cx ; Tentatively advance new tail.
- inc cx
- cmp cx, kb_buffer_end
- jb k5
- ; Went past end of buffer,
- mov cx, kb_buffer ; so wrap to beginning.
- k5:
- ; Now CX has new tail.
- cmp cx, buffer_head
- je no_room
-
- mov al, value
- mov ah, scan
- mov [bx], ax ; Store value & scan code
- ; at buffer tail.
- mov buffer_tail, cx ; New tail pointer.
-
- success:
- xor ax, ax
- jmp short exit
-
- no_room:
- mov ax, 1
-
- exit:
- popff ; Restore interrupt state.
-
- pop ds
- pop bp
- ret
-
- endProg kbplace
- end