Category : Pascal Source Code
Archive   : FIXRAW.ZIP
Filename : FIXRAW.INC

 
Output of file : FIXRAW.INC contained in archive : FIXRAW.ZIP
(*
Turbo Pascal Version 4.0 uses the standard input in places
where earlier versions of Turbo Pascal did not. In particular,
if TheVar is some variable other than a file variable, then
Read (TheVar) reads the standard input by default (it does not
read the standard input by default if have USES Crt; in the
file).

Using the standard input without redirection can cause
problems. If raw mode is on, the program will not recognize
keyboard input and will therefore lock up. If, like me, you
normally have raw mode on, this can be an annoyance. There are
two obvious solutions: (1) make sure you are not in raw mode
before your run the program; (2) put USES Crt; in the program, so
you do not use the standard input. Procedure FixRaw, set out
below, is a quick-and-dirty third solution. Include FixRaw in
your program, call it at the beginning of your main program and
again at the end. The first time you call it, it will check to
see if raw mode is set on. If it is, FixRaw turns it off. The
second time you call it, it either does nothing (if raw mode was
always off) or else turns raw mode on (if it was on when the
program started). To make sure that raw mode is set back the way
it was originally when your program finishes running, also
include a call to FixRaw in your error routine.

You might on occasion want to do the same thing if you are
using an earlier version of Turbo Pascal. However, THIS CODE
WILL NOT WORK IN VERSIONS OF TURBO PASCAL EARLIER THAN VERSION
4.0. The reason is that this code assumes that the typed
constants are in the data segment. In earlier versions of Turbo,
they were in the code segment. You could probably fix this with
segment overrides.

Yes, I know the programming here is sloppy and inefficient.
But no matter how inefficient the code, this still is not going
to delay your program by much. And even if somebody took the
time to squeeze it down, the code plus two calls to the routine
could not possibly be all that much less than the 96 or so bytes
all this now takes up. This seems to work, and that is enough
for me.

This code, complete with this documentation, is in the public
domain. If you find this procedure useful, please convey your
appreciation to David Baldwin, whose Inline.Com makes routines
like this feasible.

David Seidman
November 14, 1987
*)


Procedure FixRaw;

const
HoldDx : word = 0;
Starter : byte = 0;
begin
Inline( {Assembly by Inline 11/14/87 22:00}
$8A/$0E/>STARTER/ { mov cl,[>starter] ;get the flag that says what we do}
$80/$F9/$02/ { cmp cl,2}
$74/$3C/ { je end ;means no need to restore raw mode}
$80/$F9/$01/ { cmp cl,1}
$74/$2B/ { je restore ;means we changed to raw and must reset}
$B8/$00/$44/ { mov ax, $4400 ;otherwise, first time, and need info}
$BB/$02/$00/ { mov bx, 2 ;for standard input}
$CD/$21/ { int $21}
$F6/$C2/$20/ { test dl, $20 ;see if in raw mode}
$75/$08/ { jnz inraw}
$C6/$06/>STARTER/$02/ { mov by [>starter],2 ;if not, set flag and exit}
$E9/$22/$00/ { jmp end}
{inraw:}
$30/$F6/ { xor dh,dh ;if raw, need to reset}
$89/$16/>HOLDDX/ { mov wo [>holddx],dx ;save settings}
$C6/$06/>STARTER/$01/ { mov by [>starter],1 ;set flag for restore}
$80/$E2/$DF/ { and dl, $df ;set bit 5 to zero}
$B8/$01/$44/ { mov ax, $4401}
$CD/$21/ { int $21 ;set nonraw}
$E9/$0C/$00/ { jmp end}
{restore:}
$8B/$16/>HOLDDX/ { mov dx,[>holddx]}
$B8/$01/$44/ { mov ax, $4401}
$BB/$02/$00/ { mov bx, 2}
$CD/$21 { int $21}
); {end:}
end;



  3 Responses to “Category : Pascal Source Code
Archive   : FIXRAW.ZIP
Filename : FIXRAW.INC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/