C -> Pascal, Checking the InDOS flag

Once again, I need help translating from C to pacal, I think this will
finish off all of the customers questions.  This time it is in regards
to checking to see if it is save to make an INT 21h call, or see if DOS
is already doing something, and can not be interrupted.  Thank you very
much to all of you who have previously done some translations for me.
It is greatly appreciated, and very helpful.

Regards,
Lance O'Connor
Technical Support
Concurrent Controls, Inc.
locon...@conctrls.com

[ indos.cpp 2K ]
#include <stdlib.h>
#include <dos.h>
#include <stdio.h>
#include <conio.h>

#define GET_INDOS       0X34
#define GET_CRIT_ERR    0X5D06
#define INTR 0X1C    /* The clock tick interrupt */

#ifdef __cplusplus
    #define __CPPARGS ...
#else
    #define __CPPARGS
#endif

char far *indos_ptr=0;
char far *crit_err_ptr=0;

int DosBusy(void);
void InitInDos(void);
int Int28DosBusy(void);
int chkkey(void);

int DosFlag;

void interrupt ( *oldhandler)(__CPPARGS);

void interrupt handler(__CPPARGS)
{
        if (DosBusy() == 0)
        {
                DosFlag=0;
        }
        else
        {
                DosFlag=1;
        }

        //call the old routine */
        oldhandler();

Quote
}

int main(void)
{
        int key=0;

        //call InitInDos to initialize the InDOS flags
        InitInDos();

        //save the old interrupt vector
        oldhandler = getvect(INTR);

        //install the new interrupt handler */
        setvect(INTR, handler);
        clrscr();
        puts("INDOS.EXE - Show state of InDOS flag.  Press ESC to exit.");

        //loop until an ESC is pressed
        while(key != 27)
        {
                if (DosFlag == 0)
                {
                        cprintf("DOS is: Free\r");
                }
                else
                {
                        cprintf("DOS is: Busy\r");
                }
                key = chkkey();
        }
        //reset the old interrupt handler */
        setvect(INTR, oldhandler);

        return 0;

Quote
}

/*
* Function: Init InDos Pointers
*/

void InitInDos(void)
{
        union REGS regs;
        struct SREGS sregs;

        regs.h.ah = GET_INDOS;
        intdosx(&regs, &regs, &sregs);
        //InDOS pointer is returned in ES:BX
        FP_SEG(indos_ptr) = sregs.es;
        FP_OFF(indos_ptr) = regs.x.bx;

        //Also, get the critical error flag
        regs.x.ax = GET_CRIT_ERR;
        intdosx(&regs, &regs, &sregs);
        //Critical error flag is returned in DS:SI
        FP_SEG(crit_err_ptr) = sregs.ds;
        FP_OFF(crit_err_ptr) = regs.x.si;

Quote
}

/*
* Function: DosBusy
* Will return non-zero if DOS is busy
*/

int DosBusy(void)
{
        if (indos_ptr && crit_err_ptr)
                return (*crit_err_ptr || *indos_ptr);
        else
                return 0xFFFF;

Quote
}

/*
* Function Int28DosBusy
* This function will return non-zero if the InDos flag is > 1 or
* the critical error flag is non zero.  To be used inside of an
* INT 28 loop.  Not that inside INT 28, InDOS == 1 is normal and
* indicates that DOS is *not* busy; InDOS > 1 inside INT 28 means
* it is.
*/

int Int28DosBusy(void)
{
        if (indos_ptr && crit_err_ptr)
                return (*crit_err_ptr || (*indos_ptr > 1));
        else
                return 0xFFFF;

Quote
}

int chkkey(void)
{
        int i=0;

        //Is there a keystroke ready?
        i = kbhit();
        if (i==0)
        {
        //There is no keystroke, return nothing.
                return 0;
        }
        else
        {
        //There is a keystroke, return what it is.
                return getch();
        }

Quote
}