/*static char *SCCSID = "@(#)moninit.c  6.2 91/07/24";*/

#define INCL_ERRORS
#define INCL_16
#define INCL_NOXLATE_DOS16
#define INCL_DOSINFOSEG
#define INCL_DOSDEVICES
#define INCL_DOSSEMAPHORES
#define INCL_OS2STD

#include <os2def16.h>
#include <bsedos16.h>
#include <drt.h>
#include <bseerr.h>
#include <moncalls.h>


///////////////////////////////////////////////////////////////////////////
//  Instance data
///////////////////////////////////////////////////////////////////////////
// All data is initialized so that it will be in one segment, values are
// unimportant.  (Each segment costs 4K)

extern LISTHEADER  OpenList;

extern OPENEDDEVICES Device_List[MAX_OPENED_DEVICES];

#ifdef MMIOPH                                                        //MDLL
SEL globalIS = NULL;                                                 //MDLL
SEL localIS  = NULL;                                                 //MDLL
struct  InfoSegGDT far  *globptr = NULL;
#endif                                                               //MDLL

///////////////////////////////////////////////////////////////////////////
// Declare routines and PRAGMA them
///////////////////////////////////////////////////////////////////////////
   SHORT FAR MonInstanceInit(VOID);

// #pragma alloc_text(INITCODE, MonInstanceInit)                     //MDLL


//************************************************************************
//************************************************************************
//   Start of Init routine
//************************************************************************
//************************************************************************

//****************** START OF SPECIFICATIONS *******************
//
// SUBROUTINE NAME: MonInstanceInit
//
// DESCRIPTIVE NAME: Initialize intance data for monitor dispatcher
//
// FUNCTION:
//            This C routine will initialize the instance data for each
//            instance of the monitor dispatcher.
//
// ENTRY POINT: MonInstanceInit
//     LINKAGE:  far CALL
//
// INPUT:       none
//
// EXIT-NORMAL: nothing
//
// EXIT-ERROR:  nothing
//
// EFFECTS:
//
//
// INTERNAL REFERENCES:
//
// EXTERNAL REFERENCES:
//       DosSemClear
//
//****************** END OF SPECIFICATIONS *********************
SHORT FAR MonInstanceInit ()
   {
   register USHORT i;
   register USHORT j;
   struct OPENEDDEVICES *tempitem;

   OpenList.ListRAMSem = 0;
   DosSemClear(&OpenList.ListRAMSem);

  /* Get the global and local infosegs if MMIO build */
 #ifdef MMIOPH
   if (DosGetInfoSeg((unsigned far *)&globalIS, (unsigned far *)&localIS))
      return (-1);                                                      //MDLL
   PUT_SEG(globptr, globalIS);
   PUT_OFF(globptr,0);
 #endif

   for (i=1;i<=MAX_OPENED_DEVICES-2;i++)
      {
      tempitem = &Device_List[i];
      tempitem->Next= &Device_List[i+1];
      tempitem->Prev= &Device_List[i-1];
      tempitem->Dev_Handle = 0;
      for (j=0; j<DEVSTRINGLEN ;j++)
         {
         tempitem->Dev_String[j]= 00;
         }
      }

 //Initialize first item (couldn't use loop because of i-1)
   tempitem = &Device_List[0];
   tempitem->Prev = BAD_ITEM;
   tempitem->Next = &Device_List[1];
   tempitem->Dev_Handle = 0;
   for (j=0; j<DEVSTRINGLEN ;j++)
      {
      tempitem->Dev_String[j]= 00;
      }
 //Initialize last item (couldn't use loop because of i+1)
   tempitem = &Device_List[MAX_OPENED_DEVICES-1];
   tempitem->Next = BAD_ITEM;
   tempitem->Prev = &Device_List[MAX_OPENED_DEVICES-2];
   tempitem->Dev_Handle = 0;
   for (j=0; j<DEVSTRINGLEN ;j++)
      {
      tempitem->Dev_String[j]= 00;
      }



   OpenList.First_Item = BAD_ITEM;
   OpenList.Free_Item = &Device_List[0]; // First item is head of free list
   return(-1);
   }


