/*static char *SCCSID = "@(#)bvsldrvr.h	6.3 91/02/23";*/
/****************************************************************************/
/*                                                                          */
/*                       IBM/Microsoft Confidential                         */
/*                                                                          */
/*                 Copyright (c) IBM Corporation  1987, 1990                */
/*                 Copyright (c) Microsoft Corp.  1987, 1990                */
/*                           All Rights Reserved                            */
/*                                                                          */
/****************************************************************************/

#ifndef NULL
#define NULL                            (void far *) 0L
#endif
#ifndef TRUE
#define TRUE                            1
#endif
#ifndef FALSE
#define FALSE                           0
#endif
#define SIMPLE                          FALSE
#define COMPLETE                        TRUE
#define hAB                             (void far *)0L

#define uVideoEnableCategory            0x03
#define uVideoEnableFunction            0x73
#define uRealModePtr                    0
#define uProtModePtr                    1
#define ulGraphicsEngineVersion         0L

#define cbDefaultLvb                    0x0fa0L
#define cbMemoryBlock                   1280    /*D261*/
#define cbMaxString                     1024    /*D261*/
#define cbMaxList                       512
#define cbMaxDevName                    512
#define cbMaxCompName                   80
#define cbMaxEntryName                  32
#define cbMaxPointerName                32
#define cbDevicePrefix                  strlen (szDevPrefix)    /* @P1 */

#define cMemoryBlocks                   16
#define cMaxComponent                   16
#define cDevTblEntries                  16
#define cCallTbls                       16

#define chComponentSep                  ','
#define chParameterSep                  '+'

#define umaskPowerup                    0x0001
#define umaskAllocSeg                   0x0000

#define fcFillLogicDeviceBlock          1L
#define fcFillInitDeviceBlock           3L              /* DCR 203 - @T15 */
#define fnVioShellInit                  0x44
#define fnRetConfigInfo                 0x0104L

#define fn_BufferUpdate                 0x0100  /*D261*/
#define fn_PrintScreen                  0x0115  /*D261*/
#define fn_WriteTTY                     0x0116  /*D261*/
#define fn_NextAvail                    0x011A  /*D261*/ /*D811*/

#define cCallVectorEntries              fn_NextAvail-fn_BufferUpdate /*D261*/

#define iWinVioVDH                      0
#define iPowerUpVDH                     1

#define gf_devtblinit                   0x0001          /* @P1 */
#define gf_calltblsinit                 0x0002          /* @P1 */
#define gf_initgenvec                   0x0004          /* @P1 */
#define gf_globinitdone                 0x0008          /* @P1 */

#define dg_devszinuse                   0x0001          /* @P1 */
#define dg_ptrrealinuse                 0x0002          /* @P1 */
#define dg_ptrprotinuse                 0x0004          /* @P1 */
#define dg_calltblinuse                 0x0008          /* @P1 */
#define dg_deventinuse                  0x0010          /* @P1 */

#define NO_ERROR                        0
#define ERROR_CANT_GET_DEVICE_LIST      0xffff
#define ERROR_NO_DEVICE_INSTALLED       0xfffe
#define ERROR_CANT_INITIALIZE_DEV_DATA  0xfffd
#define ERROR_UNABLE_TO_ACCESS_DEVICE   0xfffc
#define ERROR_FUNCTION_NOT_SUPPORTED    0xfffb
#define ERROR_FAILED_GENERIC_VDH_LOAD   0xfffa
#define ERROR_DEVICE_NOT_LOADED         0xfff9
#define ERROR_INVALID_PARAMETER         0xfff8
#define ERROR_INSUFFICIENT_MEMORY       0xfff7
#define ERROR_CANT_GET_CALL_TABLE       0xfff6
#define ERROR_SHELL_NOT_INITED          0xfff5
#define ERROR_ACCESS_DENIED             5               /*@T45*/

/* NOTE this structure is used in the VDH also.  It should be defined */
/* in a common place from which BVS and the VDHs get it */

typedef struct {
        USHORT  cb;
        USHORT  adapter;
        USHORT  display;
        ULONG   cbMemory;
        USHORT  Configuration; /* 1.2 */
        USHORT  DeviceDriver;
        USHORT  Flags;
        ULONG   HWBufferSize;
        ULONG   FullSaveSize;
        ULONG   PartSaveSize;
        USHORT  EMAdaptersOFF;
        USHORT  EMDisplaysOFF;
        USHORT  LEMAdapterdata;         /* @BB7 */
        USHORT  EMAdapters;
        USHORT  LEMDisplaydata;         /* @BB7 */
        USHORT  EMDisplays;
        } VDHCONFIGINFO;


/* NOTE this structure is used in the VDH also.  It should be defined */
/* in a common place from which BVS and the VDHs get it */

typedef struct {
          USHORT         Length;
          USHORT         Flags;
          VDHCONFIGINFO far *ConfigDataPTR;
          } VDH_CONFIG;


typedef unsigned (far pascal *VDHDDI) (void far *, void far *, unsigned long);
typedef unsigned (far pascal *PEF)(unsigned long, unsigned long, unsigned long);

typedef VDHDDI CALLTBL[cCallVectorEntries];

typedef struct {                /* structure passed to BvsGetVideoCallTables */
    unsigned    cb;
    CALLTBL far *pcalltbl[1];
    }   tcv;

typedef struct _t_cmp {         /* component of a device */
    unsigned    uCategory;
    unsigned    uFunction;
    PEF         funcEnable;
    unsigned    hModule;
    }   t_cmp;

typedef struct _t_dev {
    char        szDeviceName[cbMaxDevName];
    char        szEntry[cbMaxEntryName];
    unsigned    uCategory;
    unsigned    uFunction;
    unsigned    fValid;
    unsigned    cComponents;
    unsigned    iDevice;
    t_cmp       cmpComponent[cMaxComponent];
    }   t_dev;

typedef struct _t_cnfg {
    unsigned        ulength;
    unsigned        uAdapterType;
    unsigned        uDisplayType;
    unsigned long   ulMemory;
    unsigned        uConfig;
    unsigned        uDDVersion;
    unsigned        uFlagBits;
    unsigned long   ulHwState;
    unsigned long   ulFullSave;
    unsigned long   ulPartSave;
    }   t_cnfg;

typedef struct _t_chmem {
    unsigned    fInUse;
    char        chMem[cbMemoryBlock];
    }   t_chmem ;

typedef struct _t_tmpmem {
    t_chmem chmemBlock[cMemoryBlocks];
    }   t_tmpmem;

typedef struct _devgroup  {             /* @P1 */
    unsigned    flags;                  /* @P1 */
    t_dev       devEnt;                 /* @P1 */
    CALLTBL     calltbl;                /* @P1,D261 */
    }   DEVGROUP;                       /* @P1 */


/******  If _bvscommon is changed, the corresponding structure *******/
/******  BVSGDATA in BVSCB.INC and BVSGSEG in BVSMAIN.ASM must *******/
/******  must also be changed.                                 *******/
/******  Besure to remake all BVH DLLs also.                   *******/

typedef    struct _bvscommon {
    CALLTBL far *   cmn_calltables[16]; /* Allow WDH and 15 real devices*/

    USHORT          cmn_flags;          /* Flags                        */
/*@D549    USHORT          cmn_seltable; */    /* Offset of selector table,@S10*/
/*@D549    USHORT          cmn_selentsz; */    /* Size of selector entry,  @S10*/
    USHORT          cmn_instance;       /* Selector of Instance Data    */
    USHORT          cmn_bvscbsize;      /* Size of the BVSCB            */

    USHORT          cmn_SISsel;         /* System InfoSeg GDT selector  */
    USHORT          cmn_LISsel;         /* Local InfoSeg LDT selector   */
    USHORT          cmn_maxbase;        /* Maximum Base session number  */
/*@D549    USHORT          cmn_maxvio;   */    /* Maximum VIO session number   */

    USHORT          cmn_initpid;        /* Process ID at init time      */
    USHORT          cmn_scrhandle;      /* Screen DD File Handle        */

    USHORT          cmn_sg0flag;        /* SG0 on behalf of other SG    */
    USHORT          cmn_sg0bvssel;      /* SG0 BVSCB selector           */
    USHORT          cmn_sg0envsel;      /* SG0 ENVB selector            */
    USHORT          cmn_sg0lvbsel;      /* SG0 LVB selector             */

    USHORT          cmn_open_a;         /* Open action return field     */
    USHORT          cmn_prtsclen;       /* Print screen length          */
    char            cmn_prtsc_buffer[134]; /* Print screen buffer @B719871 */
    char            cmn_cprtemp[9];     /* Template for CurPos Report   */
    char            cmn_bvscbname[20];  /* Name of the BVSCB            */
    char            cmn_mouddname[7];   /* Mouse DD name                @T25 */
    char            cmn_prtname[4];     /* Printer name asciiz string   @T25 */
    char            cmn_scrddname[8];   /* Screen DD name               @T25 */
    char            cmn_blanks[8];      /* Blanks for tab removal       */
    USHORT          cmn_3XBcpos;        /* 3xBox cursor posn save area  */
    char            cmn_parmpkt;        /* parameter packet area        @D663*/
    USHORT          cmn_pjtitlelen;     /* length of print job title    @D663*/
    USHORT          cmn_pjtitleoff;     /* offset of print job title    @D663*/
    USHORT          cmn_pjtitlesel;     /* segment of print job title   @D663*/
    char            cmn_cprtsc_title[11];  /* asciiz of cprtsc job title @D663*/
    char            cmn_cprtsc_titlelen;   /* length of title          @D663*/
    char            cmn_prtsc_title[13];   /* asciiz of cprtsc job title @D663*/
    char            cmn_prtsc_titlelen;    /* length of title          @D663*/
    char            cmn_vdd1[9];        /* primary display for MVDM      @C39*/
    char            cmn_vdd2[9];        /* secondary display for MVDM    @C39*/
    char            cmn_filler;         /* word alignment               @T73*/
    LONG            cmn_vddhandle;      /* MVDM VDD handle               @C39*/
    USHORT          cmn_seltablesz;     /* Size of selector entry,  @S10,@D549*/
    USHORT far *    cmn_seltable[256];  /* Address of selector tables,@S10,@D549*/
/*  USHORT          cmn_wndwconfig;     /* Config number in use by Shell @T25,@T46*/
}       BVSCOMMON;

typedef struct _bvsinstdata {           /*                      @T19    */

     USHORT         inst_bvssel;        /* BVSCB Selector       @T19    */
     USHORT         inst_envsel;        /* ENVB Selector        @T19    */
     USHORT         inst_lvbsel;        /* LVB Selector         @T19    */
     USHORT         inst_sgnum;         /* Screen group number  @T19    */
}       BVSINSTDATA;                    /*                      @T19    */

/*--------------------------------------------------------------------*/
/* Function Prototypes                                                */
/*--------------------------------------------------------------------*/

unsigned far pascal BvsGetVideoCallTables ( CALLTBL far **,
                        char far **,            /* @P1 */
                        char far ** );          /* @P1 */

unsigned far pascal BvsGetPtrDrawName(unsigned, unsigned, char far **);

unsigned near pascal DosDriverEnable( char far *,       /* @P1 */
                        unsigned long,
                        unsigned long,
                        unsigned long,
                        char far *,
                        unsigned,
                        unsigned );

unsigned near pascal DosLoadVideoHandler ( CALLTBL far **, /* @P1 */
                        char far * );

unsigned near uInitGenericVDH();

unsigned near uLoadWinthornVDH (CALLTBL far **);

unsigned near fGetFreeCallTable (CALLTBL far **);

unsigned near fAddDevice (t_dev far **,
                        char far *,
                        char far *,
                        unsigned,
                        unsigned );

unsigned near fFindDevice (t_dev far **,
                        char far *,
                        char far *,
                        unsigned,
                        unsigned);

unsigned near fGetEnableEntry(PEF *,
                        unsigned far *,
                        char far *,
                        char far *);

unsigned near fGetFreeDevTableEntry (t_dev far **);

unsigned near fGetNextComponent (char far **,
                        char far *,
                        char far *,
                        unsigned *,
                        unsigned *);

unsigned near fHasAddressability (t_dev far *);

unsigned near fInitializeDeviceTable();

unsigned near fInitializeCallVector (CALLTBL far *);

unsigned near fIsDeviceDriver (char far *);

unsigned near fIsPowerup (CALLTBL far *);

unsigned near fMakeDevAddressable (t_dev far **);

unsigned near fRegisterDevice (t_dev far **,
                        char far *,
                        char far *,
                        unsigned,
                        unsigned);

unsigned far pascal uErrorFunction (void far *,
                        void far *,
                        unsigned long);

void    near vFreeDevTableEntry (t_dev far *);

void    near vInitializeEntry(t_dev far *);

unsigned near PrintErrorList();

unsigned near AddErrorToList(char far *, char far *);

void    near vGetSaveSizes();

unsigned far pascal BvsDInit(unsigned);

unsigned near BvsGlobalInit();

unsigned near fGetTempBuf (char far **, unsigned);

void    near vFreeTempBuf(char far *);

unsigned near fInitTempBufs();

void    near vReleaseTempBufs();

unsigned near DosUnloadVideoHandler (char far *);

char far * near pchGrowGlobal(unsigned); /*D261*/

/*----------------------------------------------------------------------*/
/* The following routines are located in the .ASM source code           */
/*----------------------------------------------------------------------*/

unsigned far pascal VdhPrtSc();         /*D198*/

unsigned far pascal VdhWrtTTY();        /*D198*/

void     SaveRegs();

void     RestoreRegs();

void     DebugStop();                   /*@S36*/

/*@T15 = 03/03/89 TPL, DCR 203 changes, P3730 */
/*@T19 = 03/16/89 TPL, Avoid loading AVIO at boot time, P6741 */
/*@P1  = 03/25/89  PL, DCR 132 changes */
/*JOPT = 03/30/89 STJ, Convert all local routines to NEAR subroutines   */
/*D198 = 03/31/89 STJ, Install BvsPrtSc and BvsWrtTTY as default VDH routines */
/*@T25 = 04/04/89 TPL, Sizzle work B701685 */
/*D261 = 04/21/89 STJ, Use CONFIG.SYS instead of OS2.INI and optimize */
/*@BB7 = 05/09/89 WKB, Restructure config data structure, B702184 */
/*@S10 = 05/11/89 STJ, Retain separate ENVB/LVB for each config, B701174 */
/*@T45 = 08/31/89 TPL, Don't load other BVHs when starting VIO Wndw, B707495 */
/*@T46 = 09/05/89 TPL, Use the compress registration mask from VIO, PTR B70???? */
/*@S36 = 10/10/89 STJ, Add DebugStop for C routines, AR05111 */
/*@D549 = 11/02/89 CJJ, Seltable changes due to rangeless sessions, DCR 549 */
/*D811 = 11/30/89 MS,  DCR 811 */
/*@D663 = 01/02/90 TLB, Put name of print screen print job in spool queue, DCR 663*/
/*@T73 = 07/30/90 TPL, Code/data reduction/optimization and swap tune */
/*@C39 = 01/15/91 CJJ, MVDM transparent popup changes, PTR SM84577 */
/*@B719871 = 01/28/91 WKB, Increase prt-sc buffer for 132 col modes, @B719871 */
