Skip to content

Commit

Permalink
add all that old prettychips code
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Sep 6, 2013
0 parents commit eabca04
Show file tree
Hide file tree
Showing 48 changed files with 10,651 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
##---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif

include $(DEVKITARM)/ds_rules

export TARGET := $(shell basename $(CURDIR))
export TOPDIR := $(CURDIR)
export GAME_TITLE := prettychips
export GAME_ICON := $(DEVKITPRO)/prettychips.bmp
export GAME_SUBTITLE1 := holy rookies
export GAME_SUBTITLE2 := chee
ICON := -b $(DEVKITPRO)/prettychips.bmp

.PHONY: $(TARGET).arm7 $(TARGET).arm9

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
all: $(TARGET).nds

#---------------------------------------------------------------------------------
$(TARGET).nds : $(TARGET).arm7 $(TARGET).arm9
ndstool -c $(TARGET).nds -7 $(TARGET).arm7 -9 $(TARGET).arm9

#---------------------------------------------------------------------------------
$(TARGET).arm7 : arm7/$(TARGET).elf
$(TARGET).arm9 : arm9/$(TARGET).elf

#---------------------------------------------------------------------------------
arm7/$(TARGET).elf:
$(MAKE) -C arm7

#---------------------------------------------------------------------------------
arm9/$(TARGET).elf:
$(MAKE) -C arm9

#---------------------------------------------------------------------------------
clean:
$(MAKE) -C arm9 clean
$(MAKE) -C arm7 clean
rm -f $(TARGET).nds $(TARGET).arm7 $(TARGET).arm9
134 changes: 134 additions & 0 deletions arm7/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#---------------------------------------------------------------------------------
.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 :=


#---------------------------------------------------------------------------------
# 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) -fno-rtti -fno-exceptions -fno-rtti


ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm7.specs -g $(ARCH) -Wl,-Map,$(notdir $*).map

LIBS := -ldswifi7 -lmm7 -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))

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
#---------------------------------------------------------------------------------------
212 changes: 212 additions & 0 deletions arm7/source/audio.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
/*---------------------------------------------------------------------------------
Copyright (C) 2008
Dave Murphy (WinterMute)
Jason Rogers (Dovoto)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
---------------------------------------------------------------------------------*/


#include <nds/ipc.h>
#include <nds/fifocommon.h>
#include <nds/fifomessages.h>
#include <nds/system.h>
#include <nds/arm7/audio.h>

//---------------------------------------------------------------------------------
int getFreeChannel(void) {
//---------------------------------------------------------------------------------
int i;

for(i = 0; i < 16; i++)
if(!(SCHANNEL_CR(i) & SCHANNEL_ENABLE))
return i;

return -1;
}

//---------------------------------------------------------------------------------
int getFreePSGChannel(void) {
//---------------------------------------------------------------------------------
int i;

for(i = 8; i < 14; i++)
if(!(SCHANNEL_CR(i) & SCHANNEL_ENABLE))
return i;

return -1;
}

//---------------------------------------------------------------------------------
int getFreeNoiseChannel(void) {
//---------------------------------------------------------------------------------
int i;

for(i = 14; i < 16; i++)
if(!(SCHANNEL_CR(i) & SCHANNEL_ENABLE))
return i;

return -1;
}


//---------------------------------------------------------------------------------
void micSwapHandler(u8* buffer, int length) {
//---------------------------------------------------------------------------------

FifoMessage msg;
msg.type = MIC_BUFFER_FULL_MESSAGE;
msg.MicBufferFull.buffer = (void*)buffer;
msg.MicBufferFull.length = (u32)length;

fifoSendDatamsg(FIFO_SOUND, sizeof(msg) , (u8*)&msg);
}

//---------------------------------------------------------------------------------
void soundDataHandler(int bytes, void *user_data) {
//---------------------------------------------------------------------------------
int channel = -1;

FifoMessage msg;

fifoGetDatamsg(FIFO_SOUND, bytes, (u8*)&msg);

if(msg.type == SOUND_PLAY_MESSAGE) {

channel = getFreeChannel();

if(channel >= 0) {
SCHANNEL_SOURCE(channel) = (u32)msg.SoundPlay.data;
SCHANNEL_REPEAT_POINT(channel) = msg.SoundPlay.loopPoint;
SCHANNEL_LENGTH(channel) = msg.SoundPlay.dataSize;
SCHANNEL_TIMER(channel) = SOUND_FREQ(msg.SoundPlay.freq);
SCHANNEL_CR(channel) = SCHANNEL_ENABLE | SOUND_VOL(msg.SoundPlay.volume) | SOUND_PAN(msg.SoundPlay.pan) | (msg.SoundPlay.format << 29) | (msg.SoundPlay.loop ? SOUND_REPEAT : SOUND_ONE_SHOT);
}

} else if(msg.type == SOUND_PSG_MESSAGE) {

channel = getFreePSGChannel();

if(channel >= 0)
{
SCHANNEL_CR(channel) = SCHANNEL_ENABLE | msg.SoundPsg.volume | SOUND_PAN(msg.SoundPsg.pan) | (3 << 29) | (msg.SoundPsg.dutyCycle << 24);
SCHANNEL_TIMER(channel) = SOUND_FREQ(msg.SoundPsg.freq);
}
} else if(msg.type == SOUND_NOISE_MESSAGE) {

channel = getFreeNoiseChannel();

if(channel >= 0) {
SCHANNEL_CR(channel) = SCHANNEL_ENABLE | msg.SoundPsg.volume | SOUND_PAN(msg.SoundPsg.pan) | (3 << 29);
SCHANNEL_TIMER(channel) = SOUND_FREQ(msg.SoundPsg.freq);
}
} else if(msg.type == MIC_RECORD_MESSAGE) {

micStartRecording(msg.MicRecord.buffer, msg.MicRecord.bufferLength, msg.MicRecord.freq, 1, msg.MicRecord.format, micSwapHandler);

channel = 17;
}

fifoSendValue32(FIFO_SOUND, (u32)channel);
}

//---------------------------------------------------------------------------------
void enableSound() {
//---------------------------------------------------------------------------------
powerOn(POWER_SOUND);
writePowerManagement(PM_CONTROL_REG, ( readPowerManagement(PM_CONTROL_REG) & ~PM_SOUND_MUTE ) | PM_SOUND_AMP );
REG_SOUNDCNT = SOUND_ENABLE;
REG_MASTER_VOLUME = 127;
}

//---------------------------------------------------------------------------------
void disableSound() {
//---------------------------------------------------------------------------------
REG_SOUNDCNT &= ~SOUND_ENABLE;
writePowerManagement(PM_CONTROL_REG, ( readPowerManagement(PM_CONTROL_REG) & ~PM_SOUND_AMP ) | PM_SOUND_MUTE );
powerOff(POWER_SOUND);
}

//---------------------------------------------------------------------------------
void soundCommandHandler(u32 command, void* userdata) {
//---------------------------------------------------------------------------------

int cmd = (command ) & 0x00F00000;
int data = command & 0xFFFF;
int channel = (command >> 16) & 0xF;

switch(cmd) {

case SOUND_MASTER_ENABLE:
enableSound();
break;

case SOUND_MASTER_DISABLE:
disableSound();
break;

case SOUND_SET_VOLUME:
SCHANNEL_CR(channel) &= ~0xFF;
SCHANNEL_CR(channel) |= data;
break;

case SOUND_SET_PAN:
SCHANNEL_CR(channel) &= ~SOUND_PAN(0xFF);
SCHANNEL_CR(channel) |= SOUND_PAN(data);
break;

case SOUND_SET_FREQ:
SCHANNEL_TIMER(channel) = SOUND_FREQ(data);
break;

case SOUND_SET_WAVEDUTY:
SCHANNEL_CR(channel) &= ~(7 << 24);
SCHANNEL_CR(channel) |= (data) << 24;
break;

case SOUND_KILL:
SCHANNEL_CR(channel) &= ~SCHANNEL_ENABLE;
break;

case SOUND_PAUSE:
SCHANNEL_CR(channel) &= ~SCHANNEL_ENABLE;
break;

case SOUND_RESUME:
SCHANNEL_CR(channel) |= SCHANNEL_ENABLE;
break;

case MIC_STOP:
micStopRecording();
break;



default: break;
}
}

//---------------------------------------------------------------------------------
void installSoundFIFO(void) {
//---------------------------------------------------------------------------------

fifoSetDatamsgHandler(FIFO_SOUND, soundDataHandler, 0);
fifoSetValue32Handler(FIFO_SOUND, soundCommandHandler, 0);
}
Loading

0 comments on commit eabca04

Please sign in to comment.