Board index » delphi » Dos standard input

Dos standard input

Eric Liu <e...@acs.ucalgary.ca> asked me :

Quote
>> It did bother me for many years too, however if a file is piped to
>> the programme a character is ready when you check keyboard status :

>> asm    mov    ah,$0b      ; check keyboard status
>>        int    $21
>>        cmp    al,0        ; zero means not ready
>>        je     not_ready

>Two questions:
>(1) How do I put the above in inline assembly code?  I have never used
>    that before in my TP programs. And how do I know what it returned?

The above example was taken from a book, where the contents of the
AL register was used for a jump to branch of from the main program.

In pascal the normal way is to declare a normal pascaltype variable
and then to assign a value to it :

var

  is_ready  : boolean;

begin
asm    mov    ah,$0b      ; check keyboard status
       int    $21
       mov    is_ready,al
       end;

A different approach is to put it into a function. Bytesized results
does return the contents of AL ( and wordsized results return AX ) :

function is_ready:boolean; assembler;
asm    mov    ah,$0b      ; check keyboard status
       int    $21
       end;

Quote
>(2) Is this the same as KeyPressed of the CRT unit?

No it isn't, the difference is rather substantial. This function check
for the presence of a character at the default dos input handle (con).

In great contrast all procedures and functions in the CRT-unit normally
bypasses both dos and bios and does access the hardware directly.

Quote
>I tried a "if keypressed" test, but that didn't work.

No it wouldn't, nothing has actually been _typed_ on the keyboard.

Pipes, redirection and moving the console with the dos CTTY command
will affect only dos in- and output, neither CRT or bios is affected.

Erik Hjelme      Phone & fax      FidoNet BBS      E-mail
Denmark          +45 36461003     MCUG 2:235/15    hje...@login.dknet.dk

 

Re:Dos standard input


Quote
In article <-XXxlKluFL8T06...@login.dknet.dk> hje...@login.dknet.dk (Erik Hjelme) writes:
>Eric Liu <e...@acs.ucalgary.ca> asked me :
>>> It did bother me for many years too, however if a file is piped to
>>> the programme a character is ready when you check keyboard status :
>...
>function is_ready:boolean; assembler;
>asm    mov    ah,$0b      ; check keyboard status
>       int    $21
>       end;

I believe this returns $FF if a character is available and $00 if not.  $00 is
OK for FALSE, but $FF is not the correct value for TRUE. I think "if  boovar"
compiles as "if Ord(boovar)<>0" (or>0), though.

Should work, though:
        if is_ready then write('Ready') else write('Ethelred') ;

Should fail for Unready case:
        const S : array [boolean] of string[8] = ('Ethelred', 'Ready') ; ...
        write(S[is_ready]) ;

Putting " ; neg al" after "int $21" may fix it.  E&OE.

--
John Stockton : J...@dclf.npl.co.uk from off-site.   MIME.   WP.
 National Physical Laboratory, Teddington, Middlesex, TW11 0LW, UK
  Direct Phone +44 181-943 6087, Nearby Fax +44 181-943 7138  
** Postings out, Email in/out are fast; News in is often slow. **
Offshore news takes 0..10+ days to arrive; please mail copies of
replies!  Regret system puts unzoned (UK civil) time on messages.

Re:Dos standard input


Re:Dos standard input


In article <jrs.1990.00121...@dclf.npl.co.uk>, Dr John Stockton, N wrote:

Quote
>In article <-XXxlKluFL8T06...@login.dknet.dk> hje...@login.dknet.dk (Erik Hjelme) writes:
>>Eric Liu <e...@acs.ucalgary.ca> asked me :
>>>> [...] if a file is piped to the programme a character is ready
>>>> when you check keyboard status :
>> function is_ready:boolean; assembler;
>> asm    mov    ah,$0b      ; check keyboard status
>>        int    $21
>>        end;
> I believe this returns $FF if a character is available and $00 if not.
> $00 is OK for FALSE, but $FF is not the correct value for TRUE.
> I think "if boovar" compiles as "if Ord(boovar)<>0" (or>0), though.

Different compilers and languages behave differently in this matter,
however this group is Borland/Turbo Pascal only, and to the best of
my knowledge it'll accept any nonzero value as true.

The ordinal value of a boolean set true is one in TP 5.5, 6 & 7, but
other compilers/languages could theoreticly be defined as :

true only if any_boolean=$FF
true only if any_boolean=1
true only if any_boolean AND 1=1

My only possible advice : if you're in doubt make a simple test

Erik Hjelme      Phone & fax      FidoNet BBS      E-mail
Denmark          +45 36461003     MCUG 2:235/15    hje...@login.dknet.dk

Re:Dos standard input


Quote
In article <uLAzlKluFPoK06...@login.dknet.dk>, hje...@login.dknet.dk (Erik Hjelme) writes:

|> |> Different compilers and languages behave differently in this matter,
|> however this group is Borland/Turbo Pascal only, and to the best of
|> my knowledge it'll accept any nonzero value as true.

Don't know whether this has any relevance to the original question, but it might:

Borland Pascal has (at least) THREE different boolean types,
which ARE NOT COMPATIBLE with each other!

There is the "ordinary" type Boolean,
then there is WordBool and LongBool.

I also think (don't have the manuals here) that Boolean has different
semantics in BP for DOS and BP for Windows.
One bad thing to have is a file of boolean values,
and try to "share" the file between a BP/DOS and a BP/Windows application.

Matthias

Other Threads