DMAChannels

class DMAChannels

DMA stands for Direct Memory Access.

You can use these channels for fast memory transfers that do not pass through the cpu.

GBA has 4 dma channels, each one with different capabilities (work range, unit transfer count, priority and something else).

The transfer rate is

2(1N+(n-1)S)+xI

^ x=2.  If the transfer is from-to cartridge x=4

Half for writing and half for reading. n is the number of words to transfer

Obviously actual timing is based on waitstates and similars.

See Also

Memory ASICRegisters

Summary
DMAChannelsDMA stands for Direct Memory Access.
dma_dataContains pointers to io-ram to make lighter functions in DMAChannels (and thus (hopefully) faster code without branches)
Variables
sourcePointer to the source register.
destPointer to the destination register.
countPointer to the word count register.
controlPointer to the control register
saddrCurrent source address.
daddrCurrent destination address.
transfCountKeeps track of how many words have been moved
addrWidthKeeps track of the word length in the transfer (so that you don’t always have to do those shifts and ands to load it)
alreadyStartedTrue if the transfer is on the way.
mMemoryThe most important field.
mCpuWe need it to generate interrupts (if enabled)
mConsumedCyclesHow many cycles did the transfer consume? 
Functions
DMAChannelsInitializes the channels
GetDestinationAddrRetrieves the destination address of a DMAChannel.
GetSourceAddrRetrieves the source address of a DMAChannel.
GetWordsCountRetrieves the transfer words count of a DMAChannel.
GetControlRetrieves the control register of a DMAChannel.
GetDestAddrOperationReturns the destination address operation of the DMAChannel.
GetSourceAddrOperationReturns the source address operation of the DMAChannel.
GetRepeatReturns the repeat flag of the DMAChannel.
GetUnitSizeReturns the word size of the DMAChannel.
GetDRQReturns the DRQ Flag of the DMAChannel.
GetStartTimingReturns the start condition of the DMAChannel.
GetIRQEnabledReturns if DMA interrupts are enabled for a channel.
GetDMAEnabledChecks if a DMA channel is enabled.
GetStartConditionCheck if the DMA Channel should start execution
GetConsumedCyclesChecks how many cycles has the dma consumed.
TransferIncrementAddressesIncrement the addresses following the control register rules.
ExecuteTransferExecutes a DMA Transfer.
AfterTransferChecksComputes if, after a transfer, a dma has finished its transfer, if it shall be re-enabled, if there’re addresses that have to be reloaded..
IdleThis is the main function of DMAChannels.

dma_data

struct dma_data

Contains pointers to io-ram to make lighter functions in DMAChannels (and thus (hopefully) faster code without branches)

See Also

DMAChannels ASICRegisters Memory

Summary
Variables
sourcePointer to the source register.
destPointer to the destination register.
countPointer to the word count register.
controlPointer to the control register
saddrCurrent source address.
daddrCurrent destination address.
transfCountKeeps track of how many words have been moved
addrWidthKeeps track of the word length in the transfer (so that you don’t always have to do those shifts and ands to load it)
alreadyStartedTrue if the transfer is on the way.
mMemoryThe most important field.
mCpuWe need it to generate interrupts (if enabled)
mConsumedCyclesHow many cycles did the transfer consume? 
Functions
DMAChannelsInitializes the channels
GetDestinationAddrRetrieves the destination address of a DMAChannel.
GetSourceAddrRetrieves the source address of a DMAChannel.
GetWordsCountRetrieves the transfer words count of a DMAChannel.
GetControlRetrieves the control register of a DMAChannel.
GetDestAddrOperationReturns the destination address operation of the DMAChannel.
GetSourceAddrOperationReturns the source address operation of the DMAChannel.
GetRepeatReturns the repeat flag of the DMAChannel.
GetUnitSizeReturns the word size of the DMAChannel.
GetDRQReturns the DRQ Flag of the DMAChannel.
GetStartTimingReturns the start condition of the DMAChannel.
GetIRQEnabledReturns if DMA interrupts are enabled for a channel.
GetDMAEnabledChecks if a DMA channel is enabled.
GetStartConditionCheck if the DMA Channel should start execution
GetConsumedCyclesChecks how many cycles has the dma consumed.
TransferIncrementAddressesIncrement the addresses following the control register rules.
ExecuteTransferExecutes a DMA Transfer.
AfterTransferChecksComputes if, after a transfer, a dma has finished its transfer, if it shall be re-enabled, if there’re addresses that have to be reloaded..
IdleThis is the main function of DMAChannels.

Variables

source

uint32_t* source

Pointer to the source register.

dest

uint32_t* dest

Pointer to the destination register.

count

uint16_t* count

Pointer to the word count register.

control

uint16_t* control

Pointer to the control register

saddr

uint32_t saddr

Current source address.

daddr

uint32_t daddr

Current destination address.

transfCount

uint32_t transfCount

Keeps track of how many words have been moved

addrWidth

int addrWidth

Keeps track of the word length in the transfer (so that you don’t always have to do those shifts and ands to load it)

alreadyStarted

bool alreadyStarted

True if the transfer is on the way.

mMemory

Memory* mMemory

The most important field.  Allows us to use the emulated memory.

mCpu

CPU* mCpu

We need it to generate interrupts (if enabled)

mConsumedCycles

int mConsumedCycles

How many cycles did the transfer consume?  It is stored here!

Functions

DMAChannels

DMAChannels(Memory *mem,
CPU *cpu)

Initializes the channels

Parameters

memThe memory of the GBA.
cpuThe cpu of the GBA.

GetDestinationAddr

inline uint32_t GetDestinationAddr(int chan)

Retrieves the destination address of a DMAChannel.

Parameters

chanThe id of the channel to look up for.

Returns

The destination address of the DMAChannel.

GetSourceAddr

inline uint32_t GetSourceAddr(int chan)

Retrieves the source address of a DMAChannel.

Parameters

chanThe id of the channel to look up for.

Returns

The source address of the DMAChannel.

GetWordsCount

inline uint16_t GetWordsCount(int chan)

Retrieves the transfer words count of a DMAChannel.

Parameters

chanThe id of the channel to look up for.

Returns

The transfer words count of the DMAChannel.

GetControl

inline uint16_t GetControl(int chan)

Retrieves the control register of a DMAChannel.

Parameters

chanThe id of the channel to look up for.

Returns

The control register value of the DMAChannel.

GetDestAddrOperation

inline int GetDestAddrOperation(int chan)

Returns the destination address operation of the DMAChannel.

Parameters

chanThe id of the channel to look up for.

Returns

0=Increment, 1=Decrement, 2=Fixed, 3=Increment with Reload (for repeat transfers)

GetSourceAddrOperation

inline int GetSourceAddrOperation(int chan)

Returns the source address operation of the DMAChannel.

Parameters

chanThe id of the channel to look up for.

Returns

0=Increment, 1=Decrement, 2=Fixed, 3=Increment with Reload (for repeat transfers)

GetRepeat

inline bool GetRepeat(int chan)

Returns the repeat flag of the DMAChannel.

Parameters

chanThe id of the channel to look up for.

Returns

The repeat flag.

GetUnitSize

inline bool GetUnitSize(int chan)

Returns the word size of the DMAChannel.

Parameters

chanThe id of the channel to look up for.

Returns

False=16 bits, True=32 bits

GetDRQ

inline bool GetDRQ(int chan)

Returns the DRQ Flag of the DMAChannel.

Not supported here.  Useful for communicating with in-cartridge devices.

Parameters

chanThe id of the channel to look up for.

Returns

The DRQ Flag.

GetStartTiming

inline int GetStartTiming(int chan)

Returns the start condition of the DMAChannel.

Parameters

chanThe id of the channel to look up for.

Returns

0=Immediate 1=VBLANK 2=HBLANK 3=dma3?VideoCapture : Sound FIFOs

GetIRQEnabled

inline bool GetIRQEnabled(int chan)

Returns if DMA interrupts are enabled for a channel.

Parameters

chanThe id of the channel to look up for.

Returns

The IRQEnable Flag.

GetDMAEnabled

inline bool GetDMAEnabled(int chan)

Checks if a DMA channel is enabled.

Parameters

chanThe id of the channel to look up for.

Returns

True if the DMA channel is enabled

GetStartCondition

inline bool GetStartCondition(int chan)

Check if the DMA Channel should start execution

Parameters

chanThe id of the channel to look up for.

Returns

True if the condition is met.

GetConsumedCycles

inline int GetConsumedCycles()

Checks how many cycles has the dma consumed.

Returns

The number of cycles consumed by the last DMA transfer.

TransferIncrementAddresses

inline void TransferIncrementAddresses(int chan,
int sz)

Increment the addresses following the control register rules.

Parameters

chanThe channel id.
szThe size of the increment.

ExecuteTransfer

inline void ExecuteTransfer(int chan)

Executes a DMA Transfer.

Parameters

chanThe channel id.

AfterTransferChecks

inline void AfterTransferChecks(int chan)

Computes if, after a transfer, a dma has finished its transfer, if it shall be re-enabled, if there’re addresses that have to be reloaded..

Parameters

chanThe DMA Channel ID.

Idle

inline bool Idle()

This is the main function of DMAChannels.  It does all the work for DMAs emulation.

Returns

True if no dma operation was executed, which implies that the processor can continue its execution.

False otherwise (blocks the cpu).

class DMAChannels
DMA stands for Direct Memory Access.
struct dma_data
Contains pointers to io-ram to make lighter functions in DMAChannels (and thus (hopefully) faster code without branches)
DMAChannels(Memory *mem,
CPU *cpu)
Initializes the channels
uint32_t* source
Pointer to the source register.
uint32_t* dest
Pointer to the destination register.
uint16_t* count
Pointer to the word count register.
uint16_t* control
Pointer to the control register
uint32_t saddr
Current source address.
uint32_t daddr
Current destination address.
uint32_t transfCount
Keeps track of how many words have been moved
int addrWidth
Keeps track of the word length in the transfer (so that you don’t always have to do those shifts and ands to load it)
bool alreadyStarted
True if the transfer is on the way.
Memory* mMemory
The most important field.
CPU* mCpu
We need it to generate interrupts (if enabled)
int mConsumedCycles
How many cycles did the transfer consume? 
inline uint32_t GetDestinationAddr(int chan)
Retrieves the destination address of a DMAChannel.
inline uint32_t GetSourceAddr(int chan)
Retrieves the source address of a DMAChannel.
inline uint16_t GetWordsCount(int chan)
Retrieves the transfer words count of a DMAChannel.
inline uint16_t GetControl(int chan)
Retrieves the control register of a DMAChannel.
inline int GetDestAddrOperation(int chan)
Returns the destination address operation of the DMAChannel.
inline int GetSourceAddrOperation(int chan)
Returns the source address operation of the DMAChannel.
inline bool GetRepeat(int chan)
Returns the repeat flag of the DMAChannel.
inline bool GetUnitSize(int chan)
Returns the word size of the DMAChannel.
inline bool GetDRQ(int chan)
Returns the DRQ Flag of the DMAChannel.
inline int GetStartTiming(int chan)
Returns the start condition of the DMAChannel.
inline bool GetIRQEnabled(int chan)
Returns if DMA interrupts are enabled for a channel.
inline bool GetDMAEnabled(int chan)
Checks if a DMA channel is enabled.
inline bool GetStartCondition(int chan)
Check if the DMA Channel should start execution
inline int GetConsumedCycles()
Checks how many cycles has the dma consumed.
inline void TransferIncrementAddresses(int chan,
int sz)
Increment the addresses following the control register rules.
inline void ExecuteTransfer(int chan)
Executes a DMA Transfer.
inline void AfterTransferChecks(int chan)
Computes if, after a transfer, a dma has finished its transfer, if it shall be re-enabled, if there’re addresses that have to be reloaded..
inline bool Idle()
This is the main function of DMAChannels.
struct Memory
Represents the entire address space of the GBA.
struct ASICRegisters
This struct holds 0x804 bytes of data.
Close