Someone once asked me about the DMA manager I wrote for my Genesis kernel, so I figured I'd just post some sections here:
;
; kStartDMA:
;
; Start the queued DMA transfers to the Video Display Processor's VRAM.
;
; Parameters:
; None
;
; Returns:
; None
;
kStartDMA: lea VDP,a6
; kInitDMA:
;
; Initialize the queue to perform a DMA transfer to the Video Display
; Processor's VRAM.
;
; Parameters:
; None
;
; Returns:
; None
;
kInitDMA: lea kern_DMATable(a5),a0 ; get the start of the queue
; kQueueDMA:
;
; Insert into the queue a request to perform a DMA transfer to the Video
; Display Processor's VRAM.
;
; Parameters:
; d0 -> Source address
; d1 -> VDP VRAM location
; d2 = Size of the transfer in WORDs
; d3 = VRAM memory bank
;
; Returns:
; None
;
kQueueDMA: move.l d4,a1
; kWaitDMA:
;
; Wait for the DMA transfer to finish, so the application can then
; synchronize with the video memory.
;
; Parameters:
; None
;
; Returns:
; a6 -> VDP hardware address
;
kWaitDMA: lea VDP,a6 ; init common address register
.waitDMA: move VCTRL(a6),d0 ; get the status WORD
;
; kStartDMA:
;
; Start the queued DMA transfers to the Video Display Processor's VRAM.
;
; Parameters:
; None
;
; Returns:
; None
;
kStartDMA: lea VDP,a6
lea kern_DMATable(a5),a0 ; get the start of the queue
move kern_DMAQueue(a5),d0 ; get the number of requests
beq.s kInitDMA
subq #1,d0
.dmaLoop: move.l (a0)+,VCTRL(a6) ; set the VDP DMA registersmove kern_DMAQueue(a5),d0 ; get the number of requests
beq.s kInitDMA
subq #1,d0
move.l (a0)+,VCTRL(a6)
move (a0)+,VCTRL(a6)
move.l (a0)+,VCTRL(a6)
dbra d0,.dmaLoop
;move (a0)+,VCTRL(a6)
move.l (a0)+,VCTRL(a6)
dbra d0,.dmaLoop
; kInitDMA:
;
; Initialize the queue to perform a DMA transfer to the Video Display
; Processor's VRAM.
;
; Parameters:
; None
;
; Returns:
; None
;
kInitDMA: lea kern_DMATable(a5),a0 ; get the start of the queue
move.l a0,kern_DMACurrent(a5) ; reset the current pointer
clr kern_DMAQueue(a5) ; clear the queue
rts
;clr kern_DMAQueue(a5) ; clear the queue
rts
; kQueueDMA:
;
; Insert into the queue a request to perform a DMA transfer to the Video
; Display Processor's VRAM.
;
; Parameters:
; d0 -> Source address
; d1 -> VDP VRAM location
; d2 = Size of the transfer in WORDs
; d3 = VRAM memory bank
;
; Returns:
; None
;
kQueueDMA: move.l d4,a1
addq #1,kern_DMAQueue(a5) ; increment the queue
move.l kern_DMACurrent(a5),a0
move.l #$94009300,d4 ; DMA size
move.b d2,d4
lsr #8,d2
swap d4
move.b d2,d4
move.l d4,(a0)+ ; set the DMA size registers
lsr.l #1,d0
move.l #$96009500,d4 ; DMA source mid and low WORDs
move.b d0,d4
lsr #8,d0
swap d4
move.b d0,d4
move.l d4,(a0)+ ; set the DMA source register
move #$9700,d4 ; DMA source high WORD
swap d0
move.b d0,d4
move d4,(a0)+ ; set the DMA source register
move d1,d4 ; get VDP destination address
and #$3fff,d4
or d3,d4 ; set the VRAM bank
move d4,(a0)+ ; DMA VRAM location high bits
rol #2,d1 ; compute dest register bits
and #3,d1
or #$80,d1
move d1,(a0)+ ; DMA VRAM location low bits
move.l a0,kern_DMACurrent(a5) ; save the new queue start
move.l a1,d4
rts
;move.l kern_DMACurrent(a5),a0
move.l #$94009300,d4 ; DMA size
move.b d2,d4
lsr #8,d2
swap d4
move.b d2,d4
move.l d4,(a0)+ ; set the DMA size registers
lsr.l #1,d0
move.l #$96009500,d4 ; DMA source mid and low WORDs
move.b d0,d4
lsr #8,d0
swap d4
move.b d0,d4
move.l d4,(a0)+ ; set the DMA source register
move #$9700,d4 ; DMA source high WORD
swap d0
move.b d0,d4
move d4,(a0)+ ; set the DMA source register
move d1,d4 ; get VDP destination address
and #$3fff,d4
or d3,d4 ; set the VRAM bank
move d4,(a0)+ ; DMA VRAM location high bits
rol #2,d1 ; compute dest register bits
and #3,d1
or #$80,d1
move d1,(a0)+ ; DMA VRAM location low bits
move.l a0,kern_DMACurrent(a5) ; save the new queue start
move.l a1,d4
rts
; kWaitDMA:
;
; Wait for the DMA transfer to finish, so the application can then
; synchronize with the video memory.
;
; Parameters:
; None
;
; Returns:
; a6 -> VDP hardware address
;
kWaitDMA: lea VDP,a6 ; init common address register
.waitDMA: move VCTRL(a6),d0 ; get the status WORD
and #VDPF_DMA,d0 ; check for DMA done
bne.s .waitDMA
rts
bne.s .waitDMA
rts
