mirror of
https://github.com/pret/pokeruby.git
synced 2024-11-24 05:29:40 +00:00
86 lines
4.4 KiB
C
86 lines
4.4 KiB
C
#ifndef GUARD_GBA_MACRO_H
|
|
#define GUARD_GBA_MACRO_H
|
|
|
|
#define CPU_FILL(value, dest, size, bit) \
|
|
{ \
|
|
vu##bit tmp = (vu##bit)(value); \
|
|
CpuSet((void *)&tmp, \
|
|
dest, \
|
|
CPU_SET_##bit##BIT | CPU_SET_SRC_FIXED | ((size)/(bit/8) & 0x1FFFFF)); \
|
|
}
|
|
|
|
#define CpuFill16(value, dest, size) CPU_FILL(value, dest, size, 16)
|
|
#define CpuFill32(value, dest, size) CPU_FILL(value, dest, size, 32)
|
|
|
|
#define CPU_COPY(src, dest, size, bit) CpuSet(src, dest, CPU_SET_##bit##BIT | ((size)/(bit/8) & 0x1FFFFF))
|
|
|
|
#define CpuCopy16(src, dest, size) CPU_COPY(src, dest, size, 16)
|
|
#define CpuCopy32(src, dest, size) CPU_COPY(src, dest, size, 32)
|
|
|
|
#define CpuFastFill(value, dest, size) \
|
|
{ \
|
|
vu32 tmp = (vu32)(value); \
|
|
CpuFastSet((void *)&tmp, \
|
|
dest, \
|
|
CPU_FAST_SET_SRC_FIXED | ((size)/(32/8) & 0x1FFFFF)); \
|
|
}
|
|
|
|
#define CpuFastCopy(src, dest, size) CpuFastSet(src, dest, ((size)/(32/8) & 0x1FFFFF))
|
|
|
|
#define DmaSet(dmaNum, src, dest, control) \
|
|
{ \
|
|
vu32 *dmaRegs = (vu32 *)REG_ADDR_DMA##dmaNum; \
|
|
dmaRegs[0] = (vu32)(src); \
|
|
dmaRegs[1] = (vu32)(dest); \
|
|
dmaRegs[2] = (vu32)(control); \
|
|
dmaRegs[2]; \
|
|
}
|
|
|
|
#define DMA_FILL(dmaNum, value, dest, size, bit) \
|
|
{ \
|
|
vu##bit tmp = (vu##bit)(value); \
|
|
DmaSet(dmaNum, \
|
|
&tmp, \
|
|
dest, \
|
|
(DMA_ENABLE | DMA_START_NOW | DMA_##bit##BIT | DMA_SRC_FIXED | DMA_DEST_INC) << 16 \
|
|
| ((size)/(bit/8))); \
|
|
}
|
|
|
|
#define DmaFill16(dmaNum, value, dest, size) DMA_FILL(dmaNum, value, dest, size, 16)
|
|
#define DmaFill32(dmaNum, value, dest, size) DMA_FILL(dmaNum, value, dest, size, 32)
|
|
|
|
// Note that the DMA clear macros cause the DMA control value to be calculated
|
|
// at runtime rather than compile time. The size is divided by the DMA transfer
|
|
// unit size (2 or 4 bytes) and then combined with the DMA control flags using a
|
|
// bitwise OR operation.
|
|
|
|
#define DMA_CLEAR(dmaNum, dest, size, bit) \
|
|
{ \
|
|
vu##bit *_dest = (vu##bit *)(dest); \
|
|
u32 _size = size; \
|
|
DmaFill##bit(dmaNum, 0, _dest, _size); \
|
|
}
|
|
|
|
#define DmaClear16(dmaNum, dest, size) DMA_CLEAR(dmaNum, dest, size, 16)
|
|
#define DmaClear32(dmaNum, dest, size) DMA_CLEAR(dmaNum, dest, size, 32)
|
|
|
|
#define DMA_COPY(dmaNum, src, dest, size, bit) \
|
|
DmaSet(dmaNum, \
|
|
src, \
|
|
dest, \
|
|
(DMA_ENABLE | DMA_START_NOW | DMA_##bit##BIT | DMA_SRC_INC | DMA_DEST_INC) << 16 \
|
|
| ((size)/(bit/8)))
|
|
|
|
#define DmaCopy16(dmaNum, src, dest, size) DMA_COPY(dmaNum, src, dest, size, 16)
|
|
#define DmaCopy32(dmaNum, src, dest, size) DMA_COPY(dmaNum, src, dest, size, 32)
|
|
|
|
#define DmaStop(dmaNum) \
|
|
{ \
|
|
vu16 *dmaRegs = (vu16 *)REG_ADDR_DMA##dmaNum; \
|
|
dmaRegs[5] &= ~(DMA_START_MASK | DMA_DREQ_ON | DMA_REPEAT); \
|
|
dmaRegs[5] &= ~DMA_ENABLE; \
|
|
dmaRegs[5]; \
|
|
}
|
|
|
|
#endif // GUARD_GBA_MACRO_H
|