System DMA Block

From C256 Foenix Wiki
Revision as of 14:32, 18 January 2021 by PJW (talk | contribs) (Overview)
Jump to navigation Jump to search

Overview

The System DMA block is a portion of the Vicky II chip which is responsible for high speed memory transfers to or from system memory. The block supports several types of memory operations:

  • Copying a contiguous block of data from one section of memory to another (1D or linear transfers)
  • Copying a rectangular subset of a larger image from one section of memory to another (2D or block transfers)
  • Filling a contiguous block of addresses in video memory with a single byte (1D fill)
  • Filling a rectangular subset of a larger image with a single byte (2D fill)

SDMA can copy data between different locations within system RAM, it can be used in conjunction with the Video DMA Block to transfer data between video RAM and system RAM.

IMPORTANT! SDMA halts the processor while it is in operation. The CPU will be unable to perform any tasks while an SDMA transfer is in operation. This includes handling interrupts of any sort.

Setting up a SDMA

System DMA Registers

Start Address Stop Address Register Description Additional Info
$AF:0420 $AF:0420 SDMA_CTRL_REG0 SDMA control register 0
Bit Name Purpose
$01 SDMA_CTRL0_Enable Enable the SDMA block
$02 SDMA_CTRL0_1D_2D 0 - 1D (Linear) Transfer , 1 - 2D (Block) Transfer
$04 SDMA_CTRL0_TRF_Fill Set to 1 to Enable the Generation of Interrupt when the Transfer is over.
$08 SDMA_CTRL0_Int_Enable 0 - Transfer Src -> Dst, 1 - Fill Destination with "Byte2Write"
$10 SDMA_CTRL0_SysRAM_Src Set to 1 to Indicate that the Source is the System Ram Memory when transferring out of SRAM.
$20 SDMA_CTRL0_SysRAM_Dst Set to 1 to Indicate that the Destination is the System Ram Memory when transferring from outside SRAM.
$80 SDMA_CTRL0_Start_TRF Set to 1 to start the transfer.
$AF:0421 $AF:0421 SDMA_CTRL_REG1 System DMA Control Register 1
$AF:0422 $AF:0422 SDMA_SRC_ADDY_L 24-bit address of the source (if system RAM is the source)
$AF:0423 $AF:0423 SDMA_SRC_ADDY_M
$AF:0424 $AF:0424 SDMA_SRC_ADDY_H
$AF:0425 $AF:0425 SDMA_DST_ADDY_L 24-bit address of the destination (if system RAM is the destination)
$AF:0426 $AF:0426 SDMA_DST_ADDY_M
$AF:0427 $AF:0427 SDMA_DST_ADDY_H
$AF:0428 $AF:0428 SDMA_SIZE_L / SDMA_X_SIZE_L If 1D transfer, the size of the transfer in bytes (24-bits). If 2D transfer, the 16-bit width of the block.
$AF:0429 $AF:0429 SDMA_SIZE_M / SDMA_X_SIZE_H
$AF:042A $AF:042A SDMA_SIZE_H / SDMA_Y_SIZE_L If 2D transfer, the 16-bit height of the block.
$AF:042B $AF:042B Ignored / SDMA_Y_SIZE_H
$AF:042C $AF:042C SDMA_SRC_STRIDE_L If 2D transfer, the number of bytes per row in the over-all source image.
$AF:042D $AF:042D SDMA_SRC_STRIDE_H
$AF:042E $AF:042E SDMA_DST_STRIDE_L
$AF:042F $AF:042F SDMA_DST_STRIDE_H If 2D transfer, the number of bytes per row in the over-all destination image.
$AF:0430 $AF:0430 SDMA_STATUS_REG / SDMA_BYTE_2_WRITE On write, the byte to write to memory.

On read, the status of the SDMA:

Bit Name Purpose
$01 SDMA_STAT_Size_Err If Set to 1, Overall Size is Invalid
$02 SDMA_STAT_Dst_Add_Err If Set to 1, Destination Address Invalid
$04 SDMA_STAT_Src_Add_Err If Set to 1, Source Address Invalid
$08 SDMA_STAT_TimeOut_Err If Set to 1, a timeout occurred when transferring between data from and to VRAM

SDMA_CTRL_REG0

This register is the main control register for system DMA. The bits are explained in the table above, but the source and destination bits deserve further attention here. The bits should be interpreted as a pair:

SDMA_CTRL0_SysRAM_Src SDMA_CTRL0_SysRAM_Dst Tranfer
0 0 SRAM to SRAM
1 0 SRAM to VRAM
0 1 VRAM to SRAM
1 1 Transfer to or from I/O (consult SDMA_CTRL_REG1)

SDMA_SRC_ADDY

This register is the 3-byte address of the source of the data (if it is in system RAM or I/O).

SDMA_DST_ADDY

This register is the 3-byte address of the destination of the data (if it is in system RAM or I/O).

SDMA Size

The size of the block to transfer is specified in one of two ways. For a 1-D or linear transfer (bit SDMA_CTRL_1D_2D in the control register is clear), the size is specified as a 24-bit integer using SDMA_SIZE_L, SDMA_SIZE_M, and SDMA_SIZE_H. If the transfer is a 2-D or block transfer (bit SDMA_CTRL_1D_2D in the control register is set), the size is specified as a 16-bit width stored in SDMA_X_SIZE_L and SDMA_X_SIZE_H, and a 16-bit height stored in SDMA_Y_SIZE_L and SDMA_Y_SIZE_L.

Stride

For a 2-D transfer, there is the notion of a "stride," which is the total number of bytes in a row of a source or destination image. The block being transferred may be narrower than the total image. The stride along with the width of the block tells Vicky how many bytes to skip between rows. Source and destination images can have different widths and therefore different strides. The stride of the source is specified by the two-byte register SDMA_SRC_STRIDE, and the stride of the destination by SDMA_DST_STRIDE.