all repos — mgba @ b4fa4fe77e23ed774e749608144fc0d1330b941c

mGBA Game Boy Advance Emulator

include/mgba/internal/gba/dma.h (view raw)

 1/* Copyright (c) 2013-2016 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#ifndef GBA_DMA_H
 7#define GBA_DMA_H
 8
 9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13enum DMAControl {
14	DMA_INCREMENT = 0,
15	DMA_DECREMENT = 1,
16	DMA_FIXED = 2,
17	DMA_INCREMENT_RELOAD = 3
18};
19
20enum DMATiming {
21	DMA_TIMING_NOW = 0,
22	DMA_TIMING_VBLANK = 1,
23	DMA_TIMING_HBLANK = 2,
24	DMA_TIMING_CUSTOM = 3
25};
26
27DECL_BITFIELD(GBADMARegister, uint16_t);
28DECL_BITS(GBADMARegister, DestControl, 5, 2);
29DECL_BITS(GBADMARegister, SrcControl, 7, 2);
30DECL_BIT(GBADMARegister, Repeat, 9);
31DECL_BIT(GBADMARegister, Width, 10);
32DECL_BIT(GBADMARegister, DRQ, 11);
33DECL_BITS(GBADMARegister, Timing, 12, 2);
34DECL_BIT(GBADMARegister, DoIRQ, 14);
35DECL_BIT(GBADMARegister, Enable, 15);
36
37struct GBADMA {
38	GBADMARegister reg;
39
40	uint32_t source;
41	uint32_t dest;
42	int32_t count;
43	uint32_t nextSource;
44	uint32_t nextDest;
45	int32_t nextCount;
46	uint32_t when;
47};
48
49struct GBA;
50void GBADMAInit(struct GBA* gba);
51void GBADMAReset(struct GBA* gba);
52
53uint32_t GBADMAWriteSAD(struct GBA* gba, int dma, uint32_t address);
54uint32_t GBADMAWriteDAD(struct GBA* gba, int dma, uint32_t address);
55void GBADMAWriteCNT_LO(struct GBA* gba, int dma, uint16_t count);
56uint16_t GBADMAWriteCNT_HI(struct GBA* gba, int dma, uint16_t control);
57
58struct GBADMA;
59void GBADMASchedule(struct GBA* gba, int number, struct GBADMA* info);
60void GBADMARunHblank(struct GBA* gba, int32_t cycles);
61void GBADMARunVblank(struct GBA* gba, int32_t cycles);
62void GBADMAUpdate(struct GBA* gba);
63
64CXX_GUARD_END
65
66#endif