home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / dma / dma.asm
Assembly Source File  |  1994-02-11  |  8KB  |  143 lines

  1. ; DMA.ASM Copyright (C) 1994 by Chris Malcheski, Novatech Design
  2. ; FAX phone (303) 972-9107
  3.  
  4. ; This file is a direct extraction from my upcoming diagnostics program, which
  5. ; I am stupidly making available to public domain for DMA programming education-
  6. ; al purposes.  Note that even though the second DMA channel is provided for
  7. ; in this routine, it is set up for 8 bit operation and has never been tested
  8. ; above channel 3.
  9.  
  10. ; ───── variable definitions ───────────────────────────────────────────────────
  11.  
  12. ; dma_cbpt      DMA clear byte pointer port location
  13. ; dma_chnl      Requested DMA channel
  14. ; dma_mask      DMA mask register port location
  15. ; dma_memr      DMA memory register port location
  16. ; dma_mode      DMA mode value holder (0 for read, 1 for write)
  17. ; dma_page      DMA page register port location
  18. ; dma_rmod      DMA mode register port location
  19. ; dma_work      Adjusted DMA channel (0-3 down from 4-7)
  20. ; dma_xcnt      DMA xfer count register port location
  21. ; hold_hi       Utility work variable (word size)
  22. ; hold_lo       Utility work variable (word size)
  23.  
  24. ;╒═════════════════════════════════════════════════════════════════════════════╕
  25. ;│ DMA_SET:  program DMA controller for diskette I/O.                          │
  26. ;├─────────────────────────────────────────────────────────────────────────────┤
  27. ;│ Call:     AL    = 0 to read; 1 to write                                     │
  28. ;│           ES:DI = buffer address for read / write                           │
  29. ;│           BX    = transfer count in bytes                                   │
  30. ;├─────────────────────────────────────────────────────────────────────────────┤
  31. ;│ Uses:     DMA_CBPT      DMA_CHNL      DMA_MASK      DMA_MEMR      DMA_MODE  │
  32. ;│           DMA_PAGE      DMA_RMOD      DMA_WORK      DMA_XCNT      HOLD_HI   │
  33. ;│           HOLD_LO                                                           │
  34. ;├─────────────────────────────────────────────────────────────────────────────┤
  35. ;│ Calls:    Nothing.                                                          │
  36. ;├─────────────────────────────────────────────────────────────────────────────┤
  37. ;│ Returns:  Nothing.                                                          │
  38. ;├─────────────────────────────────────────────────────────────────────────────┤
  39. ;│ Destroy:  None.                                                             │
  40. ;╘═════════════════════════════════════════════════════════════════════════════╛
  41.  
  42. public        dma_set                            ; Declare procedure public
  43.  
  44.               even                               ; Set even alignment
  45. dma_set       proc      near                     ; Declare procedure
  46.  
  47. ;────── Save altered registers ─────────────────────────────────────────────────
  48.  
  49.               push      ax                       ; Save entry AX value
  50.               push      cx                       ; Save entry CX value
  51.               push      dx                       ; Save entry DX value
  52.  
  53. ;────── Select the DMA channel ─────────────────────────────────────────────────
  54.  
  55.               cli                                ; Disable interrupts
  56.               mov       dma_mode,al              ; Save incoming read/write
  57.               mov       al,04h                   ; Set mask bit
  58.               or        al,dma_work              ; OR with DMA work channel
  59.               mov       dx,dma_mask              ; Mask register to DX
  60.               out       dx,al                    ; Execute value output
  61.               jmp       short $+2                ; Clear prefetch queue
  62.  
  63. ;────── Set 20 bit address value ───────────────────────────────────────────────
  64.  
  65.               mov       ax,es                    ; Get segment value in AX
  66.               mov       cx,16                    ; Paragraph multiplier to CX
  67.               mul       cx                       ; Execute multiply
  68.               add       ax,di                    ; Add offset value to AX
  69.               jnc       dmas_1                   ; Skip carryover process
  70.               inc       dx                       ; Process carryover
  71.  
  72. ;────── Set page / address registers for DMA transfer ──────────────────────────
  73.  
  74.               even                               ; Set even alignment
  75. dmas_1:       mov       hold_hi,dx               ; Save hold value high word
  76.               mov       hold_lo,ax               ; Save hold value low word
  77.               mov       al,dl                    ; Get page value in AL
  78.               mov       dx,dma_page              ; Page register to DX
  79.               out       dx,al                    ; Send out page value
  80.               jmp       short $+2                ; Clear prefetch queue
  81.  
  82. ;────── Activate DMA clear byte pointer ────────────────────────────────────────
  83.  
  84.               xor       al,al                    ; Out value to AL
  85.               mov       dx,dma_cbpt              ; Clear byte pointer to DX
  86.               out       dx,al                    ; Send out clear byte value
  87.               jmp       short $+2                ; Clear prefetch queue
  88.  
  89. ;────── Send out value to DMAC first / last flip flop ──────────────────────────
  90.  
  91.               mov       al,44h                   ; Assume read operation
  92.               cmp       dma_mode,0               ; Read operation?
  93.               jz        dmas_2                   ; Yes -- leave AL as is
  94.               xor       al,0Ch                   ; Set AL for write
  95.               even                               ; Set even alignment
  96. dmas_2:       or        al,dma_chnl              ; Set bits 0-1 for channel
  97.               mov       dx,dma_rmod              ; DMA mode register to DX
  98.               out       dx,al                    ; Send out DMA clear byte ptr
  99.               jmp       short $+2                ; Clear prefetch queue
  100.  
  101. ;────── Send out low word address to memory address registers ──────────────────
  102.  
  103.               mov       ax,hold_lo               ; Get low word address in AX
  104.               mov       dx,dma_memr              ; DMA memory address to DX
  105.               out       dx,al                    ; LSB out to DMA address reg
  106.               jmp       short $+2                ; Clear prefetch queue
  107.               mov       al,ah                    ; Get high byte in AH
  108.               out       dx,al                    ; MSB out to DMA address reg
  109.               jmp       short $+2                ; Clear prefetch queue
  110.  
  111. ;────── Send out read count ────────────────────────────────────────────────────
  112.  
  113.               mov       ax,bx                    ; Get xfer count in AX
  114.               dec       ax                       ; Adjust for DMA interpret
  115.               mov       dx,dma_xcnt              ; Transfer count register to DX
  116.               out       dx,al                    ; LSB out to DMA word count
  117.               jmp       short $ + 2              ; Clear prefetch queue
  118.               mov       al,ah                    ; MSB to AL for out
  119.               out       dx,al                    ; MSB out to DMA word count
  120.               jmp       short $ + 2              ; Clear prefetch queue
  121.  
  122. ;────── Activate current DMA channel ───────────────────────────────────────────
  123.  
  124.               sti                                ; Enable interrupts
  125.               mov       al,dma_chnl              ; Enable DMA channel
  126.               mov       dx,dma_mask              ; Mask register to DX
  127.               out       dx,al                    ; Activate DMA channel
  128.               jmp       short $+2                ; Clear prefetch queue
  129.               clc                                ; Clear carry flag for no error
  130.  
  131. ;────── Restore altered registers ──────────────────────────────────────────────
  132.  
  133.               even                               ; Set even alignment
  134. dmas_x:       pop       dx                       ; Restore entry DX value
  135.               pop       cx                       ; Restore entry CX value
  136.               pop       ax                       ; Restore entry AX value
  137.  
  138. ;────── Return to caller ───────────────────────────────────────────────────────
  139.  
  140.               ret                                ; Return to caller
  141.  
  142. dma_set       endp                               ; End procedure
  143.