home *** CD-ROM | disk | FTP | other *** search
/ Phoenix CD 2.0 / Phoenix_CD.cdr / 01e / limspec.zip / LIMSPEC.MEM
Text File  |  1986-02-12  |  172KB  |  5,941 lines

  1.  
  2.  
  3.  
  4.  
  5.                                    READ THIS FIRST
  6.  
  7.           The Lotus/Intel/Microsoft Expanded Memory Specification changes
  8.           from time to time, so you should contact Intel occasionally to
  9.           ensure that you are using the most recent version.
  10.  
  11.           You can reach us at one of our Customer Support numbers.
  12.  
  13.           o  If you live in the continental United States but outside
  14.              Oregon, call (800) 538-3373.
  15.  
  16.           o  If you live in Oregon, Hawaii, Alaska, or outside the
  17.              continental United States, call (503) 629-7354.
  18.  
  19.           o  If you live in Canada, call (800) 234-0444.
  20.  
  21.           Customer Support representatives are ready to answer your call
  22.           Monday through Friday, from 7 a.m. to 5 p.m. Pacific time.
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.           
  72.  
  73.  
  74.           
  75.  
  76.                          THE LOTUS(R)/INTEL(R)/MICROSOFT(R)
  77.  
  78.                             EXPANDED MEMORY SPECIFICATION
  79.  
  80.                                     Version 3.20
  81.                               Part number:  300275-003
  82.                                    September, 1985
  83.  
  84.           
  85.  
  86.           
  87.  
  88.           
  89.  
  90.           
  91.  
  92.           
  93.  
  94.           
  95.  
  96.           
  97.  
  98.           
  99.  
  100.           
  101.  
  102.           
  103.  
  104.           
  105.  
  106.           
  107.  
  108.           
  109.  
  110.           
  111.  
  112.           
  113.  
  114.           
  115.  
  116.           
  117.  
  118.           
  119.  
  120.           Copyright (c) 1985
  121.           Lotus Development Corporation, 55 Cambridge Ave., Cambridge, MA
  122.           02142
  123.           Intel Corporation, 3065 Bowers Ave., Santa Clara, CA 95051
  124.           Microsoft Corporation, 10700 Northup Way, Bellevue, WA  98009
  125.  
  126.  
  127.  
  128.           ii                           300275-003                           
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.           Note:  This specification was jointly developed by Lotus
  138.           Development Corporation, Intel Corporation, and Microsoft
  139.           Corporation.  Although it has been released into the public
  140.           domain and is not confidential or proprietary, the specification
  141.           is still the copyright and property of Lotus Development
  142.           Corporation, Intel Corporation, and Microsoft Corporation.
  143.  
  144.  
  145.           DISCLAIMER OF WARRANTY
  146.  
  147.           LOTUS DEVELOPMENT CORPORATION, INTEL CORPORATION, AND MICROSOFT
  148.           CORPORATION EXCLUDE ANY AND ALL IMPLIED WARRANTIES, INCLUDING
  149.           WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  150.           PURPOSE.  NEITHER LOTUS NOR INTEL NOR MICROSOFT MAKE ANY WARRANTY
  151.           OF REPRESENTATION, EITHER EXPRESS OR IMPLIED, WITH RESPECT TO
  152.           THIS SPECIFICATION, ITS QUALITY, PERFORMANCE, MERCHANTABILITY, OR
  153.           FITNESS FOR A PARTICULAR PURPOSE.  NEITHER LOTUS NOR INTEL NOR
  154.           MICROSOFT SHALL HAVE ANY LIABILITY FOR SPECIAL, INCIDENTAL, OR
  155.           CONSEQUENTIAL DAMAGES ARISING OUT OF OR RESULTING FROM THE USE OR
  156.           MODIFICATION OF THIS SPECIFICATION.
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.                                        300275-003                        iii
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.           How to use this specification
  204.  
  205.           If you're already familiar with the concept of expanded memory or
  206.           if you're interested in only parts of the spec reading this
  207.           preface can save you time.  It gives a brief summary of each
  208.           chapter so you can decide what you need to read.
  209.  
  210.  
  211.           Chapter 1 -- Introduction to expanded memory
  212.  
  213.           This chapter introduces the concept of expanded memory and
  214.           discusses the following topics:
  215.  
  216.           o  Memory addressing capabilities of the Intel 8086, 8088, and
  217.              80286 microprocessors
  218.  
  219.           o  Accessing expanded memory
  220.  
  221.           o  Frequently used terminology
  222.  
  223.           You can skip this chapter if you're already familiar with the
  224.           Intel 8086, 8088, and 80286 microprocessors and you understand
  225.           expanded memory.
  226.  
  227.  
  228.           Chapter 2 -- Writing programs that use expanded memory
  229.  
  230.           This chapter provides guidelines to help you create programs that
  231.           use expanded memory.  It also describes the individual Expanded
  232.           Memory Manager (EMM) functions in detail, with assembly language
  233.           examples, parameter passing conventions, and an explanation of
  234.           the status and results returned by the function.
  235.  
  236.           You should read this chapter if you want to write programs that
  237.           use expanded memory.
  238.  
  239.  
  240.           Chapter 3 -- Testing for the presence of the Expanded Memory
  241.           Manager
  242.  
  243.           This chapter describes two methods your program can use to test
  244.           for the presence of the EMM.  You should read this chapter if you
  245.           want to write programs that use expanded memory.
  246.  
  247.  
  248.           Chapter 4 -- Example expanded memory programs
  249.  
  250.           This chapter presents examples of expanded memory programs.
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.           iv                           300275-003                           
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.           Glossary
  270.  
  271.           The Glossary defines some of the terms that are used frequently
  272.           in this specification.  Most of the terms are defined for readers
  273.           who understand technical terminology and are familiar with IBM
  274.           PCs, XTs, and ATs, or compatibles.
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.                                        300275-003                          v
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.           Contents
  336.  
  337.  
  338.  
  339.           How to use this specification 
  340.  
  341.           Chapter 1 -- Introduction
  342.  
  343.           The Intel 8086 and 8088 microprocessors......................1-1
  344.  
  345.           The Intel 80286 microprocessor...............................1-1
  346.  
  347.           How expanded memory is accessed..............................1-1
  348.  
  349.           Limitations of the 8086, 8088, and 80286 microprocessors.....1-2
  350.  
  351.           Terminology..................................................1-2
  352.  
  353.  
  354.           Chapter 2 -- Writing programs that use expanded memory
  355.  
  356.           Designing your program.......................................2-1
  357.             The operating environment..................................2-1
  358.             Mechanics of the EMM.......................................2-1
  359.             Programming guidelines.....................................2-2
  360.  
  361.           The EMM functions............................................2-3
  362.             Overview of the EMM functions..............................2-3
  363.             FUNCTION 1 -- Get status...................................2-5
  364.             FUNCTION 2 -- Get page frame address.......................2-6
  365.             FUNCTION 3 -- Get unallocated page count...................2-7
  366.             FUNCTION 4 -- Allocate pages...............................2-9
  367.             FUNCTION 5 -- Map handle pages.............................2-11
  368.             FUNCTION 6 -- Deallocate pages.............................2-13
  369.             FUNCTION 7 -- Get EMM version..............................2-15
  370.             FUNCTION 8 -- Save page map................................2-16
  371.             FUNCTION 9 -- Restore page map.............................2-18
  372.             FUNCTION 10 -- Reserved....................................2-20
  373.             FUNCTION 11 -- Reserved....................................2-21
  374.             FUNCTION 12 -- Get EMM handle count........................2-22
  375.             FUNCTION 13 -- Get EMM handle pages........................2-23
  376.             FUNCTION 14 -- Get all EMM handle pages....................2-25
  377.             FUNCTION 15 -- Get/set page map............................2-27
  378.  
  379.           Summary of status codes......................................2-33
  380.  
  381.  
  382.           Chapter 3 -- Testing for presence of the manager
  383.  
  384.           Which method should my program use?..........................3-1
  385.  
  386.           The "open handle" technique..................................3-1
  387.             Using the "open handle" technique..........................3-1
  388.             An example of the "open handle" technique..................3-4
  389.  
  390.  
  391.  
  392.           vi                           300275-003                           
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.           The "get interrupt vector" technique.........................3-6
  402.             Using the "get interrupt vector" technique.................3-6
  403.             An example of the "get interrupt vector" technique.........3-7
  404.  
  405.  
  406.           Chapter 4 -- Example expanded memory programs
  407.  
  408.           Characteristics of the example procedures....................4-1
  409.  
  410.           Transient application program................................4-1
  411.             Flow chart of a transient application program..............4-1
  412.             Explanation of the transient application program
  413.             flow chart.................................................4-2
  414.               Initialization procedures................................4-2
  415.               Processing procedures....................................4-3
  416.               Terminating procedures...................................4-3
  417.  
  418.           Resident application program.................................4-3
  419.             Flow chart of a resident application program...............4-4
  420.             Explanation of the resident application program
  421.             flow chart.................................................4-5
  422.               Initializing the resident program and the EMM............4-5
  423.               Saving the current state of the CPU......................4-6
  424.               Resident processing performed before accessing
  425.               expanded memory..........................................4-6
  426.               Saving the state of the expanded memory hardware.........4-6
  427.               Accessing expanded memory................................4-6
  428.               Restoring the state of the expanded memory hardware......4-7
  429.               Terminating the resident program.........................4-7
  430.               Restoring the CPU state..................................4-7
  431.  
  432.           Example EMM procedures.......................................4-8
  433.  
  434.  
  435.           Glossary
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.                                        300275-003                        vii
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.           CHAPTER 1.  INTRODUCTION TO EXPANDED MEMORY
  468.  
  469.           This specification describes a way to expand the memory
  470.           addressing capabilities of the Intel 8086, 8088, and 80286
  471.           microprocessors.  It introduces a "paging" mechanism to access
  472.           very large amounts of memory.  This memory paging (also known as
  473.           bank switching or bank swapping) uses a type of memory called
  474.           "expanded memory."
  475.  
  476.           The rest of this chapter describes the memory addressing
  477.           capabilities of the Intel 8086, 8088, and 80286 microprocessors
  478.           and how the interface described in this specification overcomes
  479.           their limitations.
  480.  
  481.  
  482.           The Intel 8086 and 8088 microprocessors
  483.  
  484.           The Intel 8086 and 8088 microprocessors let programs or operating
  485.           systems directly access up to 1M byte of address space.  DOS, the
  486.           most frequently used operating system for 8086 and 8088-based IBM
  487.           personal computers and compatibles, allows application programs
  488.           to use only up to 640K bytes of memory.
  489.  
  490.           This memory space often is not enough for application programs
  491.           which require large amounts of memory to implement spreadsheets,
  492.           databases, and other memory-intensive functions.
  493.  
  494.  
  495.           The Intel 80286 microprocessor
  496.  
  497.           Although the Intel 80286 microprocessor can address more memory
  498.           space (up to 16M bytes) than the 8086 and 8088 microprocessors,
  499.           the amount of memory DOS can access directly is still limited to
  500.           640K bytes.  This limitation is imposed because the 80286
  501.           microprocessor operates under one of two modes:  Real Mode or
  502.           Protected Virtual Addressing Mode (PVAM).
  503.  
  504.           When operating in Real Mode, the 80286 microprocessor lets
  505.           programs or operating systems directly access only up to 1M byte
  506.           of address space.  This is the mode that DOS uses, so application
  507.           programs which run on IBM's AT or AT-compatible machines are
  508.           still limited to 640K bytes of usable memory space.
  509.  
  510.           When operating in PVAM, the 80286 microprocessor lets programs
  511.           that run under the XENIX operating system address up to 16M bytes
  512.           of memory.  However, since most IBM AT or AT-compatible machines
  513.           operate under DOS, application programs can rarely take advantage
  514.           of this extra memory.
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.           Introduction                 300275-003                        1-1
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.           How expanded memory is accessed
  534.  
  535.           Much as your computer screen acts as a small "window" into a much
  536.           larger spreadsheet, memory paging provides one or more small
  537.           "windows" of memory through which a much larger memory space can
  538.           be accessed.  These windows are called physical pages.
  539.  
  540.           This specification describes a method where four contiguous
  541.           physical pages of 16K bytes each (forming a block of 64K bytes)
  542.           can access up to 8M bytes of expanded memory space via the
  543.           Expanded Memory Manager (EMM).
  544.  
  545.  
  546.           Limitations of the 8086, 8088, and 80286 microprocessors
  547.  
  548.           You can use the Expanded Memory Manager (EMM) to overcome the
  549.           memory limitations of the Intel 8086, 8088, and 80286
  550.           microprocessors.  The EMM is a set of standard interface routines
  551.           which allow programs, running on IBM PCs, XTs, ATs, or
  552.           compatibles, to use up to 8M bytes of expanded memory.
  553.  
  554.           Because the EMM is a standard, programs that adhere to the
  555.           Lotus/Intel/Microsoft Expanded Memory Specification can avoid
  556.           potential compatibility problems.  Expanded memory application
  557.           programs that deal directly with the hardware or that don't
  558.           strictly adhere to the specification run this risk.
  559.  
  560.           Chapter 3 of this specification describes the EMM in detail.
  561.  
  562.  
  563.           Terminology
  564.  
  565.           The following terms are used frequently in this specification:
  566.  
  567.           o  Conventional memory
  568.  
  569.              Conventional memory refers to the memory DOS recognizes.  In
  570.              PCs, XTs, and ATs, this is memory between 0 and 640K bytes.
  571.              Because application programs let DOS manage their memory, they
  572.              can use only conventional memory.
  573.  
  574.           o  Expanded memory
  575.  
  576.              Expanded memory is a special kind of memory that goes beyond
  577.              DOS's 640K-byte limit.  Application programs that adhere to
  578.              the Lotus/Intel Expanded Memory Specification can use the
  579.              Expanded Memory Manager (EMM) to manage expanded memory just
  580.              as other programs use DOS to manage conventional memory.
  581.  
  582.           o  Extended memory
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.           1-2                          300275-003               Introduction
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.              Extended memory is the 15M-byte address space on an IBM AT or
  600.              compatible computer outside the memory DOS can access.  This
  601.              address space is of little use to those application programs
  602.              that use DOS.  DOS does not recognized memory above 640K
  603.              bytes; the XENIX operating system manages extended memory.
  604.  
  605.           Other terms are defined in the Glossary near the end of this
  606.           specification.
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.           Introduction                 300275-003                        1-3
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.           CHAPTER 2.  WRITING PROGRAMS THAT USE
  666.                                EXPANDED MEMORY
  667.  
  668.           This chapter is divided into two major sections.  The first
  669.           section provides guidelines to help you create programs that use
  670.           expanded memory.  The second section describes the individual EMM
  671.           functions in detail, with assembly language examples, parameter
  672.           passing conventions, and an explanation of the status and results
  673.           returned by the function.
  674.  
  675.  
  676.           Designing your program
  677.  
  678.           While designing or planning a program that uses expanded memory,
  679.           consider the following topics:
  680.  
  681.           o  The operating environment
  682.  
  683.           o  The mechanics of the Expanded Memory Manager (EMM)
  684.  
  685.           o  The programming guidelines presented here
  686.  
  687.           This section discusses these topics and lists some guidelines to
  688.           help you to create programs that use expanded memory.
  689.  
  690.  
  691.           The operating environment
  692.  
  693.           The guidelines in this section help ensure that your program
  694.           works in systems that use expanded memory.  To be "safe," your
  695.           program should assume the system for which you're writing the
  696.           program contains:
  697.  
  698.           o  Multiple expanded memory boards.
  699.  
  700.           o  Other resident programs which also use expanded memory. An
  701.              example of a resident program is an interrupt service routine
  702.              or a device driver.  It can also be a program invoked by an
  703.              interrupt service routine or just a program that preempts the
  704.              active program.
  705.  
  706.           o  Registers whose contents are modified by function invocations.
  707.              This means your program can't rely on the contents of certain
  708.              registers after a function invocation.  (The registers that a
  709.              particular function modifies are listed in the description of
  710.              the function; all others are unchanged)
  711.  
  712.  
  713.           Mechanics of the EMM
  714.  
  715.           Version 3.20 of the EMM is re-entrant and its critical regions
  716.           are protected from interrupts.  This means you'll never encounter
  717.           a "busy" condition.
  718.  
  719.           However, the EMM requires programs to follow these rules:
  720.  
  721.  
  722.           2-4                          300275-003           Writing programs
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.           o  The physical size of each page is fixed at 16K bytes.
  732.  
  733.           o  Four 16K-byte pages can be mapped into the system memory
  734.              address space simultaneously and contiguously.  The 64K-byte
  735.              region which results from this mapping must begin at the
  736.              address returned by EMM FUNCTION 2 (Get page frame).
  737.  
  738.           Note:  Throughout the remainder of this document, the 64k-byte
  739.           region returned by FUNCTION 2 is called the "page frame."
  740.  
  741.  
  742.           Programming guidelines
  743.  
  744.           To ensure that your program runs correctly with the EMM, it
  745.           should:
  746.  
  747.           o  Not locate its stack within expanded memory.
  748.  
  749.           o  Test for the presence of the EMM device by using one of two
  750.              methods.  The first method is to use the DOS "open handle"
  751.              technique.  The second method is to use the DOS "get interrupt
  752.              vector" function to obtain the contents of interrupt vector
  753.              67h.  Once you get the contents of interrupt vector 67h, you
  754.              can inspect the device driver header.  (Both methods are
  755.              described Chapter 3 of this specification.)
  756.  
  757.           o  Not use interrupt 67h.  DOS normally sets aside interrupt
  758.              vector table entries 60h through 67h for non-system software
  759.              that uses software interrupts.  However, the EMM uses
  760.              interrupt vector 67h.  It sets the contents of interrupt
  761.              vector table entry 67h to the address of the EMM service
  762.              procedure using the DOS "Set Interrupt Vector" function.
  763.  
  764.              Other software that uses this vector won't work once the EMM
  765.              installs itself because the EMM does not chain to any software
  766.              previously serviced by this interrupt vector.
  767.  
  768.           Note:  Resident software that uses INT 67h and installs itself
  769.           after the EMM, will disable the EMM.
  770.  
  771.           o  Request the page frame base address after determining that the
  772.              EMM is installed.  This page frame base address is the
  773.              starting address of the 64K-byte memory segment that contains
  774.              the four 16K-byte pages.  The first 16K-byte physical page
  775.              address begins at this base address.  The second 16K-byte
  776.              physical page address starts at the base address offset by
  777.              4000h.  The third 16K-byte physical page address starts at the
  778.              base address offset by 8000h.  The fourth 16K-byte physical
  779.              page starts at the base address offset by C000h.
  780.  
  781.           o  Request the number of unallocated 16K-byte pages within the
  782.              expanded memory system.  This determines the maximum number of
  783.              pages the program can allocate.
  784.  
  785.  
  786.  
  787.  
  788.           Writing programs             300275-003                        2-5
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.           o  "Open" the EMM and allocate the number of 16K-byte pages that
  798.              it intends to use.  The EMM returns a unique "EMM handle" that
  799.              the program uses to identify itself in all future transactions
  800.              with the EMM.  The EMM uses this handle to identify the memory
  801.              it allocates to each program.  (Your program should obtain EMM
  802.              handle(s) and allocate pages only once, at the beginning of
  803.              the program.)
  804.  
  805.              The EMM attempts to assign the pages the program requests.  If
  806.              the number of pages it requests is greater than the number of
  807.              free pages, the EMM returns an "error" status.  The status
  808.              codes the EMM returns are listed in this chapter.
  809.  
  810.           Note:  A single application program can request multiple EMM
  811.           handles and as many pages per EMM handle as it desires.  The
  812.           nature of the application determines the number of EMM handles
  813.           and pages required.
  814.  
  815.           o  Issue a map request to the EMM.  (At this point the program
  816.              can map any allocated logical page into any one of the four
  817.              physical pages within the page frame.)  The map operation must
  818.              be performed before any data within the physical page can be
  819.              accessed.
  820.  
  821.              If the logical page has not been assigned to this particular
  822.              EMM handle, the EMM returns an error and doesn't carry out the
  823.              mapping procedure.  If the physical page (at which the logical
  824.              page is mapped) isn't in the range 0 thru 3, the EMM returns
  825.              an error.
  826.  
  827.           o  Keep track of the contents of each page of  expanded memory.
  828.              The EMM doesn't provide a facility for associating data with a
  829.              particular logical page.  If a page contains data that will be
  830.              accessed within the program, the program must remember which
  831.              page contains the data.
  832.  
  833.           o  "Close" the Expanded Memory Manager prior to terminating.
  834.              This deallocates all pages previously allocated to the EMM
  835.              handle.  The deallocated pages become available to all other
  836.              programs using expanded memory.  The "close" request has no
  837.              effect on these other programs.
  838.  
  839.              If the program does not perform a "close" before it exits to
  840.              DOS, the pages allocated to the EMM handle will remain
  841.              assigned.  The only way to deallocate pages left in this
  842.              condition is to power off the system.
  843.  
  844.  
  845.           The EMM functions
  846.  
  847.           This section presents a general overview of the EMM functions,
  848.           detailed descriptions of the individual functions, and a list
  849.           that summarizes the status codes the EMM functions return.
  850.  
  851.  
  852.  
  853.  
  854.           2-6                          300275-003           Writing programs
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.           Overview of the EMM functions
  864.  
  865.           The EMM functions provide you with a set of standard expanded
  866.           memory functions.  Because the EMM functions are standard, you
  867.           avoid potential compatibility problems with other expanded memory
  868.           programs that also adhere to the EMM specification.  Programs
  869.           that deal directly with the hardware or that don't adhere to the
  870.           specification run this risk.
  871.  
  872.  
  873.           Functions 1 through 7 -- for general-purpose programming
  874.  
  875.           Functions 1 through 7 provide the memory operators that typical
  876.           application programs require.  Of these seven functions, FUNCTION
  877.           5 (Map) is the only one that a program may use a great deal while
  878.           running.
  879.  
  880.  
  881.           Functions 8 and 9 -- for interrupt service routines, device
  882.           drivers, and other resident software
  883.  
  884.           Functions 8 and 9 aren't necessary for most application programs.
  885.           They are provided only for software that must save the current
  886.           state of the mapping hardware, switch mapping contexts,
  887.           manipulate the sections of expanded memory that they "own," and
  888.           restore the original context of the memory mapping hardware.
  889.           Examples of this type of software are interrupt service routines,
  890.           device drivers, and resident software such as print spoolers that
  891.           use expanded memory.
  892.  
  893.  
  894.           Functions 10 and 11 -- reserved
  895.  
  896.           In previous versions of the Lotus/Intel/Microsoft Expanded Memory
  897.           Specification, Function 10 retrieved the page mapping register
  898.           I/O array and Function 11 retrieved the logical-to-physical page
  899.           translation array.
  900.  
  901.           These functions are now reserved and new programs should not use
  902.           them.  However, existing programs that use these functions will
  903.           still work correctly.
  904.  
  905.  
  906.           Functions 12, 13, and 14 -- for utility programs
  907.  
  908.           Functions 12, 13, and 14 are also not necessary for most
  909.           application programs.  They are provided for utility programs
  910.           that need to keep track of how expanded memory is being used.
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.           Writing programs             300275-003                        2-7
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.           Function 15 -- for multitasking operating systems
  930.  
  931.           Function 15 is for multitasking operating systems that must save
  932.           the current state of the mapping hardware within each expanded
  933.           memory board before modifying the state of the mapping hardware
  934.           on any of the boards.
  935.  
  936.  
  937.  
  938.  
  939.  
  940.  
  941.  
  942.  
  943.  
  944.  
  945.  
  946.  
  947.  
  948.  
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.           2-8                          300275-003           Writing programs
  987.  
  988.  
  989.  
  990.  
  991.  
  992.           FUNCTION 1
  993.                          Get Status
  994.  
  995.  
  996.           The Get Status function returns a status code that tells you
  997.           whether the EMM is present and if the hardware is working
  998.           correctly.  This function doesn't require an EMM handle.
  999.  
  1000.  
  1001.           Parameter passing convention
  1002.  
  1003.           AH        The AH register contains the function number (40h).
  1004.  
  1005.  
  1006.           Example invocation in assembly language
  1007.  
  1008.           This example shows how to invoke the Get Status function in
  1009.           assembly language.
  1010.  
  1011.           MOV       AH, 40h
  1012.           INT       67h
  1013.           OR        AH, AH
  1014.           JNZ       error_handler
  1015.  
  1016.  
  1017.           Registers modified
  1018.  
  1019.           The Get Status function modifies the contents of the AX register.
  1020.  
  1021.  
  1022.           Status returned
  1023.  
  1024.           The Get Status function returns one of the following status
  1025.           codes.
  1026.  
  1027.           AH = 0    The manager is present in the system and the hardware
  1028.                     is working correctly.
  1029.  
  1030.           AH = 80h  The manager detected a malfunction in the EMM software.
  1031.  
  1032.           AH = 81h  The manager detected a malfunction in the expanded
  1033.                     memory hardware.
  1034.  
  1035.           AH = 84h  The function code passed to the EMM is not defined.
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.           Writing programs             300275-003                        2-5
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.           FUNCTION 2
  1059.                          Get Page Frame Address
  1060.  
  1061.  
  1062.           The Get Page Frame Address function tells your program where the
  1063.           page frame is located.  It returns the segment portion of the
  1064.           page frame address in the BX register.  This function doesn't
  1065.           require an EMM handle.
  1066.  
  1067.  
  1068.           Parameter passing convention
  1069.  
  1070.           AH        The AH register contains the function number for the
  1071.                     Get Page Frame function (41h).
  1072.  
  1073.  
  1074.           Example invocation in assembly language
  1075.  
  1076.           This example shows how to invoke the Get Page Frame Address
  1077.           function in assembly language.
  1078.  
  1079.           MOV       AH, 41h
  1080.           INT       67h
  1081.           OR        AH, AH
  1082.           JNZ       error_handler
  1083.           MOV       page_segment, BX
  1084.  
  1085.  
  1086.           Registers modified
  1087.  
  1088.           The Get Page Frame Address function modifies the contents of the
  1089.           AX and BX registers.
  1090.  
  1091.  
  1092.           Status returned
  1093.  
  1094.           The Get Page Frame Address function returns one of the following
  1095.           status codes.
  1096.  
  1097.           AH = 0    The manager has returned the page frame address.
  1098.  
  1099.           AH = 80h  The manager detected a malfunction in the EMM software.
  1100.  
  1101.           AH = 81h  The manager detected a malfunction in the expanded
  1102.                     memory hardware.
  1103.  
  1104.           AH = 84h  The function code passed to the EMM is not defined.
  1105.  
  1106.  
  1107.           Results returned
  1108.  
  1109.           The Get Page Frame Address function returns these results.
  1110.  
  1111.           BX = segment The BX register contains the segment address of the
  1112.                     page frame.  The value in BX has no meaning if AH <> 0.
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.           2-6                          300275-003           Writing programs
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.           FUNCTION 3
  1125.                          Get Unallocated Page Count
  1126.  
  1127.  
  1128.           The Get Unallocated Page Count function tells your program the
  1129.           number of unallocated pages as well as the total number of pages
  1130.           in expanded memory.  This function doesn't require an EMM handle.
  1131.  
  1132.  
  1133.           Parameter passing convention
  1134.  
  1135.           AH        The AH register contains the function number for the
  1136.                     Get Unallocated Page Count function (42h).
  1137.  
  1138.  
  1139.           Example invocation in assembly language
  1140.  
  1141.           This example shows how to invoke the Get Unallocated Pages Count
  1142.           function in assembly language.
  1143.  
  1144.           MOV       AH, 42h
  1145.           INT       67h
  1146.           OR        AH, AH
  1147.           JNZ       error_handler
  1148.           MOV       un_alloc_pages, BX
  1149.           MOV       total_pages, DX
  1150.  
  1151.  
  1152.           Registers modified
  1153.  
  1154.           The Get Unallocated Pages Count function modifies the contents of
  1155.           the AX, BX, and DX registers.
  1156.  
  1157.  
  1158.           Status returned
  1159.  
  1160.           The Get Unallocated Pages Count function returns one of the
  1161.           following status codes.
  1162.  
  1163.           AH = 0    The manager has returned the number unallocated pages
  1164.                     and the number of total pages in expanded memory.
  1165.  
  1166.           AH = 80h  The manager detected a malfunction in the EMM software.
  1167.  
  1168.           AH = 81h  The manager detected a malfunction in the expanded
  1169.                     memory hardware.
  1170.  
  1171.           AH = 84h  The function code passed to the EMM is not defined.
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.           Writing programs             300275-003                        2-7
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.           FUNCTION 3
  1191.                          Get Unallocated Page Count
  1192.                          (continued)
  1193.           Results returned
  1194.  
  1195.           The Get Unallocated Page Count function returns these results.
  1196.  
  1197.           BX = 0    All pages in expanded memory have already been
  1198.                     allocated.  None are currently available for expanded
  1199.                     memory.
  1200.  
  1201.           BX <> 0   The number of pages that are currently available.
  1202.  
  1203.           DX <> 0   The total number of pages in expanded memory
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.           2-8                          300275-003           Writing programs
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.           FUNCTION 4
  1257.                          Allocate Pages
  1258.  
  1259.  
  1260.           The Allocate Pages function allocates the number of pages your
  1261.           program requests and assigns a unique EMM handle to these pages.
  1262.           The EMM handle "owns" these pages until your program deallocates
  1263.           them.
  1264.  
  1265.  
  1266.           Parameter passing convention
  1267.  
  1268.           AH        The AH register contains the function number for the
  1269.                     Allocate Pages function (43h).
  1270.  
  1271.           BX        The BX register contains the number of pages your
  1272.                     program wishes to allocate.
  1273.  
  1274.  
  1275.           Example invocation in assembly language
  1276.  
  1277.           This example shows how to invoke the Allocate Pages function in
  1278.           assembly language.
  1279.  
  1280.           MOV       AH, 43h
  1281.           MOV       BX, num_of_pages_to_alloc
  1282.           INT       67h
  1283.           OR        AH, AH
  1284.           JNZ       error_handler
  1285.           MOV       emm_handle, DX
  1286.  
  1287.  
  1288.           Registers modified
  1289.  
  1290.           The Allocate Pages function modifies the contents of the AX and
  1291.           DX registers.
  1292.  
  1293.  
  1294.           Status returned
  1295.  
  1296.           The Allocate Pages function returns one of the following status
  1297.           codes.
  1298.  
  1299.           AH = 0    The manager has allocated the pages to an assigned EMM
  1300.                     handle.
  1301.  
  1302.           AH = 80h  The manager detected a malfunction in the EMM software.
  1303.  
  1304.           AH = 81h  The manager detected a malfunction in the expanded
  1305.                     memory hardware.
  1306.  
  1307.           AH = 84h  The function code passed to the EMM is not defined.
  1308.  
  1309.           AH = 85h  All EMM handles are being used.
  1310.  
  1311.           AH = 87h  There aren't enough expanded memory pages to supply
  1312.                     your program's request.
  1313.  
  1314.  
  1315.  
  1316.           Writing programs             300275-003                        2-9
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.           FUNCTION 4
  1323.                          Allocate Pages
  1324.                          (continued)
  1325.           AH = 88h  There aren't enough unallocated pages to supply your
  1326.                     program's request.
  1327.  
  1328.           AH = 89h  Can't allocate zero pages.
  1329.  
  1330.  
  1331.           Results returned
  1332.  
  1333.           The Allocate Pages function returns these results.
  1334.  
  1335.           DX = handle The DX register contains a unique EMM handle.  Your
  1336.                     program must use this EMM handle (as a parameter) in
  1337.                     any function invocations that map or deallocate
  1338.                     expanded memory.
  1339.  
  1340.  
  1341.  
  1342.  
  1343.  
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.           2-10                         300275-003           Writing programs
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.           FUNCTION 5
  1389.                          Map Handle Page
  1390.  
  1391.           The Map Handle Page function lets your program access the
  1392.           information stored in logical page (i) at physical page (j)
  1393.           within the page frame.
  1394.  
  1395.  
  1396.           Parameter passing convention
  1397.  
  1398.           AH        The AH register contains the function number for the
  1399.                     Map Handle Page function (44h).
  1400.  
  1401.           BX        The BX register contains the logical page (i) that is
  1402.                     mapped into the physical page within the page frame.
  1403.                     The logical page must be in the range 0 through (number
  1404.                     of pages allocated to an
  1405.                     EMM handle - 1).
  1406.  
  1407.           AL        The AL register contains the physical page (j) into
  1408.                     which the logical page (i) is mapped. This physical
  1409.                     page must be in the range 0 thru 3.
  1410.  
  1411.           DX        The DX register contains the EMM handle your program
  1412.                     received from FUNCTION 4 (Allocate Pages).
  1413.  
  1414.  
  1415.           Example invocation in assembly language
  1416.  
  1417.           This example shows how to invoke the Map Handle Page function in
  1418.           assembly language.
  1419.  
  1420.           MOV       DX, emm_handle 
  1421.           MOV       BX, i
  1422.           MOV       AL, j
  1423.           MOV       AH, 44h
  1424.           INT       67h
  1425.           OR        AH, AH
  1426.           JNZ       error_handler
  1427.  
  1428.  
  1429.           Registers modified
  1430.  
  1431.           The Map Handle Page function modifies the contents of the AX
  1432.           register.
  1433.  
  1434.  
  1435.           Status returned
  1436.  
  1437.           The Map Handle Page function returns one of the following status
  1438.           codes.
  1439.  
  1440.           AH = 0    The manager has mapped the page.  The page is now ready
  1441.                     to be accessed.
  1442.  
  1443.           AH = 80h  The manager detected a malfunction in the EMM software.
  1444.  
  1445.  
  1446.  
  1447.  
  1448.           Writing programs             300275-003                       2-11
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.           FUNCTION 5
  1455.                          Map Handle Page
  1456.                          (continued)
  1457.           AH = 81h  The manager detected a malfunction in the expanded
  1458.                     memory hardware.
  1459.  
  1460.           AH = 83h  The EMM couldn't find the EMM handle your program
  1461.                     specified.
  1462.  
  1463.           AH = 84h  The function code passed to the EMM is not defined.
  1464.  
  1465.           AH = 8Ah  The logical page is out of the range of logical pages
  1466.                     which are allocated to the EMM handle.
  1467.  
  1468.           AH = 8Bh  The physical page at which the logical page was
  1469.                     supposed to be mapped is out of the range of physical
  1470.                     pages.
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481.  
  1482.  
  1483.  
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.           2-12                         300275-003           Writing programs
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.           FUNCTION 6
  1521.                          Deallocate Pages
  1522.  
  1523.  
  1524.           The Deallocate Pages function deallocates the pages currently
  1525.           allocated to an EMM handle.  After your program invokes this
  1526.           function, other application programs can use these pages.
  1527.  
  1528.           Caution:  Your program must perform this function before it exits
  1529.           to DOS.  If it doesn't, no other programs can use these pages or
  1530.           their handle.
  1531.  
  1532.  
  1533.           Parameter passing convention
  1534.  
  1535.           AH        The AH register contains the function number for the
  1536.                     Deallocate Pages function (45h).
  1537.  
  1538.           DX        The DX register contains the EMM handle returned by
  1539.                     FUNCTION 4 (Allocate Pages).
  1540.  
  1541.  
  1542.           Example invocation in assembly language
  1543.  
  1544.           This example shows how to invoke the Deallocate Pages function in
  1545.           assembly language.
  1546.  
  1547.           MOV       DX, emm_handle 
  1548.           MOV       AH, 45h
  1549.           INT       67h
  1550.           OR        AH, AH
  1551.           JNZ       error_handler
  1552.  
  1553.  
  1554.           Registers modified
  1555.  
  1556.           The Deallocate Pages function modifies the contents of the AX
  1557.           register.
  1558.  
  1559.  
  1560.           Status returned
  1561.  
  1562.           The Deallocate Pages function returns one of the following status
  1563.           codes.
  1564.  
  1565.           AH = 0    The manager has deallocated the pages previously
  1566.                     allocated to the EMM handle.
  1567.  
  1568.           AH = 80h  The manager detected a malfunction in the EMM software.
  1569.  
  1570.           AH = 81h  The manager detected a malfunction in the expanded
  1571.                     memory hardware.
  1572.  
  1573.           AH = 83h  The EMM couldn't find the EMM handle your program
  1574.                     specified.
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.           Writing programs             300275-003                       2-13
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.           FUNCTION 6
  1587.                          Deallocate Pages
  1588.                          (continued)
  1589.           AH = 84h  The function code passed to the EMM is not defined.
  1590.  
  1591.           AH = 86h  The EMM detected a "save" or "restore"  page mapping
  1592.                     context error (FUNCTION 8 or 9).  There is a page
  1593.                     mapping register state in the "save area" for the EMM
  1594.                     handle specified.  Save Page Map (FUNCTION 8) placed it
  1595.                     there and it has not been removed by a subsequent
  1596.                     Restore Page Map (FUNCTION 9).
  1597.  
  1598.                     You need to restore the contents of the page mapping
  1599.                     register before you deallocate the EMM handle's
  1600.                     page(s).
  1601.  
  1602.  
  1603.  
  1604.  
  1605.  
  1606.  
  1607.  
  1608.  
  1609.  
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.           2-14                         300275-003           Writing programs
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.           FUNCTION 7
  1653.                          Get EMM Version
  1654.  
  1655.  
  1656.           The Get EMM Version function returns the version number of the
  1657.           Expanded Memory Manager software.
  1658.  
  1659.  
  1660.           Parameter passing convention
  1661.  
  1662.           AH        The AH register contains the function number for the
  1663.                     Get EMM Version function (46h).
  1664.  
  1665.  
  1666.           Example invocation in assembly language
  1667.  
  1668.           This example shows how to invoke the Get EMM Version function in
  1669.           assembly language.
  1670.  
  1671.           MOV       AH, 46h
  1672.           INT       67h
  1673.           OR        AH, AH
  1674.           JNZ       error_handler
  1675.  
  1676.  
  1677.           Registers modified
  1678.  
  1679.           The Get EMM Version function modifies the contents of the AX
  1680.           register.
  1681.  
  1682.  
  1683.           Status returned
  1684.  
  1685.           The Get EMM Version function returns one of the following status
  1686.           codes.
  1687.  
  1688.           AH = 0    The manager is present in the system and the hardware
  1689.                     is working correctly.
  1690.  
  1691.           AH = 80h  The manager detected a malfunction in the EMM software.
  1692.  
  1693.           AH = 81h  The manager detected a malfunction in the expanded
  1694.                     memory hardware.
  1695.  
  1696.           AH = 84h  The function code passed to the EMM is not defined.
  1697.  
  1698.  
  1699.           Results returned
  1700.  
  1701.           The Get EMM Version function returns these results.
  1702.  
  1703.           AL = version  The AL register contains the Expanded Memory
  1704.                     Manager's version number in BCD.  The upper four bits
  1705.                     in the AL register contain the integer digit (3.x) of
  1706.                     the version number.  The lower four bits in the AL
  1707.                     register contain the fractional digit of (x.2) version
  1708.                     number.
  1709.  
  1710.  
  1711.  
  1712.           Writing programs             300275-003                       2-15
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.           FUNCTION 7
  1719.                          Get EMM Version
  1720.  
  1721.                     The value contained in AL has no meaning if AH <> 0.
  1722.  
  1723.  
  1724.  
  1725.  
  1726.  
  1727.  
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  
  1733.  
  1734.  
  1735.  
  1736.  
  1737.  
  1738.  
  1739.  
  1740.  
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.  
  1747.  
  1748.  
  1749.  
  1750.  
  1751.  
  1752.  
  1753.  
  1754.  
  1755.  
  1756.  
  1757.  
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.           2-16                         300275-003           Writing programs
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.           FUNCTION 8
  1785.                          Save Page Map
  1786.                          (continued)
  1787.  
  1788.           The Save Page Map function saves the contents of the page mapping
  1789.           registers from all expanded memory boards.  These registers
  1790.           contain the memory mapping context of the EMM handle that was
  1791.           active when a software or hardware interrupt occurred.  (See
  1792.           FUNCTION 9 -- Restore Page Map for the "restore" operation.)
  1793.  
  1794.           If you're writing a resident program, an interrupt service
  1795.           routine, or a device driver that uses expanded memory, you must
  1796.           save the state of the mapping hardware.  You must save this
  1797.           state, because application software (using expanded memory) may
  1798.           be running when your program is invoked by a hardware interrupt,
  1799.           a software interrupt, or DOS.  The Save Page Map function
  1800.           facilitates saving the state of the mapping hardware.
  1801.  
  1802.           The Save Page Map function requires the EMM handle that was
  1803.           assigned to your resident program, interrupt service routine, or
  1804.           device driver at the time it was initialized.  (This is NOT the
  1805.           EMM handle that the application software was using when your
  1806.           software interrupted it.)
  1807.  
  1808.           Chapter 4 of this specification discusses resident software in
  1809.           general.  It explains the assignment of an EMM handle and the
  1810.           allocation of pages to resident programs.
  1811.  
  1812.  
  1813.           Parameter passing convention
  1814.  
  1815.           AH        The AH register contains the function number for the
  1816.                     Save Page Map function (47h).
  1817.  
  1818.           DX        The DX register contains the EMM handle assigned to the
  1819.                     interrupt service routine that's servicing the software
  1820.                     or hardware interrupt.  The interrupt service routine
  1821.                     needs to save the state of the page mapping hardware
  1822.                     before mapping any pages (FUNCTION 5).
  1823.  
  1824.  
  1825.           Example invocation in assembly language
  1826.  
  1827.           This example shows how to invoke the Save Page Map function in
  1828.           assembly language.
  1829.  
  1830.           MOV       DX, emm_handle
  1831.           MOV       AH, 47h
  1832.           INT       67h
  1833.           OR        AH, AH
  1834.           JNZ       error_handler
  1835.  
  1836.  
  1837.           Registers modified
  1838.  
  1839.           The Save Page Map function modifies the contents of the AX
  1840.           register.
  1841.  
  1842.  
  1843.  
  1844.           Writing programs             300275-003                       2-17
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.           FUNCTION 8
  1851.                          Save Page Map
  1852.  
  1853.           Status returned
  1854.  
  1855.           The Save Page Map function returns one of the following status
  1856.           codes.
  1857.  
  1858.           AH = 0    The manager has saved the state of the page mapping
  1859.                     hardware.
  1860.  
  1861.           AH = 80h  The manager detected a malfunction in the EMM software.
  1862.  
  1863.           AH = 81h  The manager detected a malfunction in the expanded
  1864.                     memory hardware.
  1865.  
  1866.           AH = 83h  The EMM couldn't find the EMM handle your program
  1867.                     specified.
  1868.  
  1869.           AH = 84h  The function code passed to the EMM is not defined.
  1870.  
  1871.           AH = 8Ch  There is no room in the "save" area to store the state
  1872.                     of the page mapping registers.
  1873.  
  1874.           AH = 8Dh  The "save area" already contains the page mapping
  1875.                     register state for the EMM handle your program
  1876.                     specified..
  1877.  
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.           2-18                         300275-003           Writing programs
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.           FUNCTION 9
  1917.                          Restore Page Map
  1918.                          (continued)
  1919.  
  1920.           The Restore Page Map function restores the contents of the page
  1921.           mapping registers on the expanded memory boards for a particular
  1922.           EMM handle.  This function lets your program restore the contents
  1923.           of the mapping registers which its EMM handle saved. (See
  1924.           FUNCTION 8 -- Save Page Map for the "save" operation.)
  1925.  
  1926.           If you're writing a resident program, an interrupt service
  1927.           routine, or a device driver that uses expanded memory, you must
  1928.           restore the mapping hardware to the state it was in before your
  1929.           program took over.  You must restore this state, because
  1930.           application software (using expanded memory) may be running when
  1931.           your program is invoked by a hardware interrupt, a software
  1932.           interrupt, or DOS.  The Restore Page Map function facilitates
  1933.           restoring the state of the mapping hardware.
  1934.  
  1935.           The Restore Page Map function requires the EMM handle that was
  1936.           assigned to your resident program, interrupt service routine, or
  1937.           device driver at the time it was initialized.  (This is NOT the
  1938.           EMM handle that the application software was using when your
  1939.           software interrupted it.)
  1940.  
  1941.           Chapter 4 of this specification discusses resident software in
  1942.           general.  It explains the assignment of an EMM handle and the
  1943.           allocation of pages to resident programs.
  1944.  
  1945.  
  1946.           Parameter passing convention
  1947.  
  1948.           AH        The AH register contains the function number for the
  1949.                     Restore Page Map function (48h).
  1950.  
  1951.           DX        The DX register contains the EMM handle assigned to the
  1952.                     interrupt service routine that's servicing the software
  1953.                     or hardware interrupt.  The interrupt service routine
  1954.                     needs to restore the state of the page mapping
  1955.                     hardware.
  1956.  
  1957.  
  1958.           Example invocation in assembly language
  1959.  
  1960.           This example shows how to invoke the Restore Page Map function in
  1961.           assembly language.
  1962.  
  1963.           MOV       DX, emm_handle
  1964.           MOV       AH, 48h
  1965.           INT       67h
  1966.           OR        AH, AH
  1967.           JNZ       error_handler
  1968.  
  1969.  
  1970.           Registers modified
  1971.  
  1972.           The Restore Page Map function modifies the contents of the AX
  1973.           register.
  1974.  
  1975.  
  1976.           Writing programs             300275-003                       2-19
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982.           FUNCTION 9
  1983.                          Restore Page Map
  1984.  
  1985.           Status returned
  1986.  
  1987.           The Restore Page Map function returns one of the following status
  1988.           codes.
  1989.  
  1990.           AH = 0    The manager has restored the state of the page mapping
  1991.                     registers.
  1992.  
  1993.           AH = 80h  The manager detected a malfunction in the EMM software.
  1994.  
  1995.           AH = 81h  The manager detected a malfunction in the expanded
  1996.                     memory hardware.
  1997.  
  1998.           AH = 83h  The EMM couldn't find the EMM handle your program
  1999.                     specified.
  2000.  
  2001.           AH = 84h  The function code passed to the EMM is not defined.
  2002.  
  2003.           AH = 8Eh  There is no page mapping register state in the save
  2004.                     area for the EMM handle your program specified.  Your
  2005.                     program didn't save the contents of the page mapping
  2006.                     hardware, so Restore Page Map can't restore it.
  2007.  
  2008.  
  2009.  
  2010.  
  2011.  
  2012.  
  2013.  
  2014.  
  2015.  
  2016.  
  2017.  
  2018.  
  2019.  
  2020.  
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030.  
  2031.  
  2032.  
  2033.  
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.           2-20                         300275-003           Writing programs
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.           FUNCTION 10
  2049.                          Reserved
  2050.  
  2051.  
  2052.           In previous versions of the Lotus/Intel/Microsoft Expanded Memory
  2053.           Specification, Function 10 retrieved the page mapping register
  2054.           I/O array.  This function is now reserved and new programs should
  2055.           not use it.
  2056.  
  2057.           Note:  Existing programs that use this function will still work
  2058.           correctly.
  2059.  
  2060.  
  2061.  
  2062.  
  2063.  
  2064.  
  2065.  
  2066.  
  2067.  
  2068.  
  2069.  
  2070.  
  2071.  
  2072.  
  2073.  
  2074.  
  2075.  
  2076.  
  2077.  
  2078.  
  2079.  
  2080.  
  2081.  
  2082.  
  2083.  
  2084.  
  2085.  
  2086.  
  2087.  
  2088.  
  2089.  
  2090.  
  2091.  
  2092.  
  2093.  
  2094.  
  2095.  
  2096.  
  2097.  
  2098.  
  2099.  
  2100.  
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.  
  2107.  
  2108.           Writing programs             300275-003                       2-21
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.           FUNCTION 11
  2115.                          Reserved
  2116.  
  2117.  
  2118.           In previous versions of the Lotus/Intel/Microsoft Expanded Memory
  2119.           Specification, Function 10 retrieved the logical-to-physical page
  2120.           translation array.  This function is now reserved and new
  2121.           programs should not use it.
  2122.  
  2123.           Note:  Existing programs that use this function will still work
  2124.           correctly.
  2125.  
  2126.  
  2127.  
  2128.  
  2129.  
  2130.  
  2131.  
  2132.  
  2133.  
  2134.  
  2135.  
  2136.  
  2137.  
  2138.  
  2139.  
  2140.  
  2141.  
  2142.  
  2143.  
  2144.  
  2145.  
  2146.  
  2147.  
  2148.  
  2149.  
  2150.  
  2151.  
  2152.  
  2153.  
  2154.  
  2155.  
  2156.  
  2157.  
  2158.  
  2159.  
  2160.  
  2161.  
  2162.  
  2163.  
  2164.  
  2165.  
  2166.  
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.           2-22                         300275-003           Writing programs
  2175.  
  2176.  
  2177.  
  2178.  
  2179.  
  2180.           FUNCTION 12
  2181.                          Get EMM Handle Count
  2182.  
  2183.  
  2184.           The Get EMM Handle Count function return the number of active EMM
  2185.           handles.
  2186.  
  2187.  
  2188.           Parameter passing convention
  2189.  
  2190.           AH        The AH register contains the function number for the
  2191.                     Get EMM Handle Count function (4Bh).
  2192.  
  2193.  
  2194.           Example invocation in assembly language
  2195.  
  2196.           This example shows how to invoke the Get EMM Handle Count
  2197.           function in assembly language.
  2198.  
  2199.           MOV       AH, 4Bh
  2200.           INT       67h
  2201.           OR        AH, AH
  2202.           JNZ       error_handler
  2203.           MOV       total_active_emm_handles, BX
  2204.  
  2205.  
  2206.           Registers modified
  2207.  
  2208.           The Get EMM Handle Count function modifies the contents of the AX
  2209.           and BX registers.
  2210.  
  2211.  
  2212.           Status returned
  2213.  
  2214.           The Get EMM Handle Count function returns one of the following
  2215.           status codes.
  2216.  
  2217.           AH = 0    The manager has returned the number of active EMM
  2218.                     handles.
  2219.  
  2220.           AH = 80h  The manager detected a malfunction in the EMM software.
  2221.  
  2222.           AH = 81h  The manager detected a malfunction in the expanded
  2223.                     memory hardware.
  2224.  
  2225.           AH = 83h  The EMM couldn't find the EMM handle your program
  2226.                     specified.
  2227.  
  2228.           AH = 84h  The function code passed to the EMM is not defined.
  2229.  
  2230.  
  2231.           Results returned
  2232.  
  2233.           The Get EMM Handle Count function returns these results.
  2234.  
  2235.           BX = x    The BX register contains the number of active EMM
  2236.                     handles. This number never exceeds 255.
  2237.                     
  2238.  
  2239.  
  2240.           Writing programs             300275-003                       2-23
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.           FUNCTION 13
  2247.                          Get EMM Handle Pages
  2248.                          (continued)
  2249.  
  2250.           The Get EMM Handle Pages function returns the number of pages
  2251.           allocated to a specific EMM handle.
  2252.  
  2253.  
  2254.           Parameter passing convention
  2255.  
  2256.           AH        The AH register contains the function number for the
  2257.                     Get EMM Handle Pages function (4Ch).
  2258.  
  2259.           DX        The DX register contains the EMM handle.
  2260.  
  2261.  
  2262.           Example invocation in assembly language
  2263.  
  2264.           This example shows how to invoke the Get EMM Handle Pages
  2265.           function in assembly language.
  2266.  
  2267.           MOV       DX, emm_handle
  2268.           MOV       AH, 4Ch
  2269.           INT       67h
  2270.           OR        AH, AH
  2271.           JNZ       error_handler
  2272.           MOV       num_pages_alloc_to_emm_handle, BX
  2273.  
  2274.  
  2275.           Registers modified
  2276.  
  2277.           The Get EMM Handle Pages function modifies the contents of the AX
  2278.           and BX registers.
  2279.  
  2280.  
  2281.           Status returned
  2282.  
  2283.           The Get EMM Handle Pages function returns one of the following
  2284.           status codes.
  2285.  
  2286.           AH = 0    The manager has returned the number of pages allocated
  2287.                     to the EMM handle.
  2288.  
  2289.           AH = 80h  The manager detected a malfunction in the EMM software.
  2290.  
  2291.           AH = 81h  The manager detected a malfunction in the expanded
  2292.                     memory hardware.
  2293.  
  2294.           AH = 83h  THe EMM couldn't find the EMM handle your program
  2295.                     specified.
  2296.  
  2297.           AH = 84h  The function code passed to the EMM is not defined.
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.           2-24                         300275-003           Writing programs
  2307.  
  2308.  
  2309.  
  2310.  
  2311.  
  2312.           FUNCTION 13
  2313.                          Get EMM Handle Pages
  2314.  
  2315.           Results returned
  2316.  
  2317.           The Get EMM Handle Pages function returns these results.
  2318.  
  2319.           BX <> 0   The BX register contains the number of pages allocated
  2320.                     to the EMM handle.  The number returned is never zero
  2321.                     because you can't allocate zero pages to an EMM handle.
  2322.                     This number never exceeds 512 because the EMM allows,
  2323.                     at most, 512 pages of expanded memory.
  2324.  
  2325.  
  2326.  
  2327.  
  2328.  
  2329.  
  2330.  
  2331.  
  2332.  
  2333.  
  2334.  
  2335.  
  2336.  
  2337.  
  2338.  
  2339.  
  2340.  
  2341.  
  2342.  
  2343.  
  2344.  
  2345.  
  2346.  
  2347.  
  2348.  
  2349.  
  2350.  
  2351.  
  2352.  
  2353.  
  2354.  
  2355.  
  2356.  
  2357.  
  2358.  
  2359.  
  2360.  
  2361.  
  2362.  
  2363.  
  2364.  
  2365.  
  2366.  
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.           Writing programs             300275-003                       2-25
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.           FUNCTION 14
  2379.                          Get All EMM Handle Pages
  2380.                          (continued)
  2381.  
  2382.           The Get All EMM Handle Pages function returns an array of the
  2383.           active EMM handles and the number of pages allocated to each one.
  2384.  
  2385.  
  2386.           Parameter passing convention
  2387.  
  2388.           AH        The AH register contains the function number for the
  2389.                     Get All EMM Handle Pages function (4Dh).
  2390.  
  2391.           ES:DI     The ES:DI address points to an array where a copy of
  2392.                     all active EMM handles and the number of pages
  2393.                     allocated to each is stored.  Each entry in the array
  2394.                     is composed of two words.  The first word contains the
  2395.                     active EMM handle.  The second word contains the number
  2396.                     of pages allocated to the EMM handle.
  2397.  
  2398.                     To ensure that the array space your program must supply
  2399.                     is large enough, use this formula to calculate the
  2400.                     amount of memory required:
  2401.  
  2402.                       number of bytes   =    2 * 2 * number of EMM
  2403.                       required in array           handles returned
  2404.  
  2405.                     (Each EMM handle requires 2 bytes as does each page
  2406.                     number.)  The array can never contain more than 1 K
  2407.                     bytes.
  2408.  
  2409.           Caution:  Be careful when you specify the array address in ES:DI
  2410.           so as not to cause "segment wrap" when the array is transferred.
  2411.  
  2412.  
  2413.           Example invocation in assembly language
  2414.  
  2415.           This example shows how to invoke the Return Open EMM Handle Pages
  2416.           function in assembly language.
  2417.  
  2418.           MOV       AX, dseg
  2419.           MOV       ES, AX
  2420.           MOV       DI, OFFSET handle_pages_array
  2421.           MOV       AH, 4Dh
  2422.           INT       67h
  2423.           OR        AH, AH
  2424.           JNZ       error_handler
  2425.           MOV       total_active_emm_handles, BX
  2426.  
  2427.  
  2428.           Registers modified
  2429.  
  2430.           The Get All EMM Handle Pages function modifies the contents of
  2431.           the AX and BX registers.
  2432.  
  2433.  
  2434.  
  2435.  
  2436.  
  2437.  
  2438.           2-26                         300275-003           Writing programs
  2439.  
  2440.  
  2441.  
  2442.  
  2443.  
  2444.           FUNCTION 14
  2445.                          Get All EMM Handle Pages
  2446.  
  2447.           Status returned
  2448.  
  2449.           The Get All EMM Handle Pages function returns one of the
  2450.           following status codes.
  2451.  
  2452.           AH = 0    The manager has returned the array.
  2453.  
  2454.           AH = 80h  The manager detected a malfunction in the EMM software.
  2455.  
  2456.           AH = 81h  The manager detected a malfunction in the expanded
  2457.                     memory hardware.
  2458.  
  2459.           AH = 84h  The function code passed to the EMM is not defined.
  2460.  
  2461.  
  2462.           Results returned
  2463.  
  2464.           The Return Open EMM Handle Pages function returns these results.
  2465.  
  2466.           BX = x    The BX register contains the number of active EMM
  2467.                     handles. If the number is 0 this indicates that the
  2468.                     manager is "idle."  This number never exceeds 255.
  2469.  
  2470.  
  2471.  
  2472.  
  2473.  
  2474.  
  2475.  
  2476.  
  2477.  
  2478.  
  2479.  
  2480.  
  2481.  
  2482.  
  2483.  
  2484.  
  2485.  
  2486.  
  2487.  
  2488.  
  2489.  
  2490.  
  2491.  
  2492.  
  2493.  
  2494.  
  2495.  
  2496.  
  2497.  
  2498.  
  2499.  
  2500.  
  2501.  
  2502.  
  2503.  
  2504.           Writing programs             300275-003                       2-27
  2505.  
  2506.  
  2507.  
  2508.  
  2509.  
  2510.           FUNCTION 15
  2511.                          Get/Set Page Map
  2512.                          (continued)
  2513.  
  2514.           When a task switch occurs, a multitasking operating system must
  2515.           save (and later restore) the mapping context of the active EMM
  2516.           handle.  The set of subfunctions that make up the Get/Set Page
  2517.           Map function let your operating system perform these operations.
  2518.  
  2519.           The Get/Set Page Map function is really a set of subfunctions.
  2520.           These subfunctions allow a multitasking operating system to:
  2521.  
  2522.           o  "Get" the contents of the page mapping registers from the
  2523.              expanded memory boards.
  2524.  
  2525.           o  "Set" the contents of the page mapping registers on the
  2526.              expanded memory boards.
  2527.  
  2528.           o  "Get and Set" the contents of the page mapping registers on
  2529.              the expanded memory boards.  This subfunction allows the
  2530.              operating system to perform both "get" and "set" in only one
  2531.              EMM invocation.
  2532.  
  2533.           o  "Return Size" of the page mapping hardware state array for the
  2534.              operating system.
  2535.  
  2536.           This function is described a bit differently than the rest of the
  2537.           functions in this chapter.  Since it is made up of four
  2538.           subfunctions, there are four subsections which contain the
  2539.           parameter passing convention, example invocation, status codes,
  2540.           and results returned for each service within the Get/Set Page Map
  2541.           function.
  2542.  
  2543.  
  2544.           Get the contents of the page mapping registers
  2545.  
  2546.           The Get subfunction copies the contents of the mapping registers
  2547.           from each expanded memory board to a destination array.  The
  2548.           operating system must point to the destination array.
  2549.  
  2550.           This subfunction doesn't require an EMM handle.
  2551.  
  2552.  
  2553.           Parameter passing convention
  2554.  
  2555.           AH        The AH register contains the function number for the
  2556.                     Get/Set Page Map function (4Eh).
  2557.  
  2558.           AL = 0    When the AL register equals 0, the invocation requests
  2559.                     the Get subfunction.  It copies the map registers to an
  2560.                     array pointed to by the ES:DI address.
  2561.  
  2562.           ES:DI     The ES:DI address points to the destination array
  2563.                     address in SEGMENT:OFFSET format.  This address is
  2564.                     required only for the Get or Get and Set services.
  2565.  
  2566.           Caution:  Be careful when you specify the array address in ES:DI
  2567.           so as not to cause "segment wrap" when the array is transferred.
  2568.  
  2569.  
  2570.           2-28                         300275-003           Writing programs
  2571.  
  2572.  
  2573.  
  2574.  
  2575.  
  2576.           FUNCTION 15
  2577.                          Get/Set Page Map
  2578.  
  2579.           Example invocation in assembly language
  2580.  
  2581.           This example shows how to invoke the Get subfunction in assembly
  2582.           language.
  2583.  
  2584.           MOV       AX, dseg
  2585.           MOV       ES, AX
  2586.           MOV       DI, OFFSET destination_page_map_array
  2587.           MOV       AH, 4Eh
  2588.           MOV       AL, 0
  2589.           INT       67h
  2590.           OR        AH, AH
  2591.           JNZ       error_handler
  2592.  
  2593.  
  2594.           Registers modified
  2595.  
  2596.           The Get subfunction modifies the contents of the AX register.
  2597.  
  2598.  
  2599.           Status returned
  2600.  
  2601.           The Get subfunction returns one of the following status codes.
  2602.  
  2603.           AH = 0    The manager has returned the array.
  2604.  
  2605.           AH = 80h  The manager detected a malfunction in the EMM software.
  2606.  
  2607.           AH = 81h  The manager detected a malfunction in the expanded
  2608.                     memory hardware.
  2609.  
  2610.           AH = 84h  The function code passed to the EMM is not defined.
  2611.  
  2612.           AH = 8Fh  The subfunction parameter isn't equal to a Get request.
  2613.  
  2614.  
  2615.           Results returned
  2616.  
  2617.           The Get subfunction returns these results.
  2618.  
  2619.           ES:DI = addr The ES:DI address points to the memory area where
  2620.                     the operating system has stored the state of all the
  2621.                     mapping registers on all boards in the system.  This
  2622.                     memory area also contains any additional information
  2623.                     necessary to restore the boards to their original state
  2624.                     when the program invokes a Set subfunction.
  2625.  
  2626.  
  2627.           Set the contents of the page mapping registers
  2628.  
  2629.           The Set subfunction copies the contents of a source array into
  2630.           the mapping registers on each expanded memory board in the
  2631.           system.  The operating system must point to the source array.
  2632.  
  2633.           This subfunction doesn't require an EMM handle.
  2634.  
  2635.  
  2636.           Writing programs             300275-003                       2-29
  2637.  
  2638.  
  2639.  
  2640.  
  2641.  
  2642.           FUNCTION 15
  2643.                          Get/Set Page Map
  2644.                          (continued)
  2645.  
  2646.  
  2647.           Parameter passing convention
  2648.  
  2649.           AH        The AH register contains the function number for the
  2650.                     Get/Set Page Map function (4Eh).
  2651.  
  2652.           AL = 1    When the AL register equals 1, the invocation requests
  2653.                     the Set subfunction.  It copies the contents of the
  2654.                     array pointed to by the DS:SI address to the map
  2655.                     registers.
  2656.  
  2657.           DS:SI     The DS:SI address points to the source array address in
  2658.                     SEGMENT:OFFSET format.  The operating system must point
  2659.                     to an array which contains the mapping register state.
  2660.                     This address is required only for the Set or Get and
  2661.                     Set services.
  2662.  
  2663.           Caution:  Be careful when you specify the array address in DS:SI
  2664.           so as not to cause "segment wrap" when the array is transferred.
  2665.  
  2666.  
  2667.           Example invocation in assembly language
  2668.  
  2669.           This example shows how to invoke the Set subfunction in assembly
  2670.           language.
  2671.  
  2672.           MOV       AX, dseg
  2673.           MOV       DS, AX                   
  2674.           MOV       SI, OFFSET source_page_map_array
  2675.           MOV       AH, 4Eh
  2676.           MOV       AL, 1
  2677.           INT       67h
  2678.           OR        AH, AH
  2679.           JNZ       error_handler
  2680.  
  2681.  
  2682.           Registers modified
  2683.  
  2684.           The Set subfunction modifies the contents of the AX register.
  2685.  
  2686.  
  2687.           Status returned
  2688.  
  2689.           The Set subfunction returns one of the following status codes.
  2690.  
  2691.           AH = 0    The manager has passed the array.
  2692.  
  2693.           AH = 80h  The manager detected a malfunction in the EMM software.
  2694.  
  2695.           AH = 81h  The manager detected a malfunction in the expanded
  2696.                     memory hardware.
  2697.  
  2698.           AH = 84h  The function code passed to the EMM is not defined.
  2699.  
  2700.  
  2701.  
  2702.           2-30                         300275-003           Writing programs
  2703.  
  2704.  
  2705.  
  2706.  
  2707.  
  2708.           FUNCTION 15
  2709.                          Get/Set Page Map
  2710.                          (continued)
  2711.           AH = 8Fh  The subfunction parameter isn't equal to a Set request
  2712.                     or the length of the array passed during the Set
  2713.                     request doesn't match the number of mapping registers
  2714.                     in the system.
  2715.  
  2716.  
  2717.  
  2718.  
  2719.  
  2720.  
  2721.  
  2722.  
  2723.  
  2724.  
  2725.  
  2726.  
  2727.  
  2728.  
  2729.  
  2730.  
  2731.  
  2732.  
  2733.  
  2734.  
  2735.  
  2736.  
  2737.  
  2738.  
  2739.  
  2740.  
  2741.  
  2742.  
  2743.  
  2744.  
  2745.  
  2746.  
  2747.  
  2748.  
  2749.  
  2750.  
  2751.  
  2752.  
  2753.  
  2754.  
  2755.  
  2756.  
  2757.  
  2758.  
  2759.  
  2760.  
  2761.  
  2762.  
  2763.  
  2764.  
  2765.  
  2766.  
  2767.  
  2768.           Writing programs             300275-003                       2-31
  2769.  
  2770.  
  2771.  
  2772.  
  2773.  
  2774.           FUNCTION 15
  2775.                          Get/Set Page Map
  2776.                          (continued)
  2777.           Results returned
  2778.  
  2779.           The Set subfunction doesn't return any results.  If the operating
  2780.           system used the Get subfunction correctly, the Set service should
  2781.           restore the expanded memory boards to their original state.  (The
  2782.           Get subfunction, described previously in this chapter, saves the
  2783.           contents of the mapping register from each expanded memory
  2784.           board.)
  2785.  
  2786.  
  2787.           Get and set the contents of the page mapping registers
  2788.  
  2789.           The Get and Set subfunction first copies the contents of the
  2790.           mapping registers from each expanded memory board in the system
  2791.           into a destination array.  (The operating system must point to
  2792.           the destination array.)  Then, the subfunction copies the
  2793.           contents of a source array into the mapping registers on each of
  2794.           the expanded memory boards.  (The operating system must point to
  2795.           the source array.)
  2796.  
  2797.           This subfunction doesn't require an EMM handle.
  2798.  
  2799.  
  2800.           Parameter passing convention
  2801.  
  2802.           AH        The AH register contains the function number for the
  2803.                     Get/Set Page Map function (4Eh).
  2804.  
  2805.           AL = 2    When the AL register equals 2, the invocation requests
  2806.                     the Get and Set subfunction.  This subfunction first
  2807.                     copies the map registers to an array pointed to by the
  2808.                     ES:DI address.  And then, it copies the contents of the
  2809.                     array pointed to by the DS:SI address to the map
  2810.                     registers.
  2811.  
  2812.           ES:DI     The ES:DI address points to the destination array
  2813.                     address in SEGMENT:OFFSET format.  This address is
  2814.                     required only for the Get or Get and Set services.
  2815.  
  2816.           DS:SI     The DS:SI address points to the source array address in
  2817.                     SEGMENT:OFFSET format.  The operating system must point
  2818.                     to an array which contains the mapping register state.
  2819.                     This address is required only for the Set or Get and
  2820.                     Set services.
  2821.  
  2822.           Caution:  Be careful when you specify the array address in ES:DI
  2823.           and DS:SI so as not to cause "segment wrap" when the array is
  2824.           transferred.
  2825.  
  2826.  
  2827.  
  2828.  
  2829.  
  2830.  
  2831.  
  2832.  
  2833.  
  2834.           2-32                         300275-003           Writing programs
  2835.  
  2836.  
  2837.  
  2838.  
  2839.  
  2840.           FUNCTION 15
  2841.                          Get/Set Page Map
  2842.                          (continued)
  2843.           Example invocation in assembly language
  2844.  
  2845.           This example shows how to invoke the Get and Set subfunction in
  2846.           assembly language.
  2847.  
  2848.           MOV       AX, dseg
  2849.           MOV       ES, AX                   
  2850.           MOV       DI, OFFSET destination_page_map_array
  2851.           MOV       DS, AX                   
  2852.           MOV       SI, OFFSET source_page_map_array
  2853.           MOV       AH, 4Eh
  2854.           MOV       AL, 2
  2855.           INT       67h
  2856.           OR        AH, AH
  2857.           JNZ       error_handler
  2858.  
  2859.  
  2860.           Registers modified
  2861.  
  2862.           The Get and Set subfunction modifies the contents of the AX
  2863.           register.
  2864.  
  2865.  
  2866.           Status returned
  2867.  
  2868.           The Get and Set subfunction returns one of the following status
  2869.           codes.
  2870.  
  2871.           AH = 0    The manager has returned and passed both arrays
  2872.  
  2873.           AH = 80h  The manager detected a malfunction in the EMM software.
  2874.  
  2875.           AH = 81h  The manager detected a malfunction in the expanded
  2876.                     memory hardware.
  2877.  
  2878.           AH = 84h  The function code passed to the EMM is not defined.
  2879.  
  2880.           AH = 8Fh  The subfunction parameter isn't equal to a Get and Set
  2881.                     request.
  2882.  
  2883.  
  2884.           Results returned
  2885.  
  2886.           The Get and Set subfunction returns these results.
  2887.  
  2888.           ES:DI = addr The ES:DI address points to the memory area where
  2889.                     the operating system stores the state of all the
  2890.                     mapping registers on all boards in the system. (This
  2891.                     happens during a Get subfunction.)  This memory area
  2892.                     also contains any additional information necessary to
  2893.                     restore the boards to their original state when the
  2894.                     program invokes a Set subfunction.
  2895.  
  2896.  
  2897.  
  2898.  
  2899.  
  2900.           Writing programs             300275-003                       2-33
  2901.  
  2902.  
  2903.  
  2904.  
  2905.  
  2906.           FUNCTION 15
  2907.                          Get/Set Page Map
  2908.                          (continued)
  2909.           Return the size of the mapping context array for the
  2910.           operating system
  2911.  
  2912.           The Return Size subfunction determines the storage requirements
  2913.           for the array passed by the other three functions prior to
  2914.           invoking them.
  2915.  
  2916.           This subfunction doesn't require an EMM handle.
  2917.  
  2918.  
  2919.  
  2920.  
  2921.  
  2922.  
  2923.  
  2924.  
  2925.  
  2926.  
  2927.  
  2928.  
  2929.  
  2930.  
  2931.  
  2932.  
  2933.  
  2934.  
  2935.  
  2936.  
  2937.  
  2938.  
  2939.  
  2940.  
  2941.  
  2942.  
  2943.  
  2944.  
  2945.  
  2946.  
  2947.  
  2948.  
  2949.  
  2950.  
  2951.  
  2952.  
  2953.  
  2954.  
  2955.  
  2956.  
  2957.  
  2958.  
  2959.  
  2960.  
  2961.  
  2962.  
  2963.  
  2964.  
  2965.  
  2966.           2-34                         300275-003           Writing programs
  2967.  
  2968.  
  2969.  
  2970.  
  2971.  
  2972.           FUNCTION 15
  2973.                          Get/Set Page Map
  2974.                          (continued)
  2975.           Parameter passing convention
  2976.  
  2977.           AH        The AH register contains the function number for the
  2978.                     Get/Set Page Map function (4Eh).
  2979.  
  2980.           AL = 3    When the AL register equals 3, the invocation requests
  2981.                     the Return Size subfunction.  This subfunction returns
  2982.                     the size (in bytes) of the array that the Get, Set, or
  2983.                     Get and Set subfunctions transfer to or from the
  2984.                     operating system.
  2985.  
  2986.  
  2987.           Example invocation in assembly language
  2988.  
  2989.           This example shows how to invoke the Return Size subfunction in
  2990.           assembly language.
  2991.  
  2992.           MOV       AH, 4Eh
  2993.           MOV       AL, 3
  2994.           INT       67h
  2995.           OR        AH, AH
  2996.           JNZ       error_handler
  2997.           MOV       size_of_array, AL
  2998.  
  2999.  
  3000.           Registers modified
  3001.  
  3002.           The Return Size subfunction modifies the contents of the AX
  3003.           register.
  3004.  
  3005.  
  3006.           Status returned
  3007.  
  3008.           The Return Size subfunction returns one of the following status
  3009.           codes.
  3010.  
  3011.           AH = 0    The manager has returned the array size.
  3012.  
  3013.           AH = 80h  The manager detected a malfunction in the EMM software.
  3014.  
  3015.           AH = 81h  The manager detected a malfunction in the expanded
  3016.                     memory hardware.
  3017.  
  3018.           AH = 84h  The function code passed to the EMM is not defined.
  3019.  
  3020.           AH = 8Fh  The subfunction parameter isn't equal to a Return Size
  3021.                     request.
  3022.  
  3023.  
  3024.           Results returned
  3025.  
  3026.           The Return Size subfunction returns these results.
  3027.  
  3028.  
  3029.  
  3030.  
  3031.  
  3032.           Writing programs             300275-003                       2-35
  3033.  
  3034.  
  3035.  
  3036.  
  3037.  
  3038.           FUNCTION 15
  3039.                          Get/Set Page Map
  3040.                          (continued)
  3041.           AL = n    The contents of the AL register equals the number of
  3042.                     bytes transferred to the memory area supplied by an
  3043.                     operating system whenever a program requests the Get,
  3044.                     Set, or Get and Set subfunction.
  3045.  
  3046.  
  3047.  
  3048.  
  3049.  
  3050.  
  3051.  
  3052.  
  3053.  
  3054.  
  3055.  
  3056.  
  3057.  
  3058.  
  3059.  
  3060.  
  3061.  
  3062.  
  3063.  
  3064.  
  3065.  
  3066.  
  3067.  
  3068.  
  3069.  
  3070.  
  3071.  
  3072.  
  3073.  
  3074.  
  3075.  
  3076.  
  3077.  
  3078.  
  3079.  
  3080.  
  3081.  
  3082.  
  3083.  
  3084.  
  3085.  
  3086.  
  3087.  
  3088.  
  3089.  
  3090.  
  3091.  
  3092.  
  3093.  
  3094.  
  3095.  
  3096.  
  3097.  
  3098.           2-36                         300275-003           Writing programs
  3099.  
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.  
  3107.           SUMMARY OF STATUS CODES -- ALL EMM FUNCTIONS
  3108.  
  3109.           Table 2-1 lists the possible status codes that the EMM functions
  3110.           can return.  This table is for quick reference; the individual
  3111.           EMM functions list the status codes they return.
  3112.  
  3113.                          Table 2-1.  Summary of status codes
  3114.             
  3115.           
  3116.             Code              Definition
  3117.                                         
  3118.  
  3119.                     
  3120.  
  3121.             AH = 0            The manager is present in the system and the
  3122.                               hardware is working correctly.
  3123.                                         
  3124.  
  3125.           
  3126.             AH = 80h          The manager detected a malfunction in the EMM
  3127.                               software.
  3128.                                         
  3129.  
  3130.           
  3131.             AH = 81h          The manager detected a malfunction in the
  3132.           expanded
  3133.                               memory hardware.
  3134.                                         
  3135.  
  3136.           
  3137.             AH = 83h          The EMM couldn't find the EMM handle your
  3138.           program
  3139.                               specified.
  3140.                                         
  3141.  
  3142.           
  3143.             AH = 84h          The function code passed to the EMM is not
  3144.                               defined.
  3145.                                         
  3146.  
  3147.           
  3148.             AH = 85h          All EMM handles are being used.
  3149.                                         
  3150.  
  3151.           
  3152.             AH = 86h          The EMM detected a "save" or "restore"  page
  3153.                               mapping context error.
  3154.                                         
  3155.  
  3156.           
  3157.             AH = 87h          There aren't enough expanded memory pages to
  3158.                               satisfy your program's request.
  3159.                                         
  3160.  
  3161.           
  3162.  
  3163.  
  3164.           Writing programs             300275-003                       2-37
  3165.  
  3166.  
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172.  
  3173.             AH = 88h          There aren't enough unallocated pages to
  3174.           satisfy
  3175.                               your program's request.
  3176.                                         
  3177.  
  3178.           
  3179.             AH = 89h          Can't allocate zero (0) pages.
  3180.                                         
  3181.  
  3182.  
  3183.  
  3184.  
  3185.  
  3186.  
  3187.  
  3188.  
  3189.  
  3190.  
  3191.  
  3192.  
  3193.  
  3194.  
  3195.  
  3196.  
  3197.  
  3198.  
  3199.  
  3200.  
  3201.  
  3202.  
  3203.  
  3204.  
  3205.  
  3206.  
  3207.  
  3208.  
  3209.  
  3210.  
  3211.  
  3212.  
  3213.  
  3214.  
  3215.  
  3216.  
  3217.  
  3218.  
  3219.  
  3220.  
  3221.  
  3222.  
  3223.  
  3224.  
  3225.  
  3226.  
  3227.  
  3228.  
  3229.  
  3230.           2-38                         300275-003           Writing programs
  3231.  
  3232.  
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.  
  3239.                    Table 2-1.  Summary of status codes (continued)
  3240.             
  3241.           
  3242.             Code              Definition
  3243.                                         
  3244.  
  3245.           
  3246.             AH = 8Ah          The logical page is out of the range of
  3247.           logical
  3248.                               pages which are allocated to the EMM handle.
  3249.                                         
  3250.  
  3251.           
  3252.             AH = 8Bh          The physical page to which the logical page
  3253.           is
  3254.                               mapped is out of the range of physical pages.
  3255.                                         
  3256.  
  3257.           
  3258.             AH = 8Ch          The page mapping hardware state save area is
  3259.           full.
  3260.                                         
  3261.  
  3262.           
  3263.             AH = 8Dh          The page mapping hardware state save area
  3264.           already has
  3265.                               a state associated with the EMM handle.
  3266.                                         
  3267.  
  3268.           
  3269.             AH = 8Eh          The page mapping hardware state save area
  3270.                               doesn't have a state associated with the EMM
  3271.                               handle.
  3272.                                         
  3273.  
  3274.           
  3275.             AH = 8Fh          The subfunction parameter passed to the
  3276.           function
  3277.                               isn't defined.
  3278.                                         
  3279.  
  3280.           
  3281.  
  3282.  
  3283.  
  3284.  
  3285.  
  3286.  
  3287.  
  3288.  
  3289.  
  3290.  
  3291.  
  3292.  
  3293.  
  3294.  
  3295.  
  3296.           Writing programs             300275-003                       2-39
  3297.  
  3298.  
  3299.  
  3300.  
  3301.  
  3302.  
  3303.  
  3304.  
  3305.  
  3306.  
  3307.  
  3308.  
  3309.  
  3310.  
  3311.  
  3312.  
  3313.  
  3314.  
  3315.  
  3316.  
  3317.  
  3318.  
  3319.  
  3320.  
  3321.  
  3322.  
  3323.  
  3324.  
  3325.  
  3326.  
  3327.  
  3328.  
  3329.  
  3330.  
  3331.  
  3332.  
  3333.  
  3334.  
  3335.  
  3336.  
  3337.  
  3338.  
  3339.  
  3340.  
  3341.  
  3342.  
  3343.  
  3344.  
  3345.  
  3346.  
  3347.  
  3348.  
  3349.  
  3350.  
  3351.  
  3352.  
  3353.  
  3354.  
  3355.  
  3356.  
  3357.  
  3358.  
  3359.  
  3360.  
  3361.  
  3362.  
  3363.  
  3364.  
  3365.  
  3366.  
  3367.  
  3368.  
  3369.  
  3370.  
  3371.           CHAPTER 3.  TESTING FOR THE PRESENCE OF THE EXPANDED
  3372.                               MEMORY MANAGER
  3373.  
  3374.           Before an application program can take advantage of the Expanded
  3375.           Memory Manager (EMM), it must determine whether the manager has
  3376.           been loaded by DOS.  This chapter describes two methods your
  3377.           program can use to test for the presence of the EMM and how to
  3378.           choose the correct one for your situation.
  3379.  
  3380.           The first method uses the DOS "open handle" technique; the second
  3381.           method uses the DOS "get interrupt vector" technique.
  3382.  
  3383.  
  3384.           Which method should my program use?
  3385.  
  3386.           The majority of application programs can use either the "open
  3387.           file" or the "get interrupt vector" method.  However, if your
  3388.           program is a device driver or if it interrupts DOS during file
  3389.           system operations, you must use only the "get interrupt vector"
  3390.           method.
  3391.  
  3392.           Device drivers execute from within DOS and can't access the DOS
  3393.           file system; programs that interrupt DOS during file system
  3394.           operations have a similar restriction.  During their interrupt
  3395.           processing procedures, they can't access the DOS file system
  3396.           because another program may be using the system.  Since the "get
  3397.           interrupt vector" method doesn't require the DOS file system, you
  3398.           must use it for these types of programs.
  3399.  
  3400.  
  3401.           The "open handle" technique
  3402.  
  3403.           Most application programs can use the DOS "open handle" technique
  3404.           to test for the presence of the EMM.  This section describes how
  3405.           to use the technique and gives an example.
  3406.  
  3407.           Caution:  Don't use this technique if your program is a device
  3408.           driver or if it interrupts DOS during file system operations.
  3409.           Use the "get interrupt vector" technique described later in this
  3410.           chapter.
  3411.  
  3412.  
  3413.           Using the "open handle" technique
  3414.  
  3415.           This section describes how to use the DOS "open handle" technique
  3416.           to test for the presence of the EMM.  Follow these steps in
  3417.           order:
  3418.  
  3419.           1.   Issue an "open handle" command (DOS function 3Dh) in "read
  3420.                only" access mode (register AL = 0).  This function requires
  3421.                your program to point to an ASCII string which contains the
  3422.                path name of the file or device in which you're interested
  3423.                (register set DS:DX contains the pointer).  In this case the
  3424.                file is actually the name of the EMM.
  3425.  
  3426.  
  3427.  
  3428.           3-2                         3000275-003Testing for the presence of the EMM
  3429.  
  3430.  
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436.  
  3437.                You should format the ASCII string as follows:
  3438.  
  3439.                     ASCII_device_name   DB   "EMMXXXX0", 0
  3440.  
  3441.                where the ASCII codes for the capital letters EMMXXXX0 are
  3442.                terminated by a byte containing a value of zero.
  3443.  
  3444.           2.   If DOS returns no error status code, skip Steps 3 and 4 and
  3445.                go to Step 5.  If DOS returns a "Too many open files" error
  3446.                status code, go to Step 3.  If DOS returns a "File/Path not
  3447.                found" error status code, skip Step 3 and go to Step 4.
  3448.  
  3449.           3.   If DOS returns a "Too many open files" (not enough handles),
  3450.                status code, your program should invoke the "open file"
  3451.                command before it opens any other files.  This will
  3452.                guarantee that at least one file handle will be available to
  3453.                perform the function without causing this error.
  3454.  
  3455.                After the program performs the "open file" command, it
  3456.                should perform the test described in Step 6 and close the
  3457.                "file handle" (DOS function 3Eh).  Don't keep the manager
  3458.                "open" after this status test is performed since "manager"
  3459.                functions are not available thru DOS.  Go to Step 6.
  3460.  
  3461.           4.   If DOS returns a "File/Path not found" the EMM is not
  3462.                installed.  If your application requires its presence the
  3463.                user will have to reboot the system with a disk containing
  3464.                the EMM and the appropriate CONFIG.SYS file before
  3465.                proceeding.
  3466.  
  3467.           5.   If DOS doesn't return an error status code you can assume
  3468.                that either a device with the name EMMXXXX0 is resident in
  3469.                the system, or a file with this name is on disk in the
  3470.                current disk drive.  Go to Step 6.
  3471.  
  3472.           6.   Issue an "I/O Control for Devices" command (DOS function
  3473.                44h) with a "get device information" command (register AL =
  3474.                0h).  DOS function 44h determines whether EMMXXXX0 is a
  3475.                device or a file.  It also requires a pointer to a buffer
  3476.                (register set DS:DX).  The EMM does not use the buffer for
  3477.                anything and will not pass information in it.
  3478.  
  3479.                You can set the number of bytes this function requires to
  3480.                perform read/write operations to zero (register CX) since no
  3481.                data is passed back in the buffer.  You must use the file
  3482.                handle (register BX) which you obtained in Step 1 to access
  3483.                the "EMM" device.
  3484.  
  3485.                This function returns the "device information" in a word
  3486.                (register DX).  Go to step 7.
  3487.  
  3488.  
  3489.  
  3490.  
  3491.  
  3492.  
  3493.  
  3494.           Testing for the presence of the EMM300275-003                  3-3
  3495.  
  3496.  
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502.  
  3503.           7.   If DOS returns any error status code, you should assume that
  3504.                the EMM device driver is not installed.  If your application
  3505.                requires its presence the user will have to reboot the
  3506.                system with a disk containing the EMM and the appropriate
  3507.                CONFIG.SYS file before proceeding.
  3508.  
  3509.           8.   If DOS didn't return an error status, test the contents of
  3510.                bit 7 (counting from 0) of the "device information" word
  3511.                (register DX) the function returned.  Go to Step 9.
  3512.  
  3513.           9.   If bit 7 of the "device information" word contains a zero,
  3514.                then EMMXXXX0 is a file and the EMM device driver is not
  3515.                present.  If your application requires its presence, the
  3516.                user will have to reboot the system with a disk containing
  3517.                the EMM and the appropriate CONFIG.SYS file before
  3518.                proceeding.
  3519.  
  3520.                If bit 7 contains a one, then EMMXXXX0 is a device. Go to
  3521.                Step 10.
  3522.  
  3523.           10.  Issue an "I/O Control for Devices" command (DOS function
  3524.                44h) with a "get output status" command (register AL = 7h).
  3525.                This function requires a pointer to a buffer (register set
  3526.                DS:DX).  The EMM does not use the buffer for anything and
  3527.                will not pass information in it.
  3528.  
  3529.                You can set the number of bytes (register CX) this function
  3530.                requires to perform read/write operations to zero since no
  3531.                data is passed back in the buffer.  You must use the file
  3532.                handle you obtained in Step 1 to access the "EMM" device
  3533.                (register BX).  Go to Step 11.
  3534.  
  3535.           11.  If the expanded memory device driver is "ready," the EMM
  3536.                passes a status value of "0FFh" in register AL.  The status
  3537.                value is "00h" if the device driver is "not ready."
  3538.  
  3539.                If the the EMM device driver is "not ready" and your
  3540.                application requires its presence, the user will have to
  3541.                reboot the system with a disk containing the EMM and the
  3542.                appropriate CONFIG.SYS file before proceeding.
  3543.  
  3544.                If the EMM device driver is "ready", go to Step 12.
  3545.  
  3546.           12.  Issue a "Close File Handle" command (DOS function 3Eh) to
  3547.                close the expanded memory device driver.  You must use the
  3548.                file handle you obtained in Step 1 to close the "EMM" device
  3549.                (register BX).
  3550.  
  3551.  
  3552.  
  3553.  
  3554.  
  3555.  
  3556.  
  3557.  
  3558.  
  3559.  
  3560.           3-4                         3000275-003Testing for the presence of the EMM
  3561.  
  3562.  
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568.  
  3569.           An example of the "open handle" technique
  3570.  
  3571.           The following procedure is an example of the "open handle"
  3572.           technique outlined in the previous section.
  3573.  
  3574.           ;;
  3575.             ;______________________________________________________________      
  3576.             ______________________________________________________________;
  3577.             ;_____The following procedure tests for the presence of the EMM      
  3578.             ______________________________________________________________;
  3579.             ;___in the system.  It returns the CARRY FLAG SET if the EMM is      
  3580.             ______________________________________________________________;
  3581.             ;___present.  If the EMM is not present, this procedure returns      
  3582.             ______________________________________________________________;
  3583.             ;_________________________________________the CARRY FLAG CLEAR.      
  3584.             ______________________________________________________________;
  3585.           ;;
  3586.           
  3587.  
  3588.           first_test_for_EMM PROC            NEAR
  3589.             
  3590.             ___________________________________________________________PUSH     D
  3591.             S______________________________________________________________     
  3592.             ___________________________________________________________PUSH     C
  3593.             S
  3594.             ____________________________________________________________POP     D
  3595.             S
  3596.             ____________________________________________________________MOV     A
  3597.             H, 3Dh__________________________________________; issue "device
  3598.             ____________________________________________________________LEA     D
  3599.             X, ASCII_device_name___________________________; open" in "read
  3600.             ____________________________________________________________MOV     A
  3601.             L, 0_______________________________________________; only" mode
  3602.             ____________________________________________________________INT     2
  3603.             1h
  3604.             _____________________________________________________________JC     f
  3605.             irst_test_for_EMM_error_exit___________________; test for error
  3606.             _______________________________________________________________      
  3607.             ; during "device
  3608.             _______________________________________________________________      
  3609.             ; open"
  3610.             
  3611.             ____________________________________________________________MOV     B
  3612.             X, AX___________________________________________; get the "file
  3613.             _______________________________________________________________      
  3614.             ; handle" returned
  3615.             _______________________________________________________________      
  3616.             ; by DOS
  3617.             
  3618.             ____________________________________________________________MOV     A
  3619.             X, 44h__________________________________________; issue "IOCTL"
  3620.             ____________________________________________________________MOV     A
  3621.             L, 00h______________________________________; "get device info"
  3622.             ____________________________________________________________INT     2
  3623.             1h
  3624.  
  3625.  
  3626.           Testing for the presence of the EMM300275-003                  3-5
  3627.  
  3628.  
  3629.  
  3630.  
  3631.  
  3632.  
  3633.  
  3634.  
  3635.             _____________________________________________________________JC     f
  3636.             irst_test_for_EMM_err_exit_____________________; test for error
  3637.             _______________________________________________________________      
  3638.             ; during "get device
  3639.             _______________________________________________________________      
  3640.             ; info"
  3641.             
  3642.             ___________________________________________________________TEST     D
  3643.             X, 0080h_________________________________; test to determine if
  3644.             _____________________________________________________________JZ     f
  3645.             irst_test_for_EMM_err_exit__________________; ASCII_device_name
  3646.             _______________________________________________________________      
  3647.             ; is a device or a
  3648.             _______________________________________________________________      
  3649.             ; file
  3650.             
  3651.             ____________________________________________________________MOV     A
  3652.             H, 44h__________________________________________; issue "IOCTL"
  3653.             ____________________________________________________________LEA     D
  3654.             X, dummy_buffer___________________________________; "get output
  3655.             ____________________________________________________________MOV     C
  3656.             X, 0__________________________________________________; status"
  3657.             ____________________________________________________________MOV     A
  3658.             L, 07h
  3659.             ____________________________________________________________INT     2
  3660.             1h
  3661.             _____________________________________________________________JC     f
  3662.             irst_test_for_EMM_error_exit___________________; test for error
  3663.             _______________________________________________________________      
  3664.             ; during "IOCTL"
  3665.             
  3666.             ___________________________________________________________PUSH     A
  3667.             X________________________________________________; save "IOCTL"
  3668.             _______________________________________________________________      
  3669.             ; status
  3670.             
  3671.  
  3672.  
  3673.  
  3674.  
  3675.  
  3676.  
  3677.  
  3678.  
  3679.  
  3680.  
  3681.  
  3682.  
  3683.  
  3684.  
  3685.  
  3686.  
  3687.  
  3688.  
  3689.  
  3690.  
  3691.  
  3692.           3-6                         3000275-003Testing for the presence of the EMM
  3693.  
  3694.  
  3695.  
  3696.  
  3697.  
  3698.  
  3699.  
  3700.  
  3701.             ____________________________________________________________MOV     A
  3702.             H, 3Eh___________________________________________; issue "close
  3703.             ____________________________________________________________INT     2
  3704.             1h_______________________________________________; file handle"
  3705.              ______________________________________________________________
  3706.             ____________________________________________________________POP     A
  3707.             X_____________________________________________; restore "IOCTL"
  3708.             _______________________________________________________________      
  3709.             ; status
  3710.             
  3711.             ____________________________________________________________CMP     A
  3712.             L, 0FFh______________________________________; test for "device
  3713.             ____________________________________________________________JNE     f
  3714.             irst_test_for_EMM_error_exit____________________; ready" status
  3715.             _______________________________________________________________      
  3716.             ; returned by the
  3717.             _______________________________________________________________      
  3718.             ; driver
  3719.             first_test_for_EMM_exit:
  3720.             
  3721.             ____________________________________________________________POP     D
  3722.             S______________________________________________; EMM is present
  3723.             ____________________________________________________________STC      
  3724.             ; in the system
  3725.             ____________________________________________________________RET
  3726.             
  3727.             first_test_for_EMM_error_exit:
  3728.             
  3729.             ____________________________________________________________POP     D
  3730.             S__________________________________________; EMM is NOT present
  3731.             ____________________________________________________________CLC      
  3732.             ; in the system
  3733.             ____________________________________________________________RET
  3734.             
  3735.           ASCII_device_name: DB              "EMMXXXX0", 0
  3736.             
  3737.           dummy_buffer DB                    0
  3738.           
  3739.           first_test_for_EMM ENDP
  3740.           
  3741.           
  3742.  
  3743.  
  3744.  
  3745.  
  3746.  
  3747.  
  3748.  
  3749.  
  3750.  
  3751.  
  3752.  
  3753.  
  3754.  
  3755.  
  3756.  
  3757.  
  3758.           Testing for the presence of the EMM300275-003                  3-7
  3759.  
  3760.  
  3761.  
  3762.  
  3763.  
  3764.  
  3765.  
  3766.  
  3767.           The "get interrupt vector" technique
  3768.  
  3769.           Any type of program can use the DOS "get interrupt vector"
  3770.           technique to test for the presence of the EMM.  This section
  3771.           describes how to use the technique and gives an example.
  3772.  
  3773.           Caution:  Be sure to use this technique (and not the "open handle
  3774.           technique) if your program is a device driver or if it interrupts
  3775.           DOS during file system operations.
  3776.  
  3777.  
  3778.           Using the "get interrupt vector" technique
  3779.  
  3780.           This section describes how to use the DOS "get interrupt vector"
  3781.           technique to test for the presence of the EMM.  Follow these
  3782.           steps in order:
  3783.  
  3784.           1.   Issue a "get vector" command (DOS function 35h) to obtain
  3785.                the contents of interrupt vector array entry number 67h
  3786.                (addresses 0000:019C thru 0000:019F).
  3787.  
  3788.                The EMM uses this interrupt vector to perform all manager
  3789.                functions.  The OFFSET portion of this interrupt service
  3790.                routine address is stored in the word located at address
  3791.                0000:019Ch; the SEGMENT portion is stored in the word
  3792.                located at address 0000:019Eh.
  3793.  
  3794.           2.   Compare the "device name field" with the contents of the
  3795.                ASCII string which starts at the address specified by the
  3796.                segment portion of the contents of interrupt vector address
  3797.                67h and a fixed offset of 000Ah.  If DOS loaded the Expanded
  3798.                Memory Manager at boot time this name field will have the
  3799.                name of the device in it.
  3800.  
  3801.                Since the Expanded Memory Manager is implemented as a
  3802.                character device driver, its program origin is 0000h.
  3803.                Device drivers are required to have a "device header"
  3804.                located at the program origin.  Within the "device header"
  3805.                is an 8 byte "device name field."  For a character mode
  3806.                device driver this name field is always located at offset
  3807.                000Ah within the device header.  The device name field
  3808.                contains the name of the device which DOS uses when the
  3809.                device is referenced by DOS.
  3810.  
  3811.           If the result of the "string compare" in this technique is
  3812.           positive you can be certain that the EMM driver is present.
  3813.  
  3814.  
  3815.  
  3816.  
  3817.  
  3818.  
  3819.  
  3820.  
  3821.  
  3822.  
  3823.  
  3824.           3-8                         3000275-003Testing for the presence of the EMM
  3825.  
  3826.  
  3827.  
  3828.  
  3829.  
  3830.  
  3831.  
  3832.  
  3833.           An example of the "get interrupt vector" technique
  3834.  
  3835.           The following procedure is an example of the "get interrupt
  3836.           vector" technique outlined in the previous section.
  3837.  
  3838.           ;;
  3839.             ;______________________________________________________________      
  3840.             ______________________________________________________________;
  3841.             ;_________The following procedure tests for the presence of the     E
  3842.             MM_____________________________________________________________     ;
  3843.             ;___in the system.  It returns the CARRY FLAG SET if the EMM is      
  3844.             ______________________________________________________________;
  3845.             ;___present.  It returns the CARRY FLAG CLEAR if the EMM is not      
  3846.             ______________________________________________________________;
  3847.             ;______________________________________________________present.      
  3848.             ______________________________________________________________;
  3849.             ;______________________________________________________________      
  3850.             ______________________________________________________________;
  3851.           ;;
  3852.           
  3853.           second_test_for_EMM PROC           NEAR
  3854.             
  3855.             ___________________________________________________________PUSH     D
  3856.             S
  3857.             ___________________________________________________________PUSH     C
  3858.             S
  3859.             ____________________________________________________________POP     D
  3860.             S
  3861.             
  3862.             ____________________________________________________________MOV     A
  3863.             H, 35h___________________________________; issue "get interrupt
  3864.             ____________________________________________________________MOV     A
  3865.             L, 67h________________________________________________; vector"
  3866.             ____________________________________________________________INT     2
  3867.             1h
  3868.             
  3869.             ____________________________________________________________MOV     D
  3870.             I, 000Ah___________________________________; use the SEGMENT in
  3871.             _______________________________________________________________      
  3872.             ; ES returned by DOS,
  3873.             _______________________________________________________________      
  3874.             ; place the "device
  3875.             _______________________________________________________________      
  3876.             ; name field"OFFSET in DI
  3877.             
  3878.             ____________________________________________________________LEA     S
  3879.             I, ASCII_device_name______________________; place the OFFSET of
  3880.             _______________________________________________________________      
  3881.             ; the EMMXXXX0 name
  3882.             _______________________________________________________________      
  3883.             ; string in SI, the
  3884.             _______________________________________________________________      
  3885.             ; SEGMENT is already in DS
  3886.             
  3887.  
  3888.  
  3889.  
  3890.           Testing for the presence of the EMM300275-003                  3-9
  3891.  
  3892.  
  3893.  
  3894.  
  3895.  
  3896.  
  3897.  
  3898.  
  3899.             ____________________________________________________________MOV     C
  3900.             X, 8_________________________________; compare the name strings
  3901.             ____________________________________________________________CLD
  3902.              __________________________________________________________REPE     C
  3903.             MPSB
  3904.              ___________________________________________________________JNE     s
  3905.             econd_test_for_EMM_error_exit
  3906.             
  3907.           second_test_for_EMM_exit:
  3908.             
  3909.             ____________________________________________________________POP     D
  3910.             S___________________________________________; EMM is present in
  3911.             ____________________________________________________________STC      
  3912.             ; the system
  3913.             ____________________________________________________________RET
  3914.             
  3915.           second_test_for_EMM_error_exit:
  3916.             
  3917.             ____________________________________________________________POP     D
  3918.             S__________________________________________; EMM is NOT present
  3919.             ____________________________________________________________CLC      
  3920.             ; in the system
  3921.             ____________________________________________________________RET
  3922.             
  3923.           ASCII_device_name: DB              "EMMXXXX0"
  3924.             
  3925.           second_test_for_EMM ENDP
  3926.  
  3927.  
  3928.  
  3929.  
  3930.  
  3931.  
  3932.  
  3933.  
  3934.  
  3935.  
  3936.  
  3937.  
  3938.  
  3939.  
  3940.  
  3941.  
  3942.  
  3943.  
  3944.  
  3945.  
  3946.  
  3947.  
  3948.  
  3949.  
  3950.  
  3951.  
  3952.  
  3953.  
  3954.  
  3955.  
  3956.           3-10                        3000275-003Testing for the presence of the EMM
  3957.  
  3958.  
  3959.  
  3960.  
  3961.  
  3962.  
  3963.  
  3964.  
  3965.           CHAPTER 4.  EXAMPLE EXPANDED MEMORY PROGRAMS
  3966.  
  3967.           This chapter presents example procedures that use expanded
  3968.           memory.  The first part of this chapter lists the basic
  3969.           characteristics of the example procedures.  Later sections
  3970.           present annotated outlines (or flow charts) for writing transient
  3971.           and resident application programs that use expanded memory.
  3972.  
  3973.           The actual example code (with comments) is listed at the end of
  3974.           the chapter.
  3975.  
  3976.  
  3977.           Characteristics of the example procedures
  3978.  
  3979.           The example procedures in this chapter illustrate the EMM
  3980.           operations that a typical transient or resident program carries
  3981.           out when using expanded memory.  When reading the examples, keep
  3982.           in mind that they:
  3983.  
  3984.           1.   Are implemented in assembly language.
  3985.  
  3986.           2.   Assume that all variables reside in the same segment and
  3987.                that DS is already set up for access to all the variables.
  3988.  
  3989.           3.   Assume that the application program  will determine what to
  3990.                do with EMM error conditions when they are returned from the
  3991.                example procedures.  The example procedures do not provide
  3992.                any error processing when an EMM error is detected.  You
  3993.                could include a simple EMM error handling procedure that
  3994.                displays the function which was invoked and the status which
  3995.                was returned.
  3996.  
  3997.  
  3998.           Transient application program
  3999.  
  4000.           A transient program is loaded by DOS, executes, and doesn't
  4001.           remain resident in the system after it returns control to DOS.
  4002.           After a transient program returns control to DOS, the memory it
  4003.           used is available for other programs.
  4004.  
  4005.           This section presents an outline (or flow chart) which
  4006.           illustrates the structure of an example transient application
  4007.           program.  It also includes a detailed explanation of the outline.
  4008.  
  4009.  
  4010.           Flow chart of a transient application program
  4011.  
  4012.           The following flow chart shows the structure of an example
  4013.           transient application program that uses expanded memory.  The
  4014.           next section contains detailed explanations of the individual
  4015.           processes.
  4016.  
  4017.  
  4018.  
  4019.  
  4020.  
  4021.  
  4022.           Example expanded memory programs300275-003                    4-11
  4023.  
  4024.  
  4025.  
  4026.  
  4027.  
  4028.  
  4029.  
  4030.  
  4031.           
  4032.  
  4033.           
  4034.  
  4035.           
  4036.  
  4037.           
  4038.  
  4039.           
  4040.  
  4041.           
  4042.  
  4043.           
  4044.  
  4045.           
  4046.  
  4047.           
  4048.  
  4049.           
  4050.  
  4051.           
  4052.  
  4053.           
  4054.  
  4055.           
  4056.  
  4057.           
  4058.  
  4059.           
  4060.  
  4061.           
  4062.  
  4063.           
  4064.  
  4065.           
  4066.  
  4067.  
  4068.           Explanation of the transient application program flow chart
  4069.  
  4070.           This example transient application program is invoked from the
  4071.           DOS command line and loaded by DOS.  It first executes some
  4072.           initialization procedures, then some processing procedures that
  4073.           use expanded memory, and finally, some terminating procedures.
  4074.           After the program terminates, it returns control to DOS.
  4075.  
  4076.           The following subsections describe the individual procedures
  4077.           within the flow chart.  These subsections refer you to the actual
  4078.           code for each procedure.
  4079.  
  4080.  
  4081.  
  4082.  
  4083.  
  4084.  
  4085.  
  4086.  
  4087.  
  4088.           4-12                         300275-003Example expanded memory programs
  4089.  
  4090.  
  4091.  
  4092.  
  4093.  
  4094.  
  4095.  
  4096.  
  4097.           Initialization procedures
  4098.  
  4099.           The block labeled "transient application initialization"
  4100.           represents any preliminary processing and interaction with the
  4101.           user that the program may need to perform.  After the transient
  4102.           program performs these operations, it should initialize the EMM.
  4103.  
  4104.           The block labeled "EMM transient initialization" represents code
  4105.           that prepares the EMM so it can run with the application program.
  4106.           An example of this type of procedure (called EMM_transient_init)
  4107.           is shown on page 4-10.
  4108.  
  4109.           This procedure uses the "open handle" technique to determine
  4110.           whether the EMM is present in the system.  (The "open handle"
  4111.           technique is described in Chapter 3 of this specification.)  The
  4112.           procedure also ensures that the version of the EMM loaded in the
  4113.           system is compatible with the version required by the application
  4114.           program, and it obtains the number of expanded memory pages your
  4115.           application code requests.
  4116.  
  4117.  
  4118.           Processing procedures
  4119.  
  4120.           The block labeled "transient application processing (not
  4121.           requiring expanded memory)" represents processing the program
  4122.           performs which does not require access to expanded memory.
  4123.  
  4124.           The block labeled "EMM access" represents the code that the
  4125.           application must execute before it can access expanded memory.
  4126.           (The expanded memory was allocated to it by the "EMM transient
  4127.           initialization" procedure.)  An example of this type of procedure
  4128.           (called EMM_access) is shown on page 4-16.  The example procedure
  4129.           maps the logical page allocated to the EMM handle into the
  4130.           physical page the application program specified. (The
  4131.           "EMM_transient_init" procedure assigned the EMM handle.)
  4132.  
  4133.           The block labeled "transient application processing (requiring
  4134.           expanded memory)" represents the processing within the program
  4135.           that uses the expanded memory area.  The application can use the
  4136.           expanded memory area for data or code.  An application program
  4137.           can locate code in the page frame and execute it, or it can just
  4138.           store data and access it.  Your program can use the page frame to
  4139.           store anything except its stack; there is no code restriction.
  4140.  
  4141.           The loop to the block labeled "EMM access" represents a possible
  4142.           iterative process.  The application may have a requirement to
  4143.           access many pages within expanded memory.  The process of calling
  4144.           the "EMM_access" procedure and accessing the data in the mapped
  4145.           page is iterative.
  4146.  
  4147.  
  4148.           Terminating procedure
  4149.  
  4150.           Once the application completes its task, it must return the
  4151.           expanded memory that the EMM allocated to it.
  4152.  
  4153.  
  4154.           Example expanded memory programs300275-003                    4-13
  4155.  
  4156.  
  4157.  
  4158.  
  4159.  
  4160.  
  4161.  
  4162.  
  4163.           The block labeled "EMM termination" represents this phase of the
  4164.           application program's execution.  An example of this type of
  4165.           procedure (called EMM_termination) is shown on page 4-17.  This
  4166.           example procedure returns both the EMM handle and the logical
  4167.           pages to the EMM.  (The EMM handle was issued and the logical
  4168.           pages were allocated by "EMM_transient_init" procedure.)
  4169.  
  4170.           The block labeled "transient application termination" represents
  4171.           the code the application needs to execute by before it terminates
  4172.           and returns control to DOS.
  4173.  
  4174.  
  4175.           Resident application program
  4176.  
  4177.           A resident application program is loaded by DOS, executes, and
  4178.           remains resident in the system after it returns control to DOS.
  4179.           This type of program is usually invoked by the operating system,
  4180.           a hardware interrupt, or a software interrupt.
  4181.  
  4182.           This section presents an outline (or flow chart) which
  4183.           illustrates the structure of an example resident application
  4184.           program.  It also includes a detailed explanation of the flow
  4185.           chart.
  4186.  
  4187.  
  4188.           Flow Chart of a resident application program
  4189.  
  4190.           The following flow chart shows the structure of an example
  4191.           resident application program that uses expanded memory.  The next
  4192.           section contains detailed explanations of the individual
  4193.           processes.
  4194.  
  4195.           
  4196.  
  4197.  
  4198.  
  4199.  
  4200.  
  4201.  
  4202.  
  4203.  
  4204.  
  4205.  
  4206.  
  4207.  
  4208.  
  4209.  
  4210.  
  4211.  
  4212.  
  4213.  
  4214.  
  4215.  
  4216.  
  4217.  
  4218.  
  4219.  
  4220.           4-14                         300275-003Example expanded memory programs
  4221.  
  4222.  
  4223.  
  4224.  
  4225.  
  4226.  
  4227.  
  4228.  
  4229.           Explanation of the resident application program flow chart
  4230.  
  4231.           Resident application programs are loaded from the CONFIG.SYS file
  4232.           as drivers or they are loaded by DOS and use the DOS "terminate
  4233.           and stay resident" function.
  4234.  
  4235.           Resident programs have special characteristics which must be
  4236.           taken into consideration when using expanded memory.  They must
  4237.           initialize their own data structures as well as initializing the
  4238.           EMM (getting the page frame address, getting a handle assigned
  4239.           and allocating pages).  Resident programs also consume a portion
  4240.           of conventional memory, making it unavailable for use by
  4241.           transient programs.
  4242.  
  4243.           Since they may interrupt transient programs which use expanded
  4244.           memory, resident programs must save and restore the state of the
  4245.           page mapping registers when using expanded memory.  Functions 8
  4246.           and 9 (described in Chapter 2) are provided for just this
  4247.           purpose.
  4248.  
  4249.           This example resident application program illustrated by the
  4250.           previous flow chart performs the following operations:
  4251.  
  4252.           o  initializes its internal data structures as well as
  4253.              initializing the EMM
  4254.  
  4255.           o  saves the CPU state
  4256.  
  4257.           o  performs any processing it requires before accessing expanded
  4258.              memory
  4259.  
  4260.           o  saves the state of the expanded memory hardware
  4261.  
  4262.           o  accesses expanded memory
  4263.  
  4264.           o  restores the state of the expanded memory hardware
  4265.  
  4266.           o  terminates
  4267.  
  4268.           o  restores the CPU state
  4269.  
  4270.           The remainder of this section describes these operations in
  4271.           detail.
  4272.  
  4273.  
  4274.           Initializing the resident program and the EMM
  4275.  
  4276.           The block labeled "resident application initialization "
  4277.           represents any preliminary processing the resident program may
  4278.           need to perform.
  4279.  
  4280.           The block labeled "EMM resident initialization" represents the
  4281.           code that prepares the EMM so it can run with the resident
  4282.           application program.  A example of this type of procedure (called
  4283.           EMM_resident_init) is shown on page 4-13.
  4284.  
  4285.  
  4286.           Example expanded memory programs300275-003                    4-15
  4287.  
  4288.  
  4289.  
  4290.  
  4291.  
  4292.  
  4293.  
  4294.  
  4295.           This procedure uses the "get interrupt vector" test described in
  4296.           Chapter 3 to determine whether the EMM is present in the system.
  4297.           The procedure also ensures that the version of the EMM loaded in
  4298.           the system is compatible with the version required by the
  4299.           application program.  In addition this procedure obtains an EMM
  4300.           handle and allocates the required number of pages for the
  4301.           resident program.  Typically, the resident program will keep the
  4302.           handle assigned to it as well as the pages allocated to it until
  4303.           the system is rebooted.
  4304.  
  4305.           The first two blocks in the flow chart aren't directly connected
  4306.           to the blocks that follow.  This flow chart depicts a common
  4307.           situation encountered in resident programs.  Resident programs
  4308.           can be divided into a section of code which executes and then
  4309.           isn't needed afterwards.  The programs usually return the memory
  4310.           consumed by the initialization section of the resident program to
  4311.           DOS for re-use by other programs.
  4312.  
  4313.           The "resident" section of the resident program remains in the
  4314.           memory until the system is rebooted.  Typically, this code is
  4315.           executed whenever a particular hardware or software interrupt
  4316.           occurs, or when it is "called" by DOS.
  4317.  
  4318.           The first two blocks represent initialization code, which after
  4319.           it executes, never needed again.  So, the code returns the memory
  4320.           which it used to DOS.  The succeeding blocks in the flow chart
  4321.           represent the resident section of the code which is executed only
  4322.           when some event, such as a hardware or software interrupt,
  4323.           occurs.  For this reason, the first two blocks in the flow chart
  4324.           are not connected to the succeeding blocks.
  4325.  
  4326.  
  4327.           Saving the current state of the CPU
  4328.  
  4329.           The block labeled "suspend transient program's execution"
  4330.           represents the code responsible for saving the current state of
  4331.           the CPU when the resident code begins executing.  A hardware or
  4332.           software interrupt usually causes the resident code to begin
  4333.           executing.
  4334.  
  4335.           Saving the CPU's state is essential.  At some point, the resident
  4336.           program must return control to the previously-executing program.
  4337.           Before the original program can continue to function correctly,
  4338.           the CPU must be returned to the exact state it was in before the
  4339.           resident program began executing.
  4340.  
  4341.  
  4342.           Resident processing performed before accessing expanded memory
  4343.  
  4344.           The block labeled "resident processing (not requiring expanded
  4345.           memory)" represents processing which must be performed by the
  4346.           resident application before it needs to access expanded memory.
  4347.  
  4348.  
  4349.  
  4350.  
  4351.  
  4352.           4-16                         300275-003Example expanded memory programs
  4353.  
  4354.  
  4355.  
  4356.  
  4357.  
  4358.  
  4359.  
  4360.  
  4361.           Saving the state of the expanded memory hardware
  4362.  
  4363.           The block labeled "save EMM map state" represents the code that
  4364.           must be executed before the resident program attempts to access
  4365.           expanded memory.  This code must save the state of the expanded
  4366.           memory hardware before the resident program can map any of its
  4367.           pages into the page frame.
  4368.  
  4369.           Saving the state of the expanded memory hardware is essential,
  4370.           because another program may have been using it when the resident
  4371.           program took over.  Saving the mapping state of the expanded
  4372.           memory hardware ensures that both the resident program and any
  4373.           transient program that may have been executing when the resident
  4374.           program started are not corrupted.  An example of such a
  4375.           procedure (called EMM_save_map_state) is shown on page 4-18.
  4376.  
  4377.  
  4378.           Accessing expanded memory
  4379.  
  4380.           The block labeled "EMM access" represents the code that the
  4381.           resident program must execute before it can access expanded
  4382.           memory.  (The expanded memory was allocated to it by "EMM
  4383.           resident initialization" procedure described earlier.)  An
  4384.           example of this type of procedure (called EMM_access) is shown on
  4385.           page 4-16.
  4386.  
  4387.           The example procedure simply maps one of the logical pages
  4388.           allocated to the EMM handle assigned by the "EMM_resident_init"
  4389.           procedure into the physical page the resident program specified.
  4390.  
  4391.           The block labeled "resident application processing (requiring
  4392.           expanded memory)" represents the processing within the resident
  4393.           program which uses expanded memory.  The resident program can use
  4394.           expanded memory for data or code.  A resident program can locate
  4395.           code in the page frame and execute it or it can just store data
  4396.           and access it.  Your program can use the page frame to store
  4397.           anything except its stack; there is no code restriction.
  4398.  
  4399.           The loop to the block labeled "EMM access" represents a possible
  4400.           iterative process.  The resident program may have a requirement
  4401.           to access many pages within expanded memory.  The process of
  4402.           calling the "EMM_access" procedure and accessing the data in the
  4403.           mapped page is iterative.
  4404.  
  4405.  
  4406.           Restoring the state of the expanded memory hardware
  4407.  
  4408.           The block labeled "restore EMM map state" represents the code in
  4409.           a resident program that restores the state of the expanded memory
  4410.           hardware.  This code restores the expanded memory hardware to the
  4411.           state it was in before the resident program mapped its pages into
  4412.           the page frame.  An example procedure (called
  4413.           EMM_restore_map_state) is shown on page 4-19.
  4414.  
  4415.  
  4416.  
  4417.  
  4418.           Example expanded memory programs300275-003                    4-17
  4419.  
  4420.  
  4421.  
  4422.  
  4423.  
  4424.  
  4425.  
  4426.  
  4427.           Terminating the resident program
  4428.  
  4429.           The block labeled "resident processing termination" represents
  4430.           any processing that the resident program must do before it
  4431.           terminates.  After the resident program terminates, it returns
  4432.           control to the transient program that was executing before it
  4433.           took control.
  4434.  
  4435.  
  4436.           Restoring the CPU state
  4437.  
  4438.           The block labeled "restore CPU state" represents the code
  4439.           responsible for restoring the CPU to the state it was before the
  4440.           resident program took control.
  4441.  
  4442.  
  4443.  
  4444.  
  4445.  
  4446.  
  4447.  
  4448.  
  4449.  
  4450.  
  4451.  
  4452.  
  4453.  
  4454.  
  4455.  
  4456.  
  4457.  
  4458.  
  4459.  
  4460.  
  4461.  
  4462.  
  4463.  
  4464.  
  4465.  
  4466.  
  4467.  
  4468.  
  4469.  
  4470.  
  4471.  
  4472.  
  4473.  
  4474.  
  4475.  
  4476.  
  4477.  
  4478.  
  4479.  
  4480.  
  4481.  
  4482.  
  4483.  
  4484.           4-18                         300275-003Example expanded memory programs
  4485.  
  4486.  
  4487.  
  4488.  
  4489.  
  4490.  
  4491.  
  4492.  
  4493.           Example EMM procedures
  4494.  
  4495.           This section lists the code for all the EMM procedures referenced
  4496.           in the previous examples.
  4497.  
  4498.           ;;
  4499.             ;______________________________________________________________      
  4500.             ______________________________________________________________;
  4501.             ;___________FUNCTIONAL "EQUATES" USED THROUGHOUT THESE EXAMPLES      
  4502.             ______________________________________________________________;
  4503.             ;______________________________________________________________      
  4504.             ______________________________________________________________;
  4505.           ;;
  4506.           
  4507.           EMM_interrupt                      EQU  67h
  4508.           get_page_frame_address             EQU  41h
  4509.           get_unalloc_page_count             EQU  42h
  4510.           allocate_pages                     EQU  43h
  4511.           map_handle_page                    EQU  44h
  4512.           deallocate_pages                   EQU  45h
  4513.           get_emm_version                    EQU  46h
  4514.           save_page_map                      EQU  47h
  4515.           restore_page_map                   EQU  48h
  4516.           
  4517.           ;;
  4518.             ;______________________________________________________________      
  4519.             ______________________________________________________________;
  4520.             ;_______________STATUS "EQUATES" USED THROUGHOUT THESE EXAMPLES      
  4521.             ______________________________________________________________;
  4522.             ;______________________________________________________________      
  4523.             ______________________________________________________________;
  4524.           ;;
  4525.           
  4526.           function_passed                    EQU  00h  ; status which
  4527.           indicates
  4528.                                                        ; that the function
  4529.                                                        ; invocation
  4530.           completed
  4531.                                                        ; successfully
  4532.           
  4533.           EMM_not_resident                   EQU  01h  ; status which
  4534.           indicates
  4535.                                                        ; the the EMM is not
  4536.                                                        ; loaded in the
  4537.           system
  4538.           
  4539.           EMM_version_mismatch               EQU  02h  ; status which
  4540.           indicates
  4541.                                                        ; that the version
  4542.           of EMM
  4543.                                                        ; is not compatible
  4544.           with
  4545.                                                        ; the version
  4546.           required by
  4547.  
  4548.  
  4549.  
  4550.           Example expanded memory programs300275-003                    4-19
  4551.  
  4552.  
  4553.  
  4554.  
  4555.  
  4556.  
  4557.  
  4558.  
  4559.                                                        ; the application
  4560.           program
  4561.           
  4562.           insuff_total_pages                 EQU  87h  ; status which EMM
  4563.                                                        ; returns if an
  4564.           attempt
  4565.                                                        ; was made to
  4566.           allocate
  4567.                                                        ; more pages than
  4568.           exist
  4569.                                                        ; in expanded memory
  4570.           
  4571.           insuff_unalloc_pages               EQU  88h  ; status which EMM
  4572.                                                        ; returns if an
  4573.           attempt
  4574.                                                        ; was made to
  4575.           allocate
  4576.                                                        ; more pages than
  4577.           are
  4578.                                                        ; currently un-
  4579.           allocated
  4580.  
  4581.  
  4582.  
  4583.  
  4584.  
  4585.  
  4586.  
  4587.  
  4588.  
  4589.  
  4590.  
  4591.  
  4592.  
  4593.  
  4594.  
  4595.  
  4596.  
  4597.  
  4598.  
  4599.  
  4600.  
  4601.  
  4602.  
  4603.  
  4604.  
  4605.  
  4606.  
  4607.  
  4608.  
  4609.  
  4610.  
  4611.  
  4612.  
  4613.  
  4614.  
  4615.  
  4616.           4-20                         300275-003Example expanded memory programs
  4617.  
  4618.  
  4619.  
  4620.  
  4621.  
  4622.  
  4623.  
  4624.  
  4625.           ;;
  4626.             ;______________________________________________________________      
  4627.             ______________________________________________________________;
  4628.             ;______________________VARIABLES USED THROUGHOUT THESE EXAMPLES      
  4629.             ______________________________________________________________;
  4630.             ;______________________________________________________________      
  4631.             ______________________________________________________________;
  4632.           ;;
  4633.           
  4634.           application_EMM_version            DB   30h  ; the lowest version
  4635.                                                        ; number of the EMM
  4636.           which
  4637.                                                        ; the application is
  4638.                                                        ; compatible with
  4639.           
  4640.           application_pages_req              DW   0    ; number of pages
  4641.           the
  4642.                                                        ; application
  4643.           requires
  4644.           
  4645.           EMM_handle                         DW   0    ; storage for the
  4646.           handle
  4647.                                                        ; which the EMM
  4648.           assigns
  4649.                                                        ; to the application
  4650.           
  4651.           EMM_status                         DB   0    ; storage for the
  4652.           status
  4653.                                                        ; which the EMM
  4654.           returns
  4655.                                                        ; to the application
  4656.           
  4657.           logical_page                       DW   0    ; specifies the
  4658.           logical
  4659.                                                        ; page which the
  4660.                                                        ; application needs
  4661.           to
  4662.                                                        ; access
  4663.           
  4664.           physical_page                      DB   0    ; specifies where
  4665.           within
  4666.                                                        ; the page frame the
  4667.                                                        ; application needs
  4668.           to
  4669.                                                        ; access the logical
  4670.           page
  4671.           
  4672.           page_frame_segment                 DW   0    ; specifies the page
  4673.                                                        ; frame base segment
  4674.                                                        ; address at which
  4675.           the
  4676.                                                        ; EMM has located
  4677.           the
  4678.                                                        ; physical pages
  4679.  
  4680.  
  4681.  
  4682.           Example expanded memory programs300275-003                    4-21
  4683.  
  4684.  
  4685.  
  4686.  
  4687.  
  4688.  
  4689.  
  4690.  
  4691.           ;;
  4692.             ;______________________________________________________________      
  4693.             ______________________________________________________________;
  4694.             ;___________EXAMPLE PROCEDURE #1   EMM TRANSIENT INITIALIZATION      
  4695.             ______________________________________________________________;
  4696.             ;______________________________________________________________      
  4697.             ______________________________________________________________;
  4698.             ;_______This example PROCEDURE determines whether or not EMM is      
  4699.             ______________________________________________________________;
  4700.             ;_present in your your system.  Next, it determines whether the      
  4701.             ______________________________________________________________;
  4702.             ;____application can run with the version of EMM present in the      
  4703.             ______________________________________________________________;
  4704.             ;___system and whether the application will "fit" in the number      
  4705.             ______________________________________________________________;
  4706.             ;_____of unallocated pages the EMM has available for use.  The,      
  4707.             ______________________________________________________________;
  4708.             ;__procedure then locates the page frame segment, and allocates      
  4709.             ______________________________________________________________;
  4710.             ;__________________________________________the pages requested.      
  4711.             ______________________________________________________________;
  4712.             ;______________________________________________________________      
  4713.             ______________________________________________________________;
  4714.             ;___If the application does not "fit" in the available expanded      
  4715.             ______________________________________________________________;
  4716.             ;__memory, or if some other EMM error is encountered, then this      
  4717.             ______________________________________________________________;
  4718.             ;____________________________________________________procedure:      
  4719.             ______________________________________________________________;
  4720.             ;__________________1. Returns the status returned by the EMM in     E
  4721.             MM_status._____________________________________________________     ;
  4722.             ;________________________________2. Returns to the application.      
  4723.             ______________________________________________________________;
  4724.             ;______________________________________________________________      
  4725.             ______________________________________________________________;
  4726.             ;____If the application "fits" in the available expanded memory      
  4727.             ______________________________________________________________;
  4728.             ;_______________________________________________then it should:      
  4729.             ______________________________________________________________;
  4730.             ;__________1. Get the version number and determines whether the      
  4731.             ______________________________________________________________;
  4732.             ;________   application is compatible with this version of EMM.      
  4733.             ______________________________________________________________;
  4734.             ;________2. Get the page frame segment address from the EMM and      
  4735.             ______________________________________________________________;
  4736.             ;_____________________________   save it in page_frame_segment.      
  4737.             ______________________________________________________________;
  4738.             ;___________________3. Get a handle from the EMM and save it in      
  4739.             ______________________________________________________________;
  4740.             ;________________________________________________   EMM_handle.      
  4741.             ______________________________________________________________;
  4742.             ;____________________________4. Allocate the pages specified in      
  4743.             ______________________________________________________________;
  4744.             ;_____________________________________   application_pages_req.      
  4745.             ______________________________________________________________;
  4746.  
  4747.  
  4748.           4-22                         300275-003Example expanded memory programs
  4749.  
  4750.  
  4751.  
  4752.  
  4753.  
  4754.  
  4755.  
  4756.  
  4757.             ;_________________5. Return an EMM passed status in emm_status.      
  4758.             ______________________________________________________________;
  4759.             ;_________________________________6. Return to the application.      
  4760.             ______________________________________________________________;
  4761.             ;______________________________________________________________      
  4762.             ______________________________________________________________;
  4763.           ;;
  4764.           
  4765.           EMM_transient_init PROC            NEAR
  4766.           
  4767.           ;;
  4768.             ;   DETERMINE WHETHER OR NOT EMM IS RESIDENT IN THE SYSTEM  ___     
  4769.             _______________________________________________________________     ;
  4770.           ;;
  4771.             _______________________________________________________________
  4772.             ____________________________________________________________MOV     B
  4773.             YTE PTR EMM_status, EMM_not_resident___________________________
  4774.             _______________________________________________________________      
  4775.             ; assume that the test
  4776.             ___________________________________________________________CALL     f
  4777.             irst_test_for_EMM_________________________; for the presence of
  4778.             ____________________________________________________________JNC     E
  4779.             MM_transient_init_exit__________________________; EMM will fail
  4780.             
  4781.           ;;
  4782.             ;   DETERMINE WHETHER RESIDENT VERSION OF EMM IS_______________      
  4783.             ______________________________________________________________;
  4784.             ;   COMPATIBLE WITH APPLICATION________________________________      
  4785.             ______________________________________________________________;
  4786.           ;;
  4787.             
  4788.             ____________________________________________________________MOV     A
  4789.             H, get_emm_version________________________; get the EMM version
  4790.             ____________________________________________________________INT     6
  4791.             7h
  4792.             
  4793.             ____________________________________________________________MOV     E
  4794.             MM_status, AH_________________________________; save the status
  4795.             
  4796.  
  4797.  
  4798.  
  4799.  
  4800.  
  4801.  
  4802.  
  4803.  
  4804.  
  4805.  
  4806.  
  4807.  
  4808.  
  4809.  
  4810.  
  4811.  
  4812.  
  4813.  
  4814.           Example expanded memory programs300275-003                    4-23
  4815.  
  4816.  
  4817.  
  4818.  
  4819.  
  4820.  
  4821.  
  4822.  
  4823.             ____________________________________________________________ORA     A
  4824.             H, AH_________________________________________; if the function
  4825.             ____________________________________________________________JNZ     E
  4826.             MM_transient_init_exit___________________; failed return to the
  4827.             _______________________________________________________________      
  4828.             ; application
  4829.             
  4830.             ____________________________________________________________MOV     B
  4831.             YTE PTR emm_status,emm_version mismatch
  4832.             ____________________________________________________________CMP     A
  4833.             L, application_emm_version__; assume that the installed version
  4834.             _____________________________________________________________JB     e
  4835.             mm_transient_init_exit_______________; is incompatible with the
  4836.             _______________________________________________________________      
  4837.             ; application version
  4838.             
  4839.           ;;
  4840.             ;   GET THE PAGE FRAME SEGMENT ADDRESS_________________________      
  4841.             ______________________________________________________________;
  4842.           ;;
  4843.                     
  4844.  
  4845.             ____________________________________________________________MOV     A
  4846.             H, get_page_frame_address__________________; get the page frame
  4847.             ____________________________________________________________INT     E
  4848.             MM_interrupt__________________________________; segment address
  4849.             
  4850.             ____________________________________________________________MOV     E
  4851.             MM_status, AH_________________________________; save the status
  4852.             
  4853.             ____________________________________________________________ORA     A
  4854.             H, AH_________________________________________; if the function
  4855.             ____________________________________________________________JNZ     E
  4856.             MM_transient_init_exit___________________; failed return to the
  4857.             _______________________________________________________________      
  4858.             ; application
  4859.             
  4860.             ____________________________________________________________MOV     p
  4861.             age_frame_segment, BX_____________________; save the page frame
  4862.             _______________________________________________________________      
  4863.             ; segment address
  4864.             
  4865.           ;;
  4866.             ;   GET THE NUMBER OF TOTAL AND UNALLOCATED PAGES PRESENT______      
  4867.             ______________________________________________________________;
  4868.           ;;
  4869.                     
  4870.  
  4871.             ____________________________________________________________MOV     A
  4872.             H, get_unalloc_page_count___________________; get the total and
  4873.             ____________________________________________________________INT     E
  4874.             MM_interrupt_______________________________; un-allocated pages
  4875.             _______________________________________________________________      
  4876.             ; in the system
  4877.             
  4878.  
  4879.  
  4880.           4-24                         300275-003Example expanded memory programs
  4881.  
  4882.  
  4883.  
  4884.  
  4885.  
  4886.  
  4887.  
  4888.  
  4889.             ____________________________________________________________MOV     E
  4890.             MM_status, AH_________________________________; save the status
  4891.             
  4892.             ____________________________________________________________ORA     A
  4893.             H, AH_________________________________________; if the function
  4894.             ____________________________________________________________JNZ     E
  4895.             MM_transient_init_exit___________________; failed return to the
  4896.             _______________________________________________________________      
  4897.             ; application
  4898.             
  4899.           ;;
  4900.             ;   DETERMINE WHETHER APPLICATION CAN RUN WITH THIS NUMBER_____      
  4901.             ______________________________________________________________;
  4902.             ;   OF TOTAL AND UNALLOCATED______________________________PAGES      
  4903.             ______________________________________________________________;
  4904.           ;;
  4905.                     
  4906.  
  4907.             ____________________________________________________________MOV     B
  4908.             YTE PTR EMM_status, insuff_total_pages_________________________
  4909.             _______________________________________________________________      
  4910.             ; check total pages
  4911.             ____________________________________________________________CMP     a
  4912.             pplication_pages_req, DX_________________________; not required
  4913.             _____________________________________________________________JA     E
  4914.             MM_transient_init_exit
  4915.             
  4916.             ____________________________________________________________MOV     B
  4917.             YTE PTR EMM_status, insuff_unalloc_pages
  4918.             ____________________________________________________________CMP     a
  4919.             pplication_pages_req, BX______________; check unallocated pages
  4920.             _____________________________________________________________JA     E
  4921.             MM_transient_init_exit
  4922.  
  4923.  
  4924.  
  4925.  
  4926.  
  4927.  
  4928.  
  4929.  
  4930.  
  4931.  
  4932.  
  4933.  
  4934.  
  4935.  
  4936.  
  4937.  
  4938.  
  4939.  
  4940.  
  4941.  
  4942.  
  4943.  
  4944.  
  4945.  
  4946.           Example expanded memory programs300275-003                    4-25
  4947.  
  4948.  
  4949.  
  4950.  
  4951.  
  4952.  
  4953.  
  4954.  
  4955.           ;;
  4956.             ;   GET AN EMM HANDLE AND SAVE IT______________________________      
  4957.             ______________________________________________________________;
  4958.             ;   ALLOCATE THE NUMBER OF PAGES THE APPLICATION REQUIRES______      
  4959.             ______________________________________________________________;
  4960.           ;;
  4961.                     
  4962.  
  4963.             ____________________________________________________________MOV     A
  4964.             H, allocate_pages____________________________; get a handle and
  4965.             ____________________________________________________________MOV     B
  4966.             X, application_pages_req_______________________; allocate pages
  4967.             ____________________________________________________________INT     E
  4968.             MM_interrupt___________________________________; to that handle
  4969.             
  4970.             ____________________________________________________________MOV     E
  4971.             MM_status, AH_________________________________; save the status
  4972.             
  4973.             EMM_transient_init_exit:
  4974.             
  4975.           ;;
  4976.             ;   RETURN TO THE APPLICATION__________________________________      
  4977.             ______________________________________________________________;
  4978.           ;;
  4979.                     
  4980.  
  4981.             ____________________________________________________________RET      
  4982.             ; return to the
  4983.             _______________________________________________________________      
  4984.             ; application
  4985.             
  4986.           EMM_transient_init        ENDP
  4987.  
  4988.  
  4989.  
  4990.  
  4991.  
  4992.  
  4993.  
  4994.  
  4995.  
  4996.  
  4997.  
  4998.  
  4999.  
  5000.  
  5001.  
  5002.  
  5003.  
  5004.  
  5005.  
  5006.  
  5007.  
  5008.  
  5009.  
  5010.  
  5011.  
  5012.           4-26                         300275-003Example expanded memory programs
  5013.  
  5014.  
  5015.  
  5016.  
  5017.  
  5018.  
  5019.  
  5020.  
  5021.           ;;
  5022.             ;______________________________________________________________      
  5023.             ______________________________________________________________;
  5024.             ;____________EXAMPLE PROCEDURE #2   EMM RESIDENT INITIALIZATION      
  5025.             ______________________________________________________________;
  5026.             ;______________________________________________________________      
  5027.             ______________________________________________________________;
  5028.             ;_______This example PROCEDURE determines whether or not EMM is      
  5029.             ______________________________________________________________;
  5030.             ;_present in your your system.  Next, it determines whether the      
  5031.             ______________________________________________________________;
  5032.             ;____application can run with the version of EMM present in the      
  5033.             ______________________________________________________________;
  5034.             ;___system and whether the application will "fit" in the number      
  5035.             ______________________________________________________________;
  5036.             ;_____of unallocated pages the EMM has available for use.  The,      
  5037.             ______________________________________________________________;
  5038.             ;__procedure then locates the page frame segment, and allocates      
  5039.             ______________________________________________________________;
  5040.             ;__________________________________________the pages requested.      
  5041.             ______________________________________________________________;
  5042.             ;______________________________________________________________      
  5043.             ______________________________________________________________;
  5044.             ;___If the application does not "fit" in the available expanded      
  5045.             ______________________________________________________________;
  5046.             ;__memory, or if some other EMM error is encountered, then this      
  5047.             ______________________________________________________________;
  5048.             ;____________________________________________________procedure:      
  5049.             ______________________________________________________________;
  5050.             ;__________________1. Returns the status returned by the EMM in     E
  5051.             MM_status._____________________________________________________     ;
  5052.             ;________________________________2. Returns to the application.      
  5053.             ______________________________________________________________;
  5054.             ;______________________________________________________________      
  5055.             ______________________________________________________________;
  5056.             ;____If the application "fits" in the available expanded memory      
  5057.             ______________________________________________________________;
  5058.             ;_______________________________________________then it should:      
  5059.             ______________________________________________________________;
  5060.             ;__________1. Get the version number and determines whether the      
  5061.             ______________________________________________________________;
  5062.             ;________   application is compatible with this version of EMM.      
  5063.             ______________________________________________________________;
  5064.             ;________2. Get the page frame segment address from the EMM and      
  5065.             ______________________________________________________________;
  5066.             ;_____________________________   save it in page_frame_segment.      
  5067.             ______________________________________________________________;
  5068.             ;___________________3. Get a handle from the EMM and save it in      
  5069.             ______________________________________________________________;
  5070.             ;________________________________________________   EMM_handle.      
  5071.             ______________________________________________________________;
  5072.             ;____________________________4. Allocate the pages specified in      
  5073.             ______________________________________________________________;
  5074.             ;_____________________________________   application_pages_req.      
  5075.             ______________________________________________________________;
  5076.  
  5077.  
  5078.           Example expanded memory programs300275-003                    4-27
  5079.  
  5080.  
  5081.  
  5082.  
  5083.  
  5084.  
  5085.  
  5086.  
  5087.             ;______________________5. Return a passed status in EMM_status.      
  5088.             ______________________________________________________________;
  5089.             ;_________________________________6. Return to the application.      
  5090.             ______________________________________________________________;
  5091.             ;______________________________________________________________      
  5092.             ______________________________________________________________;
  5093.           ;;
  5094.           
  5095.           EMM_resident_init PROC             NEAR
  5096.           
  5097.           ;;
  5098.             ;   DETERMINE WHETHER EMM IS RESIDENT IN THE SYSTEM ___________     
  5099.             _______________________________________________________________     ;
  5100.           ;;
  5101.             _______________________________________________________________
  5102.             ____________________________________________________________MOV     B
  5103.             YTE PTR EMM_status, EMM_not_resident___________________________
  5104.             _______________________________________________________________      
  5105.             ; assume that the test
  5106.             ___________________________________________________________CALL     s
  5107.             econd_first_test_for_EMM__________________; for the presence of
  5108.             ____________________________________________________________JNC     E
  5109.             MM_resident_init_exit___________________________; EMM will fail
  5110.             
  5111.           ;;
  5112.             ;   DETERMINE WHETHER RESIDENT VERSION OF EMM IS_______________      
  5113.             ______________________________________________________________;
  5114.             ;   COMPATIBLE WITH APPLICATION________________________________      
  5115.             ______________________________________________________________;
  5116.           ;;
  5117.             
  5118.             ____________________________________________________________MOV     A
  5119.             H, get_EMM_version________________________; get the EMM version
  5120.             ____________________________________________________________INT     6
  5121.             7h
  5122.             
  5123.             ____________________________________________________________MOV     E
  5124.             MM_status, AH_________________________________; save the status
  5125.             
  5126.  
  5127.  
  5128.  
  5129.  
  5130.  
  5131.  
  5132.  
  5133.  
  5134.  
  5135.  
  5136.  
  5137.  
  5138.  
  5139.  
  5140.  
  5141.  
  5142.  
  5143.  
  5144.           4-28                         300275-003Example expanded memory programs
  5145.  
  5146.  
  5147.  
  5148.  
  5149.  
  5150.  
  5151.  
  5152.  
  5153.             ____________________________________________________________ORA     A
  5154.             H, AH_________________________________________; if the function
  5155.             ____________________________________________________________JNZ     E
  5156.             MM_resident_init_exit____________________; failed return to the
  5157.             _______________________________________________________________      
  5158.             ; application
  5159.             
  5160.             ____________________________________________________________MOV     B
  5161.             YTE PTR EMM_status, EMM_version_mismatch_______________________
  5162.             _______________________________________________________________      
  5163.             ;assume that the installed
  5164.             ____________________________________________________________CMP     A
  5165.             L, application_EMM_version______;version of EMM is incompatible
  5166.             _____________________________________________________________JB     E
  5167.             MM_resident_init_exit_______; incompatible with the application
  5168.             _______________________________________________________________      
  5169.             ; version
  5170.           ;;
  5171.             ;   GET THE PAGE FRAME SEGMENT ADDRESS_________________________      
  5172.             ______________________________________________________________;
  5173.           ;;
  5174.                     
  5175.  
  5176.             ____________________________________________________________MOV     A
  5177.             H, get_page_frame_address__________________; get the page frame
  5178.             ____________________________________________________________INT     E
  5179.             MM_interrupt__________________________________; segment address
  5180.             
  5181.             ____________________________________________________________MOV     E
  5182.             MM_status, AH_________________________________; save the status
  5183.             
  5184.             ____________________________________________________________ORA     A
  5185.             H, AH_________________________________________; if the function
  5186.             ____________________________________________________________JNZ     E
  5187.             MM_resident_init_exit____________________; failed return to the
  5188.             _______________________________________________________________      
  5189.             ; application
  5190.             
  5191.             ____________________________________________________________MOV     p
  5192.             age_frame_segment, BX_____________________; save the page frame
  5193.             _______________________________________________________________      
  5194.             ; segment address
  5195.             
  5196.           ;;
  5197.             ;   GET THE NUMBER OF TOTAL AND UNALLOCATED PAGES PRESENT______      
  5198.             ______________________________________________________________;
  5199.           ;;
  5200.                     
  5201.  
  5202.             ____________________________________________________________MOV     A
  5203.             H, get_unalloc_page_count___________________; get the total and
  5204.             ____________________________________________________________INT     E
  5205.             MM_interrupt________________________________; un-allocated page
  5206.             _______________________________________________________________      
  5207.             ; in the system
  5208.  
  5209.  
  5210.           Example expanded memory programs300275-003                    4-29
  5211.  
  5212.  
  5213.  
  5214.  
  5215.  
  5216.  
  5217.  
  5218.  
  5219.             
  5220.             ____________________________________________________________MOV     E
  5221.             MM_status, AH_________________________________; save the status
  5222.             
  5223.             ____________________________________________________________ORA     A
  5224.             H, AH_________________________________________; if the function
  5225.             ____________________________________________________________JNZ     E
  5226.             MM_resident_init_exit____________________; failed return to the
  5227.             _______________________________________________________________      
  5228.             ; application
  5229.             
  5230.           ;;
  5231.             ;   DETERMINE WHETHER APPLICATION CAN RUN WITH THIS NUMBER_____      
  5232.             ______________________________________________________________;
  5233.             ;   OF TOTAL AND UNALLOCATED______________________________PAGES      
  5234.             ______________________________________________________________;
  5235.           ;;
  5236.                     
  5237.  
  5238.             ____________________________________________________________MOV     B
  5239.             YTE PTR EMM_status, insuff_total_pages_________________________
  5240.             _______________________________________________________________      
  5241.             ;check total pages
  5242.             ____________________________________________________________CMP     a
  5243.             pplication_pages_req, DX
  5244.             _____________________________________________________________JA     E
  5245.             MM_resident_init_exit
  5246.             
  5247.             ____________________________________________________________MOV     B
  5248.             YTE PTR EMM_status, insuff_unalloc_pages
  5249.             ____________________________________________________________CMP     a
  5250.             pplication_pages_req, BX_______________;check unallocated pages
  5251.             _____________________________________________________________JA     E
  5252.             MM_resident_init_exit
  5253.             
  5254.           ;;
  5255.             ;   GET AN EMM HANDLE AND SAVE IT______________________________      
  5256.             ______________________________________________________________;
  5257.             ;   ALLOCATE THE NUMBER OF PAGES THE APPLICATION REQUIRES______      
  5258.             ______________________________________________________________;
  5259.           ;;
  5260.                     
  5261.  
  5262.             ____________________________________________________________MOV     A
  5263.             H, allocate_pages____________________________; get a handle and
  5264.             ____________________________________________________________MOV     B
  5265.             X, application_pages_req_______________________; allocate pages
  5266.             ____________________________________________________________INT     E
  5267.             MM_interrupt___________________________________; to that handle
  5268.             
  5269.             ____________________________________________________________MOV     E
  5270.             MM_status, AH_________________________________; save the status
  5271.             
  5272.             EMM_resident_init_exit:
  5273.             
  5274.  
  5275.  
  5276.           4-30                         300275-003Example expanded memory programs
  5277.  
  5278.  
  5279.  
  5280.  
  5281.  
  5282.  
  5283.  
  5284.  
  5285.           ;;
  5286.             ;   RETURN TO THE APPLICATION__________________________________      
  5287.             ______________________________________________________________;
  5288.           ;;
  5289.                     
  5290.  
  5291.             ____________________________________________________________RET      
  5292.             ; return to the
  5293.             _______________________________________________________________      
  5294.             ; application
  5295.             
  5296.           EMM_resident_init        ENDP
  5297.  
  5298.  
  5299.  
  5300.  
  5301.  
  5302.  
  5303.  
  5304.  
  5305.  
  5306.  
  5307.  
  5308.  
  5309.  
  5310.  
  5311.  
  5312.  
  5313.  
  5314.  
  5315.  
  5316.  
  5317.  
  5318.  
  5319.  
  5320.  
  5321.  
  5322.  
  5323.  
  5324.  
  5325.  
  5326.  
  5327.  
  5328.  
  5329.  
  5330.  
  5331.  
  5332.  
  5333.  
  5334.  
  5335.  
  5336.  
  5337.  
  5338.  
  5339.  
  5340.  
  5341.  
  5342.           Example expanded memory programs300275-003                    4-31
  5343.  
  5344.  
  5345.  
  5346.  
  5347.  
  5348.  
  5349.  
  5350.  
  5351.           
  5352.           ;;
  5353.             ;______________________________________________________________      
  5354.             ______________________________________________________________;
  5355.             ;_____________________________EXAMPLE PROCEDURE #3   EMM ACCESS      
  5356.             ______________________________________________________________;
  5357.             ;______________________________________________________________      
  5358.             ______________________________________________________________;
  5359.             ;_____This example PROCEDURE performs the following processing:      
  5360.             ______________________________________________________________;
  5361.             ;_________1. Maps the logical page specified by logical_page at      
  5362.             ______________________________________________________________;
  5363.             ;___________   the physical page specified by physical_page. It      
  5364.             ______________________________________________________________;
  5365.             ;_______________________   uses the handle saved in EMM_handle.      
  5366.             ______________________________________________________________;
  5367.             ;_________2. Save the status returned by the EMM in EMM_status.      
  5368.             ______________________________________________________________;
  5369.             ;_________________________________3. Return to the application.      
  5370.             ______________________________________________________________;
  5371.             ;______________________________________________________________      
  5372.             ______________________________________________________________;
  5373.           ;;
  5374.           
  5375.           EMM_access PROC                    NEAR
  5376.             _______________________________________________________________
  5377.           ;;
  5378.             ;   MAP THE LOGICAL PAGE SPECIFIED BY logical_page AT THE______      
  5379.             ______________________________________________________________;
  5380.             ;   PHYSICAL PAGE SPECIFIED BY physical_page___________________      
  5381.             ______________________________________________________________;
  5382.           ;;
  5383.                     
  5384.  
  5385.             ____________________________________________________________MOV     A
  5386.             H, map_handle_page_______________________________; map the page
  5387.             ____________________________________________________________MOV     D
  5388.             X, EMM_handle
  5389.             ____________________________________________________________MOV     B
  5390.             X, logical_page
  5391.             ____________________________________________________________MOV     A
  5392.             L, physical_page
  5393.             ____________________________________________________________INT     E
  5394.             MM_interrupt
  5395.             
  5396.           ;;
  5397.             ;      RETURN THE STATUS_______________________________________      
  5398.             ______________________________________________________________;
  5399.           ;;
  5400.                     
  5401.  
  5402.             ____________________________________________________________MOV     E
  5403.             MM_status, AH_________________________________; save the status
  5404.             
  5405.           ;;
  5406.  
  5407.  
  5408.           4-32                         300275-003Example expanded memory programs
  5409.  
  5410.  
  5411.  
  5412.  
  5413.  
  5414.  
  5415.  
  5416.  
  5417.             ;      RETURN TO THE APPLICATION_______________________________      
  5418.             ______________________________________________________________;
  5419.           ;;
  5420.                     
  5421.  
  5422.             ____________________________________________________________RET      
  5423.             ; return to the
  5424.             _______________________________________________________________      
  5425.             ; application
  5426.             
  5427.           EMM_access ENDP
  5428.  
  5429.  
  5430.  
  5431.  
  5432.  
  5433.  
  5434.  
  5435.  
  5436.  
  5437.  
  5438.  
  5439.  
  5440.  
  5441.  
  5442.  
  5443.  
  5444.  
  5445.  
  5446.  
  5447.  
  5448.  
  5449.  
  5450.  
  5451.  
  5452.  
  5453.  
  5454.  
  5455.  
  5456.  
  5457.  
  5458.  
  5459.  
  5460.  
  5461.  
  5462.  
  5463.  
  5464.  
  5465.  
  5466.  
  5467.  
  5468.  
  5469.  
  5470.  
  5471.  
  5472.  
  5473.  
  5474.           Example expanded memory programs300275-003                    4-33
  5475.  
  5476.  
  5477.  
  5478.  
  5479.  
  5480.  
  5481.  
  5482.  
  5483.           ;;
  5484.             ;______________________________________________________________      
  5485.             ______________________________________________________________;
  5486.             ;________________________EXAMPLE PROCEDURE #4   EMM TERMINATION      
  5487.             ______________________________________________________________;
  5488.             ;______________________________________________________________      
  5489.             ______________________________________________________________;
  5490.             ;_____This example PROCEDURE performs the following processing:      
  5491.             ______________________________________________________________;
  5492.             ;____________1. "Close" the EMM handle assigned to your program      
  5493.             ______________________________________________________________;
  5494.             ;____________   and deallocates the pages EMM allocated to your      
  5495.             ______________________________________________________________;
  5496.             ;___________   program. It uses the handle saved in EMM_handle.      
  5497.             ______________________________________________________________;
  5498.             ;_________2. Save the status returned by the EMM in EMM_status.      
  5499.             ______________________________________________________________;
  5500.             ;_________________________________3. Return to the application.      
  5501.             ______________________________________________________________;
  5502.             ;______________________________________________________________      
  5503.             ______________________________________________________________;
  5504.           ;;
  5505.           
  5506.           EMM_terminate PROC                 NEAR
  5507.             
  5508.           ;;
  5509.             ;   CLOSE THE EMM HANDLE_______________________________________      
  5510.             ______________________________________________________________;
  5511.             ;   DEALLOCATE ALL PAGES ALLOCATED TO IT_______________________      
  5512.             ______________________________________________________________;
  5513.           ;;
  5514.                     
  5515.  
  5516.             ____________________________________________________________MOV     A
  5517.             H, deallocate_pages______________________; close the handle and
  5518.             ____________________________________________________________MOV     D
  5519.             X, EMM_handle____________________________; deallocate all pages
  5520.             ____________________________________________________________INT     E
  5521.             MM_interrupt__________________________________; allocated to it
  5522.             
  5523.           ;;
  5524.             ;   RETURN THE STATUS__________________________________________      
  5525.             ______________________________________________________________;
  5526.           ;;
  5527.                     
  5528.  
  5529.             ____________________________________________________________MOV     E
  5530.             MM_status, AH_________________________________; save the status
  5531.             
  5532.           ;;
  5533.             ;   RETURN TO THE APPLICATION__________________________________      
  5534.             ______________________________________________________________;
  5535.           ;;
  5536.                     
  5537.  
  5538.  
  5539.  
  5540.           4-34                         300275-003Example expanded memory programs
  5541.  
  5542.  
  5543.  
  5544.  
  5545.  
  5546.  
  5547.  
  5548.  
  5549.             ____________________________________________________________RET      
  5550.             ; return to the
  5551.             _______________________________________________________________      
  5552.             ; application
  5553.             
  5554.             EMM_terminate      ENDP
  5555.  
  5556.  
  5557.  
  5558.  
  5559.  
  5560.  
  5561.  
  5562.  
  5563.  
  5564.  
  5565.  
  5566.  
  5567.  
  5568.  
  5569.  
  5570.  
  5571.  
  5572.  
  5573.  
  5574.  
  5575.  
  5576.  
  5577.  
  5578.  
  5579.  
  5580.  
  5581.  
  5582.  
  5583.  
  5584.  
  5585.  
  5586.  
  5587.  
  5588.  
  5589.  
  5590.  
  5591.  
  5592.  
  5593.  
  5594.  
  5595.  
  5596.  
  5597.  
  5598.  
  5599.  
  5600.  
  5601.  
  5602.  
  5603.  
  5604.  
  5605.  
  5606.           Example expanded memory programs300275-003                    4-35
  5607.  
  5608.  
  5609.  
  5610.  
  5611.  
  5612.  
  5613.  
  5614.  
  5615.           ;;
  5616.             ;______________________________________________________________      
  5617.             ______________________________________________________________;
  5618.             ;_____________________EXAMPLE PROCEDURE #5   EMM SAVE MAP STATE      
  5619.             ______________________________________________________________;
  5620.             ;______________________________________________________________      
  5621.             ______________________________________________________________;
  5622.             ;_____This example PROCEDURE performs the following processing:      
  5623.             ______________________________________________________________;
  5624.             ;_____________________1. Saves the page mapping register state.      
  5625.             ______________________________________________________________;
  5626.             ;_________________________2. Save the EMM status in EMM_status.      
  5627.             ______________________________________________________________;
  5628.             ;________________________3. Return to the resident application.      
  5629.             ______________________________________________________________;
  5630.             ;______________________________________________________________      
  5631.             ______________________________________________________________;
  5632.           ;;
  5633.           
  5634.           EMM_save_map_state PROC            NEAR
  5635.           
  5636.             ____________________________________________________________MOV     A
  5637.             H, save_page_map_________________________; save the contents of
  5638.             ____________________________________________________________MOV     D
  5639.             X, EMM_handle________________________________; the page mapping
  5640.             ____________________________________________________________INT     E
  5641.             MM_interrupt________________________________________; registers
  5642.             
  5643.             ____________________________________________________________MOV     E
  5644.             MM_status, AH_________________________________; save the status
  5645.             
  5646.             ____________________________________________________________RET      
  5647.             ; return to the
  5648.             _______________________________________________________________      
  5649.             ; application
  5650.             
  5651.           EMM_save_map_state      ENDP
  5652.  
  5653.  
  5654.  
  5655.  
  5656.  
  5657.  
  5658.  
  5659.  
  5660.  
  5661.  
  5662.  
  5663.  
  5664.  
  5665.  
  5666.  
  5667.  
  5668.  
  5669.  
  5670.  
  5671.  
  5672.           4-36                         300275-003Example expanded memory programs
  5673.  
  5674.  
  5675.  
  5676.  
  5677.  
  5678.  
  5679.  
  5680.  
  5681.           ;;
  5682.             ;______________________________________________________________      
  5683.             ______________________________________________________________;
  5684.             ;__________________EXAMPLE PROCEDURE #6   EMM RESTORE MAP STATE      
  5685.             ______________________________________________________________;
  5686.             ;______________________________________________________________      
  5687.             ______________________________________________________________;
  5688.             ;_____This example PROCEDURE performs the following processing:      
  5689.             ______________________________________________________________;
  5690.             ;________________1. Restore the page mapping register state, if     p
  5691.             ossible._______________________________________________________     ;
  5692.             ;_________________________2. Save the EMM status in EMM_status.      
  5693.             ______________________________________________________________;
  5694.             ;________________________3. Return to the resident application.      
  5695.             ______________________________________________________________;
  5696.             ;______________________________________________________________      
  5697.             ______________________________________________________________;
  5698.           ;;
  5699.             
  5700.           EMM_restore_map_state PROC         NEAR
  5701.             
  5702.             ____________________________________________________________MOV     A
  5703.             H, restore_page_map______________________; restore the contents
  5704.             ____________________________________________________________MOV     D
  5705.             X, EMM_handle_____________________________; of the page mapping
  5706.             ____________________________________________________________INT     E
  5707.             MM_interrupt________________________________________; registers
  5708.             
  5709.             ____________________________________________________________MOV     E
  5710.             MM_status, AH_________________________________; save the status
  5711.             
  5712.             ____________________________________________________________RET      
  5713.             ; return to the
  5714.             _______________________________________________________________      
  5715.             ; application
  5716.             
  5717.           EMM_restore_map_state      ENDP
  5718.  
  5719.  
  5720.  
  5721.  
  5722.  
  5723.  
  5724.  
  5725.  
  5726.  
  5727.  
  5728.  
  5729.  
  5730.  
  5731.  
  5732.  
  5733.  
  5734.  
  5735.  
  5736.  
  5737.  
  5738.           Example expanded memory programs300275-003                    4-37
  5739.  
  5740.  
  5741.  
  5742.  
  5743.  
  5744.  
  5745.  
  5746.  
  5747.           GLOSSARY
  5748.  
  5749.           This glossary defines some of the terms that are used frequently
  5750.           in this specification.  The terms are listed in alphabetical
  5751.           order.
  5752.  
  5753.           Most of these terms are defined for readers who understand
  5754.           technical terminology and are familiar with IBM PCs, XTs, and ATs
  5755.           or compatibles.
  5756.  
  5757.  
  5758.           Application program
  5759.  
  5760.           An application program is the program you write and your customer
  5761.           uses.  Some categories of application software are word
  5762.           processors, database managers, spreadsheet managers, and project
  5763.           managers.
  5764.  
  5765.  
  5766.           Conventional memory
  5767.  
  5768.           Conventional memory refers to the memory DOS recognizes.  In PCs,
  5769.           XTs, and ATs, this is memory between 0 and 640K bytes.  Because
  5770.           application programs let DOS manage their memory, they can use
  5771.           only conventional memory.
  5772.  
  5773.  
  5774.           EMM
  5775.  
  5776.           See Expanded Memory Manager.
  5777.  
  5778.  
  5779.           EMM functions
  5780.  
  5781.           The EMM functions are a set of standard interfaces to expanded
  5782.           memory.  They provide application programs with the operators
  5783.           required to use expanded memory.
  5784.  
  5785.  
  5786.           EMM handle
  5787.  
  5788.           An EMM handle is a value that the EMM assigns to a file or a
  5789.           device.  Previous versions of this specification referred to an
  5790.           EMM handle as a Process ID.
  5791.  
  5792.  
  5793.           EMM Status code
  5794.  
  5795.           A code that an EMM function returns which indicates something
  5796.           about the result of running the function.  Some status codes may
  5797.           indicate whether the function worked correctly and others may
  5798.           tell you something about the expanded memory hardware or
  5799.           software.
  5800.  
  5801.  
  5802.  
  5803.  
  5804.           Glossary-38                  300275-003
  5805.  
  5806.  
  5807.  
  5808.  
  5809.  
  5810.  
  5811.  
  5812.  
  5813.           Expanded memory 
  5814.  
  5815.           Expanded memory is a special kind of memory that goes beyond
  5816.           DOS's 640K-byte limit.  Application programs that adhere to the
  5817.           Lotus/Intel Expanded Memory Specification can use the Expanded
  5818.           Memory Manager (EMM) to manage expanded memory just as other
  5819.           programs use DOS to manage conventional memory.
  5820.  
  5821.  
  5822.           Expanded Memory Manager
  5823.  
  5824.           The Expanded Memory Manager (EMM) is a standard device driver
  5825.           that manages expanded memory in much the same way DOS manages
  5826.           conventional memory.
  5827.  
  5828.  
  5829.           Extended memory
  5830.  
  5831.           Extended memory is the 15M-byte address space outside the memory
  5832.           DOS can access.  This address space is of little use to those
  5833.           application programs that use DOS.  DOS does not recognized
  5834.           memory above 640K bytes; the XENIX operating system uses extended
  5835.           memory.
  5836.  
  5837.  
  5838.           Logical page
  5839.  
  5840.           The EMM allocates expanded memory in 16K-byte units called
  5841.           logical pages.
  5842.  
  5843.  
  5844.           Mapping
  5845.  
  5846.           Mapping is the process of making a logical page of memory
  5847.           available for the processor to use.  Mapping is done within one
  5848.           of the four physical pages defined by this specification.
  5849.  
  5850.  
  5851.           Page frame
  5852.  
  5853.           A page frame is the collection of four 16k-byte contiguous,
  5854.           physical pages from which an application program accesses
  5855.           expanded memory.
  5856.  
  5857.  
  5858.           Page frame base address
  5859.  
  5860.           A page frame base address is the location (in segment format) of
  5861.           the first byte of the page frame.
  5862.  
  5863.  
  5864.  
  5865.  
  5866.  
  5867.  
  5868.  
  5869.  
  5870.                                        300275-003                Glossary-39
  5871.  
  5872.  
  5873.  
  5874.  
  5875.  
  5876.  
  5877.  
  5878.  
  5879.           Physical page
  5880.  
  5881.           A physical page is the range of memory addresses occupied by a
  5882.           single 16k-byte page.  The 16k-byte page is one of the four pages
  5883.           defined as a page frame.
  5884.  
  5885.  
  5886.           Process ID
  5887.  
  5888.           See EMM handle.
  5889.  
  5890.  
  5891.           Resident application program
  5892.  
  5893.           A resident application program is loaded by DOS, executes, and
  5894.           remains resident in the system after it returns control to DOS.
  5895.           This type of program occupies memory and is usually invoked by
  5896.           the operating system, an application program, or the hardware.
  5897.           Some examples of resident application programs are RAM disk
  5898.           drivers, print spoolers, and "pop-up" desktop programs.
  5899.  
  5900.  
  5901.           Transient application program
  5902.  
  5903.           A transient application program is loaded by DOS, executes, and
  5904.           doesn't remain in the system after it returns control to DOS.
  5905.           After a transient application program returns control to DOS, the
  5906.           memory it used is available for other programs.
  5907.  
  5908.  
  5909.  
  5910.  
  5911.  
  5912.  
  5913.  
  5914.  
  5915.  
  5916.  
  5917.  
  5918.  
  5919.  
  5920.  
  5921.  
  5922.  
  5923.  
  5924.  
  5925.  
  5926.  
  5927.  
  5928.  
  5929.  
  5930.  
  5931.  
  5932.  
  5933.  
  5934.  
  5935.  
  5936.           Glossary-40                  300275-003
  5937.  
  5938.  
  5939.  
  5940.  
  5941.