home *** CD-ROM | disk | FTP | other *** search
- TURBO PASCAL AND SIDEKICK
- (Control-C Issues) 29 Jul 85
-
- Pardon any confusion I caused with my previous message
- regarding Ctrl-C problems with Turbo Pascal and Sidekick,
- but after further investigation I have found the following:
-
- I had been trying to do two things: (1) Accurately detect
- function and special keys, and (2) detect and process Ctrl-C.
- The problem that I have with the standard Turbo input routine
- is that when input is buffered, one cannot tell the difference
- between a function key and an ESC followed by another key!!
- Therefore I redefined CONINPTR to point to a function which
- called DOS Function 7 (Direct Keyboard Input Without Echo).
- This worked great (now I checked for a #00 instead of a #27
- to detect function keys), except that if Sidekick was resident
- Ctrl-C would never make it to my program; rather a CRLF
- followed by a '^C' would be sent to the display!! This was
- distressing because when CONINPTR was NOT redefined (and break
- processing was turned off ( {$C-} ), Ctrl-C was being detected
- correctly. On a hunch I decided to try Function 6 (Direct
- Keyboard/Display I/O). This works great! The following code
- is what I now use in all of my programs:
-
- type
- dos_parms = record case integer of
- 1: (AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags: Integer);
- 2: (AL,AH,BL,BH,CL,CH,DL,DH : Byte);
- end;
- var
- parm: dos_parms;
-
- function cin6:char;
- {DOS Function #6: Direct Keyboard/Display I/O (without echo
- OR Ctrl-C check}
- begin
- with parm do
- begin
- repeat
- AX := $0600;
- DL := $FF; {read keyboard version}
- msdos(parm);
- until (flags and ZF) = 0; {until character present}
- cin6 := Chr (AL);
- end;
- end;
-
- {*** this statement goes in intitialization code ***}
- coninptr :=ofs(cin6);
-
- Now simply use the standard keyboard I/O routines. For example,
- READ (KBD,CH);
- to read a character from the keyboard without echo. The test
- IF (CH = #27) AND KEYPRESSED THEN
- which is currently used to check for function keys, can now be
- written simply as:
- IF (CH = #0) THEN
- and Escape (#27) can be treated like a standard character.
-
- One last note: turning off Ctrl-C has an additional benefit not
- mentioned in the Turbo ref manual. In addition to turning off
- the check for Ctrl-C break, it allows the keystrokes to be
- buffered on input. With Ctrl-C on {$C+}, Turbo checks for
- Control-C input and at the same time FLUSHES the input buffer
- about every 18 timer ticks (I think, though it may be every
- timer tick). With Ctrl-C off {$C-}, Turbo allows buffering
- of the keystrokes which is very useful for most applications.
- If this buffering is not desired, a FLUSH_INPUT routine could
- be written to be called just before any input is desired. The
- routine would simply read and discard characters as long as
- KEYPRESSED is true.
-
- Hope this helps others avoid the confusion I experienced in
- working this problem out. If anyone has any questions/comments
- I can be reached at The RidgeRunner (703)-491-7054.
- -- Greg Brunet