home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / visionix / vvdsu.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-12-28  |  12.4 KB  |  620 lines

  1. {
  2. ════════════════════════════════════════════════════════════════════════════
  3.  
  4.  Visionix Virtual DMA Services Unit (VVDS)
  5.    Version 0.1
  6.  Copyright 1991,92,93 Visionix
  7.  ALL RIGHTS RESERVED
  8.  
  9. ────────────────────────────────────────────────────────────────────────────
  10.  
  11.  Revision history in reverse chronological order:
  12.  
  13.  Initials  Date      Comment
  14.  --------  --------  -------------------------------------------------------
  15.  
  16.  mep       03/27/93  Unit created.
  17.  
  18. ────────────────────────────────────────────────────────────────────────────
  19. }
  20.  
  21. (*-
  22.  
  23. [TEXT]
  24.  
  25. <Overview>
  26.  
  27. The VVDSu unit implements functions for the Microsoft/IBM Virtual
  28. DMA Services (VDS) specification.  The virtual DMA services specifications
  29. supplies services which allow for proper first and second party DMA
  30. operations on PC/AT computers which are running in virtual memory
  31. environments.  It includes services to get the physical address of
  32. virtual memory locations; to get a scatter/gather list of virtualy
  33. fragmented memory buffers; to allocate DMA translation buffer, and more.
  34.  
  35. <Interface>
  36.  
  37. -*)
  38.  
  39. Unit VVDSu;
  40.  
  41. Interface
  42.  
  43. {────────────────────────────────────────────────────────────────────────────}
  44.  
  45. Const
  46.  
  47.   {-------------------------------------------}
  48.   { Product Numbers - use with VVDSGetVersion }
  49.   {-------------------------------------------}
  50.  
  51.   vdspnQMAPS      = $0000;  { Quadtel's QMAPS }
  52.   vdspnHPMM       = $0000;  { Hewlett-Packard's HPMM.SYS }
  53.   vdspnEMM386     = $0001;  { Microsoft's EMM386.EXE }
  54.   vdspn386MAX     = $4560;  { Qualitas' 386MAX }
  55.   vdspnMC         = $4D43;  { V Communication's Memory Commander }
  56.   vdspnQEMM386    = $5145;  { Quarterdeck's QEMM-386 }
  57.  
  58.   vdsMaxArray     = $F;
  59.  
  60.   {-----------------------------------------}
  61.   { Version Flags - use with VVDSGetVersion }
  62.   {-----------------------------------------}
  63.  
  64.   vdsvfPCXTBus    = $1;     { DMA in first megabyte only }
  65.   vdsvfPhyBuf     = $2;     { Physical buffer/Remap region in first megabyte }
  66.   vdsvfAutoRemap  = $4;     { Automatic remap enabled }
  67.   vdsvfPhyCont    = $8;     { All memory is physically contiguous }
  68.  
  69. Type
  70.  
  71.   TVDSErr = BYTE;
  72.  
  73.   {---}
  74.  
  75.   TDDS = RECORD  { DMA descriptor }
  76.  
  77.     RegionSize    : LONGINT;
  78.     Offset        : LONGINT;
  79.     SegSelector   : WORD;
  80.     BufferID      : WORD;
  81.     PhysicalAddr  : LONGINT;
  82.  
  83.   END;
  84.   PDDS = ^TDDS;
  85.  
  86.   {---}
  87.  
  88.   TEDDS_Header = RECORD
  89.  
  90.     RegionSize    : LONGINT;
  91.     Offset        : LONGINT;
  92.     SegSelector   : WORD;
  93.     Rsvp          : WORD;
  94.     NumAvail      : WORD;
  95.     NumUsed       : WORD;
  96.  
  97.   END;
  98.  
  99.   TEDDS_Region = RECORD
  100.  
  101.     PhysicalAddr  : LONGINT;
  102.     Size          : LONGINT;
  103.  
  104.   END;
  105.  
  106.   TEDDS_Array = Array[0..vdsMaxArray] of TEDDS_Region;
  107.  
  108.   TEDDS = RECORD { Extended DMA descriptor }
  109.  
  110.     Header        : TEDDS_Header;
  111.     Region        : TEDDS_Array;
  112.  
  113.   END;
  114.   PEDDS = ^TEDDS;
  115.  
  116.   {---}
  117.  
  118.   TEDDSPageTable_Header = RECORD
  119.  
  120.     RegionSize    : LONGINT;
  121.     Offset        : LONGINT;
  122.     SegSelector   : WORD;
  123.     Rsvp          : WORD;
  124.     NumAvail      : WORD;
  125.     NumUsed       : WORD;
  126.  
  127.   END;
  128.  
  129.   TEDDSPageTable_Region = RECORD
  130.  
  131.     Entry         : LONGINT;
  132.  
  133.   END;
  134.  
  135.   TEDDSPageTable_Array = Array[0..vdsMaxArray] of TEDDSPageTable_Region;
  136.  
  137.   TEDDSPageTable = RECORD { Extended DMA descriptor with page table entries }
  138.  
  139.     Header        : TEDDSPageTable_Header;
  140.     PageTable     : TEDDSPageTable_Array;
  141.  
  142.   END;
  143.   PEDDSPageTable = ^TEDDSPageTable;
  144.  
  145. {────────────────────────────────────────────────────────────────────────────}
  146.  
  147. Function  VVDSErrorToStr(              ErrorCode      : TVDSErr   ) : STRING;
  148.  
  149. Function  VVDSInstalled                                             : BOOLEAN;
  150.  
  151. Function  VVDSGetVersion(          Var Version        : STRING;
  152.                                    Var ProductNum     : WORD;
  153.                                    Var ProductRev     : WORD;
  154.                                    Var MaxDMABufSize  : LONGINT;
  155.                                    Var Flags          : WORD      ) : TVDSErr;
  156.  
  157. Function  VVDSLockRegion(              Region         : PDDS;
  158.                                        Flags          : WORD      ) : TVDSErr;
  159.  
  160. Function  VVDSUnlockRegion(            Region         : PDDS;
  161.                                        Flags          : WORD      ) : TVDSErr;
  162.  
  163. Function  VVDSScatGatLockRegion(       Region         : PEDDS;
  164.                                        Flags          : WORD      ) : TVDSErr;
  165.  
  166. Function  VVDSScatGatUnlockRegion(     Region         : PEDDS;
  167.                                        Flags          : WORD      ) : TVDSErr;
  168.  
  169. Function  VVDSRequestDMABuf(           Region         : PDDS;
  170.                                        Flags          : WORD      ) : TVDSErr;
  171.  
  172. Function  VVDSReleaseDMABuf(           Region         : PDDS;
  173.                                        Flags          : WORD      ) : TVDSErr;
  174.  
  175. Function  VVDSCopyToDMABuf(            Region         : PDDS;
  176.                                        DMABufOfs      : LONGINT   ) : TVDSErr;
  177.  
  178. Function  VVDSCopyFromDMABuf(          Region         : PDDS;
  179.                                        DMABufOfs      : LONGINT   ) : TVDSErr;
  180.  
  181. Function  VVDSDisableDMATrans(         DMAChannel     : WORD      ) : TVDSErr;
  182.  
  183. Function  VVDSEnableDMATrans(          DMAChannel     : WORD;
  184.                                    Var DCountAtZero   : BOOLEAN   ) : TVDSErr;
  185.  
  186. {────────────────────────────────────────────────────────────────────────────}
  187.  
  188. Implementation
  189.  
  190. Uses
  191.  
  192.   DOS,
  193.   VTypesu,
  194.   VGenu;
  195.  
  196. {────────────────────────────────────────────────────────────────────────────}
  197.  
  198. (*-
  199.  
  200. [FUNCTION]
  201.  
  202. Function  VVDSErrorToStr(              ErrorCode      : TVDSErr   ) : STRING;
  203.  
  204. [PARAMETERS]
  205.  
  206. ErrorCode   Errorcode of VDS call.
  207.  
  208. [RETURNS]
  209.  
  210. String of errorcode
  211.  
  212. [DESCRIPTION]
  213.  
  214. Returns a string of the cooresponding VDS errorcode.
  215.  
  216. [SEE-ALSO]
  217.  
  218. [EXAMPLE]
  219.  
  220. -*)
  221.  
  222. Function  VVDSErrorToStr(              ErrorCode      : TVDSErr   ) : STRING;
  223.  
  224. Var
  225.  
  226.   S : STRING;
  227.  
  228. BEGIN
  229.  
  230.   S := '';
  231.  
  232.   Case ErrorCode of
  233.  
  234.     $01 : S := 'Region not in contiguous memory';
  235.     $02 : S := 'Region crossed a physical alignment boundary';
  236.     $03 : S := 'Unable to lock pages';
  237.     $04 : S := 'No buffer available';
  238.     $05 : S := 'Region too large for buffer';
  239.     $06 : S := 'Buffer currently in use';
  240.     $07 : S := 'Invalid memory region';
  241.     $08 : S := 'Region was not locked';
  242.     $09 : S := 'Number of physical pages greater than table length';
  243.     $0A : S := 'Invalid buffer ID';
  244.     $0B : S := 'Copy out of buffer range';
  245.     $0C : S := 'Invalid DMA channel number';
  246.     $0D : S := 'Disable count overflow';
  247.     $0E : S := 'Disable count underflow';
  248.     $0F : S := 'Function not supported';
  249.     $10 : S := 'Reserved flag bits set in DX';
  250.  
  251.   End;
  252.  
  253.   VVDSErrorToStr := S;
  254.  
  255. END;
  256.  
  257. {────────────────────────────────────────────────────────────────────────────}
  258.  
  259. (*-
  260.  
  261. [FUNCTION]
  262.  
  263. Function  VVDSInstalled                                             : BOOLEAN;
  264.  
  265. [PARAMETERS]
  266.  
  267. (none)
  268.  
  269. [RETURNS]
  270.  
  271. Condition of VDS.
  272.  
  273. [DESCRIPTION]
  274.  
  275. Checks for the presence of the Virtual DMA Services.
  276.  
  277. [SEE-ALSO]
  278.  
  279. [EXAMPLE]
  280.  
  281. -*)
  282.  
  283. Function  VVDSInstalled                                             : BOOLEAN;
  284.  
  285. BEGIN
  286.  
  287.   {-------------------------------}
  288.   { This bit test is not reliable }
  289.   {-------------------------------}
  290.  
  291.   VVDSInstalled := ( Byte(Ptr(Seg0040, $7B)^) AND $10 <> 0 );
  292.  
  293. END;
  294.  
  295. {────────────────────────────────────────────────────────────────────────────}
  296.  
  297. (*-
  298.  
  299. [FUNCTION]
  300.  
  301. Function  VVDSGetVersion(          Var Version        : STRING;
  302.                                    Var ProductNum     : WORD;
  303.                                    Var ProductRev     : WORD;
  304.                                    Var MaxDMABufSize  : LONGINT;
  305.                                    Var Flags          : WORD      ) : TVDSErr;
  306.  
  307. [PARAMETERS]
  308.  
  309. (none)
  310.  
  311. [RETURNS]
  312.  
  313. Version        Version of VDS.
  314. ProductNum     Product number of installed VDS.
  315. ProductRev     Revision number of installed VDS.
  316. MaxDMABufSize  for later
  317.  
  318. [DESCRIPTION]
  319.  
  320. [SEE-ALSO]
  321.  
  322. [EXAMPLE]
  323.  
  324. -*)
  325.  
  326. Function  VVDSGetVersion(          Var Version        : STRING;
  327.                                    Var ProductNum     : WORD;
  328.                                    Var ProductRev     : WORD;
  329.                                    Var MaxDMABufSize  : LONGINT;
  330.                                    Var Flags          : WORD      ) : TVDSErr;
  331.  
  332. Var
  333.  
  334.   R : REGISTERS;
  335.  
  336. BEGIN
  337.  
  338.   R.AX := $8102;
  339.   R.DX := $0000;
  340.   R.ES := 0;
  341.   R.DS := 0;
  342.  
  343.   Intr( $4B, R );
  344.  
  345.   If (R.Flags AND FCarry <> 0) Then
  346.   BEGIN
  347.  
  348.     VVDSGetVersion := R.AL;
  349.  
  350.   END
  351.   Else
  352.   BEGIN
  353.  
  354.     Version        := IntToStr( R.AH ) + '.' + IntToStr( R.AL );
  355.     ProductNum     := R.BX;
  356.     ProductRev     := R.CX;
  357.     MaxDMABufSize  := (R.SI SHL 16) + R.DI;  { SI:DI }
  358.     Flags          := R.DX;
  359.  
  360.     VVDSGetVersion := 0;
  361.  
  362.   END;
  363.  
  364. END;
  365.  
  366. {────────────────────────────────────────────────────────────────────────────}
  367.  
  368. (*-
  369.  
  370. [FUNCTION]
  371.  
  372. [PARAMETERS]
  373.  
  374. [RETURNS]
  375.  
  376. [DESCRIPTION]
  377.  
  378. [SEE-ALSO]
  379.  
  380. [EXAMPLE]
  381.  
  382. -*)
  383.  
  384. Function  VVDSLockRegion(              Region         : PDDS;
  385.                                        Flags          : WORD      ) : TVDSErr;
  386.  
  387. BEGIN
  388.  
  389. END;
  390.  
  391. {────────────────────────────────────────────────────────────────────────────}
  392.  
  393. (*-
  394.  
  395. [FUNCTION]
  396.  
  397. [PARAMETERS]
  398.  
  399. [RETURNS]
  400.  
  401. [DESCRIPTION]
  402.  
  403. [SEE-ALSO]
  404.  
  405. [EXAMPLE]
  406.  
  407. -*)
  408.  
  409. Function  VVDSUnlockRegion(            Region         : PDDS;
  410.                                        Flags          : WORD      ) : TVDSErr;
  411.  
  412. BEGIN
  413.  
  414. END;
  415.  
  416. {────────────────────────────────────────────────────────────────────────────}
  417.  
  418. (*-
  419.  
  420. [FUNCTION]
  421.  
  422. [PARAMETERS]
  423.  
  424. [RETURNS]
  425.  
  426. [DESCRIPTION]
  427.  
  428. [SEE-ALSO]
  429.  
  430. [EXAMPLE]
  431.  
  432. -*)
  433.  
  434. Function  VVDSScatGatLockRegion(       Region         : PEDDS;
  435.                                        Flags          : WORD      ) : TVDSErr;
  436.  
  437. BEGIN
  438.  
  439. END;
  440.  
  441. {────────────────────────────────────────────────────────────────────────────}
  442.  
  443. (*-
  444.  
  445. [FUNCTION]
  446.  
  447. [PARAMETERS]
  448.  
  449. [RETURNS]
  450.  
  451. [DESCRIPTION]
  452.  
  453. [SEE-ALSO]
  454.  
  455. [EXAMPLE]
  456.  
  457. -*)
  458.  
  459. Function  VVDSScatGatUnlockRegion(     Region         : PEDDS;
  460.                                        Flags          : WORD      ) : TVDSErr;
  461.  
  462. BEGIN
  463.  
  464. END;
  465.  
  466. {────────────────────────────────────────────────────────────────────────────}
  467.  
  468. (*-
  469.  
  470. [FUNCTION]
  471.  
  472. [PARAMETERS]
  473.  
  474. [RETURNS]
  475.  
  476. [DESCRIPTION]
  477.  
  478. [SEE-ALSO]
  479.  
  480. [EXAMPLE]
  481.  
  482. -*)
  483.  
  484. Function  VVDSRequestDMABuf(           Region         : PDDS;
  485.                                        Flags          : WORD      ) : TVDSErr;
  486.  
  487. BEGIN
  488.  
  489. END;
  490.  
  491. {────────────────────────────────────────────────────────────────────────────}
  492.  
  493. (*-
  494.  
  495. [FUNCTION]
  496.  
  497. [PARAMETERS]
  498.  
  499. [RETURNS]
  500.  
  501. [DESCRIPTION]
  502.  
  503. [SEE-ALSO]
  504.  
  505. [EXAMPLE]
  506.  
  507. -*)
  508.  
  509. Function  VVDSReleaseDMABuf(           Region         : PDDS;
  510.                                        Flags          : WORD      ) : TVDSErr;
  511.  
  512. BEGIN
  513.  
  514. END;
  515.  
  516. {────────────────────────────────────────────────────────────────────────────}
  517.  
  518. (*-
  519.  
  520. [FUNCTION]
  521.  
  522. [PARAMETERS]
  523.  
  524. [RETURNS]
  525.  
  526. [DESCRIPTION]
  527.  
  528. [SEE-ALSO]
  529.  
  530. [EXAMPLE]
  531.  
  532. -*)
  533.  
  534. Function  VVDSCopyToDMABuf(            Region         : PDDS;
  535.                                        DMABufOfs      : LONGINT   ) : TVDSErr;
  536.  
  537. BEGIN
  538.  
  539. END;
  540.  
  541. {────────────────────────────────────────────────────────────────────────────}
  542.  
  543. (*-
  544.  
  545. [FUNCTION]
  546.  
  547. [PARAMETERS]
  548.  
  549. [RETURNS]
  550.  
  551. [DESCRIPTION]
  552.  
  553. [SEE-ALSO]
  554.  
  555. [EXAMPLE]
  556.  
  557. -*)
  558.  
  559. Function  VVDSCopyFromDMABuf(          Region         : PDDS;
  560.                                        DMABufOfs      : LONGINT   ) : TVDSErr;
  561.  
  562. BEGIN
  563.  
  564. END;
  565.  
  566. {────────────────────────────────────────────────────────────────────────────}
  567.  
  568. (*-
  569.  
  570. [FUNCTION]
  571.  
  572. [PARAMETERS]
  573.  
  574. [RETURNS]
  575.  
  576. [DESCRIPTION]
  577.  
  578. [SEE-ALSO]
  579.  
  580. [EXAMPLE]
  581.  
  582. -*)
  583.  
  584. Function  VVDSDisableDMATrans(         DMAChannel     : WORD      ) : TVDSErr;
  585.  
  586. BEGIN
  587.  
  588. END;
  589.  
  590. {────────────────────────────────────────────────────────────────────────────}
  591.  
  592. (*-
  593.  
  594. [FUNCTION]
  595.  
  596. [PARAMETERS]
  597.  
  598. [RETURNS]
  599.  
  600. [DESCRIPTION]
  601.  
  602. [SEE-ALSO]
  603.  
  604. [EXAMPLE]
  605.  
  606. -*)
  607.  
  608. Function  VVDSEnableDMATrans(          DMAChannel     : WORD;
  609.                                    Var DCountAtZero   : BOOLEAN   ) : TVDSErr;
  610.  
  611. BEGIN
  612.  
  613. END;
  614.  
  615. {────────────────────────────────────────────────────────────────────────────}
  616. {────────────────────────────────────────────────────────────────────────────}
  617. {────────────────────────────────────────────────────────────────────────────}
  618.  
  619. BEGIN
  620. END.