home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / NEWS / 554 / JUIN / EMSSTUFF.PAS < prev    next >
Pascal/Delphi Source File  |  1993-10-07  |  3KB  |  124 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 533 of 614
  3. From : Henrik Schmidt-Moeller              2:234/61.15          15 Jun 93  17:00
  4. To   : Ian Lin                             1:249/140.0
  5. Subj : Ems/Xms
  6. ────────────────────────────────────────────────────────────────────────────────
  7. Hiya, Ian...
  8.  
  9.  > Hello (yet again). Who here knows how to access XMS or
  10.  > EMS or both?
  11.  
  12. I've made some procedures for EMS addressing in TP. EMS uses a technic called
  13. bank switching. It reserves a 64k area (EmmSeg) in memory for EMS and maps/
  14. unmaps 16k EMS-pages in this area. Look at interrupt 67h for a complete list of
  15. EMS commands. I haven't had time to comment on these procedures, so if you
  16. don't understand them, feel free to ask. OK, here goes nothing...}
  17.  
  18. VAR
  19.   EmmSeg,EmmHandle : Word;
  20.   Err : Byte;
  21.  
  22. PROCEDURE DeallocateMem(Handle : Word); Forward;
  23.  
  24. PROCEDURE Error(E : String);
  25. BEGIN
  26.   DeallocateMem(Emmhandle);
  27.   WriteLn(#7+E);
  28.   Halt(1);
  29. END;
  30.  
  31. PROCEDURE AllocateMem(LogPages : Word);
  32. BEGIN
  33.   ASM
  34.   MOV  AH,43h
  35.   MOV  BX,LogPages
  36.   INT  67h
  37.   MOV  Err,AH
  38.   MOV  EmmHandle,DX
  39.   END;
  40.   CASE Err OF
  41.     $80 : Error('AllocateMem: Internal error in EMS software');
  42.     $81 : Error('AllocateMem: Malfunction in EMS software');
  43.     $84 : Error('AllocateMem: Undefined function');
  44.     $85 : Error('AllocateMem: No more handles available');
  45.     $87 : Error('AllocateMem: Allocation requested more pages than
  46. are'+#10+#13+ '             physically available; no pages allocated'); $88 :
  47. Error('AllocateMem: Specified more logical pages than are'+#10+#13+ ' currently
  48. available; no pages allocated'); $89 : Error('AllocateMem: Zero pages
  49. requested'); END; END;
  50.  
  51. PROCEDURE MapEmm(PsyPage : Byte; LogPage : Word);
  52. BEGIN
  53.   ASM
  54.   MOV  AH,44h
  55.   MOV  AL,PsyPage
  56.   MOV  BX,LogPage
  57.   MOV  DX,EmmHandle
  58.   INT  67h
  59.   MOV  Err,AH;
  60.   END;
  61.   CASE Err OF
  62.     $80 : Error('MapEmm: Internal error in EMS software');
  63.     $81 : Error('MapEmm: Malfunction in EMS software');
  64.     $83 : Error('MapEmm: Invalid handle');
  65.     $84 : Error('MapEmm: Undefined function');
  66.     $8A : Error('MapEmm: Logical page not assigned to this handle');
  67.     $8B : Error('MapEmm: Physical page number invalid');
  68.   END;
  69. END;
  70.  
  71. PROCEDURE DeallocateMem(Handle : Word);
  72. BEGIN
  73.   ASM
  74.   MOV  AH,45h
  75.   MOV  DX,Handle
  76.   INT  67h
  77.   END;
  78. END;
  79.  
  80. PROCEDURE GetPageSeg;
  81. BEGIN
  82.   ASM
  83.   MOV  AH,41h
  84.   INT  67h
  85.   MOV  EmmSeg,BX
  86.   MOV  Err,AH;
  87.   END;
  88.   CASE Err OF
  89.     $80 : Error('GetPageSeg: Internal error in EMS software');
  90.     $81 : Error('GetPageSeg: Malfunction in EMS software');
  91.     $84 : Error('GetPageSeg: Undefined function');
  92.   END;
  93. END;
  94.  
  95. PROCEDURE GetMaxPages(VAR Num : Word);
  96. VAR
  97.   Dummy : Word;
  98. BEGIN
  99.   ASM
  100.   MOV  AH,42h
  101.   INT  67h
  102.   MOV  Dummy,BX
  103.   MOV  Err,AH;
  104.   END;
  105.   Num:=Dummy;
  106.   CASE Err OF
  107.     $80 : Error('GetMaxPages: Internal error in EMS software');
  108.     $81 : Error('GetMaxPages: Malfunction in EMS software');
  109.     $84 : Error('GetMaxPages: Undefined function');
  110.   END;
  111. END;
  112.  
  113. PROCEDURE WriteMem(Page : Byte;Pos : Integer;Ch : Char);
  114. BEGIN
  115.   Mem[EmmSeg:Page*$4000+Pos]:=Ord(Ch);
  116. END;
  117.  
  118. PROCEDURE ReadMem(Page : Byte;Pos : Integer;VAR Ch : Char);
  119. BEGIN
  120.   Ch:=Chr(Mem[EmmSeg:Page*$4000+Pos]);
  121. END;
  122.  
  123. I hope you find this useful.
  124. Oh, by the way, REMEMBER to DEallocate!!!