DMA Function
Posted: Mon Oct 21, 2024 9:30 pm
Am in the process of adapting VERA into my own custom C/CC65 library and came up with this DMA function. Thought I'd leave it here for thoughts and critique. If you like it, feel free to use it.
Code: Select all
void DirectMemoryAccess(unsigned char DataBus, unsigned int destination, unsigned char stride, volatile unsigned char* Source, unsigned char ByteCount) {
ADDRx_L = destination & 0xFF; // Low Byte of destination sent to $9f20
ADDRx_M = (destination >> 8) & 0xFF; // High Byte of destination sent to $9f21
ADDRx_H = ((destination >> 16) & 0x01) | (stride << 4); // destination overflow bit sent to bit zero of $9f22. Stride sent to high nibble.
switch(DataBus) {
case 0:
CTRL = CTRL & ~0x01; // Bit 0 of $9f25 set to zero for DataBus 0
for(unsigned char i = 0; i < ByteCount; i++) {
DATA_0 = *(Source + i); // Copy Data from RAM to VRAM.
}
break;
case 1:
CTRL = (CTRL & ~0x01) | 0x01; // Bit zero of $9f5 set to one for DataBus 1.
for(unsigned char i = 0; i < ByteCount; i++) {
DATA_1 = *(Source + i); // Copy Data from RAM to VRAM.
}
break;
}
}