From: <c99...@us...> - 2006-07-08 01:57:20
|
Revision: 348 Author: c99koder Date: 2006-07-07 18:57:14 -0700 (Fri, 07 Jul 2006) ViewCVS: http://svn.sourceforge.net/cadcdev/?rev=348&view=rev Log Message: ----------- Tiki: NDS build fixes Modified Paths: -------------- tiki/examples/TikiTest/Makefile tiki/nds/Makefile.rules tiki/nds/src/Makefile Added Paths: ----------- tiki/nds/src/audio/ tiki/nds/src/audio/sound.cpp tiki/nds/src/audio/stream.cpp Modified: tiki/examples/TikiTest/Makefile =================================================================== --- tiki/examples/TikiTest/Makefile 2006-07-06 19:18:05 UTC (rev 347) +++ tiki/examples/TikiTest/Makefile 2006-07-08 01:57:14 UTC (rev 348) @@ -4,7 +4,7 @@ OBJS = $(patsubst %.cpp,%.o,$(wildcard src/*.cpp)) all: $(OBJS) - $(CXX) -L$(TIKI_DIR)$(TIKI_PLAT) -L$(TIKI_DIR)$(TIKI_PLAT)/lib $(OBJS) $(TIKI_BASE_LIBS) -o tikitest + $(CXX) $(LDFLAGS) -L$(TIKI_DIR)$(TIKI_PLAT) -L$(TIKI_DIR)$(TIKI_PLAT)/lib $(OBJS) $(TIKI_BASE_LIBS) -o tikitest clean: -rm -f $(OBJS) tikitest Modified: tiki/nds/Makefile.rules =================================================================== --- tiki/nds/Makefile.rules 2006-07-06 19:18:05 UTC (rev 347) +++ tiki/nds/Makefile.rules 2006-07-08 01:57:14 UTC (rev 348) @@ -31,4 +31,4 @@ LDFLAGS=-specs=ds_arm9.specs -mthumb -mthumb-interwork -mno-fpu -L$(DEVKITPRO)/lib -lgcc -include $(DEVKITPRO)/ds_rules +include $(DEVKITARM)/ds_rules Modified: tiki/nds/src/Makefile =================================================================== --- tiki/nds/src/Makefile 2006-07-06 19:18:05 UTC (rev 347) +++ tiki/nds/src/Makefile 2006-07-08 01:57:14 UTC (rev 348) @@ -1,5 +1,6 @@ OBJS = $(patsubst %.cpp,%.o,$(wildcard *.cpp)) +OBJS += $(patsubst %.cpp,%.o,$(wildcard audio/*.cpp)) all: $(OBJS) $(AR) ru ../libtiki.a $(OBJS) Added: tiki/nds/src/audio/sound.cpp =================================================================== --- tiki/nds/src/audio/sound.cpp (rev 0) +++ tiki/nds/src/audio/sound.cpp 2006-07-08 01:57:14 UTC (rev 348) @@ -0,0 +1,76 @@ +/* + Tiki + + sound.cpp + + Copyright (C)2002,2003,2004 Dan Potter + Copyright (C)2005 Cryptic Allusion, LLC +*/ + +#include "pch.h" +#include "Tiki/sound.h" +#include "Tiki/file.h" + +#include <string.h> + +using namespace Tiki::Audio; + +TIKI_OBJECT_NAME(Sound) +TIKI_OBJECT_BEGIN(Object, Sound) +TIKI_OBJECT_END(Sound) + +////////////////////////////////////////////////////////////////////////////////////////// + +float Sound::m_default_vol = 0.9f; + +bool Sound::initGlobal() { + return true; +} + +void Sound::shutdownGlobal() { + stopAll(); +} + +void Sound::stop(int ch) { +} + +void Sound::stopAll() { +} + +////////////////////////////////////////////////////////////////////////////////////////// + +Sound::Sound(const string & fn) { + if (!loadFromFile(fn)) + assert( false ); +} + +Sound::Sound() { +} + +Sound::~Sound() { +} + +bool Sound::loadFromFile(const string & fn) { + return false; +} + +// Set the default volume value +void Sound::setDefaultVolume(float vol) { + m_default_vol = vol; +} + +int Sound::play() { + return -1; +} + +int Sound::play(float vol) { + return -1; +} + +int Sound::play(float vol, float pan) { + return -1; +} + +void Sound::play(int ch, float vol, float pan) { +} + Property changes on: tiki/nds/src/audio/sound.cpp ___________________________________________________________________ Name: svn:executable + * Added: tiki/nds/src/audio/stream.cpp =================================================================== --- tiki/nds/src/audio/stream.cpp (rev 0) +++ tiki/nds/src/audio/stream.cpp 2006-07-08 01:57:14 UTC (rev 348) @@ -0,0 +1,162 @@ +/* + Tiki + + stream.cpp + + Copyright (C)2005 Cryptic Allusion, LLC +*/ + +#include "pch.h" +#include "Tiki/stream.h" + +#include <string.h> + +using namespace Tiki::Audio; +using namespace Tiki::Thread; + +TIKI_OBJECT_NAME(Stream) +TIKI_OBJECT_BEGIN(Object, Stream) + TIKI_OBJECT_RECEIVER("start", Stream::objectStart) + TIKI_OBJECT_RECEIVER("stop", Stream::objectStop) +TIKI_OBJECT_END(Stream) + + +bool Stream::initGlobal() { + return true; +} + +void Stream::shutdownGlobal() { +} + +Stream::Stream() { + // Default our members. + m_bufSize = 0x4000; + m_chnCount = 2; + m_freq = 44100; + m_queueing = false; + m_state = StateStopped; + m_volume = 0.8f; + m_mutex = new Mutex(); +} + +Stream::~Stream() { + destroy(); +} + +bool Stream::create() { + AutoLock lock(m_mutex); + return true; +} + +void Stream::destroy() { + AutoLock lock(m_mutex); +} + +// virtual void filter(int freq, int chncount, void * buffer, int smpcnt) { } + +void Stream::filterAdd(Filter * f) { + AutoLock lock(m_mutex); + + m_filters.insertTail(f); +} + +void Stream::filterRemove(Filter * f) { + AutoLock lock(m_mutex); + + m_filters.del(f); +} + +void Stream::setQueueing(bool isQueued) { + AutoLock lock(m_mutex); + + m_queueing = isQueued; +} + +void Stream::setFrequency(int freq) { + AutoLock lock(m_mutex); + + m_freq = freq; +} + +void Stream::setChannelCount(int chncount) { + AutoLock lock(m_mutex); + + m_chnCount = chncount; +} + +void Stream::start() { + AutoLock lock(m_mutex); + m_state = StatePlaying; +} + +void Stream::stop() { + AutoLock lock(m_mutex); + m_state = StateStopped; +} + +void Stream::pause() { + AutoLock lock(m_mutex); + m_state = StatePaused; +} + +void Stream::resume() { + AutoLock lock(m_mutex); + m_state = StatePlaying; +} + +void Stream::setVolume(float vol) { + AutoLock lock(m_mutex); + + m_volume = vol; +} + +bool Stream::isPlaying() { + AutoLock lock(m_mutex); + + return m_state == StatePlaying; +} + +int Stream::objectStart(Object * /*from*/, Object * /*arg*/) { + start(); return 0; +} + +int Stream::objectStop(Object * /*from*/, Object * /*arg*/) { + stop(); return 0; +} + + +void Stream::processFilters(void * buffer, int smpcnt) { +} + +// "len" is a *sample* count. +void Stream::sepData(void * buffer, int len, bool stereo, int16 * outl, int16 * outr) { + int16 * sep_buffer[2] = { outl, outr }; + int16 * bufsrc, * bufdst; + int cnt; + + if (stereo) { + bufsrc = (int16*)buffer; + bufdst = sep_buffer[0]; + cnt = len; + do { + *bufdst = *bufsrc; + bufdst++; bufsrc+=2; cnt--; + } while (cnt > 0); + + bufsrc = (int16*)buffer; bufsrc++; + bufdst = sep_buffer[1]; + cnt = len; + do { + *bufdst = *bufsrc; + bufdst++; bufsrc+=2; cnt--; + } while (cnt > 0); + } else { + memcpy(sep_buffer[0], buffer, len * 2); + memcpy(sep_buffer[1], buffer, len * 2); + } +} + +Stream::GetDataResult Stream::getData(uint16 * buffer, int * numSamples) { + return GDError; +} + Property changes on: tiki/nds/src/audio/stream.cpp ___________________________________________________________________ Name: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <c99...@us...> - 2007-07-17 23:06:59
|
Revision: 417 http://svn.sourceforge.net/cadcdev/?rev=417&view=rev Author: c99koder Date: 2007-07-17 16:06:07 -0700 (Tue, 17 Jul 2007) Log Message: ----------- NDS: Link with libfat, initialize libfat and the DS hardware, remove AutoLock calls from Stream class, and handle DS input events during VBlank interrupt Modified Paths: -------------- tiki/nds/Makefile.rules tiki/nds/src/audio/stream.cpp tiki/nds/src/init_shutdown.cpp tiki/nds/src/plathid.cpp tiki/nds/src/tikitime.cpp Modified: tiki/nds/Makefile.rules =================================================================== --- tiki/nds/Makefile.rules 2007-07-08 01:05:36 UTC (rev 416) +++ tiki/nds/Makefile.rules 2007-07-17 23:06:07 UTC (rev 417) @@ -12,7 +12,7 @@ $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitARM) endif -TIKI_BASE_LIBS=-ltiki -L$(DEVKITPRO)/libnds/lib -lnds9 +TIKI_BASE_LIBS=-ltiki -L$(DEVKITPRO)/libnds/lib -lfat -lnds9 CXXFLAGS=-I$(DEVKITPRO)/libnds/include Modified: tiki/nds/src/audio/stream.cpp =================================================================== --- tiki/nds/src/audio/stream.cpp 2007-07-08 01:05:36 UTC (rev 416) +++ tiki/nds/src/audio/stream.cpp 2007-07-17 23:06:07 UTC (rev 417) @@ -36,83 +36,61 @@ m_queueing = false; m_state = StateStopped; m_volume = 0.8f; - m_mutex = new Mutex(); } Stream::~Stream() { - destroy(); } bool Stream::create() { - AutoLock lock(m_mutex); return true; } void Stream::destroy() { - AutoLock lock(m_mutex); } // virtual void filter(int freq, int chncount, void * buffer, int smpcnt) { } void Stream::filterAdd(Filter * f) { - AutoLock lock(m_mutex); - m_filters.insertTail(f); } void Stream::filterRemove(Filter * f) { - AutoLock lock(m_mutex); - m_filters.del(f); } void Stream::setQueueing(bool isQueued) { - AutoLock lock(m_mutex); - m_queueing = isQueued; } void Stream::setFrequency(int freq) { - AutoLock lock(m_mutex); - m_freq = freq; } void Stream::setChannelCount(int chncount) { - AutoLock lock(m_mutex); - m_chnCount = chncount; } void Stream::start() { - AutoLock lock(m_mutex); m_state = StatePlaying; } void Stream::stop() { - AutoLock lock(m_mutex); m_state = StateStopped; } void Stream::pause() { - AutoLock lock(m_mutex); m_state = StatePaused; } void Stream::resume() { - AutoLock lock(m_mutex); m_state = StatePlaying; } void Stream::setVolume(float vol) { - AutoLock lock(m_mutex); - m_volume = vol; } bool Stream::isPlaying() { - AutoLock lock(m_mutex); - return m_state == StatePlaying; } Modified: tiki/nds/src/init_shutdown.cpp =================================================================== --- tiki/nds/src/init_shutdown.cpp 2007-07-08 01:05:36 UTC (rev 416) +++ tiki/nds/src/init_shutdown.cpp 2007-07-17 23:06:07 UTC (rev 417) @@ -13,9 +13,15 @@ #include "Tiki/plxcompat.h" #include "Tiki/hid.h" +#include <nds.h> +#include <fat.h> + namespace Tiki { bool init(int argc, char **argv) { + REG_POWERCNT = POWER_ALL; + irqInit(); + fatInitDefault(); return Hid::init(); } Modified: tiki/nds/src/plathid.cpp =================================================================== --- tiki/nds/src/plathid.cpp 2007-07-08 01:05:36 UTC (rev 416) +++ tiki/nds/src/plathid.cpp 2007-07-17 23:06:07 UTC (rev 417) @@ -4,7 +4,71 @@ namespace Tiki { namespace Hid { +#define CONTROLLER_BUTTON_MAP(OLDSTATE, NEWSTATE, BUTTON, EVENT) \ + if((NEWSTATE & BUTTON) && !(OLDSTATE & BUTTON)) { \ + Event evt(Event::EvtBtnPress); \ + evt.btn = EVENT; \ + evt.port = 1; \ + sendEvent(evt); \ + } \ + if(!(NEWSTATE & BUTTON) && (OLDSTATE & BUTTON)) { \ + Event evt(Event::EvtBtnRelease); \ + evt.btn = EVENT; \ + evt.port = 1; \ + sendEvent(evt); \ + } + +#define CONTROLLER_KEY_MAP(OLDSTATE, NEWSTATE, BUTTON, EVENT) \ + if((NEWSTATE & BUTTON) && !(OLDSTATE & BUTTON)) { \ + Event evtPress(Event::EvtKeypress); \ + evtPress.key = EVENT; \ + evtPress.port = 1; \ + sendEvent(evtPress); \ + \ + Event evt(Event::EvtKeyDown); \ + evt.key = EVENT; \ + evt.port = 1; \ + sendEvent(evt); \ + } \ + if(!(NEWSTATE & BUTTON) && (OLDSTATE & BUTTON)) { \ + Event evt(Event::EvtKeyUp); \ + evt.key = EVENT; \ + evt.port = 1; \ + sendEvent(evt); \ + } + +void TikiVBlank(void) +{ + static u32 oldkeys = 0; + scanKeys(); + u32 keys = keysHeld(); + + //Controller events + CONTROLLER_BUTTON_MAP(oldkeys, keys, KEY_UP, Event::BtnUp); + CONTROLLER_BUTTON_MAP(oldkeys, keys, KEY_DOWN, Event::BtnDown); + CONTROLLER_BUTTON_MAP(oldkeys, keys, KEY_LEFT, Event::BtnLeft); + CONTROLLER_BUTTON_MAP(oldkeys, keys, KEY_RIGHT, Event::BtnRight); + CONTROLLER_BUTTON_MAP(oldkeys, keys, KEY_A, Event::BtnA); + CONTROLLER_BUTTON_MAP(oldkeys, keys, KEY_B, Event::BtnB); + CONTROLLER_BUTTON_MAP(oldkeys, keys, KEY_X, Event::BtnX); + CONTROLLER_BUTTON_MAP(oldkeys, keys, KEY_Y, Event::BtnY); + CONTROLLER_BUTTON_MAP(oldkeys, keys, KEY_START, Event::BtnStart); + + //Keyboard emulation + CONTROLLER_KEY_MAP(oldkeys, keys, KEY_UP, Event::KeyUp); + CONTROLLER_KEY_MAP(oldkeys, keys, KEY_DOWN, Event::KeyDown); + CONTROLLER_KEY_MAP(oldkeys, keys, KEY_LEFT, Event::KeyLeft); + CONTROLLER_KEY_MAP(oldkeys, keys, KEY_RIGHT, Event::KeyRight); + CONTROLLER_KEY_MAP(oldkeys, keys, KEY_START, 13); + CONTROLLER_KEY_MAP(oldkeys, keys, KEY_A, 32); + CONTROLLER_KEY_MAP(oldkeys, keys, KEY_B, Event::KeyEsc); + + oldkeys = keys; +} + bool platInit() { + irqSet(IRQ_VBLANK,&TikiVBlank); + irqEnable(IRQ_VBLANK); return true; } Modified: tiki/nds/src/tikitime.cpp =================================================================== --- tiki/nds/src/tikitime.cpp 2007-07-08 01:05:36 UTC (rev 416) +++ tiki/nds/src/tikitime.cpp 2007-07-17 23:06:07 UTC (rev 417) @@ -11,6 +11,7 @@ #include <sys/time.h> #include <unistd.h> +#include <nds.h> namespace Tiki { namespace Time { @@ -25,17 +26,12 @@ } void sleep(uint64 us) { -// TODO: add this -} + float seconds = (float)us / 1000000.0f; + int blanks = (int)(seconds * 60.0f); + for(int i=0; i < blanks; i++) { + swiWaitForVBlank(); + } } } - - - - - - - - - +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <c99...@us...> - 2007-07-21 17:52:07
|
Revision: 425 http://svn.sourceforge.net/cadcdev/?rev=425&view=rev Author: c99koder Date: 2007-07-21 10:52:01 -0700 (Sat, 21 Jul 2007) Log Message: ----------- NDS: arm7/arm9 streaming code (mono only) Modified Paths: -------------- tiki/nds/Makefile.rules tiki/nds/src/audio/stream.cpp tiki/nds/src/init_shutdown.cpp tiki/nds/src/platgl.cpp Added Paths: ----------- tiki/nds/arm7_template/ tiki/nds/arm7_template/Makefile tiki/nds/arm7_template/source/ tiki/nds/arm7_template/source/arm7main.c tiki/nds/arm7_template/source/dssoundstream.h tiki/nds/arm7_template/source/sound7.c Modified: tiki/nds/Makefile.rules =================================================================== --- tiki/nds/Makefile.rules 2007-07-18 23:45:51 UTC (rev 424) +++ tiki/nds/Makefile.rules 2007-07-21 17:52:01 UTC (rev 425) @@ -27,7 +27,7 @@ CXXFLAGS+=-DARM9 CXXFLAGS+=-march=armv5te -mtune=arm946e-s -fomit-frame-pointer -ffast-math -mthumb -mthumb-interwork CFLAGS=$(CXXFLAGS) -CXXFLAGS+=-fno-rtti -fno-exceptions +CXXFLAGS+=-fno-rtti LDFLAGS=-specs=ds_arm9.specs -mthumb -mthumb-interwork -mno-fpu -L$(DEVKITPRO)/lib -lgcc Added: tiki/nds/arm7_template/Makefile =================================================================== --- tiki/nds/arm7_template/Makefile (rev 0) +++ tiki/nds/arm7_template/Makefile 2007-07-21 17:52:01 UTC (rev 425) @@ -0,0 +1,138 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +ifeq ($(strip $(DEVKITARM)),) +$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM) +endif + +include $(DEVKITARM)/ds_rules + +#--------------------------------------------------------------------------------- +# 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 files +# all directories are relative to this makefile +#--------------------------------------------------------------------------------- +BUILD := build +SOURCES := source +INCLUDES := include build +DATA := +TARGET := tikiarm7 + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -mthumb-interwork + +CFLAGS := -g -Wall -O2\ + -mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer\ + -ffast-math \ + $(ARCH) + +CFLAGS += $(INCLUDE) -DARM7 +CXXFLAGS := $(CFLAGS) + + +ASFLAGS := -g $(ARCH) +LDFLAGS = -specs=ds_arm7.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*).map + +LIBS := -lnds7 + +#--------------------------------------------------------------------------------- +# 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 ARM7BIN := $(TOPDIR)/$(TARGET).arm7 +export ARM7ELF := $(CURDIR)/$(TARGET).arm7.elf +export DEPSDIR := $(CURDIR)/$(BUILD) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) + +export CC := $(PREFIX)gcc +export CXX := $(PREFIX)g++ +export AR := $(PREFIX)ar +export OBJCOPY := $(PREFIX)objcopy + +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)/*.*))) + +export OFILES := $(addsuffix .o,$(BINFILES)) \ + $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#--------------------------------------------------------------------------------- + export LD := $(CC) +#--------------------------------------------------------------------------------- +else +#--------------------------------------------------------------------------------- + export LD := $(CXX) +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- + +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) *.elf + + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(ARM7BIN) : $(ARM7ELF) + @$(OBJCOPY) -O binary $< $@ + @echo built ... $(notdir $@) + + +$(ARM7ELF) : $(OFILES) + @echo linking $(notdir $@) + @$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@ + + +#--------------------------------------------------------------------------------- +# you need a rule like this for each extension you use as binary data +#--------------------------------------------------------------------------------- +%.bin.o : %.bin +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- Property changes on: tiki/nds/arm7_template/Makefile ___________________________________________________________________ Name: svn:eol-style + native Added: tiki/nds/arm7_template/source/arm7main.c =================================================================== --- tiki/nds/arm7_template/source/arm7main.c (rev 0) +++ tiki/nds/arm7_template/source/arm7main.c 2007-07-21 17:52:01 UTC (rev 425) @@ -0,0 +1,180 @@ +/* + Tiki + + arm7main.c + + Based on the libnds arm7 template and the ARM9/ARM7 streaming code from + http://forum.gbadev.org/viewtopic.php?t=10739 +*/ + +#include <nds.h> +#include <stdlib.h> +#include "dssoundstream.h" + +//--------------------------------------------------------------------------------- +void startSound(int sampleRate, const void* data, u32 bytes, u8 channel, u8 vol, u8 pan, u8 format) { +//--------------------------------------------------------------------------------- + SCHANNEL_TIMER(channel) = SOUND_FREQ(sampleRate); + SCHANNEL_SOURCE(channel) = (u32)data; + SCHANNEL_LENGTH(channel) = bytes >> 2 ; + SCHANNEL_CR(channel) = SCHANNEL_ENABLE | SOUND_ONE_SHOT | SOUND_VOL(vol) | SOUND_PAN(pan) | (format==1?SOUND_8BIT:SOUND_16BIT); +} + + +//--------------------------------------------------------------------------------- +s32 getFreeSoundChannel() { +//--------------------------------------------------------------------------------- + int i; + for (i=0; i<16; i++) { + if ( (SCHANNEL_CR(i) & SCHANNEL_ENABLE) == 0 ) return i; + } + return -1; +} + +int vcount; +touchPosition first,tempPos; + +//--------------------------------------------------------------------------------- +void VcountHandler() { +//--------------------------------------------------------------------------------- + static int lastbut = -1; + + uint16 but=0, x=0, y=0, xpx=0, ypx=0, z1=0, z2=0; + + but = REG_KEYXY; + + // Check if the lid has been closed. + if(but & BIT(7)) { + // Save the current interrupt sate. + u32 ie_save = REG_IE; + // Turn the speaker down. + swiChangeSoundBias(0,0x400); + // Save current power state. + int power = readPowerManagement(PM_CONTROL_REG); + // Set sleep LED. + writePowerManagement(PM_CONTROL_REG, PM_LED_CONTROL(1)); + // Register for the lid interrupt. + REG_IE = IRQ_LID; + + // Power down till we get our interrupt. + swiSleep(); //waits for PM (lid open) interrupt + + REG_IF = ~0; + // Restore the interrupt state. + REG_IE = ie_save; + // Restore power state. + writePowerManagement(PM_CONTROL_REG, power); + + // Turn the speaker up. + swiChangeSoundBias(1,0x400); + } + + if (!( (but ^ lastbut) & (1<<6))) { + + tempPos = touchReadXY(); + + if ( tempPos.x == 0 || tempPos.y == 0 ) { + but |= (1 <<6); + lastbut = but; + } else { + x = tempPos.x; + y = tempPos.y; + xpx = tempPos.px; + ypx = tempPos.py; + z1 = tempPos.z1; + z2 = tempPos.z2; + } + + } else { + lastbut = but; + but |= (1 <<6); + } + + if ( vcount == 80 ) { + first = tempPos; + } else { + if ( abs( xpx - first.px) > 10 || abs( ypx - first.py) > 10 || + (but & ( 1<<6)) ) { + + but |= (1 <<6); + lastbut = but; + + } else { + IPC->mailBusy = 1; + IPC->touchX = x; + IPC->touchY = y; + IPC->touchXpx = xpx; + IPC->touchYpx = ypx; + IPC->touchZ1 = z1; + IPC->touchZ2 = z2; + IPC->mailBusy = 0; + } + } + IPC->buttons = but; + vcount ^= (80 ^ 130); + SetYtrigger(vcount); + +} + +//--------------------------------------------------------------------------------- +void VblankHandler(void) { +//--------------------------------------------------------------------------------- + + u32 i; + + SoundVBlankIrq(); + + //sound code :) + TransferSound *snd = IPC->soundData; + IPC->soundData = 0; + + if (0 != snd) { + + for (i=0; i<snd->count; i++) { + s32 chan = getFreeSoundChannel(); + + if (chan >= 0) { + startSound(snd->data[i].rate, snd->data[i].data, snd->data[i].len, chan, snd->data[i].vol, snd->data[i].pan, snd->data[i].format); + } + } + } + +} +void FiFoHandler(void) +//--------------------------------------------------------------------------------- +{ + while ( !(REG_IPC_FIFO_CR & (IPC_FIFO_RECV_EMPTY)) ) + { + SoundFifoHandler(); + } +} +//--------------------------------------------------------------------------------- +int main(int argc, char ** argv) { +//--------------------------------------------------------------------------------- + + // Reset the clock if needed + rtcReset(); + + //enable sound + powerON(POWER_SOUND); + SOUND_CR = SOUND_ENABLE | SOUND_VOL(0x7F); + IPC->soundData = 0; + + irqInit(); + irqSet(IRQ_VBLANK, VblankHandler); + SetYtrigger(80); + vcount = 80; + irqSet(IRQ_VCOUNT, VcountHandler); + REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR | IPC_FIFO_RECV_IRQ; + irqSet(IRQ_FIFO_NOT_EMPTY, FiFoHandler); + irqEnable(IRQ_VBLANK | IRQ_VCOUNT|IRQ_FIFO_NOT_EMPTY); + + SoundSetTimer(0); + + // Keep the ARM7 idle + while (1){ + swiWaitForVBlank(); + } +} + + Property changes on: tiki/nds/arm7_template/source/arm7main.c ___________________________________________________________________ Name: svn:eol-style + native Added: tiki/nds/arm7_template/source/dssoundstream.h =================================================================== --- tiki/nds/arm7_template/source/dssoundstream.h (rev 0) +++ tiki/nds/arm7_template/source/dssoundstream.h 2007-07-21 17:52:01 UTC (rev 425) @@ -0,0 +1,66 @@ +/* + Tiki + + dssoundstream.h + + based on the ARM9/ARM7 streaming code from + http://forum.gbadev.org/viewtopic.php?t=10739 +*/ + +#ifndef __NDSSOUND_H +#define __NDSSOUND_H + +#include <nds.h> + +#define CLOCK (1 << 25) + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum +{ + NONE = 0, + INIT = 1, + MIX = 2, + MIXING = 4, + STOP = 8 +}CommandType; + +typedef enum +{ + FIFO_NONE = 0, + UPDATEON_ARM9 = 1, + MIXCOMPLETE_ONARM9 = 2 +}FifoType; + +typedef struct +{ + s8 *mixbuffer; + u32 rate; + u32 buffersize; + u32 cmd; + u8 channel,format; + u32 soundcursor,numsamples; + s32 prevtimer; + s16 period; +}S_SoundSystem; + +#define soundsystem ((S_SoundSystem*)((u32)(IPC)+sizeof(TransferRegion))) + +#ifdef ARM9 +extern void SoundSystemInit(u32 rate,u32 buffersize,u8 channel,u8 format); +extern void SoundStartMixer(void); +extern void SendCommandToArm7(u32 command); +#else +extern void SoundVBlankIrq(void); +extern void SoundSwapAndMix(void); +extern void SoundSetTimer(int period); +extern void SoundFifoHandler(void); +extern void SendCommandToArm9(u32 command); +#endif + +#ifdef __cplusplus +} +#endif +#endif Property changes on: tiki/nds/arm7_template/source/dssoundstream.h ___________________________________________________________________ Name: svn:eol-style + native Added: tiki/nds/arm7_template/source/sound7.c =================================================================== --- tiki/nds/arm7_template/source/sound7.c (rev 0) +++ tiki/nds/arm7_template/source/sound7.c 2007-07-21 17:52:01 UTC (rev 425) @@ -0,0 +1,123 @@ +/* + Tiki + + sound7.c + + Based on the ARM9/ARM7 streaming code from + http://forum.gbadev.org/viewtopic.php?t=10739 +*/ + +#include <nds.h> +#include <arm7/serial.h> +#include "dssoundstream.h" + +void SoundVBlankIrq(void) +{ + //REG_IME = 0; + int channel,i; + + if(soundsystem->cmd & INIT) + { + SoundSetTimer(soundsystem->period); + soundsystem->cmd &= ~INIT; + } + else if(soundsystem->cmd & MIXING) + { + SoundSwapAndMix(); + } + if(soundsystem->cmd & MIX) + { + channel = soundsystem->channel; + + if(soundsystem->format == 8) + { + SCHANNEL_CR(0) = 0; + SCHANNEL_TIMER(0) = 0x10000 - soundsystem->period; + SCHANNEL_SOURCE(0) = (u32)soundsystem->mixbuffer; + SCHANNEL_REPEAT_POINT(0) = 0; + SCHANNEL_LENGTH(0) = soundsystem->buffersize >> 2; + SCHANNEL_CR(0) = SCHANNEL_ENABLE | SOUND_REPEAT | SOUND_VOL(127) | SOUND_PAN(64) | SOUND_8BIT; + } + if(soundsystem->format == 16) + { + SCHANNEL_CR(0) = 0; + SCHANNEL_TIMER(0) = 0x10000 - soundsystem->period; + SCHANNEL_SOURCE(0) = (u32)soundsystem->mixbuffer; + SCHANNEL_REPEAT_POINT(0) = 0; + SCHANNEL_LENGTH(0) = soundsystem->buffersize >> 2; + SCHANNEL_CR(0) = SCHANNEL_ENABLE | SOUND_REPEAT | SOUND_VOL(127) | SOUND_PAN(64) | SOUND_16BIT; + } + + soundsystem->cmd &= ~MIX; + soundsystem->cmd |= MIXING; + } + //REG_IME = 1; +} +void SoundSetTimer(int period) +{ + if(!period) + { + TIMER0_DATA = 0; + TIMER0_CR = 0; + TIMER1_DATA = 0; + TIMER1_CR = 0; + } + else + { + TIMER0_DATA = 0x10000 - (period * 2); + TIMER0_CR = TIMER_ENABLE | TIMER_DIV_1; + + TIMER1_DATA = 0; + TIMER1_CR = TIMER_ENABLE | TIMER_CASCADE | TIMER_DIV_1; + } +} + +void SoundSwapAndMix(void) +{ + s32 curtimer,numsamples,remaining,tries; + + curtimer = TIMER1_DATA; + + numsamples = curtimer - soundsystem->prevtimer; + + if(numsamples < 0) numsamples += 65536; + + soundsystem->prevtimer = curtimer; + soundsystem->numsamples = numsamples; + + SendCommandToArm9(UPDATEON_ARM9); +} +void SoundFifoHandler(void) +{ + u32 command; + + if (!(REG_IPC_FIFO_CR & IPC_FIFO_RECV_EMPTY)) + { + command = REG_IPC_FIFO_RX; + + switch(command) + { + case FIFO_NONE: + break; + case MIXCOMPLETE_ONARM9: + //REG_IME = 0; + soundsystem->soundcursor += soundsystem->numsamples; + if(soundsystem->format == 8) + while (soundsystem->soundcursor > soundsystem->buffersize) soundsystem->soundcursor -= soundsystem->buffersize; + else + while (soundsystem->soundcursor > (soundsystem->buffersize >> 1)) soundsystem->soundcursor -= (soundsystem->buffersize >> 1); + //REG_IME = 1; + break; + } + } +} +void SendCommandToArm9(u32 command) +{ + while (REG_IPC_FIFO_CR & IPC_FIFO_SEND_FULL); + if (REG_IPC_FIFO_CR & IPC_FIFO_ERROR) + { + REG_IPC_FIFO_CR |= IPC_FIFO_SEND_CLEAR; + } + + REG_IPC_FIFO_TX = command; +} Property changes on: tiki/nds/arm7_template/source/sound7.c ___________________________________________________________________ Name: svn:eol-style + native Modified: tiki/nds/src/audio/stream.cpp =================================================================== --- tiki/nds/src/audio/stream.cpp 2007-07-18 23:45:51 UTC (rev 424) +++ tiki/nds/src/audio/stream.cpp 2007-07-21 17:52:01 UTC (rev 425) @@ -4,13 +4,18 @@ stream.cpp Copyright (C)2005 Cryptic Allusion, LLC + + Portions based on the ARM9/ARM7 streaming code from + http://forum.gbadev.org/viewtopic.php?t=10739 */ #include "pch.h" #include "Tiki/stream.h" - #include <string.h> +#include <nds.h> +#include "soundcommon.h" + using namespace Tiki::Audio; using namespace Tiki::Thread; @@ -20,8 +25,85 @@ TIKI_OBJECT_RECEIVER("stop", Stream::objectStop) TIKI_OBJECT_END(Stream) +std::list<Stream *> streams; +void MixTikiStream(Stream *s, void *stream,u32 len) +{ + int samples = len; + memset(stream,0,len); + if(s->isPlaying()) { + if(s->getData((uint16*)stream,&samples) != Stream::GDSuccess) { + s->stop(); + } + } +} + +void TikiStreamFiFoHandler(void) +{ + u32 command,remain; + std::list<Stream *>::iterator streams_iter; + + while ( !(REG_IPC_FIFO_CR & (IPC_FIFO_RECV_EMPTY)) ) + { + command = REG_IPC_FIFO_RX; + + switch(command) + { + case FIFO_NONE: + break; + case UPDATEON_ARM9: + REG_IME = 0; + for(streams_iter = streams.begin(); streams_iter != streams.end(); streams_iter++) { + if(soundsystem->format == 8) + { + if((soundsystem->soundcursor + soundsystem->numsamples) > soundsystem->buffersize) + { + MixTikiStream((*streams_iter),&soundsystem->mixbuffer[soundsystem->soundcursor],soundsystem->buffersize - soundsystem->soundcursor); + remain = soundsystem->numsamples - (soundsystem->buffersize - soundsystem->soundcursor); + MixTikiStream((*streams_iter),soundsystem->mixbuffer,remain); + } + else + { + MixTikiStream((*streams_iter),&soundsystem->mixbuffer[soundsystem->soundcursor],soundsystem->numsamples); + } + } + else + { + if((soundsystem->soundcursor + soundsystem->numsamples) > (soundsystem->buffersize >> 1)) + { + MixTikiStream((*streams_iter),&soundsystem->mixbuffer[soundsystem->soundcursor << 1],(soundsystem->buffersize >> 1) - soundsystem->soundcursor); + remain = soundsystem->numsamples - ((soundsystem->buffersize >> 1) - soundsystem->soundcursor); + MixTikiStream((*streams_iter),soundsystem->mixbuffer,remain); + } + else + { + MixTikiStream((*streams_iter),&soundsystem->mixbuffer[soundsystem->soundcursor << 1],soundsystem->numsamples); + } + } + } + REG_IME = 1; + SendCommandToArm7(MIXCOMPLETE_ONARM9); + break; + } + } +} + +void SendCommandToArm7(u32 command) +{ + while (REG_IPC_FIFO_CR & IPC_FIFO_SEND_FULL); + if (REG_IPC_FIFO_CR & IPC_FIFO_ERROR) + { + REG_IPC_FIFO_CR |= IPC_FIFO_SEND_CLEAR; + } + + REG_IPC_FIFO_TX = command; +} + bool Stream::initGlobal() { + irqSet(IRQ_FIFO_NOT_EMPTY,&TikiStreamFiFoHandler); + irqEnable(IRQ_FIFO_NOT_EMPTY); + + REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR | IPC_FIFO_RECV_IRQ; return true; } @@ -30,18 +112,31 @@ Stream::Stream() { // Default our members. - m_bufSize = 0x4000; + m_bufSize = 16384; m_chnCount = 2; m_freq = 44100; m_queueing = false; m_state = StateStopped; m_volume = 0.8f; + + streams.push_back(this); } Stream::~Stream() { + streams.remove(this); } bool Stream::create() { + soundsystem->rate = m_freq; + soundsystem->buffersize = m_bufSize * sizeof(short); + soundsystem->mixbuffer = (s8*)malloc(soundsystem->buffersize); + soundsystem->format = 16; + soundsystem->channel = 0; + soundsystem->prevtimer = 0; + soundsystem->soundcursor = 0; + soundsystem->numsamples = 0; + soundsystem->period = 0x1000000 / m_freq; + soundsystem->cmd = INIT | MIX; return true; } @@ -79,11 +174,12 @@ } void Stream::pause() { + stop(); m_state = StatePaused; } void Stream::resume() { - m_state = StatePlaying; + start(); } void Stream::setVolume(float vol) { Modified: tiki/nds/src/init_shutdown.cpp =================================================================== --- tiki/nds/src/init_shutdown.cpp 2007-07-18 23:45:51 UTC (rev 424) +++ tiki/nds/src/init_shutdown.cpp 2007-07-21 17:52:01 UTC (rev 425) @@ -19,9 +19,26 @@ namespace Tiki { bool init(int argc, char **argv) { - REG_POWERCNT = POWER_ALL; + // Turn on everything + powerON(POWER_ALL); + + // Setup the Main screen for 3D + videoSetMode(MODE_0_3D); + vramSetBankA(VRAM_A_TEXTURE); + lcdMainOnBottom(); + + // IRQ basic setup irqInit(); + + // initialize the geometry engine + glInit(); + + // initialize libfat fatInitDefault(); + + // initialize parallax + GL::Plxcompat::plx_mat3d_init(640, 480); + Audio::Stream::initGlobal(); return Hid::init(); } Modified: tiki/nds/src/platgl.cpp =================================================================== --- tiki/nds/src/platgl.cpp 2007-07-18 23:45:51 UTC (rev 424) +++ tiki/nds/src/platgl.cpp 2007-07-21 17:52:01 UTC (rev 425) @@ -36,6 +36,8 @@ } void tiki_scene_finish_hook() { + glFlush(0); + swiWaitForVBlank(); } void tiki_scene_begin_opaque_hook() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <c99...@us...> - 2007-07-28 06:27:23
|
Revision: 427 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=427&view=rev Author: c99koder Date: 2007-07-27 23:27:21 -0700 (Fri, 27 Jul 2007) Log Message: ----------- NDS: Enable optimizations, wifi, and use an interrupt for a higher-resolution Tiki::gettime() Modified Paths: -------------- tiki/nds/Makefile.rules tiki/nds/arm7_template/source/arm7main.c tiki/nds/src/audio/stream.cpp tiki/nds/src/init_shutdown.cpp tiki/nds/src/plathid.cpp tiki/nds/src/tikitime.cpp Modified: tiki/nds/Makefile.rules =================================================================== --- tiki/nds/Makefile.rules 2007-07-22 22:22:43 UTC (rev 426) +++ tiki/nds/Makefile.rules 2007-07-28 06:27:21 UTC (rev 427) @@ -12,7 +12,7 @@ $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitARM) endif -TIKI_BASE_LIBS=-ltiki -L$(DEVKITPRO)/libnds/lib -lfat -lnds9 +TIKI_BASE_LIBS=-ltiki -L$(DEVKITPRO)/libnds/lib -ldswifi9 -lfat -lnds9 CXXFLAGS=-I$(DEVKITPRO)/libnds/include @@ -25,7 +25,7 @@ CXXFLAGS+=-I$(TIKI_DIR)/3rdparty/libvorbis/include CXXFLAGS+=-I$(TIKI_DIR)/3rdparty/libvorbis/lib CXXFLAGS+=-DARM9 -CXXFLAGS+=-march=armv5te -mtune=arm946e-s -fomit-frame-pointer -ffast-math -mthumb -mthumb-interwork +CXXFLAGS+=-march=armv5te -mtune=arm946e-s -fomit-frame-pointer -ffast-math -mthumb -mthumb-interwork -O2 CFLAGS=$(CXXFLAGS) CXXFLAGS+=-fno-rtti Modified: tiki/nds/arm7_template/source/arm7main.c =================================================================== --- tiki/nds/arm7_template/source/arm7main.c 2007-07-22 22:22:43 UTC (rev 426) +++ tiki/nds/arm7_template/source/arm7main.c 2007-07-28 06:27:21 UTC (rev 427) @@ -9,6 +9,7 @@ #include <nds.h> #include <stdlib.h> +#include <dswifi7.h> #include "dssoundstream.h" //--------------------------------------------------------------------------------- @@ -138,20 +139,26 @@ } } } - + Wifi_Update(); } void FiFoHandler(void) //--------------------------------------------------------------------------------- { while ( !(REG_IPC_FIFO_CR & (IPC_FIFO_RECV_EMPTY)) ) { + Wifi_Sync(); SoundFifoHandler(); } } + +void arm7_synctoarm9() { // send fifo message +} + //--------------------------------------------------------------------------------- int main(int argc, char ** argv) { //--------------------------------------------------------------------------------- - + u32 fifo_temp; + // Reset the clock if needed rtcReset(); @@ -159,16 +166,33 @@ powerON(POWER_SOUND); SOUND_CR = SOUND_ENABLE | SOUND_VOL(0x7F); IPC->soundData = 0; + IPC->mailBusy = 0; irqInit(); irqSet(IRQ_VBLANK, VblankHandler); SetYtrigger(80); vcount = 80; irqSet(IRQ_VCOUNT, VcountHandler); - REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR | IPC_FIFO_RECV_IRQ; - irqSet(IRQ_FIFO_NOT_EMPTY, FiFoHandler); - irqEnable(IRQ_VBLANK | IRQ_VCOUNT|IRQ_FIFO_NOT_EMPTY); + REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR; + irqEnable(IRQ_VBLANK | IRQ_VCOUNT); + irqSet(IRQ_WIFI, Wifi_Interrupt); + irqEnable(IRQ_WIFI); + + // trade some mail, to get a pointer from arm9 + while(1) { + while(REG_IPC_FIFO_CR&IPC_FIFO_RECV_EMPTY) swiWaitForVBlank(); + fifo_temp=REG_IPC_FIFO_RX; + if(fifo_temp==0x12345678) break; + } + while(REG_IPC_FIFO_CR&IPC_FIFO_RECV_EMPTY) swiWaitForVBlank(); + fifo_temp=REG_IPC_FIFO_RX; + Wifi_Init(fifo_temp); + irqSet(IRQ_FIFO_NOT_EMPTY,FiFoHandler); + irqEnable(IRQ_FIFO_NOT_EMPTY); + REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_RECV_IRQ; + + Wifi_SetSyncHandler(arm7_synctoarm9); SoundSetTimer(0); // Keep the ARM7 idle Modified: tiki/nds/src/audio/stream.cpp =================================================================== --- tiki/nds/src/audio/stream.cpp 2007-07-22 22:22:43 UTC (rev 426) +++ tiki/nds/src/audio/stream.cpp 2007-07-28 06:27:21 UTC (rev 427) @@ -14,6 +14,7 @@ #include <string.h> #include <nds.h> +#include <dswifi9.h> #include "dssoundstream.h" using namespace Tiki::Audio; @@ -86,6 +87,7 @@ break; } } + Wifi_Sync(); } void SendCommandToArm7(u32 command) Modified: tiki/nds/src/init_shutdown.cpp =================================================================== --- tiki/nds/src/init_shutdown.cpp 2007-07-22 22:22:43 UTC (rev 426) +++ tiki/nds/src/init_shutdown.cpp 2007-07-28 06:27:21 UTC (rev 427) @@ -15,7 +15,13 @@ #include <nds.h> #include <fat.h> +#include <dswifi9.h> +// notification function to send fifo message to arm7 +void arm9_synctoarm7() { // send fifo message + //This is a NO-OP because the sound streaming code will constantly communicate with the ARM7 over the FIFO anyway +} + namespace Tiki { bool init(int argc, char **argv) { @@ -37,9 +43,30 @@ fatInitDefault(); // initialize parallax - GL::Plxcompat::plx_mat3d_init(640, 480); + GL::Plxcompat::plx_mat3d_init(256, 192); Audio::Stream::initGlobal(); - return Hid::init(); + Hid::init(); + + { // send fifo message to initialize the arm7 wifi + REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR; // enable & clear FIFO + + u32 Wifi_pass= Wifi_Init(WIFIINIT_OPTION_USELED); + REG_IPC_FIFO_TX=0x12345678; + REG_IPC_FIFO_TX=Wifi_pass; + + irqEnable(IRQ_FIFO_NOT_EMPTY); + + REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_RECV_IRQ; // enable FIFO IRQ + + Wifi_SetSyncHandler(arm9_synctoarm7); // tell wifi lib to use our handler to notify arm7 + + while(Wifi_CheckInit()==0) { // wait for arm7 to be initted successfully + swiWaitForVBlank(); + } + + } // wifi init complete - wifi lib can now be used! + + return true; } void shutdown() { Modified: tiki/nds/src/plathid.cpp =================================================================== --- tiki/nds/src/plathid.cpp 2007-07-22 22:22:43 UTC (rev 426) +++ tiki/nds/src/plathid.cpp 2007-07-28 06:27:21 UTC (rev 427) @@ -1,7 +1,10 @@ #include "pch.h" #include "Tiki/glhdrs.h" #include "Tiki/hid.h" +#include <dswifi9.h> +volatile uint64 __timecounter = 0; + namespace Tiki { namespace Hid { #define CONTROLLER_BUTTON_MAP(OLDSTATE, NEWSTATE, BUTTON, EVENT) \ @@ -64,11 +67,13 @@ CONTROLLER_KEY_MAP(oldkeys, keys, KEY_B, Event::KeyEsc); oldkeys = keys; + Wifi_Timer(50); + __timecounter += 15000; } bool platInit() { - irqSet(IRQ_VBLANK,&TikiVBlank); - irqEnable(IRQ_VBLANK); + irqSet(IRQ_VCOUNT,&TikiVBlank); + irqEnable(IRQ_VBLANK | IRQ_VCOUNT); return true; } Modified: tiki/nds/src/tikitime.cpp =================================================================== --- tiki/nds/src/tikitime.cpp 2007-07-22 22:22:43 UTC (rev 426) +++ tiki/nds/src/tikitime.cpp 2007-07-28 06:27:21 UTC (rev 427) @@ -13,16 +13,12 @@ #include <unistd.h> #include <nds.h> +extern volatile uint64 __timecounter; + namespace Tiki { namespace Time { uint64 gettime() { - timeval tv; - gettimeofday(&tv, NULL); - - uint64 rv = tv.tv_sec; rv *= 1000000; - rv += tv.tv_usec; - - return rv; + return __timecounter; } void sleep(uint64 us) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <c99...@us...> - 2007-07-29 03:21:18
|
Revision: 429 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=429&view=rev Author: c99koder Date: 2007-07-28 20:21:16 -0700 (Sat, 28 Jul 2007) Log Message: ----------- Tiki: NDS: Keep interrupts enabled during sound mixing, move wifi update into its own timer, include missing header file Modified Paths: -------------- tiki/nds/arm7_template/source/arm7main.c tiki/nds/src/audio/stream.cpp tiki/nds/src/init_shutdown.cpp tiki/nds/src/plathid.cpp Added Paths: ----------- tiki/nds/include/dssoundstream.h Modified: tiki/nds/arm7_template/source/arm7main.c =================================================================== --- tiki/nds/arm7_template/source/arm7main.c 2007-07-28 19:00:43 UTC (rev 428) +++ tiki/nds/arm7_template/source/arm7main.c 2007-07-29 03:21:16 UTC (rev 429) @@ -152,6 +152,7 @@ } void arm7_synctoarm9() { // send fifo message + SendCommandToArm9(0x87654321); } //--------------------------------------------------------------------------------- Added: tiki/nds/include/dssoundstream.h =================================================================== --- tiki/nds/include/dssoundstream.h (rev 0) +++ tiki/nds/include/dssoundstream.h 2007-07-29 03:21:16 UTC (rev 429) @@ -0,0 +1,66 @@ +/* + Tiki + + dssoundstream.h + + based on the ARM9/ARM7 streaming code from + http://forum.gbadev.org/viewtopic.php?t=10739 +*/ + +#ifndef __NDSSOUND_H +#define __NDSSOUND_H + +#include <nds.h> + +#define CLOCK (1 << 25) + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum +{ + NONE = 0, + INIT = 1, + MIX = 2, + MIXING = 4, + STOP = 8 +}CommandType; + +typedef enum +{ + FIFO_NONE = 0, + UPDATEON_ARM9 = 1, + MIXCOMPLETE_ONARM9 = 2 +}FifoType; + +typedef struct +{ + s8 *mixbuffer; + u32 rate; + u32 buffersize; + u32 cmd; + u8 channel,format; + u32 soundcursor,numsamples; + s32 prevtimer; + s16 period; +}S_SoundSystem; + +#define soundsystem ((S_SoundSystem*)((u32)(IPC)+sizeof(TransferRegion))) + +#ifdef ARM9 +extern void SoundSystemInit(u32 rate,u32 buffersize,u8 channel,u8 format); +extern void SoundStartMixer(void); +extern void SendCommandToArm7(u32 command); +#else +extern void SoundVBlankIrq(void); +extern void SoundSwapAndMix(void); +extern void SoundSetTimer(int period); +extern void SoundFifoHandler(void); +extern void SendCommandToArm9(u32 command); +#endif + +#ifdef __cplusplus +} +#endif +#endif Property changes on: tiki/nds/include/dssoundstream.h ___________________________________________________________________ Name: svn:eol-style + native Modified: tiki/nds/src/audio/stream.cpp =================================================================== --- tiki/nds/src/audio/stream.cpp 2007-07-28 19:00:43 UTC (rev 428) +++ tiki/nds/src/audio/stream.cpp 2007-07-29 03:21:16 UTC (rev 429) @@ -52,8 +52,11 @@ { case FIFO_NONE: break; + case 0x87654321: + Wifi_Sync(); + break; case UPDATEON_ARM9: - REG_IME = 0; + //REG_IME = 0; for(streams_iter = streams.begin(); streams_iter != streams.end(); streams_iter++) { if(soundsystem->format == 8) { @@ -82,12 +85,11 @@ } } } - REG_IME = 1; + //REG_IME = 1; SendCommandToArm7(MIXCOMPLETE_ONARM9); break; } } - Wifi_Sync(); } void SendCommandToArm7(u32 command) @@ -114,7 +116,7 @@ Stream::Stream() { // Default our members. - m_bufSize = 16384; + m_bufSize = 4096; m_chnCount = 2; m_freq = 44100; m_queueing = false; Modified: tiki/nds/src/init_shutdown.cpp =================================================================== --- tiki/nds/src/init_shutdown.cpp 2007-07-28 19:00:43 UTC (rev 428) +++ tiki/nds/src/init_shutdown.cpp 2007-07-29 03:21:16 UTC (rev 429) @@ -16,12 +16,16 @@ #include <nds.h> #include <fat.h> #include <dswifi9.h> +#include <dssoundstream.h> // notification function to send fifo message to arm7 void arm9_synctoarm7() { // send fifo message - //This is a NO-OP because the sound streaming code will constantly communicate with the ARM7 over the FIFO anyway + SendCommandToArm7(0x87654321); } - +// wifi timer function, to update internals of sgIP +void Timer_50ms(void) { + Wifi_Timer(50); +} namespace Tiki { bool init(int argc, char **argv) { @@ -46,7 +50,8 @@ GL::Plxcompat::plx_mat3d_init(256, 192); Audio::Stream::initGlobal(); Hid::init(); - + irqSet(IRQ_TIMER3, Timer_50ms); // setup timer IRQ + irqEnable(IRQ_TIMER3); { // send fifo message to initialize the arm7 wifi REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR; // enable & clear FIFO @@ -59,6 +64,10 @@ REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_RECV_IRQ; // enable FIFO IRQ Wifi_SetSyncHandler(arm9_synctoarm7); // tell wifi lib to use our handler to notify arm7 + + // set timer3 + *((volatile u16 *)0x0400010C) = -6553; // 6553.1 * 256 cycles = ~50ms; + *((volatile u16 *)0x0400010E) = 0x00C2; // enable, irq, 1/256 clock while(Wifi_CheckInit()==0) { // wait for arm7 to be initted successfully swiWaitForVBlank(); Modified: tiki/nds/src/plathid.cpp =================================================================== --- tiki/nds/src/plathid.cpp 2007-07-28 19:00:43 UTC (rev 428) +++ tiki/nds/src/plathid.cpp 2007-07-29 03:21:16 UTC (rev 429) @@ -117,12 +117,11 @@ } oldkeys = keys; - Wifi_Timer(50); __timecounter += 15000; } bool platInit() { - irqSet(IRQ_VCOUNT,&TikiVBlank); + irqSet(IRQ_VBLANK,&TikiVBlank); irqEnable(IRQ_VBLANK | IRQ_VCOUNT); NDSjs = new JsDevice; NDSmouse = new MouseDevice; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |