home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TOTDOC.ZIP / CHAPT4.TXT < prev    next >
Encoding:
Text File  |  1991-02-11  |  18.5 KB  |  475 lines

  1.                                                                      Determining
  2.                                                                                &
  3.                                                                      Controlling
  4.                                                                         Hardware
  5.  
  6.  
  7.  
  8.  
  9.  
  10.          "Never let a domestic quarrel ruin a day's writing. If you can't start
  11.          the next day fresh, get rid of your wife."
  12.  
  13.                                                                       Mario Puzo
  14.  
  15.  
  16.  
  17.  
  18.          This chapter describes the objects included in the totSYS unit. There
  19.          are four objects in all, designed to provide information about the
  20.          hardware and operating system on which an application is running. Dis-
  21.          playOBJ is an object relating to the monitor/display card; EquipOBJ
  22.          returns information about the peripheral devices installed on the
  23.          computer; MemOBJ provides information about base, extended and expanded
  24.          memory; OSOBJ provides information about the operating system and the
  25.          DOS configurable international settings.
  26.  
  27.          A full example illustrating the use of each object can be found at the
  28.          end of the chapter.
  29.  
  30.  
  31.  
  32. Using DisplayOBJ
  33.  
  34.          The public methods (i.e. the methods you should be calling) in Display-
  35.          OBJ are designed to provide you with information about the computer
  36.          display. Since other units in the Toolkit also need to know this
  37.          information, a global instance, called Monitor, is automatically ini-
  38.          tialized when the totSYS unit is used. Monitor is, in fact, a pointer
  39.          to an object on the heap, and has to be referenced with the pointer
  40.          symbol, e.g. Monitor^. There should be no reason to initialize another
  41.          DisplayOBJ, just access the Monitor^ methods. The following methods are
  42.          available:
  43.  
  44.  
  45.          SnowProne: boolean
  46.  
  47.          This function method returns true if the display is a "snowy" CGA.
  48.          Since the screen writing routines in totFAST take care of snow, you
  49.          should not normally need to call this method.
  50.  
  51.  
  52.          GetMode:byte
  53.  
  54.          Returns the current display mode, e.g. mode 3 is 80 column color mode.
  55.          Refer to the Turbo Pascal Programmer's Guide or a DOS Technical Refer-
  56.          ence for more information about display modes.
  57.  
  58.  
  59.          ColorOn:boolean
  60.  
  61. 4-2                                                                 User's Guide
  62.  
  63. --------------------------------------------------------------------------------
  64.  
  65.          This function returns true if the system is capable of color display.
  66.          This function is normally called to determine whether to use monochrome
  67.          or color display attributes when overriding the Toolkit's defaults.
  68.          This function will always return false if ForceBW is set to true (dis-
  69.          cussed next). It also returns false if the user is using a color sys-
  70.          tem, but has set the device to BW80 mode.
  71.  
  72.  
  73.          SetBW(On:boolean)
  74.  
  75.          Call this procedure and pass a true value if you want to force the
  76.          system to use monochrome values. This is useful for laptop systems
  77.          where the system responds as a color device, but the user only sees
  78.          gray (or orange!) scales. Because LookTOT was initialized before your
  79.          program code was executed, you should also call LookTOT^.SetDefaults,
  80.          and LookTOT will then be assigned the default monochrome settings.
  81.  
  82.  
  83.          DisplayType: tVideo
  84.  
  85.          The totSYS unit defines an enumerated type tVideo which has the follow-
  86.          ing members: UnKnown, Mono, CGA, MCGAmono, MCGAcol, EGAmono, EGAcol,
  87.          VGAmono and VGAcol. The function display type checks the installed
  88.          hardware and returns the appropriate member.
  89.  
  90.  
  91.          BaseOfScreen: pointer;
  92.  
  93.          This function returns a pointer to the base address of video memory.
  94.          This is $B800:0000 for color systems and $B000:0000 for monochrome.
  95.          Unless you are using non-Toolkit routines to directly access video
  96.          memory, you should not need to call this method.
  97.  
  98.  
  99.          Width: byte
  100.  
  101.          This function returns the width of the display in characters, which is
  102.          commonly a value of 80.
  103.  
  104.  
  105.          Depth: byte
  106.  
  107.          This function returns the depth of the display in lines. In normal
  108.          display mode the function will return 25, but in condensed mode an EGA
  109.          system will return 43, and a VGA system will return 50.
  110.  
  111.  
  112.  
  113.          The following two methods are used to switch an EGA or VGA display
  114.          system between condensed and normal modes.
  115.  
  116.  
  117.          SetCondensed: byte;
  118.  
  119.  
  120.  
  121.  
  122. Hardware                                                                     4-3
  123.  
  124. --------------------------------------------------------------------------------
  125.  
  126.          This function tries to set the display to condensed mode, and returns
  127.          the number of text lines the system can display in condensed mode. Note
  128.          that only EGA and VGA systems can be set into condensed mode.
  129.  
  130.  
  131.  
  132. 4-4                                                                 User's Guide
  133.  
  134. --------------------------------------------------------------------------------
  135.  
  136.  
  137.          Set25;
  138.  
  139.          This procedure forces the display into 25 line mode.
  140.  
  141.  
  142.  
  143.  
  144.  
  145. Using EquipOBJ
  146.  
  147.          The EquipOBJ object is designed to provide information about the
  148.          installed hardware devices. Most of the EquipOBJ methods reflect the
  149.          data which the user defined with the SETUP operating system command.
  150.          This may not correspond with the actual physical configuration, but is
  151.          the only configuration which DOS will allow software to access. Equi-
  152.          pOBJ includes the following methods:
  153.  
  154.  
  155.          ComputerID:byte;
  156.  
  157.          This function returns a byte indicating the basic system type. The
  158.          computer ID was implemented by IBM to provide an easy way for differen-
  159.          tiating between the various IBM personal computers. The following list
  160.          shows the hexadecimal values of the IBM range:
  161.  
  162.          $FF     - IBM PC
  163.          $FE,$FB - IBM XT or portable
  164.          $FD     - the infamous PC Junior
  165.          $FC     - IBM AT, XT-286, PS/2 50 and 60
  166.          $FA     - PS/2 25 and 30
  167.          $F9     - IBM PC Convertible
  168.          $F8     - PS/2 80
  169.  
  170.          Some non-IBM systems do not follow this convention, and an unlisted
  171.          number may be returned by this method.
  172.  
  173.  
  174.          ParallelPorts: byte;
  175.  
  176.          This function returns the number of installed parallel ports (LPTx).
  177.  
  178.  
  179.          SerialPorts: byte;
  180.  
  181.          This function returns the number of installed serial ports (COMx).
  182.  
  183.  
  184.          FloppyDrives: byte;
  185.  
  186.          This function returns the number of physical diskette drives.
  187.  
  188.  
  189.          ROMDate: string;
  190.  
  191.  
  192.  
  193. Hardware                                                                     4-5
  194.  
  195. --------------------------------------------------------------------------------
  196.  
  197.          Returns an eight character string representing the ROM date in the
  198.          format MM/DD/YY.
  199.  
  200.  
  201.          GameAdapter: boolean;
  202.  
  203.          Returns true if a game adapter is installed.
  204.  
  205.  
  206.          Serialprinter: boolean;
  207.  
  208.          Returns true if a serial printer is configured.
  209.  
  210.  
  211.          MathChip: boolean;
  212.  
  213.          Returns true if a math co-processor is detected. If you compile Toolkit
  214.          programs with the compiler directive FLOAT enabled, but FLOATEM dis-
  215.          abled, the program will only run on systems equipped with a math co-
  216.          processor. Use this function during program initialization to ensure
  217.          the host PC is adequately equipped.
  218.  
  219.  
  220.  
  221. Using MemOBJ
  222.  
  223.          The MemOBJ methods provide data related to base, extended and expanded
  224.          memory on the host PC. The following function methods are provided:
  225.  
  226.  
  227.          BaseMemory: integer;
  228.  
  229.          Returns the total amount of base memory installed, i.e. memory up to
  230.          640k. The value is returned in kilobytes ("k"). Remember that the Turbo
  231.          Pascal functions MemAvail and MaxAvail provide data on free memory,
  232.          i.e. memory not being used by device drivers and programs.
  233.  
  234.  
  235.          EMMInstalled: boolean;
  236.  
  237.          Returns true if an expanded memory manager is installed.
  238.  
  239.  
  240.          EMMversionMajor: byte;
  241.  
  242.          Returns the expanded memory manager major version number, i.e. the
  243.          whole portion of the version number. If an EMM is not installed, a 0 is
  244.          returned.
  245.  
  246.  
  247.          EMMversionMinor: byte;
  248.  
  249.          Returns the expanded memory manager minor version number, i.e. the dec-
  250.          imal portion of the version number. If an EMM is not installed, or if
  251.          the minor version number is zero, a 0 is returned.
  252.  
  253.  
  254. 4-6                                                                 User's Guide
  255.  
  256. --------------------------------------------------------------------------------
  257.  
  258.          EMMversion: string;
  259.  
  260.          Returns a three character string representing the complete EMM version
  261.          number, e.g. "4.0".
  262.  
  263.  
  264.          MaxExpMem: word;
  265.  
  266.          Returns the total amount of installed expanded memory in kilobytes.
  267.  
  268.  
  269.          ExpMemAvail: word;
  270.  
  271.          Returns the amount of unused (or available) expanded memory in kilo-
  272.          bytes.
  273.  
  274.  
  275.          ExtMemAvail: word;
  276.  
  277.          Returns the amount of unused extended memory in kilobytes.
  278.  
  279.  
  280.  
  281. Using OSOBJ
  282.  
  283.          The OSOBJ object is designed to provide information about the operating
  284.          system. This unit is particularly useful when programs need to be
  285.          developed for the international (read: non-American!) market place,
  286.          because the DOS configuration can be ascertained, including the date
  287.          format, currency symbol, country code, etc.
  288.  
  289.          If you develop a program to be distributed internationally, you need to
  290.          adhere to the host countries' formatting conventions, especially date
  291.          and number formats. Refer to chapter 11: Controlling User Input for a
  292.          full discussion of this topic.
  293.  
  294.          The following function methods are available:
  295.  
  296.  
  297.          OSVersionMajor: byte;
  298.  
  299.          Returns the major DOS version number, e.g. 2, 3 or 4.
  300.  
  301.  
  302.          OSVersionMinor: byte;
  303.  
  304.          Returns the minor DOS version number, e.g. 1.
  305.  
  306.  
  307.          OSVersion: string;
  308.  
  309.          Returns the full DOS version number as a string, e.g. "3.1"
  310.  
  311.  
  312.          Country: word;
  313.  
  314.  
  315. Hardware                                                                     4-7
  316.  
  317. --------------------------------------------------------------------------------
  318.  
  319.          Returns a word which represents the country code. In general, the coun-
  320.          try codes are the same as the 3-digit international phone access code.
  321.          Some of the more common codes are:
  322.  
  323.                 001   United States
  324.                 002   Canada (French)
  325.                 003   Latin America
  326.                 031   Netherlands
  327.                 032   Belgium
  328.                 033   France
  329.                 034   Spain
  330.                 039   Italy
  331.                 041   Switzerland
  332.                 044   United Kingdom
  333.                 045   Denmark
  334.                 046   Sweden
  335.                 047   Norway
  336.                 049   Germany
  337.                 061   Australia
  338.                 351   Portugal
  339.                 358   Finland
  340.  
  341.  
  342.          Currency: string;
  343.  
  344.          Returns a string identifying the country's currency abbreviation. On
  345.          systems using DOS prior to version 3.0, only a signal character can be
  346.          accessed. However, systems using DOS 3.0 and later may return more than
  347.          one character, e.g. FFR, DKR.
  348.  
  349.  
  350.          DateFmt: tDate;
  351.  
  352.          The totSYS unit includes the declaration of the tDATE enumerated type
  353.          which has three members: USA, EUROPE and JAPAN. This function returns
  354.          the member which represents the operating system default date format.
  355.          Note that the three formats are MM-DD-YY, DD-MM-YY and YY-MM-DD,
  356.          respectively.
  357.  
  358.  
  359.          ThousandsSep: char;
  360.  
  361.          Returns the character used to punctuate the thousands mark in numbers.
  362.          The USA uses a comma, whereas many other countries use a period or a
  363.          space.
  364.  
  365.  
  366.          DecimalSep: char;
  367.  
  368.          Returns the character used to punctuate the decimal place. This is
  369.          usually a period or a comma.
  370.  
  371.  
  372.  
  373. 4-8                                                                 User's Guide
  374.  
  375. --------------------------------------------------------------------------------
  376.  
  377.          DateSep: char;
  378.  
  379.          Returns the character used to separate the month, day and year elements
  380.          of a date, e.g. "/", "-". Note: this information is not accessible on
  381.          systems using DOS prior to version 3.0. If the machine does not have
  382.          DOS 3.0 or later, a '/' is returned.
  383.  
  384.  
  385.          TimeSep: char;
  386.  
  387.          Returns the character used to separate the hours, minutes and seconds
  388.          when displaying the time, e.g. ":". Note: this information is not
  389.          accessible on systems using DOS prior to version 3.0. If the machine
  390.          does not have DOS 3.0 or later, a ':' is returned.
  391.  
  392.  
  393.          TimeFmt: byte;
  394.  
  395.          Returns a byte to indicate the preferred time display. A 0 indicates a
  396.          12 hour format, and a 1 indicates a 24 hour format. Note: this informa-
  397.          tion is not accessible on systems using DOS prior to version 3.0. If
  398.          the machine does not have DOS 3.0 or later, a 0 is returned.
  399.  
  400.  
  401.          CurrencyFmt: byte;
  402.  
  403.          Returns a byte indicating the currency format. One of the following
  404.          five values will be returned:
  405.  
  406.               0     String leads currency, no space
  407.               1     String follows currency, no space
  408.               2     String leads currency, one space
  409.               3     String follows currency, one space
  410.               4     String replaces decimal separator
  411.  
  412.          Note: this information is not accessible on systems using DOS prior to
  413.          version 3.0. If the machine does not have DOS 3.0 or later, a 0 is
  414.          returned.
  415.  
  416.  
  417.          CurrencyDecPlaces: byte;
  418.  
  419.          Returns the number of decimal places normally used with the country's
  420.          currency. Note: this information is not accessible on systems using DOS
  421.          prior to version 3.0. If the machine does not have DOS 3.0 or later, a
  422.          2 is returned.
  423.  
  424.  
  425.  
  426. Hardware                                                                     4-9
  427.  
  428. --------------------------------------------------------------------------------
  429.  
  430. Example
  431.  
  432.          Listed below is the demo program, DEMSY1, which illustrates the use of
  433.          each of the four totSYS objects. Figure 4.1 reflects the resultant
  434.          output on a VGA computer.
  435.  
  436.           Program DemoSystemOne;
  437.           {DEMSY1}
  438.  
  439.           USES DOS,CRT, TOTSYS;
  440.  
  441.           var
  442.              Equip: EquipObj;
  443.              Mem: MemObj;
  444.              OS: OSObj;
  445.              Lines: byte;
  446.           begin
  447.             ClrScr;
  448.             Lines := Monitor^.SetCondensed;
  449.             if Monitor^.ColorOn then
  450.                writeln('This system is color')
  451.             else
  452.                writeln('This system is monochrome');
  453.             with Equip do
  454.             begin
  455.                Init;
  456.                Writeln('Machine ID: ',ComputerID);
  457.                Writeln('Parallel Ports: ',ParallelPorts);
  458.                Writeln('Serial Ports: ',SerialPorts);
  459.                Writeln('Floppy Drives: ',Floppydrives);
  460.                Writeln('ROM date: ',RomDate);
  461.                Writeln('Game Adapter: ',GameAdapter);
  462.                Writeln('Serial printer: ',Serialprinter);
  463.                Writeln('Math Coprocessor: ',MathChip);
  464.                Writeln;
  465.             end;
  466.  
  467.             with Mem do
  468.             begin
  469.                Init;
  470.                Writeln('Base memory: ',Basememory,'k');
  471.                Writeln('Avail Extended memory: ',ExtMemAvail,'k');
  472.                if EMMInstalled then
  473.                begin
  474.                   Writeln('Total Expanded memory: ',MaxExpMem,'k');
  475.                   Writeln('Avail Expanded memory: ',ExpMemAvail,'k');
  476.                   Writeln('Expanded memory manager version: '+
  477.                           EMMversion);
  478.                end
  479.                else
  480.  
  481.  
  482.  
  483. 4-10                                                                User's Guide
  484.  
  485. --------------------------------------------------------------------------------
  486.  
  487.                   Writeln('Expanded memory not installed: ');
  488.                writeln;
  489.             end;
  490.  
  491.             with OS do
  492.             begin
  493.                Init;
  494.                Writeln('Operating System Version: '+OSversion);
  495.                Writeln('Country Code: ',Country);
  496.                write('Currency String: ',Currency,' ');
  497.                case CurrencyFmt of
  498.                   0: writeln('(String leads currency, no space)');
  499.                   1: writeln('(String follows currency, no space)');
  500.                   2: writeln('(String leads currency, one space)');
  501.                   3: writeln('(String follows currency, one space)');
  502.                   4: writeln('(String replaces decimal separator)');
  503.                end; {case}
  504.                writeln('Currency Decimal Places: ',CurrencyDecPlaces);
  505.                write('Thousands Separator: ','''',ThousandsSep,'''');
  506.                writeln(' Decimal Separator: ','''',DecimalSep,'''');
  507.                case DateFmt of
  508.                   USA: writeln('Date Format: MM DD YY');
  509.                   Europe: writeln('Date Format: DD MM YY');
  510.                   Japan: writeln('Date Format: YY MM DD');
  511.                end; {case}
  512.                write('Date separator: ','''',DateSep,'''');
  513.                writeln(' Time separator: ','''',TimeSep,'''');
  514.                if TimeFmt = 0 then
  515.                   writeln('Time is displayed on a 12 hour clock')
  516.                else
  517.                   writeln('Time is displayed on a 24 hour clock');
  518.             end;
  519.             write('                            press any key ...');
  520.             Repeat until keypressed;
  521.             if Lines > 25 then
  522.                Monitor^.Set25;
  523.           end.
  524.  
  525.          Notice that the INIT method is not called for the Monitor^ instance.
  526.          This is because Monitor^ is a global instance, and the Toolkit automat-
  527.          ically initializes all global instances.
  528.  
  529.  
  530.  
  531. Figure 4.1                                                              [SCREEN]
  532. The System Demo
  533. Program
  534.