home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / alt / msdos / programm / 2222 < prev    next >
Encoding:
Text File  |  1992-08-20  |  6.0 KB  |  166 lines

  1. Newsgroups: alt.msdos.programmer
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!mips!sdd.hp.com!ux1.cso.uiuc.edu!news.cso.uiuc.edu!uxa.cso.uiuc.edu!jas37876
  3. From: jas37876@uxa.cso.uiuc.edu (John A. Slagel)
  4. Subject: Re: Mem to Mem DMA ??
  5. References: <BtAJCz.FAM@news.cso.uiuc.edu>
  6. Message-ID: <BtAwBt.L9y@news.cso.uiuc.edu>
  7. Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
  8. Organization: University of Illinois at Urbana
  9. Date: Thu, 20 Aug 1992 21:14:15 GMT
  10. Lines: 154
  11.  
  12.    In case it helps anyone, here is the article that got me wondering
  13.    about this. I tried the code and it locked my computer up. I don't
  14.    know enough to figure out why.
  15.  
  16. Path: news.cso.uiuc.edu!ux1.cso.uiuc.edu!sdd.hp.com!cs.utexas.edu!uunet!munnari.oz.au!yoyo.aarnet.edu.au!dstos3.dsto.gov.au!egg
  17. From: egg@dstos3.dsto.gov.au
  18. Newsgroups: rec.games.programmer
  19. Subject: DMA: buggy potential gem
  20. Message-ID: <1992Aug10.093104.164299@dstos3.dsto.gov.au>
  21. Date: 10 Aug 92 15:31:04 GMT
  22. Organization: Defence Science and Technology Organisation
  23. Lines: 135
  24.  
  25. Hi folks,
  26.  
  27.   Afew days ago I found an old article from an electronic magazine on
  28. assembly programming. It makes some startling claims about using DMA
  29. memory moves under certain conditions (Read below). I tried everything
  30. I possibly could to get it to work but I dont have the 8259 data sheets.
  31. Has anyone seen it before, used it, or have any suggestions as to why
  32. it does'nt work or if it is actually from someone just having a big
  33. w##k!
  34.  
  35. Themie
  36.  
  37. ---------------------------------------------------------------------------
  38.  
  39.                       DMA Transfers for FAST Memory Moves
  40.  
  41. If you ever have the need for super fast moves of blocks of memory and you
  42. can put up with a lot of restrictions in order to gain the speed there is a
  43. method in the PC environment to move bytes at the rate of one every 3 clock
  44. cycles. Compare that to the clocks for a rep movsb and then say that isn't
  45. fast. This isn't for every programmer and it certainly isn't for every time
  46. you need to move a few bytes.
  47.          The DMA chip is a four channel device. Channel 0 is reserved for
  48. refresh of memory that requires at least 256 consecutive bytes be read some-
  49. where in memory at intervals less than about 4ms. The other three channels
  50. are available for such things as transferring information to and from the
  51. disk drives or the ports. Interesting trivia so far, but not very useful in
  52. moving memory around. It gets worse. The 8259 DMA doesn't know anything about
  53. segments. It only knows a 64k universe. This is where the Page registers come
  54. in. The page registers decide which page (on 64k boundaries) the 8259 will
  55. look at for any operation. There are not, as you might guess, 4 page
  56. registers,but only 2 plus a default. If it is not channel 1 or 2 then it uses
  57. the default register programmed as channel 3.
  58.          A careful reading of the data sheet of the 8259 discloses that it is
  59. capable of doing a memory to memory transfer but only between channels 0 and
  60. 1. That is why this method is a little tricky to use. In order to set up your
  61. own parameters you have to disable the timer from asking for a DMA from chan-
  62. nel 0 every x milliseconds and reconfigure the 8259 and assume the respon-
  63. sibility for doing the memory refresh. It actually sounds worse than it is.
  64. The configuring and re configuring of the 8259 doesn't take all that long, so
  65. the time is made up after only moving a few tens of bytes, and if you move at
  66. least 256 CONSECUTIVE bytes the memory refresh requirement is met for another
  67. 2 or 3 milliseconds. The page registers are taken care of by setting channels
  68. 1 and 3 to the same value.
  69.          Given below is an example of a program I wrote just to test the
  70. idea.  A lot of the setup is too complex to explain in this short article, but
  71. if you are interested in checking it all out you will need a data sheet on
  72. the 8259.  This worked nicely on my machine and should on most compatibles
  73. just the way it is.  With the not-so-compatible it may very well not.  I hope
  74. this listing is well enough commented so you can figure it out and make use of
  75.  
  76.  
  77. it sometime.
  78.  
  79. `                                DMA SOURCE
  80.  
  81. PAGE 60,132
  82. TITLE DMA MEMORY TO MEMORY
  83. DMA      EQU 0
  84. STACK       SEGMENT PUBLIC 'STACK'
  85.      DB  32 DUP('STACK')
  86. STACK       ENDS
  87. DATA     SEGMENT PUBLIC 'DATA'
  88. SOURCE      DW   08000H
  89. TARGET      DW   09000H
  90. NUMBER      DW   800H
  91. INCDEC      DB   0
  92. PAGER       DB   0BH    ;PAGE (O TO F)
  93. FILL     DB 0    ;2 IF A FILL OP
  94. DATA     ENDS
  95. ASSUME      CS:CODE,DS:DATA,ES:DATA
  96. CODE     SEGMENT PUBLIC 'CODE'
  97. START:
  98.      MOV AX,DATA
  99.      MOV DS,AX
  100.      MOV AX,0B800H
  101.      MOV ES,AX
  102. PAGE:
  103.      MOV AL,PAGER ;PAGE TO OPERATE IN
  104.      OUT 83H,AL
  105. UNDMA:
  106.      OUT 0DH,AL   ;MASTER RESET OF DMA
  107.      MOV DX,03D8H
  108.      MOV AL,1
  109.      OUT DX,AL
  110.      MOV AX,SOURCE     ;WHERE IS IT COMING FROM
  111.      OUT 0H,AL
  112.      MOV AL,AH
  113.      OUT 0H,AL
  114.      MOV AX,TARGET     ;WHERE TO PUT IT
  115.      OUT 2H,AL
  116.      MOV AL,AH
  117.      OUT 2H,AL
  118.      MOV AX,NUMBER     ;HOW MANY
  119.      OUT 3H,AL
  120.      MOV AL,AH
  121.      OUT 3H,AL
  122.      MOV AL,009H  ;ENABLE M TO M,COMPRESSED
  123.      OR  AL,FILL  ;WILL BE 2 IF FILL OP
  124.      OUT 8H,AL
  125.      MOV AL,088H  ;BLOCK MODE, INC, READ
  126.      OR  AL,INCDEC     ;WILL BE 20H IF DEC
  127.      OUT 0BH,AL
  128.      MOV AL,85H   ;BLOCK MODE, INC, WRITE
  129.      OR  AL,INCDEC     ;WILL BE 20H IF DEC
  130.      OUT 0BH,AL
  131.      MOV AL,4    ;THIS IS THE REQUEST
  132.      OUT 9,AL    ;DO IT
  133.      MOV AL,9
  134.      OUT DX,AL
  135. RESET:      OUT  0DH,AL  ;THIS IS A MASTER RESET
  136.      OUT 0CH,AL   ;RESET F/L F/F
  137.      MOV AL,01
  138.      OUT 0,AL
  139.      OUT 0,AL
  140. REINIT:
  141.      MOV AL,0
  142.      OUT 83H,AL   ;MOVES REFRESH TO BASE PAGE
  143.      MOV AL,0FFH
  144.      OUT 1,AL
  145.      PUSH   AX
  146.      OUT 1,AL
  147.      OUT 0BH,AL
  148.      INC AL  ;MODE CHAN3
  149.  
  150.      OUT 0BH,AL
  151.      PUSH   AX
  152.      POP AX
  153.      POP AX
  154.      POP AX
  155.      MOV AH,4CH
  156.      INT 21H
  157. CODE     ENDS
  158. END      START
  159. `
  160.  
  161. -- 
  162. ------------------------------------------------------------------------
  163.  John A. Slagel     "My old man used to tell me, before he left this
  164.  j-slagel1@uiuc.edu  shitty world, never chase buses or women- you
  165.                      always get left behind." -The Marlboro Man
  166.