home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / c / XMS_200.ZIP / XMS_200.C < prev    next >
Encoding:
Text File  |  1991-09-17  |  14.3 KB  |  504 lines

  1. /*****************************************************************************\
  2.  
  3.                TriHex XMS Extended Memory ToolBox - Version 2.00
  4.  
  5.                   Copyright (c) 1991 TriHex Universal Systems.
  6.                               All rights reserved.
  7.  
  8.  
  9.         Class       : XMS Extended Memory Managment (Version 2.00)
  10.  
  11.         Author      : Fernando Manuel InĂ¡cio Carreiro
  12.  
  13.         File        : XMS_200.C
  14.  
  15.         Description : Definition of Classes to access XMS.
  16.  
  17.         Portability : ANSI Standard C
  18.  
  19.         Dependency  : Borland Turbo C++ (Version 1.00)
  20.                       Borland Turbo Assembler (Version 2.0)
  21.                       XMS Memory Handler (Version 2.00 or later)
  22.                       IBM PC-DOS Version 3.3 or later
  23.                       IBM PC/XT/AT Hardware Environment
  24.  
  25.             Borland Turbo C++ (Version 1.00) :
  26.  
  27.                 Compiler Options :
  28.  
  29.                     Code Generation :
  30.  
  31.                         Model : Any
  32.                           Code supports all models
  33.                           (Tiny/Small/Medium/Compact/Large/Huge)
  34.  
  35.                         Overlay Support : Yes/No
  36.                           `Yes' for generating safe code for Overlays.
  37.  
  38.                         Word Alignment : Yes/No
  39.                           `Yes' for faster code, `No' for smaller code.
  40.  
  41.                         Duplicate Strings Merged : Yes
  42.                           Produces faster, smaller code.
  43.  
  44.                         Unsigned Characters : Yes/No
  45.                           `Yes' for preffered use of unsigned chars.
  46.  
  47.                         Standard Stack Frame : Yes/No
  48.                           `Yes' for Debugging,
  49.                           `No' for preffered faster, smaller code.
  50.  
  51.                         Test Stack Overflow : No
  52.                           `No' because code use the "interrupt" keyword.
  53.  
  54.                         Floating Point : None
  55.                           `None' because no floating point is used.
  56.  
  57.                         Instruction Set : Any
  58.                           `8086/8088 / 80186 / 80286' can be used.
  59.  
  60.                         Calling Convention : C/Pascal
  61.                           `Pascal' for preffered faster, smaller code.
  62.  
  63.                         Generate Underbars : Yes
  64.                           `Yes' uses Standard Library calls.
  65.  
  66.                         Line Numbers Debug Info : Yes/No
  67.                           `Yes' for Debbuging,
  68.                           `No' for preffered smaller code.
  69.  
  70.                         Debug Info in OBJs : Yes/No
  71.                           `Yes' for Debbuging,
  72.                           `No' for preffered smaller code.
  73.  
  74.                         Treat enums as ints : Yes/No
  75.                           `Yes' for standard code,
  76.                           `No' for preffered faster, smaller code.
  77.  
  78.                         Fast Floating Point : Yes/No
  79.                           No floating point used.
  80.  
  81.                         Assume SS not equal to DS : Yes/No
  82.                           Dependant on model.
  83.  
  84.  
  85.                     C++ Options :
  86.  
  87.                         C++ Virtual Tables : Smart
  88.                           `Smart' for faster/smaller code.
  89.  
  90.                         Out-of-line Inline Functions : Yes/No
  91.                           `Yes' for Debbuging only, else 'No'.
  92.  
  93.  
  94.                     Optimizations :
  95.  
  96.                         Register Optimization : No
  97.                           `No' uses "interrupt" keyword.
  98.  
  99.                         Jump Optimization : Yes/No
  100.                           `Yes' for preffered faster code.
  101.  
  102.                         Register Variables : None
  103.                           `None' uses "interrupt" keyword.
  104.  
  105.                         Optimize for : Size/Speed
  106.                           'Speed' for faster code,
  107.                           'Size' for smaller code.
  108.  
  109.  
  110.                     Source :
  111.  
  112.                         Nested Comments : Yes
  113.                           `Yes' uses nested comments.
  114.  
  115.                         Keywords : Turbo C++
  116.                           `Turbo C++' for C++ and other dependant keywords.
  117.  
  118.  
  119.                     Messages :
  120.  
  121.                         NB! All Warnings & Error Detection On
  122.  
  123.  
  124.                     Segment Names :
  125.  
  126.                        All default Segment names.
  127.  
  128.  
  129.                     Linker : (Linkage Options to be set by main Project)
  130.  
  131.                        Warn duplicate Symbols : Yes
  132.  
  133.                        Case Sensitive Link    : Yes
  134.  
  135.                        "No Stack" Warning     : Yes
  136.                          (Unless Tiny Model)
  137.  
  138.  
  139. \*****************************************************************************/
  140.  
  141. /* Define Inline Assembly */
  142.  
  143.    #pragma inline
  144.  
  145.  
  146. /* Check for C compilation and not C++ */
  147.  
  148.    #ifdef __cplusplus
  149.       #error "Compile this file in C only!"
  150.    #endif
  151.  
  152.  
  153. /* Include Files */
  154.  
  155.    #include <XMS_200.H>  // Header file for this file
  156.  
  157.  
  158. /* Define Constants */
  159.  
  160.    #define Multiplex_Interrupt 0x2F // XMS Interrupt (Multiplex)
  161.    #define XMS_ID              0x80 // XMS ID Byte
  162.  
  163.  
  164. /* Define XMS Function Codes */
  165.  
  166.    #define XMS_Install_Check    0x4300 // XMS Instalation Check
  167.    #define XMS_Driver_Address   0x4310 // XMS Get Driver Address
  168.  
  169.  
  170. /* Define XMS Version 2.00 Sub-Function Codes */
  171.  
  172.    #define XMS_Version          0x00 // Get XMS Version Number
  173.    #define XMS_Request_HMA      0x01 // Request High Memory Area
  174.    #define XMS_Release_HMA      0x02 // Release High Memory Area
  175.    #define XMS_Glb_Ena_A20      0x03 // Global Enable  A20 for HMA
  176.    #define XMS_Glb_Dis_A20      0x04 // Global Disable A20
  177.    #define XMS_Lcl_Ena_A20      0x05 // Local  Enable  A20 for direct
  178.    #define XMS_Lcl_Dis_A20      0x06 // Local  Disable A20
  179.    #define XMS_Query_State_A20  0x07 // Query State of A20
  180.    #define XMS_Query_Free_Mem   0x08 // Query free XMS Memory (not HMA)
  181.    #define XMS_Allocate_Mem     0x09 // Allocate   XMS Memory Block
  182.    #define XMS_Release_Mem      0x0A // Release    XMS Memory Block
  183.    #define XMS_Move_Mem         0x0B // Move/Copy  XMS Memory Block
  184.    #define XMS_Lock_Mem         0x0C //   Lock     XMS Memory Block
  185.    #define XMS_UnLock_Mem       0x0D // UnLock     XMS Memory Block
  186.    #define XMS_Get_Handle_Info  0x0E // Get Handle Information
  187.    #define XMS_ReAllocate_Mem   0x0F // ReAllocate XMS Memory Block
  188.    #define XMS_Request_UMB      0x10 // Request Upper Memory Block
  189.    #define XMS_Release_UMB      0x11 // Release Upper Memory Block
  190.  
  191.  
  192. /* Define Static Variables */
  193.  
  194.    static void (far *_XMS_Driver)(void) = NULL; // Pointer to XMS Driver
  195.  
  196.  
  197. /* Define Functions */
  198.  
  199.    #pragma warn -rvl // All Functions returns values in Assemler
  200.  
  201.    /* Check if XMS Exists (It will also set the XMS Driver pointer) */
  202.  
  203.       boolean pascal _XMS_Check(void)
  204.         {
  205.                asm Mov AX,XMS_Install_Check
  206.                asm INT Multiplex_Interrupt
  207.                asm Sub DX,DX
  208.                asm Mov ES,DX
  209.                asm Cmp AL,XMS_ID
  210.                asm Mov AL,0
  211.                asm JNE Short XE0
  212.  
  213.                asm Mov AX,XMS_Driver_Address
  214.                asm INT Multiplex_Interrupt
  215.                asm Mov DX,BX
  216.                asm Sub AL,AL
  217.                asm Not AL
  218.  
  219.           XE0: asm Mov BX, Offset _XMS_Driver
  220.                asm Mov [BX]  ,DX
  221.                asm Mov [BX+2],ES
  222.         }
  223.  
  224.  
  225.    /* Get XMS Version (LSW = Revision, USW = Version) */
  226.  
  227.       udword pascal _XMS_Version(void)
  228.         {
  229.           asm Mov AH,XMS_Version
  230.           asm Call DWord Ptr [Offset _XMS_Driver]
  231.           asm Mov DX,AX
  232.           asm Mov AX,BX
  233.         }
  234.  
  235.  
  236.    /* Check if HMA Exists */
  237.  
  238.       boolean pascal _XMS_Check_HMA(void)
  239.         {
  240.           asm Mov  AH,XMS_Version
  241.           asm Call DWord Ptr [Offset _XMS_Driver]
  242.           asm Mov  AL,DL
  243.           asm Neg  AL
  244.         }
  245.  
  246.  
  247.    /* Request HMA */
  248.  
  249.       XMS_Status pascal _XMS_Request_HMA(uword Size)
  250.         {
  251.                asm Mov  AH,XMS_Request_HMA
  252.                asm Mov  DX,Size
  253.                asm Call DWord Ptr [Offset _XMS_Driver]
  254.                asm Dec  AL
  255.                asm JZ   Short RQH
  256.                asm Mov  AL,BL
  257.  
  258.           RQH: ;
  259.         }
  260.  
  261.  
  262.    /* Release HMA */
  263.  
  264.       XMS_Status pascal _XMS_Release_HMA(void)
  265.         {
  266.                asm Mov  AH,XMS_Release_HMA
  267.                asm Call DWord Ptr [Offset _XMS_Driver]
  268.                asm Dec  AL
  269.                asm JZ   Short RLH
  270.                asm Mov  AL,BL
  271.  
  272.           RLH: ;
  273.         }
  274.  
  275.  
  276.    /* Enable/Disable A20 Line */
  277.  
  278.       #pragma warn -rvl
  279.  
  280.       XMS_Status pascal _XMS_A20_Line(ubyte Type, toggle State)
  281.         {
  282.                asm Mov  AH,State
  283.                asm Inc  AH
  284.                asm Add  AH,Type
  285.                asm Call DWord Ptr [Offset _XMS_Driver]
  286.                asm Dec  AL
  287.                asm JZ   Short A20
  288.                asm Mov  AL,BL
  289.  
  290.           A20: ;
  291.         }
  292.  
  293.  
  294.    /* Query State of A20 Line */
  295.  
  296.       XMS_Status pascal _XMS_A20_State(toggle *State)
  297.         {
  298.           asm Mov  AH,XMS_Query_State_A20
  299.           asm Call DWord Ptr [Offset _XMS_Driver]
  300.           asm Mov  AH,AL
  301.           asm Neg  AH
  302.           asm Mov  AL,BL
  303.  
  304.           *State = _AH;
  305.         }
  306.  
  307.  
  308.    /* Query State of XMS Total & Largest Available Block Memory */
  309.  
  310.       XMS_Status pascal _XMS_Memory_State(uword *Total, uword *Largest)
  311.         {
  312.           asm Mov  AH,XMS_Query_Free_Mem
  313.           asm Call DWord Ptr [Offset _XMS_Driver]
  314.           asm Mov  CL,BL
  315.  
  316.           *Total   = _DX;
  317.           *Largest = _AX;
  318.  
  319.           asm Mov  AL,CL
  320.         }
  321.  
  322.  
  323.    /* Allocate XMS Memory */
  324.  
  325.       XMS_Status pascal _XMS_Allocate(uword Size, XMS_Handle *Handle)
  326.         {
  327.                asm Mov  DX,Size;
  328.                asm Mov  AH,XMS_Allocate_Mem
  329.                asm Call DWord Ptr [Offset _XMS_Driver]
  330.                asm Dec  AL
  331.                asm JZ   Short XAL
  332.                asm Mov  AL,BL
  333.                asm Sub  DX,DX
  334.                asm Dec  DX
  335.  
  336.           XAL: *Handle = _DX;
  337.         }
  338.  
  339.  
  340.    /* ReAllocate XMS Memory */
  341.  
  342.       XMS_Status pascal _XMS_ReAllocate(uword Size, XMS_Handle Handle)
  343.         {
  344.                asm Mov  BX,Size;
  345.                asm Mov  DX,Handle;
  346.                asm Mov  AH,XMS_ReAllocate_Mem
  347.                asm Call DWord Ptr [Offset _XMS_Driver]
  348.                asm Dec  AL
  349.                asm JZ   Short XRA
  350.                asm Mov  AL,BL
  351.  
  352.           XRA: ;
  353.         }
  354.  
  355.  
  356.    /* Release XMS Memory */
  357.  
  358.       XMS_Status pascal _XMS_Release(XMS_Handle Handle)
  359.         {
  360.                asm Mov  DX,Handle;
  361.                asm Mov  AH,XMS_Release_Mem
  362.                asm Call DWord Ptr [Offset _XMS_Driver]
  363.                asm Dec  AL
  364.                asm JZ   Short XRL
  365.                asm Mov  AL,BL
  366.  
  367.           XRL: ;
  368.         }
  369.  
  370.  
  371.    /* Copy XMS Memory */
  372.  
  373.       XMS_Status pascal _XMS_Copy(XMS_Transfer *Copy_Info)
  374.         {
  375.           #if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
  376.              asm Mov SI,Copy_Info
  377.           #else
  378.              #if defined(__LARGE__)
  379.                 asm Push DS
  380.              #endif
  381.  
  382.              asm LDS SI,Copy_Info
  383.           #endif
  384.  
  385.                asm Mov  AH,XMS_Move_Mem
  386.                asm Call DWord Ptr [Offset _XMS_Driver]
  387.                asm Dec  AL
  388.                asm JZ   Short XMV
  389.                asm Mov  AL,BL
  390.  
  391.           XMV: ;
  392.                #if defined(__LARGE__)
  393.                   asm Pop  DS
  394.                #endif
  395.         }
  396.  
  397.  
  398.    /* Lock XMS Memory */
  399.  
  400.       XMS_Status pascal _XMS_Lock(XMS_Handle Handle, XMS_Address *Address)
  401.         {
  402.                asm Mov  DX,Handle
  403.                asm Mov  AH,XMS_Lock_Mem
  404.                asm Call DWord Ptr [Offset _XMS_Driver]
  405.                asm Dec  AL
  406.                asm JNZ  Short XLK
  407.                asm Mov  CX,BX
  408.  
  409.                #if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
  410.                   asm Mov BX,Word Ptr Address
  411.                   asm Mov Word Ptr [BX  ],CX
  412.                   asm Mov Word Ptr [BX+2],DX
  413.                #else
  414.                   asm LES BX,DWord Ptr Address
  415.                   asm Mov Word Ptr ES:[BX  ],CX
  416.                   asm Mov Word Ptr ES:[BX+2],DX
  417.                #endif
  418.                asm Mov  BL,AL
  419.  
  420.           XLK: asm Mov  AL,BL
  421.         }
  422.  
  423.  
  424.    /* UnLock XMS Memory */
  425.  
  426.       #pragma warn -rvl
  427.  
  428.       XMS_Status pascal _XMS_UnLock(XMS_Handle Handle)
  429.         {
  430.                asm Mov  DX,Handle
  431.                asm Mov  AH,XMS_UnLock_Mem
  432.                asm Call DWord Ptr [Offset _XMS_Driver]
  433.                asm Dec  AL
  434.                asm JZ   Short XUL
  435.                asm Mov  AL,BL
  436.  
  437.           XUL: ;
  438.         }
  439.  
  440.  
  441.    /* Get XMS Handle Information */
  442.  
  443.       #pragma warn -rvl
  444.  
  445.       XMS_Status pascal _XMS_Handle_Info
  446.         ( XMS_Handle  Handle, uword *Size, ubyte *Lock_Count,
  447.                                            ubyte *Available_Handles )
  448.         {
  449.                asm Mov  DX,Handle
  450.                asm Mov  AH,XMS_Get_Handle_Info
  451.                asm Call DWord Ptr [Offset _XMS_Driver]
  452.                asm Dec  AL
  453.                asm JNZ  Short XHI
  454.                asm Mov  CX,BX
  455.  
  456.                *Size              = _DX;
  457.                *Lock_Count        = _CH;
  458.                *Available_Handles = _CL;
  459.  
  460.                asm Mov  BL,AL
  461.  
  462.           XHI: asm Mov  AL,BL
  463.         }
  464.  
  465.  
  466.    /* Request Upper Memory Block */
  467.  
  468.       XMS_Status pascal _XMS_Request_UMB(uword *Size, XMS_UMB_Seg *Segment)
  469.         {
  470.                _DX = *Size;
  471.  
  472.                asm Mov  AH,XMS_Request_UMB
  473.                asm Call DWord Ptr [Offset _XMS_Driver]
  474.                asm Mov  CX,BX
  475.                asm Dec  AL
  476.                asm JZ   Short XQU
  477.                asm Mov  AL,BL
  478.                asm Sub  CX,CX
  479.  
  480.           XQU: *Size    = _DX;
  481.                *Segment = _CX;
  482.         }
  483.  
  484.  
  485.    /* Release Upper Memory Block */
  486.  
  487.       XMS_Status pascal _XMS_Release_UMB(XMS_UMB_Seg Segment)
  488.         {
  489.                asm Mov  DX,Segment;
  490.                asm Mov  AH,XMS_Release_UMB
  491.                asm Call DWord Ptr [Offset _XMS_Driver]
  492.                asm Dec  AL
  493.                asm JZ   Short XLU
  494.                asm Mov  AL,BL
  495.  
  496.           XLU: ;
  497.         }
  498.  
  499.  
  500.    #pragma warn +rvl // No more functions with inline returns
  501.  
  502.  
  503.  
  504. /*****************************************************************************/