home *** CD-ROM | disk | FTP | other *** search
/ Der Mediaplex Sampler - Die 6 von Plex / 6_v_plex.zip / 6_v_plex / DISK3 / DFUE_100 / FAMITXT.ZIP / DMA.TXT < prev    next >
Internet Message Format  |  1994-02-07  |  6KB

  1. From:     LAY@uk.tele.nokia.fi
  2. To:       "Super Famicom Development Group" <famidev@busop.cit.wayne.edu>
  3. Subject:  RE: Assorted questions...
  4. Date:     Tue, 9 Nov 1993 11:42:13 GMT
  5. Reply-to: famidev@busop.cit.wayne.edu
  6. Sender:   Listserv@busop.cit.wayne.edu
  7. X-Mailer: Mercury MTA v1.0.
  8.  
  9. >> 2) I asked a question before about HDMA, and I got replies saying that
  10. >>    it has something to do with the horizontal interrupt or horizontal
  11. >>    blank time (I forget which).  Later on I saw people talking about
  12. >>    HDMA "channels".  Could someone please tell me what the "channels"
  13. >>    are used for, or are they another name for a register or a memory
  14. >>    storage location?
  15.  
  16. It's probably best to start by explaning "normal" DMA. The SNES
  17. supports 8 DMA channels which allow data to be copied to VRAM
  18. extremely quickly, bypassing the 65c816 processor. Each channel
  19. consists of the following registers.
  20.  
  21.     Byte    $43?0    DMA channel ? control register
  22.     Byte    $43?1    DMA channel ? destination
  23.     Word    $43?2    DMA channel ? source address offset
  24.     Byte    $43?4    DMA channel ? source address bank
  25.     Word    $43?5    DMA channel ? transfer bytes
  26.  
  27.     where ? is 0..7
  28.  
  29. A value of $01 written to the DMA channel control register at
  30. $43?0 indicates that we're using "normal" DMA. The graphics
  31. register destination is formed by using $21 as the high byte
  32. of the address and using the byte specified at $43?1 as the
  33. low byte. Hence you can DMA to any of the graphics registers
  34. between $2100..$21FF.
  35.  
  36. There is also a DMA control register.
  37.  
  38.     Byte    $420B    DMA control register
  39.  
  40. Here bit 0 enables channel 0, bit 1 enables channel 1 etc...
  41.  
  42. For example, suppose I wanted to copy a 32 x 32 character
  43. screen map (ie. $800 bytes) from location $18000 in ROM into
  44. location $0000 of VRAM. I could do this using DMA channel 0
  45. with the following code (A is 8-bits, X & Y are 16-bits).
  46.  
  47.     ldx.w #$0000    ; set VRAM pointer to $0000
  48.     stx $2116
  49.     lda #$01        ; control value for "normal" DMA
  50.     sta $4300
  51.     lda #$18        ; dma to $2118
  52.     sta $4301
  53.     ldx.w #$8000    ; source offset
  54.     stx $4302
  55.     lda #$01        ; source bank
  56.     sta $4304
  57.     ldx.w #$0800    ; number of bytes
  58.     stx $4305
  59.     lda #$01        ; enable DMA channel 0
  60.     sta $420B
  61.  
  62. And that's all there is to it. After completion of the last
  63. instruction "sta $420B" the $800 bytes at $18000 will have
  64. been copied into VRAM at location $0000.
  65.  
  66. HDMA allows you to use any combination of these DMA channels
  67. to modify graphics registers just before the start of every
  68. horizontal scan line.
  69.  
  70. To use HDMA you have to write a value of $00 or $02 to the
  71. DMA channel control register at $43?0 to indicate "horizontal"
  72. DMA. Writing $00 indicates a byte is to be DMA'd each scan
  73. line, writing $02 indicates a word. The DMA channel destination
  74. at $43?1 works just as before with "normal" DMA. The source
  75. address offset and bank registers at $43?2 & $43?4 will point
  76. to a HDMA table. The transfer bytes register at $43?5 is not
  77. used.
  78.  
  79. The format of the HDMA table depends on the value you have
  80. written to the DMA channel control register. If you have
  81. written $00 then a byte will be written to the selected
  82. graphics register each scan line. The table should have the
  83. following format.
  84.  
  85. hdma_table
  86.     Byte n ; number of bytes that follow (7-bit value 0..127)
  87.     Byte value_1, value_2, value_3 ... value_n
  88.     Byte n ; number of bytes that follow (7-bit value 0..127)
  89.     Byte value_1, value_2, value_3 ... value_n
  90.     .
  91.     etc
  92.     .
  93.     Byte 0 ; ends list
  94.  
  95. The table is made up of a number of entries. The first byte
  96. in each entry is a count on the number of bytes that follow.
  97. The table is terminated by a 0 entry.
  98.  
  99. If you have written $02 to the DMA channel control register
  100. then a word will be written to the selected graphics register
  101. each scan line. The table should have the following format.
  102.  
  103. hdma_table
  104.     Byte n ; # times to repeat next word (7-bit value 0..127)
  105.     Word value
  106.     Byte n ; # times to repeat next word (7-bit value 0..127)
  107.     Word value
  108.     .
  109.     etc
  110.     .
  111.     Byte 0 ; ends list
  112.  
  113. The table is made up of a number of entries. The first byte of
  114. each entry indicates the number of times the following word is
  115. to be repeated. The table is terminated by a 0 entry.
  116.  
  117. The only other thing you'll need to know is that there is a
  118. HDMA control register.
  119.  
  120.     Byte    $420C    HDMA control register
  121.  
  122. This is the same format as the DMA control register at $420B,
  123. ie. bit 0 enables HDMA channel 0, bit 1 enables channel 1 etc...
  124.  
  125. For example, suppose halfway down the screen I want to scroll
  126. graphics plane 0 left by 128 pixels.
  127.  
  128.     lda #$02        ; word format HDMA (count, word)
  129.     sta $4300
  130.     lda #$0D        ; plane 0 x-scroll at $210D
  131.     sta $4301
  132.     ldx.w #hdma_table&$FFFF ; hdma table offset
  133.     stx $4302
  134.     lda #hdma_table/$10000 ; hdma table bank
  135.     sta $4304
  136.     lda #$01        ; enable HDMA channel 0
  137.     sta $420c
  138.  
  139.     .
  140.     .
  141.     .
  142.  
  143. hdma_table
  144.     dc.b 112       ; for first 112 scan lines
  145.     dc.w 0         ; set plane 0 x-scroll to 0
  146.     dc.b 1         ; on next scan line
  147.     dc.w 128       ; set plane 0 x-scroll to 128
  148.     dc.b 0
  149.  
  150. You can use HDMA channels in combination, ie. you could use HDMA
  151. channel 0 to select a colour register and HDMA channel 1 to write
  152. the RGB data for that colour register.
  153.  
  154. I don't have access to any of the official Nintendo documentation 
  155. so I may not have entirely understood everything about HDMA but 
  156. this is a much as I've been able to work out. Maybe there are other 
  157. (H)DMA modes too?
  158.  
  159. I'll should have put a simple HDMA demo with source code on the
  160. busop.cit.wayne.edu ftp site (in pub/famidev/incoming/hdmademo.zip).
  161.  
  162. Hope that helps.
  163.  
  164. Paul.
  165.