Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Readkey alternative?

60 views
Skip to first unread message

fer...@tesla.njit.edu

unread,
Apr 22, 1991, 11:49:08 AM4/22/91
to
I am writing a door for a friends BBS.. everything is fine except for one
thing, the output doesn't work if i include the CRT unit.. this is
not on my end, but on the BBS's and the way it handles output.. now this
is all fine and dandy except for i need a function like readkey without
using the crt unit.. just something that gets a key without waiting for
a carriage return..

Any help?

Frank

Timo Salmi

unread,
Apr 22, 1991, 8:52:02 PM4/22/91
to
In article <1991Apr22...@tesla.njit.edu> fer...@tesla.njit.edu writes:
:

>is all fine and dandy except for i need a function like readkey without
>using the crt unit.. just something that gets a key without waiting for
>a carriage return..
:

If you have access to our archives, the /pc/ts/tspa23## (##=40 50 55
60) units include such goods. There is no source code included or
available (sorry).

...................................................................
Prof. Timo Salmi
Moderating at garbo.uwasa.fi anonymous ftp archives 128.214.12.37
School of Business Studies, University of Vaasa, SF-65101, Finland
Internet: t...@chyde.uwasa.fi Funet: gado::salmi Bitnet: salmi@finfun

Kai Henningsen

unread,
Apr 27, 1991, 8:05:00 AM4/27/91
to

fer9483 @ tesla.njit.edu schrieb am 22.04.1991, 13:49

fe>I am writing a door for a friends BBS.. everything is fine except for one
fe>thing, the output doesn't work if i include the CRT unit.. this is
fe>not on my end, but on the BBS's and the way it handles output.. now this
fe>is all fine and dandy except for i need a function like readkey without
fe>using the crt unit.. just something that gets a key without waiting for
fe>a carriage return..

Well, I won't start explaining the old Crt-rewrite('')-problem, as that
wouldn't solve your problem; I'll only say that readkey works ONLY with the
keyboard.

There are several ways to work with the serial port instead; however, if you
want to use normal DOS redirection (which, from your description, I assume),
then the obvious solution seems to be using the DOS character I/O functions.

There are several; you might try each to determine which works best for you:

AH=01 -> AL=char Character input with echo ^C works
AH=06 DL=FF -> AL=char Direct console I/O ^C is normal char
AH=07 -> AL=char Unfiltered character input without echo
^C is normal char
AH=08 -> AL=char Character input without echo ^C works

You might also consider, for a replacement to keypress,
AH=0b -> AL=00/FF Check input status ^C works

For an example of how to use these:

uses DOS;
function ReadKeyDOS: char;
var r: registers;
begin
r.ah:=$07;
msdos(r);
ReadKeyDOS:=chr(r.al);
end;

I'm not sure, but I believe ^C recognition can be disabled completely by
putting the input device into "raw" mode via an ioctl. If you need that, ask
again, and I'll look it up.

MfG Kai

Timothy Lyle Smith

unread,
Apr 23, 1991, 12:02:46 AM4/23/91
to

There seems to be quite a few people needing readkey alternatives. The
following code can be used to replace the CRT unit functions. It has worked
on every machine I've tested it on. It works with both 84 and 101/102 key
keyboards.

unit chio;

interface

function KeyPressed : boolean;

function ReadKey : char;

implementation

type
BiosArrayW = array[0..32000] of word;
BiosArrayB = array[0..64000] of byte;

BufTyp = array[0..4800] of word;
BufPtr = ^BufTyp;

var
Extended : boolean; { is an extended key press available }
KeyBufSta, { start of keyboard buffer }
KeyBufEnd : word; { end of keyboard buffer }
BiosPtr : ^BiosArrayW; { array of words at $40:00 }
KeyBuf : ^BiosArrayB; { array of bytes at $40:00 }
CurCha, { current available character in buffer }
NexOpe : ^word; { next open spot in buffer }

function Keypressed : boolean;
begin
KeyPressed := CurCha^ <> NexOpe^
end;

function ReadKey : char;
var
Ans : char;
Sta : byte;
begin
if Extended then
begin
Ans := chr(KeyBuf^[CurCha^+1]);
Extended := false;
CurCha^ := NexOpe^
end
else
begin
while CurCha^=NexOpe^ do;
Ans := chr(KeyBuf^[CurCha^]);
if (Ans=#0) or (Ans=#224) then
Extended := true
else
begin
Extended := false;
CurCha^ := NexOpe^
end;
end;
ReadKey := Ans
end;

begin
BiosPtr := ptr($40,0);
KeyBuf := ptr($40,0);
KeyBufSta := BiosPtr^[$40];
KeyBufEnd := BiosPtr^[$41];
CurCha := ptr($40,$1a);
NexOpe := ptr($40,$1c);
CurCha^ := NexOpe^;
Extended := false;
END.
--
Tim Smith
Minard 300 UUCP: ...!uunet!plains!tsmith
North Dakota State University, BITNET: tsm...@plains.bitnet
Fargo, ND 58105 INTERNET: tsm...@plains.NoDak.edu

0 new messages