gbasys

diff src/dma.c @ 0:875ef6085efc

gbasys mercurial repository
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 04 Mar 2012 04:04:25 +0200
parents
children c50064b181c2
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/dma.c	Sun Mar 04 04:04:25 2012 +0200
     1.3 @@ -0,0 +1,77 @@
     1.4 +/*
     1.5 +Copyright 2004 John Tsiombikas <nuclear@siggraph.org>
     1.6 +
     1.7 +This file is part of libgba, a library for GameBoy Advance development.
     1.8 +
     1.9 +This program is free software; you can redistribute it and/or modify
    1.10 +it under the terms of the GNU General Public License as published by
    1.11 +the Free Software Foundation; either version 2 of the License, or
    1.12 +(at your option) any later version.
    1.13 +
    1.14 +This program is distributed in the hope that it will be useful,
    1.15 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.17 +GNU General Public License for more details.
    1.18 +
    1.19 +You should have received a copy of the GNU General Public License
    1.20 +along with this program; if not, write to the Free Software
    1.21 +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.22 +*/
    1.23 +
    1.24 +#include "libgba_config.h"
    1.25 +#include "dma.h"
    1.26 +
    1.27 +/* DMA Options */
    1.28 +#define DMA_ENABLE 				0x80000000
    1.29 +#define DMA_INT_ENABLE			0x40000000
    1.30 +#define DMA_TIMING_IMMED		0x00000000
    1.31 +#define DMA_TIMING_VBLANK		0x10000000
    1.32 +#define DMA_TIMING_HBLANK		0x20000000
    1.33 +#define DMA_TIMING_DISPSYNC		0x30000000
    1.34 +#define DMA_16					0x00000000
    1.35 +#define DMA_32					0x04000000
    1.36 +#define DMA_REPEAT				0x02000000
    1.37 +#define DMA_SRC_INC				0x00000000
    1.38 +#define DMA_SRC_DEC				0x00800000
    1.39 +#define DMA_SRC_FIX				0x01000000
    1.40 +#define DMA_DST_INC				0x00000000
    1.41 +#define DMA_DST_DEC				0x00200000
    1.42 +#define DMA_DST_FIX1			0x00400000
    1.43 +#define DMA_DST_RELOAD			0x00600000
    1.44 +
    1.45 +/* DMA Register Parts */
    1.46 +#define DMA_SRC		0
    1.47 +#define DMA_DST		1
    1.48 +#define DMA_CTRL	2
    1.49 +
    1.50 +static volatile unsigned long *reg_dma[4] = {(void*)0x040000b0, (void*)0x040000bc, (void*)0x040000c8, (void*)0x040000d4 };
    1.51 +
    1.52 +/* --- perform a copy of words or halfwords using DMA --- */
    1.53 +
    1.54 +void dma_copy32(int channel, void *dst, void *src, int words) {
    1.55 +	reg_dma[channel][DMA_SRC] = (unsigned long)src;
    1.56 +	reg_dma[channel][DMA_DST] = (unsigned long)dst;
    1.57 +	reg_dma[channel][DMA_CTRL] = words | DMA_TIMING_IMMED | DMA_32 | DMA_ENABLE;
    1.58 +}
    1.59 +
    1.60 +void dma_copy16(int channel, void *dst, void *src, int halfwords) {
    1.61 +	reg_dma[channel][DMA_SRC] = (unsigned long)src;
    1.62 +	reg_dma[channel][DMA_DST] = (unsigned long)dst;
    1.63 +	reg_dma[channel][DMA_CTRL] = halfwords | DMA_TIMING_IMMED | DMA_16 | DMA_ENABLE;
    1.64 +}
    1.65 +
    1.66 +/* --- fill a buffer with an ammount of words and halfwords using DMA --- */
    1.67 +
    1.68 +void dma_fill32(int channel, void *dst, unsigned long val, int words) {
    1.69 +	unsigned long valmem = val;
    1.70 +	reg_dma[channel][DMA_SRC] = (unsigned long)&valmem;
    1.71 +	reg_dma[channel][DMA_DST] = (unsigned long)dst;
    1.72 +	reg_dma[channel][DMA_CTRL] = words | DMA_SRC_FIX | DMA_TIMING_IMMED | DMA_32 | DMA_ENABLE;
    1.73 +}
    1.74 +
    1.75 +void dma_fill16(int channel, void *dst, unsigned short val, int halfwords) {
    1.76 +	unsigned short valmem = val;
    1.77 +	reg_dma[channel][DMA_SRC] = (unsigned long)&valmem;
    1.78 +	reg_dma[channel][DMA_DST] = (unsigned long)dst;
    1.79 +	reg_dma[channel][DMA_CTRL] = halfwords | DMA_SRC_FIX | DMA_TIMING_IMMED | DMA_16 | DMA_ENABLE;
    1.80 +}