home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / tvision / dpmi / clib / init.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-22  |  2.6 KB  |  101 lines

  1. //=====================================================================
  2. //
  3. //  init.cpp
  4. //
  5. //  initialization / cleanup handling for Borland C runtime
  6. //
  7. //  dos protected mode version
  8. //
  9. //  Copyright (c) 1994, Kevin Morgan, All rights reserved.
  10. //
  11. //=====================================================================
  12. #include <stdio.h>
  13. #include <dos.h>
  14.  
  15. extern "C" void Initialize(unsigned,unsigned,unsigned);
  16. extern "C" void Cleanup(unsigned,unsigned,unsigned);
  17.  
  18. const unsigned char PNEAR = 0;
  19. const unsigned char PFAR  = 1;
  20. const unsigned char NOTUSED = 0xff;
  21.  
  22. struct startup_table {
  23.     unsigned char calltype, priority;
  24.     void (far *funcptr)();
  25. };
  26.  
  27. void Initialize(unsigned ds, unsigned lo, unsigned hi)
  28. {
  29. //  printf("Initialize called...%04x %04x %04x\n", ds, lo, hi);
  30.     startup_table *st;
  31.     FP_SEG(st) = ds;
  32.  
  33.     for (;;) {
  34.         startup_table *lowent = 0;
  35.         unsigned i;
  36.         for (i = lo; i < hi; i+=sizeof(startup_table) ) {
  37.             FP_OFF(st) = i;
  38.             if (st->calltype==PFAR||st->calltype==PNEAR) {
  39.                 if (lowent==0)
  40.                     lowent = st;
  41.                 else if (st->priority<lowent->priority) 
  42.                     lowent = st;
  43.             }
  44.         }
  45.         if (lowent==0) break;
  46. //      printf("Calling Startup entry: %02x %02x %08lx\n", lowent->calltype, lowent->priority, lowent->funcptr);
  47.         switch (lowent->calltype) {
  48.             case PFAR:
  49.                 lowent->calltype = NOTUSED;
  50.                 (*lowent->funcptr)();
  51.                 break;
  52.             case PNEAR:
  53.                 lowent->calltype = NOTUSED;
  54.                 (*lowent->funcptr)();
  55.                 asm pop ax  // pop off extra word of CS info
  56.                 break;
  57.             default:
  58.                 ;
  59.         }
  60.     }
  61. //  printf("...Initialize done\n");
  62. }
  63.  
  64. void Cleanup(unsigned ds, unsigned lo, unsigned hi)
  65. {
  66. //  printf("Cleanup called...%04x %04x %04x\n", ds, lo, hi);
  67.     startup_table *st;
  68.     FP_SEG(st) = ds;
  69.  
  70.     for (;;) {
  71.         startup_table *lowent = 0;
  72.         unsigned i;
  73.         for (i = lo; i < hi; i+=sizeof(startup_table) ) {
  74.             FP_OFF(st) = i;
  75.             if (st->calltype==PFAR||st->calltype==PNEAR) {
  76.                 if (lowent==0)
  77.                     lowent = st;
  78.                 else if (st->priority>=lowent->priority) 
  79.                     lowent = st;
  80.             }
  81.         }
  82.         if (lowent==0) break;
  83. //      printf("Calling Cleanup entry: %02x %02x %08lx\n", lowent->calltype, lowent->priority, lowent->funcptr);
  84.         switch (lowent->calltype) {
  85.             case PFAR:
  86.                 lowent->calltype = NOTUSED;
  87.                 (*lowent->funcptr)();
  88.                 break;
  89.             case PNEAR:
  90.                 lowent->calltype = NOTUSED;
  91.                 (*lowent->funcptr)();
  92.                 asm pop ax  // pop off extra word of CS info
  93.                 break;
  94.             default:
  95.                 ;
  96.         }
  97.     }
  98. //  printf("...Initialize done\n");
  99. }
  100.  
  101.