aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNebuleon Fumika2013-02-03 05:59:48 -0500
committerNebuleon Fumika2013-02-03 05:59:48 -0500
commit461f2406555faaee7191871390192d06625f5a81 (patch)
treeedbbc706e1b565855c2ae37289a622429b454988
parentfd92545013ed91d2867e1e180a9b86611eb19f9c (diff)
downloadsnesemu-461f2406555faaee7191871390192d06625f5a81.tar.gz
snesemu-461f2406555faaee7191871390192d06625f5a81.tar.bz2
snesemu-461f2406555faaee7191871390192d06625f5a81.zip
Fix a name clash between Snes9x's dma.h and the DS2 dma.h by renaming the DS2 dma.h to ds2_dma.h.
Add preliminary support for drawing emulated screens with DS2 DMA.
-rw-r--r--Makefile5
-rw-r--r--sdk-modifications/include/ds2_dma.h138
-rw-r--r--sdk-modifications/libsrc/dma/dma.h46
-rw-r--r--sdk-modifications/libsrc/dma/dmacopy.c2
-rw-r--r--sdk-modifications/libsrc/dma/ds2_dma.h (renamed from sdk-modifications/include/dma.h)8
-rw-r--r--source/nds/entry.cpp37
6 files changed, 83 insertions, 153 deletions
diff --git a/Makefile b/Makefile
index e0732d3..854a285 100644
--- a/Makefile
+++ b/Makefile
@@ -35,7 +35,7 @@ C_SOURCES = source/unzip/explode.c source/unzip/unreduce.c \
source/unzip/unshrink.c source/unzip/unzip.c \
source/nds/bdf_font.c source/nds/bitmap.c \
source/nds/draw.c source/nds/ds2_main.c source/nds/gcheat.c \
- source/nds/gui.c
+ source/nds/gui.c source/nds/dma_adj.c
CPP_SOURCES = source/apu.cpp source/apudebug.cpp source/c4.cpp \
source/c4emu.cpp source/cheats2.cpp source/cheats.cpp \
source/clip.cpp source/cpu.cpp source/cpuexec.cpp \
@@ -70,7 +70,8 @@ DEFS := -DSPC700_C -DEXECUTE_SUPERFX_PER_LINE -DSDD1_DECOMP \
-DVAR_CYCLES -DCPU_SHUTDOWN -DSPC700_SHUTDOWN \
-DNO_INLINE_SET_GET -DNOASM -DHAVE_MKSTEMP '-DACCEPT_SIZE_T=size_t' \
-DUNZIP_SUPPORT -DFOREVER_16_BIT_SOUND -DFOREVER_STEREO \
- -DFOREVER_FORWARD_STEREO -DNO_VOLATILE_SOUND -DSYNC_JOYPAD_AT_HBLANK
+ -DFOREVER_FORWARD_STEREO -DNO_VOLATILE_SOUND \
+ -DSYNC_JOYPAD_AT_HBLANK -DDS2_DMA
.PHONY: clean makedirs
.SUFFIXES: .elf .dat .plg
diff --git a/sdk-modifications/include/ds2_dma.h b/sdk-modifications/include/ds2_dma.h
index c7cd267..491df0e 100644
--- a/sdk-modifications/include/ds2_dma.h
+++ b/sdk-modifications/include/ds2_dma.h
@@ -1,120 +1,50 @@
-#ifndef _DS2_DMA_H__
-#define _DS2_DMA_H__
+#ifndef __DMA_H__
+#define __DMA_H__
#ifdef __cplusplus
extern "C" {
#endif
-
-#define MAX_DMA_NUM 6 /* max 6 channels */
-
-
-// DMA request source register
-#define DMAC_DRSR_RS_BIT 0
-#define DMAC_DRSR_RS_AUTO (8 << DMAC_DRSR_RS_BIT)
-
-
-// DMA channel command register
-#define DMAC_DCMD_SAI (1 << 23) /* source address increment */
-#define DMAC_DCMD_DAI (1 << 22) /* dest address increment */
-
-#define DMAC_DCMD_SWDH_BIT 14 /* source port width */
-#define DMAC_DCMD_SWDH_32 (0 << DMAC_DCMD_SWDH_BIT)
-#define DMAC_DCMD_SWDH_8 (1 << DMAC_DCMD_SWDH_BIT)
-#define DMAC_DCMD_SWDH_16 (2 << DMAC_DCMD_SWDH_BIT)
-
-#define DMAC_DCMD_DWDH_BIT 12 /* dest port width */
-#define DMAC_DCMD_DWDH_32 (0 << DMAC_DCMD_DWDH_BIT)
-#define DMAC_DCMD_DWDH_8 (1 << DMAC_DCMD_DWDH_BIT)
- #define DMAC_DCMD_DWDH_16 (2 << DMAC_DCMD_DWDH_BIT)
-
-#define DMAC_DCMD_DS_BIT 8 /* transfer data size of a data unit */
-#define DMAC_DCMD_DS_32BIT (0 << DMAC_DCMD_DS_BIT)
-#define DMAC_DCMD_DS_8BIT (1 << DMAC_DCMD_DS_BIT)
-#define DMAC_DCMD_DS_16BIT (2 << DMAC_DCMD_DS_BIT)
-#define DMAC_DCMD_DS_16BYTE (3 << DMAC_DCMD_DS_BIT)
-#define DMAC_DCMD_DS_32BYTE (4 << DMAC_DCMD_DS_BIT)
-
-#define DMAC_DCMD_TM (1 << 7) /* transfer mode: 0-single 1-block */
-
-
-//detect if channel has completed job
-#define DMAC_DCCSR_TT (1 << 3) /* transfer terminated */
-#define DMAC_BASE 0xB3020000
-#define REG32(addr) *((volatile u32 *)(addr))
-#define DMAC_DCCSR(n) (DMAC_BASE + (0x10 + (n) * 0x20)) /* DMA control/status */
-#define REG_DMAC_DCCSR(n) REG32(DMAC_DCCSR((n)))
-
-#define ds2_DMA_isBusy(n) \
- !( REG_DMAC_DCCSR((n)) & DMAC_DCCSR_TT )
-
-
-/*
-Copy modes
-
-*/
-
-#define DMA_MODE32BYTE DMAC_DCMD_SWDH_32 | DMAC_DCMD_DWDH_32 | \
- DMAC_DCMD_DS_32BYTE | DMAC_DCMD_TM
-
-#define DMA_MODE16BYTE DMAC_DCMD_SWDH_16 | DMAC_DCMD_DWDH_16 | \
- DMAC_DCMD_DS_16BYTE | DMAC_DCMD_TM
-
-#define DMA_MODE32BIT DMAC_DCMD_SWDH_32 | DMAC_DCMD_DWDH_32 | \
- DMAC_DCMD_DS_32BIT
-
-#define DMA_MODE16BIT DMAC_DCMD_SWDH_16 | DMAC_DCMD_DWDH_16 | \
- DMAC_DCMD_DS_16BIT
-
-#define DMA_MODE8BIT DMAC_DCMD_SWDH_8 | DMAC_DCMD_DWDH_8 | \
- DMAC_DCMD_DS_8BIT | DMAC_DCMD_TM
-
-#define DMA_MODECOPY DMAC_DCMD_SAI
-
-
-
-extern int _dmaCopy(int ch, void *dest, void *src, unsigned int size, unsigned int flags);
-
-//copy from 32 bit source to 32 bit dest
-//data must be 32 byte aligned
-#define ds2_DMAcopy_32Byte(ch, dest, src, size)\
- _dmaCopy(ch, dest, src, size, DMA_MODECOPY | DMA_MODE32BYTE)
-
-//copy from 16 bit source to 16 bit dest
-//data must be 16 byte aligned
-#define ds2_DMAcopy_16Byte(ch, dest, src, size)\
- _dmaCopy(ch, dest, src, size, DMA_MODECOPY | DMA_MODE16BYTE);
-
-//copy from 32 bit source to 32 bit dest
-//data must be 32 bit aligned
-#define ds2_DMAcopy_32Bit(ch, dest, src, size)\
- _dmaCopy(ch, dest, src, size, DMA_MODECOPY | DMA_MODE32BIT);
-
-//copy from 16 bit source to 16 bit dest
-//data must be 16 bit aligned
-#define ds2_DMAcopy_16Bit(ch, dest, src, size)\
- _dmaCopy(ch, dest, src, size, DMA_MODECOPY | DMA_MODE16BIT)
-
-//copy from 8 bit source to 8 bit dest
-//data must be 8 bit aligned
-#define ds2_DMAcopy_8Bit(ch, dest, src, size)\
- _dmaCopy(ch, dest, src, size, DMA_MODECOPY | DMA_MODE8BIT)
-
-
+//register a DMA transfer request
+//ch: channel id request, there are 6 channles,
+//irq_handler: the DMA interruption handle
+//arg: argument to the handle
+//mode: DMA mode, such as port width, address increased/fixed, and so on
+//type: DMA request type
+extern int dma_request(int ch, void (*irq_handler)(unsigned int), unsigned int arg,
+ unsigned int mode, unsigned int type);
+
+//start DMA transfer, must request a DMA first
+//ch: channel id
+//srcAddr: DMA source address
+//dstAddr: DMA destination address
+//count: DMA transfer count, the total bytes due the mode in dma_request
+extern void dma_start(int ch, unsigned int srcAddr, unsigned int dstAddr,
+ unsigned int count);
//Stop DMA transfer
extern void dma_stop(int ch);
-#define ds2_DMA_stop(ch)\
- dma_stop(ch)
-
//Wait DMA transfer over
extern int dma_wait_finish(int ch);
-#define ds2_DMA_wait(ch)\
- dma_wait_finish(ch)
-
+/*
+ * Copy 'size' bytes from src to dest, in blocks of 32 bytes.
+ * size is in bytes and must be a multiple of 32.
+ * Both src and dest must be aligned to 32 bytes.
+ * Returns 0 on failure, non-zero on success.
+ */
+extern int dma_copy32Byte(int ch, void *dest, void *src, unsigned int size);
+// Blocks of 16 bytes, aligned to 16 bytes
+extern int dma_copy16Byte(int ch, void *dest, void *src, unsigned int size);
+// Blocks of 4 bytes, aligned to 4 bytes
+extern int dma_copy32Bit(int ch, void *dest, void *src, unsigned int size);
+// Blocks of 2 bytes, aligned to 2 bytes
+extern int dma_copy16Bit(int ch, void *dest, void *src, unsigned int size);
+extern int dma_isBusy(int ch);
+extern int dma_isFree(int ch);
+extern int dma_getFree(void);
#ifdef __cplusplus
}
diff --git a/sdk-modifications/libsrc/dma/dma.h b/sdk-modifications/libsrc/dma/dma.h
deleted file mode 100644
index f6ff230..0000000
--- a/sdk-modifications/libsrc/dma/dma.h
+++ /dev/null
@@ -1,46 +0,0 @@
-#ifndef __DMA_H__
-#define __DMA_H__
-
-//register a DMA transfer request
-//ch: channel id request, there are 6 channles,
-//irq_handler: the DMA interruption handle
-//arg: argument to the handle
-//mode: DMA mode, such as port width, address increased/fixed, and so on
-//type: DMA request type
-extern int dma_request(int ch, void (*irq_handler)(unsigned int), unsigned int arg,
- unsigned int mode, unsigned int type);
-
-//start DMA transfer, must request a DMA first
-//ch: channel id
-//srcAddr: DMA source address
-//dstAddr: DMA destination address
-//count: DMA transfer count, the total bytes due the mode in dma_request
-extern void dma_start(int ch, unsigned int srcAddr, unsigned int dstAddr,
- unsigned int count);
-
-//Stop DMA transfer
-extern void dma_stop(int ch);
-
-//Wait DMA transfer over
-extern int dma_wait_finish(int ch);
-
-
-/*
- * Copy 'size' bytes from src to dest, in blocks of 32 bytes.
- * size is in bytes and must be a multiple of 32.
- * Both src and dest must be aligned to 32 bytes.
- * Returns 0 on failure, non-zero on success.
- */
-extern int dma_copy32Byte(int ch, void *dest, void *src, unsigned int size);
-// Blocks of 16 bytes, aligned to 16 bytes
-extern int dma_copy16Byte(int ch, void *dest, void *src, unsigned int size);
-// Blocks of 4 bytes, aligned to 4 bytes
-extern int dma_copy32Bit(int ch, void *dest, void *src, unsigned int size);
-// Blocks of 2 bytes, aligned to 2 bytes
-extern int dma_copy16Bit(int ch, void *dest, void *src, unsigned int size);
-extern int dma_isBusy(int ch);
-extern int dma_isFree(int ch);
-extern int dma_getFree(void);
-
-#endif //__DMA_H__
-
diff --git a/sdk-modifications/libsrc/dma/dmacopy.c b/sdk-modifications/libsrc/dma/dmacopy.c
index 2c5a2b1..83609d3 100644
--- a/sdk-modifications/libsrc/dma/dmacopy.c
+++ b/sdk-modifications/libsrc/dma/dmacopy.c
@@ -1,5 +1,5 @@
#include <stdlib.h>
-#include "dma.h"
+#include "ds2_dma.h"
#include "ds2_types.h"
#define MAX_DMA_NUM 6 /* max 6 channels */
diff --git a/sdk-modifications/include/dma.h b/sdk-modifications/libsrc/dma/ds2_dma.h
index f6ff230..491df0e 100644
--- a/sdk-modifications/include/dma.h
+++ b/sdk-modifications/libsrc/dma/ds2_dma.h
@@ -1,6 +1,10 @@
#ifndef __DMA_H__
#define __DMA_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
//register a DMA transfer request
//ch: channel id request, there are 6 channles,
//irq_handler: the DMA interruption handle
@@ -42,5 +46,9 @@ extern int dma_isBusy(int ch);
extern int dma_isFree(int ch);
extern int dma_getFree(void);
+#ifdef __cplusplus
+}
+#endif
+
#endif //__DMA_H__
diff --git a/source/nds/entry.cpp b/source/nds/entry.cpp
index 5d79b64..4aa2977 100644
--- a/source/nds/entry.cpp
+++ b/source/nds/entry.cpp
@@ -23,6 +23,11 @@
#include "entry.h"
#include "ds2sound.h"
+#ifdef DS2_DMA
+#include "ds2_dma.h"
+#include "dma_adj.h"
+#endif
+
void S9xProcessSound (unsigned int);
char *rom_filename = NULL;
@@ -58,7 +63,11 @@ void S9xExtraUsage ()
*/
void S9xDeinitDisplay (void)
{
+#ifdef DS2_DMA
+ if(GFX.Screen) AlignedFree(GFX.Screen, PtrAdj.GFXScreen);
+#else
if(GFX.Screen) free(GFX.Screen);
+#endif
if(GFX.SubScreen) free(GFX.SubScreen);
if(GFX.ZBuffer) free(GFX.ZBuffer);
if(GFX.SubZBuffer) free(GFX.SubZBuffer);
@@ -69,7 +78,11 @@ void S9xInitDisplay (int, char **)
int h = IMAGE_HEIGHT;
GFX.Pitch = IMAGE_WIDTH * 2;
+#ifdef DS2_DMA
+ GFX.Screen = (unsigned char*) AlignedMalloc (GFX.Pitch * h, 32, &PtrAdj.GFXScreen);
+#else
GFX.Screen = (unsigned char*) malloc (GFX.Pitch * h);
+#endif
GFX.SubScreen = (unsigned char*) malloc (GFX.Pitch * h);
GFX.ZBuffer = (unsigned char*) malloc ((GFX.Pitch >> 1) * h);
GFX.SubZBuffer =(unsigned char*) malloc ((GFX.Pitch >> 1) * h);
@@ -130,17 +143,35 @@ bool8 S9xDeinitUpdate (int Width, int Height, bool8 /*sixteen_bit*/)
{
//Up
case 1:
+#ifdef DS2_DMA
+ dma_copy32Byte(5 /* channel: graphics */, up_screen_addr, GFX.Screen + 256 * 32 * 2, 256 * 192 * 2);
+ dma_wait_finish(5);
+ dma_stop(5);
+#else
memcpy(up_screen_addr, GFX.Screen+256*32*2, 256*192*2);
+#endif
break;
//Down
case 2:
+#ifdef DS2_DMA
+ dma_copy32Byte(5 /* channel: graphics */, up_screen_addr, GFX.Screen, 256 * 192 * 2);
+ dma_wait_finish(5);
+ dma_stop(5);
+#else
memcpy(up_screen_addr, GFX.Screen, 256*192*2);
+#endif
break;
//Both
case 3:
+#ifdef DS2_DMA
+ dma_copy32Byte(5 /* channel: graphics */, up_screen_addr, GFX.Screen + 256 * 16 * 2, 256 * 192 * 2);
+ dma_wait_finish(5);
+ dma_stop(5);
+#else
memcpy(up_screen_addr, GFX.Screen+256*16*2, 256*192*2);
+#endif
break;
case 4:
@@ -157,7 +188,13 @@ bool8 S9xDeinitUpdate (int Width, int Height, bool8 /*sixteen_bit*/)
dst = (unsigned char*)up_screen_addr;
for(m = 0; m < 32; m++)
{
+#ifdef DS2_DMA
+ dma_copy32Byte(5 /* channel: graphics */, dst, src, 256 * 6 * 2);
+ dma_wait_finish(5);
+ dma_stop(5);
+#else
memcpy(dst, src, 256*6*2);
+#endif
dst += 256*6*2;
src += 256*7*2;
}