home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / DIVERSEN / DOS32V3B / LIB / DMA.ASM < prev    next >
Assembly Source File  |  1995-03-09  |  4KB  |  126 lines

  1. ;--------------------------------------------------------------------------;
  2. ;        DOS32                                                             ;
  3. ;                                                                          ;
  4. ; Written by Adam Seychell                                                 ;
  5. ;
  6. ; A general routine to program the DMA controler.
  7. ;
  8. ;
  9. ;--------------------------------------------------------------------------;
  10. .386
  11.  
  12. .Model flat
  13.  
  14.                         .CODE
  15. Include DMA.INC
  16.  
  17.  
  18. comment $
  19. ╒══════════════════════════════════════════════════════════════════════════╕
  20. │ "DMA_Setup"   PROGRAM A CHANNEL ON THE 8237 DMA CONTROLLER               │
  21. │                                                                          │
  22. │ INPUT:        AL    Mode Register  ( bits 0..1 ignored )                 │
  23. │               AH    channel    0..7                                      │
  24. │               EBX   Physical Base Address ( 0..0ffffffh )                │
  25. │               ECX   Bytes to transfer                                    │
  26. │                                                                          │
  27. └────────────────────────────────────────────────────────────────────────── $
  28. DMA_Setup PROC
  29.  
  30. ;
  31. ; Code has been optimized.
  32. ;
  33.         pushad
  34.         xor     edx,edx
  35.         and     ah,7
  36.         mov     DMA_channel,ah
  37.         and     al,NOT 3
  38.         mov     mode,al
  39.  
  40.         ; -----  set channel mask register ------
  41.         movzx   edi,DMA_channel
  42.         mov     eax,edi
  43.         shr     edi,2
  44.         and     al,0011b
  45.         or      al,0100b
  46.         mov     dl,DMA_SNGL[edi]
  47.         out     dx,al
  48.  
  49.         ; ----- set mode register ------
  50.         and     al,03h
  51.         or      al,Mode
  52.         mov     dl,DMA_MODE[edi]
  53.         out     dx,al
  54.  
  55.         ; ------  clear MSB/LSB flip flop -----------
  56.         mov     dl,DMA_CLRFF[edi]
  57.         out     dx,al
  58.  
  59.  
  60.  
  61.         ;---- set byte count register ----
  62.         movzx   edi,DMA_channel
  63.         mov     eax,ecx
  64.         mov     ecx,edi
  65.         shr     ecx,2
  66.         shr     eax,cl                ; divide count address by 2 for DMA # 2
  67.         dec     eax                     ; count - 1
  68.         mov     dl,DMA_CNT[edi]         ; bits 0..7
  69.         out     dx,al
  70.         shr     eax,8
  71.         out     dx,al                   ; bits 8..15
  72.  
  73.  
  74.         ;---- set channel base address ---
  75.         shr     ebx,cl                ; divide base address by 2 for DMA # 2
  76.         mov     al,BL                       ; set bits 0..7
  77.         mov     dl,DMA_ADDR[edi]
  78.         out     dx,al
  79.         mov     al,BH                       ; set bits 8..15
  80.         out     dx,al
  81.  
  82.         shr     ebx,15           ; divide base address by 8000h for DMA # 2
  83.         xor     cl,1
  84.         shr     ebx,cl           ; divide base address by 10000h for DMA # 1
  85.         mov     al,BL            ; set bits 16..23 ( in LSB page register )
  86.         mov     dl,DMA_PAGE[edi]
  87.         out     dx,al
  88.  
  89.  
  90.         ; -----  clear channel (mask register) ------
  91.         mov     eax,edi
  92.         shr     edi,2
  93.         and     al,03h
  94.         mov     dl,DMA_SNGL[edi]
  95.         out     dx,al
  96.         popad
  97.         ret
  98.  
  99.  
  100. Mode            Db  ?
  101. DMA_Channel     Db  ?
  102.  
  103.  
  104. ;* 1st & 2nd DMA Controler's ports *;
  105.  
  106.   DMA_STAT   db 008h,0D0h        ;* read status register *;
  107.   DMA_CMD    db 008h,0D0h        ;* write command register *;
  108.   DMA_REQ    db 009h,0D2h        ;* write request register *;
  109.   DMA_SNGL   db 00Ah,0D4h        ;* write single bit register *;
  110.   DMA_MODE   db 00Bh,0D6h        ;* write mode register *;
  111.   DMA_CLRFF  db 00Ch,0D8h        ;* clear byte ptr flip;flop *;
  112.   DMA_MCLR   db 00Dh,0DAh        ;* master clear register *;
  113.   DMA_CLRM   db 00Eh,0DCh        ;* clear mask register *;
  114.   DMA_WRTALL db 00Fh,0DEh        ;* write all mask register *;
  115.  
  116. ; * ports for 8 channels *;
  117.  
  118. DMA_PAGE        db 087h,083h,081h,082h,08Fh,08Bh,089h,08Ah ; page register
  119. DMA_ADDR        db 000h,002h,004h,006h,0C0h,0C4h,0C8h,0CCh ; base adddress
  120. DMA_CNT         db 001h,003h,005h,007h,0C2h,0C6h,0CAh,0CEh ; base count
  121.  
  122. DMA_Setup   Endp
  123.  
  124.  
  125.             End
  126.