Originally posted by: spoonybard
The "classical" way of communication between CPU and PPU is to write data at the $2000 - $2007 CPU address range : this range of memory can be called the "communication ports" between the CPU and the PPU. But there is another way to move data from the CPU memory to the PPU memory (quick thought : does it work both ways ? CPU mem <--> PPU mem) by using DMA.
It does not work both ways, only CPU => PPU.
Originally posted by: spoonybard
DMA is a faster way to copy data between the CPU and PPU memories because we do not send data byte by byte like the CPU would do : the exchange of data by DMA does not involve the CPU (I even think I've read that during DMA, the CPU is not working).
Yeah, normal CPU instructions are not executed while a DMA is active.
Originally posted by: spoonybard
Now, in the code, you send the sprite data which is stored at $0200 - $02FF in the CPU RAM. We send the origin address $0200 by writing first the low byte $00 at the CPU address $2003 and the high byte $02 at the CPU address $4014 which triggers the "DMA data exchange".
This is slightly incorrect. You can only control the source address at a 256 byte granularity. So if you write $02 to $4014, the transfer will always start from $200. Simply put, the source address is writtenByte*256. The register at $2003 sets the destination address (0..255) at the PPU side, not CPU.
Originally posted by: spoonybard
But we didn't give any information about how many bytes we transfer and we didn't tell where to
store it in the PPU memory. Is the number of bytes fixed for each DMA transfer ? Is the DMA transfer only possible for the sprites data, in terms of hardware : the hardware is such that the PPU memory range target is only the sprite data memory range ?
Yes, the number of bytes is fixed at 256. Yes, the DMA can only be used to transfer sprite (OAM) data.
If you write $02 to $4014, what actually happens during DMA is functionally exactly equivalent to the following code:
LDA $200
STA $2004
LDA $201
STA $2004
... (lines stripped) ...
LDA $2FE
STA $2004
LDA $2FF
STA $2004
The advantage of DMA is that it is 4 times faster than using code like above (it reads from $200 in a single cycle, then writes to $2004 in a single cycle, rinse and repeat, whereas LDA and STA would take 4 cycles each).