home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / showbox.com / EXAMPLE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-30  |  2.5 KB  |  112 lines

  1.  
  2.  
  3.  
  4. #include "screen.h"
  5. #include "showbox.hpp"
  6.  
  7. void DetectRealRam( struct MCES_SYSTEM * PsysStruc, char *Msgs )
  8. {
  9.     ushort RamSenseCnt;
  10.     int A20Sense;
  11.     int RamRet;
  12.     Box LBox("Detecting","RAM Size Detection", BRIGHTWHITEFORGROUND + BLUEBACKGROUND);
  13.     ErrorBox * WorkBox1;
  14.     uchar intctr1 = inportb(0x21);
  15.     uchar intctr2 = inportb(0xa1);
  16.  
  17.     LogTestName("Detecting real ram");
  18.  
  19.     if (cpu_type() == 4)
  20.         I486CACHE_OFF();
  21.  
  22.     A20Sense = CheckMemwrap();
  23.  
  24.     if (A20Sense)
  25.         // ensure A20 enabled before testing
  26.         kbd_a20_on_off(1);    // enable the keyboard controller A20 line
  27.  
  28.     // base ram is either 512K or 640K so there is no need
  29.     // to test below 512k
  30.  
  31.     // perform existence test on highest base ram first
  32.     // if it exists then the lower ram exists
  33.  
  34.     LBox.Redraw("Starting at block at 640K" );
  35.  
  36.     if ( !(RamRet = BEGIN_VIRTUAL( 0, 4, 512 )) )
  37.     {
  38.         PsysStruc -> BaseMemory = 1;
  39.         MsgOut( Msgs, "Installed base memory - 640K\n" );
  40.     }
  41.     else
  42.     {
  43.         if (RamRet >= 100)    // if a protected mode trap occurred
  44.         {
  45.             sprintf(line,"A protected mode error has occurred.\n"
  46.                 "The error code is %d", RamRet - 100 );
  47.             WorkBox1 = new ErrorBox(line);
  48.             delete WorkBox1;
  49.         }
  50.         PsysStruc -> BaseMemory = 0;
  51.         MsgOut( Msgs, "Installed base memory - 512K" );
  52.     }
  53.  
  54.     // check beginning of each 64k block up to 64MB
  55.     // the first 64k block is used for temp storage 
  56.     // of the data in the block being tested during mem tests
  57.     for (RamSenseCnt = 1088; RamSenseCnt < 65535; RamSenseCnt += 64)
  58.     {
  59.         sprintf(line, "Starting block at %u",RamSenseCnt);
  60.         LBox.Redraw( line );
  61.  
  62.         RamRet = BEGIN_VIRTUAL( 0, 4, RamSenseCnt );
  63.         if (RamRet >= 100)    // if a protected mode trap occurred
  64.         {
  65.             sprintf(line,"A protected mode error has occurred.\n"
  66.                 "The error code is %d", RamRet - 100 );
  67.             LogError( line );
  68.             WorkBox1 = new ErrorBox(line);
  69.             delete WorkBox1;
  70.         }
  71.  
  72.         if (RamRet)
  73.             break;
  74.     }
  75.  
  76.     sleep(3);
  77.  
  78.     asm cli
  79.  
  80.     while (inportb(0x64) & 1)
  81.     {
  82.         inportb(0x60);
  83.         sleep(1);
  84.     }
  85.  
  86.     set_int_ctrlrs(8,0x70);
  87.  
  88.     outportb( 0x21, intctr1 );
  89.     outportb( 0x20, 0x20 );
  90.     outportb( 0xa1, intctr2 );
  91.     outportb( 0xa0, 0x20 );
  92.  
  93.     asm    sti
  94.  
  95.     RamSenseCnt -= 1024;    // calc how much ext ram
  96.  
  97.     PsysStruc -> ExtMemory = RamSenseCnt / 64;
  98.     
  99.    sprintf(line, "Installed extended memory - %uK\n", RamSenseCnt );
  100.  
  101.     MsgOut( Msgs, line );
  102.  
  103.     if (A20Sense)    // if wrapping was enabled to begin with
  104.         kbd_a20_on_off(0);    // disable the keyboard controller A20 line
  105.  
  106.     printf("\nFinished with detecting real ram");
  107.     while (!kbhit());
  108.     getch();
  109.  
  110. }
  111.  
  112.