home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1986 / 07 / d16bit.jul < prev    next >
Text File  |  1986-07-31  |  7KB  |  226 lines

  1.  
  2. Screen # 0
  3. ( Support for Intel/Lotus Expanded Memory      13:16 08/14/85 )
  4.  
  5. This file contains some simple definitions to allocate
  6. Expanded Memory space and use it for word arrays.
  7.  
  8. The usage within a PC/FORTH program would follow the sequence
  9.   EM-OPEN               ( in program initialization code )
  10.   ...  d @EM ...        ( various array accesses )
  11.   EM-CLOSE              ( de-allocate memory )
  12. If you fail to issue the EM-CLOSE, the Expanded Memory pages
  13. will not be de-allocated and other programs may not be able
  14. to obtain sufficient memory.
  15.  
  16. Copyright (c) 1985 Ray Duncan, Laboratory Microsystems Inc.
  17. P. O. Box 10430, Marina del Rey, CA 90295
  18.  
  19.  
  20. Screen # 1
  21. ( arrays & variables                           13:16 08/14/85 )
  22.  
  23. FORTH DEFINITIONS HEX
  24.  
  25.                                  ( guaranteed device name for )
  26. CREATE em_name  ," EMMXXXX0" 0 C,   ( Expanded Memory Manager )
  27.  
  28. 67 CONSTANT em_int             ( hex interrupt number for EMM )
  29.  
  30. -->
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. Screen # 2
  40. ( test for EMM   device driver header method   14:02 08/14/85 )
  41.  
  42. ( --- status ; =0 if EMM present, -1 if not present )
  43. ( compares name in presumed device driver to guaranteed name )
  44. CODE ems?       SI PUSH
  45.                 DI, DI XOR   ES, DI MOV         ( pick up EMM )
  46.                 DI, # em_int  4 *  MOV           ( int vector )
  47.                 ES: ES, 2 [DI] MOV    DI, # 0A MOV
  48.                 SI, # em_name  MOV    CX, # 8 MOV
  49.                 CLD  REPZ BYTE CMPS     ( compare driver name )
  50.                 SI POP
  51.                 1$ JNZ             ( jump if EMM driver found )
  52.                 AX, # 0 MOV   2$ JMP      ( return FALSE flag )
  53.          1$:    AX, # -1 MOV               ( return TRUE flag )
  54.          2$:    AX PUSH  NEXT,  END-CODE
  55. -->
  56.  
  57.  
  58. Screen # 3
  59. ( get EMM frame, EMM free pages                14:02 08/14/85 )
  60.  
  61. ( --- segment  ;  get segment of the EMM page frame )
  62. ( segment is returned as 0 if function failed )
  63. CODE em_frame   AH, # 41 MOV
  64.                 em_int INT
  65.                 AH, AH OR  1$ JZ  BX, # 0 MOV
  66.         1$:     BX PUSH  NEXT, END-CODE
  67.  
  68. ( returns number of EMM pages which are currently available )
  69. ( ---  free_pages  total_pages )
  70. CODE em_pages   AH, # 42 MOV  em_int INT
  71.                 AH, AH OR  1$ JZ  DX, # 0 MOV  BX, DX MOV
  72.         1$:     BX PUSH  DX PUSH   NEXT,  END-CODE
  73. -->
  74.  
  75.  
  76.  
  77. Screen # 4
  78. ( open EMM & allocate pages                    15:45 08/14/85 )
  79.  
  80. ( get an EMM handle and allocate EMM logical pages to it )
  81. ( pages --- handle | 0 )
  82. CODE em_open    BX POP
  83.                 AH, # 43 MOV    em_int INT
  84.                 AH, AH OR  1$ JZ           ( jump if no error )
  85.                 DX, # 0 MOV               ( if error return 0 )
  86.         1$:     DX PUSH
  87.         2$:     NEXT, END-CODE
  88. -->
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. Screen # 5
  97. ( memory mapping                               16:20 08/14/85 )
  98.  
  99. ( map an EMM logical page owned by handle to a physical page )
  100. ( logical_page  physical_page  handle  --- status; =0 if ok )
  101. CODE em_map             DX POP                       ( handle )
  102.                         AX POP              ( physical page # )
  103.                         BX POP               ( logical page # )
  104.                         AH, # 44 MOV    em_int INT
  105.                         AH, AH OR  1$ JZ   ( jump if no error )
  106.                         AH, AL XCHG        ( AL := error code )
  107.                         AH, # 0 MOV  2$ JMP
  108.                 1$:     AX, # 0 MOV    ( return 0 if no error )
  109.                 2$:     AX PUSH  NEXT, END-CODE
  110. -->
  111.  
  112.  
  113.  
  114.  
  115. Screen # 6
  116. ( release page allocation                      16:35 08/14/85 )
  117.  
  118. ( release an EMM handle and all logical pages allocated to it )
  119. ( handle --- status )
  120. CODE em_close      DX POP    AH, # 45 MOV
  121.                    em_int INT
  122.                    AH, AH OR  1$ JZ        ( jump if no error )
  123.                    AH, AL XCHG             ( AL := error code )
  124.                    AH, # 0 MOV  2$ JMP
  125.               1$:  AX, # 0 MOV         ( return 0 if no error )
  126.               2$:  AX PUSH  NEXT,  END-CODE
  127. -->
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134. Screen # 7
  135. ( EM variables & misc defs                     11:13 10/03/85 )
  136.  
  137. 2VARIABLE $EM_USED           ( bytes of EM assigned to arrays )
  138.  
  139. VARIABLE $EM_PID           ( handle for FORTH from EM manager )
  140. VARIABLE $EM_FRAME               ( segment of EM paging frame )
  141.  
  142. ( d1 --- d2 ; quick double number multiplies )
  143. : D2*   2DUP D+ ;
  144. : D4*   D2* D2* ;
  145. : D8*   D4* D2* ;
  146.  
  147. ( d ---  ; compile a double number )
  148. : D,    HERE 2!  4 ALLOT ;
  149. -->
  150.  
  151.  
  152.  
  153. Screen # 8
  154. ( EM array alignment, EM-CLOSE                 14:02 10/04/85 )
  155.  
  156. ( --- ; align EM on 2-byte boundary for single int array )
  157. : WALIGN        $EM_USED 2@  OVER 1 AND 0 D+
  158.                 $EM_USED 2! ;
  159.  
  160. ( --- ; release Expanded Memory allocation )
  161. : EM-CLOSE      $EM_PID @ DUP 0=  ABORT" EM not opened"
  162.                 em_close  ABORT" Can't release memory"
  163.                 $EM_PID OFF ;
  164. -->
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172. Screen # 9
  173. ( EM-OPEN                                      10:01 10/04/85 )
  174.  
  175. ( --- ; establish availability of Expanded Memory & allocate )
  176. : EM-OPEN       $EM_PID @   IF EM-CLOSE THEN
  177.                 ems? ABORT" Memory manager not installed"
  178.                 em_frame DUP 0= ABORT" EM Frame not valid"
  179.                 $EM_FRAME !          ( save EM paging segment )
  180.                 em_pages SWAP DROP 4000 UM*
  181.                 $EM_USED 2@ D<
  182.                 ABORT" Insufficient expanded memory available"
  183.                 $EM_USED 2@  4000 UM/MOD SWAP
  184.                 IF 1+ THEN            ( round up to next page )
  185.                 em_open DUP 0= ABORT" Can't get EMM handle"
  186.                 $EM_PID !  ;
  187. -->
  188.  
  189.  
  190.  
  191. Screen # 10
  192. ( EM-ARRAY      word array                     12:49 10/03/85 )
  193.  
  194. ( d_cells --- ;          compiling )
  195. ( d_cell# --- em_daddr ; executing )
  196. : EM-ARRAY  CREATE  WALIGN                ( word align EM ptr )
  197.                     2DUP 1. D-  D,           ( highest cell # )
  198.                     D2*            ( *2 for # of bytes needed )
  199.                     $EM_USED 2@       ( get current EM offset )
  200.                     2DUP D,                         ( save it )
  201.                     D+  $EM_USED 2!        ( update EM offset )
  202.             DOES>   DUP >R 2@       ( get # of cells declared )
  203.                     2OVER DU<  ABORT" Index out of bounds"
  204.                     D2*                 ( cell# *2 for offset )
  205.                     R> 4 + 2@ D+ ;            ( + base offset )
  206. -->
  207.  
  208.  
  209.  
  210. Screen # 11
  211. ( @EM !EM                                      13:05 10/03/85 )
  212.  
  213. ( em_daddr --- n )
  214. : @EM           4000 UM/MOD 0        ( pa_offs log_pa phys_pa )
  215.                 $EM_PID @  em_map  ABORT" @EM mapping error"
  216.                 $EM_FRAME @ SWAP @L ;
  217.  
  218. ( n em_daddr --- )
  219. : !EM           4000 UM/MOD 0        ( pa_offs log_pa phys_pa )
  220.                 $EM_PID @  em_map  ABORT" !EM mapping error"
  221.                 $EM_FRAME @ SWAP !L ;
  222.  
  223. DECIMAL  CR CR .( EMM management routines loaded. )
  224. CR ?WORKSPACE U. .( bytes left in dictionary. ) CR CR
  225.  
  226.