📄 buffinfo.doc
字号:
By Jim Pottkotter, 05/20/85
The seventh column contains the character associated with the
ASCII code. As in the horizontal buffer window above, control
codes are displayed as periods and extended codes are displayed as
small blocks. The eighth column shows into which general category
the code belongs. Control codes include all ASCII codes below 32.
Standard codes include all ASCII codes from 32 to 255. Extended
codes do not have an ASCII code. The ninth column presents a
narrative description of the decoded keystroke. The tenth column
distinguishes the active from the inactive codes. The last column
marks the head, last, and tail.
-1The Function Keys-0
Function keys 1 through 4 are programmed to provide additional
features. This also allows the program to demonstrate that
programmed function keys are not entered into the buffer. F1
clears the buffer. F2 returns you to DOS and executes the
keyboard buffer. Whatever you have queued up when you press F2 is
executed. If you enter DIR followed by a carriage return, and
then press F2, you will get a directory listing. F3 returns you
to DOS, but does not execute the buffer. F4 displays a few
reminders about the information presented. This should put a few
ideas in your head.
You get an intuitive understanding of the keyboard buffer just
from using your PC. BUFFLOOK.EXE shows you the internals of the
buffer more clearly than a technical narrative could. You know
what the buffer is, where it is, and how it is organized. Now
that you know how it works, you can control it to your advantage.
BUFFLOAD.SUB gives you control over the buffer.
-1Take Control-0
BUFFLOAD.SUB is in listing 1. You can add these BASIC
subroutines to your own programs, and use them to load or clear
the keyboard buffer. Given what you have already learned, the
subroutines are almost self-explanatory. The routine which loads
the buffer accepts either a string of standard characters and
control codes, or a string containing extended codes. The ASCII
values of characters in the string are then poked into the
buffer. Any code or character which has an ASCII code from 1 to
255 can be passed to the routine in BUFF.1$. For example, assume
you had the following short program.
10 BUFF.1$ = "CHKDSK" + CHR$(13) 'Load string
20 GOSUB 50 'Load buffer
30 CLS 'Housekeeping
40 SYSTEM 'Exit
50 REM -- BUFFLOAD.SUB GOES HERE
Page 5
By Jim Pottkotter, 05/20/85
This program loads the buffer with "CHKDSK", followed by a
carriage return. The carriage return you place at the end of a
string you want to execute counts as one of the fifteen characters
you can load in the buffer. The sample program then clears the
screen and exits to DOS. Exiting to DOS is like exiting to direct
mode in BASIC; the contents of the buffer are transferred to the
screen. Since the string ends with a carriage return, the CHKDSK
command is executed. If you have the program CHKDSK.COM on your
default drive, the program will run and give you a report on the
default drive. EXE files, COM files, and BAT files can all be
similarly initiated from BASIC using this technique.
-1Batch Files-0
Batch files present one of the greatest opportunities. You
can perform a lot of functions with batch files. The batch
command enhancements we got with 2.X really helped. Even an
average hacker should be able to write a program to create batch
files and initiate them from BASIC. Maybe you would like to give
the user a chance to specify which files or programs are to be
executed, and to specify the order in which the programs are to
run. By building the batch file in BASIC, you can vary the
programs and sequence to meet different needs at different times.
-1Extended Codes-0
There is also a provision to load extended codes with
BUFFLOAD.SUB. BUFF.2$ is used to load the buffer with extended
codes. This is a little trickier than loading standard codes.
Recall that extended codes do not have an ASCII code, so you have
to put zero in the first byte for that character in the buffer.
For example, if you wanted to load the buffer with <ALT> <1> and
the letter "B" for some odd reason, you would build the string
like this:
BUFF.2$ = CHR$(0) + CHR$(30) + CHR$(66) + CHR$(48)
As you can see, when you want to load the buffer with a string
containing extended codes, you have to define each character with
two bytes, including the standard characters. Note that when you
define a standard character, such as the letter "B", you do have
to provide the scan code. You are passing standard codes to the
buffer exactly like you would if you generated the character using
the keyboard.
Page 6
By Jim Pottkotter, 05/20/85
-1What BUFFLOAD.SUB Does-0
The buffer is purged before it is loaded. BUFFLOAD.SUB does
this by simply setting the tail and head pointers equal. When the
pointers are equal, the system thinks the buffer is empty. If
BUFF.1$ and BUFF.2$ are both empty, the buffer is still purged.
So, if all you want to do is clear the buffer, just set BUFF.1$
and BUFF.2$ to "" and perform the routine. In addition, if you
load a string into both variables, only the string in BUFF.1$ will
be loaded. Both BUFF.1$ and BUFF.2$ are left with null values
when you exit the routine.
-1When To Clear The Buffer-0
One way to control the keyboard buffer is to clear it. You
might want to do this in an error trapping routine in your
program. If you have detected an error that will prevent the
program from continuing, such as a disk failure, it is a good
policy to clear the buffer. You have no idea if the user has
gotten ahead of you and entered a series of keystrokes in
anticipation of what should happen. If you advise the user of an
error and ask for a response, the response you get might not be
appropriate. By displaying an error message, clearing the buffer,
and then handling the next keystrokes as the response, you reduce
the confusion factor considerably.
The ability to clear the keyboard buffer is useful because it
allows you to purge keystrokes you do not want passed to your
program or the system. Loading the buffer also presents some
opportunities. But, you need to know how programs and the system
interact with the buffer in greater detail.
-1How The System Interacts With The Buffer-0
The first place to begin is within your BASIC programs. The
INKEY$ statement reads one character from the buffer. However,
INKEY$ will return a two-character string when certain keystroke
combinations are entered. Only the last character is significant
in these cases. INPUT and LINE INPUT will also read from the
buffer, but the string must be terminated with a carriage return.
The next place to consider how the system uses the buffer is
in BASIC direct mode. For a review of the difference between
direct and indirect mode, see page 2-7 in the BASIC Reference
Manual. When your program ends, it returns to direct mode, unless
you end the program with the SYSTEM or CHAIN statements. In
direct mode, commands which you enter and terminate with a
carriage return are executed immediately. If you load the buffer
with executable commands before ending your program, you can cause
some action by your program, such as listing your program, even
after it is no longer in control.
Page 7
By Jim Pottkotter, 05/20/85
You are probably wondering how much you can really do with 15
characters of buffered input. Well, on the PC, 15 characters is
not as limiting as it may sound. In BASIC you have the <ALT>
<letter> combinations that allow you to "type" certain BASIC
keywords with just two keystrokes. By loading the buffer with the
code which represents the pressing of those keys, you get the full
BASIC keyword when the program exits to direct mode.
Programming the function keys is another way to extend the
effect of loading just one character into the buffer. See the KEY
statement in the BASIC Reference Manual for more details. Since
you can program each key with up to 15 characters, that certainly
opens up new possibilities. Don't forget that function keys
programmed in BASIC lose their assigned values when you return to
DOS.
-1Other Options-0
If you still feel cramped, there is another option. Before
ending your program, you can clear the screen and print several
lines of commands, separated by blank lines. You can execute the
commands by placing the cursor in the home position, and then
loading the buffer with one carriage return for each line of
commands. When you exit the program, you will enter direct mode,
and the queued carriage returns will execute your printed
commands. Certain commands could give you trouble, such as CLS
erasing commands lower on the screen before they can be executed,
but overall the technique is straightforward.
There are other ways to end your program than using END or
SYSTEM. Figure 3 lists several statements which exit to direct
mode. By loading the buffer with a GOTO (line number) before
executing these statements, you can enter your program again and
resume execution. It is very important to note which statements
initialize variables and close files.
One of these statements deserves special attention. DELETE
does clear variables and it also closes files. However, if the
deleted lines are not referenced after the lines are deleted, the
program is still executable. It is possible to delete routines
that will not be used during a particular execution of the
program, and return control to the program without operator
intervention. Deleting initialization or hardware specific
routines could free memory in applications that are already tight
on memory.
In addition, EDIT, AUTO, RUN, and CHAIN also affect variables
and files under certain circumstances. EDIT and AUTO clear
variables and close files if the program is actually changed. RUN
clears variables and closes files, although it does not exit to
direct mode. CHAIN may do the same thing, depending on the
options used. Review these individual statements in the BASIC
Reference Manual for more information. Encountering an error
condition not handled within the program causes an exit to direct
mode. Files are closed, but variables are not lost.
Page 8
By Jim Pottkotter, 05/20/85
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -