aboutsummaryrefslogtreecommitdiff
path: root/source/nds/dma_adj.c
blob: 8b6f9adbc9afe886c8e3145a0cedc712bae0566b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "ds2_malloc.h"
#include "dma_adj.h"

#ifdef DS2_DMA

struct SPointerAdjustments PtrAdj;

void* AlignedMalloc (unsigned int Size, unsigned int Alignment, unsigned int* Adjustment)
{
	if (Alignment == 0) Alignment = 1;

	unsigned char* result = (unsigned char*) malloc(Size + Alignment);
	if (!result) {
		return result;
	} else {
		*Adjustment = Alignment - ((unsigned int) result & (Alignment - 1));
		return (void*) (result + *Adjustment);
	}
}

void AlignedFree (void* Memory, unsigned int Adjustment)
{
	free((void*) ((unsigned char*) Memory - Adjustment));
}

#endif // DS2_DMA