⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buffinfo.doc

📁 Tutorial on keyboard buffer
💻 DOC
📖 第 1 页 / 共 3 页
字号:
         By Jim Pottkotter, 05/20/85
                        -1The Keyboard Buffer Explained-0
             -1Introduction-0
             The keyboard buffer on the PC is a neat trick.  You just key
         in letters and other characters and the computer uses them as
         necessary.  That's all there is to it, right?  Well, yes and no.
             Keyboard buffers are a neat trick, and Big Blue certainly knew
         what they were doing when they put one in the PC.  Even though
         your trusty buffer serves you well now, you can get it to do even
         more if you understand how it works.  You can clear it, load it,
         and even use it to execute batch files and commands from BASIC.
         Interested?  I will give you a short BASIC subroutine to do this
         and more.
             -1Buffers In General-0
             First, we need to cover a little background material.  Buffers
         are fundamental to computer performance.  Buffers smooth out the
         delays between comparatively fast and slow processes.  Input and
         output of all types generally fall into this category because
         these processes usually require the passing of data to and from
         external devices like keyboards, disks, and printers.  Most
         printers have at least a small buffer.  The computer is fast, but
         the printer is relatively slow.  Buffering the output to the
         printer allows the printer to catch up when it can, and frees the
         computer to do something else.
             While print buffers are an example of output buffers, keyboard
         buffers are an example of input buffers.  In this case, you are
         the slow part of the system.  The buffer allows you to plod along
         at hunt and peck speed, while your program is busy doing something
         useful.  When the program stops to handle your keyboard input, it
         can usually catch up quickly.  The result of this handy
         man-machine interface is greater throughput; you get finished
         quicker.
             -1The Keyboard Buffer-0
             Almost every keystroke you enter goes through the buffer.  I
         say almost because, as you would expect, there are exceptions.
         The buffer accepts up to 15 keystrokes before beeping at you.
         Keystrokes are stored in the buffer sequentially, FIFO fashion.
         Even keystroke combinations take up only one keystroke place in
         the buffer. Examples of these are <ALT> <F1> and <CTRL> <F10>.
         These and other combinations are treated as single keystrokes
         because the <ALT> and <CTRL> keys are actually shift keys, giving
         some keys alternate uses.
         By Jim Pottkotter, 05/20/85
             One combination you probably use frequently is <CTRL> <BREAK>.
         You may not have noticed it before, but in addition to stopping
         your program, <CTRL> <BREAK> also clears the buffer.  Another
         combination you are familiar with is <CTRL> <NUM LOCK>.  You use
         these keys to make your programs pause, or to stop a fast moving
         listing on the monitor.  This combination does not go into the
         buffer, nor does the key you press to get out of pause.  SHIFT
         <PRTSC> behaves similarly, printing the screen as requested, but
         not entering the buffer.  Function keys which you monitor under
         program control using the KEY (N) ON and ON KEY(N) GOSUB features
         of BASICA are not entered into the buffer.
             -1How To Make Heads And Tails Out Of The Buffer-0
             The buffer is actually a continuous loop.  While it has a
         limited physical size, it does not have a typical beginning or
         end.  This sounds like double-talk, but bear with me.  The memory
         required to manage the keyboard buffer consists of 34 bytes.  And,
         the buffer is in the system unit, not the keyboard as you might
         assume.  One byte points to the address of the first queued
         keystroke in the buffer.  Think of it as the head of the buffer.
         One byte points to the next available address within the buffer
         for storing a keystroke.  This next available location is called
         the tail.  If the buffer is empty and you press a key, that key
         goes in the tail of the buffer, and the tail address is updated to
         reflect the next available buffer storage position.
             The buffer consists of thirty-two bytes of storage.  Thirty
         bytes are required for holding up to fifteen keystrokes.  The
         reason the buffer takes twice as many bytes as the number of
         keystrokes is because each buffered keystroke uses two bytes of
         memory.  The two remaining bytes in the buffer represent the tail
         of the buffer, the place where the next keystroke will be stored.
         Figure 1 shows the addresses of the buffer management area in
         memory.
             You can use PEEK and POKE to examine and manipulate the
         buffer.  Or, you can use BUFFLOOK.EXE to examine the buffer, and
         BUFFLOAD.SUB in listing 1 to clear or load the buffer.
         BUFFLOOK.EXE is described here, and BUFFLOAD.SUB is described in
         detail later.
             -1A Window Into The Buffer-0
             BUFFLOOK.EXE is an interactive teaching tool.  The program
         allows you to enter keystrokes, and see what effect they have on
         the buffer.  Figure 2 is a screen print from the program.  The
         upper left portion of the screen contains the decimal and hex
         addresses of the first, last, and next active character positions
         in the buffer.  These are labelled as the head, last, and tail
         respectively.  The number of active characters in the buffer is
         also displayed.  All decimal and hex address are relative to
         segment zero.
                                         Page 2
         By Jim Pottkotter, 05/20/85
             -1The Top Of The Display-0
             The top center portion of the screen contains the real-time
         window to the buffer.  This is one of the most interesting parts
         of the display.  The window display consists of four
         sixteen-character lines of information.  The first line is a
         simple scale from one to sixteen. Remember, the buffer can hold up
         to fifteen characters, and the buffer has a tail indicating where
         the next character entered will be stored.  This scale shows the
         physical buffer positions.
             The second line shows the physical buffer contents.  Almost
         all displayable characters are shown.  Control characters such as
         line feed and carriage return would corrupt the display, so
         control characters are indicated by a period.  Extended keystrokes
         such as <ALT> <F1> do not have a character representation, so they
         are indicated by a small block, CHR$(254).
             Since almost every keystroke you enter is passed through the
         buffer, it is usually full of characters.  However, not all
         characters are active.  Active characters are those presently
         queued, and represent the characters which will be passed to the
         next program to read the keyboard.  Inactive characters are "dead
         soldiers" that have already been used.
             The third line shows the relative position within the physical
         buffer that each active character holds.  Only the active
         characters are numbered.  This line also shows the caret symbol
         (^), showing where the next active character you enter will be
         inserted.
             The fourth line labels the head, last, and tail positions
         within the buffer.  Active characters are contained between the
         head and tail markers inclusive.  This is handy when buffer
         wraparound occurs.
             -1The Main Body Of The Display-0
             The main body of the display contains columns of information,
         and provides more detail about the buffer contents.  The first two
         columns show the decimal and hex address locations of each
         character in the buffer.  The address locations are consecutive,
         and correspond to the physical buffer locations.  The physical and
         relative positions of characters in the buffer are listed in the
         third and fourth columns.
                                         Page 3
         By Jim Pottkotter, 05/20/85
             The decimal codes which represent the contents of each buffer
         character are listed in the fifth and sixth columns.  Here you
         begin to understand visually why each character in the buffer
         requires two bytes of storage.  Standard and control characters
         have a positive number in the first physical byte of storage for a
         character.  This number is the ASCII value of the character.  The
         ASCII character codes are explained on pages 1 through 5 in
         appendix G of the BASIC Reference Manual.  Extended keystroke
         combinations have a zero in this column because they cannot be
         represented using standard ASCII codes.  Extended codes are
         explained and listed on pages 6 and 7 in appendix G of the Basic
         Reference Manual.
             The sixth column usually contains the scan code of the key
         pressed.  As usual, there are exceptions.  The keyboard has 83
         primary keys which have been assigned arbitray numbers.  The scan
         code is the arbitray number assigned to the key.  You don't need
         your PC to figure out that there are more than 83 valid keystroke
         combinations.  So, some of the extended codes have been assigned
         unique codes that cannot be easily mapped to the keyboard layout.
         Appendix K in the BASIC Reference Manual has a keyboard diagram
         and list of keyboard scan codes.
             The sixth column reveals a little more information.  You can
         press <CTRL> and a letter to generate certain codes.  Press <CTRL>
         <A> and you get the same character as CHR$(1).  Press <CTRL> <B>
         and you get the same character as CHR$(2), etc.  These are control
         codes, and there is a brief description of this procedure on page
         2-15 of the BASIC Reference Manual.  BUFFLOOK.EXE shows that codes
         entered using this technique have the typical ASCII code in the
         first byte, and the primary keyboard scan code in the second
         byte.
             However, there is another way to enter these codes which gives
         a different result.  You can press <ALT> and a series of numbers
         from the numeric keypad representing the ASCII code of a character
         you want to generate.  After you enter the last digit of the
         number and release the <ALT> key, you get the corresponding
         character.  This method works for ASCII values 1 through 255.
         Page 1 of Appendix G contains a description of the procedure.
         When entering characters using this keystroke sequence, you will
         notice that the scan code is always zero.  This bit of trivia
         might be of value to you if you wanted to determine in a program
         how a character was entered.
                                         Page 4

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -