Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Got this building libzengarden.a for Nintendo DS. A stub testing prog…

…ram is in src/ZenGardenDS/ but it is not yet functional.
  • Loading branch information...
commit afbf6587a30f1bd59972b43c6ee36c7d9923177d 1 parent da92238
chrism authored
1  .gitignore
View
@@ -10,5 +10,6 @@ Xcode/build
Xcode/Xcode.xcodeproj/mhroth.pbxuser
Xcode/Xcode.xcodeproj/mhroth.mode1v3
src/main.cpp
+src/sndfile.h
.*.swp
*.pyc
24 README
View
@@ -18,6 +18,7 @@ Requirements
libsndfile
- OSX: port install libsndfile
- Debian GNU/Linux: apt-get install libsndfile1-dev
+ - Nintendo DS: *experimental* see below
java - for the java example - you need at least java5
- Debian: apt-get install sun-java6-jdk
@@ -50,6 +51,29 @@ You can build individual components like so:
# build the Java hosted example
make examplegarden
+Build: Nintendo DS
+------------------
+
+To build for Nintendo DS you first need to build libsndfile for NDS:
+ * Download it from http://www.mega-nerd.com/libsndfile/#Download
+ * Run the following commands in the directory where you unpacked the libsndfile source:
+
+ export PATH=$PATH:$DEVKITARM/bin/
+ ./configure --enable-shared=no --enable-static=yes --disable-largefile --disable-alsa --disable-sqlite --host=arm-eabi --disable-external-libs --disable-test-coverage
+ make
+ # you may experience some errors to do with tests, but the .a file should be built anyway
+ # now copy the libsndfile.a library into your ZenGarden development directory
+ cp src/.libs/libsndfile.a ../ZenGarden/src/
+ # finally, copy the sndfile.h header file to the ZenGarden development directory
+ cp src/sndfile.h ../ZenGarden/src/
+
+Finally, to build a static library for the nintendo DS, invoke the following command:
+
+ OS=nds make libzengarden-static
+
+This will create ../libs/nds/libzengarden.a and you can use this library to
+statically link into your nintendo DS programs.
+
Advantages
----------
BIN  ZenGarden.jar
View
Binary file not shown
BIN  libs/Darwin-i386/libjnizengarden.jnilib
View
Binary file not shown
BIN  libs/Darwin-i386/libzengarden.a
View
Binary file not shown
BIN  libs/Darwin-i386/libzengarden.dylib
View
Binary file not shown
BIN  libs/nds/libsndfile.a
View
Binary file not shown
BIN  libs/nds/libzengarden.a
View
Binary file not shown
13 src/Makefile
View
@@ -12,7 +12,9 @@ CXXFLAGS = -g -Os -fPIC -Wall -I$(my-dir) $(SNDFILE_INCLUDE)
# figure out what platform we're on
-OS=$(shell ./platform)
+ifndef OS
+ OS=$(shell ./platform)
+endif
ifeq (,$(findstring Makefile.OS.$(OS),$(OS_MAKEFILES)))
@@ -29,14 +31,19 @@ else
include Makefile.OS.$(OS)
-all: platform libzengarden libjnizengarden examplegarden
+all: platform libzengarden libzengarden-static libjnizengarden examplegarden
platform: Makefile.OS.$(OS)
@echo "Building for the $(OS) platform"
@mkdir -p ../libs/$(OS)
clean:
- rm -rf $(LOCAL_MODULE).so *.o me/rjdj/zengarden/*.class ../ZenGarden.jar ../libs/$(OS)/*
+ rm -rf $(LOCAL_MODULE).so *.d *.o me/rjdj/zengarden/*.class ../ZenGarden.jar ../libs/$(OS)/*
+
+libzengarden-static: ../libs/$(OS)/libzengarden.a
+
+../libs/$(OS)/libzengarden.a: $(OBJS)
+ $(AR) rcs $@ $(OBJS)
libjnizengarden: ../libs/$(OS)/libjnizengarden.$(JNI_EXTENSION)
150 src/Makefile.OS.nds
View
@@ -0,0 +1,150 @@
+#---------------------------------------------------------------------------------
+.SUFFIXES:
+#---------------------------------------------------------------------------------
+
+ifeq ($(strip $(DEVKITARM)),)
+$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
+endif
+
+include $(DEVKITARM)/ds_rules
+
+#---------------------------------------------------------------------------------
+# TARGET is the name of the output
+# BUILD is the directory where object files & intermediate files will be placed
+# SOURCES is a list of directories containing source code
+# INCLUDES is a list of directories containing extra header files
+# DATA is a list of directories containing binary data
+# GRAPHICS is a list of directories containing files to be processed by grit
+#
+# All directories are specified relative to the project directory where
+# the makefile is found
+#
+#---------------------------------------------------------------------------------
+TARGET := $(notdir $(CURDIR))
+BUILD := ./
+
+#---------------------------------------------------------------------------------
+# options for code generation
+#---------------------------------------------------------------------------------
+ARCH := -mthumb -mthumb-interwork
+
+CFLAGS := -g -Wall -O2\
+ -march=armv5te -mtune=arm946e-s -fomit-frame-pointer\
+ -ffast-math \
+ $(ARCH)
+
+CFLAGS += $(INCLUDE) -DARM
+CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -I. -L.
+
+ASFLAGS := -g $(ARCH)
+LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
+
+#---------------------------------------------------------------------------------
+# any extra libraries we wish to link with the project
+#---------------------------------------------------------------------------------
+LIBS := -lmm9 -lnds9
+
+
+#---------------------------------------------------------------------------------
+# list of directories containing libraries, this must be the top level containing
+# include and lib
+#---------------------------------------------------------------------------------
+LIBDIRS := $(LIBNDS)
+
+#---------------------------------------------------------------------------------
+# no real need to edit anything past this point unless you need to add additional
+# rules for different file extensions
+#---------------------------------------------------------------------------------
+
+
+ifneq ($(BUILDDIR), $(CURDIR))
+#---------------------------------------------------------------------------------
+
+export OUTPUT := $(CURDIR)/$(TARGET)
+
+export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
+ $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \
+ $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
+
+export DEPSDIR := $(CURDIR)/$(BUILD)
+
+CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
+CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
+SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
+BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) soundbank.bin
+
+export AUDIOFILES := $(foreach dir,$(notdir $(wildcard $(MUSIC)/*.*)),$(CURDIR)/$(MUSIC)/$(dir))
+
+#---------------------------------------------------------------------------------
+# use CXX for linking C++ projects, CC for standard C
+#---------------------------------------------------------------------------------
+ifeq ($(strip $(CPPFILES)),)
+#---------------------------------------------------------------------------------
+ export LD := $(CC)
+#---------------------------------------------------------------------------------
+else
+#---------------------------------------------------------------------------------
+ export LD := $(CXX)
+#---------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------
+
+export OFILES := $(addsuffix .o,$(BINFILES)) \
+ $(BMPFILES:.bmp=.o) \
+ $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
+
+export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \
+ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
+ -I$(CURDIR)/$(BUILD)
+
+export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
+
+#.PHONY: $(BUILD) clean
+
+#---------------------------------------------------------------------------------
+#$(BUILD):
+# @[ -d $@ ] || mkdir -p $@
+# @make BUILDDIR=`cd $(BUILD) && pwd` --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
+
+#---------------------------------------------------------------------------------
+else
+
+#---------------------------------------------------------------------------------
+# main targets
+#---------------------------------------------------------------------------------
+$(OUTPUT).nds : $(OUTPUT).arm9
+$(OUTPUT).arm9 : $(OUTPUT).elf
+$(OUTPUT).elf : $(OFILES)
+
+
+#---------------------------------------------------------------------------------
+# The bin2o rule should be copied and modified
+# for each extension used in the data directories
+#---------------------------------------------------------------------------------
+
+#---------------------------------------------------------------------------------
+# rule to build soundbank from music files
+#---------------------------------------------------------------------------------
+soundbank.bin : $(AUDIOFILES)
+#---------------------------------------------------------------------------------
+ @mmutil $^ -d -osoundbank.bin -hsoundbank.h
+
+#---------------------------------------------------------------------------------
+# This rule links in binary data with the .bin extension
+#---------------------------------------------------------------------------------
+%.bin.o : %.bin
+#---------------------------------------------------------------------------------
+ @echo $(notdir $<)
+ @$(bin2o)
+
+
+
+-include $(DEPSDIR)/*.d
+
+#---------------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------------
+
+MAKE_SO=$(CC) -o $(1) $(CXXFLAGS) -shared $(2) $(3) $(SNDFILE_LIB) -lstdc++
+JNI_EXTENSION=so
+SO_EXTENSION=so
142 src/ZenGardenDS/Makefile
View
@@ -0,0 +1,142 @@
+#---------------------------------------------------------------------------------
+.SUFFIXES:
+#---------------------------------------------------------------------------------
+
+ifeq ($(strip $(DEVKITARM)),)
+$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM)
+endif
+
+include $(DEVKITARM)/ds_rules
+
+#---------------------------------------------------------------------------------
+# TARGET is the name of the output
+# BUILD is the directory where object files & intermediate files will be placed
+# SOURCES is a list of directories containing source code
+# INCLUDES is a list of directories containing extra header files
+# MAXMOD_SOUNDBANK contains a directory of music and sound effect files
+#---------------------------------------------------------------------------------
+TARGET := $(shell basename $(CURDIR))
+BUILD := build
+SOURCES := gfx source data
+INCLUDES := include build
+MAXMOD_SOUNDBANK := music
+#---------------------------------------------------------------------------------
+# options for code generation
+#---------------------------------------------------------------------------------
+ARCH := -mthumb -mthumb-interwork \
+ -march=armv5te -mtune=arm946e-s
+
+CFLAGS := -g -Wall -O2\
+ -fomit-frame-pointer\
+ -ffast-math \
+ $(ARCH)
+
+CFLAGS += $(INCLUDE) -DARM9
+CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
+
+ASFLAGS := -g $(ARCH)
+LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
+
+#---------------------------------------------------------------------------------
+# any extra libraries we wish to link with the project
+#---------------------------------------------------------------------------------
+LIBS := -lnds9
+
+#---------------------------------------------------------------------------------
+# list of directories containing libraries, this must be the top level containing
+# include and lib
+#---------------------------------------------------------------------------------
+LIBDIRS := $(LIBNDS)
+
+#---------------------------------------------------------------------------------
+# no real need to edit anything past this point unless you need to add additional
+# rules for different file extensions
+#---------------------------------------------------------------------------------
+ifneq ($(BUILD),$(notdir $(CURDIR)))
+#---------------------------------------------------------------------------------
+
+export OUTPUT := $(CURDIR)/$(TARGET)
+
+export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
+export DEPSDIR := $(CURDIR)/$(BUILD)
+
+CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
+CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
+SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
+BINFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.bin)))
+
+#---------------------------------------------------------------------------------
+# build audio file list, include full path
+#---------------------------------------------------------------------------------
+export AUDIOFILES := $(foreach dir,$(notdir $(wildcard $(MAXMOD_SOUNDBANK)/*.*)),$(CURDIR)/$(MAXMOD_SOUNDBANK)/$(dir))
+
+ifneq ($(strip $(AUDIOFILES)),)
+BINFILES += soundbank.bin
+endif
+
+#---------------------------------------------------------------------------------
+# use CXX for linking C++ projects, CC for standard C
+#---------------------------------------------------------------------------------
+ifeq ($(strip $(CPPFILES)),)
+#---------------------------------------------------------------------------------
+ export LD := $(CC)
+#---------------------------------------------------------------------------------
+else
+#---------------------------------------------------------------------------------
+ export LD := $(CXX)
+#---------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------
+
+export OFILES := $(BINFILES:.bin=.o) \
+ $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
+
+export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
+ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
+ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
+ -I$(CURDIR)/$(BUILD)
+
+export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
+
+.PHONY: $(BUILD) clean
+
+#---------------------------------------------------------------------------------
+$(BUILD):
+ @[ -d $@ ] || mkdir -p $@
+ @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
+
+#---------------------------------------------------------------------------------
+clean:
+ @echo clean ...
+ @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 $(TARGET).ds.gba
+
+
+#---------------------------------------------------------------------------------
+else
+
+DEPENDS := $(OFILES:.o=.d)
+
+#---------------------------------------------------------------------------------
+# main targets
+#---------------------------------------------------------------------------------
+$(OUTPUT).nds : $(OUTPUT).arm9
+$(OUTPUT).arm9 : $(OUTPUT).elf
+$(OUTPUT).elf : $(OFILES)
+
+#---------------------------------------------------------------------------------
+%.o : %.bin
+#---------------------------------------------------------------------------------
+ @echo $(notdir $<)
+ $(bin2o)
+
+#---------------------------------------------------------------------------------
+soundbank.bin : $(AUDIOFILES)
+#---------------------------------------------------------------------------------
+ @echo creating soundbank...
+ @mmutil -d $(AUDIOFILES) -osoundbank.bin -hsoundbank.h
+
+-include $(DEPENDS)
+
+#---------------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------------
1  src/ZenGardenDS/README
View
@@ -0,0 +1 @@
+This will be the Nintendo DS example program for running ZenGarden patches.
84 src/ZenGardenDS/source/main.c
View
@@ -0,0 +1,84 @@
+#include <nds.h>
+#include <stdio.h>
+
+//the record sample rate
+#define sample_rate 8000
+
+//buffer to hold sound data for playback
+u16* sound_buffer = 0;
+
+//buffer which is written to by the arm7
+u16* mic_buffer = 0;
+
+//the length of the current data
+u32 data_length = 0;
+
+//enough hold 5 seconds of 16bit audio
+u32 sound_buffer_size = sample_rate * 2 * 5;
+
+//the mic buffer sent to the arm7 is a double buffer
+//every time it is half full the arm7 signals us so we can read the
+//data. I want the buffer to swap about once per frame so i chose a
+//buffer size large enough to hold two frames of 16bit mic data
+u32 mic_buffer_size = sample_rate * 2 / 30;
+
+
+//mic stream handler
+void micHandler(void* data, int length)
+{
+ if(!sound_buffer || data_length > sound_buffer_size) return;
+
+
+ DC_InvalidateRange(data, length);
+
+ dmaCopy(data, ((u8*)sound_buffer) + data_length, length);
+
+ data_length += length;
+
+ iprintf(".");
+
+}
+
+void record(void)
+{
+ data_length = 0;
+ soundMicRecord(mic_buffer, mic_buffer_size, MicFormat_12Bit, sample_rate, micHandler);
+}
+
+void play(void)
+{
+ soundMicOff();
+ soundEnable();
+ iprintf("data length: %i\n", data_length);
+ soundPlaySample(sound_buffer, SoundFormat_16Bit, data_length, sample_rate, 127, 64, false, 0);
+}
+
+int main(void)
+{
+ int key;
+ bool recording = false;
+
+ sound_buffer = (u16*)malloc(sound_buffer_size);
+ mic_buffer = (u16*)malloc(mic_buffer_size);
+
+ consoleDemoInit();
+
+ iprintf("Press A to record / play\n");
+
+ while(1)
+ {
+
+ scanKeys();
+ key = keysDown();
+
+ if(key & KEY_A)
+ {
+ recording ? play() : record();
+ recording = !recording;
+ iprintf("%s\n", recording ? "recording" : "playing");
+ }
+
+ swiWaitForVBlank();
+
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.