home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / expand.seq < prev    next >
Text File  |  1991-03-05  |  7KB  |  178 lines

  1. \ EXPANDED.SEQ  An interface to expanded memory for F-PC        by Tom Zimmer
  2.  
  3. comment:
  4.  
  5.   Here is an interface to the EMM (Expanded Memory Manager). I used the
  6. LOTUS/INTEL/MICROSOFT Expanded Memory Sp[ecification Version 4.0 to impliment
  7. these operators, using the assembly examples right out of their manual. Not
  8. all functions are supported, although you can certainly add any additional
  9. ones you might need.  What is supported is I believe sufficient for most
  10. applications.
  11.                                         Tom Zimmer
  12.  
  13. comment;
  14.  
  15. FILES DEFINITIONS
  16.  
  17. VARIABLE EXPAND.SEQ
  18.  
  19. FORTH DEFINITIONS
  20.  
  21. CREATE EMMNAME ,"-T EMMXXXX0"
  22. VARIABLE PAGE-FRAME
  23. VARIABLE EMM-STATUS
  24. VARIABLE USE-EMM        $FFFF USE-EMM !-T       \ allow EMM to be used
  25.  
  26. : EMMOFF        ( -- )          \ disable use of Expanded Memory
  27.                 USE-EMM OFF
  28.                 EMM-STATUS ON ;
  29.  
  30. : EMMON         ( -- )          \ allow use of Expanded Memory if present
  31.                 USE-EMM ON ;
  32.  
  33. \ test the expanded memory system to see if it is present.  This MUST be
  34. \ successful BEFORE any other expanded memory operations may be done.
  35.  
  36. code EMM-PRESENT? ( --- f1 )            \ true  = emm is present
  37.                                         \ false = no emm present
  38.                 cmp use-emm # 0 word    \ do we want to try to use EMM
  39.              0= if      xor ax, ax      \ no, so return false
  40.                         1push
  41.                 then
  42.                 push si
  43.                 push es
  44.                 mov ah, # $35
  45.                 mov al, # $67
  46.                 int $21
  47.                 mov di, # $0A
  48.                 lea si, emmname 1+
  49.                 mov cx, # 8
  50.                 cld
  51.                 repe    cmpsb
  52.                 pop es  pop si
  53.              0= if      mov ax, # true
  54.                 else    mov ax, # false
  55.                 then
  56.                 1push           end-code
  57.  
  58. \ Get the status of the expanded memory system. Should return 0
  59.  
  60. code EMM-STATUS? ( --- )
  61.                 mov ah, # $40           \ request status code
  62.                 int $67
  63.                 mov al, ah              \ ah = status of emm
  64.                 sub ah, ah
  65.                 mov emm-status ax
  66.                 next            end-code
  67.  
  68. \ EMM status code evaluator, prints the error code for any error received.
  69.  
  70. : ?EMMERR       ( --- f1 )              \ test the most recent emm operation
  71.                 emm-status @ ;          \ TRUE if there is a problem.
  72.  
  73. \ Set the PAGE-FRAME variable with the physical segment of the EMM page frame.
  74.  
  75. code EMM-PAGE-FRAME ( --- )
  76.                 mov ah, # $41           \ request page frame segment
  77.                 int $67
  78.                 mov page-frame bx       \ page frame to PAGE-FRAME
  79.                 mov al, ah              \ ah = status
  80.                 sub ah, ah
  81.                 mov emm-status ax
  82.                 next
  83.                 end-code
  84.  
  85. \ return the number of 16k pages that are available for allocation by
  86. \ your application.
  87.  
  88. code EMM-AVAIL-PAGES ( --- pages )
  89.                 mov ah, # $42           \ request unallocated pages
  90.                 int $67
  91.                 mov dx, bx              \ unallocated pages dx
  92.                 mov al, ah              \ ah = status
  93.                 sub ah, ah
  94.                 mov emm-status ax
  95.                 push dx
  96.                 next
  97.                 end-code
  98.  
  99. \ return the total pages of expanded memory in the system. The number you
  100. \ can allocate will likely be less, and is determined by the previous func.
  101.  
  102. code EMM-TOTAL-PAGES ( --- pages )
  103.                 mov ah, # $42           \ request unallocated pages
  104.                 int $67
  105.                 mov al, ah              \ ah = status
  106.                 sub ah, ah
  107.                 mov emm-status ax
  108.                 push dx                 \ dx = total pages
  109.                 next
  110.                 end-code
  111.  
  112. \ Allocates the number of pages you specify, and returns a handle to the
  113. \ pages if successful.
  114.  
  115. code EMM-ALLOC-PAGES ( pages --- handle )
  116.                 pop bx                  \ number of pages to allocate
  117.                 mov ah, # $43           \ allocate pages function
  118.                 int $67
  119.                 mov al, ah              \ ah = status
  120.                 sub ah, ah
  121.                 mov emm-status ax
  122.                 push dx                 \ dx = handle of pages allocated
  123.                 next
  124.                 end-code                \ in the range 1 to 255
  125.  
  126. \ This un-suspecting function actually makes the expanded memory available
  127. \ for your use, by mapping the logical expanded memory into the physical
  128. \ page specified in the PAGE-FRAME variable. Each page is a 16k chunk.
  129.  
  130. code EMM-MAP-PAGES ( log-page phy-page handle --- )
  131.                 pop dx                  \ emm handle
  132.                 pop ax                  \ physical page
  133.                 pop bx                  \ logical page
  134.                 mov ah, # $44           \ map pages function
  135.                 int $67
  136.                 mov al, ah              \ ah = status
  137.                 sub ah, ah
  138.                 mov emm-status ax
  139.                 next    end-code
  140.  
  141. \ Deallocate the pages associated with handle. This gives them back to the
  142. \ system for somebody else to use. This MUST be done before exiting back
  143. \ to DOS, or the pages specified by handle will not be available to
  144. \ other programs.
  145.  
  146. code EMM-DEALLOC-PAGES ( handle --- )
  147.                 pop dx                  \ emm handle
  148.                 mov ah, # $45           \ deallocate pages function
  149.                 int $67
  150.                 mov al, ah              \ ah = status
  151.                 sub ah, ah
  152.                 mov emm-status ax
  153.                 next
  154.                 end-code
  155.  
  156. \ return the version number of the installed EMM in BCD
  157. \ (two nibbles packed into the low byte)
  158.  
  159. code EMM-GET-VERSION ( --- version )
  160.                 mov ah, # $46             \ request version funcion
  161.                 int $67
  162.                 sub dx, dx              \ clear dx to receive version
  163.                 mov dl, al              \ version to DL
  164.                 mov al, ah              \ ah = status
  165.                 sub ah, ah
  166.                 mov emm-status ax
  167.                 push dx                 \ push version and result
  168.                 next
  169.                 end-code
  170.  
  171. \ Put the segment of the PAGE-FRAME on the stack under the address specified.
  172.  
  173. code ?EMM:      ( --- page-frame )
  174.                 push page-frame
  175.                 next            end-code
  176.  
  177.  
  178.