all repos — mgba @ 54fffb7fff09bc5daca6f995b041b185f0cf2524

mGBA Game Boy Advance Emulator

src/gba/gba-memory.c (view raw)

  1#include "gba-memory.h"
  2
  3#include "gba-io.h"
  4#include "hle-bios.h"
  5
  6#include <limits.h>
  7#include <string.h>
  8#include <sys/mman.h>
  9
 10static const char* GBA_CANNOT_MMAP = "Could not map memory";
 11
 12static void GBASetActiveRegion(struct ARMMemory* memory, uint32_t region);
 13
 14static const char GBA_BASE_WAITSTATES[16] = { 0, 0, 2, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4 };
 15static const char GBA_BASE_WAITSTATES_SEQ[16] = { 0, 0, 2, 0, 0, 0, 0, 0, 2, 2, 4, 4, 8, 8, 4 };
 16static const char GBA_ROM_WAITSTATES[] = { 4, 3, 2, 8 };
 17static const char GBA_ROM_WAITSTATES_SEQ[] = { 2, 1, 4, 1, 8, 1 };
 18static const int DMA_OFFSET[] = { 1, -1, 0, 1 };
 19
 20void GBAMemoryInit(struct GBAMemory* memory) {
 21	memory->d.load32 = GBALoad32;
 22	memory->d.load16 = GBALoad16;
 23	memory->d.loadU16 = GBALoadU16;
 24	memory->d.load8 = GBALoad8;
 25	memory->d.loadU8 = GBALoadU8;
 26	memory->d.store32 = GBAStore32;
 27	memory->d.store16 = GBAStore16;
 28	memory->d.store8 = GBAStore8;
 29
 30	memory->bios = hleBios;
 31	memory->wram = mmap(0, SIZE_WORKING_RAM, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
 32	memory->iwram = mmap(0, SIZE_WORKING_IRAM, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
 33	memory->rom = 0;
 34	memset(memory->io, 0, sizeof(memory->io));
 35	memset(memory->dma, 0, sizeof(memory->dma));
 36
 37	if (!memory->wram || !memory->iwram) {
 38		GBAMemoryDeinit(memory);
 39		memory->p->errno = GBA_OUT_OF_MEMORY;
 40		memory->p->errstr = GBA_CANNOT_MMAP;
 41	}
 42
 43	int i;
 44	for (i = 0; i < 16; ++i) {
 45		memory->waitstates16[i] = GBA_BASE_WAITSTATES[i];
 46		memory->waitstatesSeq16[i] = GBA_BASE_WAITSTATES_SEQ[i];
 47		memory->waitstates32[i] = GBA_BASE_WAITSTATES[i] + GBA_BASE_WAITSTATES_SEQ[i] + 1;
 48		memory->waitstatesSeq32[i] = GBA_BASE_WAITSTATES_SEQ[i] + GBA_BASE_WAITSTATES_SEQ[i] + 1;
 49	}
 50	for (; i < 256; ++i) {
 51		memory->waitstates16[i] = 0;
 52		memory->waitstatesSeq16[i] = 0;
 53		memory->waitstates32[i] = 0;
 54		memory->waitstatesSeq32[i] = 0;
 55	}
 56
 57	memory->activeRegion = 0;
 58	memory->d.activeRegion = 0;
 59	memory->d.activeMask = 0;
 60	memory->d.setActiveRegion = GBASetActiveRegion;
 61	memory->d.activePrefetchCycles32 = 0;
 62	memory->d.activePrefetchCycles16 = 0;
 63}
 64
 65void GBAMemoryDeinit(struct GBAMemory* memory) {
 66	munmap(memory->wram, SIZE_WORKING_RAM);
 67	munmap(memory->iwram, SIZE_WORKING_IRAM);
 68}
 69
 70static void GBASetActiveRegion(struct ARMMemory* memory, uint32_t address) {
 71	struct GBAMemory* gbaMemory = (struct GBAMemory*) memory;
 72
 73	memory->activePrefetchCycles32 = gbaMemory->waitstates32[address >> BASE_OFFSET];
 74	memory->activePrefetchCycles16 = gbaMemory->waitstates16[address >> BASE_OFFSET];
 75	gbaMemory->activeRegion = address >> BASE_OFFSET;
 76	switch (address & ~OFFSET_MASK) {
 77	case BASE_BIOS:
 78		memory->activeRegion = gbaMemory->bios;
 79		memory->activeMask = SIZE_BIOS - 1;
 80		break;
 81	case BASE_WORKING_RAM:
 82		memory->activeRegion = gbaMemory->wram;
 83		memory->activeMask = SIZE_WORKING_RAM - 1;
 84		break;
 85	case BASE_WORKING_IRAM:
 86		memory->activeRegion = gbaMemory->iwram;
 87		memory->activeMask = SIZE_WORKING_IRAM - 1;
 88		break;
 89	case BASE_CART0:
 90	case BASE_CART0_EX:
 91	case BASE_CART1:
 92	case BASE_CART1_EX:
 93	case BASE_CART2:
 94	case BASE_CART2_EX:
 95		memory->activeRegion = gbaMemory->rom;
 96		memory->activeMask = SIZE_CART0 - 1;
 97		break;
 98	default:
 99		memory->activeRegion = 0;
100		memory->activeMask = 0;
101		break;
102	}
103}
104
105int32_t GBALoad32(struct ARMMemory* memory, uint32_t address) {
106	struct GBAMemory* gbaMemory = (struct GBAMemory*) memory;
107
108	switch (address & ~OFFSET_MASK) {
109	case BASE_BIOS:
110		break;
111	case BASE_WORKING_RAM:
112		return gbaMemory->wram[(address & (SIZE_WORKING_RAM - 1)) >> 2];
113	case BASE_WORKING_IRAM:
114		return gbaMemory->iwram[(address & (SIZE_WORKING_IRAM - 1)) >> 2];
115	case BASE_IO:
116		break;
117	case BASE_PALETTE_RAM:
118		break;
119	case BASE_VRAM:
120		break;
121	case BASE_OAM:
122		break;
123	case BASE_CART0:
124	case BASE_CART0_EX:
125	case BASE_CART1:
126	case BASE_CART1_EX:
127	case BASE_CART2:
128	case BASE_CART2_EX:
129		return gbaMemory->rom[(address & (SIZE_CART0 - 1)) >> 2];
130	case BASE_CART_SRAM:
131		break;
132	default:
133		break;
134	}
135
136	return 0;
137}
138
139int16_t GBALoad16(struct ARMMemory* memory, uint32_t address) {
140	struct GBAMemory* gbaMemory = (struct GBAMemory*) memory;
141
142	switch (address & ~OFFSET_MASK) {
143	case BASE_BIOS:
144		break;
145	case BASE_WORKING_RAM:
146		return ((int16_t*) gbaMemory->wram)[(address & (SIZE_WORKING_RAM - 1)) >> 1];
147	case BASE_WORKING_IRAM:
148		return ((int16_t*) gbaMemory->iwram)[(address & (SIZE_WORKING_IRAM - 1)) >> 1];
149	case BASE_IO:
150		return GBAIORead(gbaMemory->p, address & (SIZE_IO - 1));
151	case BASE_PALETTE_RAM:
152		break;
153	case BASE_VRAM:
154		break;
155	case BASE_OAM:
156		break;
157	case BASE_CART0:
158	case BASE_CART0_EX:
159	case BASE_CART1:
160	case BASE_CART1_EX:
161	case BASE_CART2:
162	case BASE_CART2_EX:
163		return ((int16_t*) gbaMemory->rom)[(address & (SIZE_CART0 - 1)) >> 1];
164	case BASE_CART_SRAM:
165		break;
166	default:
167		break;
168	}
169
170	return 0;
171}
172
173uint16_t GBALoadU16(struct ARMMemory* memory, uint32_t address) {
174	struct GBAMemory* gbaMemory = (struct GBAMemory*) memory;
175
176	switch (address & ~OFFSET_MASK) {
177	case BASE_BIOS:
178		break;
179	case BASE_WORKING_RAM:
180		return ((uint16_t*) gbaMemory->wram)[(address & (SIZE_WORKING_RAM - 1)) >> 1];
181	case BASE_WORKING_IRAM:
182		return ((uint16_t*) gbaMemory->iwram)[(address & (SIZE_WORKING_IRAM - 1)) >> 1];
183	case BASE_IO:
184		return GBAIORead(gbaMemory->p, address & (SIZE_IO - 1));
185	case BASE_PALETTE_RAM:
186		break;
187	case BASE_VRAM:
188		break;
189	case BASE_OAM:
190		break;
191	case BASE_CART0:
192	case BASE_CART0_EX:
193	case BASE_CART1:
194	case BASE_CART1_EX:
195	case BASE_CART2:
196	case BASE_CART2_EX:
197		return ((uint16_t*) gbaMemory->rom)[(address & (SIZE_CART0 - 1)) >> 1];
198	case BASE_CART_SRAM:
199		break;
200	default:
201		break;
202	}
203
204	return 0;
205}
206
207int8_t GBALoad8(struct ARMMemory* memory, uint32_t address) {
208	struct GBAMemory* gbaMemory = (struct GBAMemory*) memory;
209
210	switch (address & ~OFFSET_MASK) {
211	case BASE_BIOS:
212		break;
213	case BASE_WORKING_RAM:
214		return ((int8_t*) gbaMemory->wram)[address & (SIZE_WORKING_RAM - 1)];
215	case BASE_WORKING_IRAM:
216		return ((int8_t*) gbaMemory->iwram)[address & (SIZE_WORKING_IRAM - 1)];
217	case BASE_IO:
218		break;
219	case BASE_PALETTE_RAM:
220		break;
221	case BASE_VRAM:
222		break;
223	case BASE_OAM:
224		break;
225	case BASE_CART0:
226	case BASE_CART0_EX:
227	case BASE_CART1:
228	case BASE_CART1_EX:
229	case BASE_CART2:
230	case BASE_CART2_EX:
231		return ((int8_t*) gbaMemory->rom)[address & (SIZE_CART0 - 1)];
232	case BASE_CART_SRAM:
233		break;
234	default:
235		break;
236	}
237
238	return 0;
239}
240
241uint8_t GBALoadU8(struct ARMMemory* memory, uint32_t address) {
242	struct GBAMemory* gbaMemory = (struct GBAMemory*) memory;
243
244	switch (address & ~OFFSET_MASK) {
245	case BASE_BIOS:
246		break;
247	case BASE_WORKING_RAM:
248		return ((uint8_t*) gbaMemory->wram)[address & (SIZE_WORKING_RAM - 1)];
249		break;
250	case BASE_WORKING_IRAM:
251		return ((uint8_t*) gbaMemory->iwram)[address & (SIZE_WORKING_IRAM - 1)];
252		break;
253	case BASE_IO:
254		break;
255	case BASE_PALETTE_RAM:
256		break;
257	case BASE_VRAM:
258		break;
259	case BASE_OAM:
260		break;
261	case BASE_CART0:
262	case BASE_CART0_EX:
263	case BASE_CART1:
264	case BASE_CART1_EX:
265	case BASE_CART2:
266	case BASE_CART2_EX:
267		return ((uint8_t*) gbaMemory->rom)[address & (SIZE_CART0 - 1)];
268	case BASE_CART_SRAM:
269		break;
270	default:
271		break;
272	}
273
274	return 0;
275}
276
277void GBAStore32(struct ARMMemory* memory, uint32_t address, int32_t value) {
278	struct GBAMemory* gbaMemory = (struct GBAMemory*) memory;
279
280	switch (address & ~OFFSET_MASK) {
281	case BASE_WORKING_RAM:
282		gbaMemory->wram[(address & (SIZE_WORKING_RAM - 1)) >> 2] = value;
283		break;
284	case BASE_WORKING_IRAM:
285		gbaMemory->iwram[(address & (SIZE_WORKING_IRAM - 1)) >> 2] = value;
286		break;
287	case BASE_IO:
288		GBAIOWrite32(gbaMemory->p, address & (SIZE_IO - 1), value);
289		break;
290	case BASE_PALETTE_RAM:
291		break;
292	case BASE_VRAM:
293		break;
294	case BASE_OAM:
295		break;
296	case BASE_CART0:
297		break;
298	case BASE_CART2_EX:
299		break;
300	case BASE_CART_SRAM:
301		break;
302	default:
303		break;
304	}
305}
306
307void GBAStore16(struct ARMMemory* memory, uint32_t address, int16_t value) {
308	struct GBAMemory* gbaMemory = (struct GBAMemory*) memory;
309
310	switch (address & ~OFFSET_MASK) {
311	case BASE_WORKING_RAM:
312		((int16_t*) gbaMemory->wram)[(address & (SIZE_WORKING_RAM - 1)) >> 1] = value;
313		break;
314	case BASE_WORKING_IRAM:
315		((int16_t*) gbaMemory->iwram)[(address & (SIZE_WORKING_IRAM - 1)) >> 1] = value;
316		break;
317	case BASE_IO:
318		GBAIOWrite(gbaMemory->p, address & (SIZE_IO - 1), value);
319		break;
320	case BASE_PALETTE_RAM:
321		break;
322	case BASE_VRAM:
323		break;
324	case BASE_OAM:
325		break;
326	case BASE_CART0:
327		break;
328	case BASE_CART2_EX:
329		break;
330	case BASE_CART_SRAM:
331		break;
332	default:
333		break;
334	}
335}
336
337void GBAStore8(struct ARMMemory* memory, uint32_t address, int8_t value) {
338	struct GBAMemory* gbaMemory = (struct GBAMemory*) memory;
339
340	switch (address & ~OFFSET_MASK) {
341	case BASE_WORKING_RAM:
342		((int8_t*) gbaMemory->wram)[address & (SIZE_WORKING_RAM - 1)] = value;
343		break;
344	case BASE_WORKING_IRAM:
345		((int8_t*) gbaMemory->iwram)[address & (SIZE_WORKING_IRAM - 1)] = value;
346		break;
347	case BASE_IO:
348		break;
349	case BASE_PALETTE_RAM:
350		break;
351	case BASE_VRAM:
352		break;
353	case BASE_OAM:
354		break;
355	case BASE_CART0:
356		break;
357	case BASE_CART2_EX:
358		break;
359	case BASE_CART_SRAM:
360		break;
361	default:
362		break;
363	}
364}
365
366void GBAAdjustWaitstates(struct GBAMemory* memory, uint16_t parameters) {
367	int sram = parameters & 0x0003;
368	int ws0 = (parameters & 0x000C) >> 2;
369	int ws0seq = (parameters & 0x0010) >> 4;
370	int ws1 = (parameters & 0x0060) >> 5;
371	int ws1seq = (parameters & 0x0080) >> 7;
372	int ws2 = (parameters & 0x0300) >> 8;
373	int ws2seq = (parameters & 0x0400) >> 10;
374	int prefetch = parameters & 0x4000;
375
376	memory->waitstates16[REGION_CART_SRAM] =  GBA_ROM_WAITSTATES[sram];
377	memory->waitstatesSeq16[REGION_CART_SRAM] = GBA_ROM_WAITSTATES[sram];
378	memory->waitstates32[REGION_CART_SRAM] = 2 * GBA_ROM_WAITSTATES[sram] + 1;
379	memory->waitstatesSeq32[REGION_CART_SRAM] = 2 * GBA_ROM_WAITSTATES[sram] + 1;
380
381	memory->waitstates16[REGION_CART0] = memory->waitstates16[REGION_CART0_EX] = GBA_ROM_WAITSTATES[ws0];
382	memory->waitstates16[REGION_CART1] = memory->waitstates16[REGION_CART1_EX] = GBA_ROM_WAITSTATES[ws1];
383	memory->waitstates16[REGION_CART2] = memory->waitstates16[REGION_CART2_EX] = GBA_ROM_WAITSTATES[ws2];
384
385	memory->waitstatesSeq16[REGION_CART0] = memory->waitstatesSeq16[REGION_CART0_EX] = GBA_ROM_WAITSTATES_SEQ[ws0seq];
386	memory->waitstatesSeq16[REGION_CART1] = memory->waitstatesSeq16[REGION_CART1_EX] = GBA_ROM_WAITSTATES_SEQ[ws1seq + 2];
387	memory->waitstatesSeq16[REGION_CART2] = memory->waitstatesSeq16[REGION_CART2_EX] = GBA_ROM_WAITSTATES_SEQ[ws2seq + 4];
388
389	memory->waitstates32[REGION_CART0] = memory->waitstates32[REGION_CART0_EX] = memory->waitstates16[REGION_CART0] + 1 + memory->waitstatesSeq16[REGION_CART0];
390	memory->waitstates32[REGION_CART1] = memory->waitstates32[REGION_CART1_EX] = memory->waitstates16[REGION_CART1] + 1 + memory->waitstatesSeq16[REGION_CART1];
391	memory->waitstates32[REGION_CART2] = memory->waitstates32[REGION_CART2_EX] = memory->waitstates16[REGION_CART2] + 1 + memory->waitstatesSeq16[REGION_CART2];
392
393	memory->waitstatesSeq32[REGION_CART0] = memory->waitstatesSeq32[REGION_CART0 + 1] = 2 * memory->waitstatesSeq16[REGION_CART0] + 1;
394	memory->waitstatesSeq32[REGION_CART1] = memory->waitstatesSeq32[REGION_CART1 + 1] = 2 * memory->waitstatesSeq16[REGION_CART1] + 1;
395	memory->waitstatesSeq32[REGION_CART2] = memory->waitstatesSeq32[REGION_CART2 + 1] = 2 * memory->waitstatesSeq16[REGION_CART2] + 1;
396
397	memory->d.activePrefetchCycles32 = memory->waitstates32[memory->activeRegion];
398	memory->d.activePrefetchCycles16 = memory->waitstates16[memory->activeRegion];
399}
400
401int32_t GBAMemoryProcessEvents(struct GBAMemory* memory, int32_t cycles) {
402	struct GBADMA* dma;
403	int32_t test = INT_MAX;
404
405	dma = &memory->dma[0];
406	dma->nextIRQ -= cycles;
407	if (dma->enable && dma->doIrq && dma->nextIRQ) {
408		if (dma->nextIRQ <= 0) {
409			dma->nextIRQ = INT_MAX;
410			GBARaiseIRQ(memory->p, IRQ_DMA0);
411		} else if (dma->nextIRQ < test) {
412			test = dma->nextIRQ;
413		}
414	}
415
416	dma = &memory->dma[1];
417	dma->nextIRQ -= cycles;
418	if (dma->enable && dma->doIrq && dma->nextIRQ) {
419		if (dma->nextIRQ <= 0) {
420			dma->nextIRQ = INT_MAX;
421			GBARaiseIRQ(memory->p, IRQ_DMA1);
422		} else if (dma->nextIRQ < test) {
423			test = dma->nextIRQ;
424		}
425	}
426
427	dma = &memory->dma[2];
428	dma->nextIRQ -= cycles;
429	if (dma->enable && dma->doIrq && dma->nextIRQ) {
430		if (dma->nextIRQ <= 0) {
431			dma->nextIRQ = INT_MAX;
432			GBARaiseIRQ(memory->p, IRQ_DMA2);
433		} else if (dma->nextIRQ < test) {
434			test = dma->nextIRQ;
435		}
436	}
437
438	dma = &memory->dma[3];
439	dma->nextIRQ -= cycles;
440	if (dma->enable && dma->doIrq && dma->nextIRQ) {
441		if (dma->nextIRQ <= 0) {
442			dma->nextIRQ = INT_MAX;
443			GBARaiseIRQ(memory->p, IRQ_DMA3);
444		} else if (dma->nextIRQ < test) {
445			test = dma->nextIRQ;
446		}
447	}
448
449	return test;
450}
451
452void GBAMemoryWriteDMASAD(struct GBAMemory* memory, int dma, uint32_t address) {
453	memory->dma[dma].source = address & 0xFFFFFFFE;
454}
455
456void GBAMemoryWriteDMADAD(struct GBAMemory* memory, int dma, uint32_t address) {
457	memory->dma[dma].dest = address & 0xFFFFFFFE;
458}
459
460void GBAMemoryWriteDMACNT_LO(struct GBAMemory* memory, int dma, uint16_t count) {
461	memory->dma[dma].count = count ? count : (dma == 3 ? 0x10000 : 0x4000);
462}
463
464void GBAMemoryWriteDMACNT_HI(struct GBAMemory* memory, int dma, uint16_t control) {
465	struct GBADMA* currentDma = &memory->dma[dma];
466	int wasEnabled = currentDma->enable;
467	currentDma->packed = control;
468	currentDma->nextIRQ = 0;
469
470	if (currentDma->drq) {
471		GBALog(GBA_LOG_STUB, "DRQ not implemented");
472	}
473
474	if (!wasEnabled && currentDma->enable) {
475		currentDma->nextSource = currentDma->source;
476		currentDma->nextDest = currentDma->dest;
477		currentDma->nextCount = currentDma->count;
478		GBAMemoryScheduleDMA(memory, dma, currentDma);
479	}
480};
481
482void GBAMemoryScheduleDMA(struct GBAMemory* memory, int number, struct GBADMA* info) {
483	switch (info->timing) {
484	case DMA_TIMING_NOW:
485		GBAMemoryServiceDMA(memory, number, info);
486		break;
487	case DMA_TIMING_HBLANK:
488		// Handled implicitly
489		break;
490	case DMA_TIMING_VBLANK:
491		// Handled implicitly
492		break;
493	case DMA_TIMING_CUSTOM:
494		switch (number) {
495		case 0:
496			GBALog(GBA_LOG_WARN, "Discarding invalid DMA0 scheduling");
497			break;
498		case 1:
499		case 2:
500			//this.cpu.irq.audio.scheduleFIFODma(number, info);
501			break;
502		case 3:
503			//this.cpu.irq.video.scheduleVCaptureDma(dma, info);
504			break;
505		}
506	}
507}
508
509void GBAMemoryRunHblankDMAs(struct GBAMemory* memory) {
510	struct GBADMA* dma;
511	int i;
512	for (i = 0; i < 4; ++i) {
513		dma = &memory->dma[i];
514		if (dma->enable && dma->timing == DMA_TIMING_HBLANK) {
515			GBAMemoryServiceDMA(memory, i, dma);
516		}
517	}
518}
519
520void GBAMemoryRunVblankDMAs(struct GBAMemory* memory) {
521	struct GBADMA* dma;
522	int i;
523	for (i = 0; i < 4; ++i) {
524		dma = &memory->dma[i];
525		if (dma->enable && dma->timing == DMA_TIMING_VBLANK) {
526			GBAMemoryServiceDMA(memory, i, dma);
527		}
528	}
529}
530
531void GBAMemoryServiceDMA(struct GBAMemory* memory, int number, struct GBADMA* info) {
532	if (!info->enable) {
533		// There was a DMA scheduled that got canceled
534		return;
535	}
536
537	uint32_t width = info->width ? 4 : 2;
538	int sourceOffset = DMA_OFFSET[info->srcControl] * width;
539	int destOffset = DMA_OFFSET[info->dstControl] * width;
540	int32_t wordsRemaining = info->nextCount;
541	uint32_t source = info->nextSource;
542	uint32_t dest = info->nextDest;
543	uint32_t sourceRegion = source >> BASE_OFFSET;
544	uint32_t destRegion = dest >> BASE_OFFSET;
545
546	if (width == 4) {
547		int32_t word;
548		source &= 0xFFFFFFFC;
549		dest &= 0xFFFFFFFC;
550		while (wordsRemaining--) {
551			word = GBALoad32(&memory->d, source);
552			GBAStore32(&memory->d, dest, word);
553			source += sourceOffset;
554			dest += destOffset;
555		}
556	} else {
557		uint16_t word;
558		while (wordsRemaining--) {
559			word = GBALoadU16(&memory->d, source);
560			GBAStore16(&memory->d, dest, word);
561			source += sourceOffset;
562			dest += destOffset;
563		}
564	}
565
566	if (info->doIrq) {
567		info->nextIRQ = memory->p->cpu.cycles + 2;
568		info->nextIRQ += (width == 4 ? memory->waitstates32[sourceRegion] + memory->waitstates32[destRegion]
569		                            : memory->waitstates16[sourceRegion] + memory->waitstates16[destRegion]);
570		info->nextIRQ += (info->count - 1) * (width == 4 ? memory->waitstatesSeq32[sourceRegion] + memory->waitstatesSeq32[destRegion]
571		                                               : memory->waitstatesSeq16[sourceRegion] + memory->waitstatesSeq16[destRegion]);
572	}
573
574	info->nextSource = source;
575	info->nextDest = dest;
576	info->nextCount = wordsRemaining;
577
578	if (!info->repeat) {
579		info->enable = 0;
580
581		// Clear the enable bit in memory
582		memory->io[(REG_DMA0CNT_HI + number * (REG_DMA1CNT_HI - REG_DMA0CNT_HI)) >> 1] &= 0x7FE0;
583	} else {
584		info->nextCount = info->count;
585		if (info->dstControl == DMA_INCREMENT_RELOAD) {
586			info->nextDest = info->dest;
587		}
588		GBAMemoryScheduleDMA(memory, number, info);
589	}
590}