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.
DMAChannels | DMA stands for Direct Memory Access. |
dma_data | Contains pointers to io-ram to make lighter functions in DMAChannels (and thus (hopefully) faster code without branches) |
Variables | |
source | Pointer to the source register. |
dest | Pointer to the destination register. |
count | Pointer to the word count register. |
control | Pointer to the control register |
saddr | Current source address. |
daddr | Current destination address. |
transfCount | Keeps track of how many words have been moved |
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 | True if the transfer is on the way. |
mMemory | The most important field. |
mCpu | We need it to generate interrupts (if enabled) |
mConsumedCycles | How many cycles did the transfer consume? |
Functions | |
DMAChannels | Initializes the channels |
GetDestinationAddr | Retrieves the destination address of a DMAChannel. |
GetSourceAddr | Retrieves the source address of a DMAChannel. |
GetWordsCount | Retrieves the transfer words count of a DMAChannel. |
GetControl | Retrieves the control register of a DMAChannel. |
GetDestAddrOperation | Returns the destination address operation of the DMAChannel. |
GetSourceAddrOperation | Returns the source address operation of the DMAChannel. |
GetRepeat | Returns the repeat flag of the DMAChannel. |
GetUnitSize | Returns the word size of the DMAChannel. |
GetDRQ | Returns the DRQ Flag of the DMAChannel. |
GetStartTiming | Returns the start condition of the DMAChannel. |
GetIRQEnabled | Returns if DMA interrupts are enabled for a channel. |
GetDMAEnabled | Checks if a DMA channel is enabled. |
GetStartCondition | Check if the DMA Channel should start execution |
GetConsumedCycles | Checks how many cycles has the dma consumed. |
TransferIncrementAddresses | Increment the addresses following the control register rules. |
ExecuteTransfer | Executes a DMA Transfer. |
AfterTransferChecks | 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.. |
Idle | This is the main function of DMAChannels. |
struct dma_data
Contains pointers to io-ram to make lighter functions in DMAChannels (and thus (hopefully) faster code without branches)
DMAChannels ASICRegisters Memory
Variables | |
source | Pointer to the source register. |
dest | Pointer to the destination register. |
count | Pointer to the word count register. |
control | Pointer to the control register |
saddr | Current source address. |
daddr | Current destination address. |
transfCount | Keeps track of how many words have been moved |
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 | True if the transfer is on the way. |
mMemory | The most important field. |
mCpu | We need it to generate interrupts (if enabled) |
mConsumedCycles | How many cycles did the transfer consume? |
Functions | |
DMAChannels | Initializes the channels |
GetDestinationAddr | Retrieves the destination address of a DMAChannel. |
GetSourceAddr | Retrieves the source address of a DMAChannel. |
GetWordsCount | Retrieves the transfer words count of a DMAChannel. |
GetControl | Retrieves the control register of a DMAChannel. |
GetDestAddrOperation | Returns the destination address operation of the DMAChannel. |
GetSourceAddrOperation | Returns the source address operation of the DMAChannel. |
GetRepeat | Returns the repeat flag of the DMAChannel. |
GetUnitSize | Returns the word size of the DMAChannel. |
GetDRQ | Returns the DRQ Flag of the DMAChannel. |
GetStartTiming | Returns the start condition of the DMAChannel. |
GetIRQEnabled | Returns if DMA interrupts are enabled for a channel. |
GetDMAEnabled | Checks if a DMA channel is enabled. |
GetStartCondition | Check if the DMA Channel should start execution |
GetConsumedCycles | Checks how many cycles has the dma consumed. |
TransferIncrementAddresses | Increment the addresses following the control register rules. |
ExecuteTransfer | Executes a DMA Transfer. |
AfterTransferChecks | 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.. |
Idle | This is the main function of DMAChannels. |
inline bool Idle()
This is the main function of DMAChannels. It does all the work for DMAs emulation.
True if no dma operation was executed, which implies that the processor can continue its execution.
False otherwise (blocks the cpu).
DMA stands for Direct Memory Access.
class DMAChannels
Contains pointers to io-ram to make lighter functions in DMAChannels (and thus (hopefully) faster code without branches)
struct dma_data
Initializes the channels
DMAChannels( Memory * mem, CPU * cpu )
Pointer to the source register.
uint32_t* source
Pointer to the destination register.
uint32_t* dest
Pointer to the word count register.
uint16_t* count
Pointer to the control register
uint16_t* control
Current source address.
uint32_t saddr
Current destination address.
uint32_t daddr
Keeps track of how many words have been moved
uint32_t transfCount
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)
int addrWidth
True if the transfer is on the way.
bool alreadyStarted
The most important field.
Memory* mMemory
We need it to generate interrupts (if enabled)
CPU* mCpu
How many cycles did the transfer consume?
int mConsumedCycles
Retrieves the destination address of a DMAChannel.
inline uint32_t GetDestinationAddr( int chan )
Retrieves the source address of a DMAChannel.
inline uint32_t GetSourceAddr( int chan )
Retrieves the transfer words count of a DMAChannel.
inline uint16_t GetWordsCount( int chan )
Retrieves the control register of a DMAChannel.
inline uint16_t GetControl( int chan )
Returns the destination address operation of the DMAChannel.
inline int GetDestAddrOperation( int chan )
Returns the source address operation of the DMAChannel.
inline int GetSourceAddrOperation( int chan )
Returns the repeat flag of the DMAChannel.
inline bool GetRepeat( int chan )
Returns the word size of the DMAChannel.
inline bool GetUnitSize( int chan )
Returns the DRQ Flag of the DMAChannel.
inline bool GetDRQ( int chan )
Returns the start condition of the DMAChannel.
inline int GetStartTiming( int chan )
Returns if DMA interrupts are enabled for a channel.
inline bool GetIRQEnabled( int chan )
Checks if a DMA channel is enabled.
inline bool GetDMAEnabled( int chan )
Check if the DMA Channel should start execution
inline bool GetStartCondition( int chan )
Checks how many cycles has the dma consumed.
inline int GetConsumedCycles()
Increment the addresses following the control register rules.
inline void TransferIncrementAddresses( int chan, int sz )
Executes a DMA Transfer.
inline void ExecuteTransfer( 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 void AfterTransferChecks( int chan )
This is the main function of DMAChannels.
inline bool Idle()
Represents the entire address space of the GBA.
struct Memory
This struct holds 0x804 bytes of data.
struct ASICRegisters