DMA - Direct Memory Access on the ZX Spectrum Next
NCOT Technology
This is the third video in a short series looking at some of the more advanced parts of the Spectrum Next. If you've not seen the others, go watch them after this one. In this video we're looking at how to program the DMA controller in the Spectrum Next.
This'll be technical, it'll include code on how to do this using Z88DK and C for the Spectrum Next. It's a pretty advanced technique, but it's quite understandable and can add some nice speed boosts to code if used appropriately.
DMA or Direct Memory Access is a way to allow devices access to system RAM without the CPU being involved.
The DMA controller in the Next is a programmable device and has a few registers that need writing to. This is well documented on the Spectrum Next wiki https://wiki.specnext.dev/DMA.
There are seven registers called WR0 to WR6. Writing to them is like when we configured the sprite system in my other video. Each register is accessed through the same IO port and the pattern of the first three bits tells the DMA controller which register you're writing to.
The only thing to know is this is purely a DMA, it can copy continuous runs of bytes. It's not a blitter so it is unable to copy a rectanglular block of RAM.
Also for small copies, the setup and configuration may actually be slower than doing it by hand with memcpy. It's definitely something to use with large amounts of data though. A music playing routine running in a vblank interrupt would use this to feed the audio hardware with sound data.
Chapters:
00:00 Start! 00:45 What is DMA? 01:41 ZX Next DMA 02:01 The DMA Registers 02:32 Register WR0 03:10 Code example DMA Screen Copy 04:23 Register WR1 05:03 Registers WR2 and WR3 05:20 Register WR4 05:44 Register WR6 06:13 A note on writing to registers 06:45 Repeating DMA transfers 08:00 Closing Notes
Credits:
Casio Calculators - J. C. Barros from Portugal, CC BY 2.0, via Wikimedia Commons Random images - Midjourney Music - Epidemic Sounds ... https://www.youtube.com/watch?v=6bd7LfCcID4
121755140 Bytes