summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2008-08-19 15:47:14 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2008-08-19 15:47:14 +0000
commit49a4016507e6239ca313bafff5dcaf37cd6647fd (patch)
tree076c0ba4437083f66b3093465071a53af8e513d2
parent2008-08-19 Joel Sherrill <joel.sherrill@OARcorp.com> (diff)
downloadrtems-49a4016507e6239ca313bafff5dcaf37cd6647fd.tar.bz2
2008-08-19 Joel Sherrill <joel.sherrill@OARcorp.com>
* dswifi/arm7/makefile, dswifi/include/netinet/in.h, libnds/basicARM7/source/defaultARM7.c, libnds/include/gbfs.h, libnds/include/nds/bios.h, libnds/include/nds/card.h, libnds/include/nds/dma.h, libnds/include/nds/interrupts.h, libnds/include/nds/ipc.h, libnds/include/nds/jtypes.h, libnds/include/nds/registers_alt.h, libnds/include/nds/system.h, libnds/include/nds/timers.h, libnds/include/nds/arm7/audio.h, libnds/include/nds/arm7/clock.h, libnds/include/nds/arm7/serial.h, libnds/include/nds/arm7/touch.h, libnds/include/nds/arm9/boxtest.h, libnds/include/nds/arm9/cache.h, libnds/include/nds/arm9/console.h, libnds/include/nds/arm9/ndsmotion.h, libnds/include/nds/arm9/video.h, libnds/include/nds/arm9/videoGL.h, libnds/source/arm7/audio.c, libnds/source/arm7/clock.c, libnds/source/arm7/microphone.c, libnds/source/arm7/touch.c, libnds/source/arm7/userSettings.c, libnds/source/arm9/boxtest.c, libnds/source/arm9/gurumeditation.c, libnds/source/arm9/ndsmotion.c, libnds/source/arm9/videoGL.c, libnds/source/common/card.c, libnds/source/common/interruptDispatcher.S, touchscreen/reco.c: Fix various warnings by fixing prototypes. Remove unused .bin files. Convert all files to UNIX CF/LF. * libnds/source/arm9/COS.bin, libnds/source/arm9/SIN.bin, libnds/source/arm9/TAN.bin, libnds/source/arm9/default_font.bin: Removed.
-rw-r--r--c/src/lib/libbsp/arm/nds/ChangeLog25
-rw-r--r--c/src/lib/libbsp/arm/nds/dswifi/arm7/makefile290
-rw-r--r--c/src/lib/libbsp/arm/nds/dswifi/include/netinet/in.h2
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/basicARM7/source/defaultARM7.c134
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/gbfs.h200
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/audio.h282
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/clock.h280
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/serial.h334
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/touch.h146
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/boxtest.h220
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/cache.h176
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/console.h174
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/ndsmotion.h384
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/video.h1186
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/videoGL.h2594
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/bios.h734
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/card.h254
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/dma.h306
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/interrupts.h374
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/ipc.h314
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/jtypes.h280
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/registers_alt.h626
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/system.h500
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/include/nds/timers.h412
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/source/arm7/audio.c54
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/source/arm7/clock.c556
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/source/arm7/microphone.c230
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/source/arm7/touch.c746
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/source/arm7/userSettings.c142
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/source/arm9/COS.binbin1024 -> 0 bytes
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/source/arm9/SIN.binbin1024 -> 0 bytes
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/source/arm9/TAN.binbin1024 -> 0 bytes
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/source/arm9/boxtest.c176
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/source/arm9/default_font.binbin8192 -> 0 bytes
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/source/arm9/gurumeditation.c540
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/source/arm9/ndsmotion.c976
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/source/arm9/videoGL.c852
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/source/common/card.c788
-rw-r--r--c/src/lib/libbsp/arm/nds/libnds/source/common/interruptDispatcher.S322
-rw-r--r--c/src/lib/libbsp/arm/nds/touchscreen/reco.c478
40 files changed, 8065 insertions, 8022 deletions
diff --git a/c/src/lib/libbsp/arm/nds/ChangeLog b/c/src/lib/libbsp/arm/nds/ChangeLog
index ccecbd9270..aaa5560642 100644
--- a/c/src/lib/libbsp/arm/nds/ChangeLog
+++ b/c/src/lib/libbsp/arm/nds/ChangeLog
@@ -1,3 +1,28 @@
+2008-08-19 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * dswifi/arm7/makefile, dswifi/include/netinet/in.h,
+ libnds/basicARM7/source/defaultARM7.c, libnds/include/gbfs.h,
+ libnds/include/nds/bios.h, libnds/include/nds/card.h,
+ libnds/include/nds/dma.h, libnds/include/nds/interrupts.h,
+ libnds/include/nds/ipc.h, libnds/include/nds/jtypes.h,
+ libnds/include/nds/registers_alt.h, libnds/include/nds/system.h,
+ libnds/include/nds/timers.h, libnds/include/nds/arm7/audio.h,
+ libnds/include/nds/arm7/clock.h, libnds/include/nds/arm7/serial.h,
+ libnds/include/nds/arm7/touch.h, libnds/include/nds/arm9/boxtest.h,
+ libnds/include/nds/arm9/cache.h, libnds/include/nds/arm9/console.h,
+ libnds/include/nds/arm9/ndsmotion.h, libnds/include/nds/arm9/video.h,
+ libnds/include/nds/arm9/videoGL.h, libnds/source/arm7/audio.c,
+ libnds/source/arm7/clock.c, libnds/source/arm7/microphone.c,
+ libnds/source/arm7/touch.c, libnds/source/arm7/userSettings.c,
+ libnds/source/arm9/boxtest.c, libnds/source/arm9/gurumeditation.c,
+ libnds/source/arm9/ndsmotion.c, libnds/source/arm9/videoGL.c,
+ libnds/source/common/card.c,
+ libnds/source/common/interruptDispatcher.S, touchscreen/reco.c: Fix
+ various warnings by fixing prototypes. Remove unused .bin files.
+ Convert all files to UNIX CF/LF.
+ * libnds/source/arm9/COS.bin, libnds/source/arm9/SIN.bin,
+ libnds/source/arm9/TAN.bin, libnds/source/arm9/default_font.bin: Removed.
+
2008-07-29 Chris Johns <chrisj@rtems.org>
* block/block.c: Update to the libblock changes.
diff --git a/c/src/lib/libbsp/arm/nds/dswifi/arm7/makefile b/c/src/lib/libbsp/arm/nds/dswifi/arm7/makefile
index 4124871f6c..5546107587 100644
--- a/c/src/lib/libbsp/arm/nds/dswifi/arm7/makefile
+++ b/c/src/lib/libbsp/arm/nds/dswifi/arm7/makefile
@@ -1,145 +1,145 @@
-#---------------------------------------------------------------------------------
-.SUFFIXES:
-#---------------------------------------------------------------------------------
-ifeq ($(strip $(DEVKITARM)),)
-$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM)
-endif
-
-include $(DEVKITARM)/ds_rules
-
-TOPDIR ?= $(CURDIR)/..
-
-#---------------------------------------------------------------------------------
-# 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 ?= release
-SOURCES := source ../common/source
-INCLUDES := include build ../common/source ../include
-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)
-
-
-ASFLAGS := -g $(ARCH)
-LDFLAGS = -specs=ds_arm7.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*).map
-
-
-ifneq ($(BUILD),debug)
-export ARM7BIN := $(TOPDIR)/lib/libdswifi7.a
-else
-export ARM7BIN := $(TOPDIR)/lib/libdswifi7d.a
-CFLAGS += -DSGIP_DEBUG
-endif
-
-
-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 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 debug release
- @rm -f $(TOPDIR)/lib/libdswifi7*
-
-all: $(ARM7BIN)
-
-#---------------------------------------------------------------------------------
-else
-
-DEPENDS := $(OFILES:.o=.d)
-
-#---------------------------------------------------------------------------------
-# main targets
-#---------------------------------------------------------------------------------
-$(ARM7BIN) : $(OFILES)
- @rm -f "$(ARM7BIN)"
- @$(AR) rcs "$(ARM7BIN)" $(OFILES)
- @echo built ... $(notdir $@)
-
-
-#---------------------------------------------------------------------------------
-# you need a rule like this for each extension you use as binary data
-#---------------------------------------------------------------------------------
-%.bin.o : %.bin
-#---------------------------------------------------------------------------------
- @echo $(notdir $<)
- @$(bin2o)
-
--include $(DEPENDS)
-
-#---------------------------------------------------------------------------------------
-endif
-#---------------------------------------------------------------------------------------
+#---------------------------------------------------------------------------------
+.SUFFIXES:
+#---------------------------------------------------------------------------------
+ifeq ($(strip $(DEVKITARM)),)
+$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM)
+endif
+
+include $(DEVKITARM)/ds_rules
+
+TOPDIR ?= $(CURDIR)/..
+
+#---------------------------------------------------------------------------------
+# 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 ?= release
+SOURCES := source ../common/source
+INCLUDES := include build ../common/source ../include
+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)
+
+
+ASFLAGS := -g $(ARCH)
+LDFLAGS = -specs=ds_arm7.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*).map
+
+
+ifneq ($(BUILD),debug)
+export ARM7BIN := $(TOPDIR)/lib/libdswifi7.a
+else
+export ARM7BIN := $(TOPDIR)/lib/libdswifi7d.a
+CFLAGS += -DSGIP_DEBUG
+endif
+
+
+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 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 debug release
+ @rm -f $(TOPDIR)/lib/libdswifi7*
+
+all: $(ARM7BIN)
+
+#---------------------------------------------------------------------------------
+else
+
+DEPENDS := $(OFILES:.o=.d)
+
+#---------------------------------------------------------------------------------
+# main targets
+#---------------------------------------------------------------------------------
+$(ARM7BIN) : $(OFILES)
+ @rm -f "$(ARM7BIN)"
+ @$(AR) rcs "$(ARM7BIN)" $(OFILES)
+ @echo built ... $(notdir $@)
+
+
+#---------------------------------------------------------------------------------
+# you need a rule like this for each extension you use as binary data
+#---------------------------------------------------------------------------------
+%.bin.o : %.bin
+#---------------------------------------------------------------------------------
+ @echo $(notdir $<)
+ @$(bin2o)
+
+-include $(DEPENDS)
+
+#---------------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------------
diff --git a/c/src/lib/libbsp/arm/nds/dswifi/include/netinet/in.h b/c/src/lib/libbsp/arm/nds/dswifi/include/netinet/in.h
index 6d6e442bd8..15e46ccd53 100644
--- a/c/src/lib/libbsp/arm/nds/dswifi/include/netinet/in.h
+++ b/c/src/lib/libbsp/arm/nds/dswifi/include/netinet/in.h
@@ -51,7 +51,7 @@ extern "C" {
// actually from arpa/inet.h - but is included through netinet/in.h
unsigned long inet_addr(const char *cp);
int inet_aton(const char *cp, struct in_addr *inp);
- char *inet_ntoa(struct in_addr in);
+ char *inet_ntoa(struct in_addr in);
#ifdef __cplusplus
};
diff --git a/c/src/lib/libbsp/arm/nds/libnds/basicARM7/source/defaultARM7.c b/c/src/lib/libbsp/arm/nds/libnds/basicARM7/source/defaultARM7.c
index 943c37eb8c..ca9d39796a 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/basicARM7/source/defaultARM7.c
+++ b/c/src/lib/libbsp/arm/nds/libnds/basicARM7/source/defaultARM7.c
@@ -1,50 +1,50 @@
-/*---------------------------------------------------------------------------------
-
- default ARM7 core
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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.
-
----------------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------------
+
+ default ARM7 core
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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.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;
-}
+//---------------------------------------------------------------------------------
+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;
+}
touchPosition first,tempPos;
@@ -89,27 +89,27 @@ void VcountHandler() {
}
-//---------------------------------------------------------------------------------
-void VblankHandler(void) {
-//---------------------------------------------------------------------------------
-
- u32 i;
-
- //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 VblankHandler(void) {
+//---------------------------------------------------------------------------------
+
+ u32 i;
+
+ //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);
+ }
+ }
+ }
+}
//---------------------------------------------------------------------------------
@@ -131,7 +131,7 @@ int main(int argc, char ** argv) {
SetYtrigger(80);
irqSet(IRQ_VCOUNT, VcountHandler);
- irqSet(IRQ_VBLANK, VblankHandler);
+ irqSet(IRQ_VBLANK, VblankHandler);
irqEnable( IRQ_VBLANK | IRQ_VCOUNT);
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/gbfs.h b/c/src/lib/libbsp/arm/nds/libnds/include/gbfs.h
index 65f074662e..942e5d7a02 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/gbfs.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/gbfs.h
@@ -1,100 +1,100 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- access object in a GBFS file
-
- Copyright 2002-2004 Damian Yerrick
-
- Additional code Dave Murphy
-
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
- OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- IN THE SOFTWARE.
-
----------------------------------------------------------------------------------*/
-
-
-/* Dependency on prior include files
-
-Before you #include "gbfs.h", you should define the following types:
- typedef (unsigned 16-bit integer) u16;
- typedef (unsigned 32-bit integer) u32;
-Your system header should do this for you.
-*/
-
-#ifndef _INCLUDE_GBFS_H_
-#define _INCLUDE_GBFS_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* to make a 300 KB space called samples do GBFS_SPACE(samples, 300) */
-
-#define GBFS_SPACE(filename, kbytes) \
- const char filename[(kbytes)*1024] __attribute__ ((aligned (16))) = \
- "PinEightGBFSSpace-" #filename "-" #kbytes ;
-
-typedef struct GBFS_FILE {
- char magic[16]; /* "PinEightGBFS\r\n\032\n" */
- u32 total_len; /* total length of archive */
- u16 dir_off; /* offset in bytes to directory */
- u16 dir_nmemb; /* number of files */
- char reserved[8]; /* for future use */
-} GBFS_FILE;
-
-typedef struct GBFS_ENTRY {
- char name[24]; /* filename, nul-padded */
- u32 len; /* length of object in bytes */
- u32 data_offset; /* in bytes from beginning of file */
-} GBFS_ENTRY;
-
-
-/*---------------------------------------------------------------------------------
- Set the search limits and stride for searching
----------------------------------------------------------------------------------*/
-void gbfs_search_range( u32 gbfs_1st_limit,
- u32 gbfs_2nd_start, u32 gbfs_2nd_limit,
- u32 gbfs_stride );
-
-const GBFS_FILE * find_first_gbfs_file(const void *start);
-
-const void *skip_gbfs_file(const GBFS_FILE * file);
-
-const void *gbfs_get_obj(const GBFS_FILE *file,
- const char *name,
- u32 *len);
-
-const void *gbfs_get_nth_obj(GBFS_FILE const * file,
- size_t n,
- char *name,
- u32 *len);
-
-void *gbfs_copy_obj(void *dst,
- const GBFS_FILE *file,
- const char *name);
-
-size_t gbfs_count_objs(const GBFS_FILE *file);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // _INCLUDE_GBFS_H_
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ access object in a GBFS file
+
+ Copyright 2002-2004 Damian Yerrick
+
+ Additional code Dave Murphy
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ IN THE SOFTWARE.
+
+---------------------------------------------------------------------------------*/
+
+
+/* Dependency on prior include files
+
+Before you #include "gbfs.h", you should define the following types:
+ typedef (unsigned 16-bit integer) u16;
+ typedef (unsigned 32-bit integer) u32;
+Your system header should do this for you.
+*/
+
+#ifndef _INCLUDE_GBFS_H_
+#define _INCLUDE_GBFS_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* to make a 300 KB space called samples do GBFS_SPACE(samples, 300) */
+
+#define GBFS_SPACE(filename, kbytes) \
+ const char filename[(kbytes)*1024] __attribute__ ((aligned (16))) = \
+ "PinEightGBFSSpace-" #filename "-" #kbytes ;
+
+typedef struct GBFS_FILE {
+ char magic[16]; /* "PinEightGBFS\r\n\032\n" */
+ u32 total_len; /* total length of archive */
+ u16 dir_off; /* offset in bytes to directory */
+ u16 dir_nmemb; /* number of files */
+ char reserved[8]; /* for future use */
+} GBFS_FILE;
+
+typedef struct GBFS_ENTRY {
+ char name[24]; /* filename, nul-padded */
+ u32 len; /* length of object in bytes */
+ u32 data_offset; /* in bytes from beginning of file */
+} GBFS_ENTRY;
+
+
+/*---------------------------------------------------------------------------------
+ Set the search limits and stride for searching
+---------------------------------------------------------------------------------*/
+void gbfs_search_range( u32 gbfs_1st_limit,
+ u32 gbfs_2nd_start, u32 gbfs_2nd_limit,
+ u32 gbfs_stride );
+
+const GBFS_FILE * find_first_gbfs_file(const void *start);
+
+const void *skip_gbfs_file(const GBFS_FILE * file);
+
+const void *gbfs_get_obj(const GBFS_FILE *file,
+ const char *name,
+ u32 *len);
+
+const void *gbfs_get_nth_obj(GBFS_FILE const * file,
+ size_t n,
+ char *name,
+ u32 *len);
+
+void *gbfs_copy_obj(void *dst,
+ const GBFS_FILE *file,
+ const char *name);
+
+size_t gbfs_count_objs(const GBFS_FILE *file);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _INCLUDE_GBFS_H_
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/audio.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/audio.h
index 24457f0f90..a1c6f8b777 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/audio.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/audio.h
@@ -1,141 +1,141 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- ARM7 audio control
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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.
-
----------------------------------------------------------------------------------*/
-
-#ifndef AUDIO_ARM7_INCLUDE
-#define AUDIO_ARM7_INCLUDE
-
-//---------------------------------------------------------------------------------
-// Sound (ARM7 only)
-//---------------------------------------------------------------------------------
-#ifndef ARM7
-#error Audio is only available on the ARM7
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <nds/arm7/serial.h>
-
-
-#define SOUND_VOL(n) (n)
-#define SOUND_FREQ(n) ((-0x1000000 / (n)))
-#define SOUND_ENABLE BIT(15)
-#define SOUND_REPEAT BIT(27)
-#define SOUND_ONE_SHOT BIT(28)
-#define SOUND_FORMAT_16BIT (1<<29)
-#define SOUND_FORMAT_8BIT (0<<29)
-#define SOUND_FORMAT_PSG (3<<29)
-#define SOUND_FORMAT_ADPCM (2<<29)
-#define SOUND_16BIT (1<<29)
-#define SOUND_8BIT (0)
-
-#define SOUND_PAN(n) ((n) << 16)
-
-#define SCHANNEL_ENABLE BIT(31)
-
-//---------------------------------------------------------------------------------
-// registers
-//---------------------------------------------------------------------------------
-#define SCHANNEL_CR(n) (*(vuint32*)(0x04000400 + ((n)<<4)))
-#define SCHANNEL_VOL(n) (*(vuint8*)(0x04000400 + ((n)<<4)))
-#define SCHANNEL_PAN(n) (*(vuint8*)(0x04000402 + ((n)<<4)))
-#define SCHANNEL_SOURCE(n) (*(vuint32*)(0x04000404 + ((n)<<4)))
-#define SCHANNEL_TIMER(n) (*(vint16*)(0x04000408 + ((n)<<4)))
-#define SCHANNEL_REPEAT_POINT(n) (*(vuint16*)(0x0400040A + ((n)<<4)))
-#define SCHANNEL_LENGTH(n) (*(vuint32*)(0x0400040C + ((n)<<4)))
-
-#define SOUND_CR (*(vuint16*)0x04000500)
-#define SOUND_MASTER_VOL (*(vuint8*)0x04000500)
-
-//---------------------------------------------------------------------------------
-// not sure on the following
-//---------------------------------------------------------------------------------
-#define SOUND_BIAS (*(vuint16*)0x04000504)
-#define SOUND508 (*(vuint16*)0x04000508)
-#define SOUND510 (*(vuint16*)0x04000510)
-#define SOUND514 (*(vuint16*)0x04000514)
-#define SOUND518 (*(vuint16*)0x04000518)
-#define SOUND51C (*(vuint16*)0x0400051C)
-
-
-/*---------------------------------------------------------------------------------
- microphone code based on neimod's microphone example.
- See: http://neimod.com/dstek/
- Chris Double (chris.double@double.co.nz)
- http://www.double.co.nz/nintendo_ds
----------------------------------------------------------------------------------*/
-
-
-/*---------------------------------------------------------------------------------
- Read a byte from the microphone
----------------------------------------------------------------------------------*/
-u8 MIC_ReadData();
-
-/*---------------------------------------------------------------------------------
- Fill the buffer with data from the microphone. The buffer will be
- signed sound data at 16kHz. Once the length of the buffer is
- reached, no more data will be stored. Uses ARM7 timer 0.
----------------------------------------------------------------------------------*/
-void StartRecording(u8* buffer, int length);
-
-/*---------------------------------------------------------------------------------
- Stop recording data, and return the length of data recorded.
----------------------------------------------------------------------------------*/
-int StopRecording();
-
-/* This must be called during IRQ_TIMER0 */
-void ProcessMicrophoneTimerIRQ();
-
-void PM_SetAmp(u8 control);
-
-//---------------------------------------------------------------------------------
-// Turn the microphone on
-//---------------------------------------------------------------------------------
-static inline void MIC_On() {
-//---------------------------------------------------------------------------------
- PM_SetAmp(PM_AMP_ON);
-}
-
-
-//---------------------------------------------------------------------------------
-// Turn the microphone off
-//---------------------------------------------------------------------------------
-static inline void MIC_Off() {
-//---------------------------------------------------------------------------------
- PM_SetAmp(PM_AMP_OFF);
-}
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ ARM7 audio control
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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.
+
+---------------------------------------------------------------------------------*/
+
+#ifndef AUDIO_ARM7_INCLUDE
+#define AUDIO_ARM7_INCLUDE
+
+//---------------------------------------------------------------------------------
+// Sound (ARM7 only)
+//---------------------------------------------------------------------------------
+#ifndef ARM7
+#error Audio is only available on the ARM7
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <nds/arm7/serial.h>
+
+
+#define SOUND_VOL(n) (n)
+#define SOUND_FREQ(n) ((-0x1000000 / (n)))
+#define SOUND_ENABLE BIT(15)
+#define SOUND_REPEAT BIT(27)
+#define SOUND_ONE_SHOT BIT(28)
+#define SOUND_FORMAT_16BIT (1<<29)
+#define SOUND_FORMAT_8BIT (0<<29)
+#define SOUND_FORMAT_PSG (3<<29)
+#define SOUND_FORMAT_ADPCM (2<<29)
+#define SOUND_16BIT (1<<29)
+#define SOUND_8BIT (0)
+
+#define SOUND_PAN(n) ((n) << 16)
+
+#define SCHANNEL_ENABLE BIT(31)
+
+//---------------------------------------------------------------------------------
+// registers
+//---------------------------------------------------------------------------------
+#define SCHANNEL_CR(n) (*(vuint32*)(0x04000400 + ((n)<<4)))
+#define SCHANNEL_VOL(n) (*(vuint8*)(0x04000400 + ((n)<<4)))
+#define SCHANNEL_PAN(n) (*(vuint8*)(0x04000402 + ((n)<<4)))
+#define SCHANNEL_SOURCE(n) (*(vuint32*)(0x04000404 + ((n)<<4)))
+#define SCHANNEL_TIMER(n) (*(vint16*)(0x04000408 + ((n)<<4)))
+#define SCHANNEL_REPEAT_POINT(n) (*(vuint16*)(0x0400040A + ((n)<<4)))
+#define SCHANNEL_LENGTH(n) (*(vuint32*)(0x0400040C + ((n)<<4)))
+
+#define SOUND_CR (*(vuint16*)0x04000500)
+#define SOUND_MASTER_VOL (*(vuint8*)0x04000500)
+
+//---------------------------------------------------------------------------------
+// not sure on the following
+//---------------------------------------------------------------------------------
+#define SOUND_BIAS (*(vuint16*)0x04000504)
+#define SOUND508 (*(vuint16*)0x04000508)
+#define SOUND510 (*(vuint16*)0x04000510)
+#define SOUND514 (*(vuint16*)0x04000514)
+#define SOUND518 (*(vuint16*)0x04000518)
+#define SOUND51C (*(vuint16*)0x0400051C)
+
+
+/*---------------------------------------------------------------------------------
+ microphone code based on neimod's microphone example.
+ See: http://neimod.com/dstek/
+ Chris Double (chris.double@double.co.nz)
+ http://www.double.co.nz/nintendo_ds
+---------------------------------------------------------------------------------*/
+
+
+/*---------------------------------------------------------------------------------
+ Read a byte from the microphone
+---------------------------------------------------------------------------------*/
+u8 MIC_ReadData();
+
+/*---------------------------------------------------------------------------------
+ Fill the buffer with data from the microphone. The buffer will be
+ signed sound data at 16kHz. Once the length of the buffer is
+ reached, no more data will be stored. Uses ARM7 timer 0.
+---------------------------------------------------------------------------------*/
+void StartRecording(u8* buffer, int length);
+
+/*---------------------------------------------------------------------------------
+ Stop recording data, and return the length of data recorded.
+---------------------------------------------------------------------------------*/
+int StopRecording();
+
+/* This must be called during IRQ_TIMER0 */
+void ProcessMicrophoneTimerIRQ();
+
+void PM_SetAmp(u8 control);
+
+//---------------------------------------------------------------------------------
+// Turn the microphone on
+//---------------------------------------------------------------------------------
+static inline void MIC_On() {
+//---------------------------------------------------------------------------------
+ PM_SetAmp(PM_AMP_ON);
+}
+
+
+//---------------------------------------------------------------------------------
+// Turn the microphone off
+//---------------------------------------------------------------------------------
+static inline void MIC_Off() {
+//---------------------------------------------------------------------------------
+ PM_SetAmp(PM_AMP_OFF);
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/clock.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/clock.h
index 13cbf113e6..c5a5dbc30d 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/clock.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/clock.h
@@ -1,140 +1,140 @@
-/*---------------------------------------------------------------------------------
-
- ARM7 realtime clock
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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.
-
----------------------------------------------------------------------------------*/
-
-#ifndef ARM7_CLOCK_INCLUDE
-#define ARM7_CLOCK_INCLUDE
-
-
-#ifndef ARM7
-#error The clock is only available on the ARM7
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#include <nds/arm7/serial.h>
-
-// RTC registers
-#define WRITE_STATUS_REG1 0x60
-#define READ_STATUS_REG1 0x61
-
-/*
- Status Register 1
- 0 W Reset (0=Normal, 1=Reset)
- 1 R/W 12/24 hour mode (0=12 hour, 1=24 hour)
- 2-3 R/W General purpose bits
- 4 R Interrupt 1 Flag (1=Yes) ;auto-cleared on read
- 5 R Interrupt 2 Flag (1=Yes) ;auto-cleared on read
- 6 R Power Low Flag (0=Normal, 1=Power is/was low) ;auto-cleared on read
- 7 R Power Off Flag (0=Normal, 1=Power was off) ;auto-cleared on read
- Power off indicates that the battery was removed or fully discharged,
- all registers are reset to 00h (or 01h), and must be re-initialized.
-*/
-#define STATUS_POC (1<<7) // read-only, cleared by reading (1 if just powered on)
-#define STATUS_BLD (1<<6) // read-only, cleared by reading (1 if power dropped below the safety threshold)
-#define STATUS_INT2 (1<<5) // read-only, INT2 has occured
-#define STATUS_INT1 (1<<4) // read-only, INT1 has occured
-#define STATUS_SC1 (1<<3) // R/W scratch bit
-#define STATUS_SC0 (1<<2) // R/W scratch bit
-#define STATUS_24HRS (1<<1) // 24 hour mode when 1, 12 hour mode when 0
-#define STATUS_RESET (1<<0) // write-only, reset when 1 written
-
-#define WRITE_STATUS_REG2 0x62
-#define READ_STATUS_REG2 0x63
-/*
- Status Register 2
- 0-3 R/W INT1 Mode/Enable
- 0000b Disable
- 0x01b Selected Frequency steady interrupt
- 0x10b Per-minute edge interrupt
- 0011b Per-minute steady interrupt 1 (duty 30.0 secomds)
- 0100b Alarm 1 interrupt
- 0111b Per-minute steady interrupt 2 (duty 0.0079 secomds)
- 1xxxb 32kHz output
- 4-5 R/W General purpose bits
- 6 R/W INT2 Enable
- 0b Disable
- 1b Alarm 2 interrupt
- 7 R/W Test Mode (0=Normal, 1=Test, don't use) (cleared on Reset)
-*/
-#define STATUS_TEST (1<<7) //
-#define STATUS_INT2AE (1<<6) //
-#define STATUS_SC3 (1<<5) // R/W scratch bit
-#define STATUS_SC2 (1<<4) // R/W scratch bit
-
-#define STATUS_32kE (1<<3) // Interrupt mode bits
-#define STATUS_INT1AE (1<<2) //
-#define STATUS_INT1ME (1<<1) //
-#define STATUS_INT1FE (1<<0) //
-
-// full 7 bytes for time and date
-#define WRITE_TIME_AND_DATE 0x64
-#define READ_TIME_AND_DATE 0x65
-
-// last 3 bytes of current time
-#define WRITE_TIME 0x66
-#define READ_TIME 0x67
-
-#define WRITE_INT_REG1 0x68
-#define READ_INT_REG1 0x69
-
-#define READ_INT_REG2 0x6A
-#define WRITE_INT_REG2 0x6B
-
-#define READ_CLOCK_ADJUST_REG 0x6C
-#define WRITE_CLOCK_ADJUST_REG 0x6D
-// clock-adjustment register
-
-#define READ_FREE_REG 0x6E
-#define WRITE_FREE_REG 0x6F
-
-
-void rtcReset(void);
-void rtcTransaction(uint8 * command, uint32 commandLength, uint8 * result, uint32 resultLength);
-
-void rtcGetTime(uint8 * time);
-void rtcSetTime(uint8 * time);
-
-void rtcGetTimeAndDate(uint8 * time);
-void rtcSetTimeAndDate(uint8 * time);
-
-void rtcGetData(uint8 * data, uint32 size);
-
-void BCDToInteger(uint8 * data, uint32 length);
-void integerToBCD(uint8 * data, uint32 length);
-
-void initClockIRQ();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
+/*---------------------------------------------------------------------------------
+
+ ARM7 realtime clock
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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.
+
+---------------------------------------------------------------------------------*/
+
+#ifndef ARM7_CLOCK_INCLUDE
+#define ARM7_CLOCK_INCLUDE
+
+
+#ifndef ARM7
+#error The clock is only available on the ARM7
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#include <nds/arm7/serial.h>
+
+// RTC registers
+#define WRITE_STATUS_REG1 0x60
+#define READ_STATUS_REG1 0x61
+
+/*
+ Status Register 1
+ 0 W Reset (0=Normal, 1=Reset)
+ 1 R/W 12/24 hour mode (0=12 hour, 1=24 hour)
+ 2-3 R/W General purpose bits
+ 4 R Interrupt 1 Flag (1=Yes) ;auto-cleared on read
+ 5 R Interrupt 2 Flag (1=Yes) ;auto-cleared on read
+ 6 R Power Low Flag (0=Normal, 1=Power is/was low) ;auto-cleared on read
+ 7 R Power Off Flag (0=Normal, 1=Power was off) ;auto-cleared on read
+ Power off indicates that the battery was removed or fully discharged,
+ all registers are reset to 00h (or 01h), and must be re-initialized.
+*/
+#define STATUS_POC (1<<7) // read-only, cleared by reading (1 if just powered on)
+#define STATUS_BLD (1<<6) // read-only, cleared by reading (1 if power dropped below the safety threshold)
+#define STATUS_INT2 (1<<5) // read-only, INT2 has occured
+#define STATUS_INT1 (1<<4) // read-only, INT1 has occured
+#define STATUS_SC1 (1<<3) // R/W scratch bit
+#define STATUS_SC0 (1<<2) // R/W scratch bit
+#define STATUS_24HRS (1<<1) // 24 hour mode when 1, 12 hour mode when 0
+#define STATUS_RESET (1<<0) // write-only, reset when 1 written
+
+#define WRITE_STATUS_REG2 0x62
+#define READ_STATUS_REG2 0x63
+/*
+ Status Register 2
+ 0-3 R/W INT1 Mode/Enable
+ 0000b Disable
+ 0x01b Selected Frequency steady interrupt
+ 0x10b Per-minute edge interrupt
+ 0011b Per-minute steady interrupt 1 (duty 30.0 secomds)
+ 0100b Alarm 1 interrupt
+ 0111b Per-minute steady interrupt 2 (duty 0.0079 secomds)
+ 1xxxb 32kHz output
+ 4-5 R/W General purpose bits
+ 6 R/W INT2 Enable
+ 0b Disable
+ 1b Alarm 2 interrupt
+ 7 R/W Test Mode (0=Normal, 1=Test, don't use) (cleared on Reset)
+*/
+#define STATUS_TEST (1<<7) //
+#define STATUS_INT2AE (1<<6) //
+#define STATUS_SC3 (1<<5) // R/W scratch bit
+#define STATUS_SC2 (1<<4) // R/W scratch bit
+
+#define STATUS_32kE (1<<3) // Interrupt mode bits
+#define STATUS_INT1AE (1<<2) //
+#define STATUS_INT1ME (1<<1) //
+#define STATUS_INT1FE (1<<0) //
+
+// full 7 bytes for time and date
+#define WRITE_TIME_AND_DATE 0x64
+#define READ_TIME_AND_DATE 0x65
+
+// last 3 bytes of current time
+#define WRITE_TIME 0x66
+#define READ_TIME 0x67
+
+#define WRITE_INT_REG1 0x68
+#define READ_INT_REG1 0x69
+
+#define READ_INT_REG2 0x6A
+#define WRITE_INT_REG2 0x6B
+
+#define READ_CLOCK_ADJUST_REG 0x6C
+#define WRITE_CLOCK_ADJUST_REG 0x6D
+// clock-adjustment register
+
+#define READ_FREE_REG 0x6E
+#define WRITE_FREE_REG 0x6F
+
+
+void rtcReset(void);
+void rtcTransaction(uint8 * command, uint32 commandLength, uint8 * result, uint32 resultLength);
+
+void rtcGetTime(uint8 * time);
+void rtcSetTime(uint8 * time);
+
+void rtcGetTimeAndDate(uint8 * time);
+void rtcSetTimeAndDate(uint8 * time);
+
+void rtcGetData(uint8 * data, uint32 size);
+
+void BCDToInteger(uint8 * data, uint32 length);
+void integerToBCD(uint8 * data, uint32 length);
+
+void initClockIRQ();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/serial.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/serial.h
index e21185ff43..1064226575 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/serial.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/serial.h
@@ -1,167 +1,167 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- ARM7 serial control
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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.
-
----------------------------------------------------------------------------------*/
-
-#ifndef SERIAL_ARM7_INCLUDE
-#define SERIAL_ARM7_INCLUDE
-
-#ifndef ARM7
-#error Serial header is for ARM7 only
-#endif
-
-
-#include <nds/bios.h>
-
-
-// 'Networking'
-#define REG_RCNT (*(vuint16*)0x04000134)
-#define REG_KEYXY (*(vuint16*)0x04000136)
-#define RTC_CR (*(vuint16*)0x04000138)
-#define RTC_CR8 (*( vuint8*)0x04000138)
-
-#define REG_SIOCNT (*(vuint16*)0x04000128)
-
-#define SIO_DATA8 (*(vuint8*)0x0400012A)
-#define SIO_DATA32 (*(vuint32*)0x04000120)
-
-
-// Fixme: Does the hardware still support 16 bit comms mode?
-// BIOS makes use of 32 bit mode, so some regs still exist
-#define SIO_MULTI_0 (*(vuint16*)0x04000120)
-#define SIO_MULTI_1 (*(vuint16*)0x04000122)
-#define SIO_MULTI_2 (*(vuint16*)0x04000124)
-#define SIO_MULTI_3 (*(vuint16*)0x04000126)
-#define SIO_MULTI_SEND (*(vuint16*)0x0400012A)
-
-
-// SPI chain registers
-#define REG_SPICNT (*(vuint16*)0x040001C0)
-#define REG_SPIDATA (*(vuint16*)0x040001C2)
-
-#define SPI_ENABLE BIT(15)
-#define SPI_IRQ BIT(14)
-#define SPI_BUSY BIT(7)
-
-// Pick the SPI clock speed
-#define SPI_BAUD_4MHZ 0
-#define SPI_BAUD_2MHZ 1
-#define SPI_BAUD_1MHZ 2
-#define SPI_BAUD_512KHZ 3
-
-// meh
-#define SPI_BAUD_4MHz 0
-#define SPI_BAUD_2MHz 1
-#define SPI_BAUD_1MHz 2
-#define SPI_BAUD_512KHz 3
-
-// Pick the SPI transfer length
-#define SPI_BYTE_MODE (0<<10)
-#define SPI_HWORD_MODE (1<<10)
-
-// Pick the SPI device
-#define SPI_DEVICE_POWER (0 << 8)
-#define SPI_DEVICE_FIRMWARE (1 << 8)
-#define SPI_DEVICE_NVRAM (1 << 8)
-#define SPI_DEVICE_TOUCH (2 << 8)
-#define SPI_DEVICE_MICROPHONE (2 << 8)
-
-// When used, the /CS line will stay low after the transfer ends
-// i.e. when we're part of a continuous transfer
-#define SPI_CONTINUOUS BIT(11)
-
-// Fixme: does this stuff really belong in serial.h?
-
-// Power management registers
-#define PM_CONTROL_REG 0
-#define PM_BATTERY_REG 1
-#define PM_AMPLIFIER_REG 2
-#define PM_READ_REGISTER (1<<7)
-
-// PM control register bits - power control
-#define PM_SOUND_AMP BIT(0) // Power the sound hardware (needed to hear stuff in GBA mode too)
-#define PM_SOUND_MUTE BIT(1) // Mute the main speakers, headphone output will still work.
-#define PM_BACKLIGHT_BOTTOM BIT(2) // Enable the top backlight if set
-#define PM_BACKLIGHT_TOP BIT(3) // Enable the bottom backlight if set
-#define PM_SYSTEM_PWR BIT(6) // Turn the power *off* if set
-#define PM_POWER_DOWN BIT(6) // Same thing, I like this name better tho
-
-// PM control register bits - LED control
-#define PM_LED_CONTROL(m) ((m)<<4) // ?
-
-
-#define PM_LED_ON (0<<4) // Steady on
-#define PM_LED_SLEEP (1<<4) // Blinking, mostly off
-#define PM_LED_BLINK (3<<4) // Blinking, mostly on
-
-
-#define PM_AMP_OFFSET 2
-#define PM_AMP_ON 1
-#define PM_AMP_OFF 0
-
-// Fixme: does this stuff really belong in serial.h?
-
-// Firmware commands
-#define FIRMWARE_WREN 0x06
-#define FIRMWARE_WRDI 0x04
-#define FIRMWARE_RDID 0x9F
-#define FIRMWARE_RDSR 0x05
-#define FIRMWARE_READ 0x03
-#define FIRMWARE_PW 0x0A
-#define FIRMWARE_PP 0x02
-#define FIRMWARE_FAST 0x0B
-#define FIRMWARE_PE 0xDB
-#define FIRMWARE_SE 0xD8
-#define FIRMWARE_DP 0xB9
-#define FIRMWARE_RDP 0xAB
-
-
-static inline
-void SerialWaitBusy() {
- while (REG_SPICNT & SPI_BUSY)
- swiDelay(1);
-}
-
-
-// Warning: These functions use the SPI chain, and are thus 'critical'
-// sections, make sure to disable interrupts during the call if you've
-// got a VBlank IRQ polling the touch screen, etc...
-
-// Read/write a power management register
-int writePowerManagement(int reg, int command);
-
-static inline
-int readPowerManagement(int reg) {
- return writePowerManagement((reg)|PM_READ_REGISTER, 0);
-}
-
-// Read the firmware
-void readFirmware(uint32 address, void * destination, uint32 size);
-
-
-#endif
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ ARM7 serial control
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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.
+
+---------------------------------------------------------------------------------*/
+
+#ifndef SERIAL_ARM7_INCLUDE
+#define SERIAL_ARM7_INCLUDE
+
+#ifndef ARM7
+#error Serial header is for ARM7 only
+#endif
+
+
+#include <nds/bios.h>
+
+
+// 'Networking'
+#define REG_RCNT (*(vuint16*)0x04000134)
+#define REG_KEYXY (*(vuint16*)0x04000136)
+#define RTC_CR (*(vuint16*)0x04000138)
+#define RTC_CR8 (*( vuint8*)0x04000138)
+
+#define REG_SIOCNT (*(vuint16*)0x04000128)
+
+#define SIO_DATA8 (*(vuint8*)0x0400012A)
+#define SIO_DATA32 (*(vuint32*)0x04000120)
+
+
+// Fixme: Does the hardware still support 16 bit comms mode?
+// BIOS makes use of 32 bit mode, so some regs still exist
+#define SIO_MULTI_0 (*(vuint16*)0x04000120)
+#define SIO_MULTI_1 (*(vuint16*)0x04000122)
+#define SIO_MULTI_2 (*(vuint16*)0x04000124)
+#define SIO_MULTI_3 (*(vuint16*)0x04000126)
+#define SIO_MULTI_SEND (*(vuint16*)0x0400012A)
+
+
+// SPI chain registers
+#define REG_SPICNT (*(vuint16*)0x040001C0)
+#define REG_SPIDATA (*(vuint16*)0x040001C2)
+
+#define SPI_ENABLE BIT(15)
+#define SPI_IRQ BIT(14)
+#define SPI_BUSY BIT(7)
+
+// Pick the SPI clock speed
+#define SPI_BAUD_4MHZ 0
+#define SPI_BAUD_2MHZ 1
+#define SPI_BAUD_1MHZ 2
+#define SPI_BAUD_512KHZ 3
+
+// meh
+#define SPI_BAUD_4MHz 0
+#define SPI_BAUD_2MHz 1
+#define SPI_BAUD_1MHz 2
+#define SPI_BAUD_512KHz 3
+
+// Pick the SPI transfer length
+#define SPI_BYTE_MODE (0<<10)
+#define SPI_HWORD_MODE (1<<10)
+
+// Pick the SPI device
+#define SPI_DEVICE_POWER (0 << 8)
+#define SPI_DEVICE_FIRMWARE (1 << 8)
+#define SPI_DEVICE_NVRAM (1 << 8)
+#define SPI_DEVICE_TOUCH (2 << 8)
+#define SPI_DEVICE_MICROPHONE (2 << 8)
+
+// When used, the /CS line will stay low after the transfer ends
+// i.e. when we're part of a continuous transfer
+#define SPI_CONTINUOUS BIT(11)
+
+// Fixme: does this stuff really belong in serial.h?
+
+// Power management registers
+#define PM_CONTROL_REG 0
+#define PM_BATTERY_REG 1
+#define PM_AMPLIFIER_REG 2
+#define PM_READ_REGISTER (1<<7)
+
+// PM control register bits - power control
+#define PM_SOUND_AMP BIT(0) // Power the sound hardware (needed to hear stuff in GBA mode too)
+#define PM_SOUND_MUTE BIT(1) // Mute the main speakers, headphone output will still work.
+#define PM_BACKLIGHT_BOTTOM BIT(2) // Enable the top backlight if set
+#define PM_BACKLIGHT_TOP BIT(3) // Enable the bottom backlight if set
+#define PM_SYSTEM_PWR BIT(6) // Turn the power *off* if set
+#define PM_POWER_DOWN BIT(6) // Same thing, I like this name better tho
+
+// PM control register bits - LED control
+#define PM_LED_CONTROL(m) ((m)<<4) // ?
+
+
+#define PM_LED_ON (0<<4) // Steady on
+#define PM_LED_SLEEP (1<<4) // Blinking, mostly off
+#define PM_LED_BLINK (3<<4) // Blinking, mostly on
+
+
+#define PM_AMP_OFFSET 2
+#define PM_AMP_ON 1
+#define PM_AMP_OFF 0
+
+// Fixme: does this stuff really belong in serial.h?
+
+// Firmware commands
+#define FIRMWARE_WREN 0x06
+#define FIRMWARE_WRDI 0x04
+#define FIRMWARE_RDID 0x9F
+#define FIRMWARE_RDSR 0x05
+#define FIRMWARE_READ 0x03
+#define FIRMWARE_PW 0x0A
+#define FIRMWARE_PP 0x02
+#define FIRMWARE_FAST 0x0B
+#define FIRMWARE_PE 0xDB
+#define FIRMWARE_SE 0xD8
+#define FIRMWARE_DP 0xB9
+#define FIRMWARE_RDP 0xAB
+
+
+static inline
+void SerialWaitBusy() {
+ while (REG_SPICNT & SPI_BUSY)
+ swiDelay(1);
+}
+
+
+// Warning: These functions use the SPI chain, and are thus 'critical'
+// sections, make sure to disable interrupts during the call if you've
+// got a VBlank IRQ polling the touch screen, etc...
+
+// Read/write a power management register
+int writePowerManagement(int reg, int command);
+
+static inline
+int readPowerManagement(int reg) {
+ return writePowerManagement((reg)|PM_READ_REGISTER, 0);
+}
+
+// Read the firmware
+void readFirmware(uint32 address, void * destination, uint32 size);
+
+
+#endif
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/touch.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/touch.h
index 059a5de173..9bf7a71556 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/touch.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm7/touch.h
@@ -1,73 +1,73 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- Microphone control for the ARM7
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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.
-
----------------------------------------------------------------------------------*/
-#ifndef ARM7_TOUCH_INCLUDE
-#define ARM7_TOUCH_INCLUDE
-//---------------------------------------------------------------------------------
-
-
-#ifndef ARM7
-#error Touch screen is only available on the ARM7
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <nds/arm7/serial.h>
-
-
-#define SCREEN_WIDTH 256
-#define SCREEN_HEIGHT 192
-
-
-#define TSC_MEASURE_TEMP1 0x84
-#define TSC_MEASURE_Y 0x90
-#define TSC_MEASURE_BATTERY 0xA4
-#define TSC_MEASURE_Z1 0xB4
-#define TSC_MEASURE_Z2 0xC4
-#define TSC_MEASURE_X 0xD0
-#define TSC_MEASURE_AUX 0xE4
-#define TSC_MEASURE_TEMP2 0xF4
-
-
-
-touchPosition touchReadXY();
-
-uint16 touchRead(uint32 command);
-uint32 touchReadTemperature(int * t1, int * t2);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-//---------------------------------------------------------------------------------
-#endif // ARM7_TOUCH_INCLUDE
-//---------------------------------------------------------------------------------
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ Microphone control for the ARM7
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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.
+
+---------------------------------------------------------------------------------*/
+#ifndef ARM7_TOUCH_INCLUDE
+#define ARM7_TOUCH_INCLUDE
+//---------------------------------------------------------------------------------
+
+
+#ifndef ARM7
+#error Touch screen is only available on the ARM7
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <nds/arm7/serial.h>
+
+
+#define SCREEN_WIDTH 256
+#define SCREEN_HEIGHT 192
+
+
+#define TSC_MEASURE_TEMP1 0x84
+#define TSC_MEASURE_Y 0x90
+#define TSC_MEASURE_BATTERY 0xA4
+#define TSC_MEASURE_Z1 0xB4
+#define TSC_MEASURE_Z2 0xC4
+#define TSC_MEASURE_X 0xD0
+#define TSC_MEASURE_AUX 0xE4
+#define TSC_MEASURE_TEMP2 0xF4
+
+
+
+touchPosition touchReadXY();
+
+uint16 touchRead(uint32 command);
+uint32 touchReadTemperature(int * t1, int * t2);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+//---------------------------------------------------------------------------------
+#endif // ARM7_TOUCH_INCLUDE
+//---------------------------------------------------------------------------------
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/boxtest.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/boxtest.h
index 92865a8037..ee82f989e4 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/boxtest.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/boxtest.h
@@ -1,110 +1,110 @@
-/*---------------------------------------------------------------------------------
-$Id$
-
-BoxTest.h -- Code for performing hardware box test against viewing frustrum
-
-Copyright (C) 2005
-Michael Noland (joat)
-Jason Rogers (dovoto)
-Dave Murphy (WinterMute)
-
-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.
-
-
----------------------------------------------------------------------------------*/
-#ifndef BOX_TEST_INCLUDE
-#define BOX_TEST_INCLUDE
-
-#include <nds/arm9/video.h>
-#include <nds/arm9/videoGL.h>
-
-/*! \file boxtest.h
-\brief Box Test Functions.
-
-*/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*! \fn int BoxTest(v16 x, v16 y, v16 z, v16 width, v16 height, v16 depth)
-\brief Performs a test to determine if the provided box is in the view frustrum.
-\param x (x, y, z) point of a vertex on the box
-\param y (x, y, z) point of a vertex on the box
-\param z (x, y, z) point of a vertex on the box
-\param height (height, width, depth) describe the size of the box referenced from (x, y, z)
-\param width (height, width, depth) describe the size of the box referenced from (x, y, z)
-\param depth (height, width, depth) describe the size of the box referenced from (x, y, z)
-
-\return non zero if any or all of the box is in the view frustum
-*/
-int BoxTest(v16 x, v16 y, v16 z, v16 width, v16 height, v16 depth);
-
-/*! \fn int BoxTestf(float x, float y, float z, float width, float height, float depth)
-\brief Performs a test to determine if the provided box is in the view frustum.
-\param x (x, y, z) point of a vertex on the box
-\param y (x, y, z) point of a vertex on the box
-\param z (x, y, z) point of a vertex on the box
-\param width (width, height, depth) describe the size of the box referenced from (x, y, z)
-\param height (width, height, depth) describe the size of the box referenced from (x, y, z)
-\param depth (width, height, depth) describe the size of the box referenced from (x, y, z)
-
-\return non zero if any or all of the box is in the view frustum
-*/
-int BoxTestf(float x, float y, float z, float width, float height, float depth);
-
-/*! \fn void BoxTest_Asynch(v16 x, v16 y, v16 z, v16 width, v16 height, v16 depth)
-\brief Performs a test to determine if the provided box is in the view frustum.
-\param x (x, y, z) point of a vertex on the box
-\param y (x, y, z) point of a vertex on the box
-\param z (x, y, z) point of a vertex on the box
-\param width (width, height, depth) describe the size of the box referenced from (x, y, z)
-\param height (width, height, depth) describe the size of the box referenced from (x, y, z)
-\param depth (width, height, depth) describe the size of the box referenced from (x, y, z)
-
-Performs a test to determine if the provided box is in the view frustum. BoxTestResult must be called to get the result of this
-operation.
-*/
-void BoxTest_Asynch(v16 x, v16 y, v16 z, v16 height, v16 width, v16 depth);
-
-/*! \fn void BoxTestf_Asynch(float x, float y, float z, float width, float height, float depth)
-\brief Performs a test to determine if the provided box is in the view frustum.
-\param x (x, y, z) point of a vertex on the box
-\param y (x, y, z) point of a vertex on the box
-\param z (x, y, z) point of a vertex on the box
-\param width (width, height, depth) describe the size of the box referenced from (x, y, z)
-\param height (width, height, depth) describe the size of the box referenced from (x, y, z)
-\param depth (width, height, depth) describe the size of the box referenced from (x, y, z)
-
-Performs a test to determine if the provided box is in the view frustum. BoxTestResult must be called to get the result of this
-operation.
-*/
-void BoxTestf_Asynch(float x, float y, float z, float width, float height, float depth);
-
-/*! \fn void BoxTestResult(void)
-\brief Gets the result of the last box test. Needed for asynch box test calls.
-\return non zero if any or all of the box is in the view frustum
-
-*/
-int BoxTestResult(void);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
+/*---------------------------------------------------------------------------------
+$Id$
+
+BoxTest.h -- Code for performing hardware box test against viewing frustrum
+
+Copyright (C) 2005
+Michael Noland (joat)
+Jason Rogers (dovoto)
+Dave Murphy (WinterMute)
+
+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.
+
+
+---------------------------------------------------------------------------------*/
+#ifndef BOX_TEST_INCLUDE
+#define BOX_TEST_INCLUDE
+
+#include <nds/arm9/video.h>
+#include <nds/arm9/videoGL.h>
+
+/*! \file boxtest.h
+\brief Box Test Functions.
+
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*! \fn int BoxTest(v16 x, v16 y, v16 z, v16 width, v16 height, v16 depth)
+\brief Performs a test to determine if the provided box is in the view frustrum.
+\param x (x, y, z) point of a vertex on the box
+\param y (x, y, z) point of a vertex on the box
+\param z (x, y, z) point of a vertex on the box
+\param height (height, width, depth) describe the size of the box referenced from (x, y, z)
+\param width (height, width, depth) describe the size of the box referenced from (x, y, z)
+\param depth (height, width, depth) describe the size of the box referenced from (x, y, z)
+
+\return non zero if any or all of the box is in the view frustum
+*/
+int BoxTest(v16 x, v16 y, v16 z, v16 width, v16 height, v16 depth);
+
+/*! \fn int BoxTestf(float x, float y, float z, float width, float height, float depth)
+\brief Performs a test to determine if the provided box is in the view frustum.
+\param x (x, y, z) point of a vertex on the box
+\param y (x, y, z) point of a vertex on the box
+\param z (x, y, z) point of a vertex on the box
+\param width (width, height, depth) describe the size of the box referenced from (x, y, z)
+\param height (width, height, depth) describe the size of the box referenced from (x, y, z)
+\param depth (width, height, depth) describe the size of the box referenced from (x, y, z)
+
+\return non zero if any or all of the box is in the view frustum
+*/
+int BoxTestf(float x, float y, float z, float width, float height, float depth);
+
+/*! \fn void BoxTest_Asynch(v16 x, v16 y, v16 z, v16 width, v16 height, v16 depth)
+\brief Performs a test to determine if the provided box is in the view frustum.
+\param x (x, y, z) point of a vertex on the box
+\param y (x, y, z) point of a vertex on the box
+\param z (x, y, z) point of a vertex on the box
+\param width (width, height, depth) describe the size of the box referenced from (x, y, z)
+\param height (width, height, depth) describe the size of the box referenced from (x, y, z)
+\param depth (width, height, depth) describe the size of the box referenced from (x, y, z)
+
+Performs a test to determine if the provided box is in the view frustum. BoxTestResult must be called to get the result of this
+operation.
+*/
+void BoxTest_Asynch(v16 x, v16 y, v16 z, v16 height, v16 width, v16 depth);
+
+/*! \fn void BoxTestf_Asynch(float x, float y, float z, float width, float height, float depth)
+\brief Performs a test to determine if the provided box is in the view frustum.
+\param x (x, y, z) point of a vertex on the box
+\param y (x, y, z) point of a vertex on the box
+\param z (x, y, z) point of a vertex on the box
+\param width (width, height, depth) describe the size of the box referenced from (x, y, z)
+\param height (width, height, depth) describe the size of the box referenced from (x, y, z)
+\param depth (width, height, depth) describe the size of the box referenced from (x, y, z)
+
+Performs a test to determine if the provided box is in the view frustum. BoxTestResult must be called to get the result of this
+operation.
+*/
+void BoxTestf_Asynch(float x, float y, float z, float width, float height, float depth);
+
+/*! \fn void BoxTestResult(void)
+\brief Gets the result of the last box test. Needed for asynch box test calls.
+\return non zero if any or all of the box is in the view frustum
+
+*/
+int BoxTestResult(void);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/cache.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/cache.h
index 804b804a5c..08a6158aa7 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/cache.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/cache.h
@@ -1,88 +1,88 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- key input code -- provides slightly higher level input forming
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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.
-
----------------------------------------------------------------------------------*/
-/*! \file cache.h
-\brief ARM9 cache control functions.
-
-*/
-#ifndef _cache_h_
-#define _cache_h_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "nds/jtypes.h"
-
-
-/*! \fn IC_InvalidateAll()
- \brief invalidate entire instruction cache.
-*/
-void IC_InvalidateAll();
-
-
-/*! \fn IC_InvalidateRange(const void *base, u32 size)
- \brief invalidate the instruction cache for a range of addresses.
- \param base base address of the region to invalidate
- \param size size of the region to invalidate.
-*/
-void IC_InvalidateRange(const void *base, u32 size);
-
-
-/*! \fn DC_FlushAll()
- \brief flush the entire data cache to memory.
-*/
-void DC_FlushAll();
-
-
-/*! \fn DC_FlushRange(const void *base, u32 size)
- \brief flush the data cache for a range of addresses to memory.
- \param base base address of the region to flush.
- \param size size of the region to flush.
-*/
-void DC_FlushRange(const void *base, u32 size);
-
-
-/*! \fn DC_InvalidateAll()
- \brief invalidate the entire data cache.
-*/
-void DC_InvalidateAll();
-
-
-/*! \fn DC_InvalidateRange(const void *base, u32 size)
- \brief invalidate the data cache for a range of addresses.
- \param base base address of the region to invalidate
- \param size size of the region to invalidate.
-*/
-void DC_InvalidateRange(const void *base, u32 size);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ key input code -- provides slightly higher level input forming
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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.
+
+---------------------------------------------------------------------------------*/
+/*! \file cache.h
+\brief ARM9 cache control functions.
+
+*/
+#ifndef _cache_h_
+#define _cache_h_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "nds/jtypes.h"
+
+
+/*! \fn IC_InvalidateAll(void)
+ \brief invalidate entire instruction cache.
+*/
+void IC_InvalidateAll(void);
+
+
+/*! \fn IC_InvalidateRange(const void *base, u32 size)
+ \brief invalidate the instruction cache for a range of addresses.
+ \param base base address of the region to invalidate
+ \param size size of the region to invalidate.
+*/
+void IC_InvalidateRange(const void *base, u32 size);
+
+
+/*! \fn DC_FlushAll(void)
+ \brief flush the entire data cache to memory.
+*/
+void DC_FlushAll(void);
+
+
+/*! \fn DC_FlushRange(const void *base, u32 size)
+ \brief flush the data cache for a range of addresses to memory.
+ \param base base address of the region to flush.
+ \param size size of the region to flush.
+*/
+void DC_FlushRange(const void *base, u32 size);
+
+
+/*! \fn DC_InvalidateAll(void)
+ \brief invalidate the entire data cache.
+*/
+void DC_InvalidateAll(void);
+
+
+/*! \fn DC_InvalidateRange(const void *base, u32 size)
+ \brief invalidate the data cache for a range of addresses.
+ \param base base address of the region to invalidate
+ \param size size of the region to invalidate.
+*/
+void DC_InvalidateRange(const void *base, u32 size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/console.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/console.h
index 908c325131..19ac5382f9 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/console.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/console.h
@@ -1,87 +1,87 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- console functions
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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.
-
-
----------------------------------------------------------------------------------*/
-
-/*! \file console.h
- \brief nds stdio support.
-*/
-
-#ifndef CONSOLE_H
-#define CONSOLE_H
-
-#define CONSOLE_USE_COLOR255 16
-
-#include <nds/jtypes.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*! \fn void consoleInit(u16* font, u16* charBase, u16 numCharacters, u8 charStart, u16* map, u8 pal, u8 bitDepth)
- \brief Initialise the console.
- \param font base address of the 16 color font to use
- \param charBase VRAM address to load the font
- \param numCharacters number of characters in the font
- \param charStart ascii code of the first character in the font
- \param map base address of the map to use for printing
- \param pal 16 color palette index to use
- \param bitDepth 256/16 color tile flag.
-
- Initializes the console with the given parameters. When pal is greater than 15 and
- bitDepth is 16 then all non zero entries in the font are set to index 255. When bitDepth
- is not 16 then the font tiles are created as 8bit (256 color).
-
-*/
-void consoleInit(u16* font, u16* charBase, u16 numCharacters, u8 charStart, u16* map, u8 pal, u8 bitDepth);
-/*! \fn void consoleInitDefault(u16* map, u16* charBase, u8 bitDepth)
- \brief Initialize the console with some default parameters.
- \param charBase VRAM address to load the font
- \param map base address of the map to use for printing
- \param bitDepth 256/16 color tile flag
-
- This function calls consoleInit() with the default built in font and character ranges, the parameters given
- are as for that function.
-*/
-void consoleInitDefault(u16* map, u16* charBase, u8 bitDepth);
-
-/*! \fn void consoleDemoInit(void)
-\brief Initialize the console to a default state for prototyping.
-This function sets the console to use sub display, VRAM_C, and BG0 and enables MODE_0_2D on the
-sub display. It is intended for use in prototyping applications which need print ability and not actual
-game use. Print functionality can be utilized with just this call.
-*/
-void consoleDemoInit(void);
-/*! \fn void consoleClear(void)
-\brief Clears the screan by iprintf("\x1b[2J");
-*/
-void consoleClear(void);
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ console functions
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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.
+
+
+---------------------------------------------------------------------------------*/
+
+/*! \file console.h
+ \brief nds stdio support.
+*/
+
+#ifndef CONSOLE_H
+#define CONSOLE_H
+
+#define CONSOLE_USE_COLOR255 16
+
+#include <nds/jtypes.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*! \fn void consoleInit(u16* font, u16* charBase, u16 numCharacters, u8 charStart, u16* map, u8 pal, u8 bitDepth)
+ \brief Initialise the console.
+ \param font base address of the 16 color font to use
+ \param charBase VRAM address to load the font
+ \param numCharacters number of characters in the font
+ \param charStart ascii code of the first character in the font
+ \param map base address of the map to use for printing
+ \param pal 16 color palette index to use
+ \param bitDepth 256/16 color tile flag.
+
+ Initializes the console with the given parameters. When pal is greater than 15 and
+ bitDepth is 16 then all non zero entries in the font are set to index 255. When bitDepth
+ is not 16 then the font tiles are created as 8bit (256 color).
+
+*/
+void consoleInit(u16* font, u16* charBase, u16 numCharacters, u8 charStart, u16* map, u8 pal, u8 bitDepth);
+/*! \fn void consoleInitDefault(u16* map, u16* charBase, u8 bitDepth)
+ \brief Initialize the console with some default parameters.
+ \param charBase VRAM address to load the font
+ \param map base address of the map to use for printing
+ \param bitDepth 256/16 color tile flag
+
+ This function calls consoleInit() with the default built in font and character ranges, the parameters given
+ are as for that function.
+*/
+void consoleInitDefault(u16* map, u16* charBase, u8 bitDepth);
+
+/*! \fn void consoleDemoInit(void)
+\brief Initialize the console to a default state for prototyping.
+This function sets the console to use sub display, VRAM_C, and BG0 and enables MODE_0_2D on the
+sub display. It is intended for use in prototyping applications which need print ability and not actual
+game use. Print functionality can be utilized with just this call.
+*/
+void consoleDemoInit(void);
+/*! \fn void consoleClear(void)
+\brief Clears the screan by iprintf("\x1b[2J");
+*/
+void consoleClear(void);
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/ndsmotion.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/ndsmotion.h
index 8b2301621b..e1ab018b5a 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/ndsmotion.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/ndsmotion.h
@@ -1,192 +1,192 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- DS Motion Card/DS Motion Pak functionality
-
- Copyright (C) 2007
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
- Keith Epstein (KeithE)
-
- 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.
-
----------------------------------------------------------------------------------*/
-
-/*! \file ndsmotion.h
-\brief interface code for the ds motion card, ds motion pak, MK6
-
-*/
-#ifndef NDS_MOTION_INCLUDE
-#define NDS_MOTION_INCLUDE
-//---------------------------------------------------------------------------------
-
-
-typedef struct
-{
- short xoff, yoff, zoff, goff;
- short xsens, ysens, zsens, gsens;
-}MotionCalibration;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*! \fn int motion_init()
-\brief Initializes the DS Motion Sensor.
-Run this before using any of the DS Motion Sensor functions
-save the return value and pass it to the other motion_ functions
-*/
-int motion_init();
-
-/*! \fn int motion_deinit()
-\brief Deinitializes the DS Motion Sensor
-*/
-void motion_deinit();
-
-/*! \fn signed int motion_read_x()
-\brief read the X acceleration
-*/
-signed int motion_read_x();
-
-/*! \fn signed int motion_read_y()
-\brief read the Y acceleration
-*/
-signed int motion_read_y();
-
-/*! \fn signed int motion_read_z()
-\brief read the Z acceleration
-*/
-signed int motion_read_z();
-
-/*! \fn signed int motion_read_gyro()
-\brief read the Z rotational speed
-*/
-signed int motion_read_gyro();
-
-/*! \fn int motion_acceleration_x()
-\brief gets acceleration value to mili G (where g is 9.8 m/s*s)
-*/
-int motion_acceleration_x();
-
-/*! \fn int motion_acceleration_y()
-\brief gets acceleration value to mili G (where g is 9.8 m/s*s)
-*/
-int motion_acceleration_y();
-
-/*! \fn int motion_acceleration_z()
-\brief gets acceleration value to mili G (where g is 9.8 m/s*s)
-*/
-int motion_acceleration_z();
-
-/*! \fn void motion_set_sens_x(int sens)
-\brief this should be passed the raw reading at 1g for accurate
-acceleration calculations. Default is 819
-*/
-void motion_set_sens_x(int sens);
-
-/*! \fn void motion_set_sens_y(int sens)
-\brief this should be passed the raw reading at 1g for accurate
-acceleration calculations. Default is 819
-*/
-void motion_set_sens_y(int sens);
-
-/*! \fn void motion_set_sens_z(int sens)
-\brief this should be passed the raw reading at 1g for accurate
-acceleration calculations. Default is 819
-*/
-void motion_set_sens_z(int sens);
-
-/*! \fn void motion_set_sens_x(int sens)
-\brief this should be passed the raw reading at 1g for accurate
-acceleration calculations. Default is 825
-*/
-void motion_set_sens_gyro(int sens);
-
-/*! \fn void motion_set_offs_x()
-\brief this should be called when the axis is under no acceleration
-default is 2048
-*/
-void motion_set_offs_x();
-
-/*! \fn void motion_set_offs_y()
-\brief this should be called when the axis is under no acceleration
-default is 2048
-*/
-void motion_set_offs_y();
-
-/*! \fn void motion_set_offs_z()
-\brief this should be called when the axis is under no acceleration
-default is 2048
-*/
-void motion_set_offs_z();
-
-/*! \fn void motion_set_offs_gyro()
-\brief this should be called when the axis is under no rotation
-default is 1680
-*/
-void motion_set_offs_gyro();
-
-/*! \fn int motion_rotation()
-\brief converts raw rotation value to degrees per second
-*/
-int motion_rotation();
-
-/*! \fn MotionCalibration* motion_get_calibration()
-\brief This returns the current calibration settings for saving
-*/
-MotionCalibration* motion_get_calibration();
-
-/*! \fn void motion_set_calibration(MotionCalibration* cal)
-\brief This sets the calibration settings. Intended
-to restore saved calibration settings
-*/
-void motion_set_calibration(MotionCalibration* cal);
-
-/*! \fn MotionCalibration* motion_enable_ain_1()
-\brief This enables the analog input number 1.
-Required before reading analog input number 1.
-*/
-void motion_enable_ain_1();
-
-/*! \fn MotionCalibration* motion_enable_ain_2()
-\brief This enables the analog input number 2.
-Required before reading analog input number 2.
-*/
-void motion_enable_ain_2();
-
-/*! \fn MotionCalibration* motion_read_ain_1()
-\brief This reads the analog input number 1.
-analog input number 1 needs to be enabled before reading.
-*/
-int motion_read_ain_1();
-
-/*! \fn MotionCalibration* motion_read_ain_2()
-\brief This reads the analog input number 2.
-analog input number 2 needs to be enabled before reading.
-*/
-int motion_read_ain_2();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ DS Motion Card/DS Motion Pak functionality
+
+ Copyright (C) 2007
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+ Keith Epstein (KeithE)
+
+ 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.
+
+---------------------------------------------------------------------------------*/
+
+/*! \file ndsmotion.h
+\brief interface code for the ds motion card, ds motion pak, MK6
+
+*/
+#ifndef NDS_MOTION_INCLUDE
+#define NDS_MOTION_INCLUDE
+//---------------------------------------------------------------------------------
+
+
+typedef struct
+{
+ short xoff, yoff, zoff, goff;
+ short xsens, ysens, zsens, gsens;
+}MotionCalibration;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*! \fn int motion_init()
+\brief Initializes the DS Motion Sensor.
+Run this before using any of the DS Motion Sensor functions
+save the return value and pass it to the other motion_ functions
+*/
+int motion_init();
+
+/*! \fn int motion_deinit()
+\brief Deinitializes the DS Motion Sensor
+*/
+void motion_deinit();
+
+/*! \fn signed int motion_read_x()
+\brief read the X acceleration
+*/
+signed int motion_read_x();
+
+/*! \fn signed int motion_read_y()
+\brief read the Y acceleration
+*/
+signed int motion_read_y();
+
+/*! \fn signed int motion_read_z()
+\brief read the Z acceleration
+*/
+signed int motion_read_z();
+
+/*! \fn signed int motion_read_gyro()
+\brief read the Z rotational speed
+*/
+signed int motion_read_gyro();
+
+/*! \fn int motion_acceleration_x()
+\brief gets acceleration value to mili G (where g is 9.8 m/s*s)
+*/
+int motion_acceleration_x();
+
+/*! \fn int motion_acceleration_y()
+\brief gets acceleration value to mili G (where g is 9.8 m/s*s)
+*/
+int motion_acceleration_y();
+
+/*! \fn int motion_acceleration_z()
+\brief gets acceleration value to mili G (where g is 9.8 m/s*s)
+*/
+int motion_acceleration_z();
+
+/*! \fn void motion_set_sens_x(int sens)
+\brief this should be passed the raw reading at 1g for accurate
+acceleration calculations. Default is 819
+*/
+void motion_set_sens_x(int sens);
+
+/*! \fn void motion_set_sens_y(int sens)
+\brief this should be passed the raw reading at 1g for accurate
+acceleration calculations. Default is 819
+*/
+void motion_set_sens_y(int sens);
+
+/*! \fn void motion_set_sens_z(int sens)
+\brief this should be passed the raw reading at 1g for accurate
+acceleration calculations. Default is 819
+*/
+void motion_set_sens_z(int sens);
+
+/*! \fn void motion_set_sens_x(int sens)
+\brief this should be passed the raw reading at 1g for accurate
+acceleration calculations. Default is 825
+*/
+void motion_set_sens_gyro(int sens);
+
+/*! \fn void motion_set_offs_x()
+\brief this should be called when the axis is under no acceleration
+default is 2048
+*/
+void motion_set_offs_x();
+
+/*! \fn void motion_set_offs_y()
+\brief this should be called when the axis is under no acceleration
+default is 2048
+*/
+void motion_set_offs_y();
+
+/*! \fn void motion_set_offs_z()
+\brief this should be called when the axis is under no acceleration
+default is 2048
+*/
+void motion_set_offs_z();
+
+/*! \fn void motion_set_offs_gyro()
+\brief this should be called when the axis is under no rotation
+default is 1680
+*/
+void motion_set_offs_gyro();
+
+/*! \fn int motion_rotation()
+\brief converts raw rotation value to degrees per second
+*/
+int motion_rotation();
+
+/*! \fn MotionCalibration* motion_get_calibration()
+\brief This returns the current calibration settings for saving
+*/
+MotionCalibration* motion_get_calibration();
+
+/*! \fn void motion_set_calibration(MotionCalibration* cal)
+\brief This sets the calibration settings. Intended
+to restore saved calibration settings
+*/
+void motion_set_calibration(MotionCalibration* cal);
+
+/*! \fn MotionCalibration* motion_enable_ain_1()
+\brief This enables the analog input number 1.
+Required before reading analog input number 1.
+*/
+void motion_enable_ain_1();
+
+/*! \fn MotionCalibration* motion_enable_ain_2()
+\brief This enables the analog input number 2.
+Required before reading analog input number 2.
+*/
+void motion_enable_ain_2();
+
+/*! \fn MotionCalibration* motion_read_ain_1()
+\brief This reads the analog input number 1.
+analog input number 1 needs to be enabled before reading.
+*/
+int motion_read_ain_1();
+
+/*! \fn MotionCalibration* motion_read_ain_2()
+\brief This reads the analog input number 2.
+analog input number 2 needs to be enabled before reading.
+*/
+int motion_read_ain_2();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/video.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/video.h
index fdf8dfe6eb..723ca41ba0 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/video.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/video.h
@@ -1,593 +1,593 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- Video registers and defines
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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.
-
----------------------------------------------------------------------------------*/
-
-#ifndef VIDEO_ARM9_INCLUDE
-#define VIDEO_ARM9_INCLUDE
-
-
-#ifndef ARM9
-#error Video is only available on the ARM9
-#endif
-
-#include <nds/jtypes.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// macro creates a 15 bit color from 3x5 bit components
-#define RGB15(r,g,b) ((r)|((g)<<5)|((b)<<10))
-#define RGB5(r,g,b) ((r)|((g)<<5)|((b)<<10))
-#define RGB8(r,g,b) (((r)>>3)|(((g)>>3)<<5)|(((b)>>3)<<10))
-
-
-#define SCREEN_HEIGHT 192
-#define SCREEN_WIDTH 256
-// Vram Control
-#define VRAM_CR (*(vuint32*)0x04000240)
-#define VRAM_A_CR (*(vuint8*)0x04000240)
-#define VRAM_B_CR (*(vuint8*)0x04000241)
-#define VRAM_C_CR (*(vuint8*)0x04000242)
-#define VRAM_D_CR (*(vuint8*)0x04000243)
-#define VRAM_E_CR (*(vuint8*)0x04000244)
-#define VRAM_F_CR (*(vuint8*)0x04000245)
-#define VRAM_G_CR (*(vuint8*)0x04000246)
-#define WRAM_CR (*(vuint8*)0x04000247)
-#define VRAM_H_CR (*(vuint8*)0x04000248)
-#define VRAM_I_CR (*(vuint8*)0x04000249)
-
-#define VRAM_ENABLE (1<<7)
-
-#define VRAM_OFFSET(n) ((n)<<3)
-
-
-typedef enum {
- VRAM_A_LCD = 0,
- VRAM_A_MAIN_BG = 1,
- VRAM_A_MAIN_BG_0x06000000 = 1 | VRAM_OFFSET(0),
- VRAM_A_MAIN_BG_0x06020000 = 1 | VRAM_OFFSET(1),
- VRAM_A_MAIN_BG_0x06040000 = 1 | VRAM_OFFSET(2),
- VRAM_A_MAIN_BG_0x06060000 = 1 | VRAM_OFFSET(3),
- VRAM_A_MAIN_SPRITE = 2,
- VRAM_A_MAIN_SPRITE_0x06400000 = 2,
- VRAM_A_MAIN_SPRITE_0x06420000 = 2 | VRAM_OFFSET(1),
- VRAM_A_TEXTURE = 3,
- VRAM_A_TEXTURE_SLOT0 = 3 | VRAM_OFFSET(0),
- VRAM_A_TEXTURE_SLOT1 = 3 | VRAM_OFFSET(1),
- VRAM_A_TEXTURE_SLOT2 = 3 | VRAM_OFFSET(2),
- VRAM_A_TEXTURE_SLOT3 = 3 | VRAM_OFFSET(3)
-} VRAM_A_TYPE;
-
-typedef enum {
- VRAM_B_LCD = 0,
- VRAM_B_MAIN_BG = 1 | VRAM_OFFSET(1),
- VRAM_B_MAIN_BG_0x06000000 = 1 | VRAM_OFFSET(0),
- VRAM_B_MAIN_BG_0x06020000 = 1 | VRAM_OFFSET(1),
- VRAM_B_MAIN_BG_0x06040000 = 1 | VRAM_OFFSET(2),
- VRAM_B_MAIN_BG_0x06060000 = 1 | VRAM_OFFSET(3),
- VRAM_B_MAIN_SPRITE = 2 | VRAM_OFFSET(1),
- VRAM_B_MAIN_SPRITE_0x06400000 = 2,
- VRAM_B_MAIN_SPRITE_0x06420000 = 2 | VRAM_OFFSET(1),
- VRAM_B_TEXTURE = 3 | VRAM_OFFSET(1),
- VRAM_B_TEXTURE_SLOT0 = 3 | VRAM_OFFSET(0),
- VRAM_B_TEXTURE_SLOT1 = 3 | VRAM_OFFSET(1),
- VRAM_B_TEXTURE_SLOT2 = 3 | VRAM_OFFSET(2),
- VRAM_B_TEXTURE_SLOT3 = 3 | VRAM_OFFSET(3)
-} VRAM_B_TYPE;
-
-typedef enum {
- VRAM_C_LCD = 0,
- VRAM_C_MAIN_BG = 1 | VRAM_OFFSET(2),
- VRAM_C_MAIN_BG_0x06000000 = 1 | VRAM_OFFSET(0),
- VRAM_C_MAIN_BG_0x06020000 = 1 | VRAM_OFFSET(1),
- VRAM_C_MAIN_BG_0x06040000 = 1 | VRAM_OFFSET(2),
- VRAM_C_MAIN_BG_0x06060000 = 1 | VRAM_OFFSET(3),
- VRAM_C_ARM7 = 2,
- VRAM_C_ARM7_0x06000000 = 2,
- VRAM_C_ARM7_0x06020000 = 2 | VRAM_OFFSET(1),
- VRAM_C_SUB_BG = 4,
- VRAM_C_SUB_BG_0x06200000 = 4 | VRAM_OFFSET(0),
- VRAM_C_SUB_BG_0x06220000 = 4 | VRAM_OFFSET(1),
- VRAM_C_SUB_BG_0x06240000 = 4 | VRAM_OFFSET(2),
- VRAM_C_SUB_BG_0x06260000 = 4 | VRAM_OFFSET(3),
- VRAM_C_TEXTURE = 3 | VRAM_OFFSET(2),
- VRAM_C_TEXTURE_SLOT0 = 3 | VRAM_OFFSET(0),
- VRAM_C_TEXTURE_SLOT1 = 3 | VRAM_OFFSET(1),
- VRAM_C_TEXTURE_SLOT2 = 3 | VRAM_OFFSET(2),
- VRAM_C_TEXTURE_SLOT3 = 3 | VRAM_OFFSET(3)
-} VRAM_C_TYPE;
-
-typedef enum {
- VRAM_D_LCD = 0,
- VRAM_D_MAIN_BG = 1 | VRAM_OFFSET(3),
- VRAM_D_MAIN_BG_0x06000000 = 1 | VRAM_OFFSET(0),
- VRAM_D_MAIN_BG_0x06020000 = 1 | VRAM_OFFSET(1),
- VRAM_D_MAIN_BG_0x06040000 = 1 | VRAM_OFFSET(2),
- VRAM_D_MAIN_BG_0x06060000 = 1 | VRAM_OFFSET(3),
- VRAM_D_ARM7 = 2 | VRAM_OFFSET(1),
- VRAM_D_ARM7_0x06000000 = 2,
- VRAM_D_ARM7_0x06020000 = 2 | VRAM_OFFSET(1),
- VRAM_D_SUB_SPRITE = 4,
- VRAM_D_TEXTURE = 3 | VRAM_OFFSET(3),
- VRAM_D_TEXTURE_SLOT0 = 3 | VRAM_OFFSET(0),
- VRAM_D_TEXTURE_SLOT1 = 3 | VRAM_OFFSET(1),
- VRAM_D_TEXTURE_SLOT2 = 3 | VRAM_OFFSET(2),
- VRAM_D_TEXTURE_SLOT3 = 3 | VRAM_OFFSET(3)
-} VRAM_D_TYPE;
-
-typedef enum {
- VRAM_E_LCD = 0,
- VRAM_E_MAIN_BG = 1,
- VRAM_E_MAIN_SPRITE = 2,
- VRAM_E_TEX_PALETTE = 3,
- VRAM_E_BG_EXT_PALETTE = 4,
- VRAM_E_OBJ_EXT_PALETTE = 5,
-} VRAM_E_TYPE;
-
-typedef enum {
- VRAM_F_LCD = 0,
- VRAM_F_MAIN_BG = 1,
- VRAM_F_MAIN_SPRITE = 2,
- VRAM_F_MAIN_SPRITE_0x06000000 = 2,
- VRAM_F_MAIN_SPRITE_0x06004000 = 2 | VRAM_OFFSET(1),
- VRAM_F_MAIN_SPRITE_0x06010000 = 2 | VRAM_OFFSET(2),
- VRAM_F_MAIN_SPRITE_0x06014000 = 2 | VRAM_OFFSET(3),
- VRAM_F_TEX_PALETTE = 3,
- VRAM_F_BG_EXT_PALETTE = 4,
- VRAM_F_OBJ_EXT_PALETTE = 5,
-} VRAM_F_TYPE;
-
-typedef enum {
- VRAM_G_LCD = 0,
- VRAM_G_MAIN_BG = 1,
- VRAM_G_MAIN_SPRITE = 2,
- VRAM_G_MAIN_SPRITE_0x06000000 = 2,
- VRAM_G_MAIN_SPRITE_0x06004000 = 2 | VRAM_OFFSET(1),
- VRAM_G_MAIN_SPRITE_0x06010000 = 2 | VRAM_OFFSET(2),
- VRAM_G_MAIN_SPRITE_0x06014000 = 2 | VRAM_OFFSET(3),
- VRAM_G_TEX_PALETTE = 3,
- VRAM_G_BG_EXT_PALETTE = 4,
- VRAM_G_OBJ_EXT_PALETTE = 5,
-} VRAM_G_TYPE;
-
-typedef enum {
- VRAM_H_LCD = 0,
- VRAM_H_SUB_BG = 1,
- VRAM_H_SUB_BG_EXT_PALETTE = 2,
-} VRAM_H_TYPE;
-
-typedef enum {
- VRAM_I_LCD = 0,
- VRAM_I_SUB_BG = 1,
- VRAM_I_SUB_SPRITE = 2,
- VRAM_I_SUB_SPRITE_EXT_PALETTE = 3,
-}VRAM_I_TYPE;
-
-
-typedef u16 _palette[256];
-typedef _palette _ext_palette[16];
-
-#define VRAM_E_EXT_PALETTE ((_ext_palette *)VRAM_E)
-#define VRAM_F_EXT_PALETTE ((_ext_palette *)VRAM_F)
-#define VRAM_G_EXT_PALETTE ((_ext_palette *)VRAM_G)
-#define VRAM_H_EXT_PALETTE ((_ext_palette *)VRAM_H)
-
-
-uint32 vramSetMainBanks(VRAM_A_TYPE a, VRAM_B_TYPE b, VRAM_C_TYPE c, VRAM_D_TYPE d);
-void vramRestoreMainBanks(uint32 vramTemp);
-
-void vramSetBankA(VRAM_A_TYPE a);
-void vramSetBankB(VRAM_B_TYPE b);
-void vramSetBankC(VRAM_C_TYPE c);
-void vramSetBankD(VRAM_D_TYPE d);
-void vramSetBankE(VRAM_E_TYPE e);
-void vramSetBankF(VRAM_F_TYPE f);
-void vramSetBankG(VRAM_G_TYPE g);
-void vramSetBankH(VRAM_H_TYPE h);
-void vramSetBankI(VRAM_I_TYPE i);
-
-
-// Display control registers
-#define DISPLAY_CR (*(vuint32*)0x04000000)
-#define SUB_DISPLAY_CR (*(vuint32*)0x04001000)
-
-#define MODE_0_2D 0x10000
-#define MODE_1_2D 0x10001
-#define MODE_2_2D 0x10002
-#define MODE_3_2D 0x10003
-#define MODE_4_2D 0x10004
-#define MODE_5_2D 0x10005
-
-// main display only
-#define MODE_6_2D 0x10006
-#define MODE_FIFO (3<<16)
-
-#define ENABLE_3D (1<<3)
-
-#define DISPLAY_BG0_ACTIVE (1 << 8)
-#define DISPLAY_BG1_ACTIVE (1 << 9)
-#define DISPLAY_BG2_ACTIVE (1 << 10)
-#define DISPLAY_BG3_ACTIVE (1 << 11)
-#define DISPLAY_SPR_ACTIVE (1 << 12)
-#define DISPLAY_WIN0_ON (1 << 13)
-#define DISPLAY_WIN1_ON (1 << 14)
-#define DISPLAY_SPR_WIN_ON (1 << 15)
-
-
-// Main display only
-#define MODE_0_3D (MODE_0_2D | DISPLAY_BG0_ACTIVE | ENABLE_3D)
-#define MODE_1_3D (MODE_1_2D | DISPLAY_BG0_ACTIVE | ENABLE_3D)
-#define MODE_2_3D (MODE_2_2D | DISPLAY_BG0_ACTIVE | ENABLE_3D)
-#define MODE_3_3D (MODE_3_2D | DISPLAY_BG0_ACTIVE | ENABLE_3D)
-#define MODE_4_3D (MODE_4_2D | DISPLAY_BG0_ACTIVE | ENABLE_3D)
-#define MODE_5_3D (MODE_5_2D | DISPLAY_BG0_ACTIVE | ENABLE_3D)
-#define MODE_6_3D (MODE_6_2D | DISPLAY_BG0_ACTIVE | ENABLE_3D)
-
-#define MODE_FB0 (0x00020000)
-#define MODE_FB1 (0x00060000)
-#define MODE_FB2 (0x000A0000)
-#define MODE_FB3 (0x000E0000)
-
-#define DISPLAY_SPR_HBLANK (1 << 23)
-
-#define DISPLAY_SPR_1D_LAYOUT (1 << 4)
-
-#define DISPLAY_SPR_1D (1 << 4)
-#define DISPLAY_SPR_2D (0 << 4)
-#define DISPLAY_SPR_1D_BMP (4 << 4)
-#define DISPLAY_SPR_2D_BMP_128 (0 << 4)
-#define DISPLAY_SPR_2D_BMP_256 (2 << 4)
-
-
-#define DISPLAY_SPR_1D_SIZE_32 (0 << 20)
-#define DISPLAY_SPR_1D_SIZE_64 (1 << 20)
-#define DISPLAY_SPR_1D_SIZE_128 (2 << 20)
-#define DISPLAY_SPR_1D_SIZE_256 (3 << 20)
-#define DISPLAY_SPR_1D_BMP_SIZE_128 (0 << 22)
-#define DISPLAY_SPR_1D_BMP_SIZE_256 (1 << 22)
-
-
-#define DISPLAY_SPR_EXT_PALETTE (1 << 31)
-#define DISPLAY_BG_EXT_PALETTE (1 << 30)
-
-#define DISPLAY_SCREEN_OFF (1 << 7)
-
-// The next two defines only apply to MAIN 2d engine
-// In tile modes, this is multiplied by 64KB and added to BG_TILE_BASE
-// In all bitmap modes, it is not used.
-#define DISPLAY_CHAR_BASE(n) (((n)&7)<<24)
-
-// In tile modes, this is multiplied by 64KB and added to BG_MAP_BASE
-// In bitmap modes, this is multiplied by 64KB and added to BG_BMP_BASE
-// In large bitmap modes, this is not used
-#define DISPLAY_SCREEN_BASE(n) (((n)&7)<<27)
-
-static inline
-void videoSetMode( uint32 mode) { DISPLAY_CR = mode; }
-static inline
-void videoSetModeSub( uint32 mode) { SUB_DISPLAY_CR = mode; }
-
-#define BRIGHTNESS (*(vuint16*)0x0400006C)
-#define SUB_BRIGHTNESS (*(vuint16*)0x0400106C)
-
-#define BGCTRL ((vuint16*)0x04000008)
-#define BG0_CR (*(vuint16*)0x04000008)
-#define BG1_CR (*(vuint16*)0x0400000A)
-#define BG2_CR (*(vuint16*)0x0400000C)
-#define BG3_CR (*(vuint16*)0x0400000E)
-
-#define BGCTRL_SUB ((vuint16*)0x04001008)
-#define SUB_BG0_CR (*(vuint16*)0x04001008)
-#define SUB_BG1_CR (*(vuint16*)0x0400100A)
-#define SUB_BG2_CR (*(vuint16*)0x0400100C)
-#define SUB_BG3_CR (*(vuint16*)0x0400100E)
-
-#define BG_256_COLOR (BIT(7))
-#define BG_16_COLOR (0)
-
-#define BG_MOSAIC_ON (BIT(6))
-#define BG_MOSAIC_OFF (0)
-
-#define BG_PRIORITY(n) (n)
-#define BG_PRIORITY_0 (0)
-#define BG_PRIORITY_1 (1)
-#define BG_PRIORITY_2 (2)
-#define BG_PRIORITY_3 (3)
-
-#define BG_TILE_BASE(base) ((base) << 2)
-#define BG_MAP_BASE(base) ((base) << 8)
-#define BG_BMP_BASE(base) ((base) << 8)
-
-#define BG_MAP_RAM(base) (((base)*0x800) + 0x06000000)
-#define BG_MAP_RAM_SUB(base) (((base)*0x800) + 0x06200000)
-
-#define BG_TILE_RAM(base) (((base)*0x4000) + 0x06000000)
-#define BG_TILE_RAM_SUB(base) (((base)*0x4000) + 0x06200000)
-
-#define BG_BMP_RAM(base) (((base)*0x4000) + 0x06000000)
-#define BG_BMP_RAM_SUB(base) (((base)*0x4000) + 0x06200000)
-
-#define BG_WRAP_OFF (0)
-#define BG_WRAP_ON (1 << 13)
-
-#define BG_32x32 (0 << 14)
-#define BG_64x32 (1 << 14)
-#define BG_32x64 (2 << 14)
-#define BG_64x64 (3 << 14)
-
-#define BG_RS_16x16 (0 << 14)
-#define BG_RS_32x32 (1 << 14)
-#define BG_RS_64x64 (2 << 14)
-#define BG_RS_128x128 (3 << 14)
-
-#define BG_BMP8_128x128 (BG_RS_16x16 | BG_256_COLOR)
-#define BG_BMP8_256x256 (BG_RS_32x32 | BG_256_COLOR)
-#define BG_BMP8_512x256 (BG_RS_64x64 | BG_256_COLOR)
-#define BG_BMP8_512x512 (BG_RS_128x128 | BG_256_COLOR)
-#define BG_BMP8_1024x512 BIT(14)
-#define BG_BMP8_512x1024 0
-
-#define BG_BMP16_128x128 (BG_RS_16x16 | BG_256_COLOR | BIT(2))
-#define BG_BMP16_256x256 (BG_RS_32x32 | BG_256_COLOR | BIT(2))
-#define BG_BMP16_512x256 (BG_RS_64x64 | BG_256_COLOR | BIT(2))
-#define BG_BMP16_512x512 (BG_RS_128x128 | BG_256_COLOR | BIT(2))
-
-#define BG_PALETTE_SLOT0 0
-#define BG_PALETTE_SLOT1 0
-#define BG_PALETTE_SLOT2 BIT(13)
-#define BG_PALETTE_SLOT3 BIT(13)
-
-typedef struct {
- u16 x;
- u16 y;
-} bg_scroll;
-
-typedef struct {
- u16 xdx;
- u16 xdy;
- u16 ydx;
- u16 ydy;
- u32 centerX;
- u32 centerY;
-} bg_rotation;
-
-typedef struct {
- u16 control[4];
- bg_scroll scroll[4];
- bg_rotation bg2_rotation;
- bg_rotation bg3_rotation;
-} bg_attribute;
-
-#define BACKGROUND (*((bg_attribute *)0x04000008))
-#define BACKGROUND_SUB (*((bg_attribute *)0x04001008))
-
-#define BG_OFFSET ((bg_scroll *)(0x04000010))
-
-#define BG0_X0 (*(vuint16*)0x04000010)
-#define BG0_Y0 (*(vuint16*)0x04000012)
-#define BG1_X0 (*(vuint16*)0x04000014)
-#define BG1_Y0 (*(vuint16*)0x04000016)
-#define BG2_X0 (*(vuint16*)0x04000018)
-#define BG2_Y0 (*(vuint16*)0x0400001A)
-#define BG3_X0 (*(vuint16*)0x0400001C)
-#define BG3_Y0 (*(vuint16*)0x0400001E)
-
-#define BG2_XDX (*(vuint16*)0x04000020)
-#define BG2_XDY (*(vuint16*)0x04000022)
-#define BG2_YDX (*(vuint16*)0x04000024)
-#define BG2_YDY (*(vuint16*)0x04000026)
-#define BG2_CX (*(vuint32*)0x04000028)
-#define BG2_CY (*(vuint32*)0x0400002C)
-
-#define BG3_XDX (*(vuint16*)0x04000030)
-#define BG3_XDY (*(vuint16*)0x04000032)
-#define BG3_YDX (*(vuint16*)0x04000034)
-#define BG3_YDY (*(vuint16*)0x04000036)
-#define BG3_CX (*(vuint32*)0x04000038)
-#define BG3_CY (*(vuint32*)0x0400003C)
-
-#define SUB_BG0_X0 (*(vuint16*)0x04001010)
-#define SUB_BG0_Y0 (*(vuint16*)0x04001012)
-#define SUB_BG1_X0 (*(vuint16*)0x04001014)
-#define SUB_BG1_Y0 (*(vuint16*)0x04001016)
-#define SUB_BG2_X0 (*(vuint16*)0x04001018)
-#define SUB_BG2_Y0 (*(vuint16*)0x0400101A)
-#define SUB_BG3_X0 (*(vuint16*)0x0400101C)
-#define SUB_BG3_Y0 (*(vuint16*)0x0400101E)
-
-#define SUB_BG2_XDX (*(vuint16*)0x04001020)
-#define SUB_BG2_XDY (*(vuint16*)0x04001022)
-#define SUB_BG2_YDX (*(vuint16*)0x04001024)
-#define SUB_BG2_YDY (*(vuint16*)0x04001026)
-#define SUB_BG2_CX (*(vuint32*)0x04001028)
-#define SUB_BG2_CY (*(vuint32*)0x0400102C)
-
-#define SUB_BG3_XDX (*(vuint16*)0x04001030)
-#define SUB_BG3_XDY (*(vuint16*)0x04001032)
-#define SUB_BG3_YDX (*(vuint16*)0x04001034)
-#define SUB_BG3_YDY (*(vuint16*)0x04001036)
-#define SUB_BG3_CX (*(vuint32*)0x04001038)
-#define SUB_BG3_CY (*(vuint32*)0x0400103C)
-
-// Window 0
-#define WIN0_X0 (*(vuint8*)0x04000041)
-#define WIN0_X1 (*(vuint8*)0x04000040)
-#define WIN0_Y0 (*(vuint8*)0x04000045)
-#define WIN0_Y1 (*(vuint8*)0x04000044)
-
-// Window 1
-#define WIN1_X0 (*(vuint8*)0x04000042)
-#define WIN1_X1 (*(vuint8*)0x04000043)
-#define WIN1_Y0 (*(vuint8*)0x04000047)
-#define WIN1_Y1 (*(vuint8*)0x04000046)
-
-#define WIN_IN (*(vuint16*)0x04000048)
-#define WIN_OUT (*(vuint16*)0x0400004A)
-
-// Window 0
-#define SUB_WIN0_X0 (*(vuint8*)0x04001041)
-#define SUB_WIN0_X1 (*(vuint8*)0x04001040)
-#define SUB_WIN0_Y0 (*(vuint8*)0x04001045)
-#define SUB_WIN0_Y1 (*(vuint8*)0x04001044)
-
-// Window 1
-#define SUB_WIN1_X0 (*(vuint8*)0x04001042)
-#define SUB_WIN1_X1 (*(vuint8*)0x04001043)
-#define SUB_WIN1_Y0 (*(vuint8*)0x04001047)
-#define SUB_WIN1_Y1 (*(vuint8*)0x04001046)
-
-#define SUB_WIN_IN (*(vuint16*)0x04001048)
-#define SUB_WIN_OUT (*(vuint16*)0x0400104A)
-
-#define MOSAIC_CR (*(vuint16*)0x0400004C)
-#define SUB_MOSAIC_CR (*(vuint16*)0x0400104C)
-
-#define BLEND_CR (*(vuint16*)0x04000050)
-#define BLEND_AB (*(vuint16*)0x04000052)
-#define BLEND_Y (*(vuint16*)0x04000054)
-
-#define SUB_BLEND_CR (*(vuint16*)0x04001050)
-#define SUB_BLEND_AB (*(vuint16*)0x04001052)
-#define SUB_BLEND_Y (*(vuint16*)0x04001054)
-
-#define BLEND_NONE (0<<6)
-#define BLEND_ALPHA (1<<6)
-#define BLEND_FADE_WHITE (2<<6)
-#define BLEND_FADE_BLACK (3<<6)
-
-#define BLEND_SRC_BG0 (1<<0)
-#define BLEND_SRC_BG1 (1<<1)
-#define BLEND_SRC_BG2 (1<<2)
-#define BLEND_SRC_BG3 (1<<3)
-#define BLEND_SRC_SPRITE (1<<4)
-#define BLEND_SRC_BACKDROP (1<<5)
-
-#define BLEND_DST_BG0 (1<<8)
-#define BLEND_DST_BG1 (1<<9)
-#define BLEND_DST_BG2 (1<<10)
-#define BLEND_DST_BG3 (1<<11)
-#define BLEND_DST_SPRITE (1<<12)
-#define BLEND_DST_BACKDROP (1<<13)
-
-// Display capture control
-
-#define REG_DISPCAPCNT (*(vuint32*)0x04000064)
-#define REG_ DISP_MMEM_FIFO (*(vuint32*)0x04000068)
-
-#define DCAP_ENABLE BIT(31)
-#define DCAP_MODE(n) (((n) & 3) << 29)
-#define DCAP_DST(n) (((n) & 3) << 26)
-#define DCAP_SRC(n) (((n) & 3) << 24)
-#define DCAP_SIZE(n) (((n) & 3) << 20)
-#define DCAP_OFFSET(n) (((n) & 3) << 18)
-#define DCAP_BANK(n) (((n) & 3) << 16)
-#define DCAP_B(n) (((n) & 0x1F) << 8)
-#define DCAP_A(n) (((n) & 0x1F) << 0)
-
-
-// 3D core control
-
-#define GFX_CONTROL (*(vuint16*) 0x04000060)
-
-#define GFX_FIFO (*(vuint32*) 0x04000400)
-#define GFX_STATUS (*(vuint32*) 0x04000600)
-#define GFX_COLOR (*(vuint32*) 0x04000480)
-
-#define GFX_VERTEX10 (*(vuint32*) 0x04000490)
-#define GFX_VERTEX_XY (*(vuint32*) 0x04000494)
-#define GFX_VERTEX_XZ (*(vuint32*) 0x04000498)
-#define GFX_VERTEX_YZ (*(vuint32*) 0x0400049C)
-#define GFX_VERTEX_DIFF (*(vuint32*) 0x040004A0)
-
-#define GFX_VERTEX16 (*(vuint32*) 0x0400048C)
-#define GFX_TEX_COORD (*(vuint32*) 0x04000488)
-#define GFX_TEX_FORMAT (*(vuint32*) 0x040004A8)
-#define GFX_PAL_FORMAT (*(vuint32*) 0x040004AC)
-
-#define GFX_CLEAR_COLOR (*(vuint32*) 0x04000350)
-#define GFX_CLEAR_DEPTH (*(vuint16*) 0x04000354)
-
-#define GFX_LIGHT_VECTOR (*(vuint32*) 0x040004C8)
-#define GFX_LIGHT_COLOR (*(vuint32*) 0x040004CC)
-#define GFX_NORMAL (*(vuint32*) 0x04000484)
-
-#define GFX_DIFFUSE_AMBIENT (*(vuint32*) 0x040004C0)
-#define GFX_SPECULAR_EMISSION (*(vuint32*) 0x040004C4)
-#define GFX_SHININESS (*(vuint32*) 0x040004D0)
-
-#define GFX_POLY_FORMAT (*(vuint32*) 0x040004A4)
-#define GFX_ALPHA_TEST (*(vuint16*) 0x04000340)
-
-#define GFX_BEGIN (*(vuint32*) 0x04000500)
-#define GFX_END (*(vuint32*) 0x04000504)
-#define GFX_FLUSH (*(vuint32*) 0x04000540)
-#define GFX_VIEWPORT (*(vuint32*) 0x04000580)
-#define GFX_TOON_TABLE ((vuint16*) 0x04000380)
-#define GFX_EDGE_TABLE ((vuint16*) 0x04000330)
-#define GFX_FOG_COLOR (*(vuint32*) 0x04000358)
-#define GFX_FOG_OFFSET (*(vuint32*) 0x0400035C)
-#define GFX_FOG_TABLE ((vuint8*) 0x04000360)
-#define GFX_BOX_TEST (*(vint32*) 0x040005C0)
-#define GFX_POS_TEST (*(vuint32*) 0x040005C4)
-#define GFX_POS_RESULT ((vint32*) 0x04000620)
-
-#define GFX_BUSY (GFX_STATUS & BIT(27))
-
-#define GFX_VERTEX_RAM_USAGE (*(uint16*) 0x04000606)
-#define GFX_POLYGON_RAM_USAGE (*(uint16*) 0x04000604)
-
-#define GFX_CUTOFF_DEPTH (*(uint16*)0x04000610)
-
-// Matrix processor control
-
-#define MATRIX_CONTROL (*(vuint32*)0x04000440)
-#define MATRIX_PUSH (*(vuint32*)0x04000444)
-#define MATRIX_POP (*(vuint32*)0x04000448)
-#define MATRIX_SCALE (*(vint32*) 0x0400046C)
-#define MATRIX_TRANSLATE (*(vint32*) 0x04000470)
-#define MATRIX_RESTORE (*(vuint32*)0x04000450)
-#define MATRIX_STORE (*(vuint32*)0x0400044C)
-#define MATRIX_IDENTITY (*(vuint32*)0x04000454)
-#define MATRIX_LOAD4x4 (*(vint32*) 0x04000458)
-#define MATRIX_LOAD4x3 (*(vint32*) 0x0400045C)
-#define MATRIX_MULT4x4 (*(vint32*) 0x04000460)
-#define MATRIX_MULT4x3 (*(vint32*) 0x04000464)
-#define MATRIX_MULT3x3 (*(vint32*) 0x04000468)
-
-//matrix operation results
-#define MATRIX_READ_CLIP ((vint32*) (0x04000640))
-#define MATRIX_READ_VECTOR ((vint32*) (0x04000680))
-#define POINT_RESULT ((vint32*) (0x04000620))
-#define VECTOR_RESULT ((vuint16*)(0x04000630))
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ Video registers and defines
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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.
+
+---------------------------------------------------------------------------------*/
+
+#ifndef VIDEO_ARM9_INCLUDE
+#define VIDEO_ARM9_INCLUDE
+
+
+#ifndef ARM9
+#error Video is only available on the ARM9
+#endif
+
+#include <nds/jtypes.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// macro creates a 15 bit color from 3x5 bit components
+#define RGB15(r,g,b) ((r)|((g)<<5)|((b)<<10))
+#define RGB5(r,g,b) ((r)|((g)<<5)|((b)<<10))
+#define RGB8(r,g,b) (((r)>>3)|(((g)>>3)<<5)|(((b)>>3)<<10))
+
+
+#define SCREEN_HEIGHT 192
+#define SCREEN_WIDTH 256
+// Vram Control
+#define VRAM_CR (*(vuint32*)0x04000240)
+#define VRAM_A_CR (*(vuint8*)0x04000240)
+#define VRAM_B_CR (*(vuint8*)0x04000241)
+#define VRAM_C_CR (*(vuint8*)0x04000242)
+#define VRAM_D_CR (*(vuint8*)0x04000243)
+#define VRAM_E_CR (*(vuint8*)0x04000244)
+#define VRAM_F_CR (*(vuint8*)0x04000245)
+#define VRAM_G_CR (*(vuint8*)0x04000246)
+#define WRAM_CR (*(vuint8*)0x04000247)
+#define VRAM_H_CR (*(vuint8*)0x04000248)
+#define VRAM_I_CR (*(vuint8*)0x04000249)
+
+#define VRAM_ENABLE (1<<7)
+
+#define VRAM_OFFSET(n) ((n)<<3)
+
+
+typedef enum {
+ VRAM_A_LCD = 0,
+ VRAM_A_MAIN_BG = 1,
+ VRAM_A_MAIN_BG_0x06000000 = 1 | VRAM_OFFSET(0),
+ VRAM_A_MAIN_BG_0x06020000 = 1 | VRAM_OFFSET(1),
+ VRAM_A_MAIN_BG_0x06040000 = 1 | VRAM_OFFSET(2),
+ VRAM_A_MAIN_BG_0x06060000 = 1 | VRAM_OFFSET(3),
+ VRAM_A_MAIN_SPRITE = 2,
+ VRAM_A_MAIN_SPRITE_0x06400000 = 2,
+ VRAM_A_MAIN_SPRITE_0x06420000 = 2 | VRAM_OFFSET(1),
+ VRAM_A_TEXTURE = 3,
+ VRAM_A_TEXTURE_SLOT0 = 3 | VRAM_OFFSET(0),
+ VRAM_A_TEXTURE_SLOT1 = 3 | VRAM_OFFSET(1),
+ VRAM_A_TEXTURE_SLOT2 = 3 | VRAM_OFFSET(2),
+ VRAM_A_TEXTURE_SLOT3 = 3 | VRAM_OFFSET(3)
+} VRAM_A_TYPE;
+
+typedef enum {
+ VRAM_B_LCD = 0,
+ VRAM_B_MAIN_BG = 1 | VRAM_OFFSET(1),
+ VRAM_B_MAIN_BG_0x06000000 = 1 | VRAM_OFFSET(0),
+ VRAM_B_MAIN_BG_0x06020000 = 1 | VRAM_OFFSET(1),
+ VRAM_B_MAIN_BG_0x06040000 = 1 | VRAM_OFFSET(2),
+ VRAM_B_MAIN_BG_0x06060000 = 1 | VRAM_OFFSET(3),
+ VRAM_B_MAIN_SPRITE = 2 | VRAM_OFFSET(1),
+ VRAM_B_MAIN_SPRITE_0x06400000 = 2,
+ VRAM_B_MAIN_SPRITE_0x06420000 = 2 | VRAM_OFFSET(1),
+ VRAM_B_TEXTURE = 3 | VRAM_OFFSET(1),
+ VRAM_B_TEXTURE_SLOT0 = 3 | VRAM_OFFSET(0),
+ VRAM_B_TEXTURE_SLOT1 = 3 | VRAM_OFFSET(1),
+ VRAM_B_TEXTURE_SLOT2 = 3 | VRAM_OFFSET(2),
+ VRAM_B_TEXTURE_SLOT3 = 3 | VRAM_OFFSET(3)
+} VRAM_B_TYPE;
+
+typedef enum {
+ VRAM_C_LCD = 0,
+ VRAM_C_MAIN_BG = 1 | VRAM_OFFSET(2),
+ VRAM_C_MAIN_BG_0x06000000 = 1 | VRAM_OFFSET(0),
+ VRAM_C_MAIN_BG_0x06020000 = 1 | VRAM_OFFSET(1),
+ VRAM_C_MAIN_BG_0x06040000 = 1 | VRAM_OFFSET(2),
+ VRAM_C_MAIN_BG_0x06060000 = 1 | VRAM_OFFSET(3),
+ VRAM_C_ARM7 = 2,
+ VRAM_C_ARM7_0x06000000 = 2,
+ VRAM_C_ARM7_0x06020000 = 2 | VRAM_OFFSET(1),
+ VRAM_C_SUB_BG = 4,
+ VRAM_C_SUB_BG_0x06200000 = 4 | VRAM_OFFSET(0),
+ VRAM_C_SUB_BG_0x06220000 = 4 | VRAM_OFFSET(1),
+ VRAM_C_SUB_BG_0x06240000 = 4 | VRAM_OFFSET(2),
+ VRAM_C_SUB_BG_0x06260000 = 4 | VRAM_OFFSET(3),
+ VRAM_C_TEXTURE = 3 | VRAM_OFFSET(2),
+ VRAM_C_TEXTURE_SLOT0 = 3 | VRAM_OFFSET(0),
+ VRAM_C_TEXTURE_SLOT1 = 3 | VRAM_OFFSET(1),
+ VRAM_C_TEXTURE_SLOT2 = 3 | VRAM_OFFSET(2),
+ VRAM_C_TEXTURE_SLOT3 = 3 | VRAM_OFFSET(3)
+} VRAM_C_TYPE;
+
+typedef enum {
+ VRAM_D_LCD = 0,
+ VRAM_D_MAIN_BG = 1 | VRAM_OFFSET(3),
+ VRAM_D_MAIN_BG_0x06000000 = 1 | VRAM_OFFSET(0),
+ VRAM_D_MAIN_BG_0x06020000 = 1 | VRAM_OFFSET(1),
+ VRAM_D_MAIN_BG_0x06040000 = 1 | VRAM_OFFSET(2),
+ VRAM_D_MAIN_BG_0x06060000 = 1 | VRAM_OFFSET(3),
+ VRAM_D_ARM7 = 2 | VRAM_OFFSET(1),
+ VRAM_D_ARM7_0x06000000 = 2,
+ VRAM_D_ARM7_0x06020000 = 2 | VRAM_OFFSET(1),
+ VRAM_D_SUB_SPRITE = 4,
+ VRAM_D_TEXTURE = 3 | VRAM_OFFSET(3),
+ VRAM_D_TEXTURE_SLOT0 = 3 | VRAM_OFFSET(0),
+ VRAM_D_TEXTURE_SLOT1 = 3 | VRAM_OFFSET(1),
+ VRAM_D_TEXTURE_SLOT2 = 3 | VRAM_OFFSET(2),
+ VRAM_D_TEXTURE_SLOT3 = 3 | VRAM_OFFSET(3)
+} VRAM_D_TYPE;
+
+typedef enum {
+ VRAM_E_LCD = 0,
+ VRAM_E_MAIN_BG = 1,
+ VRAM_E_MAIN_SPRITE = 2,
+ VRAM_E_TEX_PALETTE = 3,
+ VRAM_E_BG_EXT_PALETTE = 4,
+ VRAM_E_OBJ_EXT_PALETTE = 5,
+} VRAM_E_TYPE;
+
+typedef enum {
+ VRAM_F_LCD = 0,
+ VRAM_F_MAIN_BG = 1,
+ VRAM_F_MAIN_SPRITE = 2,
+ VRAM_F_MAIN_SPRITE_0x06000000 = 2,
+ VRAM_F_MAIN_SPRITE_0x06004000 = 2 | VRAM_OFFSET(1),
+ VRAM_F_MAIN_SPRITE_0x06010000 = 2 | VRAM_OFFSET(2),
+ VRAM_F_MAIN_SPRITE_0x06014000 = 2 | VRAM_OFFSET(3),
+ VRAM_F_TEX_PALETTE = 3,
+ VRAM_F_BG_EXT_PALETTE = 4,
+ VRAM_F_OBJ_EXT_PALETTE = 5,
+} VRAM_F_TYPE;
+
+typedef enum {
+ VRAM_G_LCD = 0,
+ VRAM_G_MAIN_BG = 1,
+ VRAM_G_MAIN_SPRITE = 2,
+ VRAM_G_MAIN_SPRITE_0x06000000 = 2,
+ VRAM_G_MAIN_SPRITE_0x06004000 = 2 | VRAM_OFFSET(1),
+ VRAM_G_MAIN_SPRITE_0x06010000 = 2 | VRAM_OFFSET(2),
+ VRAM_G_MAIN_SPRITE_0x06014000 = 2 | VRAM_OFFSET(3),
+ VRAM_G_TEX_PALETTE = 3,
+ VRAM_G_BG_EXT_PALETTE = 4,
+ VRAM_G_OBJ_EXT_PALETTE = 5,
+} VRAM_G_TYPE;
+
+typedef enum {
+ VRAM_H_LCD = 0,
+ VRAM_H_SUB_BG = 1,
+ VRAM_H_SUB_BG_EXT_PALETTE = 2,
+} VRAM_H_TYPE;
+
+typedef enum {
+ VRAM_I_LCD = 0,
+ VRAM_I_SUB_BG = 1,
+ VRAM_I_SUB_SPRITE = 2,
+ VRAM_I_SUB_SPRITE_EXT_PALETTE = 3,
+}VRAM_I_TYPE;
+
+
+typedef u16 _palette[256];
+typedef _palette _ext_palette[16];
+
+#define VRAM_E_EXT_PALETTE ((_ext_palette *)VRAM_E)
+#define VRAM_F_EXT_PALETTE ((_ext_palette *)VRAM_F)
+#define VRAM_G_EXT_PALETTE ((_ext_palette *)VRAM_G)
+#define VRAM_H_EXT_PALETTE ((_ext_palette *)VRAM_H)
+
+
+uint32 vramSetMainBanks(VRAM_A_TYPE a, VRAM_B_TYPE b, VRAM_C_TYPE c, VRAM_D_TYPE d);
+void vramRestoreMainBanks(uint32 vramTemp);
+
+void vramSetBankA(VRAM_A_TYPE a);
+void vramSetBankB(VRAM_B_TYPE b);
+void vramSetBankC(VRAM_C_TYPE c);
+void vramSetBankD(VRAM_D_TYPE d);
+void vramSetBankE(VRAM_E_TYPE e);
+void vramSetBankF(VRAM_F_TYPE f);
+void vramSetBankG(VRAM_G_TYPE g);
+void vramSetBankH(VRAM_H_TYPE h);
+void vramSetBankI(VRAM_I_TYPE i);
+
+
+// Display control registers
+#define DISPLAY_CR (*(vuint32*)0x04000000)
+#define SUB_DISPLAY_CR (*(vuint32*)0x04001000)
+
+#define MODE_0_2D 0x10000
+#define MODE_1_2D 0x10001
+#define MODE_2_2D 0x10002
+#define MODE_3_2D 0x10003
+#define MODE_4_2D 0x10004
+#define MODE_5_2D 0x10005
+
+// main display only
+#define MODE_6_2D 0x10006
+#define MODE_FIFO (3<<16)
+
+#define ENABLE_3D (1<<3)
+
+#define DISPLAY_BG0_ACTIVE (1 << 8)
+#define DISPLAY_BG1_ACTIVE (1 << 9)
+#define DISPLAY_BG2_ACTIVE (1 << 10)
+#define DISPLAY_BG3_ACTIVE (1 << 11)
+#define DISPLAY_SPR_ACTIVE (1 << 12)
+#define DISPLAY_WIN0_ON (1 << 13)
+#define DISPLAY_WIN1_ON (1 << 14)
+#define DISPLAY_SPR_WIN_ON (1 << 15)
+
+
+// Main display only
+#define MODE_0_3D (MODE_0_2D | DISPLAY_BG0_ACTIVE | ENABLE_3D)
+#define MODE_1_3D (MODE_1_2D | DISPLAY_BG0_ACTIVE | ENABLE_3D)
+#define MODE_2_3D (MODE_2_2D | DISPLAY_BG0_ACTIVE | ENABLE_3D)
+#define MODE_3_3D (MODE_3_2D | DISPLAY_BG0_ACTIVE | ENABLE_3D)
+#define MODE_4_3D (MODE_4_2D | DISPLAY_BG0_ACTIVE | ENABLE_3D)
+#define MODE_5_3D (MODE_5_2D | DISPLAY_BG0_ACTIVE | ENABLE_3D)
+#define MODE_6_3D (MODE_6_2D | DISPLAY_BG0_ACTIVE | ENABLE_3D)
+
+#define MODE_FB0 (0x00020000)
+#define MODE_FB1 (0x00060000)
+#define MODE_FB2 (0x000A0000)
+#define MODE_FB3 (0x000E0000)
+
+#define DISPLAY_SPR_HBLANK (1 << 23)
+
+#define DISPLAY_SPR_1D_LAYOUT (1 << 4)
+
+#define DISPLAY_SPR_1D (1 << 4)
+#define DISPLAY_SPR_2D (0 << 4)
+#define DISPLAY_SPR_1D_BMP (4 << 4)
+#define DISPLAY_SPR_2D_BMP_128 (0 << 4)
+#define DISPLAY_SPR_2D_BMP_256 (2 << 4)
+
+
+#define DISPLAY_SPR_1D_SIZE_32 (0 << 20)
+#define DISPLAY_SPR_1D_SIZE_64 (1 << 20)
+#define DISPLAY_SPR_1D_SIZE_128 (2 << 20)
+#define DISPLAY_SPR_1D_SIZE_256 (3 << 20)
+#define DISPLAY_SPR_1D_BMP_SIZE_128 (0 << 22)
+#define DISPLAY_SPR_1D_BMP_SIZE_256 (1 << 22)
+
+
+#define DISPLAY_SPR_EXT_PALETTE (1 << 31)
+#define DISPLAY_BG_EXT_PALETTE (1 << 30)
+
+#define DISPLAY_SCREEN_OFF (1 << 7)
+
+// The next two defines only apply to MAIN 2d engine
+// In tile modes, this is multiplied by 64KB and added to BG_TILE_BASE
+// In all bitmap modes, it is not used.
+#define DISPLAY_CHAR_BASE(n) (((n)&7)<<24)
+
+// In tile modes, this is multiplied by 64KB and added to BG_MAP_BASE
+// In bitmap modes, this is multiplied by 64KB and added to BG_BMP_BASE
+// In large bitmap modes, this is not used
+#define DISPLAY_SCREEN_BASE(n) (((n)&7)<<27)
+
+static inline
+void videoSetMode( uint32 mode) { DISPLAY_CR = mode; }
+static inline
+void videoSetModeSub( uint32 mode) { SUB_DISPLAY_CR = mode; }
+
+#define BRIGHTNESS (*(vuint16*)0x0400006C)
+#define SUB_BRIGHTNESS (*(vuint16*)0x0400106C)
+
+#define BGCTRL ((vuint16*)0x04000008)
+#define BG0_CR (*(vuint16*)0x04000008)
+#define BG1_CR (*(vuint16*)0x0400000A)
+#define BG2_CR (*(vuint16*)0x0400000C)
+#define BG3_CR (*(vuint16*)0x0400000E)
+
+#define BGCTRL_SUB ((vuint16*)0x04001008)
+#define SUB_BG0_CR (*(vuint16*)0x04001008)
+#define SUB_BG1_CR (*(vuint16*)0x0400100A)
+#define SUB_BG2_CR (*(vuint16*)0x0400100C)
+#define SUB_BG3_CR (*(vuint16*)0x0400100E)
+
+#define BG_256_COLOR (BIT(7))
+#define BG_16_COLOR (0)
+
+#define BG_MOSAIC_ON (BIT(6))
+#define BG_MOSAIC_OFF (0)
+
+#define BG_PRIORITY(n) (n)
+#define BG_PRIORITY_0 (0)
+#define BG_PRIORITY_1 (1)
+#define BG_PRIORITY_2 (2)
+#define BG_PRIORITY_3 (3)
+
+#define BG_TILE_BASE(base) ((base) << 2)
+#define BG_MAP_BASE(base) ((base) << 8)
+#define BG_BMP_BASE(base) ((base) << 8)
+
+#define BG_MAP_RAM(base) (((base)*0x800) + 0x06000000)
+#define BG_MAP_RAM_SUB(base) (((base)*0x800) + 0x06200000)
+
+#define BG_TILE_RAM(base) (((base)*0x4000) + 0x06000000)
+#define BG_TILE_RAM_SUB(base) (((base)*0x4000) + 0x06200000)
+
+#define BG_BMP_RAM(base) (((base)*0x4000) + 0x06000000)
+#define BG_BMP_RAM_SUB(base) (((base)*0x4000) + 0x06200000)
+
+#define BG_WRAP_OFF (0)
+#define BG_WRAP_ON (1 << 13)
+
+#define BG_32x32 (0 << 14)
+#define BG_64x32 (1 << 14)
+#define BG_32x64 (2 << 14)
+#define BG_64x64 (3 << 14)
+
+#define BG_RS_16x16 (0 << 14)
+#define BG_RS_32x32 (1 << 14)
+#define BG_RS_64x64 (2 << 14)
+#define BG_RS_128x128 (3 << 14)
+
+#define BG_BMP8_128x128 (BG_RS_16x16 | BG_256_COLOR)
+#define BG_BMP8_256x256 (BG_RS_32x32 | BG_256_COLOR)
+#define BG_BMP8_512x256 (BG_RS_64x64 | BG_256_COLOR)
+#define BG_BMP8_512x512 (BG_RS_128x128 | BG_256_COLOR)
+#define BG_BMP8_1024x512 BIT(14)
+#define BG_BMP8_512x1024 0
+
+#define BG_BMP16_128x128 (BG_RS_16x16 | BG_256_COLOR | BIT(2))
+#define BG_BMP16_256x256 (BG_RS_32x32 | BG_256_COLOR | BIT(2))
+#define BG_BMP16_512x256 (BG_RS_64x64 | BG_256_COLOR | BIT(2))
+#define BG_BMP16_512x512 (BG_RS_128x128 | BG_256_COLOR | BIT(2))
+
+#define BG_PALETTE_SLOT0 0
+#define BG_PALETTE_SLOT1 0
+#define BG_PALETTE_SLOT2 BIT(13)
+#define BG_PALETTE_SLOT3 BIT(13)
+
+typedef struct {
+ u16 x;
+ u16 y;
+} bg_scroll;
+
+typedef struct {
+ u16 xdx;
+ u16 xdy;
+ u16 ydx;
+ u16 ydy;
+ u32 centerX;
+ u32 centerY;
+} bg_rotation;
+
+typedef struct {
+ u16 control[4];
+ bg_scroll scroll[4];
+ bg_rotation bg2_rotation;
+ bg_rotation bg3_rotation;
+} bg_attribute;
+
+#define BACKGROUND (*((bg_attribute *)0x04000008))
+#define BACKGROUND_SUB (*((bg_attribute *)0x04001008))
+
+#define BG_OFFSET ((bg_scroll *)(0x04000010))
+
+#define BG0_X0 (*(vuint16*)0x04000010)
+#define BG0_Y0 (*(vuint16*)0x04000012)
+#define BG1_X0 (*(vuint16*)0x04000014)
+#define BG1_Y0 (*(vuint16*)0x04000016)
+#define BG2_X0 (*(vuint16*)0x04000018)
+#define BG2_Y0 (*(vuint16*)0x0400001A)
+#define BG3_X0 (*(vuint16*)0x0400001C)
+#define BG3_Y0 (*(vuint16*)0x0400001E)
+
+#define BG2_XDX (*(vuint16*)0x04000020)
+#define BG2_XDY (*(vuint16*)0x04000022)
+#define BG2_YDX (*(vuint16*)0x04000024)
+#define BG2_YDY (*(vuint16*)0x04000026)
+#define BG2_CX (*(vuint32*)0x04000028)
+#define BG2_CY (*(vuint32*)0x0400002C)
+
+#define BG3_XDX (*(vuint16*)0x04000030)
+#define BG3_XDY (*(vuint16*)0x04000032)
+#define BG3_YDX (*(vuint16*)0x04000034)
+#define BG3_YDY (*(vuint16*)0x04000036)
+#define BG3_CX (*(vuint32*)0x04000038)
+#define BG3_CY (*(vuint32*)0x0400003C)
+
+#define SUB_BG0_X0 (*(vuint16*)0x04001010)
+#define SUB_BG0_Y0 (*(vuint16*)0x04001012)
+#define SUB_BG1_X0 (*(vuint16*)0x04001014)
+#define SUB_BG1_Y0 (*(vuint16*)0x04001016)
+#define SUB_BG2_X0 (*(vuint16*)0x04001018)
+#define SUB_BG2_Y0 (*(vuint16*)0x0400101A)
+#define SUB_BG3_X0 (*(vuint16*)0x0400101C)
+#define SUB_BG3_Y0 (*(vuint16*)0x0400101E)
+
+#define SUB_BG2_XDX (*(vuint16*)0x04001020)
+#define SUB_BG2_XDY (*(vuint16*)0x04001022)
+#define SUB_BG2_YDX (*(vuint16*)0x04001024)
+#define SUB_BG2_YDY (*(vuint16*)0x04001026)
+#define SUB_BG2_CX (*(vuint32*)0x04001028)
+#define SUB_BG2_CY (*(vuint32*)0x0400102C)
+
+#define SUB_BG3_XDX (*(vuint16*)0x04001030)
+#define SUB_BG3_XDY (*(vuint16*)0x04001032)
+#define SUB_BG3_YDX (*(vuint16*)0x04001034)
+#define SUB_BG3_YDY (*(vuint16*)0x04001036)
+#define SUB_BG3_CX (*(vuint32*)0x04001038)
+#define SUB_BG3_CY (*(vuint32*)0x0400103C)
+
+// Window 0
+#define WIN0_X0 (*(vuint8*)0x04000041)
+#define WIN0_X1 (*(vuint8*)0x04000040)
+#define WIN0_Y0 (*(vuint8*)0x04000045)
+#define WIN0_Y1 (*(vuint8*)0x04000044)
+
+// Window 1
+#define WIN1_X0 (*(vuint8*)0x04000042)
+#define WIN1_X1 (*(vuint8*)0x04000043)
+#define WIN1_Y0 (*(vuint8*)0x04000047)
+#define WIN1_Y1 (*(vuint8*)0x04000046)
+
+#define WIN_IN (*(vuint16*)0x04000048)
+#define WIN_OUT (*(vuint16*)0x0400004A)
+
+// Window 0
+#define SUB_WIN0_X0 (*(vuint8*)0x04001041)
+#define SUB_WIN0_X1 (*(vuint8*)0x04001040)
+#define SUB_WIN0_Y0 (*(vuint8*)0x04001045)
+#define SUB_WIN0_Y1 (*(vuint8*)0x04001044)
+
+// Window 1
+#define SUB_WIN1_X0 (*(vuint8*)0x04001042)
+#define SUB_WIN1_X1 (*(vuint8*)0x04001043)
+#define SUB_WIN1_Y0 (*(vuint8*)0x04001047)
+#define SUB_WIN1_Y1 (*(vuint8*)0x04001046)
+
+#define SUB_WIN_IN (*(vuint16*)0x04001048)
+#define SUB_WIN_OUT (*(vuint16*)0x0400104A)
+
+#define MOSAIC_CR (*(vuint16*)0x0400004C)
+#define SUB_MOSAIC_CR (*(vuint16*)0x0400104C)
+
+#define BLEND_CR (*(vuint16*)0x04000050)
+#define BLEND_AB (*(vuint16*)0x04000052)
+#define BLEND_Y (*(vuint16*)0x04000054)
+
+#define SUB_BLEND_CR (*(vuint16*)0x04001050)
+#define SUB_BLEND_AB (*(vuint16*)0x04001052)
+#define SUB_BLEND_Y (*(vuint16*)0x04001054)
+
+#define BLEND_NONE (0<<6)
+#define BLEND_ALPHA (1<<6)
+#define BLEND_FADE_WHITE (2<<6)
+#define BLEND_FADE_BLACK (3<<6)
+
+#define BLEND_SRC_BG0 (1<<0)
+#define BLEND_SRC_BG1 (1<<1)
+#define BLEND_SRC_BG2 (1<<2)
+#define BLEND_SRC_BG3 (1<<3)
+#define BLEND_SRC_SPRITE (1<<4)
+#define BLEND_SRC_BACKDROP (1<<5)
+
+#define BLEND_DST_BG0 (1<<8)
+#define BLEND_DST_BG1 (1<<9)
+#define BLEND_DST_BG2 (1<<10)
+#define BLEND_DST_BG3 (1<<11)
+#define BLEND_DST_SPRITE (1<<12)
+#define BLEND_DST_BACKDROP (1<<13)
+
+// Display capture control
+
+#define REG_DISPCAPCNT (*(vuint32*)0x04000064)
+#define REG_ DISP_MMEM_FIFO (*(vuint32*)0x04000068)
+
+#define DCAP_ENABLE BIT(31)
+#define DCAP_MODE(n) (((n) & 3) << 29)
+#define DCAP_DST(n) (((n) & 3) << 26)
+#define DCAP_SRC(n) (((n) & 3) << 24)
+#define DCAP_SIZE(n) (((n) & 3) << 20)
+#define DCAP_OFFSET(n) (((n) & 3) << 18)
+#define DCAP_BANK(n) (((n) & 3) << 16)
+#define DCAP_B(n) (((n) & 0x1F) << 8)
+#define DCAP_A(n) (((n) & 0x1F) << 0)
+
+
+// 3D core control
+
+#define GFX_CONTROL (*(vuint16*) 0x04000060)
+
+#define GFX_FIFO (*(vuint32*) 0x04000400)
+#define GFX_STATUS (*(vuint32*) 0x04000600)
+#define GFX_COLOR (*(vuint32*) 0x04000480)
+
+#define GFX_VERTEX10 (*(vuint32*) 0x04000490)
+#define GFX_VERTEX_XY (*(vuint32*) 0x04000494)
+#define GFX_VERTEX_XZ (*(vuint32*) 0x04000498)
+#define GFX_VERTEX_YZ (*(vuint32*) 0x0400049C)
+#define GFX_VERTEX_DIFF (*(vuint32*) 0x040004A0)
+
+#define GFX_VERTEX16 (*(vuint32*) 0x0400048C)
+#define GFX_TEX_COORD (*(vuint32*) 0x04000488)
+#define GFX_TEX_FORMAT (*(vuint32*) 0x040004A8)
+#define GFX_PAL_FORMAT (*(vuint32*) 0x040004AC)
+
+#define GFX_CLEAR_COLOR (*(vuint32*) 0x04000350)
+#define GFX_CLEAR_DEPTH (*(vuint16*) 0x04000354)
+
+#define GFX_LIGHT_VECTOR (*(vuint32*) 0x040004C8)
+#define GFX_LIGHT_COLOR (*(vuint32*) 0x040004CC)
+#define GFX_NORMAL (*(vuint32*) 0x04000484)
+
+#define GFX_DIFFUSE_AMBIENT (*(vuint32*) 0x040004C0)
+#define GFX_SPECULAR_EMISSION (*(vuint32*) 0x040004C4)
+#define GFX_SHININESS (*(vuint32*) 0x040004D0)
+
+#define GFX_POLY_FORMAT (*(vuint32*) 0x040004A4)
+#define GFX_ALPHA_TEST (*(vuint16*) 0x04000340)
+
+#define GFX_BEGIN (*(vuint32*) 0x04000500)
+#define GFX_END (*(vuint32*) 0x04000504)
+#define GFX_FLUSH (*(vuint32*) 0x04000540)
+#define GFX_VIEWPORT (*(vuint32*) 0x04000580)
+#define GFX_TOON_TABLE ((vuint16*) 0x04000380)
+#define GFX_EDGE_TABLE ((vuint16*) 0x04000330)
+#define GFX_FOG_COLOR (*(vuint32*) 0x04000358)
+#define GFX_FOG_OFFSET (*(vuint32*) 0x0400035C)
+#define GFX_FOG_TABLE ((vuint8*) 0x04000360)
+#define GFX_BOX_TEST (*(vint32*) 0x040005C0)
+#define GFX_POS_TEST (*(vuint32*) 0x040005C4)
+#define GFX_POS_RESULT ((vint32*) 0x04000620)
+
+#define GFX_BUSY (GFX_STATUS & BIT(27))
+
+#define GFX_VERTEX_RAM_USAGE (*(uint16*) 0x04000606)
+#define GFX_POLYGON_RAM_USAGE (*(uint16*) 0x04000604)
+
+#define GFX_CUTOFF_DEPTH (*(uint16*)0x04000610)
+
+// Matrix processor control
+
+#define MATRIX_CONTROL (*(vuint32*)0x04000440)
+#define MATRIX_PUSH (*(vuint32*)0x04000444)
+#define MATRIX_POP (*(vuint32*)0x04000448)
+#define MATRIX_SCALE (*(vint32*) 0x0400046C)
+#define MATRIX_TRANSLATE (*(vint32*) 0x04000470)
+#define MATRIX_RESTORE (*(vuint32*)0x04000450)
+#define MATRIX_STORE (*(vuint32*)0x0400044C)
+#define MATRIX_IDENTITY (*(vuint32*)0x04000454)
+#define MATRIX_LOAD4x4 (*(vint32*) 0x04000458)
+#define MATRIX_LOAD4x3 (*(vint32*) 0x0400045C)
+#define MATRIX_MULT4x4 (*(vint32*) 0x04000460)
+#define MATRIX_MULT4x3 (*(vint32*) 0x04000464)
+#define MATRIX_MULT3x3 (*(vint32*) 0x04000468)
+
+//matrix operation results
+#define MATRIX_READ_CLIP ((vint32*) (0x04000640))
+#define MATRIX_READ_VECTOR ((vint32*) (0x04000680))
+#define POINT_RESULT ((vint32*) (0x04000620))
+#define VECTOR_RESULT ((vuint16*)(0x04000630))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/videoGL.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/videoGL.h
index c96e89b523..84f16c30b6 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/videoGL.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/videoGL.h
@@ -1,1297 +1,1297 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- videoGL.h -- Video API vaguely similar to OpenGL
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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.
-
-
----------------------------------------------------------------------------------*/
-/*! \file videoGL.h
-\brief openGL (ish) interface to DS 3D hardware.
-*/
-
-#ifndef VIDEOGL_ARM9_INCLUDE
-#define VIDEOGL_ARM9_INCLUDE
-
-//---------------------------------------------------------------------------------
-
-// for some reason doxygen doesn't like "static inline" but is fine with "GL_STATIC_INL"
-#define GL_STATIC_INL static inline
-
-#ifndef ARM9
-#error 3D hardware is only available from the ARM9
-#endif
-
-//---------------------------------------------------------------------------------
-#include <nds/jtypes.h>
-#include <nds/arm9/video.h>
-#include <nds/dma.h>
-#include <nds/memory.h>
-#include <nds/bios.h>
-#include <nds/arm9/math.h>
-#include <nds/arm9/trig_lut.h>
-#include <nds/arm9/cache.h>
-
-/*---------------------------------------------------------------------------------
- lut resolution for trig functions
- (must be power of two and must be the same as LUT resolution)
- in other words dont change unless you also change your LUTs
----------------------------------------------------------------------------------*/
-#define LUT_SIZE (512)
-#define LUT_MASK (0x1FF)
-
-////////////////////////////////////////////////////////////
-// Misc. constants
-////////////////////////////////////////////////////////////
-
-#define MAX_TEXTURES 2048 //this should be enough ! but feel free to change
-
-
-//////////////////////////////////////////////////////////////////////
-// Fixed point / floating point / integer conversion macros
-//////////////////////////////////////////////////////////////////////
-
-typedef uint16 fixed12d3; /*!< \brief Used for depth (glClearDepth, glCutoffDepth) */
-
-#define int_to_12d3(n) ((n) << 3) /*!< \brief convert int to fixed12d3 */
-#define float_to_12d3(n) ((fixed12d3)((n) * (1 << 3))) /*!< \brief convert float to fixed12d3 */
-#define GL_MAX_DEPTH 0x7FFF /*!< \brief the maximum value for type fixed12d3 */
-
-//////////////////////////////////////////////////////////////////////
-
-#define inttof32(n) ((n) << 12) /*!< \brief convert int to f32 */
-#define f32toint(n) ((n) >> 12) /*!< \brief convert f32 to int */
-#define floattof32(n) ((int32)((n) * (1 << 12))) /*!< \brief convert float to f32 */
-#define f32tofloat(n) (((float)(n)) / (float)(1<<12)) /*!< \brief convert f32 to float */
-
-typedef short int t16; /*!< \brief text coordinate 12.4 fixed point */
-#define f32tot16(n) ((t16)(n >> 8)) /*!< \brief convert f32 to t16 */
-#define inttot16(n) ((n) << 4) /*!< \brief convert int to t16 */
-#define t16toint(n) ((n) >> 4) /*!< \brief convert t16 to int */
-#define floattot16(n) ((t16)((n) * (1 << 4))) /*!< \brief convert float to t16 */
-#define TEXTURE_PACK(u,v) ((u & 0xFFFF) | ((v) << 16)) /*!< \brief Pack 2 t16 texture coordinate values into a 32bit value */
-
-typedef short int v16; /*!< \brief vertex 4.12 fixed format */
-#define inttov16(n) ((n) << 12) /*!< \brief convert int to v16 */
-#define f32tov16(n) (n) /*!< \brief f32 to v16 */
-#define v16toint(n) ((n) >> 12) /*!< \brief convert v16 to int */
-#define floattov16(n) ((v16)((n) * (1 << 12))) /*!< \brief convert float to v16 */
-#define VERTEX_PACK(x,y) (((x) & 0xFFFF) | ((y) << 16)) /*!< \brief Pack to v16 values into one 32bit value */
-
-typedef short int v10; /*!< \brief normal .10 fixed point, NOT USED FOR 10bit VERTEXES!!!*/
-#define inttov10(n) ((n) << 9) /*!< \brief convert int to v10 */
-#define f32tov10(n) ((v10)(n >> 3)) /*!< \brief convert f32 to v10 */
-#define v10toint(n) ((n) >> 9) /*!< \brief convert v10 to int */
-#define floattov10(n) ((n>.998) ? 0x1FF : ((v10)((n)*(1<<9)))) /*!< \brief convert float to v10 */
-#define NORMAL_PACK(x,y,z) (((x) & 0x3FF) | (((y) & 0x3FF) << 10) | ((z) << 20)) /*!< \brief Pack 3 v10 normals into a 32bit value */
-
-//////////////////////////////////////////////////////////////////////
-
-typedef unsigned short rgb; /*!< \brief Holds a color value. 1bit alpha, 5bits red, 5bits green, 5bits blue. */
-
-/*! \brief Holds a Matrix of 3x3 */
-typedef struct {
- int32 m[9]; /*!< array that holds matrix */
-} m3x3;
-
-/*! \brief Holds a Matrix of 4x4 */
-typedef struct {
- int32 m[16]; /*!< array that holds matrix */
-} m4x4;
-
-/*! \brief Holds a Matrix of 4x3 */
-typedef struct {
- int32 m[12]; /*!< array that holds matrix */
-} m4x3;
-
-/*! \brief Holds a Vector<BR>related functions: glScalev(), glTranslatev() */
-typedef struct {
- int32 x, y, z;
-} GLvector;
-
-//////////////////////////////////////////////////////////////////////
-
-#define GL_FALSE 0
-#define GL_TRUE 1
-
-/*! \brief Enums selecting polygon draw mode<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices</A><BR>
-related functions: glBegin() */
-typedef enum {
- GL_TRIANGLES = 0, /*!< draw triangles with each 3 vertices defining a triangle */
- GL_QUADS = 1, /*!< draw quads with each 4 vertices defining a quad */
- GL_TRIANGLE_STRIP = 2, /*!< draw triangles with the first triangle defined by 3 vertices, then each additional triangle being defined by one additional vertex */
- GL_QUAD_STRIP = 3, /*!< draw quads with the first quad being defined by 4 vertices, then each additional triangle being defined by 2 vertices. */
- GL_TRIANGLE = 0, /*!< same as GL_TRIANGLES, old non-OpenGL version */
- GL_QUAD = 1 /*!< same as GL_QUADS, old non-OpenGL version */
-} GL_GLBEGIN_ENUM;
-
-/*! \brief Enums selecting matrix mode<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A><BR>
-related functions: glMatrixMode() */
-typedef enum {
- GL_PROJECTION = 0, /*!< used to set the Projection Matrix */
- GL_POSITION = 1, /*!< used to set the Position Matrix */
- GL_MODELVIEW = 2, /*!< used to set the Modelview Matrix */
- GL_TEXTURE = 3 /*!< used to set the Texture Matrix */
-} GL_MATRIX_MODE_ENUM;
-
-/*! \brief Enums for setting up materials<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A><BR>
-related functions: glMaterialf() */
-typedef enum {
- GL_AMBIENT = 0x01, /*!< sets the ambient color for the material. The color when the normal is not facing light*/
- GL_DIFFUSE = 0x02, /*!< sets the diffuse color for the material. The color when the normal is facing light */
- GL_AMBIENT_AND_DIFFUSE = 0x03, /*!< sets the set ambient and diffuse colors for the material; just a two-in-one of the above.*/
- GL_SPECULAR = 0x04, /*!< sets the specular color for the material. The glossy(highlight) color of the polygon */
- GL_SHININESS = 0x08, /*!< sets the shininess color for the material. The color that shines back to the user. I have shiny pants! */
- GL_EMISSION = 0x10 /*!< sets the emission color for the material. bright color that is indepentant of normals and lights*/
-} GL_MATERIALS_ENUM;
-
-/*! \brief Enums for setting how polygons will be displayed<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes</A><BR>
-related functions: glPolyFmt(), glInit(), POLY_ALPHA(), POLY_ID() */
-enum GL_POLY_FORMAT_ENUM {
- POLY_FORMAT_LIGHT0 = (1<<0), /*!< enable light number 0 */
- POLY_FORMAT_LIGHT1 = (1<<1), /*!< enable light number 1 */
- POLY_FORMAT_LIGHT2 = (1<<2), /*!< enable light number 2 */
- POLY_FORMAT_LIGHT3 = (1<<3), /*!< enable light number 3 */
- POLY_MODULATION = (0<<4), /*!< enable modulation shading mode; this is the default */
- POLY_DECAL = (1<<4), /*!< enable decal shading */
- POLY_TOON_HIGHLIGHT = (2<<4), /*!< enable toon/highlight shading mode */
- POLY_SHADOW = (3<<4), /*!< enable shadow shading */
- POLY_CULL_FRONT = (1<<6), /*!< cull front polygons */
- POLY_CULL_BACK = (2<<6), /*!< cull rear polygons */
- POLY_CULL_NONE = (3<<6), /*!< don't cull any polygons */
- POLY_FOG = (1<<15) /*!< enable/disable fog for this polygon */
-};
-
-/*! \brief Enums for size of a texture, specify one for horizontal and one for vertical
-related functions: glTexImage2d(), glTexParameter() */
-enum GL_TEXTURE_SIZE_ENUM {
- TEXTURE_SIZE_8 = 0, /*!< 8 texels */
- TEXTURE_SIZE_16 = 1, /*!< 16 texels */
- TEXTURE_SIZE_32 = 2, /*!< 32 texels */
- TEXTURE_SIZE_64 = 3, /*!< 64 texels */
- TEXTURE_SIZE_128 = 4, /*!< 128 texels */
- TEXTURE_SIZE_256 = 5, /*!< 256 texels */
- TEXTURE_SIZE_512 = 6, /*!< 512 texels */
- TEXTURE_SIZE_1024 = 7 /*!< 1024 texels */
-};
-
-/*! \brief Enums for texture parameters, such as texture wrapping and texture coord stuff<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes</A><BR>
-related functions: glTexImage2d(), glTexParameter() */
-enum GL_TEXTURE_PARAM_ENUM {
- GL_TEXTURE_WRAP_S = (1 << 16), /*!< wrap(repeat) texture on S axis */
- GL_TEXTURE_WRAP_T = (1 << 17), /*!< wrap(repeat) texture on T axis */
- GL_TEXTURE_FLIP_S = (1 << 18), /*!< flip texture on S axis when wrapping */
- GL_TEXTURE_FLIP_T = (1 << 19), /*!< flip texture on T axis when wrapping */
- GL_TEXTURE_COLOR0_TRANSPARENT = (1<<29), /*!< interpret color 0 as clear, same as old GL_TEXTURE_ALPHA_MASK */
- TEXGEN_OFF = (0<<30), /*!< use unmodified texcoord */
- TEXGEN_TEXCOORD = (1<<30), /*!< multiply texcoords by the texture-matrix */
- TEXGEN_NORMAL = (2<<30), /*!< set texcoords equal to normal * texture-matrix, used for spherical reflection mapping */
- TEXGEN_POSITION = (3<<30) /*!< set texcoords equal to vertex * texture-matrix */
-};
-
-/*! \brief Enums for texture formats<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureformats">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureformats</A><BR>
-related functions: glTexImage2d(), glTexParameter() */
-typedef enum {
- GL_RGB32_A3 = 1, /*!< 32 color palette, 3 bits of alpha */
- GL_RGB4 = 2, /*!< 4 color palette */
- GL_RGB16 = 3, /*!< 16 color palette */
- GL_RGB256 = 4, /*!< 256 color palette */
- GL_COMPRESSED = 5, /*!< compressed texture */
- GL_RGB8_A5 = 6, /*!< 8 color palette, 5 bits of alpha */
- GL_RGBA = 7, /*!< 15 bit direct color, 1 bit of alpha */
- GL_RGB = 8 /*!< 15 bit direct color, manually sets alpha bit to 1 */
-} GL_TEXTURE_TYPE_ENUM;
-
-/*! \brief 3D Display Control Register Enums<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A><BR>
-related functions: glEnable(), glDisable(), glInit() */
-enum DISP3DCNT_ENUM {
- GL_TEXTURE_2D = (1<<0), /*!< enable/disable textures on the geometry engine */
- GL_TOON_HIGHLIGHT = (1<<1), /*!< enable = Highlight shading; disable = Toon shading */
- GL_ALPHA_TEST = (1<<2), /*!< whether to use the alpha threshold set in glAlphaFunc() */
- GL_BLEND = (1<<3), /*!< enable/disable alpha blending */
- GL_ANTIALIAS = (1<<4), /*!< nable/disable edge antialiasing; polygons must have different polygon IDs for the effect to work and the rear plane must be clear */
- GL_OUTLINE = (1<<5), /*!< enable/disable edge coloring; the high 3bits of the polygon ID determine the color; glSetOutlineColor() sets the available colors */
- GL_FOG_ONLY_ALPHA = (1<<6), /*!< enable = fade into background?; disable = don't fade? */
- GL_FOG = (1<<7), /*!< enables/disables fog */
- GL_COLOR_UNDERFLOW = (1<<12), /*!< enable = color buffer underflow, setting resets overflow flag; disable = no color buffer overflow */
- GL_POLY_OVERFLOW = (1<<13), /*!< enable = polygon/vertex buffer overflow, setting resets overflow flag; disable = no polygon/vertex buffer overflow */
- GL_CLEAR_BMP = (1<<14) /*!< rear/clear plane is in BMP mode; disable = rear/color plane is in clear mode */
-};
-
-/*! \brief Enums for reading stuff from the geometry engine<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3diomap">http://nocash.emubase.de/gbatek.htm#ds3diomap</A><BR>
-related functions: glGetInt(), glGetFixed()*/
-typedef enum {
- GL_GET_VERTEX_RAM_COUNT, /*!< returns a count of vertexes currently stored in hardware vertex ram. Use glGetInt() to retrieve */
- GL_GET_POLYGON_RAM_COUNT, /*!< returns a count of polygons currently stored in hardware polygon ram. Use glGetInt() to retrieve */
- GL_GET_MATRIX_VECTOR, /*!< returns the current 3x3 directional vector matrix. Use glGetFixed() to retrieve */
- GL_GET_MATRIX_POSITION, /*!< returns the current 4x4 position matrix. Use glGetFixed() to retrieve */
- GL_GET_MATRIX_PROJECTION, /*!< returns the current 4x4 projection matrix. Use glGetFixed() to retrieve */
- GL_GET_MATRIX_CLIP, /*!< returns the current 4x4 clip matrix. Use glGetFixed() to retrieve */
- GL_GET_TEXTURE_WIDTH, /*!< returns the width of the currently bound texture. Use glGetInt() to retrieve */
- GL_GET_TEXTURE_HEIGHT /*!< returns the height of the currently bound texture. Use glGetInt() to retrieve */
-} GL_GET_ENUM;
-
-
-/*! \brief Enums for glFlush()<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A><BR>
-related functions: glEnable(), glDisable(), glInit() */
-enum GLFLUSH_ENUM {
- GL_TRANS_MANUALSORT = (1<<0), /*!< enable manual sorting of translucent polygons, otherwise uses Y-sorting */
- GL_WBUFFERING = (1<<1) /*!< enable W depth buffering of vertices, otherwise uses Z depth buffering */
-};
-
-
-/*---------------------------------------------------------------------------------
-This struct hold hidden globals for videoGL. The structure is initialized in the
-.c file and returned by glGetGlobals() so that it can be used across compilation
-units without problem. This is automatically done by glInit() so don't worry too
-much about it. This is only an issue because of hte mix of inlined/real functions.
----------------------------------------------------------------------------------*/
-typedef struct {
- GL_MATRIX_MODE_ENUM matrixMode; // holds the current Matrix Mode
-
- // holds the current state of the clear color register
- uint32 clearColor; // state of clear color register
-
- // texture globals
- uint32 textures[MAX_TEXTURES];
- uint32 activeTexture;
- uint32* nextBlock;
- uint32 nextPBlock;
- int nameCount;
-
-} gl_hidden_globals;
-
-// Pointer to global data for videoGL
-static gl_hidden_globals* glGlob = 0;
-
-//---------------------------------------------------------------------------------
-//Fifo commands
-//---------------------------------------------------------------------------------
-
-#define FIFO_COMMAND_PACK(c1,c2,c3,c4) (((c4) << 24) | ((c3) << 16) | ((c2) << 8) | (c1)) /*!< \brief packs four packed commands into a 32bit command for sending to the GFX FIFO */
-
-#define REG2ID(r) (u8)( ( ((u32)(&(r)))-0x04000400 ) >> 2 ) /*!< \brief converts a GFX command for use in a packed command list */
-
-#define FIFO_NOP REG2ID(GFX_FIFO) /*!< \brief packed command for nothing, just here to pad your command lists */
-#define FIFO_STATUS REG2ID(GFX_STATUS) /*!< \brief packed command for geometry engine status register<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dstatus">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dstatus</A> */
-#define FIFO_COLOR REG2ID(GFX_COLOR) /*!< \brief packed command for vertex color directly<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes</A> */
-
-#define FIFO_VERTEX16 REG2ID(GFX_VERTEX16) /*!< \brief packed command for a vertex with 3 16bit paramaters(and 16bits of padding)<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices</A> */
-#define FIFO_TEX_COORD REG2ID(GFX_TEX_COORD) /*!< \brief packed command for a texture coordinate<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtexturecoordinates">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtexturecoordinates</A> */
-#define FIFO_TEX_FORMAT REG2ID(GFX_TEX_FORMAT) /*!< \brief packed command for texture format<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureformats">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureformats</A> */
-#define FIFO_PAL_FORMAT REG2ID(GFX_PAL_FORMAT) /*!< \brief packed command for texture palette attributes<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes</A> */
-
-#define FIFO_CLEAR_COLOR REG2ID(GFX_CLEAR_COLOR) /*!< \brief packed command for clear color of the rear plane<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3drearplane">GBATEK http://nocash.emubase.de/gbatek.htm#ds3drearplane</A> */
-#define FIFO_CLEAR_DEPTH REG2ID(GFX_CLEAR_DEPTH) /*!< \brief sets depth of the rear plane<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3drearplane">GBATEK http://nocash.emubase.de/gbatek.htm#ds3drearplane</A> */
-
-#define FIFO_LIGHT_VECTOR REG2ID(GFX_LIGHT_VECTOR) /*!< \brief packed command for direction of a light source<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
-#define FIFO_LIGHT_COLOR REG2ID(GFX_LIGHT_COLOR) /*!< \brief packed command for color for a light<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
-#define FIFO_NORMAL REG2ID(GFX_NORMAL) /*!< \brief packed command for normal for following vertices<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
-
-#define FIFO_DIFFUSE_AMBIENT REG2ID(GFX_DIFFUSE_AMBIENT) /*!< \brief packed command for setting diffuse and ambient material properties for the following vertices<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
-#define FIFO_SPECULAR_EMISSION REG2ID(GFX_SPECULAR_EMISSION) /*!< \brief packed command for setting specular and emmissive material properties for the following vertices<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
-#define FIFO_SHININESS REG2ID(GFX_SHININESS) /*!< \brief packed command for setting the shininess table to be used for the following vertices<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
-
-#define FIFO_POLY_FORMAT REG2ID(GFX_POLY_FORMAT) /*!< \brief packed command for setting polygon attributes<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes</A> */
-
-#define FIFO_BEGIN REG2ID(GFX_BEGIN) /*!< \brief packed command that starts a polygon vertex list<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices</A>*/
-#define FIFO_END REG2ID(GFX_END) /*!< \brief packed command that has no discernable effect, it's probably best to never use it since it bloats the size of the list.<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices</A>*/
-#define FIFO_FLUSH REG2ID(GFX_FLUSH) /*!< \brief packed command that has the same effect as swiWaitForVBlank()<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A> */
-#define FIFO_VIEWPORT REG2ID(GFX_VIEWPORT) /*!< \brief packed command for setting viewport<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A> */
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*! \brief Rotates the model view matrix by angle about the specified unit vector
-\param angle The angle to rotate by
-\param x X component of the unit vector axis.
-\param y Y component of the unit vector axis.
-\param z Z component of the unit vector axis. */
-void glRotatef32i(int angle, int32 x, int32 y, int32 z);
-
-/*! \brief Loads a 2D texture into texture memory and sets the currently bound texture ID to the attributes specified
-\param target not used, just here for OpenGL compatibility
-\param empty1 not used, just here for OpenGL compatibility
-\param type The format of the texture
-\param sizeX the horizontal size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM
-\param sizeY the vertical size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM
-\param empty2 not used, just here for OpenGL compatibility
-\param param parameters for the texture
-\param texture pointer to the texture data to load */
-int glTexImage2D(int target, int empty1, GL_TEXTURE_TYPE_ENUM type, int sizeX, int sizeY, int empty2, int param, const uint8* texture);
-
-/*! \brief Loads a palette into the specified texture addr
-\param pal pointer to the palette to load
-\param count the size of the palette
-\param addr the offset in VRAM to load the palette */
-void glTexLoadPal(const u16* pal, u16 count, u32 addr );
-
-/*! \brief Loads a palette into the next available palette slot, returns the addr on success or -1
-\param pal pointer to the palette to load
-\param count the size of the palette
-\param format the format of the texture */
-int gluTexLoadPal(const u16* pal, u16 count, uint8 format);
-
-/*! \brief Set parameters for the current texture. Although named the same as its gl counterpart, it is not compatible. Effort may be made in the future to make it so.
-\param sizeX the horizontal size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM
-\param sizeY the vertical size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM
-\param addr offset into VRAM where you put the texture
-\param mode the type of texture
-\param param paramaters for the texture */
-void glTexParameter( uint8 sizeX, uint8 sizeY,
- const uint32* addr,
- GL_TEXTURE_TYPE_ENUM mode,
- uint32 param) ;
-
-/*! \brief Returns the active texture parameter (constructed from internal call to glTexParameter) */
-u32 glGetTexParameter();
-
-/*! \brief returns the address alocated to the texure named by name
-\param name the name of the texture to get a pointer to */
-void* glGetTexturePointer( int name);
-
-/*! \brief glBindTexure sets the current named texture to the active texture. Target is ignored as all DS textures are 2D
-\param target ignored, only here for OpenGL compatability
-\param name the name(int value) to set to the current texture */
-void glBindTexture(int target, int name);
-
-/*! \brief glColorTable establishes the location of the current palette. Roughly follows glColorTableEXT. Association of palettes with named textures is left to the application. */
-void glColorTable(uint8 format, uint32 addr);
-
-/*! \brief Creates room for the specified number of textures
-\param n the number of textures to generate
-\param names pointer to the names array to fill */
-int glGenTextures(int n, int *names);
-
-/*! \brief Resets the gl texture state freeing all texture memory */
-void glResetTextures(void);
-
-/*! \brief Sets texture coordinates for following vertices<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes</A>
-\param u U(a.k.a. S) texture coordinate (0.0 - 1.0)
-\param v V(a.k.a. T) texture coordinate (0.0 - 1.0)*/
-void glTexCoord2f32(int32 u, int32 v);
-
-/*! \brief specify the material properties to be used in rendering lit polygons
-\param mode which material property to change
-\param color the color to set for that material property */
-void glMaterialf(GL_MATERIALS_ENUM mode, rgb color);
-
-// This handles initialization of the GL state; this is called from glInit to keep globals synced between compilation units
-void glInit_C(void);
-
-// This returns a pointer to the globals for videoGL
-gl_hidden_globals* glGetGlobals();
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-//////////////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////////////
-//////////// ////////////
-//////////// ////////////
-//////////// ////////////
-//////////// INLINED FUNCTIONS ////////////
-//////////// ////////////
-//////////// ////////////
-//////////// ////////////
-//////////////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////////////
-
-
-
-/*! \brief used in glPolyFmt() to set the alpha level for the following polygons, set to 0 for wireframe mode
-\param n the level of alpha (0-31) */
-GL_STATIC_INL uint32 POLY_ALPHA(int n) { return (uint32)((n) << 16); };
-
-/*! \brief used in glPolyFmt() to set the Polygon ID for the following polygons
-\param n the ID to set for following polygons (0-63) */
-GL_STATIC_INL uint32 POLY_ID(int n) { return (uint32)((n)<<24); };
-
-/*! \brief Starts a polygon group
-\param mode the draw mode for the polygon */
-GL_STATIC_INL void glBegin(GL_GLBEGIN_ENUM mode) { GFX_BEGIN = mode; }
-
-/*! \brief Ends a polygon group, this seems to be a dummy function that does absolutely nothing, feel free to never use it. */
-GL_STATIC_INL void glEnd(void) { GFX_END = 0; }
-
-/*! \brief reset the depth buffer to this value; generally set this to GL_MAX_DEPTH.<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3drearplane">GBATEK http://nocash.emubase.de/gbatek.htm#ds3drearplane</A>
-\param depth Something to do with the depth buffer, generally set to GL_MAX_DEPTH */
-GL_STATIC_INL void glClearDepth(fixed12d3 depth) { GFX_CLEAR_DEPTH = depth; }
-
-/*! \brief Set the color for following vertices
-\param red the red component (0-31)
-\param green the green component (0-31)
-\param blue the blue component (0-31) */
-
-GL_STATIC_INL void glColor3b(uint8 red, uint8 green, uint8 blue) { GFX_COLOR = (vuint32)RGB15(red>>3, green>>3, blue>>3); }
-
-/*! \brief Set the color for following vertices
-\param color the 15bit color value */
-GL_STATIC_INL void glColor(rgb color) { GFX_COLOR = (vuint32)color; }
-
-/*! \brief specifies a vertex
-\param x the x component for the vertex
-\param y the y component for the vertex
-\param z the z component for the vertex */
-GL_STATIC_INL void glVertex3v16(v16 x, v16 y, v16 z) {
- GFX_VERTEX16 = (y << 16) | (x & 0xFFFF);
- GFX_VERTEX16 = ((uint32)(uint16)z);
-}
-
-/*! \brief Sets texture coordinates for following vertices<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes</A>
-\param u U(a.k.a. S) texture coordinate in texels
-\param v V(a.k.a. T) texture coordinate in texels */
-GL_STATIC_INL void glTexCoord2t16(t16 u, t16 v) { GFX_TEX_COORD = TEXTURE_PACK(u,v); }
-
-/*! \brief Pushs the current matrix onto the stack<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack</A> */
-GL_STATIC_INL void glPushMatrix(void) { MATRIX_PUSH = 0; }
-
-/*! \brief Pops num matrices off the stack<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack</A>
-\param num the number to pop down the stack */
-GL_STATIC_INL void glPopMatrix(int32 num) { MATRIX_POP = num; }
-
-/*! \brief Restores the current matrix from a location in the stack<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack</A>
-\param index the place in the stack to restore to */
-GL_STATIC_INL void glRestoreMatrix(int32 index) { MATRIX_RESTORE = index; }
-
-/*! \brief Place the current matrix into the stack at a location<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack</A>
-\param index the place in the stack to put the current matrix */
-GL_STATIC_INL void glStoreMatrix(int32 index) { MATRIX_STORE = index; }
-
-/*! \brief multiply the current matrix by a translation matrix<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
-\param v the vector to translate by */
-GL_STATIC_INL void glScalev(const GLvector* v) {
- MATRIX_SCALE = v->x;
- MATRIX_SCALE = v->y;
- MATRIX_SCALE = v->z;
-}
-
-/*! \brief multiply the current matrix by a translation matrix<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
-\param v the vector to translate by */
-GL_STATIC_INL void glTranslatev(const GLvector* v) {
- MATRIX_TRANSLATE = v->x;
- MATRIX_TRANSLATE = v->y;
- MATRIX_TRANSLATE = v->z;
-}
-
-/*! \brief multiply the current matrix by a translation matrix<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
-\param x translation on the x axis
-\param y translation on the y axis
-\param z translation on the z axis */
-GL_STATIC_INL void glTranslate3f32(int32 x, int32 y, int32 z) {
- MATRIX_TRANSLATE = x;
- MATRIX_TRANSLATE = y;
- MATRIX_TRANSLATE = z;
-}
-
-/*! \brief multiply the current matrix by a scale matrix<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
-\param factor the factor to scale by */
-GL_STATIC_INL void glScalef32(int32 factor) {
- MATRIX_SCALE = factor;
- MATRIX_SCALE = factor;
- MATRIX_SCALE = factor;
-}
-
-/*! \brief set a light up. Only parallel light sources are supported on the DS<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A>
-\param id the number of the light to setup
-\param color the color of the light
-\param x the x component of the lights directional vector. Direction must be normalized
-\param y the y component of the lights directional vector. Direction must be normalized
-\param z the z component of the lights directional vector. Direction must be normalized */
-GL_STATIC_INL void glLight(int id, rgb color, v10 x, v10 y, v10 z) {
- id = (id & 3) << 30;
- GFX_LIGHT_VECTOR = id | ((z & 0x3FF) << 20) | ((y & 0x3FF) << 10) | (x & 0x3FF);
- GFX_LIGHT_COLOR = id | color;
-}
-
-/*! \brief the normal to use for following vertices<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A>
-\warning The nature of the format means that you can't represent the following normals exactly (0,0,1), (0,1,0), or (1,0,0)
-\param normal the packed normal(3 * 10bit x, y, z) */
-GL_STATIC_INL void glNormal(uint32 normal) { GFX_NORMAL = normal; }
-
-/*! \brief loads an identity matrix to the current matrix, same as glIdentity(void) */
-GL_STATIC_INL void glLoadIdentity(void) { MATRIX_IDENTITY = 0; }
-
-/*! \brief change the current matrix mode<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A><BR>
-\param mode the mode for the matrix */
-GL_STATIC_INL void glMatrixMode(GL_MATRIX_MODE_ENUM mode) { MATRIX_CONTROL = mode; }
-
-/*! \brief specify the viewport for following drawing, can be set several times per frame.<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A>
-\param x1 the left of the viewport
-\param y1 the bottom of the viewport
-\param x2 the right of the viewport
-\param y2 the top of the viewport */
-GL_STATIC_INL void glViewport(uint8 x1, uint8 y1, uint8 x2, uint8 y2) { GFX_VIEWPORT = (x1) + (y1 << 8) + (x2 << 16) + (y2 << 24); }
-
-/*! \brief Waits for a Vblank and swaps the buffers(like swiWaitForVBlank), but lets you specify some 3D options<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A>
-\param mode flags from GLFLUSH_ENUM for enabling Y-sorting of translucent polygons and W-Buffering of all vertices*/
-GL_STATIC_INL void glFlush(uint32 mode) { GFX_FLUSH = mode; }
-
-/*! \brief The DS uses a table for shinyness..this generates a half-ass one */
-GL_STATIC_INL void glMaterialShinyness(void) {
- uint32 shiny32[128/4];
- uint8 *shiny8 = (uint8*)shiny32;
-
- int i;
-
- for (i = 0; i < 128 * 2; i += 2)
- shiny8[i>>1] = i;
-
- for (i = 0; i < 128 / 4; i++)
- GFX_SHININESS = shiny32[i];
-}
-
-/*! \brief throws a packed list of commands into the graphics FIFO via asyncronous DMA<BR>
-The first 32bits is the length of the packed command list, followed by a the packed list.<BR>
-If you want to do this really fast then write your own code that that does this synchronously and only flushes the cache when the list is changed<BR>
-There is sometimes a problem when you pack the GFX_END command into a list, so don't. GFX_END is a dummy command and never needs called<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dgeometrycommands">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dgeometrycommands</A> */
-GL_STATIC_INL void glCallList(const u32* list) {
- u32 count = *list++;
-
- // flush the area that we are going to DMA
- DC_FlushRange(list, count*4);
-
- // don't start DMAing while anything else is being DMAed because FIFO DMA is touchy as hell
- // If anyone can explain this better that would be great. -- gabebear
- while((DMA_CR(0) & DMA_BUSY)||(DMA_CR(1) & DMA_BUSY)||(DMA_CR(2) & DMA_BUSY)||(DMA_CR(3) & DMA_BUSY));
-
- // send the packed list asynchronously via DMA to the FIFO
- DMA_SRC(0) = (uint32)list;
- DMA_DEST(0) = 0x4000400;
- DMA_CR(0) = DMA_FIFO | count;
- while(DMA_CR(0) & DMA_BUSY);
-}
-
-/*! \brief Set the parameters for polygons rendered on the current frame<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes</A>
-\param params the paramters to set for the polygons for the current frame. valid paramters are enumerated in GL_POLY_FORMAT_ENUM and in the functions POLY_ALPHA() and POLY_ID() */
-GL_STATIC_INL void glPolyFmt(uint32 params) { GFX_POLY_FORMAT = params; }
-
-/*! \brief Enables various gl states (blend, alpha test, etc..)
-\param bits bit mask of desired attributes, attributes are enumerated in DISP3DCNT_ENUM */
-GL_STATIC_INL void glEnable(int bits) { GFX_CONTROL |= bits; }
-
-/*! \brief Disables various gl states (blend, alpha test, etc..)
-\param bits bit mask of desired attributes, attributes are enumerated in DISP3DCNT_ENUM */
-GL_STATIC_INL void glDisable(int bits) { GFX_CONTROL &= ~bits; }
-
-/*! \brief Loads a 4x4 matrix into the current matrix
-\param m pointer to a 4x4 matrix */
-GL_STATIC_INL void glLoadMatrix4x4(const m4x4 *m) {
- MATRIX_LOAD4x4 = m->m[0];
- MATRIX_LOAD4x4 = m->m[1];
- MATRIX_LOAD4x4 = m->m[2];
- MATRIX_LOAD4x4 = m->m[3];
-
- MATRIX_LOAD4x4 = m->m[4];
- MATRIX_LOAD4x4 = m->m[5];
- MATRIX_LOAD4x4 = m->m[6];
- MATRIX_LOAD4x4 = m->m[7];
-
- MATRIX_LOAD4x4 = m->m[8];
- MATRIX_LOAD4x4 = m->m[9];
- MATRIX_LOAD4x4 = m->m[10];
- MATRIX_LOAD4x4 = m->m[11];
-
- MATRIX_LOAD4x4 = m->m[12];
- MATRIX_LOAD4x4 = m->m[13];
- MATRIX_LOAD4x4 = m->m[14];
- MATRIX_LOAD4x4 = m->m[15];
-}
-
-/*! \brief Loads a 4x3 matrix into the current matrix
-\param m pointer to a 4x4 matrix */
-GL_STATIC_INL void glLoadMatrix4x3(const m4x3 * m) {
- MATRIX_LOAD4x3 = m->m[0];
- MATRIX_LOAD4x3 = m->m[1];
- MATRIX_LOAD4x3 = m->m[2];
- MATRIX_LOAD4x3 = m->m[3];
-
- MATRIX_LOAD4x3 = m->m[4];
- MATRIX_LOAD4x3 = m->m[5];
- MATRIX_LOAD4x3 = m->m[6];
- MATRIX_LOAD4x3 = m->m[7];
-
- MATRIX_LOAD4x3 = m->m[8];
- MATRIX_LOAD4x3 = m->m[9];
- MATRIX_LOAD4x3 = m->m[10];
- MATRIX_LOAD4x3 = m->m[11];
-}
-
-/*! \brief Multiplies the current matrix by m
-\param m pointer to a 4x4 matrix */
-GL_STATIC_INL void glMultMatrix4x4(const m4x4 * m) {
- MATRIX_MULT4x4 = m->m[0];
- MATRIX_MULT4x4 = m->m[1];
- MATRIX_MULT4x4 = m->m[2];
- MATRIX_MULT4x4 = m->m[3];
-
- MATRIX_MULT4x4 = m->m[4];
- MATRIX_MULT4x4 = m->m[5];
- MATRIX_MULT4x4 = m->m[6];
- MATRIX_MULT4x4 = m->m[7];
-
- MATRIX_MULT4x4 = m->m[8];
- MATRIX_MULT4x4 = m->m[9];
- MATRIX_MULT4x4 = m->m[10];
- MATRIX_MULT4x4 = m->m[11];
-
- MATRIX_MULT4x4 = m->m[12];
- MATRIX_MULT4x4 = m->m[13];
- MATRIX_MULT4x4 = m->m[14];
- MATRIX_MULT4x4 = m->m[15];
-}
-
-/*! \brief multiplies the current matrix by
-\param m pointer to a 4x3 matrix */
-GL_STATIC_INL void glMultMatrix4x3(const m4x3 * m) {
- MATRIX_MULT4x3 = m->m[0];
- MATRIX_MULT4x3 = m->m[1];
- MATRIX_MULT4x3 = m->m[2];
- MATRIX_MULT4x3 = m->m[3];
-
- MATRIX_MULT4x3 = m->m[4];
- MATRIX_MULT4x3 = m->m[5];
- MATRIX_MULT4x3 = m->m[6];
- MATRIX_MULT4x3 = m->m[7];
-
- MATRIX_MULT4x3 = m->m[8];
- MATRIX_MULT4x3 = m->m[9];
- MATRIX_MULT4x3 = m->m[10];
- MATRIX_MULT4x3 = m->m[11];
-
-}
-
-/*! \brief multiplies the current matrix by m
-\param m pointer to a 3x3 matrix */
-GL_STATIC_INL void glMultMatrix3x3(const m3x3 * m) {
- MATRIX_MULT3x3 = m->m[0];
- MATRIX_MULT3x3 = m->m[1];
- MATRIX_MULT3x3 = m->m[2];
-
- MATRIX_MULT3x3 = m->m[3];
- MATRIX_MULT3x3 = m->m[4];
- MATRIX_MULT3x3 = m->m[5];
-
- MATRIX_MULT3x3 = m->m[6];
- MATRIX_MULT3x3 = m->m[7];
- MATRIX_MULT3x3 = m->m[8];
-}
-
-/*! \brief Rotates the current modelview matrix by angle about the x axis
-\param angle The angle to rotate by (angle is 0-511) */
-GL_STATIC_INL void glRotateXi(int angle) {
- int32 sine = SIN[angle & LUT_MASK];
- int32 cosine = COS[angle & LUT_MASK];
-
- MATRIX_MULT3x3 = inttof32(1);
- MATRIX_MULT3x3 = 0;
- MATRIX_MULT3x3 = 0;
-
- MATRIX_MULT3x3 = 0;
- MATRIX_MULT3x3 = cosine;
- MATRIX_MULT3x3 = sine;
-
- MATRIX_MULT3x3 = 0;
- MATRIX_MULT3x3 = -sine;
- MATRIX_MULT3x3 = cosine;
-}
-
-/*! \brief Rotates the current modelview matrix by angle about the y axis
-\param angle The angle to rotate by (angle is 0-511) */
-GL_STATIC_INL void glRotateYi(int angle) {
- int32 sine = SIN[angle & LUT_MASK];
- int32 cosine = COS[angle & LUT_MASK];
-
- MATRIX_MULT3x3 = cosine;
- MATRIX_MULT3x3 = 0;
- MATRIX_MULT3x3 = -sine;
-
- MATRIX_MULT3x3 = 0;
- MATRIX_MULT3x3 = inttof32(1);
- MATRIX_MULT3x3 = 0;
-
- MATRIX_MULT3x3 = sine;
- MATRIX_MULT3x3 = 0;
- MATRIX_MULT3x3 = cosine;
-}
-
-/*! \brief Rotates the current modelview matrix by angle about the z axis
-\param angle The angle to rotate by (angle is 0-511) */
-GL_STATIC_INL void glRotateZi(int angle) {
- int32 sine = SIN[angle & LUT_MASK];
- int32 cosine = COS[angle & LUT_MASK];
-
- MATRIX_MULT3x3 = cosine;
- MATRIX_MULT3x3 = sine;
- MATRIX_MULT3x3 = 0;
-
- MATRIX_MULT3x3 = - sine;
- MATRIX_MULT3x3 = cosine;
- MATRIX_MULT3x3 = 0;
-
- MATRIX_MULT3x3 = 0;
- MATRIX_MULT3x3 = 0;
- MATRIX_MULT3x3 = inttof32(1);
-}
-
-
-/*! \brief Multiplies the current matrix into ortho graphic mode
-\param left left vertical clipping plane
-\param right right vertical clipping plane
-\param bottom bottom vertical clipping plane
-\param top top vertical clipping plane
-\param zNear near clipping plane
-\param zFar far clipping plane */
-GL_STATIC_INL void glOrthof32(int32 left, int32 right, int32 bottom, int32 top, int32 zNear, int32 zFar) {
- MATRIX_MULT4x4 = divf32(inttof32(2), right - left);
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = 0;
-
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = divf32(inttof32(2), top - bottom);
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = 0;
-
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = divf32(inttof32(-2), zFar - zNear);
- MATRIX_MULT4x4 = 0;
-
- MATRIX_MULT4x4 = -divf32(right + left, right - left);//0;
- MATRIX_MULT4x4 = -divf32(top + bottom, top - bottom); //0;
- MATRIX_MULT4x4 = -divf32(zFar + zNear, zFar - zNear);//0;
- MATRIX_MULT4x4 = floattof32(1.0F);
-}
-
-/*! \brief Places the camera at the specified location and orientation (fixed point version)
-\param eyex (eyex, eyey, eyez) Location of the camera.
-\param eyey (eyex, eyey, eyez) Location of the camera.
-\param eyez (eyex, eyey, eyez) Location of the camera.
-\param lookAtx (lookAtx, lookAty, lookAtz) Where the camera is looking.
-\param lookAty (lookAtx, lookAty, lookAtz) Where the camera is looking.
-\param lookAtz (lookAtx, lookAty, lookAtz) Where the camera is looking.
-\param upx <upx, upy, upz> Unit vector describing which direction is up for the camera.
-\param upy <upx, upy, upz> Unit vector describing which direction is up for the camera.
-\param upz <upx, upy, upz> Unit vector describing which direction is up for the camera. */
-GL_STATIC_INL void gluLookAtf32(int32 eyex, int32 eyey, int32 eyez, int32 lookAtx, int32 lookAty, int32 lookAtz, int32 upx, int32 upy, int32 upz) {
- int32 side[3], forward[3], up[3], eye[3];
-
- forward[0] = eyex - lookAtx;
- forward[1] = eyey - lookAty;
- forward[2] = eyez - lookAtz;
-
- normalizef32(forward);
-
- up[0] = upx;
- up[1] = upy;
- up[2] = upz;
- eye[0] = eyex;
- eye[1] = eyey;
- eye[2] = eyez;
-
- crossf32(up, forward, side);
-
- normalizef32(side);
-
- // Recompute local up
- crossf32(forward, side, up);
-
- glMatrixMode(GL_MODELVIEW);
-
-
- // should we use MATRIX_MULT4x3?
- MATRIX_MULT4x3 = side[0];
- MATRIX_MULT4x3 = up[0];
- MATRIX_MULT4x3 = forward[0];
-
- MATRIX_MULT4x3 = side[1];
- MATRIX_MULT4x3 = up[1];
- MATRIX_MULT4x3 = forward[1];
-
- MATRIX_MULT4x3 = side[2];
- MATRIX_MULT4x3 = up[2];
- MATRIX_MULT4x3 = forward[2];
-
- MATRIX_MULT4x3 = -dotf32(eye,side);
- MATRIX_MULT4x3 = -dotf32(eye,up);
- MATRIX_MULT4x3 = -dotf32(eye,forward);
-
-}
-
-
-/*! \brief Specifies the viewing frustum for the projection matrix (fixed point version)
-\param left left right top and bottom describe a rectangle located at the near clipping plane
-\param right left right top and bottom describe a rectangle located at the near clipping plane
-\param top left right top and bottom describe a rectangle located at the near clipping plane
-\param bottom left right top and bottom describe a rectangle located at the near clipping plane
-\param near Location of a the near clipping plane (parallel to viewing window)
-\param far Location of a the far clipping plane (parallel to viewing window) */
-GL_STATIC_INL void glFrustumf32(int32 left, int32 right, int32 bottom, int32 top, int32 near, int32 far) {
-/* MATRIX_MULT4x4 = divf32(2*near, right - left);
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = divf32(right + left, right - left);
- MATRIX_MULT4x4 = 0;
-
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = divf32(2*near, top - bottom);
- MATRIX_MULT4x4 = divf32(top + bottom, top - bottom);
- MATRIX_MULT4x4 = 0;
-
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = -divf32(far + near, far - near);
- MATRIX_MULT4x4 = floattof32(-1.0F);
- MATRIX_MULT4x4 = 0;
-
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = -divf32(2 * mulf32(far, near), far - near);
- MATRIX_MULT4x4 = 0;
-*/
-
-
- MATRIX_MULT4x4 = divf32(2*near, right - left);
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = 0;
-
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = divf32(2*near, top - bottom);
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = 0;
-
- MATRIX_MULT4x4 = divf32(right + left, right - left);
- MATRIX_MULT4x4 = divf32(top + bottom, top - bottom);
- MATRIX_MULT4x4 = -divf32(far + near, far - near);
- MATRIX_MULT4x4 = floattof32(-1.0F);
-
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = -divf32(2 * mulf32(far, near), far - near);
- MATRIX_MULT4x4 = 0;
-
-}
-
-/*! \brief Utility function which sets up the projection matrix (fixed point version)
-\param fovy Specifies the field of view in degrees (0 -511)
-\param aspect Specifies the aspect ratio of the screen (normally screen width/screen height)
-\param zNear Specifies the near clipping plane
-\param zFar Specifies the far clipping plane */
-GL_STATIC_INL void gluPerspectivef32(int fovy, int32 aspect, int32 zNear, int32 zFar) {
- int32 xmin, xmax, ymin, ymax;
-
- ymax = mulf32(zNear, TAN[(fovy>>1) & LUT_MASK]);
- ymin = -ymax;
- xmin = mulf32(ymin, aspect);
- xmax = mulf32(ymax, aspect);
-
- glFrustumf32(xmin, xmax, ymin, ymax, zNear, zFar);
-}
-
-/*! \brief Utility function which generates a picking matrix for selection
-\param x 2D x of center (touch x normally)
-\param y 2D y of center (touch y normally)
-\param width width in pixels of the window (3 or 4 is a good number)
-\param height height in pixels of the window (3 or 4 is a good number)
-\param viewport the current viewport (normaly {0, 0, 255, 191}) */
-GL_STATIC_INL void gluPickMatrix(int x, int y, int width, int height, const int viewport[4]) {
- MATRIX_MULT4x4 = inttof32(viewport[2]) / width;
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = inttof32(viewport[3]) / height;
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = inttof32(1);
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = inttof32(viewport[2] + ((viewport[0] - x)<<1)) / width;
- MATRIX_MULT4x4 = inttof32(viewport[3] + ((viewport[1] - y)<<1)) / height;
- MATRIX_MULT4x4 = 0;
- MATRIX_MULT4x4 = inttof32(1);
-}
-
-/*! \brief Resets matrix stack to top level */
-GL_STATIC_INL void glResetMatrixStack(void) {
- // make sure there are no push/pops that haven't executed yet
- while(GFX_STATUS & BIT(14)){
- GFX_STATUS |= 1 << 15; // clear push/pop errors or push/pop busy bit never clears
- }
-
- // pop the projection stack to the top; poping 0 off an empty stack causes an error... weird?
- if((GFX_STATUS&(1<<13))!=0) {
- glMatrixMode(GL_PROJECTION);
- glPopMatrix(1);
- }
-
- // 31 deep modelview matrix; 32nd entry works but sets error flag
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix((GFX_STATUS >> 8) & 0x1F);
-
- // load identity to all the matrices
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
-}
-
-/*! \brief Specifies an edge color for polygons
-\param id which outline color to set (0-7)
-\param color the 15bit color to set */
-GL_STATIC_INL void glSetOutlineColor(int id, rgb color) { GFX_EDGE_TABLE[id] = color; }
-
-/*! \brief Loads a toon table
-\param pointer to the 32 color palette to load into the toon table*/
-GL_STATIC_INL void glSetToonTable(const uint16 *table) {
- int i;
- for(i = 0; i < 32; i++ )
- GFX_TOON_TABLE[i] = table[i];
-}
-
-/*! \brief Sets a range of colors on the toon table
-\param start the start of the range
-\param end the end of the range
-\param color the color to set for that range */
-GL_STATIC_INL void glSetToonTableRange(int start, int end, rgb color) {
- int i;
- for(i = start; i <= end; i++ )
- GFX_TOON_TABLE[i] = color;
-}
-
-/*! \brief Grabs fixed format of state variables<BR>
-OpenGL's modelview matrix is handled on the DS with two matrices. The combination of the DS's position matrix and directional vector matrix hold the data that is in OpenGL's one modelview matrix. (a.k.a. modelview = postion and vector)<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3diomap">http://nocash.emubase.de/gbatek.htm#ds3diomap</A>
-\param param The state variable to retrieve
-\param f pointer with room to hold the requested data */
-GL_STATIC_INL void glGetFixed(const GL_GET_ENUM param, int32* f) {
- int i;
- switch (param) {
- case GL_GET_MATRIX_VECTOR:
- while(GFX_BUSY); // wait until the graphics engine has stopped to read matrixes
- for(i = 0; i < 9; i++) f[i] = MATRIX_READ_VECTOR[i];
- break;
- case GL_GET_MATRIX_CLIP:
- while(GFX_BUSY); // wait until the graphics engine has stopped to read matrixes
- for(i = 0; i < 16; i++) f[i] = MATRIX_READ_CLIP[i];
- break;
- case GL_GET_MATRIX_PROJECTION:
- glMatrixMode(GL_POSITION);
- glPushMatrix(); // save the current state of the position matrix
- glLoadIdentity(); // load an identity matrix into the position matrix so that the clip matrix = projection matrix
- while(GFX_BUSY); // wait until the graphics engine has stopped to read matrixes
- for(i = 0; i < 16; i++) f[i] = MATRIX_READ_CLIP[i]; // read out the projection matrix
- glPopMatrix(1); // restore the position matrix
- break;
- case GL_GET_MATRIX_POSITION:
- glMatrixMode(GL_PROJECTION);
- glPushMatrix(); // save the current state of the projection matrix
- glLoadIdentity(); // load a identity matrix into the projection matrix so that the clip matrix = position matrix
- while(GFX_BUSY); // wait until the graphics engine has stopped to read matrixes
- for(i = 0; i < 16; i++) f[i] = MATRIX_READ_CLIP[i]; // read out the position matrix
- glPopMatrix(1); // restore the projection matrix
- break;
- default:
- break;
- }
-}
-
-/*! \brief set the minimum alpha value that will be used<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A>
-\param alphaThreshold minimum alpha value that will be used (0-15) */
-GL_STATIC_INL void glAlphaFunc(int alphaThreshold) { GFX_ALPHA_TEST = alphaThreshold; }
-
-/*! \brief Stop the drawing of polygons that are a certain distance from the camera.<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A>
-\param polygons that are beyond this W-value(distance from camera) will not be drawn; 15bit value. */
-GL_STATIC_INL void glCutoffDepth(fixed12d3 wVal) { GFX_CUTOFF_DEPTH = wVal; }
-
-/*! \brief Initializes the gl state machine (must be called once before using gl calls) */
-GL_STATIC_INL void glInit() {
- glGlob = glGetGlobals(); // make sure globals are synced between compilation units
- glInit_C(); // actually does the initialization
-}
-
-/*! \brief sets the color of the rear-plane(a.k.a Clear Color/Plane)
-\param red component (0-31)
-\param green component (0-31)
-\param blue component (0-31)
-\param alpha from 0(clear) to 31(opaque)*/
-GL_STATIC_INL void glClearColor(uint8 red, uint8 green, uint8 blue, uint8 alpha) {
- GFX_CLEAR_COLOR = glGlob->clearColor = ( glGlob->clearColor & 0xFFE08000) | (0x7FFF & RGB15(red, green, blue)) | ((alpha & 0x1F) << 16);
-}
-
-/*! \brief sets the polygon ID of the rear-plane(a.k.a. Clear/Color Plane), useful for antialiasing and edge coloring
-\param ID the polygon ID to give the rear-plane */
-GL_STATIC_INL void glClearPolyID(uint8 ID) {
- GFX_CLEAR_COLOR = glGlob->clearColor = ( glGlob->clearColor & 0xC0FFFFFF) | (( ID & 0x3F ) << 24 );
-}
-
-/*! \brief Grabs integer state variables from openGL
-\param param The state variable to retrieve
-\param i pointer with room to hold the requested data */
-GL_STATIC_INL void glGetInt(GL_GET_ENUM param, int* i) {
- switch (param) {
- case GL_GET_POLYGON_RAM_COUNT:
- *i = GFX_POLYGON_RAM_USAGE;
- break;
- case GL_GET_VERTEX_RAM_COUNT:
- *i = GFX_VERTEX_RAM_USAGE;
- break;
- case GL_GET_TEXTURE_WIDTH:
- *i = 8 << (((glGlob->textures[glGlob->activeTexture]) >> 20) & 7);
- break;
- case GL_GET_TEXTURE_HEIGHT:
- *i = 8 << (((glGlob->textures[glGlob->activeTexture]) >> 23) & 7);
- break;
- default:
- break;
- }
-}
-
-
-//---------------------------------------------------------------------------------
-// INLINED FlOAT WRAPPERS
-//
-// All floating point functions.
-//
-
-/*! \brief specifies a vertex location
-\warning FLOAT VERSION!!!! please use glVertex3v16()
-\param x the x component of the vertex
-\param y the y component of the vertex
-\param z the z component of the vertex */
-GL_STATIC_INL void glVertex3f(float x, float y, float z) {
- glVertex3v16(floattov16(x), floattov16(y), floattov16(z));
-}
-
-/*! \brief Rotate on an arbitrary axis
-\warning FLOAT VERSION!!!! please use glRotatef32i()
-\param angle the angle to rotate by
-\param x the x component of the axis to rotate on
-\param y the y component of the axis to rotate on
-\param z the z component of the axis to rotate on */
-GL_STATIC_INL void glRotatef32(float angle, int32 x, int32 y, int32 z) {
- glRotatef32i((int)(angle * LUT_SIZE / 360.0), x, y, z);
-}
-
-/*! \brief Rotate about an arbitrary axis
-\warning FLOAT VERSION!!!! please use glRotatef32i()
-\param angle the angle to rotate by
-\param x the x component of the axis to rotate on
-\param y the y component of the axis to rotate on
-\param z the z component of the axis to rotate on */
-GL_STATIC_INL void glRotatef(float angle, float x, float y, float z) {
- glRotatef32(angle, floattof32(x), floattof32(y), floattof32(z));
-}
-
-/*! \brief specify a color for following vertices
-\warning FLOAT VERSION!!!! please use glColor3b()
-\param r the red component of the color
-\param g the green component of the color
-\param b the blue component of the color */
-GL_STATIC_INL void glColor3f(float r, float g, float b) {
- glColor3b((uint8)(r*255), (uint8)(g*255), (uint8)(b*255));
-}
-
-/*! \brief multiply the current matrix by a scale matrix<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
-\warning FLOAT VERSION!!!! please use glScalev() or glScalef32()
-\param x scaling on the x axis
-\param y scaling on the y axis
-\param z scaling on the z axis */
-GL_STATIC_INL void glScalef(float x, float y, float z) {
- MATRIX_SCALE = floattof32(x);
- MATRIX_SCALE = floattof32(y);
- MATRIX_SCALE = floattof32(z);
-}
-
-/*! \brief multiply the current matrix by a translation matrix<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
-\warning FLOAT VERSION!!!! please use glTranslate3f32()
-\param x translation on the x axis
-\param y translation on the y axis
-\param z translation on the z axis */
-GL_STATIC_INL void glTranslatef(float x, float y, float z) {
- MATRIX_TRANSLATE = floattof32(x);
- MATRIX_TRANSLATE = floattof32(y);
- MATRIX_TRANSLATE = floattof32(z);
-}
-
-/*! \brief the normal to use for following vertices<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A>
-\warning FLOAT VERSION!!!! please use glNormal()
-\param x x component of the normal, vector must be normalized
-\param y y component of the normal, vector must be normalized
-\param z z component of the normal, vector must be normalized */
-GL_STATIC_INL void glNormal3f(float x, float y, float z) {
- glNormal(NORMAL_PACK(floattov10(x), floattov10(y), floattov10(z)));
-}
-
-/*! \brief Rotates the current modelview matrix by angle degrees about the x axis
-\warning FLOAT VERSION!!!! please use glRotateXi()
-\param angle The angle to rotate by */
-GL_STATIC_INL void glRotateX(float angle) {
- glRotateXi((int)(angle * LUT_SIZE / 360.0));
-}
-
-/*! \brief Rotates the current modelview matrix by angle degrees about the y axis
-\warning FLOAT VERSION!!!! please use glRotateYi()
-\param angle The angle to rotate by */
-GL_STATIC_INL void glRotateY(float angle) {
- glRotateYi((int)(angle * LUT_SIZE / 360.0));
-}
-
-/*! \brief Rotates the current modelview matrix by angle degrees about the z axis
-\warning FLOAT VERSION!!!! please use glRotateZi()
-\param angle The angle to rotate by */
-GL_STATIC_INL void glRotateZ(float angle) {
- glRotateZi((int)(angle * LUT_SIZE / 360.0));
-}
-
-/*! \brief Multiplies the current matrix into ortho graphic mode
-\warning FLOAT VERSION!!!! please use glOrthof32()
-\param left left vertical clipping plane
-\param right right vertical clipping plane
-\param bottom bottom vertical clipping plane
-\param top top vertical clipping plane
-\param zNear near clipping plane
-\param zFar far clipping plane */
-GL_STATIC_INL void glOrtho(float left, float right, float bottom, float top, float zNear, float zFar) {
- glOrthof32(floattof32(left), floattof32(right), floattof32(bottom), floattof32(top), floattof32(zNear), floattof32(zFar));
-}
-
-/*! \brief Places the camera at the specified location and orientation (floating point version)
-\warning FLOAT VERSION!!!! please use gluLookAtf32()
-\param eyex (eyex, eyey, eyez) Location of the camera.
-\param eyey (eyex, eyey, eyez) Location of the camera.
-\param eyez (eyex, eyey, eyez) Location of the camera.
-\param lookAtx (lookAtx, lookAty, lookAtz) Where the camera is looking.
-\param lookAty (lookAtx, lookAty, lookAtz) Where the camera is looking.
-\param lookAtz (lookAtx, lookAty, lookAtz) Where the camera is looking.
-\param upx <upx, upy, upz> Unit vector describing which direction is up for the camera.
-\param upy <upx, upy, upz> Unit vector describing which direction is up for the camera.
-\param upz <upx, upy, upz> Unit vector describing which direction is up for the camera. */
-GL_STATIC_INL void gluLookAt( float eyex, float eyey, float eyez,
- float lookAtx, float lookAty, float lookAtz,
- float upx, float upy, float upz) {
- gluLookAtf32(floattof32(eyex), floattof32(eyey), floattof32(eyez),
- floattof32(lookAtx), floattof32(lookAty), floattof32(lookAtz),
- floattof32(upx), floattof32(upy), floattof32(upz));
-}
-
-/*! \brief Specifies the viewing frustum for the projection matrix (floating point version)
-\warning FLOAT VERSION!!!! please use glFrustumf32()
-\param left left right top and bottom describe a rectangle located at the near clipping plane
-\param right left right top and bottom describe a rectangle located at the near clipping plane
-\param top left right top and bottom describe a rectangle located at the near clipping plane
-\param bottom left right top and bottom describe a rectangle located at the near clipping plane
-\param near Location of a the near clipping plane (parallel to viewing window)
-\param far Location of a the far clipping plane (parallel to viewing window) */
-GL_STATIC_INL void glFrustum(float left, float right, float bottom, float top, float near, float far) {
- glFrustumf32(floattof32(left), floattof32(right), floattof32(bottom), floattof32(top), floattof32(near), floattof32(far));
-}
-
-/*! \brief Utility function which sets up the projection matrix (floating point version)
-\warning FLOAT VERSION!!!! please use gluPerspectivef32()
-\param fovy Specifies the field of view in degrees
-\param aspect Specifies the aspect ratio of the screen (normally screen width/screen height)
-\param zNear Specifies the near clipping plane
-\param zFar Specifies the far clipping plane */
-GL_STATIC_INL void gluPerspective(float fovy, float aspect, float zNear, float zFar) {
- gluPerspectivef32((int)(fovy * LUT_SIZE / 360.0), floattof32(aspect), floattof32(zNear), floattof32(zFar));
-}
-
-/*! \brief Sets texture coordinates for following vertices<BR>
-<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes</A>
-\warning FLOAT VERSION!!!! please use glTexCoord2t16()
-\param s S(a.k.a. U) texture coordinate (0.0 - 1.0)
-\param t T(a.k.a. V) texture coordinate (0.0 - 1.0)*/
-GL_STATIC_INL void glTexCoord2f(float s, float t) {
- int x = ((glGlob->textures[glGlob->activeTexture]) >> 20) & 7;
- int y = ((glGlob->textures[glGlob->activeTexture]) >> 23) & 7;
-
- glTexCoord2t16(floattot16(s*(8 << x)), floattot16(t*(8<<y)));
-}
-
-
-#endif // #ifndef VIDEOGL_ARM9_INCLUDE
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ videoGL.h -- Video API vaguely similar to OpenGL
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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.
+
+
+---------------------------------------------------------------------------------*/
+/*! \file videoGL.h
+\brief openGL (ish) interface to DS 3D hardware.
+*/
+
+#ifndef VIDEOGL_ARM9_INCLUDE
+#define VIDEOGL_ARM9_INCLUDE
+
+//---------------------------------------------------------------------------------
+
+// for some reason doxygen doesn't like "static inline" but is fine with "GL_STATIC_INL"
+#define GL_STATIC_INL static inline
+
+#ifndef ARM9
+#error 3D hardware is only available from the ARM9
+#endif
+
+//---------------------------------------------------------------------------------
+#include <nds/jtypes.h>
+#include <nds/arm9/video.h>
+#include <nds/dma.h>
+#include <nds/memory.h>
+#include <nds/bios.h>
+#include <nds/arm9/math.h>
+#include <nds/arm9/trig_lut.h>
+#include <nds/arm9/cache.h>
+
+/*---------------------------------------------------------------------------------
+ lut resolution for trig functions
+ (must be power of two and must be the same as LUT resolution)
+ in other words dont change unless you also change your LUTs
+---------------------------------------------------------------------------------*/
+#define LUT_SIZE (512)
+#define LUT_MASK (0x1FF)
+
+////////////////////////////////////////////////////////////
+// Misc. constants
+////////////////////////////////////////////////////////////
+
+#define MAX_TEXTURES 2048 //this should be enough ! but feel free to change
+
+
+//////////////////////////////////////////////////////////////////////
+// Fixed point / floating point / integer conversion macros
+//////////////////////////////////////////////////////////////////////
+
+typedef uint16 fixed12d3; /*!< \brief Used for depth (glClearDepth, glCutoffDepth) */
+
+#define int_to_12d3(n) ((n) << 3) /*!< \brief convert int to fixed12d3 */
+#define float_to_12d3(n) ((fixed12d3)((n) * (1 << 3))) /*!< \brief convert float to fixed12d3 */
+#define GL_MAX_DEPTH 0x7FFF /*!< \brief the maximum value for type fixed12d3 */
+
+//////////////////////////////////////////////////////////////////////
+
+#define inttof32(n) ((n) << 12) /*!< \brief convert int to f32 */
+#define f32toint(n) ((n) >> 12) /*!< \brief convert f32 to int */
+#define floattof32(n) ((int32)((n) * (1 << 12))) /*!< \brief convert float to f32 */
+#define f32tofloat(n) (((float)(n)) / (float)(1<<12)) /*!< \brief convert f32 to float */
+
+typedef short int t16; /*!< \brief text coordinate 12.4 fixed point */
+#define f32tot16(n) ((t16)(n >> 8)) /*!< \brief convert f32 to t16 */
+#define inttot16(n) ((n) << 4) /*!< \brief convert int to t16 */
+#define t16toint(n) ((n) >> 4) /*!< \brief convert t16 to int */
+#define floattot16(n) ((t16)((n) * (1 << 4))) /*!< \brief convert float to t16 */
+#define TEXTURE_PACK(u,v) ((u & 0xFFFF) | ((v) << 16)) /*!< \brief Pack 2 t16 texture coordinate values into a 32bit value */
+
+typedef short int v16; /*!< \brief vertex 4.12 fixed format */
+#define inttov16(n) ((n) << 12) /*!< \brief convert int to v16 */
+#define f32tov16(n) (n) /*!< \brief f32 to v16 */
+#define v16toint(n) ((n) >> 12) /*!< \brief convert v16 to int */
+#define floattov16(n) ((v16)((n) * (1 << 12))) /*!< \brief convert float to v16 */
+#define VERTEX_PACK(x,y) (((x) & 0xFFFF) | ((y) << 16)) /*!< \brief Pack to v16 values into one 32bit value */
+
+typedef short int v10; /*!< \brief normal .10 fixed point, NOT USED FOR 10bit VERTEXES!!!*/
+#define inttov10(n) ((n) << 9) /*!< \brief convert int to v10 */
+#define f32tov10(n) ((v10)(n >> 3)) /*!< \brief convert f32 to v10 */
+#define v10toint(n) ((n) >> 9) /*!< \brief convert v10 to int */
+#define floattov10(n) ((n>.998) ? 0x1FF : ((v10)((n)*(1<<9)))) /*!< \brief convert float to v10 */
+#define NORMAL_PACK(x,y,z) (((x) & 0x3FF) | (((y) & 0x3FF) << 10) | ((z) << 20)) /*!< \brief Pack 3 v10 normals into a 32bit value */
+
+//////////////////////////////////////////////////////////////////////
+
+typedef unsigned short rgb; /*!< \brief Holds a color value. 1bit alpha, 5bits red, 5bits green, 5bits blue. */
+
+/*! \brief Holds a Matrix of 3x3 */
+typedef struct {
+ int32 m[9]; /*!< array that holds matrix */
+} m3x3;
+
+/*! \brief Holds a Matrix of 4x4 */
+typedef struct {
+ int32 m[16]; /*!< array that holds matrix */
+} m4x4;
+
+/*! \brief Holds a Matrix of 4x3 */
+typedef struct {
+ int32 m[12]; /*!< array that holds matrix */
+} m4x3;
+
+/*! \brief Holds a Vector<BR>related functions: glScalev(), glTranslatev() */
+typedef struct {
+ int32 x, y, z;
+} GLvector;
+
+//////////////////////////////////////////////////////////////////////
+
+#define GL_FALSE 0
+#define GL_TRUE 1
+
+/*! \brief Enums selecting polygon draw mode<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices</A><BR>
+related functions: glBegin() */
+typedef enum {
+ GL_TRIANGLES = 0, /*!< draw triangles with each 3 vertices defining a triangle */
+ GL_QUADS = 1, /*!< draw quads with each 4 vertices defining a quad */
+ GL_TRIANGLE_STRIP = 2, /*!< draw triangles with the first triangle defined by 3 vertices, then each additional triangle being defined by one additional vertex */
+ GL_QUAD_STRIP = 3, /*!< draw quads with the first quad being defined by 4 vertices, then each additional triangle being defined by 2 vertices. */
+ GL_TRIANGLE = 0, /*!< same as GL_TRIANGLES, old non-OpenGL version */
+ GL_QUAD = 1 /*!< same as GL_QUADS, old non-OpenGL version */
+} GL_GLBEGIN_ENUM;
+
+/*! \brief Enums selecting matrix mode<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A><BR>
+related functions: glMatrixMode() */
+typedef enum {
+ GL_PROJECTION = 0, /*!< used to set the Projection Matrix */
+ GL_POSITION = 1, /*!< used to set the Position Matrix */
+ GL_MODELVIEW = 2, /*!< used to set the Modelview Matrix */
+ GL_TEXTURE = 3 /*!< used to set the Texture Matrix */
+} GL_MATRIX_MODE_ENUM;
+
+/*! \brief Enums for setting up materials<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A><BR>
+related functions: glMaterialf() */
+typedef enum {
+ GL_AMBIENT = 0x01, /*!< sets the ambient color for the material. The color when the normal is not facing light*/
+ GL_DIFFUSE = 0x02, /*!< sets the diffuse color for the material. The color when the normal is facing light */
+ GL_AMBIENT_AND_DIFFUSE = 0x03, /*!< sets the set ambient and diffuse colors for the material; just a two-in-one of the above.*/
+ GL_SPECULAR = 0x04, /*!< sets the specular color for the material. The glossy(highlight) color of the polygon */
+ GL_SHININESS = 0x08, /*!< sets the shininess color for the material. The color that shines back to the user. I have shiny pants! */
+ GL_EMISSION = 0x10 /*!< sets the emission color for the material. bright color that is indepentant of normals and lights*/
+} GL_MATERIALS_ENUM;
+
+/*! \brief Enums for setting how polygons will be displayed<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes</A><BR>
+related functions: glPolyFmt(), glInit(), POLY_ALPHA(), POLY_ID() */
+enum GL_POLY_FORMAT_ENUM {
+ POLY_FORMAT_LIGHT0 = (1<<0), /*!< enable light number 0 */
+ POLY_FORMAT_LIGHT1 = (1<<1), /*!< enable light number 1 */
+ POLY_FORMAT_LIGHT2 = (1<<2), /*!< enable light number 2 */
+ POLY_FORMAT_LIGHT3 = (1<<3), /*!< enable light number 3 */
+ POLY_MODULATION = (0<<4), /*!< enable modulation shading mode; this is the default */
+ POLY_DECAL = (1<<4), /*!< enable decal shading */
+ POLY_TOON_HIGHLIGHT = (2<<4), /*!< enable toon/highlight shading mode */
+ POLY_SHADOW = (3<<4), /*!< enable shadow shading */
+ POLY_CULL_FRONT = (1<<6), /*!< cull front polygons */
+ POLY_CULL_BACK = (2<<6), /*!< cull rear polygons */
+ POLY_CULL_NONE = (3<<6), /*!< don't cull any polygons */
+ POLY_FOG = (1<<15) /*!< enable/disable fog for this polygon */
+};
+
+/*! \brief Enums for size of a texture, specify one for horizontal and one for vertical
+related functions: glTexImage2d(), glTexParameter() */
+enum GL_TEXTURE_SIZE_ENUM {
+ TEXTURE_SIZE_8 = 0, /*!< 8 texels */
+ TEXTURE_SIZE_16 = 1, /*!< 16 texels */
+ TEXTURE_SIZE_32 = 2, /*!< 32 texels */
+ TEXTURE_SIZE_64 = 3, /*!< 64 texels */
+ TEXTURE_SIZE_128 = 4, /*!< 128 texels */
+ TEXTURE_SIZE_256 = 5, /*!< 256 texels */
+ TEXTURE_SIZE_512 = 6, /*!< 512 texels */
+ TEXTURE_SIZE_1024 = 7 /*!< 1024 texels */
+};
+
+/*! \brief Enums for texture parameters, such as texture wrapping and texture coord stuff<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes</A><BR>
+related functions: glTexImage2d(), glTexParameter() */
+enum GL_TEXTURE_PARAM_ENUM {
+ GL_TEXTURE_WRAP_S = (1 << 16), /*!< wrap(repeat) texture on S axis */
+ GL_TEXTURE_WRAP_T = (1 << 17), /*!< wrap(repeat) texture on T axis */
+ GL_TEXTURE_FLIP_S = (1 << 18), /*!< flip texture on S axis when wrapping */
+ GL_TEXTURE_FLIP_T = (1 << 19), /*!< flip texture on T axis when wrapping */
+ GL_TEXTURE_COLOR0_TRANSPARENT = (1<<29), /*!< interpret color 0 as clear, same as old GL_TEXTURE_ALPHA_MASK */
+ TEXGEN_OFF = (0<<30), /*!< use unmodified texcoord */
+ TEXGEN_TEXCOORD = (1<<30), /*!< multiply texcoords by the texture-matrix */
+ TEXGEN_NORMAL = (2<<30), /*!< set texcoords equal to normal * texture-matrix, used for spherical reflection mapping */
+ TEXGEN_POSITION = (3<<30) /*!< set texcoords equal to vertex * texture-matrix */
+};
+
+/*! \brief Enums for texture formats<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureformats">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureformats</A><BR>
+related functions: glTexImage2d(), glTexParameter() */
+typedef enum {
+ GL_RGB32_A3 = 1, /*!< 32 color palette, 3 bits of alpha */
+ GL_RGB4 = 2, /*!< 4 color palette */
+ GL_RGB16 = 3, /*!< 16 color palette */
+ GL_RGB256 = 4, /*!< 256 color palette */
+ GL_COMPRESSED = 5, /*!< compressed texture */
+ GL_RGB8_A5 = 6, /*!< 8 color palette, 5 bits of alpha */
+ GL_RGBA = 7, /*!< 15 bit direct color, 1 bit of alpha */
+ GL_RGB = 8 /*!< 15 bit direct color, manually sets alpha bit to 1 */
+} GL_TEXTURE_TYPE_ENUM;
+
+/*! \brief 3D Display Control Register Enums<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A><BR>
+related functions: glEnable(), glDisable(), glInit() */
+enum DISP3DCNT_ENUM {
+ GL_TEXTURE_2D = (1<<0), /*!< enable/disable textures on the geometry engine */
+ GL_TOON_HIGHLIGHT = (1<<1), /*!< enable = Highlight shading; disable = Toon shading */
+ GL_ALPHA_TEST = (1<<2), /*!< whether to use the alpha threshold set in glAlphaFunc() */
+ GL_BLEND = (1<<3), /*!< enable/disable alpha blending */
+ GL_ANTIALIAS = (1<<4), /*!< nable/disable edge antialiasing; polygons must have different polygon IDs for the effect to work and the rear plane must be clear */
+ GL_OUTLINE = (1<<5), /*!< enable/disable edge coloring; the high 3bits of the polygon ID determine the color; glSetOutlineColor() sets the available colors */
+ GL_FOG_ONLY_ALPHA = (1<<6), /*!< enable = fade into background?; disable = don't fade? */
+ GL_FOG = (1<<7), /*!< enables/disables fog */
+ GL_COLOR_UNDERFLOW = (1<<12), /*!< enable = color buffer underflow, setting resets overflow flag; disable = no color buffer overflow */
+ GL_POLY_OVERFLOW = (1<<13), /*!< enable = polygon/vertex buffer overflow, setting resets overflow flag; disable = no polygon/vertex buffer overflow */
+ GL_CLEAR_BMP = (1<<14) /*!< rear/clear plane is in BMP mode; disable = rear/color plane is in clear mode */
+};
+
+/*! \brief Enums for reading stuff from the geometry engine<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3diomap">http://nocash.emubase.de/gbatek.htm#ds3diomap</A><BR>
+related functions: glGetInt(), glGetFixed()*/
+typedef enum {
+ GL_GET_VERTEX_RAM_COUNT, /*!< returns a count of vertexes currently stored in hardware vertex ram. Use glGetInt() to retrieve */
+ GL_GET_POLYGON_RAM_COUNT, /*!< returns a count of polygons currently stored in hardware polygon ram. Use glGetInt() to retrieve */
+ GL_GET_MATRIX_VECTOR, /*!< returns the current 3x3 directional vector matrix. Use glGetFixed() to retrieve */
+ GL_GET_MATRIX_POSITION, /*!< returns the current 4x4 position matrix. Use glGetFixed() to retrieve */
+ GL_GET_MATRIX_PROJECTION, /*!< returns the current 4x4 projection matrix. Use glGetFixed() to retrieve */
+ GL_GET_MATRIX_CLIP, /*!< returns the current 4x4 clip matrix. Use glGetFixed() to retrieve */
+ GL_GET_TEXTURE_WIDTH, /*!< returns the width of the currently bound texture. Use glGetInt() to retrieve */
+ GL_GET_TEXTURE_HEIGHT /*!< returns the height of the currently bound texture. Use glGetInt() to retrieve */
+} GL_GET_ENUM;
+
+
+/*! \brief Enums for glFlush()<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A><BR>
+related functions: glEnable(), glDisable(), glInit() */
+enum GLFLUSH_ENUM {
+ GL_TRANS_MANUALSORT = (1<<0), /*!< enable manual sorting of translucent polygons, otherwise uses Y-sorting */
+ GL_WBUFFERING = (1<<1) /*!< enable W depth buffering of vertices, otherwise uses Z depth buffering */
+};
+
+
+/*---------------------------------------------------------------------------------
+This struct hold hidden globals for videoGL. The structure is initialized in the
+.c file and returned by glGetGlobals() so that it can be used across compilation
+units without problem. This is automatically done by glInit() so don't worry too
+much about it. This is only an issue because of hte mix of inlined/real functions.
+---------------------------------------------------------------------------------*/
+typedef struct {
+ GL_MATRIX_MODE_ENUM matrixMode; // holds the current Matrix Mode
+
+ // holds the current state of the clear color register
+ uint32 clearColor; // state of clear color register
+
+ // texture globals
+ uint32 textures[MAX_TEXTURES];
+ uint32 activeTexture;
+ uint32* nextBlock;
+ uint32 nextPBlock;
+ int nameCount;
+
+} gl_hidden_globals;
+
+// Pointer to global data for videoGL
+static gl_hidden_globals* glGlob = 0;
+
+//---------------------------------------------------------------------------------
+//Fifo commands
+//---------------------------------------------------------------------------------
+
+#define FIFO_COMMAND_PACK(c1,c2,c3,c4) (((c4) << 24) | ((c3) << 16) | ((c2) << 8) | (c1)) /*!< \brief packs four packed commands into a 32bit command for sending to the GFX FIFO */
+
+#define REG2ID(r) (u8)( ( ((u32)(&(r)))-0x04000400 ) >> 2 ) /*!< \brief converts a GFX command for use in a packed command list */
+
+#define FIFO_NOP REG2ID(GFX_FIFO) /*!< \brief packed command for nothing, just here to pad your command lists */
+#define FIFO_STATUS REG2ID(GFX_STATUS) /*!< \brief packed command for geometry engine status register<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dstatus">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dstatus</A> */
+#define FIFO_COLOR REG2ID(GFX_COLOR) /*!< \brief packed command for vertex color directly<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes</A> */
+
+#define FIFO_VERTEX16 REG2ID(GFX_VERTEX16) /*!< \brief packed command for a vertex with 3 16bit paramaters(and 16bits of padding)<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices</A> */
+#define FIFO_TEX_COORD REG2ID(GFX_TEX_COORD) /*!< \brief packed command for a texture coordinate<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtexturecoordinates">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtexturecoordinates</A> */
+#define FIFO_TEX_FORMAT REG2ID(GFX_TEX_FORMAT) /*!< \brief packed command for texture format<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureformats">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureformats</A> */
+#define FIFO_PAL_FORMAT REG2ID(GFX_PAL_FORMAT) /*!< \brief packed command for texture palette attributes<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes</A> */
+
+#define FIFO_CLEAR_COLOR REG2ID(GFX_CLEAR_COLOR) /*!< \brief packed command for clear color of the rear plane<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3drearplane">GBATEK http://nocash.emubase.de/gbatek.htm#ds3drearplane</A> */
+#define FIFO_CLEAR_DEPTH REG2ID(GFX_CLEAR_DEPTH) /*!< \brief sets depth of the rear plane<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3drearplane">GBATEK http://nocash.emubase.de/gbatek.htm#ds3drearplane</A> */
+
+#define FIFO_LIGHT_VECTOR REG2ID(GFX_LIGHT_VECTOR) /*!< \brief packed command for direction of a light source<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
+#define FIFO_LIGHT_COLOR REG2ID(GFX_LIGHT_COLOR) /*!< \brief packed command for color for a light<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
+#define FIFO_NORMAL REG2ID(GFX_NORMAL) /*!< \brief packed command for normal for following vertices<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
+
+#define FIFO_DIFFUSE_AMBIENT REG2ID(GFX_DIFFUSE_AMBIENT) /*!< \brief packed command for setting diffuse and ambient material properties for the following vertices<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
+#define FIFO_SPECULAR_EMISSION REG2ID(GFX_SPECULAR_EMISSION) /*!< \brief packed command for setting specular and emmissive material properties for the following vertices<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
+#define FIFO_SHININESS REG2ID(GFX_SHININESS) /*!< \brief packed command for setting the shininess table to be used for the following vertices<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
+
+#define FIFO_POLY_FORMAT REG2ID(GFX_POLY_FORMAT) /*!< \brief packed command for setting polygon attributes<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes</A> */
+
+#define FIFO_BEGIN REG2ID(GFX_BEGIN) /*!< \brief packed command that starts a polygon vertex list<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices</A>*/
+#define FIFO_END REG2ID(GFX_END) /*!< \brief packed command that has no discernable effect, it's probably best to never use it since it bloats the size of the list.<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices</A>*/
+#define FIFO_FLUSH REG2ID(GFX_FLUSH) /*!< \brief packed command that has the same effect as swiWaitForVBlank()<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A> */
+#define FIFO_VIEWPORT REG2ID(GFX_VIEWPORT) /*!< \brief packed command for setting viewport<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A> */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*! \brief Rotates the model view matrix by angle about the specified unit vector
+\param angle The angle to rotate by
+\param x X component of the unit vector axis.
+\param y Y component of the unit vector axis.
+\param z Z component of the unit vector axis. */
+void glRotatef32i(int angle, int32 x, int32 y, int32 z);
+
+/*! \brief Loads a 2D texture into texture memory and sets the currently bound texture ID to the attributes specified
+\param target not used, just here for OpenGL compatibility
+\param empty1 not used, just here for OpenGL compatibility
+\param type The format of the texture
+\param sizeX the horizontal size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM
+\param sizeY the vertical size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM
+\param empty2 not used, just here for OpenGL compatibility
+\param param parameters for the texture
+\param texture pointer to the texture data to load */
+int glTexImage2D(int target, int empty1, GL_TEXTURE_TYPE_ENUM type, int sizeX, int sizeY, int empty2, int param, const uint8* texture);
+
+/*! \brief Loads a palette into the specified texture addr
+\param pal pointer to the palette to load
+\param count the size of the palette
+\param addr the offset in VRAM to load the palette */
+void glTexLoadPal(const u16* pal, u16 count, u32 addr );
+
+/*! \brief Loads a palette into the next available palette slot, returns the addr on success or -1
+\param pal pointer to the palette to load
+\param count the size of the palette
+\param format the format of the texture */
+int gluTexLoadPal(const u16* pal, u16 count, uint8 format);
+
+/*! \brief Set parameters for the current texture. Although named the same as its gl counterpart, it is not compatible. Effort may be made in the future to make it so.
+\param sizeX the horizontal size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM
+\param sizeY the vertical size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM
+\param addr offset into VRAM where you put the texture
+\param mode the type of texture
+\param param paramaters for the texture */
+void glTexParameter( uint8 sizeX, uint8 sizeY,
+ const uint32* addr,
+ GL_TEXTURE_TYPE_ENUM mode,
+ uint32 param) ;
+
+/*! \brief Returns the active texture parameter (constructed from internal call to glTexParameter) */
+u32 glGetTexParameter();
+
+/*! \brief returns the address alocated to the texure named by name
+\param name the name of the texture to get a pointer to */
+void* glGetTexturePointer( int name);
+
+/*! \brief glBindTexure sets the current named texture to the active texture. Target is ignored as all DS textures are 2D
+\param target ignored, only here for OpenGL compatability
+\param name the name(int value) to set to the current texture */
+void glBindTexture(int target, int name);
+
+/*! \brief glColorTable establishes the location of the current palette. Roughly follows glColorTableEXT. Association of palettes with named textures is left to the application. */
+void glColorTable(uint8 format, uint32 addr);
+
+/*! \brief Creates room for the specified number of textures
+\param n the number of textures to generate
+\param names pointer to the names array to fill */
+int glGenTextures(int n, int *names);
+
+/*! \brief Resets the gl texture state freeing all texture memory */
+void glResetTextures(void);
+
+/*! \brief Sets texture coordinates for following vertices<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes</A>
+\param u U(a.k.a. S) texture coordinate (0.0 - 1.0)
+\param v V(a.k.a. T) texture coordinate (0.0 - 1.0)*/
+void glTexCoord2f32(int32 u, int32 v);
+
+/*! \brief specify the material properties to be used in rendering lit polygons
+\param mode which material property to change
+\param color the color to set for that material property */
+void glMaterialf(GL_MATERIALS_ENUM mode, rgb color);
+
+// This handles initialization of the GL state; this is called from glInit to keep globals synced between compilation units
+void glInit_C(void);
+
+// This returns a pointer to the globals for videoGL
+gl_hidden_globals* glGetGlobals();
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////
+//////////// ////////////
+//////////// ////////////
+//////////// ////////////
+//////////// INLINED FUNCTIONS ////////////
+//////////// ////////////
+//////////// ////////////
+//////////// ////////////
+//////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////
+
+
+
+/*! \brief used in glPolyFmt() to set the alpha level for the following polygons, set to 0 for wireframe mode
+\param n the level of alpha (0-31) */
+GL_STATIC_INL uint32 POLY_ALPHA(int n) { return (uint32)((n) << 16); };
+
+/*! \brief used in glPolyFmt() to set the Polygon ID for the following polygons
+\param n the ID to set for following polygons (0-63) */
+GL_STATIC_INL uint32 POLY_ID(int n) { return (uint32)((n)<<24); };
+
+/*! \brief Starts a polygon group
+\param mode the draw mode for the polygon */
+GL_STATIC_INL void glBegin(GL_GLBEGIN_ENUM mode) { GFX_BEGIN = mode; }
+
+/*! \brief Ends a polygon group, this seems to be a dummy function that does absolutely nothing, feel free to never use it. */
+GL_STATIC_INL void glEnd(void) { GFX_END = 0; }
+
+/*! \brief reset the depth buffer to this value; generally set this to GL_MAX_DEPTH.<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3drearplane">GBATEK http://nocash.emubase.de/gbatek.htm#ds3drearplane</A>
+\param depth Something to do with the depth buffer, generally set to GL_MAX_DEPTH */
+GL_STATIC_INL void glClearDepth(fixed12d3 depth) { GFX_CLEAR_DEPTH = depth; }
+
+/*! \brief Set the color for following vertices
+\param red the red component (0-31)
+\param green the green component (0-31)
+\param blue the blue component (0-31) */
+
+GL_STATIC_INL void glColor3b(uint8 red, uint8 green, uint8 blue) { GFX_COLOR = (vuint32)RGB15(red>>3, green>>3, blue>>3); }
+
+/*! \brief Set the color for following vertices
+\param color the 15bit color value */
+GL_STATIC_INL void glColor(rgb color) { GFX_COLOR = (vuint32)color; }
+
+/*! \brief specifies a vertex
+\param x the x component for the vertex
+\param y the y component for the vertex
+\param z the z component for the vertex */
+GL_STATIC_INL void glVertex3v16(v16 x, v16 y, v16 z) {
+ GFX_VERTEX16 = (y << 16) | (x & 0xFFFF);
+ GFX_VERTEX16 = ((uint32)(uint16)z);
+}
+
+/*! \brief Sets texture coordinates for following vertices<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes</A>
+\param u U(a.k.a. S) texture coordinate in texels
+\param v V(a.k.a. T) texture coordinate in texels */
+GL_STATIC_INL void glTexCoord2t16(t16 u, t16 v) { GFX_TEX_COORD = TEXTURE_PACK(u,v); }
+
+/*! \brief Pushs the current matrix onto the stack<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack</A> */
+GL_STATIC_INL void glPushMatrix(void) { MATRIX_PUSH = 0; }
+
+/*! \brief Pops num matrices off the stack<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack</A>
+\param num the number to pop down the stack */
+GL_STATIC_INL void glPopMatrix(int32 num) { MATRIX_POP = num; }
+
+/*! \brief Restores the current matrix from a location in the stack<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack</A>
+\param index the place in the stack to restore to */
+GL_STATIC_INL void glRestoreMatrix(int32 index) { MATRIX_RESTORE = index; }
+
+/*! \brief Place the current matrix into the stack at a location<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack</A>
+\param index the place in the stack to put the current matrix */
+GL_STATIC_INL void glStoreMatrix(int32 index) { MATRIX_STORE = index; }
+
+/*! \brief multiply the current matrix by a translation matrix<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
+\param v the vector to translate by */
+GL_STATIC_INL void glScalev(const GLvector* v) {
+ MATRIX_SCALE = v->x;
+ MATRIX_SCALE = v->y;
+ MATRIX_SCALE = v->z;
+}
+
+/*! \brief multiply the current matrix by a translation matrix<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
+\param v the vector to translate by */
+GL_STATIC_INL void glTranslatev(const GLvector* v) {
+ MATRIX_TRANSLATE = v->x;
+ MATRIX_TRANSLATE = v->y;
+ MATRIX_TRANSLATE = v->z;
+}
+
+/*! \brief multiply the current matrix by a translation matrix<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
+\param x translation on the x axis
+\param y translation on the y axis
+\param z translation on the z axis */
+GL_STATIC_INL void glTranslate3f32(int32 x, int32 y, int32 z) {
+ MATRIX_TRANSLATE = x;
+ MATRIX_TRANSLATE = y;
+ MATRIX_TRANSLATE = z;
+}
+
+/*! \brief multiply the current matrix by a scale matrix<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
+\param factor the factor to scale by */
+GL_STATIC_INL void glScalef32(int32 factor) {
+ MATRIX_SCALE = factor;
+ MATRIX_SCALE = factor;
+ MATRIX_SCALE = factor;
+}
+
+/*! \brief set a light up. Only parallel light sources are supported on the DS<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A>
+\param id the number of the light to setup
+\param color the color of the light
+\param x the x component of the lights directional vector. Direction must be normalized
+\param y the y component of the lights directional vector. Direction must be normalized
+\param z the z component of the lights directional vector. Direction must be normalized */
+GL_STATIC_INL void glLight(int id, rgb color, v10 x, v10 y, v10 z) {
+ id = (id & 3) << 30;
+ GFX_LIGHT_VECTOR = id | ((z & 0x3FF) << 20) | ((y & 0x3FF) << 10) | (x & 0x3FF);
+ GFX_LIGHT_COLOR = id | color;
+}
+
+/*! \brief the normal to use for following vertices<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A>
+\warning The nature of the format means that you can't represent the following normals exactly (0,0,1), (0,1,0), or (1,0,0)
+\param normal the packed normal(3 * 10bit x, y, z) */
+GL_STATIC_INL void glNormal(uint32 normal) { GFX_NORMAL = normal; }
+
+/*! \brief loads an identity matrix to the current matrix, same as glIdentity(void) */
+GL_STATIC_INL void glLoadIdentity(void) { MATRIX_IDENTITY = 0; }
+
+/*! \brief change the current matrix mode<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A><BR>
+\param mode the mode for the matrix */
+GL_STATIC_INL void glMatrixMode(GL_MATRIX_MODE_ENUM mode) { MATRIX_CONTROL = mode; }
+
+/*! \brief specify the viewport for following drawing, can be set several times per frame.<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A>
+\param x1 the left of the viewport
+\param y1 the bottom of the viewport
+\param x2 the right of the viewport
+\param y2 the top of the viewport */
+GL_STATIC_INL void glViewport(uint8 x1, uint8 y1, uint8 x2, uint8 y2) { GFX_VIEWPORT = (x1) + (y1 << 8) + (x2 << 16) + (y2 << 24); }
+
+/*! \brief Waits for a Vblank and swaps the buffers(like swiWaitForVBlank), but lets you specify some 3D options<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A>
+\param mode flags from GLFLUSH_ENUM for enabling Y-sorting of translucent polygons and W-Buffering of all vertices*/
+GL_STATIC_INL void glFlush(uint32 mode) { GFX_FLUSH = mode; }
+
+/*! \brief The DS uses a table for shinyness..this generates a half-ass one */
+GL_STATIC_INL void glMaterialShinyness(void) {
+ uint32 shiny32[128/4];
+ uint8 *shiny8 = (uint8*)shiny32;
+
+ int i;
+
+ for (i = 0; i < 128 * 2; i += 2)
+ shiny8[i>>1] = i;
+
+ for (i = 0; i < 128 / 4; i++)
+ GFX_SHININESS = shiny32[i];
+}
+
+/*! \brief throws a packed list of commands into the graphics FIFO via asyncronous DMA<BR>
+The first 32bits is the length of the packed command list, followed by a the packed list.<BR>
+If you want to do this really fast then write your own code that that does this synchronously and only flushes the cache when the list is changed<BR>
+There is sometimes a problem when you pack the GFX_END command into a list, so don't. GFX_END is a dummy command and never needs called<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dgeometrycommands">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dgeometrycommands</A> */
+GL_STATIC_INL void glCallList(const u32* list) {
+ u32 count = *list++;
+
+ // flush the area that we are going to DMA
+ DC_FlushRange(list, count*4);
+
+ // don't start DMAing while anything else is being DMAed because FIFO DMA is touchy as hell
+ // If anyone can explain this better that would be great. -- gabebear
+ while((DMA_CR(0) & DMA_BUSY)||(DMA_CR(1) & DMA_BUSY)||(DMA_CR(2) & DMA_BUSY)||(DMA_CR(3) & DMA_BUSY));
+
+ // send the packed list asynchronously via DMA to the FIFO
+ DMA_SRC(0) = (uint32)list;
+ DMA_DEST(0) = 0x4000400;
+ DMA_CR(0) = DMA_FIFO | count;
+ while(DMA_CR(0) & DMA_BUSY);
+}
+
+/*! \brief Set the parameters for polygons rendered on the current frame<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes</A>
+\param params the paramters to set for the polygons for the current frame. valid paramters are enumerated in GL_POLY_FORMAT_ENUM and in the functions POLY_ALPHA() and POLY_ID() */
+GL_STATIC_INL void glPolyFmt(uint32 params) { GFX_POLY_FORMAT = params; }
+
+/*! \brief Enables various gl states (blend, alpha test, etc..)
+\param bits bit mask of desired attributes, attributes are enumerated in DISP3DCNT_ENUM */
+GL_STATIC_INL void glEnable(int bits) { GFX_CONTROL |= bits; }
+
+/*! \brief Disables various gl states (blend, alpha test, etc..)
+\param bits bit mask of desired attributes, attributes are enumerated in DISP3DCNT_ENUM */
+GL_STATIC_INL void glDisable(int bits) { GFX_CONTROL &= ~bits; }
+
+/*! \brief Loads a 4x4 matrix into the current matrix
+\param m pointer to a 4x4 matrix */
+GL_STATIC_INL void glLoadMatrix4x4(const m4x4 *m) {
+ MATRIX_LOAD4x4 = m->m[0];
+ MATRIX_LOAD4x4 = m->m[1];
+ MATRIX_LOAD4x4 = m->m[2];
+ MATRIX_LOAD4x4 = m->m[3];
+
+ MATRIX_LOAD4x4 = m->m[4];
+ MATRIX_LOAD4x4 = m->m[5];
+ MATRIX_LOAD4x4 = m->m[6];
+ MATRIX_LOAD4x4 = m->m[7];
+
+ MATRIX_LOAD4x4 = m->m[8];
+ MATRIX_LOAD4x4 = m->m[9];
+ MATRIX_LOAD4x4 = m->m[10];
+ MATRIX_LOAD4x4 = m->m[11];
+
+ MATRIX_LOAD4x4 = m->m[12];
+ MATRIX_LOAD4x4 = m->m[13];
+ MATRIX_LOAD4x4 = m->m[14];
+ MATRIX_LOAD4x4 = m->m[15];
+}
+
+/*! \brief Loads a 4x3 matrix into the current matrix
+\param m pointer to a 4x4 matrix */
+GL_STATIC_INL void glLoadMatrix4x3(const m4x3 * m) {
+ MATRIX_LOAD4x3 = m->m[0];
+ MATRIX_LOAD4x3 = m->m[1];
+ MATRIX_LOAD4x3 = m->m[2];
+ MATRIX_LOAD4x3 = m->m[3];
+
+ MATRIX_LOAD4x3 = m->m[4];
+ MATRIX_LOAD4x3 = m->m[5];
+ MATRIX_LOAD4x3 = m->m[6];
+ MATRIX_LOAD4x3 = m->m[7];
+
+ MATRIX_LOAD4x3 = m->m[8];
+ MATRIX_LOAD4x3 = m->m[9];
+ MATRIX_LOAD4x3 = m->m[10];
+ MATRIX_LOAD4x3 = m->m[11];
+}
+
+/*! \brief Multiplies the current matrix by m
+\param m pointer to a 4x4 matrix */
+GL_STATIC_INL void glMultMatrix4x4(const m4x4 * m) {
+ MATRIX_MULT4x4 = m->m[0];
+ MATRIX_MULT4x4 = m->m[1];
+ MATRIX_MULT4x4 = m->m[2];
+ MATRIX_MULT4x4 = m->m[3];
+
+ MATRIX_MULT4x4 = m->m[4];
+ MATRIX_MULT4x4 = m->m[5];
+ MATRIX_MULT4x4 = m->m[6];
+ MATRIX_MULT4x4 = m->m[7];
+
+ MATRIX_MULT4x4 = m->m[8];
+ MATRIX_MULT4x4 = m->m[9];
+ MATRIX_MULT4x4 = m->m[10];
+ MATRIX_MULT4x4 = m->m[11];
+
+ MATRIX_MULT4x4 = m->m[12];
+ MATRIX_MULT4x4 = m->m[13];
+ MATRIX_MULT4x4 = m->m[14];
+ MATRIX_MULT4x4 = m->m[15];
+}
+
+/*! \brief multiplies the current matrix by
+\param m pointer to a 4x3 matrix */
+GL_STATIC_INL void glMultMatrix4x3(const m4x3 * m) {
+ MATRIX_MULT4x3 = m->m[0];
+ MATRIX_MULT4x3 = m->m[1];
+ MATRIX_MULT4x3 = m->m[2];
+ MATRIX_MULT4x3 = m->m[3];
+
+ MATRIX_MULT4x3 = m->m[4];
+ MATRIX_MULT4x3 = m->m[5];
+ MATRIX_MULT4x3 = m->m[6];
+ MATRIX_MULT4x3 = m->m[7];
+
+ MATRIX_MULT4x3 = m->m[8];
+ MATRIX_MULT4x3 = m->m[9];
+ MATRIX_MULT4x3 = m->m[10];
+ MATRIX_MULT4x3 = m->m[11];
+
+}
+
+/*! \brief multiplies the current matrix by m
+\param m pointer to a 3x3 matrix */
+GL_STATIC_INL void glMultMatrix3x3(const m3x3 * m) {
+ MATRIX_MULT3x3 = m->m[0];
+ MATRIX_MULT3x3 = m->m[1];
+ MATRIX_MULT3x3 = m->m[2];
+
+ MATRIX_MULT3x3 = m->m[3];
+ MATRIX_MULT3x3 = m->m[4];
+ MATRIX_MULT3x3 = m->m[5];
+
+ MATRIX_MULT3x3 = m->m[6];
+ MATRIX_MULT3x3 = m->m[7];
+ MATRIX_MULT3x3 = m->m[8];
+}
+
+/*! \brief Rotates the current modelview matrix by angle about the x axis
+\param angle The angle to rotate by (angle is 0-511) */
+GL_STATIC_INL void glRotateXi(int angle) {
+ int32 sine = SIN[angle & LUT_MASK];
+ int32 cosine = COS[angle & LUT_MASK];
+
+ MATRIX_MULT3x3 = inttof32(1);
+ MATRIX_MULT3x3 = 0;
+ MATRIX_MULT3x3 = 0;
+
+ MATRIX_MULT3x3 = 0;
+ MATRIX_MULT3x3 = cosine;
+ MATRIX_MULT3x3 = sine;
+
+ MATRIX_MULT3x3 = 0;
+ MATRIX_MULT3x3 = -sine;
+ MATRIX_MULT3x3 = cosine;
+}
+
+/*! \brief Rotates the current modelview matrix by angle about the y axis
+\param angle The angle to rotate by (angle is 0-511) */
+GL_STATIC_INL void glRotateYi(int angle) {
+ int32 sine = SIN[angle & LUT_MASK];
+ int32 cosine = COS[angle & LUT_MASK];
+
+ MATRIX_MULT3x3 = cosine;
+ MATRIX_MULT3x3 = 0;
+ MATRIX_MULT3x3 = -sine;
+
+ MATRIX_MULT3x3 = 0;
+ MATRIX_MULT3x3 = inttof32(1);
+ MATRIX_MULT3x3 = 0;
+
+ MATRIX_MULT3x3 = sine;
+ MATRIX_MULT3x3 = 0;
+ MATRIX_MULT3x3 = cosine;
+}
+
+/*! \brief Rotates the current modelview matrix by angle about the z axis
+\param angle The angle to rotate by (angle is 0-511) */
+GL_STATIC_INL void glRotateZi(int angle) {
+ int32 sine = SIN[angle & LUT_MASK];
+ int32 cosine = COS[angle & LUT_MASK];
+
+ MATRIX_MULT3x3 = cosine;
+ MATRIX_MULT3x3 = sine;
+ MATRIX_MULT3x3 = 0;
+
+ MATRIX_MULT3x3 = - sine;
+ MATRIX_MULT3x3 = cosine;
+ MATRIX_MULT3x3 = 0;
+
+ MATRIX_MULT3x3 = 0;
+ MATRIX_MULT3x3 = 0;
+ MATRIX_MULT3x3 = inttof32(1);
+}
+
+
+/*! \brief Multiplies the current matrix into ortho graphic mode
+\param left left vertical clipping plane
+\param right right vertical clipping plane
+\param bottom bottom vertical clipping plane
+\param top top vertical clipping plane
+\param zNear near clipping plane
+\param zFar far clipping plane */
+GL_STATIC_INL void glOrthof32(int32 left, int32 right, int32 bottom, int32 top, int32 zNear, int32 zFar) {
+ MATRIX_MULT4x4 = divf32(inttof32(2), right - left);
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = 0;
+
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = divf32(inttof32(2), top - bottom);
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = 0;
+
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = divf32(inttof32(-2), zFar - zNear);
+ MATRIX_MULT4x4 = 0;
+
+ MATRIX_MULT4x4 = -divf32(right + left, right - left);//0;
+ MATRIX_MULT4x4 = -divf32(top + bottom, top - bottom); //0;
+ MATRIX_MULT4x4 = -divf32(zFar + zNear, zFar - zNear);//0;
+ MATRIX_MULT4x4 = floattof32(1.0F);
+}
+
+/*! \brief Places the camera at the specified location and orientation (fixed point version)
+\param eyex (eyex, eyey, eyez) Location of the camera.
+\param eyey (eyex, eyey, eyez) Location of the camera.
+\param eyez (eyex, eyey, eyez) Location of the camera.
+\param lookAtx (lookAtx, lookAty, lookAtz) Where the camera is looking.
+\param lookAty (lookAtx, lookAty, lookAtz) Where the camera is looking.
+\param lookAtz (lookAtx, lookAty, lookAtz) Where the camera is looking.
+\param upx <upx, upy, upz> Unit vector describing which direction is up for the camera.
+\param upy <upx, upy, upz> Unit vector describing which direction is up for the camera.
+\param upz <upx, upy, upz> Unit vector describing which direction is up for the camera. */
+GL_STATIC_INL void gluLookAtf32(int32 eyex, int32 eyey, int32 eyez, int32 lookAtx, int32 lookAty, int32 lookAtz, int32 upx, int32 upy, int32 upz) {
+ int32 side[3], forward[3], up[3], eye[3];
+
+ forward[0] = eyex - lookAtx;
+ forward[1] = eyey - lookAty;
+ forward[2] = eyez - lookAtz;
+
+ normalizef32(forward);
+
+ up[0] = upx;
+ up[1] = upy;
+ up[2] = upz;
+ eye[0] = eyex;
+ eye[1] = eyey;
+ eye[2] = eyez;
+
+ crossf32(up, forward, side);
+
+ normalizef32(side);
+
+ // Recompute local up
+ crossf32(forward, side, up);
+
+ glMatrixMode(GL_MODELVIEW);
+
+
+ // should we use MATRIX_MULT4x3?
+ MATRIX_MULT4x3 = side[0];
+ MATRIX_MULT4x3 = up[0];
+ MATRIX_MULT4x3 = forward[0];
+
+ MATRIX_MULT4x3 = side[1];
+ MATRIX_MULT4x3 = up[1];
+ MATRIX_MULT4x3 = forward[1];
+
+ MATRIX_MULT4x3 = side[2];
+ MATRIX_MULT4x3 = up[2];
+ MATRIX_MULT4x3 = forward[2];
+
+ MATRIX_MULT4x3 = -dotf32(eye,side);
+ MATRIX_MULT4x3 = -dotf32(eye,up);
+ MATRIX_MULT4x3 = -dotf32(eye,forward);
+
+}
+
+
+/*! \brief Specifies the viewing frustum for the projection matrix (fixed point version)
+\param left left right top and bottom describe a rectangle located at the near clipping plane
+\param right left right top and bottom describe a rectangle located at the near clipping plane
+\param top left right top and bottom describe a rectangle located at the near clipping plane
+\param bottom left right top and bottom describe a rectangle located at the near clipping plane
+\param near Location of a the near clipping plane (parallel to viewing window)
+\param far Location of a the far clipping plane (parallel to viewing window) */
+GL_STATIC_INL void glFrustumf32(int32 left, int32 right, int32 bottom, int32 top, int32 near, int32 far) {
+/* MATRIX_MULT4x4 = divf32(2*near, right - left);
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = divf32(right + left, right - left);
+ MATRIX_MULT4x4 = 0;
+
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = divf32(2*near, top - bottom);
+ MATRIX_MULT4x4 = divf32(top + bottom, top - bottom);
+ MATRIX_MULT4x4 = 0;
+
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = -divf32(far + near, far - near);
+ MATRIX_MULT4x4 = floattof32(-1.0F);
+ MATRIX_MULT4x4 = 0;
+
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = -divf32(2 * mulf32(far, near), far - near);
+ MATRIX_MULT4x4 = 0;
+*/
+
+
+ MATRIX_MULT4x4 = divf32(2*near, right - left);
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = 0;
+
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = divf32(2*near, top - bottom);
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = 0;
+
+ MATRIX_MULT4x4 = divf32(right + left, right - left);
+ MATRIX_MULT4x4 = divf32(top + bottom, top - bottom);
+ MATRIX_MULT4x4 = -divf32(far + near, far - near);
+ MATRIX_MULT4x4 = floattof32(-1.0F);
+
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = -divf32(2 * mulf32(far, near), far - near);
+ MATRIX_MULT4x4 = 0;
+
+}
+
+/*! \brief Utility function which sets up the projection matrix (fixed point version)
+\param fovy Specifies the field of view in degrees (0 -511)
+\param aspect Specifies the aspect ratio of the screen (normally screen width/screen height)
+\param zNear Specifies the near clipping plane
+\param zFar Specifies the far clipping plane */
+GL_STATIC_INL void gluPerspectivef32(int fovy, int32 aspect, int32 zNear, int32 zFar) {
+ int32 xmin, xmax, ymin, ymax;
+
+ ymax = mulf32(zNear, TAN[(fovy>>1) & LUT_MASK]);
+ ymin = -ymax;
+ xmin = mulf32(ymin, aspect);
+ xmax = mulf32(ymax, aspect);
+
+ glFrustumf32(xmin, xmax, ymin, ymax, zNear, zFar);
+}
+
+/*! \brief Utility function which generates a picking matrix for selection
+\param x 2D x of center (touch x normally)
+\param y 2D y of center (touch y normally)
+\param width width in pixels of the window (3 or 4 is a good number)
+\param height height in pixels of the window (3 or 4 is a good number)
+\param viewport the current viewport (normaly {0, 0, 255, 191}) */
+GL_STATIC_INL void gluPickMatrix(int x, int y, int width, int height, const int viewport[4]) {
+ MATRIX_MULT4x4 = inttof32(viewport[2]) / width;
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = inttof32(viewport[3]) / height;
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = inttof32(1);
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = inttof32(viewport[2] + ((viewport[0] - x)<<1)) / width;
+ MATRIX_MULT4x4 = inttof32(viewport[3] + ((viewport[1] - y)<<1)) / height;
+ MATRIX_MULT4x4 = 0;
+ MATRIX_MULT4x4 = inttof32(1);
+}
+
+/*! \brief Resets matrix stack to top level */
+GL_STATIC_INL void glResetMatrixStack(void) {
+ // make sure there are no push/pops that haven't executed yet
+ while(GFX_STATUS & BIT(14)){
+ GFX_STATUS |= 1 << 15; // clear push/pop errors or push/pop busy bit never clears
+ }
+
+ // pop the projection stack to the top; poping 0 off an empty stack causes an error... weird?
+ if((GFX_STATUS&(1<<13))!=0) {
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix(1);
+ }
+
+ // 31 deep modelview matrix; 32nd entry works but sets error flag
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix((GFX_STATUS >> 8) & 0x1F);
+
+ // load identity to all the matrices
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glMatrixMode(GL_TEXTURE);
+ glLoadIdentity();
+}
+
+/*! \brief Specifies an edge color for polygons
+\param id which outline color to set (0-7)
+\param color the 15bit color to set */
+GL_STATIC_INL void glSetOutlineColor(int id, rgb color) { GFX_EDGE_TABLE[id] = color; }
+
+/*! \brief Loads a toon table
+\param pointer to the 32 color palette to load into the toon table*/
+GL_STATIC_INL void glSetToonTable(const uint16 *table) {
+ int i;
+ for(i = 0; i < 32; i++ )
+ GFX_TOON_TABLE[i] = table[i];
+}
+
+/*! \brief Sets a range of colors on the toon table
+\param start the start of the range
+\param end the end of the range
+\param color the color to set for that range */
+GL_STATIC_INL void glSetToonTableRange(int start, int end, rgb color) {
+ int i;
+ for(i = start; i <= end; i++ )
+ GFX_TOON_TABLE[i] = color;
+}
+
+/*! \brief Grabs fixed format of state variables<BR>
+OpenGL's modelview matrix is handled on the DS with two matrices. The combination of the DS's position matrix and directional vector matrix hold the data that is in OpenGL's one modelview matrix. (a.k.a. modelview = postion and vector)<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3diomap">http://nocash.emubase.de/gbatek.htm#ds3diomap</A>
+\param param The state variable to retrieve
+\param f pointer with room to hold the requested data */
+GL_STATIC_INL void glGetFixed(const GL_GET_ENUM param, int32* f) {
+ int i;
+ switch (param) {
+ case GL_GET_MATRIX_VECTOR:
+ while(GFX_BUSY); // wait until the graphics engine has stopped to read matrixes
+ for(i = 0; i < 9; i++) f[i] = MATRIX_READ_VECTOR[i];
+ break;
+ case GL_GET_MATRIX_CLIP:
+ while(GFX_BUSY); // wait until the graphics engine has stopped to read matrixes
+ for(i = 0; i < 16; i++) f[i] = MATRIX_READ_CLIP[i];
+ break;
+ case GL_GET_MATRIX_PROJECTION:
+ glMatrixMode(GL_POSITION);
+ glPushMatrix(); // save the current state of the position matrix
+ glLoadIdentity(); // load an identity matrix into the position matrix so that the clip matrix = projection matrix
+ while(GFX_BUSY); // wait until the graphics engine has stopped to read matrixes
+ for(i = 0; i < 16; i++) f[i] = MATRIX_READ_CLIP[i]; // read out the projection matrix
+ glPopMatrix(1); // restore the position matrix
+ break;
+ case GL_GET_MATRIX_POSITION:
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix(); // save the current state of the projection matrix
+ glLoadIdentity(); // load a identity matrix into the projection matrix so that the clip matrix = position matrix
+ while(GFX_BUSY); // wait until the graphics engine has stopped to read matrixes
+ for(i = 0; i < 16; i++) f[i] = MATRIX_READ_CLIP[i]; // read out the position matrix
+ glPopMatrix(1); // restore the projection matrix
+ break;
+ default:
+ break;
+ }
+}
+
+/*! \brief set the minimum alpha value that will be used<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A>
+\param alphaThreshold minimum alpha value that will be used (0-15) */
+GL_STATIC_INL void glAlphaFunc(int alphaThreshold) { GFX_ALPHA_TEST = alphaThreshold; }
+
+/*! \brief Stop the drawing of polygons that are a certain distance from the camera.<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A>
+\param polygons that are beyond this W-value(distance from camera) will not be drawn; 15bit value. */
+GL_STATIC_INL void glCutoffDepth(fixed12d3 wVal) { GFX_CUTOFF_DEPTH = wVal; }
+
+/*! \brief Initializes the gl state machine (must be called once before using gl calls) */
+GL_STATIC_INL void glInit() {
+ glGlob = glGetGlobals(); // make sure globals are synced between compilation units
+ glInit_C(); // actually does the initialization
+}
+
+/*! \brief sets the color of the rear-plane(a.k.a Clear Color/Plane)
+\param red component (0-31)
+\param green component (0-31)
+\param blue component (0-31)
+\param alpha from 0(clear) to 31(opaque)*/
+GL_STATIC_INL void glClearColor(uint8 red, uint8 green, uint8 blue, uint8 alpha) {
+ GFX_CLEAR_COLOR = glGlob->clearColor = ( glGlob->clearColor & 0xFFE08000) | (0x7FFF & RGB15(red, green, blue)) | ((alpha & 0x1F) << 16);
+}
+
+/*! \brief sets the polygon ID of the rear-plane(a.k.a. Clear/Color Plane), useful for antialiasing and edge coloring
+\param ID the polygon ID to give the rear-plane */
+GL_STATIC_INL void glClearPolyID(uint8 ID) {
+ GFX_CLEAR_COLOR = glGlob->clearColor = ( glGlob->clearColor & 0xC0FFFFFF) | (( ID & 0x3F ) << 24 );
+}
+
+/*! \brief Grabs integer state variables from openGL
+\param param The state variable to retrieve
+\param i pointer with room to hold the requested data */
+GL_STATIC_INL void glGetInt(GL_GET_ENUM param, int* i) {
+ switch (param) {
+ case GL_GET_POLYGON_RAM_COUNT:
+ *i = GFX_POLYGON_RAM_USAGE;
+ break;
+ case GL_GET_VERTEX_RAM_COUNT:
+ *i = GFX_VERTEX_RAM_USAGE;
+ break;
+ case GL_GET_TEXTURE_WIDTH:
+ *i = 8 << (((glGlob->textures[glGlob->activeTexture]) >> 20) & 7);
+ break;
+ case GL_GET_TEXTURE_HEIGHT:
+ *i = 8 << (((glGlob->textures[glGlob->activeTexture]) >> 23) & 7);
+ break;
+ default:
+ break;
+ }
+}
+
+
+//---------------------------------------------------------------------------------
+// INLINED FlOAT WRAPPERS
+//
+// All floating point functions.
+//
+
+/*! \brief specifies a vertex location
+\warning FLOAT VERSION!!!! please use glVertex3v16()
+\param x the x component of the vertex
+\param y the y component of the vertex
+\param z the z component of the vertex */
+GL_STATIC_INL void glVertex3f(float x, float y, float z) {
+ glVertex3v16(floattov16(x), floattov16(y), floattov16(z));
+}
+
+/*! \brief Rotate on an arbitrary axis
+\warning FLOAT VERSION!!!! please use glRotatef32i()
+\param angle the angle to rotate by
+\param x the x component of the axis to rotate on
+\param y the y component of the axis to rotate on
+\param z the z component of the axis to rotate on */
+GL_STATIC_INL void glRotatef32(float angle, int32 x, int32 y, int32 z) {
+ glRotatef32i((int)(angle * LUT_SIZE / 360.0), x, y, z);
+}
+
+/*! \brief Rotate about an arbitrary axis
+\warning FLOAT VERSION!!!! please use glRotatef32i()
+\param angle the angle to rotate by
+\param x the x component of the axis to rotate on
+\param y the y component of the axis to rotate on
+\param z the z component of the axis to rotate on */
+GL_STATIC_INL void glRotatef(float angle, float x, float y, float z) {
+ glRotatef32(angle, floattof32(x), floattof32(y), floattof32(z));
+}
+
+/*! \brief specify a color for following vertices
+\warning FLOAT VERSION!!!! please use glColor3b()
+\param r the red component of the color
+\param g the green component of the color
+\param b the blue component of the color */
+GL_STATIC_INL void glColor3f(float r, float g, float b) {
+ glColor3b((uint8)(r*255), (uint8)(g*255), (uint8)(b*255));
+}
+
+/*! \brief multiply the current matrix by a scale matrix<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
+\warning FLOAT VERSION!!!! please use glScalev() or glScalef32()
+\param x scaling on the x axis
+\param y scaling on the y axis
+\param z scaling on the z axis */
+GL_STATIC_INL void glScalef(float x, float y, float z) {
+ MATRIX_SCALE = floattof32(x);
+ MATRIX_SCALE = floattof32(y);
+ MATRIX_SCALE = floattof32(z);
+}
+
+/*! \brief multiply the current matrix by a translation matrix<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
+\warning FLOAT VERSION!!!! please use glTranslate3f32()
+\param x translation on the x axis
+\param y translation on the y axis
+\param z translation on the z axis */
+GL_STATIC_INL void glTranslatef(float x, float y, float z) {
+ MATRIX_TRANSLATE = floattof32(x);
+ MATRIX_TRANSLATE = floattof32(y);
+ MATRIX_TRANSLATE = floattof32(z);
+}
+
+/*! \brief the normal to use for following vertices<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A>
+\warning FLOAT VERSION!!!! please use glNormal()
+\param x x component of the normal, vector must be normalized
+\param y y component of the normal, vector must be normalized
+\param z z component of the normal, vector must be normalized */
+GL_STATIC_INL void glNormal3f(float x, float y, float z) {
+ glNormal(NORMAL_PACK(floattov10(x), floattov10(y), floattov10(z)));
+}
+
+/*! \brief Rotates the current modelview matrix by angle degrees about the x axis
+\warning FLOAT VERSION!!!! please use glRotateXi()
+\param angle The angle to rotate by */
+GL_STATIC_INL void glRotateX(float angle) {
+ glRotateXi((int)(angle * LUT_SIZE / 360.0));
+}
+
+/*! \brief Rotates the current modelview matrix by angle degrees about the y axis
+\warning FLOAT VERSION!!!! please use glRotateYi()
+\param angle The angle to rotate by */
+GL_STATIC_INL void glRotateY(float angle) {
+ glRotateYi((int)(angle * LUT_SIZE / 360.0));
+}
+
+/*! \brief Rotates the current modelview matrix by angle degrees about the z axis
+\warning FLOAT VERSION!!!! please use glRotateZi()
+\param angle The angle to rotate by */
+GL_STATIC_INL void glRotateZ(float angle) {
+ glRotateZi((int)(angle * LUT_SIZE / 360.0));
+}
+
+/*! \brief Multiplies the current matrix into ortho graphic mode
+\warning FLOAT VERSION!!!! please use glOrthof32()
+\param left left vertical clipping plane
+\param right right vertical clipping plane
+\param bottom bottom vertical clipping plane
+\param top top vertical clipping plane
+\param zNear near clipping plane
+\param zFar far clipping plane */
+GL_STATIC_INL void glOrtho(float left, float right, float bottom, float top, float zNear, float zFar) {
+ glOrthof32(floattof32(left), floattof32(right), floattof32(bottom), floattof32(top), floattof32(zNear), floattof32(zFar));
+}
+
+/*! \brief Places the camera at the specified location and orientation (floating point version)
+\warning FLOAT VERSION!!!! please use gluLookAtf32()
+\param eyex (eyex, eyey, eyez) Location of the camera.
+\param eyey (eyex, eyey, eyez) Location of the camera.
+\param eyez (eyex, eyey, eyez) Location of the camera.
+\param lookAtx (lookAtx, lookAty, lookAtz) Where the camera is looking.
+\param lookAty (lookAtx, lookAty, lookAtz) Where the camera is looking.
+\param lookAtz (lookAtx, lookAty, lookAtz) Where the camera is looking.
+\param upx <upx, upy, upz> Unit vector describing which direction is up for the camera.
+\param upy <upx, upy, upz> Unit vector describing which direction is up for the camera.
+\param upz <upx, upy, upz> Unit vector describing which direction is up for the camera. */
+GL_STATIC_INL void gluLookAt( float eyex, float eyey, float eyez,
+ float lookAtx, float lookAty, float lookAtz,
+ float upx, float upy, float upz) {
+ gluLookAtf32(floattof32(eyex), floattof32(eyey), floattof32(eyez),
+ floattof32(lookAtx), floattof32(lookAty), floattof32(lookAtz),
+ floattof32(upx), floattof32(upy), floattof32(upz));
+}
+
+/*! \brief Specifies the viewing frustum for the projection matrix (floating point version)
+\warning FLOAT VERSION!!!! please use glFrustumf32()
+\param left left right top and bottom describe a rectangle located at the near clipping plane
+\param right left right top and bottom describe a rectangle located at the near clipping plane
+\param top left right top and bottom describe a rectangle located at the near clipping plane
+\param bottom left right top and bottom describe a rectangle located at the near clipping plane
+\param near Location of a the near clipping plane (parallel to viewing window)
+\param far Location of a the far clipping plane (parallel to viewing window) */
+GL_STATIC_INL void glFrustum(float left, float right, float bottom, float top, float near, float far) {
+ glFrustumf32(floattof32(left), floattof32(right), floattof32(bottom), floattof32(top), floattof32(near), floattof32(far));
+}
+
+/*! \brief Utility function which sets up the projection matrix (floating point version)
+\warning FLOAT VERSION!!!! please use gluPerspectivef32()
+\param fovy Specifies the field of view in degrees
+\param aspect Specifies the aspect ratio of the screen (normally screen width/screen height)
+\param zNear Specifies the near clipping plane
+\param zFar Specifies the far clipping plane */
+GL_STATIC_INL void gluPerspective(float fovy, float aspect, float zNear, float zFar) {
+ gluPerspectivef32((int)(fovy * LUT_SIZE / 360.0), floattof32(aspect), floattof32(zNear), floattof32(zFar));
+}
+
+/*! \brief Sets texture coordinates for following vertices<BR>
+<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes</A>
+\warning FLOAT VERSION!!!! please use glTexCoord2t16()
+\param s S(a.k.a. U) texture coordinate (0.0 - 1.0)
+\param t T(a.k.a. V) texture coordinate (0.0 - 1.0)*/
+GL_STATIC_INL void glTexCoord2f(float s, float t) {
+ int x = ((glGlob->textures[glGlob->activeTexture]) >> 20) & 7;
+ int y = ((glGlob->textures[glGlob->activeTexture]) >> 23) & 7;
+
+ glTexCoord2t16(floattot16(s*(8 << x)), floattot16(t*(8<<y)));
+}
+
+
+#endif // #ifndef VIDEOGL_ARM9_INCLUDE
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/bios.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/bios.h
index 1e8c73eb38..c439bf24df 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/bios.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/bios.h
@@ -1,367 +1,367 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- BIOS functions
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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.
-
----------------------------------------------------------------------------------*/
-
-#ifndef BIOS_H_INCLUDE
-#define BIOS_H_INCLUDE
-
-/*! \file bios.h
-
- \brief Nintendo DS Bios functions
-*/
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#include <nds/jtypes.h>
-
-
-typedef struct DecompressionStream {
- int (*getSize)(uint8 * source, uint16 * dest, uint32 r2);
- int (*getResult)(uint8 * source); // can be NULL
- uint8 (*readByte)(uint8 * source);
-} PACKED TDecompressionStream;
-
-
-typedef struct UnpackStruct {
- uint16 sourceSize; // in bytes
- uint8 sourceWidth;
- uint8 destWidth;
- uint32 dataOffset;
-} PACKED TUnpackStruct, * PUnpackStruct;
-
-
-/*! \fn swiSoftReset()
- \brief reset the DS.
-
-*/
-void swiSoftReset(void);
-
-/*! \fn swiDelay( uint32 duration)
- \brief delay
-
- Delays for for a period X + Y*duration where X is the swi overhead and Y is a cycle of
-<CODE><PRE>
- loop:
- sub r0, #1
- bgt loop
-</PRE></CODE>
- of thumb fetches in BIOS memory
- \param duration
- length of delay
- \note
- Duration should be 1 or more, a duration of 0 is a huge delay
-
-*/
-void swiDelay(uint32 duration);
-
-/*! \fn swiIntrWait(int waitForSet, uint32 flags)
-
- \brief wait for interrupt(s) to occur
-
- \param waitForSet
- 0: Return if the interrupt has already occured
- 1: Wait until the interrupt has been set since the call
- \param flags
- interrupt mask to wait for
-
-*/
-
-void swiIntrWait(int waitForSet, uint32 flags);
-
-/*! \fn swiWaitForVBlank()
- \brief Wait for vblank interrupt
-
- Waits for a vertical blank interrupt
-
- \note Identical to calling swiIntrWait(1, 1)
-*/
-
-void swiWaitForVBlank(void);
-
-/*! \fn int swiDivide(int numerator, int divisor)
- \param numerator
- signed integer to divide
- \param divisor
- signed integer to divide by
- \return numerator / divisor
-
- \fn int swiRemainder(int numerator, int divisor)
- \param numerator
- signed integer to divide
- \param divisor
- signed integer to divide by
- \return numerator % divisor
-
- \fn void swiDivMod(int numerator, int divisor, int * result, int * remainder)
- \param numerator
- signed integer to divide
- \param divisor
- signed integer to divide by
- \param result
- pointer to integer set to numerator / divisor
- \param remainder
- pointer to integer set to numerator % divisor
-*/
-
-int swiDivide(int numerator, int divisor);
-int swiRemainder(int numerator, int divisor);
-void swiDivMod(int numerator, int divisor, int * result, int * remainder);
-
-/*! \fn swiCopy(const void * source, void * dest, int flags)
- \param source
- pointer to transfer source
- \param dest
- dest = pointer to transfer destination
- \param flags
- copy mode and size
-// flags(26) = transfer width (0: halfwords, 1: words)
-// flags(24) = transfer mode (0: copy, 1: fill)
-// flags(20..0) = transfer count (always in words)
-
- \fn swiFastCopy (const void * source, void * dest, int flags)
- \param source
- pointer to transfer source
- \param dest
- dest = pointer to transfer destination
- \param flags
- copy mode and size
-// flags(24) = transfer mode (0: copy, 1: fill)
-// flags(20..0) = transfer count (in words)
-
- \note Transfers more quickly than swiCopy, but has higher interrupt latency
-*/
-
-#define COPY_MODE_HWORD (0)
-#define COPY_MODE_WORD (1<<26)
-#define COPY_MODE_COPY (0)
-#define COPY_MODE_FILL (1<<24)
-
-void swiCopy(const void * source, void * dest, int flags);
-void swiFastCopy(const void * source, void * dest, int flags);
-
-// swiSqrt (swi 0x0D)
-
-int swiSqrt(int value);
-
-// swiCRC16(uint16 crc, void * data, uint32 size) (swi 0x0E)
-// crc - starting CRC-16
-// data - pointer to data (processed nibble by nibble)
-// size - size in bytes
-//
-// Returns the CRC-16 after the data has been processed
-
-uint16 swiCRC16(uint16 crc, void * data, uint32 size);
-
-// int swiIsDebugger(void)
-// Returns 0 if running on a debugger (8 MB of ram instead of 4 MB)
-//
-// Note: swi 0x0F on both CPUs
-
-int swiIsDebugger(void);
-
-// swiUnpackBits
-// source - Source address
-// destination - destination address (word aligned)
-// params - Unpack structure
-// uint16 sourceSize (in bytes)
-// uint8 sourceWidth (1,2,4,8)
-// uint8 destWidth (1,2,4,8,16,32)
-// uint32 dataOffset (bits 0..30 are added to all non-zero
-// destination writes, unless b31 is set,
-// which does it for zeros too)
-//
-// Unpack data stored multiple elements to a byte into a larger space
-// i.e. 8 elements per byte (i.e. b/w font), into 1 element per byte
-//
-// Note: swi 0x10 on both CPUs
-
-void swiUnpackBits(uint8 * source, uint32 * destination, PUnpackStruct params);
-
-// DecompressLZSSWram (swi 0x11)
-// source - pointer to a header word, followed by compressed data
-// word(31..8) = size of uncompressed data (in bytes)
-// word(7..0) = ignored
-// destination - destination address
-// Writes data a byte at a time
-//
-// DecompressLZSSVram (swi 0x12)
-// Writes data a halfword at a time
-// See DecompressRLEVram for parameter details
-
-void swiDecompressLZSSWram(void * source, void * destination);
-int swiDecompressLZSSVram(void * source, void * destination, uint32 toGetSize, TDecompressionStream * stream);
-
-// swiDecompressHuffman (swi 0x13)
-// See DecompressRLE for parameter details
-
-int swiDecompressHuffman(void * source, void * destination, uint32 toGetSize, TDecompressionStream * stream);
-
-// DecompressRLEWram (swi 0x14)
-// r0 - pointer to a header word, followed by compressed data
-// word(31..8) = size of uncompressed data (in bytes)
-// word(7..0) = ignored
-// r1 - destination address
-// Writes data a byte at a time
-//
-// DecompressRLEVram (swi 0x15)
-// r0 - pointer to compressed source data, maybe! (always goes through
-// the function pointers, so could just be an offset)
-// r1 - pointer to destination (halfword)
-// r2 - no idea, passed to getSize function
-// r3 - pointer to a structure
-// Writes data a halfword at a time
-//
-// Result of getSize is a word, with the size of decompressed data in
-// bits 31..8, and bits 7..0 are ignored. This value is also returned
-// by the swi, unless getResult is non-NULL and returns a neg. value
-//
-// getResult is used to provide a result for the swi, given the source
-// pointer after all data has been read (or if getSize < 0). It can
-// be NULL, unlike getSize and readByte. Its value is only returned
-// if negative, otherwise the typical result is used, so it is likely
-// some sort of error-checking procedure
-//
-// readByte is used in lieu of directly accessing memory
-//
-// compressed data format:
-// bit(7): 0: uncompressed, 1: compressed
-// bit(6..0) when uncompressed: run length - 1, followed by run_length bytes of true data
-// bit(6..0) when compressed: run length - 3, followed by one byte of true data, to be repeated
-
-void swiDecompressRLEWram(void * source, void * destination);
-int swiDecompressRLEVram(void * source, void * destination, uint32 toGetSize, TDecompressionStream * stream);
-
-// swiDecodeDelta8
-// source - pointer to a header word, followed by encoded data
-// word(31..8) = size of data (in bytes)
-// word(7..0) = ignored
-// destination - destination address
-// Writes data a byte at a time
-//
-// Note: ARM9 exclusive swi 0x16
-
-#ifdef ARM9
-
-/*! \fn swiWaitForIRQ
- \brief wait for any interrupt
-
- \note ARM9 exclusive
-*/
-void swiWaitForIRQ(void);
-
-void swiSetHaltCR(uint32 data);
-
-
-extern void swiDecodeDelta8(void * source, void * destination);
-
-// swiDecodeDelta16
-// source - pointer to a header word, followed by encoded data
-// word(31..8) = size of data (in bytes)
-// word(7..0) = ignored
-// destination - destination address
-// Writes data a halfword at a time
-//
-// Note: ARM9 exclusive swi 0x18
-
-void swiDecodeDelta16(void * source, void * destination);
-#endif
-
-
-#ifdef ARM7
-
-//
-// swiHalt (swi 0x06)
-// Same as swiSetHaltCR(0x80)
-//
-// swiSleep (swi 0x07)
-// Same as swiSetHaltCR(0xC0)
-//
-// swiSwitchToGBAMode (not a SWI)
-// Same as swiSetHaltCR(0x40)
-//
-// swiSetHaltCR (swi 0x1F)
-// Writes a byte of the data to 0x04000301:8
-//
-// Note: All of these are ARM7 exclusive
-//
-// swiSetHaltCR (swi 0x1F)
-// Writes a word of the data to 0x04000300:32
-//
-// Note: This is on the ARM9, but works differently to the ARM7 function!
-//
-
-void swiHalt(void);
-void swiSleep(void);
-void swiSwitchToGBAMode(void);
-void swiSetHaltCR(uint8 data);
-
-// swiGetSineTable(int index)
-// Returns an entry in the sine table (index = 0..63)
-//
-// Note: ARM7 exclusive swi 0x1A
-
-uint16 swiGetSineTable(int index);
-//
-// swiGetPitchTable(int index)
-// Returns an entry in the pitch table (index = 0..767)
-//
-// Note: ARM7 exclusive swi 0x1B
-
-uint16 swiGetPitchTable(int index);
-
-
-// swiGetVolumeTable(int index)
-// Returns an entry in the volume table (index = 0..723)
-//
-// Note: ARM7 exclusive swi 0x1C
-uint8 swiGetVolumeTable(int index);
-// swiChangeSoundBias(int enabled, int delay)
-// enabled
-// 0: decrement SOUND_BIAS once per delay until it reaches 0x000
-// 1: increment SOUND_BIAS once per delay until it reaches 0x200
-// delay is in the same units of time as swiDelay
-//
-// Note: ARM7 exclusive SWI 0x08
-
-void swiChangeSoundBias(int enabled, int delay);
-
-
-#endif //ARM7
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ BIOS functions
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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.
+
+---------------------------------------------------------------------------------*/
+
+#ifndef BIOS_H_INCLUDE
+#define BIOS_H_INCLUDE
+
+/*! \file bios.h
+
+ \brief Nintendo DS Bios functions
+*/
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#include <nds/jtypes.h>
+
+
+typedef struct DecompressionStream {
+ int (*getSize)(uint8 * source, uint16 * dest, uint32 r2);
+ int (*getResult)(uint8 * source); // can be NULL
+ uint8 (*readByte)(uint8 * source);
+} PACKED TDecompressionStream;
+
+
+typedef struct UnpackStruct {
+ uint16 sourceSize; // in bytes
+ uint8 sourceWidth;
+ uint8 destWidth;
+ uint32 dataOffset;
+} PACKED TUnpackStruct, * PUnpackStruct;
+
+
+/*! \fn swiSoftReset(void)
+ \brief reset the DS.
+
+*/
+void swiSoftReset(void);
+
+/*! \fn swiDelay( uint32 duration)
+ \brief delay
+
+ Delays for for a period X + Y*duration where X is the swi overhead and Y is a cycle of
+<CODE><PRE>
+ loop:
+ sub r0, #1
+ bgt loop
+</PRE></CODE>
+ of thumb fetches in BIOS memory
+ \param duration
+ length of delay
+ \note
+ Duration should be 1 or more, a duration of 0 is a huge delay
+
+*/
+void swiDelay(uint32 duration);
+
+/*! \fn swiIntrWait(int waitForSet, uint32 flags)
+
+ \brief wait for interrupt(s) to occur
+
+ \param waitForSet
+ 0: Return if the interrupt has already occured
+ 1: Wait until the interrupt has been set since the call
+ \param flags
+ interrupt mask to wait for
+
+*/
+
+void swiIntrWait(int waitForSet, uint32 flags);
+
+/*! \fn swiWaitForVBlank(void)
+ \brief Wait for vblank interrupt
+
+ Waits for a vertical blank interrupt
+
+ \note Identical to calling swiIntrWait(1, 1)
+*/
+
+void swiWaitForVBlank(void);
+
+/*! \fn int swiDivide(int numerator, int divisor)
+ \param numerator
+ signed integer to divide
+ \param divisor
+ signed integer to divide by
+ \return numerator / divisor
+
+ \fn int swiRemainder(int numerator, int divisor)
+ \param numerator
+ signed integer to divide
+ \param divisor
+ signed integer to divide by
+ \return numerator % divisor
+
+ \fn void swiDivMod(int numerator, int divisor, int * result, int * remainder)
+ \param numerator
+ signed integer to divide
+ \param divisor
+ signed integer to divide by
+ \param result
+ pointer to integer set to numerator / divisor
+ \param remainder
+ pointer to integer set to numerator % divisor
+*/
+
+int swiDivide(int numerator, int divisor);
+int swiRemainder(int numerator, int divisor);
+void swiDivMod(int numerator, int divisor, int * result, int * remainder);
+
+/*! \fn swiCopy(const void * source, void * dest, int flags)
+ \param source
+ pointer to transfer source
+ \param dest
+ dest = pointer to transfer destination
+ \param flags
+ copy mode and size
+// flags(26) = transfer width (0: halfwords, 1: words)
+// flags(24) = transfer mode (0: copy, 1: fill)
+// flags(20..0) = transfer count (always in words)
+
+ \fn swiFastCopy (const void * source, void * dest, int flags)
+ \param source
+ pointer to transfer source
+ \param dest
+ dest = pointer to transfer destination
+ \param flags
+ copy mode and size
+// flags(24) = transfer mode (0: copy, 1: fill)
+// flags(20..0) = transfer count (in words)
+
+ \note Transfers more quickly than swiCopy, but has higher interrupt latency
+*/
+
+#define COPY_MODE_HWORD (0)
+#define COPY_MODE_WORD (1<<26)
+#define COPY_MODE_COPY (0)
+#define COPY_MODE_FILL (1<<24)
+
+void swiCopy(const void * source, void * dest, int flags);
+void swiFastCopy(const void * source, void * dest, int flags);
+
+// swiSqrt (swi 0x0D)
+
+int swiSqrt(int value);
+
+// swiCRC16(uint16 crc, void * data, uint32 size) (swi 0x0E)
+// crc - starting CRC-16
+// data - pointer to data (processed nibble by nibble)
+// size - size in bytes
+//
+// Returns the CRC-16 after the data has been processed
+
+uint16 swiCRC16(uint16 crc, void * data, uint32 size);
+
+// int swiIsDebugger(void)
+// Returns 0 if running on a debugger (8 MB of ram instead of 4 MB)
+//
+// Note: swi 0x0F on both CPUs
+
+int swiIsDebugger(void);
+
+// swiUnpackBits
+// source - Source address
+// destination - destination address (word aligned)
+// params - Unpack structure
+// uint16 sourceSize (in bytes)
+// uint8 sourceWidth (1,2,4,8)
+// uint8 destWidth (1,2,4,8,16,32)
+// uint32 dataOffset (bits 0..30 are added to all non-zero
+// destination writes, unless b31 is set,
+// which does it for zeros too)
+//
+// Unpack data stored multiple elements to a byte into a larger space
+// i.e. 8 elements per byte (i.e. b/w font), into 1 element per byte
+//
+// Note: swi 0x10 on both CPUs
+
+void swiUnpackBits(uint8 * source, uint32 * destination, PUnpackStruct params);
+
+// DecompressLZSSWram (swi 0x11)
+// source - pointer to a header word, followed by compressed data
+// word(31..8) = size of uncompressed data (in bytes)
+// word(7..0) = ignored
+// destination - destination address
+// Writes data a byte at a time
+//
+// DecompressLZSSVram (swi 0x12)
+// Writes data a halfword at a time
+// See DecompressRLEVram for parameter details
+
+void swiDecompressLZSSWram(void * source, void * destination);
+int swiDecompressLZSSVram(void * source, void * destination, uint32 toGetSize, TDecompressionStream * stream);
+
+// swiDecompressHuffman (swi 0x13)
+// See DecompressRLE for parameter details
+
+int swiDecompressHuffman(void * source, void * destination, uint32 toGetSize, TDecompressionStream * stream);
+
+// DecompressRLEWram (swi 0x14)
+// r0 - pointer to a header word, followed by compressed data
+// word(31..8) = size of uncompressed data (in bytes)
+// word(7..0) = ignored
+// r1 - destination address
+// Writes data a byte at a time
+//
+// DecompressRLEVram (swi 0x15)
+// r0 - pointer to compressed source data, maybe! (always goes through
+// the function pointers, so could just be an offset)
+// r1 - pointer to destination (halfword)
+// r2 - no idea, passed to getSize function
+// r3 - pointer to a structure
+// Writes data a halfword at a time
+//
+// Result of getSize is a word, with the size of decompressed data in
+// bits 31..8, and bits 7..0 are ignored. This value is also returned
+// by the swi, unless getResult is non-NULL and returns a neg. value
+//
+// getResult is used to provide a result for the swi, given the source
+// pointer after all data has been read (or if getSize < 0). It can
+// be NULL, unlike getSize and readByte. Its value is only returned
+// if negative, otherwise the typical result is used, so it is likely
+// some sort of error-checking procedure
+//
+// readByte is used in lieu of directly accessing memory
+//
+// compressed data format:
+// bit(7): 0: uncompressed, 1: compressed
+// bit(6..0) when uncompressed: run length - 1, followed by run_length bytes of true data
+// bit(6..0) when compressed: run length - 3, followed by one byte of true data, to be repeated
+
+void swiDecompressRLEWram(void * source, void * destination);
+int swiDecompressRLEVram(void * source, void * destination, uint32 toGetSize, TDecompressionStream * stream);
+
+// swiDecodeDelta8
+// source - pointer to a header word, followed by encoded data
+// word(31..8) = size of data (in bytes)
+// word(7..0) = ignored
+// destination - destination address
+// Writes data a byte at a time
+//
+// Note: ARM9 exclusive swi 0x16
+
+#ifdef ARM9
+
+/*! \fn swiWaitForIRQ
+ \brief wait for any interrupt
+
+ \note ARM9 exclusive
+*/
+void swiWaitForIRQ(void);
+
+void swiSetHaltCR(uint32 data);
+
+
+extern void swiDecodeDelta8(void * source, void * destination);
+
+// swiDecodeDelta16
+// source - pointer to a header word, followed by encoded data
+// word(31..8) = size of data (in bytes)
+// word(7..0) = ignored
+// destination - destination address
+// Writes data a halfword at a time
+//
+// Note: ARM9 exclusive swi 0x18
+
+void swiDecodeDelta16(void * source, void * destination);
+#endif
+
+
+#ifdef ARM7
+
+//
+// swiHalt (swi 0x06)
+// Same as swiSetHaltCR(0x80)
+//
+// swiSleep (swi 0x07)
+// Same as swiSetHaltCR(0xC0)
+//
+// swiSwitchToGBAMode (not a SWI)
+// Same as swiSetHaltCR(0x40)
+//
+// swiSetHaltCR (swi 0x1F)
+// Writes a byte of the data to 0x04000301:8
+//
+// Note: All of these are ARM7 exclusive
+//
+// swiSetHaltCR (swi 0x1F)
+// Writes a word of the data to 0x04000300:32
+//
+// Note: This is on the ARM9, but works differently to the ARM7 function!
+//
+
+void swiHalt(void);
+void swiSleep(void);
+void swiSwitchToGBAMode(void);
+void swiSetHaltCR(uint8 data);
+
+// swiGetSineTable(int index)
+// Returns an entry in the sine table (index = 0..63)
+//
+// Note: ARM7 exclusive swi 0x1A
+
+uint16 swiGetSineTable(int index);
+//
+// swiGetPitchTable(int index)
+// Returns an entry in the pitch table (index = 0..767)
+//
+// Note: ARM7 exclusive swi 0x1B
+
+uint16 swiGetPitchTable(int index);
+
+
+// swiGetVolumeTable(int index)
+// Returns an entry in the volume table (index = 0..723)
+//
+// Note: ARM7 exclusive swi 0x1C
+uint8 swiGetVolumeTable(int index);
+// swiChangeSoundBias(int enabled, int delay)
+// enabled
+// 0: decrement SOUND_BIAS once per delay until it reaches 0x000
+// 1: increment SOUND_BIAS once per delay until it reaches 0x200
+// delay is in the same units of time as swiDelay
+//
+// Note: ARM7 exclusive SWI 0x08
+
+void swiChangeSoundBias(int enabled, int delay);
+
+
+#endif //ARM7
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/card.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/card.h
index 7e380382e1..3c4a732629 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/card.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/card.h
@@ -1,127 +1,127 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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.
-
----------------------------------------------------------------------------------*/
-
-#ifndef NDS_CARD_INCLUDE
-#define NDS_CARD_INCLUDE
-
-
-#include "jtypes.h"
-
-// Card bus
-#define CARD_CR1 (*(vuint16*)0x040001A0)
-#define CARD_CR1H (*(vuint8*)0x040001A1)
-#define CARD_EEPDATA (*(vuint8*)0x040001A2)
-#define CARD_CR2 (*(vuint32*)0x040001A4)
-#define CARD_COMMAND ((vuint8*)0x040001A8)
-
-#define CARD_DATA_RD (*(vuint32*)0x04100010)
-
-#define CARD_1B0 (*(vuint32*)0x040001B0)
-#define CARD_1B4 (*(vuint32*)0x040001B4)
-#define CARD_1B8 (*(vuint16*)0x040001B8)
-#define CARD_1BA (*(vuint16*)0x040001BA)
-
-
-#define CARD_CR1_ENABLE 0x80 // in byte 1, i.e. 0x8000
-#define CARD_CR1_IRQ 0x40 // in byte 1, i.e. 0x4000
-
-
-// CARD_CR2 register:
-
-#define CARD_ACTIVATE (1<<31) // when writing, get the ball rolling
-// 1<<30
-#define CARD_nRESET (1<<29) // value on the /reset pin (1 = high out, not a reset state, 0 = low out = in reset)
-#define CARD_28 (1<<28) // when writing
-#define CARD_27 (1<<27) // when writing
-#define CARD_26 (1<<26)
-#define CARD_22 (1<<22)
-#define CARD_19 (1<<19)
-#define CARD_ENCRYPTED (1<<14) // when writing, this command should be encrypted
-#define CARD_13 (1<<13) // when writing
-#define CARD_4 (1<<4) // when writing
-
-// 3 bits in b10..b8 indicate something
-// read bits
-#define CARD_BUSY (1<<31) // when reading, still expecting incomming data?
-#define CARD_DATA_READY (1<<23) // when reading, CARD_DATA_RD or CARD_DATA has another word of data and is good to go
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-void cardWriteCommand(const uint8 * command);
-
-void cardPolledTransfer(uint32 flags, uint32 * destination, uint32 length, const uint8 * command);
-void cardStartTransfer(const uint8 * command, uint32 * destination, int channel, uint32 flags);
-uint32 cardWriteAndRead(const uint8 * command, uint32 flags);
-
-// These commands require the cart to not be initialized yet, which may mean the user
-// needs to eject and reinsert the cart or they will return random data.
-void cardRead00(uint32 address, uint32 * destination, uint32 length, uint32 flags);
-void cardReadHeader(uint8 * header);
-int cardReadID(uint32 flags);
-
-// Reads from the EEPROM
-void cardReadEeprom(uint32 address, uint8 *data, uint32 length, uint32 addrtype);
-
-// Writes to the EEPROM. TYPE 3 EEPROM must be erased first (I think?)
-void cardWriteEeprom(uint32 address, uint8 *data, uint32 length, uint32 addrtype);
-
-// Returns the ID of the EEPROM chip? Doesn't work well, most chips give ff,ff
-// i = 0 or 1
-uint8 cardEepromReadID(uint8 i);
-
-// Sends a command to the EEPROM
-uint8 cardEepromCommand(uint8 command, uint32 address);
-
-/*
- * -1:no card or no EEPROM
- * 0:unknown PassMe?
- * 1:TYPE 1 4Kbit(512Byte) EEPROM
- * 2:TYPE 2 64Kbit(8KByte)or 512kbit(64Kbyte) EEPROM
- * 3:TYPE 3 2Mbit(256KByte) FLASH MEMORY (some rare 4Mbit and 8Mbit chips also)
- */
-int cardEepromGetType(void);
-
-// Returns the size in bytes of EEPROM
-uint32 cardEepromGetSize();
-
-// Erases the entire chip. TYPE 3 chips MUST be erased before writing to them. (I think?)
-void cardEepromChipErase(void);
-
-// Erases a single sector of the TYPE 3 chip
-void cardEepromSectorErase(uint32 address);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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.
+
+---------------------------------------------------------------------------------*/
+
+#ifndef NDS_CARD_INCLUDE
+#define NDS_CARD_INCLUDE
+
+
+#include "jtypes.h"
+
+// Card bus
+#define CARD_CR1 (*(vuint16*)0x040001A0)
+#define CARD_CR1H (*(vuint8*)0x040001A1)
+#define CARD_EEPDATA (*(vuint8*)0x040001A2)
+#define CARD_CR2 (*(vuint32*)0x040001A4)
+#define CARD_COMMAND ((vuint8*)0x040001A8)
+
+#define CARD_DATA_RD (*(vuint32*)0x04100010)
+
+#define CARD_1B0 (*(vuint32*)0x040001B0)
+#define CARD_1B4 (*(vuint32*)0x040001B4)
+#define CARD_1B8 (*(vuint16*)0x040001B8)
+#define CARD_1BA (*(vuint16*)0x040001BA)
+
+
+#define CARD_CR1_ENABLE 0x80 // in byte 1, i.e. 0x8000
+#define CARD_CR1_IRQ 0x40 // in byte 1, i.e. 0x4000
+
+
+// CARD_CR2 register:
+
+#define CARD_ACTIVATE (1<<31) // when writing, get the ball rolling
+// 1<<30
+#define CARD_nRESET (1<<29) // value on the /reset pin (1 = high out, not a reset state, 0 = low out = in reset)
+#define CARD_28 (1<<28) // when writing
+#define CARD_27 (1<<27) // when writing
+#define CARD_26 (1<<26)
+#define CARD_22 (1<<22)
+#define CARD_19 (1<<19)
+#define CARD_ENCRYPTED (1<<14) // when writing, this command should be encrypted
+#define CARD_13 (1<<13) // when writing
+#define CARD_4 (1<<4) // when writing
+
+// 3 bits in b10..b8 indicate something
+// read bits
+#define CARD_BUSY (1<<31) // when reading, still expecting incomming data?
+#define CARD_DATA_READY (1<<23) // when reading, CARD_DATA_RD or CARD_DATA has another word of data and is good to go
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+void cardWriteCommand(const uint8 * command);
+
+void cardPolledTransfer(uint32 flags, uint32 * destination, uint32 length, const uint8 * command);
+void cardStartTransfer(const uint8 * command, uint32 * destination, int channel, uint32 flags);
+uint32 cardWriteAndRead(const uint8 * command, uint32 flags);
+
+// These commands require the cart to not be initialized yet, which may mean the user
+// needs to eject and reinsert the cart or they will return random data.
+void cardRead00(uint32 address, uint32 * destination, uint32 length, uint32 flags);
+void cardReadHeader(uint8 * header);
+int cardReadID(uint32 flags);
+
+// Reads from the EEPROM
+void cardReadEeprom(uint32 address, uint8 *data, uint32 length, uint32 addrtype);
+
+// Writes to the EEPROM. TYPE 3 EEPROM must be erased first (I think?)
+void cardWriteEeprom(uint32 address, uint8 *data, uint32 length, uint32 addrtype);
+
+// Returns the ID of the EEPROM chip? Doesn't work well, most chips give ff,ff
+// i = 0 or 1
+uint8 cardEepromReadID(uint8 i);
+
+// Sends a command to the EEPROM
+uint8 cardEepromCommand(uint8 command, uint32 address);
+
+/*
+ * -1:no card or no EEPROM
+ * 0:unknown PassMe?
+ * 1:TYPE 1 4Kbit(512Byte) EEPROM
+ * 2:TYPE 2 64Kbit(8KByte)or 512kbit(64Kbyte) EEPROM
+ * 3:TYPE 3 2Mbit(256KByte) FLASH MEMORY (some rare 4Mbit and 8Mbit chips also)
+ */
+int cardEepromGetType(void);
+
+// Returns the size in bytes of EEPROM
+uint32 cardEepromGetSize(void);
+
+// Erases the entire chip. TYPE 3 chips MUST be erased before writing to them. (I think?)
+void cardEepromChipErase(void);
+
+// Erases a single sector of the TYPE 3 chip
+void cardEepromSectorErase(uint32 address);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/dma.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/dma.h
index db85becd26..637fe74fdd 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/dma.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/dma.h
@@ -1,153 +1,153 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- Copyright (C) 2005
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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.
-
----------------------------------------------------------------------------------*/
-
-#ifndef NDS_DMA_INCLUDE
-#define NDS_DMA_INCLUDE
-
-
-#define DMA0_SRC (*(vuint32*)0x040000B0)
-#define DMA0_DEST (*(vuint32*)0x040000B4)
-#define DMA0_CR (*(vuint32*)0x040000B8)
-
-#define DMA1_SRC (*(vuint32*)0x040000BC)
-#define DMA1_DEST (*(vuint32*)0x040000C0)
-#define DMA1_CR (*(vuint32*)0x040000C4)
-
-#define DMA2_SRC (*(vuint32*)0x040000C8)
-#define DMA2_DEST (*(vuint32*)0x040000CC)
-#define DMA2_CR (*(vuint32*)0x040000D0)
-
-#define DMA3_SRC (*(vuint32*)0x040000D4)
-#define DMA3_DEST (*(vuint32*)0x040000D8)
-#define DMA3_CR (*(vuint32*)0x040000DC)
-
-#define DMA_SRC(n) (*(vuint32*)(0x040000B0+(n*12)))
-#define DMA_DEST(n) (*(vuint32*)(0x040000B4+(n*12)))
-#define DMA_CR(n) (*(vuint32*)(0x040000B8+(n*12)))
-
-
-// DMA control register contents
-// The defaults are 16-bit, increment source/dest addresses, no irq
-#define DMA_ENABLE BIT(31)
-#define DMA_BUSY BIT(31)
-#define DMA_IRQ_REQ BIT(30)
-
-#define DMA_START_NOW 0
-#define DMA_START_CARD (5<<27)
-
-#ifdef ARM7
-#define DMA_START_VBL BIT(27)
-#endif
-
-#ifdef ARM9
-#define DMA_START_HBL BIT(28)
-#define DMA_START_VBL BIT(27)
-#define DMA_START_FIFO (7<<27)
-#define DMA_DISP_FIFO (4<<27)
-#endif
-
-#define DMA_16_BIT 0
-#define DMA_32_BIT BIT(26)
-
-
-#define DMA_REPEAT BIT(25)
-
-#define DMA_SRC_INC (0)
-#define DMA_SRC_DEC BIT(23)
-#define DMA_SRC_FIX BIT(24)
-
-#define DMA_DST_INC (0)
-#define DMA_DST_DEC BIT(21)
-#define DMA_DST_FIX BIT(22)
-#define DMA_DST_RESET (3<<21)
-
-#define DMA_COPY_WORDS (DMA_ENABLE | DMA_32_BIT | DMA_START_NOW)
-#define DMA_COPY_HALFWORDS (DMA_ENABLE | DMA_16_BIT | DMA_START_NOW)
-#define DMA_FIFO (DMA_ENABLE | DMA_32_BIT | DMA_DST_FIX | DMA_START_FIFO)
-
-static inline void dmaCopyWords(uint8 channel, const void* src, void* dest, uint32 size) {
- DMA_SRC(channel) = (uint32)src;
- DMA_DEST(channel) = (uint32)dest;
- DMA_CR(channel) = DMA_COPY_WORDS | (size>>2);
- while(DMA_CR(channel) & DMA_BUSY);
-}
-
-static inline void dmaCopyHalfWords(uint8 channel, const void* src, void* dest, uint32 size) {
- DMA_SRC(channel) = (uint32)src;
- DMA_DEST(channel) = (uint32)dest;
- DMA_CR(channel) = DMA_COPY_HALFWORDS | (size>>1);
- while(DMA_CR(channel) & DMA_BUSY);
-}
-
-static inline void dmaCopy(const void * source, void * dest, uint32 size) {
- DMA_SRC(3) = (uint32)source;
- DMA_DEST(3) = (uint32)dest;
- DMA_CR(3) = DMA_COPY_HALFWORDS | (size>>1);
- while(DMA_CR(3) & DMA_BUSY);
-}
-
-static inline void dmaCopyWordsAsynch(uint8 channel, const void* src, void* dest, uint32 size) {
- DMA_SRC(channel) = (uint32)src;
- DMA_DEST(channel) = (uint32)dest;
- DMA_CR(channel) = DMA_COPY_WORDS | (size>>2);
-
-}
-
-static inline void dmaCopyHalfWordsAsynch(uint8 channel, const void* src, void* dest, uint32 size) {
- DMA_SRC(channel) = (uint32)src;
- DMA_DEST(channel) = (uint32)dest;
- DMA_CR(channel) = DMA_COPY_HALFWORDS | (size>>1);
-}
-
-static inline void dmaCopyAsynch(const void * source, void * dest, uint32 size) {
- DMA_SRC(3) = (uint32)source;
- DMA_DEST(3) = (uint32)dest;
- DMA_CR(3) = DMA_COPY_HALFWORDS | (size>>1);
-}
-
-static inline void dmaFillWords( const void* src, void* dest, uint32 size) {
- DMA_SRC(3) = (uint32)src;
- DMA_DEST(3) = (uint32)dest;
- DMA_CR(3) = DMA_SRC_FIX | DMA_COPY_WORDS | (size>>2);
- while(DMA_CR(3) & DMA_BUSY);
-}
-
-static inline void dmaFillHalfWords( const void* src, void* dest, uint32 size) {
- DMA_SRC(3) = (uint32)src;
- DMA_DEST(3) = (uint32)dest;
- DMA_CR(3) = DMA_SRC_FIX | DMA_COPY_HALFWORDS | (size>>1);
- while(DMA_CR(3) & DMA_BUSY);
-}
-
-static inline int dmaBusy(uint8 channel) {
- return (DMA_CR(channel) & DMA_BUSY)>>31;
-}
-
-
-#endif
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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.
+
+---------------------------------------------------------------------------------*/
+
+#ifndef NDS_DMA_INCLUDE
+#define NDS_DMA_INCLUDE
+
+
+#define DMA0_SRC (*(vuint32*)0x040000B0)
+#define DMA0_DEST (*(vuint32*)0x040000B4)
+#define DMA0_CR (*(vuint32*)0x040000B8)
+
+#define DMA1_SRC (*(vuint32*)0x040000BC)
+#define DMA1_DEST (*(vuint32*)0x040000C0)
+#define DMA1_CR (*(vuint32*)0x040000C4)
+
+#define DMA2_SRC (*(vuint32*)0x040000C8)
+#define DMA2_DEST (*(vuint32*)0x040000CC)
+#define DMA2_CR (*(vuint32*)0x040000D0)
+
+#define DMA3_SRC (*(vuint32*)0x040000D4)
+#define DMA3_DEST (*(vuint32*)0x040000D8)
+#define DMA3_CR (*(vuint32*)0x040000DC)
+
+#define DMA_SRC(n) (*(vuint32*)(0x040000B0+(n*12)))
+#define DMA_DEST(n) (*(vuint32*)(0x040000B4+(n*12)))
+#define DMA_CR(n) (*(vuint32*)(0x040000B8+(n*12)))
+
+
+// DMA control register contents
+// The defaults are 16-bit, increment source/dest addresses, no irq
+#define DMA_ENABLE BIT(31)
+#define DMA_BUSY BIT(31)
+#define DMA_IRQ_REQ BIT(30)
+
+#define DMA_START_NOW 0
+#define DMA_START_CARD (5<<27)
+
+#ifdef ARM7
+#define DMA_START_VBL BIT(27)
+#endif
+
+#ifdef ARM9
+#define DMA_START_HBL BIT(28)
+#define DMA_START_VBL BIT(27)
+#define DMA_START_FIFO (7<<27)
+#define DMA_DISP_FIFO (4<<27)
+#endif
+
+#define DMA_16_BIT 0
+#define DMA_32_BIT BIT(26)
+
+
+#define DMA_REPEAT BIT(25)
+
+#define DMA_SRC_INC (0)
+#define DMA_SRC_DEC BIT(23)
+#define DMA_SRC_FIX BIT(24)
+
+#define DMA_DST_INC (0)
+#define DMA_DST_DEC BIT(21)
+#define DMA_DST_FIX BIT(22)
+#define DMA_DST_RESET (3<<21)
+
+#define DMA_COPY_WORDS (DMA_ENABLE | DMA_32_BIT | DMA_START_NOW)
+#define DMA_COPY_HALFWORDS (DMA_ENABLE | DMA_16_BIT | DMA_START_NOW)
+#define DMA_FIFO (DMA_ENABLE | DMA_32_BIT | DMA_DST_FIX | DMA_START_FIFO)
+
+static inline void dmaCopyWords(uint8 channel, const void* src, void* dest, uint32 size) {
+ DMA_SRC(channel) = (uint32)src;
+ DMA_DEST(channel) = (uint32)dest;
+ DMA_CR(channel) = DMA_COPY_WORDS | (size>>2);
+ while(DMA_CR(channel) & DMA_BUSY);
+}
+
+static inline void dmaCopyHalfWords(uint8 channel, const void* src, void* dest, uint32 size) {
+ DMA_SRC(channel) = (uint32)src;
+ DMA_DEST(channel) = (uint32)dest;
+ DMA_CR(channel) = DMA_COPY_HALFWORDS | (size>>1);
+ while(DMA_CR(channel) & DMA_BUSY);
+}
+
+static inline void dmaCopy(const void * source, void * dest, uint32 size) {
+ DMA_SRC(3) = (uint32)source;
+ DMA_DEST(3) = (uint32)dest;
+ DMA_CR(3) = DMA_COPY_HALFWORDS | (size>>1);
+ while(DMA_CR(3) & DMA_BUSY);
+}
+
+static inline void dmaCopyWordsAsynch(uint8 channel, const void* src, void* dest, uint32 size) {
+ DMA_SRC(channel) = (uint32)src;
+ DMA_DEST(channel) = (uint32)dest;
+ DMA_CR(channel) = DMA_COPY_WORDS | (size>>2);
+
+}
+
+static inline void dmaCopyHalfWordsAsynch(uint8 channel, const void* src, void* dest, uint32 size) {
+ DMA_SRC(channel) = (uint32)src;
+ DMA_DEST(channel) = (uint32)dest;
+ DMA_CR(channel) = DMA_COPY_HALFWORDS | (size>>1);
+}
+
+static inline void dmaCopyAsynch(const void * source, void * dest, uint32 size) {
+ DMA_SRC(3) = (uint32)source;
+ DMA_DEST(3) = (uint32)dest;
+ DMA_CR(3) = DMA_COPY_HALFWORDS | (size>>1);
+}
+
+static inline void dmaFillWords( const void* src, void* dest, uint32 size) {
+ DMA_SRC(3) = (uint32)src;
+ DMA_DEST(3) = (uint32)dest;
+ DMA_CR(3) = DMA_SRC_FIX | DMA_COPY_WORDS | (size>>2);
+ while(DMA_CR(3) & DMA_BUSY);
+}
+
+static inline void dmaFillHalfWords( const void* src, void* dest, uint32 size) {
+ DMA_SRC(3) = (uint32)src;
+ DMA_DEST(3) = (uint32)dest;
+ DMA_CR(3) = DMA_SRC_FIX | DMA_COPY_HALFWORDS | (size>>1);
+ while(DMA_CR(3) & DMA_BUSY);
+}
+
+static inline int dmaBusy(uint8 channel) {
+ return (DMA_CR(channel) & DMA_BUSY)>>31;
+}
+
+
+#endif
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/interrupts.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/interrupts.h
index bb6832f81a..57d21fbc88 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/interrupts.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/interrupts.h
@@ -1,187 +1,187 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- Interrupt registers and vector pointers
-
- Copyright (C) 2005
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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.
-
-
----------------------------------------------------------------------------------*/
-
-/*! \file interrupts.h
-
- \brief nds interrupt support.
-
-*/
-
-#ifndef NDS_INTERRUPTS_INCLUDE
-#define NDS_INTERRUPTS_INCLUDE
-
-#include <nds/jtypes.h>
-
-/*! \enum IRQ_MASKS
- \brief values allowed for REG_IE and REG_IF
-
-*/
-enum IRQ_MASKS {
- IRQ_VBLANK = BIT(0), /*!< vertical blank interrupt mask */
- IRQ_HBLANK = BIT(1), /*!< horizontal blank interrupt mask */
- IRQ_VCOUNT = BIT(2), /*!< vcount match interrupt mask */
- IRQ_TIMER0 = BIT(3), /*!< timer 0 interrupt mask */
- IRQ_TIMER1 = BIT(4), /*!< timer 1 interrupt mask */
- IRQ_TIMER2 = BIT(5), /*!< timer 2 interrupt mask */
- IRQ_TIMER3 = BIT(6), /*!< timer 3 interrupt mask */
- IRQ_NETWORK = BIT(7), /*!< serial interrupt mask */
- IRQ_DMA0 = BIT(8), /*!< DMA 0 interrupt mask */
- IRQ_DMA1 = BIT(9), /*!< DMA 1 interrupt mask */
- IRQ_DMA2 = BIT(10), /*!< DMA 2 interrupt mask */
- IRQ_DMA3 = BIT(11), /*!< DMA 3 interrupt mask */
- IRQ_KEYS = BIT(12), /*!< Keypad interrupt mask */
- IRQ_CART = BIT(13), /*!< GBA cartridge interrupt mask */
- IRQ_IPC_SYNC = BIT(16), /*!< IPC sync interrupt mask */
- IRQ_FIFO_EMPTY = BIT(17), /*!< Send FIFO empty interrupt mask */
- IRQ_FIFO_NOT_EMPTY = BIT(18), /*!< Receive FIFO empty interrupt mask */
- IRQ_CARD = BIT(19), /*!< interrupt mask */
- IRQ_CARD_LINE = BIT(20), /*!< interrupt mask */
- IRQ_GEOMETRY_FIFO = BIT(21), /*!< geometry FIFO interrupt mask */
- IRQ_LID = BIT(22), /*!< interrupt mask */
- IRQ_SPI = BIT(23), /*!< SPI interrupt mask */
- IRQ_WIFI = BIT(24), /*!< WIFI interrupt mask (ARM7)*/
- IRQ_ALL = (~0)
-};
-
-#define MAX_INTERRUPTS 25
-
-typedef enum IRQ_MASKS IRQ_MASK;
-
-/*! \def REG_IE
-
- \brief Interrupt Enable Register.
-
- This is the activation mask for the internal interrupts. Unless
- the corresponding bit is set, the IRQ will be masked out.
-*/
-#define REG_IE (*(vuint32*)0x04000210)
-
-/*! \def REG_IF
-
- \brief Interrupt Flag Register.
-
- Since there is only one hardware interrupt vector, the IF register
- contains flags to indicate when a particular of interrupt has occured.
- To acknowledge processing interrupts, set IF to the value of the
- interrupt handled.
-
-*/
-#define REG_IF (*(vuint32*)0x04000214)
-
-/*! \def REG_IME
-
- \brief Interrupt Master Enable Register.
-
- When bit 0 is clear, all interrupts are masked. When it is 1,
- interrupts will occur if not masked out in REG_IE.
-
-*/
-#define REG_IME (*(vuint16*)0x04000208)
-
-/*! \enum IME_VALUE
- \brief values allowed for REG_IME
-*/
-enum IME_VALUE {
- IME_DISABLE = 0, /*!< Disable all interrupts. */
- IME_ENABLE = 1, /*!< Enable all interrupts not masked out in REG_IE */
-};
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-extern VoidFunctionPointer __irq_vector[];
-extern vuint32 __irq_flags[];
-#define VBLANK_INTR_WAIT_FLAGS *(__irq_flags)
-#define IRQ_HANDLER *(__irq_vector)
-
-struct IntTable{IntFn handler; u32 mask;};
-
-/*! \fn irqInit()
- \brief Initialise the libnds interrupt system.
-
- Call this function at the start of any application which requires interrupt support.
- This function should be used in preference to irqInitHandler.
-
-*/
-void irqInit();
-/*! \fn irqSet(IRQ_MASK irq, VoidFunctionPointer handler)
- \brief Add a handler for the given interrupt mask.
-
- Specify the handler to use for the given interrupt. This only works with
- the default interrupt handler, do not mix the use of this routine with a
- user-installed IRQ handler.
- \param irq Mask associated with the interrupt.
- \param handler Address of the function to use as an interrupt service routine
- \note
- When any handler specifies using IRQ_VBLANK or IRQ_HBLANK, DISP_SR
- is automatically updated to include the corresponding DISP_VBLANK_IRQ or DISP_HBLANK_IRQ.
-
- \warning Only one IRQ_MASK can be specified with this function.
-*/
-void irqSet(IRQ_MASK irq, VoidFunctionPointer handler);
-/*! \fn irqClear(IRQ_MASK irq)
- \brief remove the handler associated with the interrupt mask irq.
- \param irq Mask associated with the interrupt.
-*/
-void irqClear(IRQ_MASK irq);
-/*! \fn irqInitHandler(VoidFunctionPointer handler)
- \brief Install a user interrupt dispatcher.
-
- This function installs the main interrupt function, all interrupts are serviced through this routine. For most
- purposes the libnds interrupt dispacther should be used in preference to user code unless you know *exactly* what you're doing.
-
- \param handler Address of the function to use as an interrupt dispatcher
- \note the function *must* be ARM code
-*/
-void irqInitHandler(VoidFunctionPointer handler);
-/*! \fn irqEnable(uint32 irq)
- \brief Allow the given interrupt to occur.
- \param irq The set of interrupt masks to enable.
- \note Specify multiple interrupts to enable by ORing several IRQ_MASKS.
-*/
-void irqEnable(uint32 irq);
-/*! \fn irqDisable(uint32 irq)
- \brief Prevent the given interrupt from occuring.
- \param irq The set of interrupt masks to disable.
- \note Specify multiple interrupts to disable by ORing several IRQ_MASKS.
-*/
-void irqDisable(uint32 irq);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //NDS_INTERRUPTS_INCLUDE
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ Interrupt registers and vector pointers
+
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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.
+
+
+---------------------------------------------------------------------------------*/
+
+/*! \file interrupts.h
+
+ \brief nds interrupt support.
+
+*/
+
+#ifndef NDS_INTERRUPTS_INCLUDE
+#define NDS_INTERRUPTS_INCLUDE
+
+#include <nds/jtypes.h>
+
+/*! \enum IRQ_MASKS
+ \brief values allowed for REG_IE and REG_IF
+
+*/
+enum IRQ_MASKS {
+ IRQ_VBLANK = BIT(0), /*!< vertical blank interrupt mask */
+ IRQ_HBLANK = BIT(1), /*!< horizontal blank interrupt mask */
+ IRQ_VCOUNT = BIT(2), /*!< vcount match interrupt mask */
+ IRQ_TIMER0 = BIT(3), /*!< timer 0 interrupt mask */
+ IRQ_TIMER1 = BIT(4), /*!< timer 1 interrupt mask */
+ IRQ_TIMER2 = BIT(5), /*!< timer 2 interrupt mask */
+ IRQ_TIMER3 = BIT(6), /*!< timer 3 interrupt mask */
+ IRQ_NETWORK = BIT(7), /*!< serial interrupt mask */
+ IRQ_DMA0 = BIT(8), /*!< DMA 0 interrupt mask */
+ IRQ_DMA1 = BIT(9), /*!< DMA 1 interrupt mask */
+ IRQ_DMA2 = BIT(10), /*!< DMA 2 interrupt mask */
+ IRQ_DMA3 = BIT(11), /*!< DMA 3 interrupt mask */
+ IRQ_KEYS = BIT(12), /*!< Keypad interrupt mask */
+ IRQ_CART = BIT(13), /*!< GBA cartridge interrupt mask */
+ IRQ_IPC_SYNC = BIT(16), /*!< IPC sync interrupt mask */
+ IRQ_FIFO_EMPTY = BIT(17), /*!< Send FIFO empty interrupt mask */
+ IRQ_FIFO_NOT_EMPTY = BIT(18), /*!< Receive FIFO empty interrupt mask */
+ IRQ_CARD = BIT(19), /*!< interrupt mask */
+ IRQ_CARD_LINE = BIT(20), /*!< interrupt mask */
+ IRQ_GEOMETRY_FIFO = BIT(21), /*!< geometry FIFO interrupt mask */
+ IRQ_LID = BIT(22), /*!< interrupt mask */
+ IRQ_SPI = BIT(23), /*!< SPI interrupt mask */
+ IRQ_WIFI = BIT(24), /*!< WIFI interrupt mask (ARM7)*/
+ IRQ_ALL = (~0)
+};
+
+#define MAX_INTERRUPTS 25
+
+typedef enum IRQ_MASKS IRQ_MASK;
+
+/*! \def REG_IE
+
+ \brief Interrupt Enable Register.
+
+ This is the activation mask for the internal interrupts. Unless
+ the corresponding bit is set, the IRQ will be masked out.
+*/
+#define REG_IE (*(vuint32*)0x04000210)
+
+/*! \def REG_IF
+
+ \brief Interrupt Flag Register.
+
+ Since there is only one hardware interrupt vector, the IF register
+ contains flags to indicate when a particular of interrupt has occured.
+ To acknowledge processing interrupts, set IF to the value of the
+ interrupt handled.
+
+*/
+#define REG_IF (*(vuint32*)0x04000214)
+
+/*! \def REG_IME
+
+ \brief Interrupt Master Enable Register.
+
+ When bit 0 is clear, all interrupts are masked. When it is 1,
+ interrupts will occur if not masked out in REG_IE.
+
+*/
+#define REG_IME (*(vuint16*)0x04000208)
+
+/*! \enum IME_VALUE
+ \brief values allowed for REG_IME
+*/
+enum IME_VALUE {
+ IME_DISABLE = 0, /*!< Disable all interrupts. */
+ IME_ENABLE = 1, /*!< Enable all interrupts not masked out in REG_IE */
+};
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+extern VoidFunctionPointer __irq_vector[];
+extern vuint32 __irq_flags[];
+#define VBLANK_INTR_WAIT_FLAGS *(__irq_flags)
+#define IRQ_HANDLER *(__irq_vector)
+
+struct IntTable{IntFn handler; u32 mask;};
+
+/*! \fn irqInit(void)
+ \brief Initialise the libnds interrupt system.
+
+ Call this function at the start of any application which requires interrupt support.
+ This function should be used in preference to irqInitHandler.
+
+*/
+void irqInit(void);
+/*! \fn irqSet(IRQ_MASK irq, VoidFunctionPointer handler)
+ \brief Add a handler for the given interrupt mask.
+
+ Specify the handler to use for the given interrupt. This only works with
+ the default interrupt handler, do not mix the use of this routine with a
+ user-installed IRQ handler.
+ \param irq Mask associated with the interrupt.
+ \param handler Address of the function to use as an interrupt service routine
+ \note
+ When any handler specifies using IRQ_VBLANK or IRQ_HBLANK, DISP_SR
+ is automatically updated to include the corresponding DISP_VBLANK_IRQ or DISP_HBLANK_IRQ.
+
+ \warning Only one IRQ_MASK can be specified with this function.
+*/
+void irqSet(IRQ_MASK irq, VoidFunctionPointer handler);
+/*! \fn irqClear(IRQ_MASK irq)
+ \brief remove the handler associated with the interrupt mask irq.
+ \param irq Mask associated with the interrupt.
+*/
+void irqClear(IRQ_MASK irq);
+/*! \fn irqInitHandler(VoidFunctionPointer handler)
+ \brief Install a user interrupt dispatcher.
+
+ This function installs the main interrupt function, all interrupts are serviced through this routine. For most
+ purposes the libnds interrupt dispacther should be used in preference to user code unless you know *exactly* what you're doing.
+
+ \param handler Address of the function to use as an interrupt dispatcher
+ \note the function *must* be ARM code
+*/
+void irqInitHandler(VoidFunctionPointer handler);
+/*! \fn irqEnable(uint32 irq)
+ \brief Allow the given interrupt to occur.
+ \param irq The set of interrupt masks to enable.
+ \note Specify multiple interrupts to enable by ORing several IRQ_MASKS.
+*/
+void irqEnable(uint32 irq);
+/*! \fn irqDisable(uint32 irq)
+ \brief Prevent the given interrupt from occuring.
+ \param irq The set of interrupt masks to disable.
+ \note Specify multiple interrupts to disable by ORing several IRQ_MASKS.
+*/
+void irqDisable(uint32 irq);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //NDS_INTERRUPTS_INCLUDE
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/ipc.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/ipc.h
index 85623396ef..6b74747a4a 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/ipc.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/ipc.h
@@ -1,157 +1,157 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- Inter Processor Communication
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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.
-
----------------------------------------------------------------------------------*/
-
-#ifndef NDS_IPC_INCLUDE
-#define NDS_IPC_INCLUDE
-
-#include <nds/jtypes.h>
-
-//---------------------------------------------------------------------------------
-typedef struct sTransferSoundData {
-//---------------------------------------------------------------------------------
- const void *data;
- u32 len;
- u32 rate;
- u8 vol;
- u8 pan;
- u8 format;
- u8 PADDING;
-} TransferSoundData, * pTransferSoundData;
-
-
-//---------------------------------------------------------------------------------
-typedef struct sTransferSound {
-//---------------------------------------------------------------------------------
- TransferSoundData data[16];
- u8 count;
- u8 PADDING[3];
-} TransferSound, * pTransferSound;
-
-
-//---------------------------------------------------------------------------------
-typedef struct sTransferRegion {
-//---------------------------------------------------------------------------------
- vint16 touchX, touchY; // TSC X, Y
- vint16 touchXpx, touchYpx; // TSC X, Y pixel values
- vint16 touchZ1, touchZ2; // TSC x-panel measurements
- vuint16 tdiode1, tdiode2; // TSC temperature diodes
- vuint32 temperature; // TSC computed temperature
-
- uint16 buttons; // X, Y, /PENIRQ buttons
-
- union {
- vuint8 curtime[8]; // current time response from RTC
-
- struct {
- vu8 command;
- vu8 year; //add 2000 to get 4 digit year
- vu8 month; //1 to 12
- vu8 day; //1 to (days in month)
-
- vu8 weekday; // day of week
- vu8 hours; //0 to 11 for AM, 52 to 63 for PM
- vu8 minutes; //0 to 59
- vu8 seconds; //0 to 59
- } rtc;
- } time;
- vint32 unixTime;
-
- uint16 battery; // battery life ?? hopefully. :)
- uint16 aux; // i have no idea...
-
- // Don't rely on these below, will change or be removed in the future
- pTransferSound soundData;
-
- vuint32 mailAddr;
- vuint32 mailData;
- vuint8 mailRead;
- vuint8 mailBusy;
- vuint32 mailSize;
-} TransferRegion, * pTransferRegion;
-
-
-static inline
-TransferRegion volatile * getIPC(); // __attribute__ ((deprecated));
-
-static inline
-TransferRegion volatile * getIPC() {
- return (TransferRegion volatile *)(0x027FF000);
-}
-
-#define IPC getIPC()
-
-#define IPC_PEN_DOWN BIT(6)
-#define IPC_X BIT(0)
-#define IPC_Y BIT(1)
-#define IPC_LID_CLOSED BIT(7)
-
-//---------------------------------------------------------------------------------
-// Synchronization register
-//---------------------------------------------------------------------------------
-#define REG_IPC_SYNC (*(vuint16*)0x04000180)
-
-enum IPC_SYNC_BITS {
- IPC_SYNC_IRQ_ENABLE = BIT(14),
- IPC_SYNC_IRQ_REQUEST = BIT(13)
-};
-
-//---------------------------------------------------------------------------------
-static inline void IPC_SendSync(unsigned int sync) {
-//---------------------------------------------------------------------------------
- REG_IPC_SYNC = (REG_IPC_SYNC & 0xf0ff) | (((sync) & 0x0f) << 8) | IPC_SYNC_IRQ_REQUEST;
-}
-
-//---------------------------------------------------------------------------------
-static inline int IPC_GetSync() {
-//---------------------------------------------------------------------------------
- return REG_IPC_SYNC & 0x0f;
-}
-
-//---------------------------------------------------------------------------------
-// fifo
-//---------------------------------------------------------------------------------
-#define REG_IPC_FIFO_TX (*(vu32*)0x4000188)
-#define REG_IPC_FIFO_RX (*(vu32*)0x4100000)
-#define REG_IPC_FIFO_CR (*(vu16*)0x4000184)
-
-enum IPC_CONTROL_BITS {
- IPC_FIFO_SEND_EMPTY = (1<<0),
- IPC_FIFO_SEND_FULL = (1<<1),
- IPC_FIFO_SEND_IRQ = (1<<2),
- IPC_FIFO_SEND_CLEAR = (1<<3),
- IPC_FIFO_RECV_EMPTY = (1<<8),
- IPC_FIFO_RECV_FULL = (1<<9),
- IPC_FIFO_RECV_IRQ = (1<<10),
- IPC_FIFO_ERROR = (1<<14),
- IPC_FIFO_ENABLE = (1<<15)
-};
-
-#endif // NDS_IPC_INCLUDE
-
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ Inter Processor Communication
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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.
+
+---------------------------------------------------------------------------------*/
+
+#ifndef NDS_IPC_INCLUDE
+#define NDS_IPC_INCLUDE
+
+#include <nds/jtypes.h>
+
+//---------------------------------------------------------------------------------
+typedef struct sTransferSoundData {
+//---------------------------------------------------------------------------------
+ const void *data;
+ u32 len;
+ u32 rate;
+ u8 vol;
+ u8 pan;
+ u8 format;
+ u8 PADDING;
+} TransferSoundData, * pTransferSoundData;
+
+
+//---------------------------------------------------------------------------------
+typedef struct sTransferSound {
+//---------------------------------------------------------------------------------
+ TransferSoundData data[16];
+ u8 count;
+ u8 PADDING[3];
+} TransferSound, * pTransferSound;
+
+
+//---------------------------------------------------------------------------------
+typedef struct sTransferRegion {
+//---------------------------------------------------------------------------------
+ vint16 touchX, touchY; // TSC X, Y
+ vint16 touchXpx, touchYpx; // TSC X, Y pixel values
+ vint16 touchZ1, touchZ2; // TSC x-panel measurements
+ vuint16 tdiode1, tdiode2; // TSC temperature diodes
+ vuint32 temperature; // TSC computed temperature
+
+ uint16 buttons; // X, Y, /PENIRQ buttons
+
+ union {
+ vuint8 curtime[8]; // current time response from RTC
+
+ struct {
+ vu8 command;
+ vu8 year; //add 2000 to get 4 digit year
+ vu8 month; //1 to 12
+ vu8 day; //1 to (days in month)
+
+ vu8 weekday; // day of week
+ vu8 hours; //0 to 11 for AM, 52 to 63 for PM
+ vu8 minutes; //0 to 59
+ vu8 seconds; //0 to 59
+ } rtc;
+ } time;
+ vint32 unixTime;
+
+ uint16 battery; // battery life ?? hopefully. :)
+ uint16 aux; // i have no idea...
+
+ // Don't rely on these below, will change or be removed in the future
+ pTransferSound soundData;
+
+ vuint32 mailAddr;
+ vuint32 mailData;
+ vuint8 mailRead;
+ vuint8 mailBusy;
+ vuint32 mailSize;
+} TransferRegion, * pTransferRegion;
+
+
+static inline
+TransferRegion volatile * getIPC(void); // __attribute__ ((deprecated));
+
+static inline
+TransferRegion volatile * getIPC(void) {
+ return (TransferRegion volatile *)(0x027FF000);
+}
+
+#define IPC getIPC()
+
+#define IPC_PEN_DOWN BIT(6)
+#define IPC_X BIT(0)
+#define IPC_Y BIT(1)
+#define IPC_LID_CLOSED BIT(7)
+
+//---------------------------------------------------------------------------------
+// Synchronization register
+//---------------------------------------------------------------------------------
+#define REG_IPC_SYNC (*(vuint16*)0x04000180)
+
+enum IPC_SYNC_BITS {
+ IPC_SYNC_IRQ_ENABLE = BIT(14),
+ IPC_SYNC_IRQ_REQUEST = BIT(13)
+};
+
+//---------------------------------------------------------------------------------
+static inline void IPC_SendSync(unsigned int sync) {
+//---------------------------------------------------------------------------------
+ REG_IPC_SYNC = (REG_IPC_SYNC & 0xf0ff) | (((sync) & 0x0f) << 8) | IPC_SYNC_IRQ_REQUEST;
+}
+
+//---------------------------------------------------------------------------------
+static inline int IPC_GetSync(void) {
+//---------------------------------------------------------------------------------
+ return REG_IPC_SYNC & 0x0f;
+}
+
+//---------------------------------------------------------------------------------
+// fifo
+//---------------------------------------------------------------------------------
+#define REG_IPC_FIFO_TX (*(vu32*)0x4000188)
+#define REG_IPC_FIFO_RX (*(vu32*)0x4100000)
+#define REG_IPC_FIFO_CR (*(vu16*)0x4000184)
+
+enum IPC_CONTROL_BITS {
+ IPC_FIFO_SEND_EMPTY = (1<<0),
+ IPC_FIFO_SEND_FULL = (1<<1),
+ IPC_FIFO_SEND_IRQ = (1<<2),
+ IPC_FIFO_SEND_CLEAR = (1<<3),
+ IPC_FIFO_RECV_EMPTY = (1<<8),
+ IPC_FIFO_RECV_FULL = (1<<9),
+ IPC_FIFO_RECV_IRQ = (1<<10),
+ IPC_FIFO_ERROR = (1<<14),
+ IPC_FIFO_ENABLE = (1<<15)
+};
+
+#endif // NDS_IPC_INCLUDE
+
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/jtypes.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/jtypes.h
index cbe74aeb47..2bdf3d3de6 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/jtypes.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/jtypes.h
@@ -1,140 +1,140 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- jtypes.h -- Common types (and a few useful macros)
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
- Chris Double (doublec)
-
- 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.
-
----------------------------------------------------------------------------------*/
-#ifndef NDS_JTYPES_INCLUDE
-#define NDS_JTYPES_INCLUDE
-//---------------------------------------------------------------------------------
-
-
-#define PACKED __attribute__ ((packed))
-#define packed_struct struct PACKED
-
-//---------------------------------------------------------------------------------
-// libgba compatible section macros
-//---------------------------------------------------------------------------------
-#define ITCM_CODE __attribute__((section(".itcm"), long_call))
-
-#define DTCM_DATA __attribute__((section(".dtcm")))
-#define DTCM_BSS __attribute__((section(".sbss")))
-#define ALIGN(m) __attribute__((aligned (m)))
-
-#define PACKED __attribute__ ((packed))
-#define packed_struct struct PACKED
-
-//---------------------------------------------------------------------------------
-// These are linked to the bin2o macro in the Makefile
-//---------------------------------------------------------------------------------
-#define GETRAW(name) (name)
-#define GETRAWSIZE(name) ((int)name##_size)
-#define GETRAWEND(name) ((int)name##_end)
-
-#ifndef TRUE
-#define TRUE 1
-#define FALSE 0
-#endif
-
-#define BIT(n) (1 << (n))
-
-// define libnds types in terms of stdint
-#include <stdint.h>
-
-typedef uint8_t uint8;
-typedef uint16_t uint16;
-typedef uint32_t uint32;
-typedef uint64_t uint64;
-
-typedef int8_t int8;
-typedef int16_t int16;
-typedef int32_t int32;
-typedef int64_t int64;
-
-typedef float float32;
-typedef double float64;
-
-typedef volatile uint8_t vuint8;
-typedef volatile uint16_t vuint16;
-typedef volatile uint32_t vuint32;
-typedef volatile uint64_t vuint64;
-
-typedef volatile int8_t vint8;
-typedef volatile int16_t vint16;
-typedef volatile int32_t vint32;
-typedef volatile int64_t vint64;
-
-typedef volatile float32 vfloat32;
-typedef volatile float64 vfloat64;
-
-typedef uint8_t byte;
-
-typedef uint8_t u8;
-typedef uint16_t u16;
-typedef uint32_t u32;
-typedef uint64_t u64;
-
-typedef int8_t s8;
-typedef int16_t s16;
-typedef int32_t s32;
-typedef int64_t s64;
-
-typedef volatile u8 vu8;
-typedef volatile u16 vu16;
-typedef volatile u32 vu32;
-typedef volatile u64 vu64;
-
-typedef volatile s8 vs8;
-typedef volatile s16 vs16;
-typedef volatile s32 vs32;
-typedef volatile s64 vs64;
-
-typedef struct touchPosition {
- int16 x;
- int16 y;
- int16 px;
- int16 py;
- int16 z1;
- int16 z2;
-} touchPosition;
-
-
-#ifndef __cplusplus
-/** C++ compatible bool for C
-
-*/
-typedef enum { false, true } bool;
-#endif
-
-// Handy function pointer typedefs
-typedef void ( * IntFn)(void);
-typedef void (* VoidFunctionPointer)(void);
-typedef void (* fp)(void);
-
-//---------------------------------------------------------------------------------
-#endif
-//---------------------------------------------------------------------------------
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ jtypes.h -- Common types (and a few useful macros)
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+ Chris Double (doublec)
+
+ 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.
+
+---------------------------------------------------------------------------------*/
+#ifndef NDS_JTYPES_INCLUDE
+#define NDS_JTYPES_INCLUDE
+//---------------------------------------------------------------------------------
+
+
+#define PACKED __attribute__ ((packed))
+#define packed_struct struct PACKED
+
+//---------------------------------------------------------------------------------
+// libgba compatible section macros
+//---------------------------------------------------------------------------------
+#define ITCM_CODE __attribute__((section(".itcm"), long_call))
+
+#define DTCM_DATA __attribute__((section(".dtcm")))
+#define DTCM_BSS __attribute__((section(".sbss")))
+#define ALIGN(m) __attribute__((aligned (m)))
+
+#define PACKED __attribute__ ((packed))
+#define packed_struct struct PACKED
+
+//---------------------------------------------------------------------------------
+// These are linked to the bin2o macro in the Makefile
+//---------------------------------------------------------------------------------
+#define GETRAW(name) (name)
+#define GETRAWSIZE(name) ((int)name##_size)
+#define GETRAWEND(name) ((int)name##_end)
+
+#ifndef TRUE
+#define TRUE 1
+#define FALSE 0
+#endif
+
+#define BIT(n) (1 << (n))
+
+// define libnds types in terms of stdint
+#include <stdint.h>
+
+typedef uint8_t uint8;
+typedef uint16_t uint16;
+typedef uint32_t uint32;
+typedef uint64_t uint64;
+
+typedef int8_t int8;
+typedef int16_t int16;
+typedef int32_t int32;
+typedef int64_t int64;
+
+typedef float float32;
+typedef double float64;
+
+typedef volatile uint8_t vuint8;
+typedef volatile uint16_t vuint16;
+typedef volatile uint32_t vuint32;
+typedef volatile uint64_t vuint64;
+
+typedef volatile int8_t vint8;
+typedef volatile int16_t vint16;
+typedef volatile int32_t vint32;
+typedef volatile int64_t vint64;
+
+typedef volatile float32 vfloat32;
+typedef volatile float64 vfloat64;
+
+typedef uint8_t byte;
+
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef uint32_t u32;
+typedef uint64_t u64;
+
+typedef int8_t s8;
+typedef int16_t s16;
+typedef int32_t s32;
+typedef int64_t s64;
+
+typedef volatile u8 vu8;
+typedef volatile u16 vu16;
+typedef volatile u32 vu32;
+typedef volatile u64 vu64;
+
+typedef volatile s8 vs8;
+typedef volatile s16 vs16;
+typedef volatile s32 vs32;
+typedef volatile s64 vs64;
+
+typedef struct touchPosition {
+ int16 x;
+ int16 y;
+ int16 px;
+ int16 py;
+ int16 z1;
+ int16 z2;
+} touchPosition;
+
+
+#ifndef __cplusplus
+/** C++ compatible bool for C
+
+*/
+typedef enum { false, true } bool;
+#endif
+
+// Handy function pointer typedefs
+typedef void ( * IntFn)(void);
+typedef void (* VoidFunctionPointer)(void);
+typedef void (* fp)(void);
+
+//---------------------------------------------------------------------------------
+#endif
+//---------------------------------------------------------------------------------
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/registers_alt.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/registers_alt.h
index 7c8316c89d..32cc36b04d 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/registers_alt.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/registers_alt.h
@@ -1,313 +1,313 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
- Chris Double (doublec)
-
- 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.
-
----------------------------------------------------------------------------------*/
-
-/*
- This file should be deprecated.
-
- All hardware register defines should be replaced with REG_ for consistency and namespacing
-
- http://forum.gbadev.org/viewtopic.php?t=4993
-
-*/
-#ifndef NDS_REGISTERS_H
-#define NDS_REGISTERS_H
-
-
-#include <nds/jtypes.h>
-
-
-#define REG_DISPCNT (*(vu32*)0x4000000)
-
-#ifdef ARM9
-#define WAIT_CR REG_EXMEMCNT
-#else
-#define WAIT_CR REG_EXMEMSTAT
-#endif
-
-#define DISP_SR REG_DISPSTAT
-#define DISP_Y REG_VCOUNT
-
-#define REG_BGCTRL ( (vu16*)0x4000008)
-#define REG_BG0CNT (*(vu16*)0x4000008)
-#define REG_BG1CNT (*(vu16*)0x400000A)
-#define REG_BG2CNT (*(vu16*)0x400000C)
-#define REG_BG3CNT (*(vu16*)0x400000E)
-
-#define REG_BGOFFSETS ( (vu16*)0x4000010)
-#define REG_BG0HOFS (*(vu16*)0x4000010)
-#define REG_BG0VOFS (*(vu16*)0x4000012)
-#define REG_BG1HOFS (*(vu16*)0x4000014)
-#define REG_BG1VOFS (*(vu16*)0x4000016)
-#define REG_BG2HOFS (*(vu16*)0x4000018)
-#define REG_BG2VOFS (*(vu16*)0x400001A)
-#define REG_BG3HOFS (*(vu16*)0x400001C)
-#define REG_BG3VOFS (*(vu16*)0x400001E)
-
-#define REG_BG2PA (*(vu16*)0x4000020)
-#define REG_BG2PB (*(vu16*)0x4000022)
-#define REG_BG2PC (*(vu16*)0x4000024)
-#define REG_BG2PD (*(vu16*)0x4000026)
-
-#define REG_BG2X (*(vu32*)0x4000028)
-#define REG_BG2X_L (*(vu16*)0x4000028)
-#define REG_BG2X_H (*(vu16*)0x400002A)
-
-#define REG_BG2Y (*(vu32*)0x400002C)
-#define REG_BG2Y_L (*(vu16*)0x400002C)
-#define REG_BG2Y_H (*(vu16*)0x400002E)
-
-#define REG_BG3PA (*(vu16*)0x4000030)
-#define REG_BG3PB (*(vu16*)0x4000032)
-#define REG_BG3PC (*(vu16*)0x4000034)
-#define REG_BG3PD (*(vu16*)0x4000036)
-
-#define REG_BG3X (*(vu32*)0x4000038)
-#define REG_BG3X_L (*(vu16*)0x4000038)
-#define REG_BG3X_H (*(vu16*)0x400003A)
-#define REG_BG3Y (*(vu32*)0x400003C)
-#define REG_BG3Y_L (*(vu16*)0x400003C)
-#define REG_BG3Y_H (*(vu16*)0x400003E)
-
-#define REG_WIN0H (*(vu16*)0x4000040)
-#define REG_WIN1H (*(vu16*)0x4000042)
-#define REG_WIN0V (*(vu16*)0x4000044)
-#define REG_WIN1V (*(vu16*)0x4000046)
-#define REG_WININ (*(vu16*)0x4000048)
-#define REG_WINOUT (*(vu16*)0x400004A)
-
-#define REG_MOSAIC (*(vu32*)0x400004C)
-#define REG_MOSAIC_L (*(vu32*)0x400004C)
-#define REG_MOSAIC_H (*(vu32*)0x400004E)
-
-#define REG_BLDMOD (*(vu16*)0x4000050)
-#define REG_COLV (*(vu16*)0x4000052)
-#define REG_COLY (*(vu16*)0x4000054)
-
-#define SERIAL_CR REG_SPICNT
-#define SERIAL_DATA REG_SPIDATA
-#define SIO_CR REG_SIOCNT
-#define R_CR REG_RCNT
-
-#define DISP_CAPTURE REG_DISPCAPCNT
-
-
-/* secondary screen */
-#define REG_DISPCNT_SUB (*(vu32*)0x4001000)
-#define REG_BGCTRL_SUB ( (vu16*)0x4001008)
-#define REG_BG0CNT_SUB (*(vu16*)0x4001008)
-#define REG_BG1CNT_SUB (*(vu16*)0x400100A)
-#define REG_BG2CNT_SUB (*(vu16*)0x400100C)
-#define REG_BG3CNT_SUB (*(vu16*)0x400100E)
-
-#define REG_BGOFFSETS_SUB ( (vu16*)0x4001010)
-#define REG_BG0HOFS_SUB (*(vu16*)0x4001010)
-#define REG_BG0VOFS_SUB (*(vu16*)0x4001012)
-#define REG_BG1HOFS_SUB (*(vu16*)0x4001014)
-#define REG_BG1VOFS_SUB (*(vu16*)0x4001016)
-#define REG_BG2HOFS_SUB (*(vu16*)0x4001018)
-#define REG_BG2VOFS_SUB (*(vu16*)0x400101A)
-#define REG_BG3HOFS_SUB (*(vu16*)0x400101C)
-#define REG_BG3VOFS_SUB (*(vu16*)0x400101E)
-
-#define REG_BG2PA_SUB (*(vu16*)0x4001020)
-#define REG_BG2PB_SUB (*(vu16*)0x4001022)
-#define REG_BG2PC_SUB (*(vu16*)0x4001024)
-#define REG_BG2PD_SUB (*(vu16*)0x4001026)
-
-#define REG_BG2X_SUB (*(vu32*)0x4001028)
-#define REG_BG2Y_SUB (*(vu32*)0x400102C)
-
-#define REG_BG3PA_SUB (*(vu16*)0x4001030)
-#define REG_BG3PB_SUB (*(vu16*)0x4001032)
-#define REG_BG3PC_SUB (*(vu16*)0x4001034)
-#define REG_BG3PD_SUB (*(vu16*)0x4001036)
-
-#define REG_BG3X_SUB (*(vu32*)0x4001038)
-#define REG_BG3X_L_SUB (*(vu16*)0x4001038)
-#define REG_BG3X_H_SUB (*(vu16*)0x400103A)
-#define REG_BG3Y_SUB (*(vu32*)0x400103C)
-#define REG_BG3Y_L_SUB (*(vu16*)0x400103C)
-#define REG_BG3Y_H_SUB (*(vu16*)0x400103E)
-
-#define REG_WIN0H_SUB (*(vu16*)0x4001040)
-#define REG_WIN1H_SUB (*(vu16*)0x4001042)
-#define REG_WIN0V_SUB (*(vu16*)0x4001044)
-#define REG_WIN1V_SUB (*(vu16*)0x4001046)
-#define REG_WININ_SUB (*(vu16*)0x4001048)
-#define REG_WINOUT_SUB (*(vu16*)0x400104A)
-
-#define REG_MOSAIC_SUB (*(vu32*)0x400104C)
-#define REG_MOSAIC_L_SUB (*(vu32*)0x400104C)
-#define REG_MOSAIC_H_SUB (*(vu32*)0x400104E)
-
-#define REG_BLDMOD_SUB (*(vu16*)0x4001050)
-#define REG_COLV_SUB (*(vu16*)0x4001052)
-#define REG_COLY_SUB (*(vu16*)0x4001054)
-
-/*common*/
-#define REG_DMA ( (vu32*)0x40000B0)
-
-#define REG_DMA0SAD (*(vu32*)0x40000B0)
-#define REG_DMA0SAD_L (*(vu16*)0x40000B0)
-#define REG_DMA0SAD_H (*(vu16*)0x40000B2)
-#define REG_DMA0DAD (*(vu32*)0x40000B4)
-#define REG_DMA0DAD_L (*(vu16*)0x40000B4)
-#define REG_DMA0DAD_H (*(vu16*)0x40000B6)
-#define REG_DMA0CNT (*(vu32*)0x40000B8)
-#define REG_DMA0CNT_L (*(vu16*)0x40000B8)
-#define REG_DMA0CNT_H (*(vu16*)0x40000BA)
-
-#define REG_DMA1SAD (*(vu32*)0x40000BC)
-#define REG_DMA1SAD_L (*(vu16*)0x40000BC)
-#define REG_DMA1SAD_H (*(vu16*)0x40000BE)
-#define REG_DMA1DAD (*(vu32*)0x40000C0)
-#define REG_DMA1DAD_L (*(vu16*)0x40000C0)
-#define REG_DMA1DAD_H (*(vu16*)0x40000C2)
-#define REG_DMA1CNT (*(vu32*)0x40000C4)
-#define REG_DMA1CNT_L (*(vu16*)0x40000C4)
-#define REG_DMA1CNT_H (*(vu16*)0x40000C6)
-
-#define REG_DMA2SAD (*(vu32*)0x40000C8)
-#define REG_DMA2SAD_L (*(vu16*)0x40000C8)
-#define REG_DMA2SAD_H (*(vu16*)0x40000CA)
-#define REG_DMA2DAD (*(vu32*)0x40000CC)
-#define REG_DMA2DAD_L (*(vu16*)0x40000CC)
-#define REG_DMA2DAD_H (*(vu16*)0x40000CE)
-#define REG_DMA2CNT (*(vu32*)0x40000D0)
-#define REG_DMA2CNT_L (*(vu16*)0x40000D0)
-#define REG_DMA2CNT_H (*(vu16*)0x40000D2)
-
-#define REG_DMA3SAD (*(vu32*)0x40000D4)
-#define REG_DMA3SAD_L (*(vu16*)0x40000D4)
-#define REG_DMA3SAD_H (*(vu16*)0x40000D6)
-#define REG_DMA3DAD (*(vu32*)0x40000D8)
-#define REG_DMA3DAD_L (*(vu16*)0x40000D8)
-#define REG_DMA3DAD_H (*(vu16*)0x40000DA)
-#define REG_DMA3CNT (*(vu32*)0x40000DC)
-#define REG_DMA3CNT_L (*(vu16*)0x40000DC)
-#define REG_DMA3CNT_H (*(vu16*)0x40000DE)
-
-#define REG_TIME ( (vu16*)0x4000100)
-#define REG_TM0D (*(vu16*)0x4000100)
-#define REG_TM0CNT (*(vu16*)0x4000102)
-#define REG_TM1D (*(vu16*)0x4000106)
-#define REG_TM2D (*(vu16*)0x4000108)
-#define REG_TM2CNT (*(vu16*)0x400010A)
-#define REG_TM3D (*(vu16*)0x400010C)
-#define REG_TM3CNT (*(vu16*)0x400010E)
-
-
-#define REG_SIOCNT (*(vu16*)0x4000128)
-#define REG_SIOMLT_SEND (*(vu16*)0x400012A)
-
-#define KEYS REG_KEYINPUT
-#define KEYS_CR REG_KEYCNT
-//???
-#define REG_RCNT (*(vu16*)0x4000134)
-#define REG_HS_CTRL (*(vu16*)0x4000140)
-
-/* Interupt enable registers */
-#define IE REG_IE
-#define IF REG_IF
-#define IME REG_IME
-
-/*controls power 0x30f is all on */
-#define POWER_CR REG_POWERCNT
-
-/* ram controllers 0x8 is enabled, other bits have to do with mapping */
-#define REG_VRAM_A_CR (*(vu8*) 0x4000240)
-#define REG_VRAM_B_CR (*(vu8*) 0x4000241)
-#define REG_VRAM_C_CR (*(vu8*) 0x4000242)
-#define REG_VRAM_D_CR (*(vu8*) 0x4000243)
-#define REG_VRAM_E_CR (*(vu8*) 0x4000244)
-#define REG_VRAM_F_CR (*(vu8*) 0x4000245)
-#define REG_VRAM_G_CR (*(vu8*) 0x4000246)
-#define REG_VRAM_H_CR (*(vu8*) 0x4000248)
-#define REG_VRAM_I_CR (*(vu8*) 0x4000249)
-#define REG_WRAM_CNT (*(vu8*) 0x4000247)
-
-
-
-
-/*3D graphics suff*/
-#define REG_GFX_FIFO (*(vu32*) 0x4000400)
-#define REG_GFX_STATUS (*(vu32*) 0x4000600)
-#define REG_GFX_CONTROL (*(vu16*) 0x4000060)
-#define REG_COLOR (*(vu32*) 0x4000480)
-#define REG_VERTEX16 (*(vu32*) 0x400048C)
-#define REG_TEXT_COORD (*(vu32*) 0x4000488)
-#define REG_TEXT_FORMAT (*(vu32*) 0x40004A8)
-
-
-#define REG_CLEAR_COLOR (*(vu32*) 0x4000350)
-#define REG_CLEAR_DEPTH (*(vu16*) 0x4000354)
-
-#define REG_LIGHT_VECTOR (*(vu32*) 0x40004C8)
-#define REG_LIGHT_COLOR (*(vu32*) 0x40004CC)
-#define REG_NORMAL (*(vu32*) 0x4000484)
-
-#define REG_DIFFUSE_AMBIENT (*(vu32*) 0x40004C0)
-#define REG_SPECULAR_EMISSION (*(vu32*) 0x40004C4)
-#define REG_SHININESS (*(vu32*) 0x40004D0)
-
-#define REG_POLY_FORMAT (*(vu32*) 0x40004A4)
-
-#define REG_GFX_BEGIN (*(vu32*) 0x4000500)
-#define REG_GFX_END (*(vu32*) 0x4000504)
-#define REG_GFX_FLUSH (*(vu32*) 0x4000540)
-#define REG_GFX_VIEWPORT (*(vu32*) 0x4000580)
-
-#define REG_MTX_CONTROL (*(vu32*) 0x4000440)
-#define REG_MTX_PUSH (*(vu32*) 0x4000444)
-#define REG_MTX_POP (*(vu32*) 0x4000448)
-#define REG_MTX_SCALE (*(vint32*) 0x400046C)
-#define REG_MTX_TRANSLATE (*(vint32*) 0x4000470)
-#define REG_MTX_RESTORE (*(vu32*) 0x4000450)
-#define REG_MTX_STORE (*(vu32*) 0x400044C)
-#define REG_MTX_IDENTITY (*(vu32*) 0x4000454)
-#define REG_MTX_LOAD4x4 (*(volatile f32*) 0x4000458)
-#define REG_MTX_LOAD4x3 (*(volatile f32*) 0x400045C)
-#define REG_MTX_MULT4x4 (*(volatile f32*) 0x4000460)
-#define REG_MTX_MULT4x3 (*(volatile f32*) 0x4000464)
-#define REG_MTX_MULT3x3 (*(volatile f32*) 0x4000468)
-
-// Card bus
-
-#define REG_CARD_CR1 (*(vu32*)0x040001A0)
-#define REG_CARD_CR1H (*(vu8*)0x040001A1)
-#define REG_CARD_CR2 (*(vu32*)0x040001A4)
-#define REG_CARD_COMMAND ((vu8*)0x040001A8)
-
-#define REG_CARD_DATA (*(vu32*)0x04100000)
-#define REG_CARD_DATA_RD (*(vu32*)0x04100010)
-
-#define REG_CARD_1B0 (*(vu32*)0x040001B0)
-#define REG_CARD_1B4 (*(vu32*)0x040001B4)
-#define REG_CARD_1B8 (*(vu16*)0x040001B8)
-#define REG_CARD_1BA (*(vu16*)0x040001BA)
-#endif
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+ Chris Double (doublec)
+
+ 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.
+
+---------------------------------------------------------------------------------*/
+
+/*
+ This file should be deprecated.
+
+ All hardware register defines should be replaced with REG_ for consistency and namespacing
+
+ http://forum.gbadev.org/viewtopic.php?t=4993
+
+*/
+#ifndef NDS_REGISTERS_H
+#define NDS_REGISTERS_H
+
+
+#include <nds/jtypes.h>
+
+
+#define REG_DISPCNT (*(vu32*)0x4000000)
+
+#ifdef ARM9
+#define WAIT_CR REG_EXMEMCNT
+#else
+#define WAIT_CR REG_EXMEMSTAT
+#endif
+
+#define DISP_SR REG_DISPSTAT
+#define DISP_Y REG_VCOUNT
+
+#define REG_BGCTRL ( (vu16*)0x4000008)
+#define REG_BG0CNT (*(vu16*)0x4000008)
+#define REG_BG1CNT (*(vu16*)0x400000A)
+#define REG_BG2CNT (*(vu16*)0x400000C)
+#define REG_BG3CNT (*(vu16*)0x400000E)
+
+#define REG_BGOFFSETS ( (vu16*)0x4000010)
+#define REG_BG0HOFS (*(vu16*)0x4000010)
+#define REG_BG0VOFS (*(vu16*)0x4000012)
+#define REG_BG1HOFS (*(vu16*)0x4000014)
+#define REG_BG1VOFS (*(vu16*)0x4000016)
+#define REG_BG2HOFS (*(vu16*)0x4000018)
+#define REG_BG2VOFS (*(vu16*)0x400001A)
+#define REG_BG3HOFS (*(vu16*)0x400001C)
+#define REG_BG3VOFS (*(vu16*)0x400001E)
+
+#define REG_BG2PA (*(vu16*)0x4000020)
+#define REG_BG2PB (*(vu16*)0x4000022)
+#define REG_BG2PC (*(vu16*)0x4000024)
+#define REG_BG2PD (*(vu16*)0x4000026)
+
+#define REG_BG2X (*(vu32*)0x4000028)
+#define REG_BG2X_L (*(vu16*)0x4000028)
+#define REG_BG2X_H (*(vu16*)0x400002A)
+
+#define REG_BG2Y (*(vu32*)0x400002C)
+#define REG_BG2Y_L (*(vu16*)0x400002C)
+#define REG_BG2Y_H (*(vu16*)0x400002E)
+
+#define REG_BG3PA (*(vu16*)0x4000030)
+#define REG_BG3PB (*(vu16*)0x4000032)
+#define REG_BG3PC (*(vu16*)0x4000034)
+#define REG_BG3PD (*(vu16*)0x4000036)
+
+#define REG_BG3X (*(vu32*)0x4000038)
+#define REG_BG3X_L (*(vu16*)0x4000038)
+#define REG_BG3X_H (*(vu16*)0x400003A)
+#define REG_BG3Y (*(vu32*)0x400003C)
+#define REG_BG3Y_L (*(vu16*)0x400003C)
+#define REG_BG3Y_H (*(vu16*)0x400003E)
+
+#define REG_WIN0H (*(vu16*)0x4000040)
+#define REG_WIN1H (*(vu16*)0x4000042)
+#define REG_WIN0V (*(vu16*)0x4000044)
+#define REG_WIN1V (*(vu16*)0x4000046)
+#define REG_WININ (*(vu16*)0x4000048)
+#define REG_WINOUT (*(vu16*)0x400004A)
+
+#define REG_MOSAIC (*(vu32*)0x400004C)
+#define REG_MOSAIC_L (*(vu32*)0x400004C)
+#define REG_MOSAIC_H (*(vu32*)0x400004E)
+
+#define REG_BLDMOD (*(vu16*)0x4000050)
+#define REG_COLV (*(vu16*)0x4000052)
+#define REG_COLY (*(vu16*)0x4000054)
+
+#define SERIAL_CR REG_SPICNT
+#define SERIAL_DATA REG_SPIDATA
+#define SIO_CR REG_SIOCNT
+#define R_CR REG_RCNT
+
+#define DISP_CAPTURE REG_DISPCAPCNT
+
+
+/* secondary screen */
+#define REG_DISPCNT_SUB (*(vu32*)0x4001000)
+#define REG_BGCTRL_SUB ( (vu16*)0x4001008)
+#define REG_BG0CNT_SUB (*(vu16*)0x4001008)
+#define REG_BG1CNT_SUB (*(vu16*)0x400100A)
+#define REG_BG2CNT_SUB (*(vu16*)0x400100C)
+#define REG_BG3CNT_SUB (*(vu16*)0x400100E)
+
+#define REG_BGOFFSETS_SUB ( (vu16*)0x4001010)
+#define REG_BG0HOFS_SUB (*(vu16*)0x4001010)
+#define REG_BG0VOFS_SUB (*(vu16*)0x4001012)
+#define REG_BG1HOFS_SUB (*(vu16*)0x4001014)
+#define REG_BG1VOFS_SUB (*(vu16*)0x4001016)
+#define REG_BG2HOFS_SUB (*(vu16*)0x4001018)
+#define REG_BG2VOFS_SUB (*(vu16*)0x400101A)
+#define REG_BG3HOFS_SUB (*(vu16*)0x400101C)
+#define REG_BG3VOFS_SUB (*(vu16*)0x400101E)
+
+#define REG_BG2PA_SUB (*(vu16*)0x4001020)
+#define REG_BG2PB_SUB (*(vu16*)0x4001022)
+#define REG_BG2PC_SUB (*(vu16*)0x4001024)
+#define REG_BG2PD_SUB (*(vu16*)0x4001026)
+
+#define REG_BG2X_SUB (*(vu32*)0x4001028)
+#define REG_BG2Y_SUB (*(vu32*)0x400102C)
+
+#define REG_BG3PA_SUB (*(vu16*)0x4001030)
+#define REG_BG3PB_SUB (*(vu16*)0x4001032)
+#define REG_BG3PC_SUB (*(vu16*)0x4001034)
+#define REG_BG3PD_SUB (*(vu16*)0x4001036)
+
+#define REG_BG3X_SUB (*(vu32*)0x4001038)
+#define REG_BG3X_L_SUB (*(vu16*)0x4001038)
+#define REG_BG3X_H_SUB (*(vu16*)0x400103A)
+#define REG_BG3Y_SUB (*(vu32*)0x400103C)
+#define REG_BG3Y_L_SUB (*(vu16*)0x400103C)
+#define REG_BG3Y_H_SUB (*(vu16*)0x400103E)
+
+#define REG_WIN0H_SUB (*(vu16*)0x4001040)
+#define REG_WIN1H_SUB (*(vu16*)0x4001042)
+#define REG_WIN0V_SUB (*(vu16*)0x4001044)
+#define REG_WIN1V_SUB (*(vu16*)0x4001046)
+#define REG_WININ_SUB (*(vu16*)0x4001048)
+#define REG_WINOUT_SUB (*(vu16*)0x400104A)
+
+#define REG_MOSAIC_SUB (*(vu32*)0x400104C)
+#define REG_MOSAIC_L_SUB (*(vu32*)0x400104C)
+#define REG_MOSAIC_H_SUB (*(vu32*)0x400104E)
+
+#define REG_BLDMOD_SUB (*(vu16*)0x4001050)
+#define REG_COLV_SUB (*(vu16*)0x4001052)
+#define REG_COLY_SUB (*(vu16*)0x4001054)
+
+/*common*/
+#define REG_DMA ( (vu32*)0x40000B0)
+
+#define REG_DMA0SAD (*(vu32*)0x40000B0)
+#define REG_DMA0SAD_L (*(vu16*)0x40000B0)
+#define REG_DMA0SAD_H (*(vu16*)0x40000B2)
+#define REG_DMA0DAD (*(vu32*)0x40000B4)
+#define REG_DMA0DAD_L (*(vu16*)0x40000B4)
+#define REG_DMA0DAD_H (*(vu16*)0x40000B6)
+#define REG_DMA0CNT (*(vu32*)0x40000B8)
+#define REG_DMA0CNT_L (*(vu16*)0x40000B8)
+#define REG_DMA0CNT_H (*(vu16*)0x40000BA)
+
+#define REG_DMA1SAD (*(vu32*)0x40000BC)
+#define REG_DMA1SAD_L (*(vu16*)0x40000BC)
+#define REG_DMA1SAD_H (*(vu16*)0x40000BE)
+#define REG_DMA1DAD (*(vu32*)0x40000C0)
+#define REG_DMA1DAD_L (*(vu16*)0x40000C0)
+#define REG_DMA1DAD_H (*(vu16*)0x40000C2)
+#define REG_DMA1CNT (*(vu32*)0x40000C4)
+#define REG_DMA1CNT_L (*(vu16*)0x40000C4)
+#define REG_DMA1CNT_H (*(vu16*)0x40000C6)
+
+#define REG_DMA2SAD (*(vu32*)0x40000C8)
+#define REG_DMA2SAD_L (*(vu16*)0x40000C8)
+#define REG_DMA2SAD_H (*(vu16*)0x40000CA)
+#define REG_DMA2DAD (*(vu32*)0x40000CC)
+#define REG_DMA2DAD_L (*(vu16*)0x40000CC)
+#define REG_DMA2DAD_H (*(vu16*)0x40000CE)
+#define REG_DMA2CNT (*(vu32*)0x40000D0)
+#define REG_DMA2CNT_L (*(vu16*)0x40000D0)
+#define REG_DMA2CNT_H (*(vu16*)0x40000D2)
+
+#define REG_DMA3SAD (*(vu32*)0x40000D4)
+#define REG_DMA3SAD_L (*(vu16*)0x40000D4)
+#define REG_DMA3SAD_H (*(vu16*)0x40000D6)
+#define REG_DMA3DAD (*(vu32*)0x40000D8)
+#define REG_DMA3DAD_L (*(vu16*)0x40000D8)
+#define REG_DMA3DAD_H (*(vu16*)0x40000DA)
+#define REG_DMA3CNT (*(vu32*)0x40000DC)
+#define REG_DMA3CNT_L (*(vu16*)0x40000DC)
+#define REG_DMA3CNT_H (*(vu16*)0x40000DE)
+
+#define REG_TIME ( (vu16*)0x4000100)
+#define REG_TM0D (*(vu16*)0x4000100)
+#define REG_TM0CNT (*(vu16*)0x4000102)
+#define REG_TM1D (*(vu16*)0x4000106)
+#define REG_TM2D (*(vu16*)0x4000108)
+#define REG_TM2CNT (*(vu16*)0x400010A)
+#define REG_TM3D (*(vu16*)0x400010C)
+#define REG_TM3CNT (*(vu16*)0x400010E)
+
+
+#define REG_SIOCNT (*(vu16*)0x4000128)
+#define REG_SIOMLT_SEND (*(vu16*)0x400012A)
+
+#define KEYS REG_KEYINPUT
+#define KEYS_CR REG_KEYCNT
+//???
+#define REG_RCNT (*(vu16*)0x4000134)
+#define REG_HS_CTRL (*(vu16*)0x4000140)
+
+/* Interupt enable registers */
+#define IE REG_IE
+#define IF REG_IF
+#define IME REG_IME
+
+/*controls power 0x30f is all on */
+#define POWER_CR REG_POWERCNT
+
+/* ram controllers 0x8 is enabled, other bits have to do with mapping */
+#define REG_VRAM_A_CR (*(vu8*) 0x4000240)
+#define REG_VRAM_B_CR (*(vu8*) 0x4000241)
+#define REG_VRAM_C_CR (*(vu8*) 0x4000242)
+#define REG_VRAM_D_CR (*(vu8*) 0x4000243)
+#define REG_VRAM_E_CR (*(vu8*) 0x4000244)
+#define REG_VRAM_F_CR (*(vu8*) 0x4000245)
+#define REG_VRAM_G_CR (*(vu8*) 0x4000246)
+#define REG_VRAM_H_CR (*(vu8*) 0x4000248)
+#define REG_VRAM_I_CR (*(vu8*) 0x4000249)
+#define REG_WRAM_CNT (*(vu8*) 0x4000247)
+
+
+
+
+/*3D graphics suff*/
+#define REG_GFX_FIFO (*(vu32*) 0x4000400)
+#define REG_GFX_STATUS (*(vu32*) 0x4000600)
+#define REG_GFX_CONTROL (*(vu16*) 0x4000060)
+#define REG_COLOR (*(vu32*) 0x4000480)
+#define REG_VERTEX16 (*(vu32*) 0x400048C)
+#define REG_TEXT_COORD (*(vu32*) 0x4000488)
+#define REG_TEXT_FORMAT (*(vu32*) 0x40004A8)
+
+
+#define REG_CLEAR_COLOR (*(vu32*) 0x4000350)
+#define REG_CLEAR_DEPTH (*(vu16*) 0x4000354)
+
+#define REG_LIGHT_VECTOR (*(vu32*) 0x40004C8)
+#define REG_LIGHT_COLOR (*(vu32*) 0x40004CC)
+#define REG_NORMAL (*(vu32*) 0x4000484)
+
+#define REG_DIFFUSE_AMBIENT (*(vu32*) 0x40004C0)
+#define REG_SPECULAR_EMISSION (*(vu32*) 0x40004C4)
+#define REG_SHININESS (*(vu32*) 0x40004D0)
+
+#define REG_POLY_FORMAT (*(vu32*) 0x40004A4)
+
+#define REG_GFX_BEGIN (*(vu32*) 0x4000500)
+#define REG_GFX_END (*(vu32*) 0x4000504)
+#define REG_GFX_FLUSH (*(vu32*) 0x4000540)
+#define REG_GFX_VIEWPORT (*(vu32*) 0x4000580)
+
+#define REG_MTX_CONTROL (*(vu32*) 0x4000440)
+#define REG_MTX_PUSH (*(vu32*) 0x4000444)
+#define REG_MTX_POP (*(vu32*) 0x4000448)
+#define REG_MTX_SCALE (*(vint32*) 0x400046C)
+#define REG_MTX_TRANSLATE (*(vint32*) 0x4000470)
+#define REG_MTX_RESTORE (*(vu32*) 0x4000450)
+#define REG_MTX_STORE (*(vu32*) 0x400044C)
+#define REG_MTX_IDENTITY (*(vu32*) 0x4000454)
+#define REG_MTX_LOAD4x4 (*(volatile f32*) 0x4000458)
+#define REG_MTX_LOAD4x3 (*(volatile f32*) 0x400045C)
+#define REG_MTX_MULT4x4 (*(volatile f32*) 0x4000460)
+#define REG_MTX_MULT4x3 (*(volatile f32*) 0x4000464)
+#define REG_MTX_MULT3x3 (*(volatile f32*) 0x4000468)
+
+// Card bus
+
+#define REG_CARD_CR1 (*(vu32*)0x040001A0)
+#define REG_CARD_CR1H (*(vu8*)0x040001A1)
+#define REG_CARD_CR2 (*(vu32*)0x040001A4)
+#define REG_CARD_COMMAND ((vu8*)0x040001A8)
+
+#define REG_CARD_DATA (*(vu32*)0x04100000)
+#define REG_CARD_DATA_RD (*(vu32*)0x04100010)
+
+#define REG_CARD_1B0 (*(vu32*)0x040001B0)
+#define REG_CARD_1B4 (*(vu32*)0x040001B4)
+#define REG_CARD_1B8 (*(vu16*)0x040001B8)
+#define REG_CARD_1BA (*(vu16*)0x040001BA)
+#endif
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/system.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/system.h
index 23bd30b9ba..0684c6faf9 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/system.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/system.h
@@ -1,250 +1,250 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- Power control, keys, and HV clock registers
-
- Copyright (C) 2005
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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.
-
----------------------------------------------------------------------------------*/
-
-//! NDS hardware definitions.
-/*! \file system.h
-
- These definitions are usually only touched during
- the initialization of the program.
-*/
-
-#ifndef NDS_SYSTEM_INCLUDE
-#define NDS_SYSTEM_INCLUDE
-
-//! LCD status register.
-#define REG_DISPSTAT (*(vu16*)0x04000004)
-
-//! The display currently in a vertical blank.
-#define DISP_IN_VBLANK BIT(0)
-
-//! The display currently in a horizontal blank.
-#define DISP_IN_HBLANK BIT(1)
-
-//! Current scanline and %DISP_Y match.
-#define DISP_YTRIGGERED BIT(2)
-
-//! Interrupt on vertical blank.
-#define DISP_VBLANK_IRQ BIT(3)
-
-//! Interrupt on horizontal blank.
-#define DISP_HBLANK_IRQ BIT(4)
-
-//! Interrupt when current scanline and %DISP_Y match.
-#define DISP_YTRIGGER_IRQ BIT(5)
-
-static inline
-void SetYtrigger(int Yvalue) {
- REG_DISPSTAT = (REG_DISPSTAT & 0x007F ) | (Yvalue << 8) | (( Yvalue & 0x100 ) >> 2) ;
-}
-
-//! Current display scanline.
-#define REG_VCOUNT (*(vu16*)0x4000006)
-
-
-//! Halt control register.
-/*! Writing 0x40 to HALT_CR activates GBA mode.
- %HALT_CR can only be accessed via the BIOS.
-*/
-#define HALT_CR (*(vuint16*)0x04000300)
-
-//! Power control register.
-/*! This register controls what hardware should
- be turned on or off.
-*/
-#define REG_POWERCNT *(vu16*)0x4000304
-
-//! Turns on specified hardware.
-/*! This function should only be called after %powerSET.
-
- \param on What to power on.
-*/
-static inline
-void powerON(int on) { REG_POWERCNT |= on;}
-
-//! Turns on only the specified hardware.
-/*! Use this function to power on basic hardware types you
- wish to use throughout your program.
-
- \param on What to power on.
-*/
-static inline void powerSET(int on) { REG_POWERCNT = on;}
-
-//! Turns off the specified hardware.
-/*! \param off What to power off.
-*/
-static inline void powerOFF(int off) { REG_POWERCNT &= ~off;}
-
-#ifdef ARM9
-#ifdef DOXYGEN
-//! Power-controlled hardware devices accessable to the ARM9.
-/*! Used with %powerON, %powerSET, and %powerOFF functions.
- Note that these should only be used when programming for
- the ARM9. Trying to boot up these hardware devices via
- the ARM7 would lead to unexpected results.
-*/
-enum ARM9_power
-{
- POWER_LCD, //!< Controls the power for both LCD screens.
- POWER_2D_A, //!< Controls the power for the main 2D core.
- POWER_MATRIX, //!< Controls the power for the 3D matrix.
- POWER_3D_CORE, //!< Controls the power for the main 3D core.
- POWER_2D_B, //!< Controls the power for the sub 2D core.
- POWER_SWAP_LCDS, //!< Controls which screen should use the main core.
-};
-#else
-#define POWER_LCD BIT(0)
-#define POWER_2D_A BIT(1)
-#define POWER_MATRIX BIT(2)
-#define POWER_3D_CORE BIT(3)
-#define POWER_2D_B BIT(9)
-#define POWER_SWAP_LCDS BIT(15)
-#endif /* DOXYGEN */
-
-//! Enables power to all hardware required for 2D video.
-#define POWER_ALL_2D (POWER_LCD |POWER_2D_A |POWER_2D_B)
-
-//! Enables power to all hardware required for 3D video.
-#define POWER_ALL (POWER_ALL_2D | POWER_3D_CORE | POWER_MATRIX)
-
-//! Switches the screens.
-static inline void lcdSwap(void) { REG_POWERCNT ^= POWER_SWAP_LCDS; }
-
-//! Forces the main core to display on the top.
-static inline void lcdMainOnTop(void) { REG_POWERCNT |= POWER_SWAP_LCDS; }
-
-//! Forces the main core to display on the bottom.
-static inline void lcdMainOnBottom(void) { REG_POWERCNT &= ~POWER_SWAP_LCDS; }
-#endif
-
-#ifdef ARM7
-#ifdef DOXYGEN
-//! Power-controlled hardware devices accessable to the ARM7.
-/*! Note that these should only be used when programming for
- the ARM7. Trying to boot up these hardware devices via
- the ARM9 would lead to unexpected results.
-*/
-enum ARM7_power
-{
- POWER_SOUND, //!< Controls the power for the sound controller.
- POWER_UNKNOWN, //!< Controls the power for an unknown device.
-};
-#else
-#define POWER_SOUND BIT(0)
-#define POWER_UNKNOWN BIT(1)
-#endif /* DOXYGEN */
-
-void readUserSettings();
-
-#endif /* ARM7 */
-
-//! User's DS settings.
-/*! \struct tPERSONAL_DATA
-
- Defines the structure the DS firmware uses for transfer
- of the user's settings to the booted program.
-*/
-typedef struct tPERSONAL_DATA {
- u8 RESERVED0[2]; //!< ??? (0x05 0x00).
-
- u8 theme; //!< The user's theme color (0-15).
- u8 birthMonth; //!< The user's birth month (1-12).
- u8 birthDay; //!< The user's birth day (1-31).
-
- u8 RESERVED1[1]; //!< ???
-
- s16 name[10]; //!< The user's name in UTF-16 format.
- u16 nameLen; //!< The length of the user's name in characters.
-
- s16 message[26]; //!< The user's message.
- u16 messageLen; //!< The length of the user's message in characters.
-
- u8 alarmHour; //!< What hour the alarm clock is set to (0-23).
- u8 alarmMinute; //!< What minute the alarm clock is set to (0-59).
- //0x027FFCD3 alarm minute
-
- u8 RESERVED2[4]; //!< ???
- //0x027FFCD4 ??
-
- u16 calX1; //!< Touchscreen calibration: first X touch
- u16 calY1; //!< Touchscreen calibration: first Y touch
- u8 calX1px; //!< Touchscreen calibration: first X touch pixel
- u8 calY1px; //!< Touchscreen calibration: first X touch pixel
-
- u16 calX2; //!< Touchscreen calibration: second X touch
- u16 calY2; //!< Touchscreen calibration: second Y touch
- u8 calX2px; //!< Touchscreen calibration: second X touch pixel
- u8 calY2px; //!< Touchscreen calibration: second Y touch pixel
-
- packed_struct {
- unsigned language : 3; //!< User's language.
- unsigned gbaScreen : 1; //!< GBA screen selection (lower screen if set, otherwise upper screen).
- unsigned defaultBrightness : 2; //!< Brightness level at power on, dslite.
- unsigned autoMode : 1; //!< The DS should boot from the DS cart or GBA cart automatically if one is inserted.
- unsigned RESERVED1 : 2; //!< ???
- unsigned settingsLost : 1; //!< User Settings Lost (0=Normal, 1=Prompt/Settings Lost)
- unsigned RESERVED2 : 6; //!< ???
- } _user_data;
-
- u16 RESERVED3;
- u32 rtcOffset;
- u32 RESERVED4;
-} PACKED PERSONAL_DATA ;
-
-//! Key input register.
-/*! On the ARM9, the hinge "button," the touch status, and the
- X and Y buttons cannot be accessed directly.
-*/
-#define REG_KEYINPUT (*(vuint16*)0x04000130)
-
-//! Key input control register.
-#define REG_KEYCNT (*(vuint16*)0x04000132)
-
-//! Default location for the user's personal data (see %PERSONAL_DATA).
-#define PersonalData ((PERSONAL_DATA*)0x27FFC80)
-
-//! argv structure
-/*! \struct __argv
-
- structure used to set up argc/argv on the DS
-
-*/
-struct __argv {
- int argvMagic; //!< argv magic number, set to 0x5f617267 ('_arg') if valid
- char *commandLine; //!< base address of command line, set of null terminated strings
- int length; //!< total length of command line
-};
-
-//! Default location for the libnds argv structure.
-#define libnds_argv ((struct __argv *)0x027FFF70)
-
-// argv struct magic number
-#define argvMagic 0x5f617267
-
-#endif
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ Power control, keys, and HV clock registers
+
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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.
+
+---------------------------------------------------------------------------------*/
+
+//! NDS hardware definitions.
+/*! \file system.h
+
+ These definitions are usually only touched during
+ the initialization of the program.
+*/
+
+#ifndef NDS_SYSTEM_INCLUDE
+#define NDS_SYSTEM_INCLUDE
+
+//! LCD status register.
+#define REG_DISPSTAT (*(vu16*)0x04000004)
+
+//! The display currently in a vertical blank.
+#define DISP_IN_VBLANK BIT(0)
+
+//! The display currently in a horizontal blank.
+#define DISP_IN_HBLANK BIT(1)
+
+//! Current scanline and %DISP_Y match.
+#define DISP_YTRIGGERED BIT(2)
+
+//! Interrupt on vertical blank.
+#define DISP_VBLANK_IRQ BIT(3)
+
+//! Interrupt on horizontal blank.
+#define DISP_HBLANK_IRQ BIT(4)
+
+//! Interrupt when current scanline and %DISP_Y match.
+#define DISP_YTRIGGER_IRQ BIT(5)
+
+static inline
+void SetYtrigger(int Yvalue) {
+ REG_DISPSTAT = (REG_DISPSTAT & 0x007F ) | (Yvalue << 8) | (( Yvalue & 0x100 ) >> 2) ;
+}
+
+//! Current display scanline.
+#define REG_VCOUNT (*(vu16*)0x4000006)
+
+
+//! Halt control register.
+/*! Writing 0x40 to HALT_CR activates GBA mode.
+ %HALT_CR can only be accessed via the BIOS.
+*/
+#define HALT_CR (*(vuint16*)0x04000300)
+
+//! Power control register.
+/*! This register controls what hardware should
+ be turned on or off.
+*/
+#define REG_POWERCNT *(vu16*)0x4000304
+
+//! Turns on specified hardware.
+/*! This function should only be called after %powerSET.
+
+ \param on What to power on.
+*/
+static inline
+void powerON(int on) { REG_POWERCNT |= on;}
+
+//! Turns on only the specified hardware.
+/*! Use this function to power on basic hardware types you
+ wish to use throughout your program.
+
+ \param on What to power on.
+*/
+static inline void powerSET(int on) { REG_POWERCNT = on;}
+
+//! Turns off the specified hardware.
+/*! \param off What to power off.
+*/
+static inline void powerOFF(int off) { REG_POWERCNT &= ~off;}
+
+#ifdef ARM9
+#ifdef DOXYGEN
+//! Power-controlled hardware devices accessable to the ARM9.
+/*! Used with %powerON, %powerSET, and %powerOFF functions.
+ Note that these should only be used when programming for
+ the ARM9. Trying to boot up these hardware devices via
+ the ARM7 would lead to unexpected results.
+*/
+enum ARM9_power
+{
+ POWER_LCD, //!< Controls the power for both LCD screens.
+ POWER_2D_A, //!< Controls the power for the main 2D core.
+ POWER_MATRIX, //!< Controls the power for the 3D matrix.
+ POWER_3D_CORE, //!< Controls the power for the main 3D core.
+ POWER_2D_B, //!< Controls the power for the sub 2D core.
+ POWER_SWAP_LCDS, //!< Controls which screen should use the main core.
+};
+#else
+#define POWER_LCD BIT(0)
+#define POWER_2D_A BIT(1)
+#define POWER_MATRIX BIT(2)
+#define POWER_3D_CORE BIT(3)
+#define POWER_2D_B BIT(9)
+#define POWER_SWAP_LCDS BIT(15)
+#endif /* DOXYGEN */
+
+//! Enables power to all hardware required for 2D video.
+#define POWER_ALL_2D (POWER_LCD |POWER_2D_A |POWER_2D_B)
+
+//! Enables power to all hardware required for 3D video.
+#define POWER_ALL (POWER_ALL_2D | POWER_3D_CORE | POWER_MATRIX)
+
+//! Switches the screens.
+static inline void lcdSwap(void) { REG_POWERCNT ^= POWER_SWAP_LCDS; }
+
+//! Forces the main core to display on the top.
+static inline void lcdMainOnTop(void) { REG_POWERCNT |= POWER_SWAP_LCDS; }
+
+//! Forces the main core to display on the bottom.
+static inline void lcdMainOnBottom(void) { REG_POWERCNT &= ~POWER_SWAP_LCDS; }
+#endif
+
+#ifdef ARM7
+#ifdef DOXYGEN
+//! Power-controlled hardware devices accessable to the ARM7.
+/*! Note that these should only be used when programming for
+ the ARM7. Trying to boot up these hardware devices via
+ the ARM9 would lead to unexpected results.
+*/
+enum ARM7_power
+{
+ POWER_SOUND, //!< Controls the power for the sound controller.
+ POWER_UNKNOWN, //!< Controls the power for an unknown device.
+};
+#else
+#define POWER_SOUND BIT(0)
+#define POWER_UNKNOWN BIT(1)
+#endif /* DOXYGEN */
+
+void readUserSettings(void);
+
+#endif /* ARM7 */
+
+//! User's DS settings.
+/*! \struct tPERSONAL_DATA
+
+ Defines the structure the DS firmware uses for transfer
+ of the user's settings to the booted program.
+*/
+typedef struct tPERSONAL_DATA {
+ u8 RESERVED0[2]; //!< ??? (0x05 0x00).
+
+ u8 theme; //!< The user's theme color (0-15).
+ u8 birthMonth; //!< The user's birth month (1-12).
+ u8 birthDay; //!< The user's birth day (1-31).
+
+ u8 RESERVED1[1]; //!< ???
+
+ s16 name[10]; //!< The user's name in UTF-16 format.
+ u16 nameLen; //!< The length of the user's name in characters.
+
+ s16 message[26]; //!< The user's message.
+ u16 messageLen; //!< The length of the user's message in characters.
+
+ u8 alarmHour; //!< What hour the alarm clock is set to (0-23).
+ u8 alarmMinute; //!< What minute the alarm clock is set to (0-59).
+ //0x027FFCD3 alarm minute
+
+ u8 RESERVED2[4]; //!< ???
+ //0x027FFCD4 ??
+
+ u16 calX1; //!< Touchscreen calibration: first X touch
+ u16 calY1; //!< Touchscreen calibration: first Y touch
+ u8 calX1px; //!< Touchscreen calibration: first X touch pixel
+ u8 calY1px; //!< Touchscreen calibration: first X touch pixel
+
+ u16 calX2; //!< Touchscreen calibration: second X touch
+ u16 calY2; //!< Touchscreen calibration: second Y touch
+ u8 calX2px; //!< Touchscreen calibration: second X touch pixel
+ u8 calY2px; //!< Touchscreen calibration: second Y touch pixel
+
+ packed_struct {
+ unsigned language : 3; //!< User's language.
+ unsigned gbaScreen : 1; //!< GBA screen selection (lower screen if set, otherwise upper screen).
+ unsigned defaultBrightness : 2; //!< Brightness level at power on, dslite.
+ unsigned autoMode : 1; //!< The DS should boot from the DS cart or GBA cart automatically if one is inserted.
+ unsigned RESERVED1 : 2; //!< ???
+ unsigned settingsLost : 1; //!< User Settings Lost (0=Normal, 1=Prompt/Settings Lost)
+ unsigned RESERVED2 : 6; //!< ???
+ } _user_data;
+
+ u16 RESERVED3;
+ u32 rtcOffset;
+ u32 RESERVED4;
+} PACKED PERSONAL_DATA ;
+
+//! Key input register.
+/*! On the ARM9, the hinge "button," the touch status, and the
+ X and Y buttons cannot be accessed directly.
+*/
+#define REG_KEYINPUT (*(vuint16*)0x04000130)
+
+//! Key input control register.
+#define REG_KEYCNT (*(vuint16*)0x04000132)
+
+//! Default location for the user's personal data (see %PERSONAL_DATA).
+#define PersonalData ((PERSONAL_DATA*)0x27FFC80)
+
+//! argv structure
+/*! \struct __argv
+
+ structure used to set up argc/argv on the DS
+
+*/
+struct __argv {
+ int argvMagic; //!< argv magic number, set to 0x5f617267 ('_arg') if valid
+ char *commandLine; //!< base address of command line, set of null terminated strings
+ int length; //!< total length of command line
+};
+
+//! Default location for the libnds argv structure.
+#define libnds_argv ((struct __argv *)0x027FFF70)
+
+// argv struct magic number
+#define argvMagic 0x5f617267
+
+#endif
diff --git a/c/src/lib/libbsp/arm/nds/libnds/include/nds/timers.h b/c/src/lib/libbsp/arm/nds/libnds/include/nds/timers.h
index c0edfbb6b7..39951d33ca 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/include/nds/timers.h
+++ b/c/src/lib/libbsp/arm/nds/libnds/include/nds/timers.h
@@ -1,206 +1,206 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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.
-
----------------------------------------------------------------------------------*/
-
-
-/*! \file timers.h
- \brief Contains defines and macros for ARM7 and ARM9 timer operation.
-
- The timers are fed with a 33.4 MHz source on the ARM9. The ARM7
- timing hasn't been tested yet, but is likely to be the same.
-*/
-
-//---------------------------------------------------------------------------------
-#ifndef NDS_TIMERS_INCLUDE
-#define NDS_TIMERS_INCLUDE
-//---------------------------------------------------------------------------------
-
-
-//---------------------------------------------------------------------------------
-#ifdef __cplusplus
-extern "C" {
-#endif
-//---------------------------------------------------------------------------------
-
-
-#include <nds/jtypes.h>
-
-// Timers
-
-//! A macro that calculates %TIMER_DATA(n) settings for a given frequency of n.
-/*! Use the appropriate macro depending on clock divider: \n
- <ul>
- <li> %TIMER_FREQ(f) </li>
- <li> %TIMER_FREQ_64(f) </li>
- <li> %TIMER_FREQ_256(f) </li>
- <li> %TIMER_FREQ_1024(f) </li>
- </ul>
- Clock divider is controlled by %TIMER_CR(n) \n
- \n
- <b>Example Usage:</b>
-
- %TIMER_DATA(0) = %TIMER_FREQ(freq_in_hz); \n
- %TIMER_CR(0) = %TIMER_DIV1 | %TIMER_ENABLE; \n
- \n
- Max frequency is: 33554432Hz\n
- Min frequency is: 512Hz\n
-*/
-#define TIMER_FREQ(n) (-0x2000000/(n))
-
-//! A macro that calculates %TIMER_DATA(n) settings for a given frequency of n.
-/*! Use the appropriate macro depending on clock divider: \n
- <ul>
- <li> %TIMER_FREQ(f) </li>
- <li> %TIMER_FREQ_64(f) </li>
- <li> %TIMER_FREQ_256(f) </li>
- <li> %TIMER_FREQ_1024(f) </li>
- </ul>
-
-
- Clock divider is controlled by %TIMER_CR(n) \n
- \n
- <b>Example Usage:</b>
- %TIMER_DATA(x) = %TIMER_FREQ_64(freq_in_hz)\n
- \n
- Max frequency is: 524288Hz\n
- Min frequency is: 8Hz\n
-*/
-#define TIMER_FREQ_64(n) (-(0x2000000>>6)/(n))
-
-//! A macro that calculates %TIMER_DATA(n) settings for a given frequency of n.
-/*! Use the appropriate macro depending on clock divider: \n
- <ul>
- <li> %TIMER_FREQ(f) </li>
- <li> %TIMER_FREQ_64(f) </li>
- <li> %TIMER_FREQ_256(f) </li>
- <li> %TIMER_FREQ_1024(f) </li>
- </ul> <p>
-
- Clock divider is controlled by %TIMER_CR(n) \n
- \n
- <b>Example Usage:</b>
- %TIMER_DATA(x) = %TIMER_FREQ_256(freq_in_hz)\n
- \n
- Max frequency is: 131072Hz\n
- Min frequency is: 2Hz\n
-*/
-#define TIMER_FREQ_256(n) (-(0x2000000>>8)/(n))
-
-//! A macro that calculates %TIMER_DATA(n) settings for a given frequency of n.
-/*! Use the appropriate macro depending on clock divider: \n
- <ul>
- <li> %TIMER_FREQ(f) </li>
- <li> %TIMER_FREQ_64(f) </li>
- <li> %TIMER_FREQ_256(f) </li>
- <li> TIMER_FREQ_1024(f) </li>
- </ul>
-
- Clock divider is controlled by %TIMER_CR(n) \n
- \n
- <b>Example Usage:</b>
- %TIMER_DATA(x) = %TIMER_FREQ_1024(freq_in_hz)\n
- \n
- Max frequency is: 32768Hz\n
- Min frequency is: 0.5Hz\n
-*/
-#define TIMER_FREQ_1024(n) (-(0x2000000>>10)/(n))
-
-
-//! Same as %TIMER_DATA(0).
-#define TIMER0_DATA (*(vuint16*)0x04000100)
-//! Same as %TIMER_DATA(1).
-#define TIMER1_DATA (*(vuint16*)0x04000104)
-//! Same as %TIMER_DATA(2).
-#define TIMER2_DATA (*(vuint16*)0x04000108)
-//! Same as %TIMER_DATA(3).
-#define TIMER3_DATA (*(vuint16*)0x0400010C)
-
-//! Returns a dereferenced pointer to the data register for timer number "n".
-/*! \see TIMER_CR(n)
- \see TIMER_FREQ(n)
-
- %TIMER_DATA(n) when set will latch that value into the counter. Everytime the
- counter rolls over %TIMER_DATA(0) will return to the latched value. This allows
- you to control the frequency of the timer using the following formula:\n
- %TIMER_DATA(x) = -(0x2000000/(freq * divider)); \n
- \n
- <b>Example Usage:</b>
- %TIMER_DATA(0) = value; were 0 can be 0 through 3 and value is 16 bits.
-*/
-#define TIMER_DATA(n) (*(vuint16*)(0x04000100+((n)<<2)))
-
-// Timer control registers
-//! Same as %TIMER_CR(0).
-#define TIMER0_CR (*(vuint16*)0x04000102)
-//! Same as %TIMER_CR(1).
-#define TIMER1_CR (*(vuint16*)0x04000106)
-//! Same as %TIMER_CR(2).
-#define TIMER2_CR (*(vuint16*)0x0400010A)
-//! Same as %TIMER_CR(3).
-#define TIMER3_CR (*(vuint16*)0x0400010E)
-
-//! Returns a dereferenced pointer to the data register for timer control Register.
-/*! <b>Example Usage:</b> %TIMER_CR(x) = %TIMER_ENABLE | %TIMER_DIV_64; \n
- \n
- Possible bit defines: \n
-
- \see TIMER_ENABLE
- \see TIMER_IRQ_REQ
- \see TIMER_DIV_1
- \see TIMER_DIV_64
- \see TIMER_DIV_256
- \see TIMER_DIV_1024
-*/
-#define TIMER_CR(n) (*(vuint16*)(0x04000102+((n)<<2)))
-
-//! Enables the timer.
-#define TIMER_ENABLE (1<<7)
-
-//! Causes the timer to request an Interupt on overflow.
-#define TIMER_IRQ_REQ (1<<6)
-
-//! When set will cause the timer to count when the timer below overflows (unavailable for timer 0).
-#define TIMER_CASCADE (1<<2)
-
-//! Causes the timer to count at 33.514Mhz.
-#define TIMER_DIV_1 (0)
-//! Causes the timer to count at (33.514 / 64) Mhz.
-#define TIMER_DIV_64 (1)
-//! Causes the timer to count at (33.514 / 256) Mhz.
-#define TIMER_DIV_256 (2)
-//! Causes the timer to count at (33.514 / 1024)Mhz.
-#define TIMER_DIV_1024 (3)
-
-//---------------------------------------------------------------------------------
-#ifdef __cplusplus
-}
-#endif
-//---------------------------------------------------------------------------------
-
-//---------------------------------------------------------------------------------
-#endif
-//---------------------------------------------------------------------------------
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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.
+
+---------------------------------------------------------------------------------*/
+
+
+/*! \file timers.h
+ \brief Contains defines and macros for ARM7 and ARM9 timer operation.
+
+ The timers are fed with a 33.4 MHz source on the ARM9. The ARM7
+ timing hasn't been tested yet, but is likely to be the same.
+*/
+
+//---------------------------------------------------------------------------------
+#ifndef NDS_TIMERS_INCLUDE
+#define NDS_TIMERS_INCLUDE
+//---------------------------------------------------------------------------------
+
+
+//---------------------------------------------------------------------------------
+#ifdef __cplusplus
+extern "C" {
+#endif
+//---------------------------------------------------------------------------------
+
+
+#include <nds/jtypes.h>
+
+// Timers
+
+//! A macro that calculates %TIMER_DATA(n) settings for a given frequency of n.
+/*! Use the appropriate macro depending on clock divider: \n
+ <ul>
+ <li> %TIMER_FREQ(f) </li>
+ <li> %TIMER_FREQ_64(f) </li>
+ <li> %TIMER_FREQ_256(f) </li>
+ <li> %TIMER_FREQ_1024(f) </li>
+ </ul>
+ Clock divider is controlled by %TIMER_CR(n) \n
+ \n
+ <b>Example Usage:</b>
+
+ %TIMER_DATA(0) = %TIMER_FREQ(freq_in_hz); \n
+ %TIMER_CR(0) = %TIMER_DIV1 | %TIMER_ENABLE; \n
+ \n
+ Max frequency is: 33554432Hz\n
+ Min frequency is: 512Hz\n
+*/
+#define TIMER_FREQ(n) (-0x2000000/(n))
+
+//! A macro that calculates %TIMER_DATA(n) settings for a given frequency of n.
+/*! Use the appropriate macro depending on clock divider: \n
+ <ul>
+ <li> %TIMER_FREQ(f) </li>
+ <li> %TIMER_FREQ_64(f) </li>
+ <li> %TIMER_FREQ_256(f) </li>
+ <li> %TIMER_FREQ_1024(f) </li>
+ </ul>
+
+
+ Clock divider is controlled by %TIMER_CR(n) \n
+ \n
+ <b>Example Usage:</b>
+ %TIMER_DATA(x) = %TIMER_FREQ_64(freq_in_hz)\n
+ \n
+ Max frequency is: 524288Hz\n
+ Min frequency is: 8Hz\n
+*/
+#define TIMER_FREQ_64(n) (-(0x2000000>>6)/(n))
+
+//! A macro that calculates %TIMER_DATA(n) settings for a given frequency of n.
+/*! Use the appropriate macro depending on clock divider: \n
+ <ul>
+ <li> %TIMER_FREQ(f) </li>
+ <li> %TIMER_FREQ_64(f) </li>
+ <li> %TIMER_FREQ_256(f) </li>
+ <li> %TIMER_FREQ_1024(f) </li>
+ </ul> <p>
+
+ Clock divider is controlled by %TIMER_CR(n) \n
+ \n
+ <b>Example Usage:</b>
+ %TIMER_DATA(x) = %TIMER_FREQ_256(freq_in_hz)\n
+ \n
+ Max frequency is: 131072Hz\n
+ Min frequency is: 2Hz\n
+*/
+#define TIMER_FREQ_256(n) (-(0x2000000>>8)/(n))
+
+//! A macro that calculates %TIMER_DATA(n) settings for a given frequency of n.
+/*! Use the appropriate macro depending on clock divider: \n
+ <ul>
+ <li> %TIMER_FREQ(f) </li>
+ <li> %TIMER_FREQ_64(f) </li>
+ <li> %TIMER_FREQ_256(f) </li>
+ <li> TIMER_FREQ_1024(f) </li>
+ </ul>
+
+ Clock divider is controlled by %TIMER_CR(n) \n
+ \n
+ <b>Example Usage:</b>
+ %TIMER_DATA(x) = %TIMER_FREQ_1024(freq_in_hz)\n
+ \n
+ Max frequency is: 32768Hz\n
+ Min frequency is: 0.5Hz\n
+*/
+#define TIMER_FREQ_1024(n) (-(0x2000000>>10)/(n))
+
+
+//! Same as %TIMER_DATA(0).
+#define TIMER0_DATA (*(vuint16*)0x04000100)
+//! Same as %TIMER_DATA(1).
+#define TIMER1_DATA (*(vuint16*)0x04000104)
+//! Same as %TIMER_DATA(2).
+#define TIMER2_DATA (*(vuint16*)0x04000108)
+//! Same as %TIMER_DATA(3).
+#define TIMER3_DATA (*(vuint16*)0x0400010C)
+
+//! Returns a dereferenced pointer to the data register for timer number "n".
+/*! \see TIMER_CR(n)
+ \see TIMER_FREQ(n)
+
+ %TIMER_DATA(n) when set will latch that value into the counter. Everytime the
+ counter rolls over %TIMER_DATA(0) will return to the latched value. This allows
+ you to control the frequency of the timer using the following formula:\n
+ %TIMER_DATA(x) = -(0x2000000/(freq * divider)); \n
+ \n
+ <b>Example Usage:</b>
+ %TIMER_DATA(0) = value; were 0 can be 0 through 3 and value is 16 bits.
+*/
+#define TIMER_DATA(n) (*(vuint16*)(0x04000100+((n)<<2)))
+
+// Timer control registers
+//! Same as %TIMER_CR(0).
+#define TIMER0_CR (*(vuint16*)0x04000102)
+//! Same as %TIMER_CR(1).
+#define TIMER1_CR (*(vuint16*)0x04000106)
+//! Same as %TIMER_CR(2).
+#define TIMER2_CR (*(vuint16*)0x0400010A)
+//! Same as %TIMER_CR(3).
+#define TIMER3_CR (*(vuint16*)0x0400010E)
+
+//! Returns a dereferenced pointer to the data register for timer control Register.
+/*! <b>Example Usage:</b> %TIMER_CR(x) = %TIMER_ENABLE | %TIMER_DIV_64; \n
+ \n
+ Possible bit defines: \n
+
+ \see TIMER_ENABLE
+ \see TIMER_IRQ_REQ
+ \see TIMER_DIV_1
+ \see TIMER_DIV_64
+ \see TIMER_DIV_256
+ \see TIMER_DIV_1024
+*/
+#define TIMER_CR(n) (*(vuint16*)(0x04000102+((n)<<2)))
+
+//! Enables the timer.
+#define TIMER_ENABLE (1<<7)
+
+//! Causes the timer to request an Interupt on overflow.
+#define TIMER_IRQ_REQ (1<<6)
+
+//! When set will cause the timer to count when the timer below overflows (unavailable for timer 0).
+#define TIMER_CASCADE (1<<2)
+
+//! Causes the timer to count at 33.514Mhz.
+#define TIMER_DIV_1 (0)
+//! Causes the timer to count at (33.514 / 64) Mhz.
+#define TIMER_DIV_64 (1)
+//! Causes the timer to count at (33.514 / 256) Mhz.
+#define TIMER_DIV_256 (2)
+//! Causes the timer to count at (33.514 / 1024)Mhz.
+#define TIMER_DIV_1024 (3)
+
+//---------------------------------------------------------------------------------
+#ifdef __cplusplus
+}
+#endif
+//---------------------------------------------------------------------------------
+
+//---------------------------------------------------------------------------------
+#endif
+//---------------------------------------------------------------------------------
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/source/arm7/audio.c b/c/src/lib/libbsp/arm/nds/libnds/source/arm7/audio.c
index 365ac688fe..7a32b1b618 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/source/arm7/audio.c
+++ b/c/src/lib/libbsp/arm/nds/libnds/source/arm7/audio.c
@@ -1,27 +1,27 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
-
- Copyright (C) 2005
- Dave Murphy (WinterMute)
-
- 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/arm7/audio.h"
+/*---------------------------------------------------------------------------------
+ $Id$
+
+
+ Copyright (C) 2005
+ Dave Murphy (WinterMute)
+
+ 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/arm7/audio.h"
diff --git a/c/src/lib/libbsp/arm/nds/libnds/source/arm7/clock.c b/c/src/lib/libbsp/arm/nds/libnds/source/arm7/clock.c
index eb27824ad0..78727af35c 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/source/arm7/clock.c
+++ b/c/src/lib/libbsp/arm/nds/libnds/source/arm7/clock.c
@@ -1,278 +1,278 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- Copyright (C) 2005
- Michael Noland (Joat)
- Jason Rogers (Dovoto)
- Dave Murphy (WinterMute)
-
- 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/bios.h"
-#include "nds/arm7/clock.h"
-#include "nds/interrupts.h"
-#include "nds/ipc.h"
-
-#include <time.h>
-
-
-
-// Delay (in swiDelay units) for each bit transfer
-#define RTC_DELAY 48
-
-// Pin defines on RTC_CR
-#define CS_0 (1<<6)
-#define CS_1 ((1<<6) | (1<<2))
-#define SCK_0 (1<<5)
-#define SCK_1 ((1<<5) | (1<<1))
-#define SIO_0 (1<<4)
-#define SIO_1 ((1<<4) | (1<<0))
-#define SIO_out (1<<4)
-#define SIO_in (1)
-
-//---------------------------------------------------------------------------------
-void BCDToInteger(uint8 * data, uint32 length) {
-//---------------------------------------------------------------------------------
- u32 i;
- for (i = 0; i < length; i++) {
- data[i] = (data[i] & 0xF) + ((data[i] & 0xF0)>>4)*10;
- }
-}
-
-
-//---------------------------------------------------------------------------------
-void integerToBCD(uint8 * data, uint32 length) {
-//---------------------------------------------------------------------------------
- u32 i;
- for (i = 0; i < length; i++) {
- int high, low;
- swiDivMod(data[i], 10, &high, &low);
- data[i] = (high<<4) | low;
- }
-}
-
-//---------------------------------------------------------------------------------
-void rtcTransaction(uint8 * command, uint32 commandLength, uint8 * result, uint32 resultLength) {
-//---------------------------------------------------------------------------------
- uint32 bit;
- uint8 data;
-
- // Raise CS
- RTC_CR8 = CS_0 | SCK_1 | SIO_1;
- swiDelay(RTC_DELAY);
- RTC_CR8 = CS_1 | SCK_1 | SIO_1;
- swiDelay(RTC_DELAY);
-
- // Write command byte (high bit first)
- data = *command++;
-
- for (bit = 0; bit < 8; bit++) {
- RTC_CR8 = CS_1 | SCK_0 | SIO_out | (data>>7);
- swiDelay(RTC_DELAY);
-
- RTC_CR8 = CS_1 | SCK_1 | SIO_out | (data>>7);
- swiDelay(RTC_DELAY);
-
- data = data << 1;
- }
- // Write parameter bytes (low bit first)
- for ( ; commandLength > 1; commandLength--) {
- data = *command++;
-
- for (bit = 0; bit < 8; bit++) {
- RTC_CR8 = CS_1 | SCK_0 | SIO_out | (data & 1);
- swiDelay(RTC_DELAY);
-
- RTC_CR8 = CS_1 | SCK_1 | SIO_out | (data & 1);
- swiDelay(RTC_DELAY);
-
- data = data >> 1;
- }
- }
-
- // Read result bytes (low bit first)
- for ( ; resultLength > 0; resultLength--) {
- data = 0;
-
- for (bit = 0; bit < 8; bit++) {
- RTC_CR8 = CS_1 | SCK_0;
- swiDelay(RTC_DELAY);
-
- RTC_CR8 = CS_1 | SCK_1;
- swiDelay(RTC_DELAY);
-
- if (RTC_CR8 & SIO_in) data |= (1 << bit);
- }
- *result++ = data;
- }
-
- // Finish up by dropping CS low
- RTC_CR8 = CS_0 | SCK_1;
- swiDelay(RTC_DELAY);
-}
-
-
-//---------------------------------------------------------------------------------
-void rtcReset(void) {
-//---------------------------------------------------------------------------------
- uint8 status;
- uint8 command[2];
-
- // Read the first status register
- command[0] = READ_STATUS_REG1;
- rtcTransaction(command, 1, &status, 1);
-
- // Reset the RTC if needed
- if (status & (STATUS_POC | STATUS_BLD)) {
- command[0] = WRITE_STATUS_REG1;
- command[1] = status | STATUS_RESET;
- rtcTransaction(command, 2, 0, 0);
- }
-}
-
-
-//---------------------------------------------------------------------------------
-void rtcGetTimeAndDate(uint8 * time) {
-//---------------------------------------------------------------------------------
- uint8 command, status;
-
- command = READ_TIME_AND_DATE;
- rtcTransaction(&command, 1, time, 7);
-
- command = READ_STATUS_REG1;
- rtcTransaction(&command, 1, &status, 1);
-
- if ( status & STATUS_24HRS ) {
- time[4] &= 0x3f;
- } else {
-
- }
- BCDToInteger(time,7);
-}
-
-//---------------------------------------------------------------------------------
-void rtcSetTimeAndDate(uint8 * time) {
-//---------------------------------------------------------------------------------
- uint8 command[8];
-
- int i;
- for ( i=0; i< 8; i++ ) {
- command[i+1] = time[i];
- }
- command[0] = WRITE_TIME_AND_DATE;
- // fixme: range checking on the data we tell it
- rtcTransaction(command, 8, 0, 0);
-}
-
-//---------------------------------------------------------------------------------
-void rtcGetTime(uint8 * time) {
-//---------------------------------------------------------------------------------
- uint8 command, status;
-
- command = READ_TIME;
- rtcTransaction(&command, 1, time, 3);
-
- command = READ_STATUS_REG1;
- rtcTransaction(&command, 1, &status, 1);
- if ( status & STATUS_24HRS ) {
- time[0] &= 0x3f;
- } else {
-
- }
- BCDToInteger(time,3);
-
-}
-
-//---------------------------------------------------------------------------------
-void rtcSetTime(uint8 * time) {
-//---------------------------------------------------------------------------------
- uint8 command[4];
-
- int i;
- for ( i=0; i< 3; i++ ) {
- command[i+1] = time[i];
- }
- command[0] = WRITE_TIME;
- // fixme: range checking on the data we tell it
- rtcTransaction(command, 4, 0, 0);
-}
-
-//---------------------------------------------------------------------------------
-void syncRTC() {
-//---------------------------------------------------------------------------------
- if (++IPC->time.rtc.seconds == 60 ) {
- IPC->time.rtc.seconds = 0;
- if (++IPC->time.rtc.minutes == 60) {
- IPC->time.rtc.minutes = 0;
- if (++IPC->time.rtc.hours == 24) {
- rtcGetTimeAndDate((uint8 *)&(IPC->time.rtc.year));
- }
- }
- }
-
- IPC->unixTime++;
-}
-
-//---------------------------------------------------------------------------------
-void initClockIRQ() {
-//---------------------------------------------------------------------------------
-
- REG_RCNT = 0x8100;
- irqSet(IRQ_NETWORK, syncRTC);
- // Reset the clock if needed
- rtcReset();
-
- uint8 command[4];
- command[0] = READ_STATUS_REG2;
- rtcTransaction(command, 1, &command[1], 1);
-
- command[0] = WRITE_STATUS_REG2;
- command[1] = 0x41;
- rtcTransaction(command, 2, 0, 0);
-
- command[0] = WRITE_INT_REG1;
- command[1] = 0x01;
- rtcTransaction(command, 2, 0, 0);
-
- command[0] = WRITE_INT_REG2;
- command[1] = 0x00;
- command[2] = 0x21;
- command[3] = 0x35;
- rtcTransaction(command, 4, 0, 0);
-
- // Read all time settings on first start
- rtcGetTimeAndDate((uint8 *)&(IPC->time.rtc.year));
-
-
- struct tm currentTime;
-
- currentTime.tm_sec = IPC->time.rtc.seconds;
- currentTime.tm_min = IPC->time.rtc.minutes;
- currentTime.tm_hour = IPC->time.rtc.hours;
-
- currentTime.tm_mday = IPC->time.rtc.day;
- currentTime.tm_mon = IPC->time.rtc.month - 1;
- currentTime.tm_year = IPC->time.rtc.year + 100;
-
- currentTime.tm_isdst = -1;
-
- IPC->unixTime = mktime(&currentTime);
-}
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ Copyright (C) 2005
+ Michael Noland (Joat)
+ Jason Rogers (Dovoto)
+ Dave Murphy (WinterMute)
+
+ 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/bios.h"
+#include "nds/arm7/clock.h"
+#include "nds/interrupts.h"
+#include "nds/ipc.h"
+
+#include <time.h>
+
+
+
+// Delay (in swiDelay units) for each bit transfer
+#define RTC_DELAY 48
+
+// Pin defines on RTC_CR
+#define CS_0 (1<<6)
+#define CS_1 ((1<<6) | (1<<2))
+#define SCK_0 (1<<5)
+#define SCK_1 ((1<<5) | (1<<1))
+#define SIO_0 (1<<4)
+#define SIO_1 ((1<<4) | (1<<0))
+#define SIO_out (1<<4)
+#define SIO_in (1)
+
+//---------------------------------------------------------------------------------
+void BCDToInteger(uint8 * data, uint32 length) {
+//---------------------------------------------------------------------------------
+ u32 i;
+ for (i = 0; i < length; i++) {
+ data[i] = (data[i] & 0xF) + ((data[i] & 0xF0)>>4)*10;
+ }
+}
+
+
+//---------------------------------------------------------------------------------
+void integerToBCD(uint8 * data, uint32 length) {
+//---------------------------------------------------------------------------------
+ u32 i;
+ for (i = 0; i < length; i++) {
+ int high, low;
+ swiDivMod(data[i], 10, &high, &low);
+ data[i] = (high<<4) | low;
+ }
+}
+
+//---------------------------------------------------------------------------------
+void rtcTransaction(uint8 * command, uint32 commandLength, uint8 * result, uint32 resultLength) {
+//---------------------------------------------------------------------------------
+ uint32 bit;
+ uint8 data;
+
+ // Raise CS
+ RTC_CR8 = CS_0 | SCK_1 | SIO_1;
+ swiDelay(RTC_DELAY);
+ RTC_CR8 = CS_1 | SCK_1 | SIO_1;
+ swiDelay(RTC_DELAY);
+
+ // Write command byte (high bit first)
+ data = *command++;
+
+ for (bit = 0; bit < 8; bit++) {
+ RTC_CR8 = CS_1 | SCK_0 | SIO_out | (data>>7);
+ swiDelay(RTC_DELAY);
+
+ RTC_CR8 = CS_1 | SCK_1 | SIO_out | (data>>7);
+ swiDelay(RTC_DELAY);
+
+ data = data << 1;
+ }
+ // Write parameter bytes (low bit first)
+ for ( ; commandLength > 1; commandLength--) {
+ data = *command++;
+
+ for (bit = 0; bit < 8; bit++) {
+ RTC_CR8 = CS_1 | SCK_0 | SIO_out | (data & 1);
+ swiDelay(RTC_DELAY);
+
+ RTC_CR8 = CS_1 | SCK_1 | SIO_out | (data & 1);
+ swiDelay(RTC_DELAY);
+
+ data = data >> 1;
+ }
+ }
+
+ // Read result bytes (low bit first)
+ for ( ; resultLength > 0; resultLength--) {
+ data = 0;
+
+ for (bit = 0; bit < 8; bit++) {
+ RTC_CR8 = CS_1 | SCK_0;
+ swiDelay(RTC_DELAY);
+
+ RTC_CR8 = CS_1 | SCK_1;
+ swiDelay(RTC_DELAY);
+
+ if (RTC_CR8 & SIO_in) data |= (1 << bit);
+ }
+ *result++ = data;
+ }
+
+ // Finish up by dropping CS low
+ RTC_CR8 = CS_0 | SCK_1;
+ swiDelay(RTC_DELAY);
+}
+
+
+//---------------------------------------------------------------------------------
+void rtcReset(void) {
+//---------------------------------------------------------------------------------
+ uint8 status;
+ uint8 command[2];
+
+ // Read the first status register
+ command[0] = READ_STATUS_REG1;
+ rtcTransaction(command, 1, &status, 1);
+
+ // Reset the RTC if needed
+ if (status & (STATUS_POC | STATUS_BLD)) {
+ command[0] = WRITE_STATUS_REG1;
+ command[1] = status | STATUS_RESET;
+ rtcTransaction(command, 2, 0, 0);
+ }
+}
+
+
+//---------------------------------------------------------------------------------
+void rtcGetTimeAndDate(uint8 * time) {
+//---------------------------------------------------------------------------------
+ uint8 command, status;
+
+ command = READ_TIME_AND_DATE;
+ rtcTransaction(&command, 1, time, 7);
+
+ command = READ_STATUS_REG1;
+ rtcTransaction(&command, 1, &status, 1);
+
+ if ( status & STATUS_24HRS ) {
+ time[4] &= 0x3f;
+ } else {
+
+ }
+ BCDToInteger(time,7);
+}
+
+//---------------------------------------------------------------------------------
+void rtcSetTimeAndDate(uint8 * time) {
+//---------------------------------------------------------------------------------
+ uint8 command[8];
+
+ int i;
+ for ( i=0; i< 8; i++ ) {
+ command[i+1] = time[i];
+ }
+ command[0] = WRITE_TIME_AND_DATE;
+ // fixme: range checking on the data we tell it
+ rtcTransaction(command, 8, 0, 0);
+}
+
+//---------------------------------------------------------------------------------
+void rtcGetTime(uint8 * time) {
+//---------------------------------------------------------------------------------
+ uint8 command, status;
+
+ command = READ_TIME;
+ rtcTransaction(&command, 1, time, 3);
+
+ command = READ_STATUS_REG1;
+ rtcTransaction(&command, 1, &status, 1);
+ if ( status & STATUS_24HRS ) {
+ time[0] &= 0x3f;
+ } else {
+
+ }
+ BCDToInteger(time,3);
+
+}
+
+//---------------------------------------------------------------------------------
+void rtcSetTime(uint8 * time) {
+//---------------------------------------------------------------------------------
+ uint8 command[4];
+
+ int i;
+ for ( i=0; i< 3; i++ ) {
+ command[i+1] = time[i];
+ }
+ command[0] = WRITE_TIME;
+ // fixme: range checking on the data we tell it
+ rtcTransaction(command, 4, 0, 0);
+}
+
+//---------------------------------------------------------------------------------
+void syncRTC() {
+//---------------------------------------------------------------------------------
+ if (++IPC->time.rtc.seconds == 60 ) {
+ IPC->time.rtc.seconds = 0;
+ if (++IPC->time.rtc.minutes == 60) {
+ IPC->time.rtc.minutes = 0;
+ if (++IPC->time.rtc.hours == 24) {
+ rtcGetTimeAndDate((uint8 *)&(IPC->time.rtc.year));
+ }
+ }
+ }
+
+ IPC->unixTime++;
+}
+
+//---------------------------------------------------------------------------------
+void initClockIRQ() {
+//---------------------------------------------------------------------------------
+
+ REG_RCNT = 0x8100;
+ irqSet(IRQ_NETWORK, syncRTC);
+ // Reset the clock if needed
+ rtcReset();
+
+ uint8 command[4];
+ command[0] = READ_STATUS_REG2;
+ rtcTransaction(command, 1, &command[1], 1);
+
+ command[0] = WRITE_STATUS_REG2;
+ command[1] = 0x41;
+ rtcTransaction(command, 2, 0, 0);
+
+ command[0] = WRITE_INT_REG1;
+ command[1] = 0x01;
+ rtcTransaction(command, 2, 0, 0);
+
+ command[0] = WRITE_INT_REG2;
+ command[1] = 0x00;
+ command[2] = 0x21;
+ command[3] = 0x35;
+ rtcTransaction(command, 4, 0, 0);
+
+ // Read all time settings on first start
+ rtcGetTimeAndDate((uint8 *)&(IPC->time.rtc.year));
+
+
+ struct tm currentTime;
+
+ currentTime.tm_sec = IPC->time.rtc.seconds;
+ currentTime.tm_min = IPC->time.rtc.minutes;
+ currentTime.tm_hour = IPC->time.rtc.hours;
+
+ currentTime.tm_mday = IPC->time.rtc.day;
+ currentTime.tm_mon = IPC->time.rtc.month - 1;
+ currentTime.tm_year = IPC->time.rtc.year + 100;
+
+ currentTime.tm_isdst = -1;
+
+ IPC->unixTime = mktime(&currentTime);
+}
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/source/arm7/microphone.c b/c/src/lib/libbsp/arm/nds/libnds/source/arm7/microphone.c
index e5e29db24b..df04527e48 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/source/arm7/microphone.c
+++ b/c/src/lib/libbsp/arm/nds/libnds/source/arm7/microphone.c
@@ -1,115 +1,115 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- Microphone control for the ARM7
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
- Chris Double (doublec)
-
- 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/arm7/audio.h>
-#include <nds/timers.h>
-
-//---------------------------------------------------------------------------------
-// Turn on the Microphone Amp. Code based on neimod's example.
-//---------------------------------------------------------------------------------
-void PM_SetAmp(u8 control) {
-//---------------------------------------------------------------------------------
- SerialWaitBusy();
- REG_SPICNT = SPI_ENABLE | SPI_DEVICE_POWER | SPI_BAUD_1MHz | SPI_CONTINUOUS;
- REG_SPIDATA = PM_AMP_OFFSET;
-
- SerialWaitBusy();
-
- REG_SPICNT = SPI_ENABLE | SPI_DEVICE_POWER | SPI_BAUD_1MHz;
- REG_SPIDATA = control;
-}
-
-//---------------------------------------------------------------------------------
-// Read a byte from the microphone. Code based on neimod's example.
-//---------------------------------------------------------------------------------
-u8 MIC_ReadData() {
-//---------------------------------------------------------------------------------
- u16 result, result2;
-
- SerialWaitBusy();
-
- REG_SPICNT = SPI_ENABLE | SPI_DEVICE_MICROPHONE | SPI_BAUD_2MHz | SPI_CONTINUOUS;
- REG_SPIDATA = 0xEC; // Touchscreen command format for AUX
-
- SerialWaitBusy();
-
- REG_SPIDATA = 0x00;
-
- SerialWaitBusy();
-
- result = REG_SPIDATA;
- REG_SPICNT = SPI_ENABLE | SPI_DEVICE_TOUCH | SPI_BAUD_2MHz;
- REG_SPIDATA = 0x00;
-
- SerialWaitBusy();
-
- result2 = REG_SPIDATA;
-
- return (((result & 0x7F) << 1) | ((result2>>7)&1));
-}
-
-static u8* microphone_buffer = 0;
-static int microphone_buffer_length = 0;
-static int current_length = 0;
-
-
-//---------------------------------------------------------------------------------
-void StartRecording(u8* buffer, int length) {
-//---------------------------------------------------------------------------------
- microphone_buffer = buffer;
- microphone_buffer_length = length;
- current_length = 0;
-
- MIC_On();
-
- // Setup a 16kHz timer
- TIMER0_DATA = 0xF7CF;
- TIMER0_CR = TIMER_ENABLE | TIMER_DIV_1 | TIMER_IRQ_REQ;
-}
-
-//---------------------------------------------------------------------------------
-int StopRecording() {
-//---------------------------------------------------------------------------------
- TIMER0_CR &= ~TIMER_ENABLE;
- MIC_Off();
- microphone_buffer = 0;
- return current_length;
-}
-
-//---------------------------------------------------------------------------------
-void ProcessMicrophoneTimerIRQ() {
-//---------------------------------------------------------------------------------
- if(microphone_buffer && microphone_buffer_length > 0) {
- // Read data from the microphone. Data from the Mic is unsigned, flipping
- // the highest bit makes it signed.
- *microphone_buffer++ = MIC_ReadData() ^ 0x80;
- --microphone_buffer_length;
- current_length++;
- }
-}
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ Microphone control for the ARM7
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+ Chris Double (doublec)
+
+ 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/arm7/audio.h>
+#include <nds/timers.h>
+
+//---------------------------------------------------------------------------------
+// Turn on the Microphone Amp. Code based on neimod's example.
+//---------------------------------------------------------------------------------
+void PM_SetAmp(u8 control) {
+//---------------------------------------------------------------------------------
+ SerialWaitBusy();
+ REG_SPICNT = SPI_ENABLE | SPI_DEVICE_POWER | SPI_BAUD_1MHz | SPI_CONTINUOUS;
+ REG_SPIDATA = PM_AMP_OFFSET;
+
+ SerialWaitBusy();
+
+ REG_SPICNT = SPI_ENABLE | SPI_DEVICE_POWER | SPI_BAUD_1MHz;
+ REG_SPIDATA = control;
+}
+
+//---------------------------------------------------------------------------------
+// Read a byte from the microphone. Code based on neimod's example.
+//---------------------------------------------------------------------------------
+u8 MIC_ReadData() {
+//---------------------------------------------------------------------------------
+ u16 result, result2;
+
+ SerialWaitBusy();
+
+ REG_SPICNT = SPI_ENABLE | SPI_DEVICE_MICROPHONE | SPI_BAUD_2MHz | SPI_CONTINUOUS;
+ REG_SPIDATA = 0xEC; // Touchscreen command format for AUX
+
+ SerialWaitBusy();
+
+ REG_SPIDATA = 0x00;
+
+ SerialWaitBusy();
+
+ result = REG_SPIDATA;
+ REG_SPICNT = SPI_ENABLE | SPI_DEVICE_TOUCH | SPI_BAUD_2MHz;
+ REG_SPIDATA = 0x00;
+
+ SerialWaitBusy();
+
+ result2 = REG_SPIDATA;
+
+ return (((result & 0x7F) << 1) | ((result2>>7)&1));
+}
+
+static u8* microphone_buffer = 0;
+static int microphone_buffer_length = 0;
+static int current_length = 0;
+
+
+//---------------------------------------------------------------------------------
+void StartRecording(u8* buffer, int length) {
+//---------------------------------------------------------------------------------
+ microphone_buffer = buffer;
+ microphone_buffer_length = length;
+ current_length = 0;
+
+ MIC_On();
+
+ // Setup a 16kHz timer
+ TIMER0_DATA = 0xF7CF;
+ TIMER0_CR = TIMER_ENABLE | TIMER_DIV_1 | TIMER_IRQ_REQ;
+}
+
+//---------------------------------------------------------------------------------
+int StopRecording() {
+//---------------------------------------------------------------------------------
+ TIMER0_CR &= ~TIMER_ENABLE;
+ MIC_Off();
+ microphone_buffer = 0;
+ return current_length;
+}
+
+//---------------------------------------------------------------------------------
+void ProcessMicrophoneTimerIRQ() {
+//---------------------------------------------------------------------------------
+ if(microphone_buffer && microphone_buffer_length > 0) {
+ // Read data from the microphone. Data from the Mic is unsigned, flipping
+ // the highest bit makes it signed.
+ *microphone_buffer++ = MIC_ReadData() ^ 0x80;
+ --microphone_buffer_length;
+ current_length++;
+ }
+}
diff --git a/c/src/lib/libbsp/arm/nds/libnds/source/arm7/touch.c b/c/src/lib/libbsp/arm/nds/libnds/source/arm7/touch.c
index a6cdd6b07f..11c25cb03c 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/source/arm7/touch.c
+++ b/c/src/lib/libbsp/arm/nds/libnds/source/arm7/touch.c
@@ -1,373 +1,373 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- Touch screen control for the ARM7
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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/jtypes.h>
-#include <nds/system.h>
-#include <nds/arm7/touch.h>
-#include <nds/interrupts.h>
-
-#include <stdlib.h>
-
-static u8 last_time_touched = 0;
-
-static u8 range_counter_1 = 0;
-static u8 range_counter_2 = 0;
-static u8 range = 20;
-static u8 min_range = 20;
-
-//---------------------------------------------------------------------------------
-u8 CheckStylus(){
-//---------------------------------------------------------------------------------
-
- SerialWaitBusy();
-
- REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH | SPI_CONTINUOUS; //0x8A01;
- REG_SPIDATA = TSC_MEASURE_TEMP1;
-
- SerialWaitBusy();
-
- REG_SPIDATA = 0;
-
- SerialWaitBusy();
-
- REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH;// 0x8201;
- REG_SPIDATA = 0;
-
- SerialWaitBusy();
-
- if(last_time_touched == 1){
- if( !(REG_KEYXY & 0x40) )
- return 1;
- else{
- REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH | SPI_CONTINUOUS;
- REG_SPIDATA = TSC_MEASURE_TEMP1;
-
- SerialWaitBusy();
-
- REG_SPIDATA = 0;
-
- SerialWaitBusy();
-
- REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH;
- REG_SPIDATA = 0;
-
- SerialWaitBusy();
-
- return !(REG_KEYXY & 0x40) ? 2 : 0;
- }
- }else{
- return !(REG_KEYXY & 0x40) ? 1 : 0;
- }
-}
-
-//---------------------------------------------------------------------------------
-uint16 touchRead(uint32 command) {
-//---------------------------------------------------------------------------------
- uint16 result, result2;
-
- uint32 oldIME = REG_IME;
-
- REG_IME = 0;
-
- SerialWaitBusy();
-
- // Write the command and wait for it to complete
- REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH | SPI_CONTINUOUS; //0x8A01;
- REG_SPIDATA = command;
- SerialWaitBusy();
-
- // Write the second command and clock in part of the data
- REG_SPIDATA = 0;
- SerialWaitBusy();
- result = REG_SPIDATA;
-
- // Clock in the rest of the data (last transfer)
- REG_SPICNT = SPI_ENABLE | 0x201;
- REG_SPIDATA = 0;
- SerialWaitBusy();
-
- result2 = REG_SPIDATA >>3;
-
- REG_IME = oldIME;
-
- // Return the result
- return ((result & 0x7F) << 5) | result2;
-}
-
-
-//---------------------------------------------------------------------------------
-uint32 touchReadTemperature(int * t1, int * t2) {
-//---------------------------------------------------------------------------------
- *t1 = touchRead(TSC_MEASURE_TEMP1);
- *t2 = touchRead(TSC_MEASURE_TEMP2);
- return 8490 * (*t2 - *t1) - 273*4096;
-}
-
-
-static bool touchInit = false;
-static s32 xscale, yscale;
-static s32 xoffset, yoffset;
-
-//---------------------------------------------------------------------------------
-int16 readTouchValue(uint32 command, int16 *dist_max, u8 *err){
-//---------------------------------------------------------------------------------
- int16 values[5];
- int32 aux1, aux2, aux3, dist, dist2, result = 0;
- u8 i, j, k;
-
- *err = 1;
-
- SerialWaitBusy();
-
- REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH | SPI_CONTINUOUS;
- REG_SPIDATA = command;
-
- SerialWaitBusy();
-
- for(i=0; i<5; i++){
- REG_SPIDATA = 0;
- SerialWaitBusy();
-
- aux1 = REG_SPIDATA;
- aux1 = aux1 & 0xFF;
- aux1 = aux1 << 16;
- aux1 = aux1 >> 8;
-
- values[4-i] = aux1;
-
- REG_SPIDATA = command;
- SerialWaitBusy();
-
- aux1 = REG_SPIDATA;
- aux1 = aux1 & 0xFF;
- aux1 = aux1 << 16;
-
- aux1 = values[4-i] | (aux1 >> 16);
- values[4-i] = ((aux1 & 0x7FF8) >> 3);
- }
-
- REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH;
- REG_SPIDATA = 0;
- SerialWaitBusy();
-
- dist = 0;
- for(i=0; i<4; i++){
- aux1 = values[i];
-
- for(j=i+1; j<5; j++){
- aux2 = values[j];
- aux2 = abs(aux1 - aux2);
- if(aux2>dist) dist = aux2;
- }
- }
-
- *dist_max = dist;
-
- for(i=0; i<3; i++){
- aux1 = values[i];
-
- for(j=i+1; j<4; j++){
- aux2 = values[j];
- dist = abs(aux1 - aux2);
-
- if( dist <= range ){
- for(k=j+1; k<5; k++){
- aux3 = values[k];
- dist2 = abs(aux1 - aux3);
-
- if( dist2 <= range ){
- result = aux2 + (aux1 << 1);
- result = result + aux3;
- result = result >> 2;
- result = result & (~7);
-
- *err = 0;
-
- break;
- }
- }
- }
- }
- }
-
- if((*err) == 1){
- result = values[0] + values[4];
- result = result >> 1;
- result = result & (~7);
- }
-
- return (result & 0xFFF);
-}
-
-//---------------------------------------------------------------------------------
-void UpdateRange(uint8 *this_range, int16 last_dist_max, u8 data_error, u8 tsc_touched){
-//---------------------------------------------------------------------------------
- //range_counter_1 = counter_0x380A98C
- //range_counter_2 = counter_0x380A990
- //Initial values:
- // range = 20
- // min_range = 20
-
- if(tsc_touched != 0){
- if( data_error == 0){
- range_counter_2 = 0;
-
- if( last_dist_max >= ((*this_range) >> 1)){
- range_counter_1 = 0;
- }else{
- range_counter_1++;
-
- if(range_counter_1 >= 4){
- range_counter_1 = 0;
-
- if((*this_range) > min_range){
- (*this_range)--;
- range_counter_2 = 3;
- }
- }
- }
- }else{
- range_counter_1 = 0;
- range_counter_2++;
-
- if(range_counter_2 >= 4){
-
- range_counter_2 = 0;
-
- if((*this_range) < 35){ //0x23 = 35
- *this_range = (*this_range) + 1;
- }
- }
- }
- }else{
- range_counter_2 = 0;
- range_counter_1 = 0;
- }
-}
-
-//---------------------------------------------------------------------------------
-// reading pixel position:
-//---------------------------------------------------------------------------------
-touchPosition touchReadXY() {
-//---------------------------------------------------------------------------------
-
- int16 dist_max_y, dist_max_x, dist_max;
- u8 error, error_where, first_check, i;
-
- touchPosition touchPos = { 0, 0, 0, 0, 0, 0 };
-
- if ( !touchInit ) {
-
- xscale = ((PersonalData->calX2px - PersonalData->calX1px) << 19) / ((PersonalData->calX2) - (PersonalData->calX1));
- yscale = ((PersonalData->calY2px - PersonalData->calY1px) << 19) / ((PersonalData->calY2) - (PersonalData->calY1));
-
- xoffset = ((PersonalData->calX1 + PersonalData->calX2) * xscale - ((PersonalData->calX1px + PersonalData->calX2px) << 19) ) / 2;
- yoffset = ((PersonalData->calY1 + PersonalData->calY2) * yscale - ((PersonalData->calY1px + PersonalData->calY2px) << 19) ) / 2;
- touchInit = true;
- }
-
- uint32 oldIME = REG_IME;
-
- REG_IME = 0;
-
- first_check = CheckStylus();
- if(first_check != 0){
- error_where = 0;
-
- touchPos.z1 = readTouchValue(TSC_MEASURE_Z1 | 1, &dist_max, &error);
- touchPos.z2 = readTouchValue(TSC_MEASURE_Z2 | 1, &dist_max, &error);
-
- touchPos.x = readTouchValue(TSC_MEASURE_X | 1, &dist_max_x, &error);
- if(error==1) error_where += 1;
-
- touchPos.y = readTouchValue(TSC_MEASURE_Y | 1, &dist_max_y, &error);
- if(error==1) error_where += 2;
-
- REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH | SPI_CONTINUOUS;
- for(i=0; i<12; i++){
- REG_SPIDATA = 0;
-
- SerialWaitBusy();
- }
-
- REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH;
- REG_SPIDATA = 0;
-
- SerialWaitBusy();
-
- if(first_check == 2) error_where = 3;
-
- switch( CheckStylus() ){
- case 0:
- last_time_touched = 0;
- break;
- case 1:
- last_time_touched = 1;
-
- if(dist_max_x > dist_max_y)
- dist_max = dist_max_x;
- else
- dist_max = dist_max_y;
-
- break;
- case 2:
- last_time_touched = 0;
- error_where = 3;
-
- break;
- }
-
- s16 px = ( touchPos.x * xscale - xoffset + xscale/2 ) >>19;
- s16 py = ( touchPos.y * yscale - yoffset + yscale/2 ) >>19;
-
- if ( px < 0) px = 0;
- if ( py < 0) py = 0;
- if ( px > (SCREEN_WIDTH -1)) px = SCREEN_WIDTH -1;
- if ( py > (SCREEN_HEIGHT -1)) py = SCREEN_HEIGHT -1;
-
- touchPos.px = px;
- touchPos.py = py;
-
-
- }else{
- error_where = 3;
- touchPos.x = 0;
- touchPos.y = 0;
- last_time_touched = 0;
- }
-
- UpdateRange(&range, dist_max, error_where, last_time_touched);
-
- REG_IME = oldIME;
-
-
- return touchPos;
-
-}
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ Touch screen control for the ARM7
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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/jtypes.h>
+#include <nds/system.h>
+#include <nds/arm7/touch.h>
+#include <nds/interrupts.h>
+
+#include <stdlib.h>
+
+static u8 last_time_touched = 0;
+
+static u8 range_counter_1 = 0;
+static u8 range_counter_2 = 0;
+static u8 range = 20;
+static u8 min_range = 20;
+
+//---------------------------------------------------------------------------------
+u8 CheckStylus(){
+//---------------------------------------------------------------------------------
+
+ SerialWaitBusy();
+
+ REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH | SPI_CONTINUOUS; //0x8A01;
+ REG_SPIDATA = TSC_MEASURE_TEMP1;
+
+ SerialWaitBusy();
+
+ REG_SPIDATA = 0;
+
+ SerialWaitBusy();
+
+ REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH;// 0x8201;
+ REG_SPIDATA = 0;
+
+ SerialWaitBusy();
+
+ if(last_time_touched == 1){
+ if( !(REG_KEYXY & 0x40) )
+ return 1;
+ else{
+ REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH | SPI_CONTINUOUS;
+ REG_SPIDATA = TSC_MEASURE_TEMP1;
+
+ SerialWaitBusy();
+
+ REG_SPIDATA = 0;
+
+ SerialWaitBusy();
+
+ REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH;
+ REG_SPIDATA = 0;
+
+ SerialWaitBusy();
+
+ return !(REG_KEYXY & 0x40) ? 2 : 0;
+ }
+ }else{
+ return !(REG_KEYXY & 0x40) ? 1 : 0;
+ }
+}
+
+//---------------------------------------------------------------------------------
+uint16 touchRead(uint32 command) {
+//---------------------------------------------------------------------------------
+ uint16 result, result2;
+
+ uint32 oldIME = REG_IME;
+
+ REG_IME = 0;
+
+ SerialWaitBusy();
+
+ // Write the command and wait for it to complete
+ REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH | SPI_CONTINUOUS; //0x8A01;
+ REG_SPIDATA = command;
+ SerialWaitBusy();
+
+ // Write the second command and clock in part of the data
+ REG_SPIDATA = 0;
+ SerialWaitBusy();
+ result = REG_SPIDATA;
+
+ // Clock in the rest of the data (last transfer)
+ REG_SPICNT = SPI_ENABLE | 0x201;
+ REG_SPIDATA = 0;
+ SerialWaitBusy();
+
+ result2 = REG_SPIDATA >>3;
+
+ REG_IME = oldIME;
+
+ // Return the result
+ return ((result & 0x7F) << 5) | result2;
+}
+
+
+//---------------------------------------------------------------------------------
+uint32 touchReadTemperature(int * t1, int * t2) {
+//---------------------------------------------------------------------------------
+ *t1 = touchRead(TSC_MEASURE_TEMP1);
+ *t2 = touchRead(TSC_MEASURE_TEMP2);
+ return 8490 * (*t2 - *t1) - 273*4096;
+}
+
+
+static bool touchInit = false;
+static s32 xscale, yscale;
+static s32 xoffset, yoffset;
+
+//---------------------------------------------------------------------------------
+int16 readTouchValue(uint32 command, int16 *dist_max, u8 *err){
+//---------------------------------------------------------------------------------
+ int16 values[5];
+ int32 aux1, aux2, aux3, dist, dist2, result = 0;
+ u8 i, j, k;
+
+ *err = 1;
+
+ SerialWaitBusy();
+
+ REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH | SPI_CONTINUOUS;
+ REG_SPIDATA = command;
+
+ SerialWaitBusy();
+
+ for(i=0; i<5; i++){
+ REG_SPIDATA = 0;
+ SerialWaitBusy();
+
+ aux1 = REG_SPIDATA;
+ aux1 = aux1 & 0xFF;
+ aux1 = aux1 << 16;
+ aux1 = aux1 >> 8;
+
+ values[4-i] = aux1;
+
+ REG_SPIDATA = command;
+ SerialWaitBusy();
+
+ aux1 = REG_SPIDATA;
+ aux1 = aux1 & 0xFF;
+ aux1 = aux1 << 16;
+
+ aux1 = values[4-i] | (aux1 >> 16);
+ values[4-i] = ((aux1 & 0x7FF8) >> 3);
+ }
+
+ REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH;
+ REG_SPIDATA = 0;
+ SerialWaitBusy();
+
+ dist = 0;
+ for(i=0; i<4; i++){
+ aux1 = values[i];
+
+ for(j=i+1; j<5; j++){
+ aux2 = values[j];
+ aux2 = abs(aux1 - aux2);
+ if(aux2>dist) dist = aux2;
+ }
+ }
+
+ *dist_max = dist;
+
+ for(i=0; i<3; i++){
+ aux1 = values[i];
+
+ for(j=i+1; j<4; j++){
+ aux2 = values[j];
+ dist = abs(aux1 - aux2);
+
+ if( dist <= range ){
+ for(k=j+1; k<5; k++){
+ aux3 = values[k];
+ dist2 = abs(aux1 - aux3);
+
+ if( dist2 <= range ){
+ result = aux2 + (aux1 << 1);
+ result = result + aux3;
+ result = result >> 2;
+ result = result & (~7);
+
+ *err = 0;
+
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if((*err) == 1){
+ result = values[0] + values[4];
+ result = result >> 1;
+ result = result & (~7);
+ }
+
+ return (result & 0xFFF);
+}
+
+//---------------------------------------------------------------------------------
+void UpdateRange(uint8 *this_range, int16 last_dist_max, u8 data_error, u8 tsc_touched){
+//---------------------------------------------------------------------------------
+ //range_counter_1 = counter_0x380A98C
+ //range_counter_2 = counter_0x380A990
+ //Initial values:
+ // range = 20
+ // min_range = 20
+
+ if(tsc_touched != 0){
+ if( data_error == 0){
+ range_counter_2 = 0;
+
+ if( last_dist_max >= ((*this_range) >> 1)){
+ range_counter_1 = 0;
+ }else{
+ range_counter_1++;
+
+ if(range_counter_1 >= 4){
+ range_counter_1 = 0;
+
+ if((*this_range) > min_range){
+ (*this_range)--;
+ range_counter_2 = 3;
+ }
+ }
+ }
+ }else{
+ range_counter_1 = 0;
+ range_counter_2++;
+
+ if(range_counter_2 >= 4){
+
+ range_counter_2 = 0;
+
+ if((*this_range) < 35){ //0x23 = 35
+ *this_range = (*this_range) + 1;
+ }
+ }
+ }
+ }else{
+ range_counter_2 = 0;
+ range_counter_1 = 0;
+ }
+}
+
+//---------------------------------------------------------------------------------
+// reading pixel position:
+//---------------------------------------------------------------------------------
+touchPosition touchReadXY() {
+//---------------------------------------------------------------------------------
+
+ int16 dist_max_y, dist_max_x, dist_max;
+ u8 error, error_where, first_check, i;
+
+ touchPosition touchPos = { 0, 0, 0, 0, 0, 0 };
+
+ if ( !touchInit ) {
+
+ xscale = ((PersonalData->calX2px - PersonalData->calX1px) << 19) / ((PersonalData->calX2) - (PersonalData->calX1));
+ yscale = ((PersonalData->calY2px - PersonalData->calY1px) << 19) / ((PersonalData->calY2) - (PersonalData->calY1));
+
+ xoffset = ((PersonalData->calX1 + PersonalData->calX2) * xscale - ((PersonalData->calX1px + PersonalData->calX2px) << 19) ) / 2;
+ yoffset = ((PersonalData->calY1 + PersonalData->calY2) * yscale - ((PersonalData->calY1px + PersonalData->calY2px) << 19) ) / 2;
+ touchInit = true;
+ }
+
+ uint32 oldIME = REG_IME;
+
+ REG_IME = 0;
+
+ first_check = CheckStylus();
+ if(first_check != 0){
+ error_where = 0;
+
+ touchPos.z1 = readTouchValue(TSC_MEASURE_Z1 | 1, &dist_max, &error);
+ touchPos.z2 = readTouchValue(TSC_MEASURE_Z2 | 1, &dist_max, &error);
+
+ touchPos.x = readTouchValue(TSC_MEASURE_X | 1, &dist_max_x, &error);
+ if(error==1) error_where += 1;
+
+ touchPos.y = readTouchValue(TSC_MEASURE_Y | 1, &dist_max_y, &error);
+ if(error==1) error_where += 2;
+
+ REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH | SPI_CONTINUOUS;
+ for(i=0; i<12; i++){
+ REG_SPIDATA = 0;
+
+ SerialWaitBusy();
+ }
+
+ REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH;
+ REG_SPIDATA = 0;
+
+ SerialWaitBusy();
+
+ if(first_check == 2) error_where = 3;
+
+ switch( CheckStylus() ){
+ case 0:
+ last_time_touched = 0;
+ break;
+ case 1:
+ last_time_touched = 1;
+
+ if(dist_max_x > dist_max_y)
+ dist_max = dist_max_x;
+ else
+ dist_max = dist_max_y;
+
+ break;
+ case 2:
+ last_time_touched = 0;
+ error_where = 3;
+
+ break;
+ }
+
+ s16 px = ( touchPos.x * xscale - xoffset + xscale/2 ) >>19;
+ s16 py = ( touchPos.y * yscale - yoffset + yscale/2 ) >>19;
+
+ if ( px < 0) px = 0;
+ if ( py < 0) py = 0;
+ if ( px > (SCREEN_WIDTH -1)) px = SCREEN_WIDTH -1;
+ if ( py > (SCREEN_HEIGHT -1)) py = SCREEN_HEIGHT -1;
+
+ touchPos.px = px;
+ touchPos.py = py;
+
+
+ }else{
+ error_where = 3;
+ touchPos.x = 0;
+ touchPos.y = 0;
+ last_time_touched = 0;
+ }
+
+ UpdateRange(&range, dist_max, error_where, last_time_touched);
+
+ REG_IME = oldIME;
+
+
+ return touchPos;
+
+}
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/source/arm7/userSettings.c b/c/src/lib/libbsp/arm/nds/libnds/source/arm7/userSettings.c
index eb546c7ddc..8e92cb2b79 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/source/arm7/userSettings.c
+++ b/c/src/lib/libbsp/arm/nds/libnds/source/arm7/userSettings.c
@@ -1,71 +1,71 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- Copyright (C) 2005
- Dave Murphy (WinterMute)
-
- 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/arm7/serial.h>
-#include <nds/system.h>
-#include <string.h>
-
-//---------------------------------------------------------------------------------
-void readUserSettings() {
-//---------------------------------------------------------------------------------
-
- PERSONAL_DATA slot1;
- PERSONAL_DATA slot2;
-
- short slot1count, slot2count;
- short slot1CRC, slot2CRC;
-
- uint32 userSettingsBase;
- readFirmware( 0x20, &userSettingsBase,2);
-
- uint32 slot1Address = userSettingsBase * 8;
- uint32 slot2Address = userSettingsBase * 8 + 0x100;
-
- readFirmware( slot1Address , &slot1, sizeof(PERSONAL_DATA));
- readFirmware( slot2Address , &slot2, sizeof(PERSONAL_DATA));
- readFirmware( slot1Address + 0x70, &slot1count, 2);
- readFirmware( slot2Address + 0x70, &slot2count, 2);
- readFirmware( slot1Address + 0x72, &slot1CRC, 2);
- readFirmware( slot2Address + 0x72, &slot2CRC, 2);
-
- // default to slot 1 user Settings
- void *currentSettings = &slot1;
-
- short calc1CRC = swiCRC16( 0xffff, &slot1, sizeof(PERSONAL_DATA));
- short calc2CRC = swiCRC16( 0xffff, &slot2, sizeof(PERSONAL_DATA));
-
- // bail out if neither slot is valid
- if ( calc1CRC != slot1CRC && calc2CRC != slot2CRC) return;
-
- // if both slots are valid pick the most recent
- if ( calc1CRC == slot1CRC && calc2CRC == slot2CRC ) {
- currentSettings = (slot2count == (( slot2count + 1 ) & 0x7f) ? &slot2 : &slot1);
- } else {
- if ( calc2CRC == slot2CRC )
- currentSettings = &slot2;
- }
- memcpy ( PersonalData, currentSettings, sizeof(PERSONAL_DATA));
-
-}
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ Copyright (C) 2005
+ Dave Murphy (WinterMute)
+
+ 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/arm7/serial.h>
+#include <nds/system.h>
+#include <string.h>
+
+//---------------------------------------------------------------------------------
+void readUserSettings() {
+//---------------------------------------------------------------------------------
+
+ PERSONAL_DATA slot1;
+ PERSONAL_DATA slot2;
+
+ short slot1count, slot2count;
+ short slot1CRC, slot2CRC;
+
+ uint32 userSettingsBase;
+ readFirmware( 0x20, &userSettingsBase,2);
+
+ uint32 slot1Address = userSettingsBase * 8;
+ uint32 slot2Address = userSettingsBase * 8 + 0x100;
+
+ readFirmware( slot1Address , &slot1, sizeof(PERSONAL_DATA));
+ readFirmware( slot2Address , &slot2, sizeof(PERSONAL_DATA));
+ readFirmware( slot1Address + 0x70, &slot1count, 2);
+ readFirmware( slot2Address + 0x70, &slot2count, 2);
+ readFirmware( slot1Address + 0x72, &slot1CRC, 2);
+ readFirmware( slot2Address + 0x72, &slot2CRC, 2);
+
+ // default to slot 1 user Settings
+ void *currentSettings = &slot1;
+
+ short calc1CRC = swiCRC16( 0xffff, &slot1, sizeof(PERSONAL_DATA));
+ short calc2CRC = swiCRC16( 0xffff, &slot2, sizeof(PERSONAL_DATA));
+
+ // bail out if neither slot is valid
+ if ( calc1CRC != slot1CRC && calc2CRC != slot2CRC) return;
+
+ // if both slots are valid pick the most recent
+ if ( calc1CRC == slot1CRC && calc2CRC == slot2CRC ) {
+ currentSettings = (slot2count == (( slot2count + 1 ) & 0x7f) ? &slot2 : &slot1);
+ } else {
+ if ( calc2CRC == slot2CRC )
+ currentSettings = &slot2;
+ }
+ memcpy ( PersonalData, currentSettings, sizeof(PERSONAL_DATA));
+
+}
diff --git a/c/src/lib/libbsp/arm/nds/libnds/source/arm9/COS.bin b/c/src/lib/libbsp/arm/nds/libnds/source/arm9/COS.bin
deleted file mode 100644
index fa384d6e1d..0000000000
--- a/c/src/lib/libbsp/arm/nds/libnds/source/arm9/COS.bin
+++ /dev/null
Binary files differ
diff --git a/c/src/lib/libbsp/arm/nds/libnds/source/arm9/SIN.bin b/c/src/lib/libbsp/arm/nds/libnds/source/arm9/SIN.bin
deleted file mode 100644
index 6526dc10e2..0000000000
--- a/c/src/lib/libbsp/arm/nds/libnds/source/arm9/SIN.bin
+++ /dev/null
Binary files differ
diff --git a/c/src/lib/libbsp/arm/nds/libnds/source/arm9/TAN.bin b/c/src/lib/libbsp/arm/nds/libnds/source/arm9/TAN.bin
deleted file mode 100644
index 2187f6d8a9..0000000000
--- a/c/src/lib/libbsp/arm/nds/libnds/source/arm9/TAN.bin
+++ /dev/null
Binary files differ
diff --git a/c/src/lib/libbsp/arm/nds/libnds/source/arm9/boxtest.c b/c/src/lib/libbsp/arm/nds/libnds/source/arm9/boxtest.c
index caa26f74d5..47b44369c3 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/source/arm9/boxtest.c
+++ b/c/src/lib/libbsp/arm/nds/libnds/source/arm9/boxtest.c
@@ -1,88 +1,88 @@
-/*---------------------------------------------------------------------------------
-$Id$
-
- BoxTest.c -- Code for performing hardware box test against viewing frustrum
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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/arm9/video.h>
-#include <nds/arm9/videoGL.h>
-
-//---------------------------------------------------------------------------------
-void BoxTest_Asynch(v16 x, v16 y, v16 z, v16 width, v16 height, v16 depth)
-//---------------------------------------------------------------------------------
-{
- glPolyFmt(BIT(12) | BIT(13));
- glBegin(GL_TRIANGLES);
- glEnd();
-
- GFX_BOX_TEST = VERTEX_PACK(x, y);
- GFX_BOX_TEST = VERTEX_PACK(z, width);
- GFX_BOX_TEST = VERTEX_PACK(height, depth);
-}
-
-//---------------------------------------------------------------------------------
-void BoxTestf_Asynch(float x, float y, float z, float width, float height, float depth)
-//---------------------------------------------------------------------------------
-{
- BoxTest_Asynch(floattov16(x), floattov16(y), floattov16(z),
- floattov16(width), floattov16(height), floattov16(depth));
-}
-
-//---------------------------------------------------------------------------------
-int BoxTestResult(void)
-//---------------------------------------------------------------------------------
-{
- while(GFX_STATUS & BIT(0));
-
- return (GFX_STATUS & BIT(1));
-}
-
-//---------------------------------------------------------------------------------
-int BoxTest(v16 x, v16 y, v16 z, v16 width, v16 height, v16 depth)
-//---------------------------------------------------------------------------------
-{
- glPolyFmt(BIT(12) | BIT(13));
- glBegin(GL_TRIANGLES);
- glEnd();
-
- GFX_BOX_TEST = VERTEX_PACK(x, y);
- GFX_BOX_TEST = VERTEX_PACK(z, width);
- GFX_BOX_TEST = VERTEX_PACK(height, depth);
-
- while(GFX_STATUS & BIT(0));
-
- return (GFX_STATUS & BIT(1));
-}
-
-//---------------------------------------------------------------------------------
-int BoxTestf(float x, float y, float z, float width, float height, float depth)
-//---------------------------------------------------------------------------------
-{
- return BoxTest(floattov16(x), floattov16(y), floattov16(z),
- floattov16(width), floattov16(height), floattov16(depth));
-}
+/*---------------------------------------------------------------------------------
+$Id$
+
+ BoxTest.c -- Code for performing hardware box test against viewing frustrum
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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/arm9/video.h>
+#include <nds/arm9/videoGL.h>
+
+//---------------------------------------------------------------------------------
+void BoxTest_Asynch(v16 x, v16 y, v16 z, v16 width, v16 height, v16 depth)
+//---------------------------------------------------------------------------------
+{
+ glPolyFmt(BIT(12) | BIT(13));
+ glBegin(GL_TRIANGLES);
+ glEnd();
+
+ GFX_BOX_TEST = VERTEX_PACK(x, y);
+ GFX_BOX_TEST = VERTEX_PACK(z, width);
+ GFX_BOX_TEST = VERTEX_PACK(height, depth);
+}
+
+//---------------------------------------------------------------------------------
+void BoxTestf_Asynch(float x, float y, float z, float width, float height, float depth)
+//---------------------------------------------------------------------------------
+{
+ BoxTest_Asynch(floattov16(x), floattov16(y), floattov16(z),
+ floattov16(width), floattov16(height), floattov16(depth));
+}
+
+//---------------------------------------------------------------------------------
+int BoxTestResult(void)
+//---------------------------------------------------------------------------------
+{
+ while(GFX_STATUS & BIT(0));
+
+ return (GFX_STATUS & BIT(1));
+}
+
+//---------------------------------------------------------------------------------
+int BoxTest(v16 x, v16 y, v16 z, v16 width, v16 height, v16 depth)
+//---------------------------------------------------------------------------------
+{
+ glPolyFmt(BIT(12) | BIT(13));
+ glBegin(GL_TRIANGLES);
+ glEnd();
+
+ GFX_BOX_TEST = VERTEX_PACK(x, y);
+ GFX_BOX_TEST = VERTEX_PACK(z, width);
+ GFX_BOX_TEST = VERTEX_PACK(height, depth);
+
+ while(GFX_STATUS & BIT(0));
+
+ return (GFX_STATUS & BIT(1));
+}
+
+//---------------------------------------------------------------------------------
+int BoxTestf(float x, float y, float z, float width, float height, float depth)
+//---------------------------------------------------------------------------------
+{
+ return BoxTest(floattov16(x), floattov16(y), floattov16(z),
+ floattov16(width), floattov16(height), floattov16(depth));
+}
diff --git a/c/src/lib/libbsp/arm/nds/libnds/source/arm9/default_font.bin b/c/src/lib/libbsp/arm/nds/libnds/source/arm9/default_font.bin
deleted file mode 100644
index 112e78b336..0000000000
--- a/c/src/lib/libbsp/arm/nds/libnds/source/arm9/default_font.bin
+++ /dev/null
Binary files differ
diff --git a/c/src/lib/libbsp/arm/nds/libnds/source/arm9/gurumeditation.c b/c/src/lib/libbsp/arm/nds/libnds/source/arm9/gurumeditation.c
index 3eef28ea31..8209be6fa1 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/source/arm9/gurumeditation.c
+++ b/c/src/lib/libbsp/arm/nds/libnds/source/arm9/gurumeditation.c
@@ -1,270 +1,270 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- Copyright (C) 2005
- Dave Murphy (WinterMute)
-
- 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/jtypes.h>
-#include <nds/memory.h>
-
-#include <nds/arm9/video.h>
-#include <nds/arm9/console.h>
-#include <nds/arm9/exceptions.h>
-#include <nds/arm9/background.h>
-
-#include <stdio.h>
-
-//---------------------------------------------------------------------------------
-unsigned long ARMShift(unsigned long value,unsigned char shift) {
-//---------------------------------------------------------------------------------
- // no shift at all
- if (shift == 0x0B) return value ;
- int index ;
- if (shift & 0x01) {
- // shift index is a register
- index = exceptionRegisters[(shift >> 4) & 0x0F];
- } else {
- // constant shift index
- index = ((shift >> 3) & 0x1F) ;
- } ;
- int i ;
- bool isN ;
- switch (shift & 0x06) {
- case 0x00:
- // logical left
- return (value << index) ;
- case 0x02:
- // logical right
- return (value >> index) ;
- case 0x04:
- // arithmetical right
- isN = (value & 0x80000000) ;
- value = value >> index ;
- if (isN) {
- for (i=31;i>31-index;i--) {
- value = value | (1 << i) ;
- } ;
- } ;
- return value ;
- case 0x06:
- // rotate right
- index = index & 0x1F;
- value = (value >> index) | (value << (32-index));
- return value;
- };
- return value;
-}
-
-
-//---------------------------------------------------------------------------------
-u32 getExceptionAddress( u32 opcodeAddress, u32 thumbState) {
-//---------------------------------------------------------------------------------
-
- int Rf, Rb, Rd, Rn, Rm;
-
- if (thumbState) {
- // Thumb
-
- unsigned short opcode = *(unsigned short *)opcodeAddress ;
- // ldr r,[pc,###] 01001ddd ffffffff
- // ldr r,[r,r] 0101xx0f ffbbbddd
- // ldrsh 0101xx1f ffbbbddd
- // ldr r,[r,imm] 011xxfff ffbbbddd
- // ldrh 1000xfff ffbbbddd
- // ldr r,[sp,###] 1001xddd ffffffff
- // push 1011x10l llllllll
- // ldm 1100xbbb llllllll
-
-
- if ((opcode & 0xF800) == 0x4800) {
- // ldr r,[pc,###]
- s8 offset = opcode & 0xff;
- return exceptionRegisters[15] + offset;
- } else if ((opcode & 0xF200) == 0x5000) {
- // ldr r,[r,r]
- Rb = (opcode >> 3) & 0x07 ;
- Rf = (opcode >> 6) & 0x07 ;
- return exceptionRegisters[Rb] + exceptionRegisters[Rf];
-
- } else if ((opcode & 0xF200) == 0x5200) {
- // ldrsh
- Rb = (opcode >> 3) & 0x07;
- Rf = (opcode >> 6) & 0x03;
- return exceptionRegisters[Rb] + exceptionRegisters[Rf];
-
- } else if ((opcode & 0xE000) == 0x6000) {
- // ldr r,[r,imm]
- Rb = (opcode >> 3) & 0x07;
- Rf = (opcode >> 6) & 0x1F ;
- return exceptionRegisters[Rb] + (Rf << 2);
- } else if ((opcode & 0xF000) == 0x8000) {
- // ldrh
- Rb = (opcode >> 3) & 0x07 ;
- Rf = (opcode >> 6) & 0x1F ;
- return exceptionRegisters[Rb] + (Rf << 2);
- } else if ((opcode & 0xF000) == 0x9000) {
- // ldr r,[sp,#imm]
- s8 offset = opcode & 0xff;
- return exceptionRegisters[13] + offset;
- } else if ((opcode & 0xF700) == 0xB500) {
- // push/pop
- return exceptionRegisters[13];
- } else if ((opcode & 0xF000) == 0xC000) {
- // ldm/stm
- Rd = (opcode >> 8) & 0x07;
- return exceptionRegisters[Rd];
- }
- } else {
- // arm32
- unsigned long opcode = *(unsigned long *)opcodeAddress ;
-
- // SWP xxxx0001 0x00nnnn dddd0000 1001mmmm
- // STR/LDR xxxx01xx xxxxnnnn ddddffff ffffffff
- // STRH/LDRH xxxx000x x0xxnnnn dddd0000 1xx1mmmm
- // STRH/LDRH xxxx000x x1xxnnnn ddddffff 1xx1ffff
- // STM/LDM xxxx100x xxxxnnnn llllllll llllllll
-
- if ((opcode & 0x0FB00FF0) == 0x01000090) {
- // SWP
- Rn = (opcode >> 16) & 0x0F;
- return exceptionRegisters[Rn];
- } else if ((opcode & 0x0C000000) == 0x04000000) {
- // STR/LDR
- Rn = (opcode >> 16) & 0x0F;
- if (opcode & 0x02000000) {
- // Register offset
- Rm = opcode & 0x0F;
- if (opcode & 0x01000000) {
- unsigned short shift = (unsigned short)((opcode >> 4) & 0xFF) ;
- // pre indexing
- long Offset = ARMShift(exceptionRegisters[Rm],shift);
- // add or sub the offset depending on the U-Bit
- return exceptionRegisters[Rn] + ((opcode & 0x00800000)?Offset:-Offset);
- } else {
- // post indexing
- return exceptionRegisters[Rn];
- }
- } else {
- // Immediate offset
- unsigned long Offset = (opcode & 0xFFF) ;
- if (opcode & 0x01000000) {
- // pre indexing
- // add or sub the offset depending on the U-Bit
- return exceptionRegisters[Rn] + ((opcode & 0x00800000)?Offset:-Offset);
- } else {
- // post indexing
- return exceptionRegisters[Rn];
- }
- }
- } else if ((opcode & 0x0E400F90) == 0x00000090) {
- // LDRH/STRH with register Rm
- Rn = (opcode >> 16) & 0x0F;
- Rd = (opcode >> 12) & 0x0F;
- Rm = opcode & 0x0F;
- unsigned short shift = (unsigned short)((opcode >> 4) & 0xFF);
- long Offset = ARMShift(exceptionRegisters[Rm],shift);
- // add or sub the offset depending on the U-Bit
- return exceptionRegisters[Rn] + ((opcode & 0x00800000)?Offset:-Offset);
- } else if ((opcode & 0x0E400F90) == 0x00400090) {
- // LDRH/STRH with immediate offset
- Rn = (opcode >> 16) & 0x0F;
- Rd = (opcode >> 12) & 0x0F;
- unsigned long Offset = (opcode & 0xF) | ((opcode & 0xF00)>>8) ;
- // add or sub the offset depending on the U-Bit
- return exceptionRegisters[Rn] + ((opcode & 0x00800000)?Offset:-Offset) ;
- } else if ((opcode & 0x0E000000) == 0x08000000) {
- // LDM/STM
- Rn = (opcode >> 16) & 0x0F;
- return exceptionRegisters[Rn];
- }
- }
- return 0;
-}
-
-static const char *registerNames[] =
- { "r0","r1","r2","r3","r4","r5","r6","r7",
- "r8 ","r9 ","r10","r11","r12","sp ","lr ","pc " };
-
-extern const char __itcm_start[];
-//---------------------------------------------------------------------------------
-static void defaultHandler() {
-//---------------------------------------------------------------------------------
- videoSetMode(0);
- videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);
- vramSetBankC(VRAM_C_SUB_BG);
-
- SUB_BG0_CR = BG_MAP_BASE(31);
-
- BG_PALETTE_SUB[0] = RGB15(31,0,0);
- BG_PALETTE_SUB[255] = RGB15(31,31,31);
-
- consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
-
- iprintf("\x1b[5CGuru Meditation Error!\n");
- u32 currentMode = getCPSR() & 0x1f;
- u32 thumbState = ((*(u32*)0x027FFD90) & 0x20);
-
- u32 codeAddress, exceptionAddress = 0;
-
- int offset = 8;
-
- if ( currentMode == 0x17 ) {
- iprintf ("\x1b[10Cdata abort!\n\n");
- codeAddress = exceptionRegisters[15] - offset;
- if ( (codeAddress > 0x02000000 && codeAddress < 0x02400000) ||
- (codeAddress > (u32)__itcm_start && codeAddress < (u32)(__itcm_start + 32768)) )
- exceptionAddress = getExceptionAddress( codeAddress, thumbState);
- else
- exceptionAddress = codeAddress;
-
- } else {
- if (thumbState)
- offset = 2;
- else
- offset = 4;
- iprintf("\x1b[5Cundefined instruction!\n\n");
- codeAddress = exceptionRegisters[15] - offset;
- exceptionAddress = codeAddress;
- }
-
- iprintf(" pc: %08X addr: %08X\n\n",codeAddress,exceptionAddress);
-
- int i;
- for ( i=0; i < 8; i++ ) {
- iprintf( " %s: %08X %s: %08X\n",
- registerNames[i], exceptionRegisters[i],
- registerNames[i+8],exceptionRegisters[i+8]);
- }
- iprintf("\n");
- u32 *stack = (u32 *)exceptionRegisters[13];
- for ( i=0; i<10; i++ ) {
- iprintf( "\x1b[%d;2H%08X: %08X %08X", i + 14, (u32)&stack[i*2],stack[i*2], stack[(i*2)+1] );
- }
- while(1);
-
-}
-
-//---------------------------------------------------------------------------------
-void defaultExceptionHandler() {
-//---------------------------------------------------------------------------------
- setExceptionHandler(defaultHandler) ;
-}
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ Copyright (C) 2005
+ Dave Murphy (WinterMute)
+
+ 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/jtypes.h>
+#include <nds/memory.h>
+
+#include <nds/arm9/video.h>
+#include <nds/arm9/console.h>
+#include <nds/arm9/exceptions.h>
+#include <nds/arm9/background.h>
+
+#include <stdio.h>
+
+//---------------------------------------------------------------------------------
+unsigned long ARMShift(unsigned long value,unsigned char shift) {
+//---------------------------------------------------------------------------------
+ // no shift at all
+ if (shift == 0x0B) return value ;
+ int index ;
+ if (shift & 0x01) {
+ // shift index is a register
+ index = exceptionRegisters[(shift >> 4) & 0x0F];
+ } else {
+ // constant shift index
+ index = ((shift >> 3) & 0x1F) ;
+ } ;
+ int i ;
+ bool isN ;
+ switch (shift & 0x06) {
+ case 0x00:
+ // logical left
+ return (value << index) ;
+ case 0x02:
+ // logical right
+ return (value >> index) ;
+ case 0x04:
+ // arithmetical right
+ isN = (value & 0x80000000) ;
+ value = value >> index ;
+ if (isN) {
+ for (i=31;i>31-index;i--) {
+ value = value | (1 << i) ;
+ } ;
+ } ;
+ return value ;
+ case 0x06:
+ // rotate right
+ index = index & 0x1F;
+ value = (value >> index) | (value << (32-index));
+ return value;
+ };
+ return value;
+}
+
+
+//---------------------------------------------------------------------------------
+u32 getExceptionAddress( u32 opcodeAddress, u32 thumbState) {
+//---------------------------------------------------------------------------------
+
+ int Rf, Rb, Rd, Rn, Rm;
+
+ if (thumbState) {
+ // Thumb
+
+ unsigned short opcode = *(unsigned short *)opcodeAddress ;
+ // ldr r,[pc,###] 01001ddd ffffffff
+ // ldr r,[r,r] 0101xx0f ffbbbddd
+ // ldrsh 0101xx1f ffbbbddd
+ // ldr r,[r,imm] 011xxfff ffbbbddd
+ // ldrh 1000xfff ffbbbddd
+ // ldr r,[sp,###] 1001xddd ffffffff
+ // push 1011x10l llllllll
+ // ldm 1100xbbb llllllll
+
+
+ if ((opcode & 0xF800) == 0x4800) {
+ // ldr r,[pc,###]
+ s8 offset = opcode & 0xff;
+ return exceptionRegisters[15] + offset;
+ } else if ((opcode & 0xF200) == 0x5000) {
+ // ldr r,[r,r]
+ Rb = (opcode >> 3) & 0x07 ;
+ Rf = (opcode >> 6) & 0x07 ;
+ return exceptionRegisters[Rb] + exceptionRegisters[Rf];
+
+ } else if ((opcode & 0xF200) == 0x5200) {
+ // ldrsh
+ Rb = (opcode >> 3) & 0x07;
+ Rf = (opcode >> 6) & 0x03;
+ return exceptionRegisters[Rb] + exceptionRegisters[Rf];
+
+ } else if ((opcode & 0xE000) == 0x6000) {
+ // ldr r,[r,imm]
+ Rb = (opcode >> 3) & 0x07;
+ Rf = (opcode >> 6) & 0x1F ;
+ return exceptionRegisters[Rb] + (Rf << 2);
+ } else if ((opcode & 0xF000) == 0x8000) {
+ // ldrh
+ Rb = (opcode >> 3) & 0x07 ;
+ Rf = (opcode >> 6) & 0x1F ;
+ return exceptionRegisters[Rb] + (Rf << 2);
+ } else if ((opcode & 0xF000) == 0x9000) {
+ // ldr r,[sp,#imm]
+ s8 offset = opcode & 0xff;
+ return exceptionRegisters[13] + offset;
+ } else if ((opcode & 0xF700) == 0xB500) {
+ // push/pop
+ return exceptionRegisters[13];
+ } else if ((opcode & 0xF000) == 0xC000) {
+ // ldm/stm
+ Rd = (opcode >> 8) & 0x07;
+ return exceptionRegisters[Rd];
+ }
+ } else {
+ // arm32
+ unsigned long opcode = *(unsigned long *)opcodeAddress ;
+
+ // SWP xxxx0001 0x00nnnn dddd0000 1001mmmm
+ // STR/LDR xxxx01xx xxxxnnnn ddddffff ffffffff
+ // STRH/LDRH xxxx000x x0xxnnnn dddd0000 1xx1mmmm
+ // STRH/LDRH xxxx000x x1xxnnnn ddddffff 1xx1ffff
+ // STM/LDM xxxx100x xxxxnnnn llllllll llllllll
+
+ if ((opcode & 0x0FB00FF0) == 0x01000090) {
+ // SWP
+ Rn = (opcode >> 16) & 0x0F;
+ return exceptionRegisters[Rn];
+ } else if ((opcode & 0x0C000000) == 0x04000000) {
+ // STR/LDR
+ Rn = (opcode >> 16) & 0x0F;
+ if (opcode & 0x02000000) {
+ // Register offset
+ Rm = opcode & 0x0F;
+ if (opcode & 0x01000000) {
+ unsigned short shift = (unsigned short)((opcode >> 4) & 0xFF) ;
+ // pre indexing
+ long Offset = ARMShift(exceptionRegisters[Rm],shift);
+ // add or sub the offset depending on the U-Bit
+ return exceptionRegisters[Rn] + ((opcode & 0x00800000)?Offset:-Offset);
+ } else {
+ // post indexing
+ return exceptionRegisters[Rn];
+ }
+ } else {
+ // Immediate offset
+ unsigned long Offset = (opcode & 0xFFF) ;
+ if (opcode & 0x01000000) {
+ // pre indexing
+ // add or sub the offset depending on the U-Bit
+ return exceptionRegisters[Rn] + ((opcode & 0x00800000)?Offset:-Offset);
+ } else {
+ // post indexing
+ return exceptionRegisters[Rn];
+ }
+ }
+ } else if ((opcode & 0x0E400F90) == 0x00000090) {
+ // LDRH/STRH with register Rm
+ Rn = (opcode >> 16) & 0x0F;
+ Rd = (opcode >> 12) & 0x0F;
+ Rm = opcode & 0x0F;
+ unsigned short shift = (unsigned short)((opcode >> 4) & 0xFF);
+ long Offset = ARMShift(exceptionRegisters[Rm],shift);
+ // add or sub the offset depending on the U-Bit
+ return exceptionRegisters[Rn] + ((opcode & 0x00800000)?Offset:-Offset);
+ } else if ((opcode & 0x0E400F90) == 0x00400090) {
+ // LDRH/STRH with immediate offset
+ Rn = (opcode >> 16) & 0x0F;
+ Rd = (opcode >> 12) & 0x0F;
+ unsigned long Offset = (opcode & 0xF) | ((opcode & 0xF00)>>8) ;
+ // add or sub the offset depending on the U-Bit
+ return exceptionRegisters[Rn] + ((opcode & 0x00800000)?Offset:-Offset) ;
+ } else if ((opcode & 0x0E000000) == 0x08000000) {
+ // LDM/STM
+ Rn = (opcode >> 16) & 0x0F;
+ return exceptionRegisters[Rn];
+ }
+ }
+ return 0;
+}
+
+static const char *registerNames[] =
+ { "r0","r1","r2","r3","r4","r5","r6","r7",
+ "r8 ","r9 ","r10","r11","r12","sp ","lr ","pc " };
+
+extern const char __itcm_start[];
+//---------------------------------------------------------------------------------
+static void defaultHandler() {
+//---------------------------------------------------------------------------------
+ videoSetMode(0);
+ videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);
+ vramSetBankC(VRAM_C_SUB_BG);
+
+ SUB_BG0_CR = BG_MAP_BASE(31);
+
+ BG_PALETTE_SUB[0] = RGB15(31,0,0);
+ BG_PALETTE_SUB[255] = RGB15(31,31,31);
+
+ consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
+
+ iprintf("\x1b[5CGuru Meditation Error!\n");
+ u32 currentMode = getCPSR() & 0x1f;
+ u32 thumbState = ((*(u32*)0x027FFD90) & 0x20);
+
+ u32 codeAddress, exceptionAddress = 0;
+
+ int offset = 8;
+
+ if ( currentMode == 0x17 ) {
+ iprintf ("\x1b[10Cdata abort!\n\n");
+ codeAddress = exceptionRegisters[15] - offset;
+ if ( (codeAddress > 0x02000000 && codeAddress < 0x02400000) ||
+ (codeAddress > (u32)__itcm_start && codeAddress < (u32)(__itcm_start + 32768)) )
+ exceptionAddress = getExceptionAddress( codeAddress, thumbState);
+ else
+ exceptionAddress = codeAddress;
+
+ } else {
+ if (thumbState)
+ offset = 2;
+ else
+ offset = 4;
+ iprintf("\x1b[5Cundefined instruction!\n\n");
+ codeAddress = exceptionRegisters[15] - offset;
+ exceptionAddress = codeAddress;
+ }
+
+ iprintf(" pc: %08X addr: %08X\n\n",codeAddress,exceptionAddress);
+
+ int i;
+ for ( i=0; i < 8; i++ ) {
+ iprintf( " %s: %08X %s: %08X\n",
+ registerNames[i], exceptionRegisters[i],
+ registerNames[i+8],exceptionRegisters[i+8]);
+ }
+ iprintf("\n");
+ u32 *stack = (u32 *)exceptionRegisters[13];
+ for ( i=0; i<10; i++ ) {
+ iprintf( "\x1b[%d;2H%08X: %08X %08X", i + 14, (u32)&stack[i*2],stack[i*2], stack[(i*2)+1] );
+ }
+ while(1);
+
+}
+
+//---------------------------------------------------------------------------------
+void defaultExceptionHandler() {
+//---------------------------------------------------------------------------------
+ setExceptionHandler(defaultHandler) ;
+}
diff --git a/c/src/lib/libbsp/arm/nds/libnds/source/arm9/ndsmotion.c b/c/src/lib/libbsp/arm/nds/libnds/source/arm9/ndsmotion.c
index 7a31e1cfbc..830329fe11 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/source/arm9/ndsmotion.c
+++ b/c/src/lib/libbsp/arm/nds/libnds/source/arm9/ndsmotion.c
@@ -1,488 +1,488 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- DS Motion Card/DS Motion Pak functionality
-
- Copyright (C) 2007
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
- Keith Epstein (KeithE)
-
- 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/card.h>
-#include <nds/system.h>
-#include <nds/memory.h>
-#include <nds/bios.h>
-#include <nds/arm9/ndsmotion.h>
-
-#define WAIT_CYCLES 185
-
-#define CARD_WaitBusy() while (CARD_CR1 & /*BUSY*/0x80);
-
-// enables SPI bus at 4.19 MHz
-#define SPI_On() CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40 | 0;
-
-// disables SPI bus
-#define SPI_Off() CARD_CR1 = 0;
-
-// Volatile GBA bus SRAM for reading from DS Motion Pak
-#define V_SRAM ((volatile unsigned char*)0x0A000000)
-
-
-int card_type = -1;
-
-//these are the default calibration values for sensitivity and offset
-MotionCalibration calibration = {2048, 2048, 2048, 1680, 819, 819, 819, 825};
-
-// sends and receives 1 byte on the SPI bus
-unsigned char motion_spi(unsigned char in_byte){
-
- unsigned char out_byte;
- CARD_EEPDATA = in_byte; // send the output byte to the SPI bus
- CARD_WaitBusy(); // wait for transmission to complete
- out_byte=CARD_EEPDATA; // read the input byte from the SPI bus
- return out_byte;
-}
-
-
-void motion_MK6_sensor_mode() {
- // send some commands on the SPI bus
- SPI_On()
- motion_spi(0xFE);
- SPI_Off()
- SPI_On()
- motion_spi(0xFD);
- SPI_Off()
- SPI_On()
- motion_spi(0xFB);
- SPI_Off()
- SPI_On()
- motion_spi(0xF8);
- SPI_Off()
-}
-
-void motion_MK6_EEPROM_mode() {
- // send some commands on the SPI bus
- SPI_On()
- motion_spi(0xFE);
- SPI_Off()
- SPI_On()
- motion_spi(0xFD);
- SPI_Off()
- SPI_On()
- motion_spi(0xFB);
- SPI_Off()
- SPI_On()
- motion_spi(0xF9);
- SPI_Off()
-}
-
-// checks whether a DS Motion Pak is plugged in
-int motion_pak_is_inserted(){
- int motion_pak = 0;
- unsigned char return_byte = V_SRAM[10]; // read first byte of DS Motion Pak check
- swiDelay(WAIT_CYCLES);
- return_byte = V_SRAM[0];
- swiDelay(WAIT_CYCLES);
- if (return_byte==0xF0) { // DS Motion Pak returns 0xF0
- return_byte = V_SRAM[0]; // read second byte of DS Motion Pak check
- swiDelay(WAIT_CYCLES);
- if(return_byte==0x0F) { // DS Motion Pak returns 0x0F
- motion_pak = 1;
- }
- }
- return motion_pak;
-}
-
-// checks whether a DS Motion Card is plugged in
-// this only works after motion_init()
-// it will return false if it is run before motion_init()
-int motion_card_is_inserted(){
- // send 0x03 to read from DS Motion Card control register
- SPI_On()
- motion_spi(0x03); // command to read from control register
- // if the control register is 0x04 then the enable was successful
- if( motion_spi(0x00) == 0x04)
- {
- SPI_Off()
- return 1;
- }
- SPI_Off();
- return 0;
-}
-
-// turn on the DS Motion Sensor (DS Motion Pak or DS Motion Card)
-// Requires knowing which type is present (can be found by using motion_init)
-int motion_enable(int card_type) {
- switch (card_type)
- {
- case 1: // DS Motion Pak - automatically enabled on powerup
- // check to see whether Motion Pak is alive
- return motion_pak_is_inserted();
- break;
- case 2: // DS Motion Card
- // send 0x04, 0x04 to enable
- SPI_On()
- motion_spi(0x04); // command to write to control register
- motion_spi(0x04); // enable
- SPI_Off()
- // check to see whether Motion Card is alive
- return motion_card_is_inserted();
- break;
- case 3: // MK6 - same command as DS Motion Card
- // send 0x04, 0x04 to enable
- SPI_On()
- motion_spi(0x04); // command to write to control register
- motion_spi(0x04); // enable
- SPI_Off()
- // check to see whether Motion Card is alive
- return motion_card_is_inserted();
- break;
- default: // if input parameter is not recognized, return 0
- return 0;
- break;
- }
-}
-
-// Initialize the DS Motion Sensor
-// Determines which DS Motion Sensor is present
-// Turns it on
-// Does not require knowing which type is present
-int motion_init() {
- sysSetBusOwners(true, true);
- // first, check for the DS Motion Pak - type 1
- if( motion_pak_is_inserted() == 1 )
- {
- card_type = 1;
- return 1;
- }// next, check for DS Motion Card - type 2
- if( motion_enable(2) == 1 )
- {
- card_type = 2;
- return 2;
- }
-
- motion_MK6_sensor_mode(); // send command to switch MK6 to sensor mode
-
- if( motion_enable(3) == 1 )
- {
- card_type = 3;
- return 3;
- }// if neither cases are true, then return 0 to indicate no DS Motion Sensor
- return 0;
-}
-
-// Deinitialize the DS Motion Sensor
-// In the case of a DS Motion Pak, do nothing - there is nothing to de-init
-// In the case of a DS Motion Card, turns off the accelerometer
-// In the case of an MK6, turns off accelerometer and switches out of sensor mode into EEPROM mode
-void motion_deinit() {
- // DS Motion Card - turn off accelerometer
- SPI_On()
- motion_spi(0x04); // command to write to control register
- motion_spi(0x00); // turn it off
- SPI_Off()
- // MK6 - switch to EEPROM mode
- motion_MK6_EEPROM_mode(); // switch MK6 to EEPROM mode
-}
-
-// read the X acceleration
-signed int motion_read_x(void) {
- unsigned char High_byte = 0;
- unsigned char Low_byte = 0;
- signed int output = 0;
- switch(card_type)
- {
- case 1: // DS Motion Pak
- High_byte = V_SRAM[2]; // Command to load X High onto bus
- swiDelay(WAIT_CYCLES); // wait for data ready
- High_byte = V_SRAM[0]; // get the high byte
- swiDelay(WAIT_CYCLES); // wait for data ready
- Low_byte = V_SRAM[0]; // get the low byte
- swiDelay(WAIT_CYCLES); // wait after for Motion Pak to be ready for next command
- output = (signed int)( (High_byte<<8 | Low_byte)>>4);
- return output;
- break;
- case 2: // DS Motion Card
- SPI_On()
- motion_spi(0x00); // command to convert X axis
- swiDelay(625); // wait at least 40 microseconds for the A-D conversion
- output = ( (motion_spi(0x00)<<8)|motion_spi(0x00) )>>4; // read 16 bits and store as a 12 bit number
- SPI_Off()
- return output;
- break;
- case 3: // MK6 - same command as DS Motion Card
- SPI_On()
- motion_spi(0x00); // command to convert X axis
- swiDelay(625); // wait at least 40 microseconds for the A-D conversion
- output = ( (motion_spi(0x00)<<8)|motion_spi(0x00) )>>4; // read 16 bits and store as a 12 bit number
- SPI_Off()
- return output;
- break;
- default:
- return 0;
- break;
- }
-}
-
-// read the Y acceleration
-signed int motion_read_y() {
- unsigned char High_byte = 0;
- unsigned char Low_byte = 0;
- signed int output = 0;
- switch (card_type)
- {
- case 1: // DS Motion Pak
- High_byte = V_SRAM[4]; // Command to load Y High onto bus
- swiDelay(WAIT_CYCLES); // wait for data ready
- High_byte = V_SRAM[0]; // get the high byte
- swiDelay(WAIT_CYCLES); // wait for data ready
- Low_byte = V_SRAM[0]; // get the low byte
- swiDelay(WAIT_CYCLES); // wait after for Motion Pak to be ready for next command
- output = (signed int)( (High_byte<<8 | Low_byte)>>4);
- return output;
- break;
- case 2: // DS Motion Card
- SPI_On()
- motion_spi(0x02); // command to convert Y axis
- swiDelay(625); // wait at least 40 microseconds for the A-D conversion
- output = ( (motion_spi(0x00)<<8)|motion_spi(0x00) )>>4; // read 16 bits and store as a 12 bit number
- SPI_Off()
- return output;
- break;
- case 3: // MK6 - same command as DS Motion Card
- SPI_On()
- motion_spi(0x02); // command to convert Y axis
- swiDelay(625); // wait at least 40 microseconds for the A-D conversion
- output = ( (motion_spi(0x00)<<8)|motion_spi(0x00) )>>4; // read 16 bits and store as a 12 bit number
- SPI_Off()
- return output;
- break;
- default:
- return 0;
- break;
- }
-}
-
-// read the Z acceleration
-signed int motion_read_z(void) {
- unsigned char High_byte = 0;
- unsigned char Low_byte = 0;
- signed int output = 0;
- switch (card_type)
- {
- case 1: // DS Motion Pak
- High_byte = V_SRAM[6]; // Command to load Z High onto bus
- swiDelay(WAIT_CYCLES); // wait for data ready
- High_byte = V_SRAM[0]; // get the high byte
- swiDelay(WAIT_CYCLES); // wait for data ready
- Low_byte = V_SRAM[0]; // get the low byte
- swiDelay(WAIT_CYCLES); // wait after for Motion Pak to be ready for next command
- output = (signed int)( (High_byte<<8 | Low_byte)>>4);
- return output;
- break;
- case 2: // DS Motion Card
- SPI_On()
- motion_spi(0x01); // command to convert Z axis
- swiDelay(625); // wait at least 40 microseconds for the A-D conversion
- output = ( (motion_spi(0x00)<<8)|motion_spi(0x00) )>>4; // read 16 bits and store as a 12 bit number
- SPI_Off()
- return output;
- break;
- case 3: // MK6 - same command as DS Motion Card
- SPI_On()
- motion_spi(0x01); // command to convert Z axis
- swiDelay(625); // wait at least 40 microseconds for the A-D conversion
- output = ( (motion_spi(0x00)<<8)|motion_spi(0x00) )>>4; // read 16 bits and store as a 12 bit number
- SPI_Off()
- return output;
- break;
- default:
- return 0;
- break;
- }
-}
-
-// read the Z rotation (gyro)
-signed int motion_read_gyro(void) {
- unsigned char High_byte = 0;
- unsigned char Low_byte = 0;
- signed int output = 0;
- switch (card_type)
- {
- case 1: // DS Motion Pak
- High_byte = V_SRAM[8]; // Command to load Gyro High onto bus
- swiDelay(WAIT_CYCLES); // wait for data ready
- High_byte = V_SRAM[0]; // get the high byte
- swiDelay(WAIT_CYCLES); // wait for data ready
- Low_byte = V_SRAM[0]; // get the low byte
- swiDelay(WAIT_CYCLES); // wait after for Motion Pak to be ready for next command
- output = (signed int)( (High_byte<<8 | Low_byte)>>4);
- return output;
- break;
- case 2: // DS Motion Card
- SPI_On()
- motion_spi(0x07); // command to convert Gyro axis
- swiDelay(625); // wait at least 40 microseconds for the A-D conversion
- output = ( (motion_spi(0x00)<<8)|motion_spi(0x00) )>>4; // read 16 bits and store as a 12 bit number
- SPI_Off()
- return output;
- break;
- case 3: // MK6 - same command as DS Motion Card
- SPI_On()
- motion_spi(0x07); // command to convert Gyro axis
- swiDelay(625); // wait at least 40 microseconds for the A-D conversion
- output = ( (motion_spi(0x00)<<8)|motion_spi(0x00) )>>4; // read 16 bits and store as a 12 bit number
- SPI_Off()
- return output;
- break;
- default:
- return 0;
- break;
- }
-}
-
-//gets acceleration value in mili G (where g is 9.8 m/s*s)
-int motion_acceleration_x(void){
- int accel = motion_read_x();
- return (accel - calibration.xoff) * 1000 / calibration.xsens;
-}
-
-//gets acceleration value in mili G (where g is 9.8 m/s*s)
-int motion_acceleration_y(void){
- int accel = motion_read_y();
- return (accel - calibration.yoff) * 1000 / calibration.ysens;
-}
-//gets acceleration value in mili G (where g is 9.8 m/s*s)
-int motion_acceleration_z(void){
- int accel = motion_read_z();
- return (accel - calibration.zoff) * 1000 / calibration.zsens;
-}
-
-//converts raw rotation value to degrees per second
-int motion_rotation(void){
- int rotation = motion_read_gyro();
- return (rotation - calibration.goff) * 1000 / calibration.gsens;
-}
-
-//this should be passed the raw reading at 1g for accurate
-//acceleration calculations. Default is 819
-void motion_set_sens_x(int sens){
- calibration.xsens = sens - calibration.xoff;
-}
-
-//this should be passed the raw reading at 1g for accurate
-//acceleration calculations. Default is 819
-void motion_set_sens_y(int sens){
- calibration.ysens = sens - calibration.yoff;
-}
-
-//this should be passed the raw reading at 1g for accurate
-//acceleration calculations. Default is 819
-void motion_set_sens_z(int sens){
- calibration.zsens = sens - calibration.zoff;
-}
-
-//this should be passed the raw reading at 1g for accurate
-//acceleration calculations. Default is 825
-void motion_set_sens_gyro(int sens){
- calibration.gsens = sens;
-}
-
-//this should be called when the axis is under no acceleration
-//default is 2048
-void motion_set_offs_x(void){
- calibration.xoff = motion_read_x();
-}
-
-//this should be called when the axis is under no acceleration
-//default is 2048
-void motion_set_offs_y(void){
- calibration.yoff = motion_read_y();
-}
-
-//this should be called when the axis is under no acceleration
-//default is 2048
-void motion_set_offs_z(void){
- calibration.zoff = motion_read_z();
-}
-
-//this should be called when the axis is under no acceleration
-//default is 1680
-void motion_set_offs_gyro(void){
- calibration.goff = motion_read_gyro();
-}
-
-MotionCalibration* motion_get_calibration(){
- return &calibration;
-}
-
-void motion_set_calibration(MotionCalibration* cal){
- calibration.xsens = cal->xsens;
- calibration.ysens = cal->ysens;
- calibration.zsens = cal->zsens;
- calibration.gsens = cal->gsens;
- calibration.xoff = cal->xoff;
- calibration.yoff = cal->yoff;
- calibration.zoff = cal->zoff;
- calibration.goff = cal->goff;
-}
-
-// enable analog input number 1 (ain_1)
-void motion_enable_ain_1(){
- unsigned char return_byte;
- return_byte = V_SRAM[16];
- swiDelay(WAIT_CYCLES);
-}
-
-// enable analog input number 2 (ain_2)
-void motion_enable_ain_2(){
- unsigned char return_byte;
- return_byte = V_SRAM[18];
- swiDelay(WAIT_CYCLES);
-}
-
-// read from the analog input number 1 - requires enabling ain_1 first
-int motion_read_ain_1(){
- unsigned char High_byte = V_SRAM[12]; // Command to load AIN_1 High onto bus
- swiDelay(WAIT_CYCLES); // wait for data ready
- High_byte = V_SRAM[0]; // get the high byte
- swiDelay(WAIT_CYCLES); // wait for data ready
- unsigned char Low_byte = V_SRAM[0]; // get the low byte
- swiDelay(WAIT_CYCLES); // wait after for Motion Pak to be ready for next command
- signed int output = (signed int)( (High_byte<<8 | Low_byte)>>4);
- return output;
-}
-
-// read from the analog input number 2 - requires enabling ain_2 first
-int motion_read_ain_2(){
- unsigned char High_byte = V_SRAM[14]; // Command to load AIN_1 High onto bus
- swiDelay(WAIT_CYCLES); // wait for data ready
- High_byte = V_SRAM[0]; // get the high byte
- swiDelay(WAIT_CYCLES); // wait for data ready
- unsigned char Low_byte = V_SRAM[0]; // get the low byte
- swiDelay(WAIT_CYCLES); // wait after for Motion Pak to be ready for next command
- signed int output = (signed int)( (High_byte<<8 | Low_byte)>>4);
- return output;
-}
-
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ DS Motion Card/DS Motion Pak functionality
+
+ Copyright (C) 2007
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+ Keith Epstein (KeithE)
+
+ 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/card.h>
+#include <nds/system.h>
+#include <nds/memory.h>
+#include <nds/bios.h>
+#include <nds/arm9/ndsmotion.h>
+
+#define WAIT_CYCLES 185
+
+#define CARD_WaitBusy() while (CARD_CR1 & /*BUSY*/0x80);
+
+// enables SPI bus at 4.19 MHz
+#define SPI_On() CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40 | 0;
+
+// disables SPI bus
+#define SPI_Off() CARD_CR1 = 0;
+
+// Volatile GBA bus SRAM for reading from DS Motion Pak
+#define V_SRAM ((volatile unsigned char*)0x0A000000)
+
+
+int card_type = -1;
+
+//these are the default calibration values for sensitivity and offset
+MotionCalibration calibration = {2048, 2048, 2048, 1680, 819, 819, 819, 825};
+
+// sends and receives 1 byte on the SPI bus
+unsigned char motion_spi(unsigned char in_byte){
+
+ unsigned char out_byte;
+ CARD_EEPDATA = in_byte; // send the output byte to the SPI bus
+ CARD_WaitBusy(); // wait for transmission to complete
+ out_byte=CARD_EEPDATA; // read the input byte from the SPI bus
+ return out_byte;
+}
+
+
+void motion_MK6_sensor_mode() {
+ // send some commands on the SPI bus
+ SPI_On()
+ motion_spi(0xFE);
+ SPI_Off()
+ SPI_On()
+ motion_spi(0xFD);
+ SPI_Off()
+ SPI_On()
+ motion_spi(0xFB);
+ SPI_Off()
+ SPI_On()
+ motion_spi(0xF8);
+ SPI_Off()
+}
+
+void motion_MK6_EEPROM_mode() {
+ // send some commands on the SPI bus
+ SPI_On()
+ motion_spi(0xFE);
+ SPI_Off()
+ SPI_On()
+ motion_spi(0xFD);
+ SPI_Off()
+ SPI_On()
+ motion_spi(0xFB);
+ SPI_Off()
+ SPI_On()
+ motion_spi(0xF9);
+ SPI_Off()
+}
+
+// checks whether a DS Motion Pak is plugged in
+int motion_pak_is_inserted(){
+ int motion_pak = 0;
+ unsigned char return_byte = V_SRAM[10]; // read first byte of DS Motion Pak check
+ swiDelay(WAIT_CYCLES);
+ return_byte = V_SRAM[0];
+ swiDelay(WAIT_CYCLES);
+ if (return_byte==0xF0) { // DS Motion Pak returns 0xF0
+ return_byte = V_SRAM[0]; // read second byte of DS Motion Pak check
+ swiDelay(WAIT_CYCLES);
+ if(return_byte==0x0F) { // DS Motion Pak returns 0x0F
+ motion_pak = 1;
+ }
+ }
+ return motion_pak;
+}
+
+// checks whether a DS Motion Card is plugged in
+// this only works after motion_init()
+// it will return false if it is run before motion_init()
+int motion_card_is_inserted(){
+ // send 0x03 to read from DS Motion Card control register
+ SPI_On()
+ motion_spi(0x03); // command to read from control register
+ // if the control register is 0x04 then the enable was successful
+ if( motion_spi(0x00) == 0x04)
+ {
+ SPI_Off()
+ return 1;
+ }
+ SPI_Off();
+ return 0;
+}
+
+// turn on the DS Motion Sensor (DS Motion Pak or DS Motion Card)
+// Requires knowing which type is present (can be found by using motion_init)
+int motion_enable(int card_type) {
+ switch (card_type)
+ {
+ case 1: // DS Motion Pak - automatically enabled on powerup
+ // check to see whether Motion Pak is alive
+ return motion_pak_is_inserted();
+ break;
+ case 2: // DS Motion Card
+ // send 0x04, 0x04 to enable
+ SPI_On()
+ motion_spi(0x04); // command to write to control register
+ motion_spi(0x04); // enable
+ SPI_Off()
+ // check to see whether Motion Card is alive
+ return motion_card_is_inserted();
+ break;
+ case 3: // MK6 - same command as DS Motion Card
+ // send 0x04, 0x04 to enable
+ SPI_On()
+ motion_spi(0x04); // command to write to control register
+ motion_spi(0x04); // enable
+ SPI_Off()
+ // check to see whether Motion Card is alive
+ return motion_card_is_inserted();
+ break;
+ default: // if input parameter is not recognized, return 0
+ return 0;
+ break;
+ }
+}
+
+// Initialize the DS Motion Sensor
+// Determines which DS Motion Sensor is present
+// Turns it on
+// Does not require knowing which type is present
+int motion_init() {
+ sysSetBusOwners(true, true);
+ // first, check for the DS Motion Pak - type 1
+ if( motion_pak_is_inserted() == 1 )
+ {
+ card_type = 1;
+ return 1;
+ }// next, check for DS Motion Card - type 2
+ if( motion_enable(2) == 1 )
+ {
+ card_type = 2;
+ return 2;
+ }
+
+ motion_MK6_sensor_mode(); // send command to switch MK6 to sensor mode
+
+ if( motion_enable(3) == 1 )
+ {
+ card_type = 3;
+ return 3;
+ }// if neither cases are true, then return 0 to indicate no DS Motion Sensor
+ return 0;
+}
+
+// Deinitialize the DS Motion Sensor
+// In the case of a DS Motion Pak, do nothing - there is nothing to de-init
+// In the case of a DS Motion Card, turns off the accelerometer
+// In the case of an MK6, turns off accelerometer and switches out of sensor mode into EEPROM mode
+void motion_deinit() {
+ // DS Motion Card - turn off accelerometer
+ SPI_On()
+ motion_spi(0x04); // command to write to control register
+ motion_spi(0x00); // turn it off
+ SPI_Off()
+ // MK6 - switch to EEPROM mode
+ motion_MK6_EEPROM_mode(); // switch MK6 to EEPROM mode
+}
+
+// read the X acceleration
+signed int motion_read_x(void) {
+ unsigned char High_byte = 0;
+ unsigned char Low_byte = 0;
+ signed int output = 0;
+ switch(card_type)
+ {
+ case 1: // DS Motion Pak
+ High_byte = V_SRAM[2]; // Command to load X High onto bus
+ swiDelay(WAIT_CYCLES); // wait for data ready
+ High_byte = V_SRAM[0]; // get the high byte
+ swiDelay(WAIT_CYCLES); // wait for data ready
+ Low_byte = V_SRAM[0]; // get the low byte
+ swiDelay(WAIT_CYCLES); // wait after for Motion Pak to be ready for next command
+ output = (signed int)( (High_byte<<8 | Low_byte)>>4);
+ return output;
+ break;
+ case 2: // DS Motion Card
+ SPI_On()
+ motion_spi(0x00); // command to convert X axis
+ swiDelay(625); // wait at least 40 microseconds for the A-D conversion
+ output = ( (motion_spi(0x00)<<8)|motion_spi(0x00) )>>4; // read 16 bits and store as a 12 bit number
+ SPI_Off()
+ return output;
+ break;
+ case 3: // MK6 - same command as DS Motion Card
+ SPI_On()
+ motion_spi(0x00); // command to convert X axis
+ swiDelay(625); // wait at least 40 microseconds for the A-D conversion
+ output = ( (motion_spi(0x00)<<8)|motion_spi(0x00) )>>4; // read 16 bits and store as a 12 bit number
+ SPI_Off()
+ return output;
+ break;
+ default:
+ return 0;
+ break;
+ }
+}
+
+// read the Y acceleration
+signed int motion_read_y() {
+ unsigned char High_byte = 0;
+ unsigned char Low_byte = 0;
+ signed int output = 0;
+ switch (card_type)
+ {
+ case 1: // DS Motion Pak
+ High_byte = V_SRAM[4]; // Command to load Y High onto bus
+ swiDelay(WAIT_CYCLES); // wait for data ready
+ High_byte = V_SRAM[0]; // get the high byte
+ swiDelay(WAIT_CYCLES); // wait for data ready
+ Low_byte = V_SRAM[0]; // get the low byte
+ swiDelay(WAIT_CYCLES); // wait after for Motion Pak to be ready for next command
+ output = (signed int)( (High_byte<<8 | Low_byte)>>4);
+ return output;
+ break;
+ case 2: // DS Motion Card
+ SPI_On()
+ motion_spi(0x02); // command to convert Y axis
+ swiDelay(625); // wait at least 40 microseconds for the A-D conversion
+ output = ( (motion_spi(0x00)<<8)|motion_spi(0x00) )>>4; // read 16 bits and store as a 12 bit number
+ SPI_Off()
+ return output;
+ break;
+ case 3: // MK6 - same command as DS Motion Card
+ SPI_On()
+ motion_spi(0x02); // command to convert Y axis
+ swiDelay(625); // wait at least 40 microseconds for the A-D conversion
+ output = ( (motion_spi(0x00)<<8)|motion_spi(0x00) )>>4; // read 16 bits and store as a 12 bit number
+ SPI_Off()
+ return output;
+ break;
+ default:
+ return 0;
+ break;
+ }
+}
+
+// read the Z acceleration
+signed int motion_read_z(void) {
+ unsigned char High_byte = 0;
+ unsigned char Low_byte = 0;
+ signed int output = 0;
+ switch (card_type)
+ {
+ case 1: // DS Motion Pak
+ High_byte = V_SRAM[6]; // Command to load Z High onto bus
+ swiDelay(WAIT_CYCLES); // wait for data ready
+ High_byte = V_SRAM[0]; // get the high byte
+ swiDelay(WAIT_CYCLES); // wait for data ready
+ Low_byte = V_SRAM[0]; // get the low byte
+ swiDelay(WAIT_CYCLES); // wait after for Motion Pak to be ready for next command
+ output = (signed int)( (High_byte<<8 | Low_byte)>>4);
+ return output;
+ break;
+ case 2: // DS Motion Card
+ SPI_On()
+ motion_spi(0x01); // command to convert Z axis
+ swiDelay(625); // wait at least 40 microseconds for the A-D conversion
+ output = ( (motion_spi(0x00)<<8)|motion_spi(0x00) )>>4; // read 16 bits and store as a 12 bit number
+ SPI_Off()
+ return output;
+ break;
+ case 3: // MK6 - same command as DS Motion Card
+ SPI_On()
+ motion_spi(0x01); // command to convert Z axis
+ swiDelay(625); // wait at least 40 microseconds for the A-D conversion
+ output = ( (motion_spi(0x00)<<8)|motion_spi(0x00) )>>4; // read 16 bits and store as a 12 bit number
+ SPI_Off()
+ return output;
+ break;
+ default:
+ return 0;
+ break;
+ }
+}
+
+// read the Z rotation (gyro)
+signed int motion_read_gyro(void) {
+ unsigned char High_byte = 0;
+ unsigned char Low_byte = 0;
+ signed int output = 0;
+ switch (card_type)
+ {
+ case 1: // DS Motion Pak
+ High_byte = V_SRAM[8]; // Command to load Gyro High onto bus
+ swiDelay(WAIT_CYCLES); // wait for data ready
+ High_byte = V_SRAM[0]; // get the high byte
+ swiDelay(WAIT_CYCLES); // wait for data ready
+ Low_byte = V_SRAM[0]; // get the low byte
+ swiDelay(WAIT_CYCLES); // wait after for Motion Pak to be ready for next command
+ output = (signed int)( (High_byte<<8 | Low_byte)>>4);
+ return output;
+ break;
+ case 2: // DS Motion Card
+ SPI_On()
+ motion_spi(0x07); // command to convert Gyro axis
+ swiDelay(625); // wait at least 40 microseconds for the A-D conversion
+ output = ( (motion_spi(0x00)<<8)|motion_spi(0x00) )>>4; // read 16 bits and store as a 12 bit number
+ SPI_Off()
+ return output;
+ break;
+ case 3: // MK6 - same command as DS Motion Card
+ SPI_On()
+ motion_spi(0x07); // command to convert Gyro axis
+ swiDelay(625); // wait at least 40 microseconds for the A-D conversion
+ output = ( (motion_spi(0x00)<<8)|motion_spi(0x00) )>>4; // read 16 bits and store as a 12 bit number
+ SPI_Off()
+ return output;
+ break;
+ default:
+ return 0;
+ break;
+ }
+}
+
+//gets acceleration value in mili G (where g is 9.8 m/s*s)
+int motion_acceleration_x(void){
+ int accel = motion_read_x();
+ return (accel - calibration.xoff) * 1000 / calibration.xsens;
+}
+
+//gets acceleration value in mili G (where g is 9.8 m/s*s)
+int motion_acceleration_y(void){
+ int accel = motion_read_y();
+ return (accel - calibration.yoff) * 1000 / calibration.ysens;
+}
+//gets acceleration value in mili G (where g is 9.8 m/s*s)
+int motion_acceleration_z(void){
+ int accel = motion_read_z();
+ return (accel - calibration.zoff) * 1000 / calibration.zsens;
+}
+
+//converts raw rotation value to degrees per second
+int motion_rotation(void){
+ int rotation = motion_read_gyro();
+ return (rotation - calibration.goff) * 1000 / calibration.gsens;
+}
+
+//this should be passed the raw reading at 1g for accurate
+//acceleration calculations. Default is 819
+void motion_set_sens_x(int sens){
+ calibration.xsens = sens - calibration.xoff;
+}
+
+//this should be passed the raw reading at 1g for accurate
+//acceleration calculations. Default is 819
+void motion_set_sens_y(int sens){
+ calibration.ysens = sens - calibration.yoff;
+}
+
+//this should be passed the raw reading at 1g for accurate
+//acceleration calculations. Default is 819
+void motion_set_sens_z(int sens){
+ calibration.zsens = sens - calibration.zoff;
+}
+
+//this should be passed the raw reading at 1g for accurate
+//acceleration calculations. Default is 825
+void motion_set_sens_gyro(int sens){
+ calibration.gsens = sens;
+}
+
+//this should be called when the axis is under no acceleration
+//default is 2048
+void motion_set_offs_x(void){
+ calibration.xoff = motion_read_x();
+}
+
+//this should be called when the axis is under no acceleration
+//default is 2048
+void motion_set_offs_y(void){
+ calibration.yoff = motion_read_y();
+}
+
+//this should be called when the axis is under no acceleration
+//default is 2048
+void motion_set_offs_z(void){
+ calibration.zoff = motion_read_z();
+}
+
+//this should be called when the axis is under no acceleration
+//default is 1680
+void motion_set_offs_gyro(void){
+ calibration.goff = motion_read_gyro();
+}
+
+MotionCalibration* motion_get_calibration(){
+ return &calibration;
+}
+
+void motion_set_calibration(MotionCalibration* cal){
+ calibration.xsens = cal->xsens;
+ calibration.ysens = cal->ysens;
+ calibration.zsens = cal->zsens;
+ calibration.gsens = cal->gsens;
+ calibration.xoff = cal->xoff;
+ calibration.yoff = cal->yoff;
+ calibration.zoff = cal->zoff;
+ calibration.goff = cal->goff;
+}
+
+// enable analog input number 1 (ain_1)
+void motion_enable_ain_1(){
+ unsigned char return_byte;
+ return_byte = V_SRAM[16];
+ swiDelay(WAIT_CYCLES);
+}
+
+// enable analog input number 2 (ain_2)
+void motion_enable_ain_2(){
+ unsigned char return_byte;
+ return_byte = V_SRAM[18];
+ swiDelay(WAIT_CYCLES);
+}
+
+// read from the analog input number 1 - requires enabling ain_1 first
+int motion_read_ain_1(){
+ unsigned char High_byte = V_SRAM[12]; // Command to load AIN_1 High onto bus
+ swiDelay(WAIT_CYCLES); // wait for data ready
+ High_byte = V_SRAM[0]; // get the high byte
+ swiDelay(WAIT_CYCLES); // wait for data ready
+ unsigned char Low_byte = V_SRAM[0]; // get the low byte
+ swiDelay(WAIT_CYCLES); // wait after for Motion Pak to be ready for next command
+ signed int output = (signed int)( (High_byte<<8 | Low_byte)>>4);
+ return output;
+}
+
+// read from the analog input number 2 - requires enabling ain_2 first
+int motion_read_ain_2(){
+ unsigned char High_byte = V_SRAM[14]; // Command to load AIN_1 High onto bus
+ swiDelay(WAIT_CYCLES); // wait for data ready
+ High_byte = V_SRAM[0]; // get the high byte
+ swiDelay(WAIT_CYCLES); // wait for data ready
+ unsigned char Low_byte = V_SRAM[0]; // get the low byte
+ swiDelay(WAIT_CYCLES); // wait after for Motion Pak to be ready for next command
+ signed int output = (signed int)( (High_byte<<8 | Low_byte)>>4);
+ return output;
+}
+
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/source/arm9/videoGL.c b/c/src/lib/libbsp/arm/nds/libnds/source/arm9/videoGL.c
index 167748294e..217beb0582 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/source/arm9/videoGL.c
+++ b/c/src/lib/libbsp/arm/nds/libnds/source/arm9/videoGL.c
@@ -1,426 +1,426 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- Video API vaguely similar to OpenGL
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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/jtypes.h>
-#include <nds/memory.h>
-#include <nds/bios.h>
-#include <nds/arm9/math.h>
-#include <nds/arm9/video.h>
-#include <nds/arm9/videoGL.h>
-#include <nds/arm9/trig_lut.h>
-
-// this is the actual data of the globals for videoGL
-// Please use the glGlob pointer to access this data since that makes it easier to move stuff in/out of the header.
-static gl_hidden_globals glGlobalData;
-
-// This returns the pointer to the globals for videoGL
-gl_hidden_globals* glGetGlobals() {
- return &glGlobalData;
-}
-
-//---------------------------------------------------------------------------------
-void glRotatef32i(int angle, int32 x, int32 y, int32 z) {
-//---------------------------------------------------------------------------------
- int32 axis[3];
- int32 sine = SIN[angle & LUT_MASK];
- int32 cosine = COS[angle & LUT_MASK];
- int32 one_minus_cosine = inttof32(1) - cosine;
-
- axis[0]=x;
- axis[1]=y;
- axis[2]=z;
-
- normalizef32(axis); // should require passed in normalized?
-
- MATRIX_MULT3x3 = cosine + mulf32(one_minus_cosine, mulf32(axis[0], axis[0]));
- MATRIX_MULT3x3 = mulf32(one_minus_cosine, mulf32(axis[0], axis[1])) - mulf32(axis[2], sine);
- MATRIX_MULT3x3 = mulf32(mulf32(one_minus_cosine, axis[0]), axis[2]) + mulf32(axis[1], sine);
-
- MATRIX_MULT3x3 = mulf32(mulf32(one_minus_cosine, axis[0]), axis[1]) + mulf32(axis[2], sine);
- MATRIX_MULT3x3 = cosine + mulf32(mulf32(one_minus_cosine, axis[1]), axis[1]);
- MATRIX_MULT3x3 = mulf32(mulf32(one_minus_cosine, axis[1]), axis[2]) - mulf32(axis[0], sine);
-
- MATRIX_MULT3x3 = mulf32(mulf32(one_minus_cosine, axis[0]), axis[2]) - mulf32(axis[1], sine);
- MATRIX_MULT3x3 = mulf32(mulf32(one_minus_cosine, axis[1]), axis[2]) + mulf32(axis[0], sine);
- MATRIX_MULT3x3 = cosine + mulf32(mulf32(one_minus_cosine, axis[2]), axis[2]);
-}
-
-
-
-
-//---------------------------------------------------------------------------------
-void glMaterialf(GL_MATERIALS_ENUM mode, rgb color) {
-//---------------------------------------------------------------------------------
- static uint32 diffuse_ambient = 0;
- static uint32 specular_emission = 0;
-
- switch(mode) {
- case GL_AMBIENT:
- diffuse_ambient = (color << 16) | (diffuse_ambient & 0xFFFF);
- break;
- case GL_DIFFUSE:
- diffuse_ambient = color | (diffuse_ambient & 0xFFFF0000);
- break;
- case GL_AMBIENT_AND_DIFFUSE:
- diffuse_ambient= color + (color << 16);
- break;
- case GL_SPECULAR:
- specular_emission = color | (specular_emission & 0xFFFF0000);
- break;
- case GL_SHININESS:
- break;
- case GL_EMISSION:
- specular_emission = (color << 16) | (specular_emission & 0xFFFF);
- break;
- }
-
- GFX_DIFFUSE_AMBIENT = diffuse_ambient;
- GFX_SPECULAR_EMISSION = specular_emission;
-}
-
-//---------------------------------------------------------------------------------
-void glInit_C(void) {
-//---------------------------------------------------------------------------------
- glGlob = glGetGlobals();
-
- glGlob->clearColor = 0;
-
- // init texture globals
- glGlob->activeTexture = 0;
- glGlob->nextBlock = (uint32*)0x06800000;
- glGlob->nextPBlock = 0;
- glGlob->nameCount = 1;
-
- while (GFX_STATUS & (1<<27)); // wait till gfx engine is not busy
-
- // Clear the FIFO
- GFX_STATUS |= (1<<29);
-
- // Clear overflows from list memory
- glResetMatrixStack();
-
- // prime the vertex/polygon buffers
- glFlush(0);
-
- // reset the control bits
- GFX_CONTROL = 0;
-
- // reset the rear-plane(a.k.a. clear color) to black, ID=0, and opaque
- glClearColor(0,0,0,31);
- glClearPolyID(0);
-
- // reset stored texture locations
- glResetTextures();
-
- // reset the depth to it's max
- glClearDepth(GL_MAX_DEPTH);
-
- GFX_TEX_FORMAT = 0;
- GFX_POLY_FORMAT = 0;
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
-}
-
-//---------------------------------------------------------------------------------
-void glResetTextures(void) {
-//---------------------------------------------------------------------------------
- glGlob->activeTexture = 0;
- glGlob->nextBlock = (uint32*)0x06800000;
- glGlob->nextPBlock = 0;
- glGlob->nameCount = 1;
-}
-
-//---------------------------------------------------------------------------------
-// glGenTextures creates integer names for your table
-// takes n as the number of textures to generate and
-// a pointer to the names array that it needs to fill.
-// Returns 1 if succesful and 0 if out of texture names
-//---------------------------------------------------------------------------------
-
-int glGenTextures(int n, int *names) {
-//---------------------------------------------------------------------------------
- int index = 0;
- for(index = 0; index < n; index++) {
- if(glGlob->nameCount >= MAX_TEXTURES)
- return 0;
- else
- names[index] = glGlob->nameCount++;
- }
- return 1;
-}
-
-//---------------------------------------------------------------------------------
-// glBindTexure sets the current named
-// texture to the active texture. Target
-// is ignored as all DS textures are 2D
-//---------------------------------------------------------------------------------
-void glBindTexture(int target, int name) {
-//---------------------------------------------------------------------------------
- if (name == 0)
- GFX_TEX_FORMAT = 0;
- else
- GFX_TEX_FORMAT = glGlob->textures[name];
-
-
- glGlob->activeTexture = name;
-}
-//---------------------------------------------------------------------------------
-// glColorTable establishes the location of the current palette.
-// Roughly follows glColorTableEXT. Association of palettes with
-// named textures is left to the application.
-//---------------------------------------------------------------------------------
-void glColorTable( uint8 format, uint32 addr ) {
-//---------------------------------------------------------------------------------
- GFX_PAL_FORMAT = addr>>(4-(format==GL_RGB4));
-}
-
-//---------------------------------------------------------------------------------
-//---------------------------------------------------------------------------------
-void glTexCoord2f32(int32 u, int32 v) {
-//---------------------------------------------------------------------------------
- int x, y;
-
- x = ((glGlob->textures[glGlob->activeTexture]) >> 20) & 7;
- y = ((glGlob->textures[glGlob->activeTexture]) >> 23) & 7;
-
- glTexCoord2t16(f32tot16 (mulf32(u,inttof32(8<<x))), f32tot16 (mulf32(v,inttof32(8<<y))));
-}
-
-//---------------------------------------------------------------------------------
-// glTexParameter although named the same
-// as its gl counterpart it is not compatible
-// Effort may be made in the future to make it so.
-//---------------------------------------------------------------------------------
-void glTexParameter( uint8 sizeX, uint8 sizeY,
- const uint32* addr,
- GL_TEXTURE_TYPE_ENUM mode,
- uint32 param) {
-//---------------------------------------------------------------------------------
- glGlob->textures[glGlob->activeTexture] = param | (sizeX << 20) | (sizeY << 23) | (((uint32)addr >> 3) & 0xFFFF) | (mode << 26);
-}
-//---------------------------------------------------------------------------------
-//glGetTexturePointer gets a pointer to vram which contains the texture
-//
-//---------------------------------------------------------------------------------
-void* glGetTexturePointer( int name) {
-//---------------------------------------------------------------------------------
- return (void*) ((glGlob->textures[name] & 0xFFFF) << 3);
-}
-
-//---------------------------------------------------------------------------------
-u32 glGetTexParameter(){
-//---------------------------------------------------------------------------------
- return glGlob->textures[glGlob->activeTexture];
-}
-
-
-//---------------------------------------------------------------------------------
-inline uint32 alignVal( uint32 val, uint32 to ) {
- return (val & (to-1))? (val & ~(to-1)) + to : val;
-}
-
-//---------------------------------------------------------------------------------
-int getNextPaletteSlot(u16 count, uint8 format) {
-//---------------------------------------------------------------------------------
- // ensure the result aligns on a palette block for this format
- uint32 result = alignVal(glGlob->nextPBlock, 1<<(4-(format==GL_RGB4)));
-
- // convert count to bytes and align to next (smallest format) palette block
- count = alignVal( count<<1, 1<<3 );
-
- // ensure that end is within palette video mem
- if( result+count > 0x10000 ) // VRAM_F - VRAM_E
- return -1;
-
- glGlob->nextPBlock = result+count;
- return (int)result;
-}
-
-//---------------------------------------------------------------------------------
-uint16* vramGetBank(uint16 *addr) {
-//---------------------------------------------------------------------------------
- if(addr >= VRAM_A && addr < VRAM_B)
- return VRAM_A;
- else if(addr >= VRAM_B && addr < VRAM_C)
- return VRAM_B;
- else if(addr >= VRAM_C && addr < VRAM_D)
- return VRAM_C;
- else if(addr >= VRAM_D && addr < VRAM_E)
- return VRAM_D;
- else if(addr >= VRAM_E && addr < VRAM_F)
- return VRAM_E;
- else if(addr >= VRAM_F && addr < VRAM_G)
- return VRAM_F;
- else if(addr >= VRAM_G && addr < VRAM_H)
- return VRAM_H;
- else if(addr >= VRAM_H && addr < VRAM_I)
- return VRAM_H;
- else return VRAM_I;
-}
-
-
-//---------------------------------------------------------------------------------
-int vramIsTextureBank(uint16 *addr) {
-//---------------------------------------------------------------------------------
- uint16* vram = vramGetBank(addr);
-
- if(vram == VRAM_A)
- {
- if((VRAM_A_CR & 3) == ((VRAM_A_TEXTURE) & 3))
- return 1;
- else return 0;
- }
- else if(vram == VRAM_B)
- {
- if((VRAM_B_CR & 3) == ((VRAM_B_TEXTURE) & 3))
- return 1;
- else return 0;
- }
- else if(vram == VRAM_C)
- {
- if((VRAM_C_CR & 3) == ((VRAM_C_TEXTURE) & 3))
- return 1;
- else return 0;
- }
- else if(vram == VRAM_D)
- {
- if((VRAM_D_CR & 3) == ((VRAM_D_TEXTURE) & 3))
- return 1;
- else return 0;
- }
- else
- return 0;
-}
-//---------------------------------------------------------------------------------
-uint32* getNextTextureSlot(int size) {
-//---------------------------------------------------------------------------------
- uint32* result = glGlob->nextBlock;
- glGlob->nextBlock += size >> 2;
-
- //uh-oh...out of texture memory in this bank...find next one assigned to textures
- while(!vramIsTextureBank((uint16*)glGlob->nextBlock - 1) && glGlob->nextBlock <= (uint32*)VRAM_E)
- {
- glGlob->nextBlock = (uint32*)vramGetBank((uint16*)result) + (0x20000 >> 2); //next bank
- result = glGlob->nextBlock;
- glGlob->nextBlock += size >> 2;
- }
-
- if(glGlob->nextBlock > (uint32*)VRAM_E) {
- result = 0;
- }
- return result;
-}
-
-//---------------------------------------------------------------------------------
-// Similer to glTextImage2D from gl it takes a pointer to data
-// Empty fields and target are unused but provided for code compatibility.
-// type is simply the texture type (GL_RGB, GL_RGB8 ect...)
-//---------------------------------------------------------------------------------
-int glTexImage2D(int target, int empty1, GL_TEXTURE_TYPE_ENUM type, int sizeX, int sizeY, int empty2, int param, const uint8* texture) {
-//---------------------------------------------------------------------------------
- uint32 size = 0;
- uint32* addr;
- uint32 vramTemp;
-
- size = 1 << (sizeX + sizeY + 6);
-
-
- switch (type) {
- case GL_RGB:
- case GL_RGBA:
- size = size << 1;
- break;
- case GL_RGB4:
- size = size >> 2;
- break;
- case GL_RGB16:
- size = size >> 1;
- break;
- default:
- break;
- }
-
- addr = getNextTextureSlot(size);
-
- if(!addr)
- return 0;
-
- // unlock texture memory
- vramTemp = vramSetMainBanks(VRAM_A_LCD,VRAM_B_LCD,VRAM_C_LCD,VRAM_D_LCD);
-
- if (type == GL_RGB) {
- // We do GL_RGB as GL_RGBA, but we set each alpha bit to 1 during the copy
- u16 * src = (u16*)texture;
- u16 * dest = (u16*)addr;
-
- glTexParameter(sizeX, sizeY, addr, GL_RGBA, param);
-
- while (size--) {
- *dest++ = *src | (1 << 15);
- src++;
- }
- } else {
- // For everything else, we do a straight copy
- glTexParameter(sizeX, sizeY, addr, type, param);
- swiCopy((uint32*)texture, addr , size / 4 | COPY_MODE_WORD);
- }
- vramRestoreMainBanks(vramTemp);
- return 1;
-}
-
-//---------------------------------------------------------------------------------
-void glTexLoadPal(const u16* pal, u16 count, u32 addr) {
-//---------------------------------------------------------------------------------
- vramSetBankE(VRAM_E_LCD);
- swiCopy( pal, &VRAM_E[addr>>1] , count / 2 | COPY_MODE_WORD);
- vramSetBankE(VRAM_E_TEX_PALETTE);
-}
-
-//---------------------------------------------------------------------------------
-int gluTexLoadPal(const u16* pal, u16 count, uint8 format) {
-//---------------------------------------------------------------------------------
- int addr = getNextPaletteSlot(count, format);
- if( addr>=0 )
- glTexLoadPal(pal, count, (u32) addr);
-
- return addr;
-}
-
-
-
-
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ Video API vaguely similar to OpenGL
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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/jtypes.h>
+#include <nds/memory.h>
+#include <nds/bios.h>
+#include <nds/arm9/math.h>
+#include <nds/arm9/video.h>
+#include <nds/arm9/videoGL.h>
+#include <nds/arm9/trig_lut.h>
+
+// this is the actual data of the globals for videoGL
+// Please use the glGlob pointer to access this data since that makes it easier to move stuff in/out of the header.
+static gl_hidden_globals glGlobalData;
+
+// This returns the pointer to the globals for videoGL
+gl_hidden_globals* glGetGlobals() {
+ return &glGlobalData;
+}
+
+//---------------------------------------------------------------------------------
+void glRotatef32i(int angle, int32 x, int32 y, int32 z) {
+//---------------------------------------------------------------------------------
+ int32 axis[3];
+ int32 sine = SIN[angle & LUT_MASK];
+ int32 cosine = COS[angle & LUT_MASK];
+ int32 one_minus_cosine = inttof32(1) - cosine;
+
+ axis[0]=x;
+ axis[1]=y;
+ axis[2]=z;
+
+ normalizef32(axis); // should require passed in normalized?
+
+ MATRIX_MULT3x3 = cosine + mulf32(one_minus_cosine, mulf32(axis[0], axis[0]));
+ MATRIX_MULT3x3 = mulf32(one_minus_cosine, mulf32(axis[0], axis[1])) - mulf32(axis[2], sine);
+ MATRIX_MULT3x3 = mulf32(mulf32(one_minus_cosine, axis[0]), axis[2]) + mulf32(axis[1], sine);
+
+ MATRIX_MULT3x3 = mulf32(mulf32(one_minus_cosine, axis[0]), axis[1]) + mulf32(axis[2], sine);
+ MATRIX_MULT3x3 = cosine + mulf32(mulf32(one_minus_cosine, axis[1]), axis[1]);
+ MATRIX_MULT3x3 = mulf32(mulf32(one_minus_cosine, axis[1]), axis[2]) - mulf32(axis[0], sine);
+
+ MATRIX_MULT3x3 = mulf32(mulf32(one_minus_cosine, axis[0]), axis[2]) - mulf32(axis[1], sine);
+ MATRIX_MULT3x3 = mulf32(mulf32(one_minus_cosine, axis[1]), axis[2]) + mulf32(axis[0], sine);
+ MATRIX_MULT3x3 = cosine + mulf32(mulf32(one_minus_cosine, axis[2]), axis[2]);
+}
+
+
+
+
+//---------------------------------------------------------------------------------
+void glMaterialf(GL_MATERIALS_ENUM mode, rgb color) {
+//---------------------------------------------------------------------------------
+ static uint32 diffuse_ambient = 0;
+ static uint32 specular_emission = 0;
+
+ switch(mode) {
+ case GL_AMBIENT:
+ diffuse_ambient = (color << 16) | (diffuse_ambient & 0xFFFF);
+ break;
+ case GL_DIFFUSE:
+ diffuse_ambient = color | (diffuse_ambient & 0xFFFF0000);
+ break;
+ case GL_AMBIENT_AND_DIFFUSE:
+ diffuse_ambient= color + (color << 16);
+ break;
+ case GL_SPECULAR:
+ specular_emission = color | (specular_emission & 0xFFFF0000);
+ break;
+ case GL_SHININESS:
+ break;
+ case GL_EMISSION:
+ specular_emission = (color << 16) | (specular_emission & 0xFFFF);
+ break;
+ }
+
+ GFX_DIFFUSE_AMBIENT = diffuse_ambient;
+ GFX_SPECULAR_EMISSION = specular_emission;
+}
+
+//---------------------------------------------------------------------------------
+void glInit_C(void) {
+//---------------------------------------------------------------------------------
+ glGlob = glGetGlobals();
+
+ glGlob->clearColor = 0;
+
+ // init texture globals
+ glGlob->activeTexture = 0;
+ glGlob->nextBlock = (uint32*)0x06800000;
+ glGlob->nextPBlock = 0;
+ glGlob->nameCount = 1;
+
+ while (GFX_STATUS & (1<<27)); // wait till gfx engine is not busy
+
+ // Clear the FIFO
+ GFX_STATUS |= (1<<29);
+
+ // Clear overflows from list memory
+ glResetMatrixStack();
+
+ // prime the vertex/polygon buffers
+ glFlush(0);
+
+ // reset the control bits
+ GFX_CONTROL = 0;
+
+ // reset the rear-plane(a.k.a. clear color) to black, ID=0, and opaque
+ glClearColor(0,0,0,31);
+ glClearPolyID(0);
+
+ // reset stored texture locations
+ glResetTextures();
+
+ // reset the depth to it's max
+ glClearDepth(GL_MAX_DEPTH);
+
+ GFX_TEX_FORMAT = 0;
+ GFX_POLY_FORMAT = 0;
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ glMatrixMode(GL_TEXTURE);
+ glLoadIdentity();
+}
+
+//---------------------------------------------------------------------------------
+void glResetTextures(void) {
+//---------------------------------------------------------------------------------
+ glGlob->activeTexture = 0;
+ glGlob->nextBlock = (uint32*)0x06800000;
+ glGlob->nextPBlock = 0;
+ glGlob->nameCount = 1;
+}
+
+//---------------------------------------------------------------------------------
+// glGenTextures creates integer names for your table
+// takes n as the number of textures to generate and
+// a pointer to the names array that it needs to fill.
+// Returns 1 if succesful and 0 if out of texture names
+//---------------------------------------------------------------------------------
+
+int glGenTextures(int n, int *names) {
+//---------------------------------------------------------------------------------
+ int index = 0;
+ for(index = 0; index < n; index++) {
+ if(glGlob->nameCount >= MAX_TEXTURES)
+ return 0;
+ else
+ names[index] = glGlob->nameCount++;
+ }
+ return 1;
+}
+
+//---------------------------------------------------------------------------------
+// glBindTexure sets the current named
+// texture to the active texture. Target
+// is ignored as all DS textures are 2D
+//---------------------------------------------------------------------------------
+void glBindTexture(int target, int name) {
+//---------------------------------------------------------------------------------
+ if (name == 0)
+ GFX_TEX_FORMAT = 0;
+ else
+ GFX_TEX_FORMAT = glGlob->textures[name];
+
+
+ glGlob->activeTexture = name;
+}
+//---------------------------------------------------------------------------------
+// glColorTable establishes the location of the current palette.
+// Roughly follows glColorTableEXT. Association of palettes with
+// named textures is left to the application.
+//---------------------------------------------------------------------------------
+void glColorTable( uint8 format, uint32 addr ) {
+//---------------------------------------------------------------------------------
+ GFX_PAL_FORMAT = addr>>(4-(format==GL_RGB4));
+}
+
+//---------------------------------------------------------------------------------
+//---------------------------------------------------------------------------------
+void glTexCoord2f32(int32 u, int32 v) {
+//---------------------------------------------------------------------------------
+ int x, y;
+
+ x = ((glGlob->textures[glGlob->activeTexture]) >> 20) & 7;
+ y = ((glGlob->textures[glGlob->activeTexture]) >> 23) & 7;
+
+ glTexCoord2t16(f32tot16 (mulf32(u,inttof32(8<<x))), f32tot16 (mulf32(v,inttof32(8<<y))));
+}
+
+//---------------------------------------------------------------------------------
+// glTexParameter although named the same
+// as its gl counterpart it is not compatible
+// Effort may be made in the future to make it so.
+//---------------------------------------------------------------------------------
+void glTexParameter( uint8 sizeX, uint8 sizeY,
+ const uint32* addr,
+ GL_TEXTURE_TYPE_ENUM mode,
+ uint32 param) {
+//---------------------------------------------------------------------------------
+ glGlob->textures[glGlob->activeTexture] = param | (sizeX << 20) | (sizeY << 23) | (((uint32)addr >> 3) & 0xFFFF) | (mode << 26);
+}
+//---------------------------------------------------------------------------------
+//glGetTexturePointer gets a pointer to vram which contains the texture
+//
+//---------------------------------------------------------------------------------
+void* glGetTexturePointer( int name) {
+//---------------------------------------------------------------------------------
+ return (void*) ((glGlob->textures[name] & 0xFFFF) << 3);
+}
+
+//---------------------------------------------------------------------------------
+u32 glGetTexParameter(){
+//---------------------------------------------------------------------------------
+ return glGlob->textures[glGlob->activeTexture];
+}
+
+
+//---------------------------------------------------------------------------------
+inline uint32 alignVal( uint32 val, uint32 to ) {
+ return (val & (to-1))? (val & ~(to-1)) + to : val;
+}
+
+//---------------------------------------------------------------------------------
+int getNextPaletteSlot(u16 count, uint8 format) {
+//---------------------------------------------------------------------------------
+ // ensure the result aligns on a palette block for this format
+ uint32 result = alignVal(glGlob->nextPBlock, 1<<(4-(format==GL_RGB4)));
+
+ // convert count to bytes and align to next (smallest format) palette block
+ count = alignVal( count<<1, 1<<3 );
+
+ // ensure that end is within palette video mem
+ if( result+count > 0x10000 ) // VRAM_F - VRAM_E
+ return -1;
+
+ glGlob->nextPBlock = result+count;
+ return (int)result;
+}
+
+//---------------------------------------------------------------------------------
+uint16* vramGetBank(uint16 *addr) {
+//---------------------------------------------------------------------------------
+ if(addr >= VRAM_A && addr < VRAM_B)
+ return VRAM_A;
+ else if(addr >= VRAM_B && addr < VRAM_C)
+ return VRAM_B;
+ else if(addr >= VRAM_C && addr < VRAM_D)
+ return VRAM_C;
+ else if(addr >= VRAM_D && addr < VRAM_E)
+ return VRAM_D;
+ else if(addr >= VRAM_E && addr < VRAM_F)
+ return VRAM_E;
+ else if(addr >= VRAM_F && addr < VRAM_G)
+ return VRAM_F;
+ else if(addr >= VRAM_G && addr < VRAM_H)
+ return VRAM_H;
+ else if(addr >= VRAM_H && addr < VRAM_I)
+ return VRAM_H;
+ else return VRAM_I;
+}
+
+
+//---------------------------------------------------------------------------------
+int vramIsTextureBank(uint16 *addr) {
+//---------------------------------------------------------------------------------
+ uint16* vram = vramGetBank(addr);
+
+ if(vram == VRAM_A)
+ {
+ if((VRAM_A_CR & 3) == ((VRAM_A_TEXTURE) & 3))
+ return 1;
+ else return 0;
+ }
+ else if(vram == VRAM_B)
+ {
+ if((VRAM_B_CR & 3) == ((VRAM_B_TEXTURE) & 3))
+ return 1;
+ else return 0;
+ }
+ else if(vram == VRAM_C)
+ {
+ if((VRAM_C_CR & 3) == ((VRAM_C_TEXTURE) & 3))
+ return 1;
+ else return 0;
+ }
+ else if(vram == VRAM_D)
+ {
+ if((VRAM_D_CR & 3) == ((VRAM_D_TEXTURE) & 3))
+ return 1;
+ else return 0;
+ }
+ else
+ return 0;
+}
+//---------------------------------------------------------------------------------
+uint32* getNextTextureSlot(int size) {
+//---------------------------------------------------------------------------------
+ uint32* result = glGlob->nextBlock;
+ glGlob->nextBlock += size >> 2;
+
+ //uh-oh...out of texture memory in this bank...find next one assigned to textures
+ while(!vramIsTextureBank((uint16*)glGlob->nextBlock - 1) && glGlob->nextBlock <= (uint32*)VRAM_E)
+ {
+ glGlob->nextBlock = (uint32*)vramGetBank((uint16*)result) + (0x20000 >> 2); //next bank
+ result = glGlob->nextBlock;
+ glGlob->nextBlock += size >> 2;
+ }
+
+ if(glGlob->nextBlock > (uint32*)VRAM_E) {
+ result = 0;
+ }
+ return result;
+}
+
+//---------------------------------------------------------------------------------
+// Similer to glTextImage2D from gl it takes a pointer to data
+// Empty fields and target are unused but provided for code compatibility.
+// type is simply the texture type (GL_RGB, GL_RGB8 ect...)
+//---------------------------------------------------------------------------------
+int glTexImage2D(int target, int empty1, GL_TEXTURE_TYPE_ENUM type, int sizeX, int sizeY, int empty2, int param, const uint8* texture) {
+//---------------------------------------------------------------------------------
+ uint32 size = 0;
+ uint32* addr;
+ uint32 vramTemp;
+
+ size = 1 << (sizeX + sizeY + 6);
+
+
+ switch (type) {
+ case GL_RGB:
+ case GL_RGBA:
+ size = size << 1;
+ break;
+ case GL_RGB4:
+ size = size >> 2;
+ break;
+ case GL_RGB16:
+ size = size >> 1;
+ break;
+ default:
+ break;
+ }
+
+ addr = getNextTextureSlot(size);
+
+ if(!addr)
+ return 0;
+
+ // unlock texture memory
+ vramTemp = vramSetMainBanks(VRAM_A_LCD,VRAM_B_LCD,VRAM_C_LCD,VRAM_D_LCD);
+
+ if (type == GL_RGB) {
+ // We do GL_RGB as GL_RGBA, but we set each alpha bit to 1 during the copy
+ u16 * src = (u16*)texture;
+ u16 * dest = (u16*)addr;
+
+ glTexParameter(sizeX, sizeY, addr, GL_RGBA, param);
+
+ while (size--) {
+ *dest++ = *src | (1 << 15);
+ src++;
+ }
+ } else {
+ // For everything else, we do a straight copy
+ glTexParameter(sizeX, sizeY, addr, type, param);
+ swiCopy((uint32*)texture, addr , size / 4 | COPY_MODE_WORD);
+ }
+ vramRestoreMainBanks(vramTemp);
+ return 1;
+}
+
+//---------------------------------------------------------------------------------
+void glTexLoadPal(const u16* pal, u16 count, u32 addr) {
+//---------------------------------------------------------------------------------
+ vramSetBankE(VRAM_E_LCD);
+ swiCopy( pal, &VRAM_E[addr>>1] , count / 2 | COPY_MODE_WORD);
+ vramSetBankE(VRAM_E_TEX_PALETTE);
+}
+
+//---------------------------------------------------------------------------------
+int gluTexLoadPal(const u16* pal, u16 count, uint8 format) {
+//---------------------------------------------------------------------------------
+ int addr = getNextPaletteSlot(count, format);
+ if( addr>=0 )
+ glTexLoadPal(pal, count, (u32) addr);
+
+ return addr;
+}
+
+
+
+
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/source/common/card.c b/c/src/lib/libbsp/arm/nds/libnds/source/common/card.c
index 8aad2d93aa..6990380471 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/source/common/card.c
+++ b/c/src/lib/libbsp/arm/nds/libnds/source/common/card.c
@@ -1,394 +1,394 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- Copyright (C) 2005
- Michael Noland (joat)
- Jason Rogers (dovoto)
- Dave Murphy (WinterMute)
-
- 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/card.h"
-#include "nds/dma.h"
-#include "nds/memory.h"
-
-
-//---------------------------------------------------------------------------------
-void cardWriteCommand(const uint8 * command) {
-//---------------------------------------------------------------------------------
- int index;
-
- CARD_CR1H = CARD_CR1_ENABLE | CARD_CR1_IRQ;
-
- for (index = 0; index < 8; index++) {
- CARD_COMMAND[7-index] = command[index];
- }
-}
-
-
-//---------------------------------------------------------------------------------
-void cardPolledTransfer(uint32 flags, uint32 * destination, uint32 length, const uint8 * command) {
-//---------------------------------------------------------------------------------
- u32 data;;
- cardWriteCommand(command);
- CARD_CR2 = flags;
- uint32 * target = destination + length;
- do {
- // Read data if available
- if (CARD_CR2 & CARD_DATA_READY) {
- data=CARD_DATA_RD;
- if (destination < target)
- *destination = data;
- destination++;
- }
- } while (CARD_CR2 & CARD_BUSY);
-}
-
-
-//---------------------------------------------------------------------------------
-void cardStartTransfer(const uint8 * command, uint32 * destination, int channel, uint32 flags) {
-//---------------------------------------------------------------------------------
- cardWriteCommand(command);
-
- // Set up a DMA channel to transfer a word every time the card makes one
- DMA_SRC(channel) = (uint32)&CARD_DATA_RD;
- DMA_DEST(channel) = (uint32)destination;
- DMA_CR(channel) = DMA_ENABLE | DMA_START_CARD | DMA_32_BIT | DMA_REPEAT | DMA_SRC_FIX | 0x0001;;
-
- CARD_CR2 = flags;
-}
-
-
-//---------------------------------------------------------------------------------
-uint32 cardWriteAndRead(const uint8 * command, uint32 flags) {
-//---------------------------------------------------------------------------------
- cardWriteCommand(command);
- CARD_CR2 = flags | CARD_ACTIVATE | CARD_nRESET | 0x07000000;
- while (!(CARD_CR2 & CARD_DATA_READY)) ;
- return CARD_DATA_RD;
-}
-
-
-//---------------------------------------------------------------------------------
-void cardRead00(uint32 address, uint32 * destination, uint32 length, uint32 flags) {
-//---------------------------------------------------------------------------------f
- uint8 command[8];
- command[7] = 0;
- command[6] = (address >> 24) & 0xff;
- command[5] = (address >> 16) & 0xff;
- command[4] = (address >> 8) & 0xff;
- command[3] = address & 0xff;
- command[2] = 0;
- command[1] = 0;
- command[0] = 0;
- cardPolledTransfer(flags, destination, length, command);
-}
-
-
-//---------------------------------------------------------------------------------
-void cardReadHeader(uint8 * header) {
-//---------------------------------------------------------------------------------
- cardRead00(0, (uint32 *)header, 512, 0xA93F1FFF);
-}
-
-
-//---------------------------------------------------------------------------------
-int cardReadID(uint32 flags) {
-//---------------------------------------------------------------------------------
- uint8 command[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90};
- return cardWriteAndRead(command, flags);
-}
-
-
-//---------------------------------------------------------------------------------
-static inline void EepromWaitBusy() {
-//---------------------------------------------------------------------------------
- while (CARD_CR1 & /*BUSY*/0x80);
-}
-
-//---------------------------------------------------------------------------------
-uint8 cardEepromReadID(uint8 i) {
-//---------------------------------------------------------------------------------
- return cardEepromCommand(/*READID*/0xAB, i&1);
-}
-
-//---------------------------------------------------------------------------------
-uint8 cardEepromCommand(uint8 command, uint32 address) {
-//---------------------------------------------------------------------------------
- uint8 retval;
- int k;
- CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40;
-
- CARD_CR1 = 0xFFFF;
- CARD_EEPDATA = command;
-
- EepromWaitBusy();
-
- CARD_EEPDATA = (address >> 16) & 0xFF;
- EepromWaitBusy();
-
- CARD_EEPDATA = (address >> 8) & 0xFF;
- EepromWaitBusy();
-
- CARD_EEPDATA = (address) & 0xFF;
- EepromWaitBusy();
-
- for(k=0;k<256;k++)
- {
- retval = CARD_EEPDATA;
- if(retval!=0xFF)
- break;
- EepromWaitBusy();
- }
-
- CARD_CR1 = /*MODE*/0x40;
- return retval;
-}
-
-//---------------------------------------------------------------------------------
-int cardEepromGetType(void)
-//---------------------------------------------------------------------------------
-{
- uint8 c00;
- uint8 c05;
- uint8 c9f;
- uint8 c03;
-
-#ifdef ARM9
- sysSetBusOwners(BUS_OWNER_ARM9, BUS_OWNER_ARM9);
-#endif
-
- c03=cardEepromCommand(0x03,0);
- c05=cardEepromCommand(0x05,0);
- c9f=cardEepromCommand(0x9f,0);
- c00=cardEepromCommand(0x00,0);
-
- if((c00==0x00) && (c9f==0x00)) return 0; // PassMe?
- if((c00==0xff) && (c05==0xff) && (c9f==0xff))return -1;
-
- if((c00==0xff) && (c05 & 0xFD) == 0xF0 && (c9f==0xff))return 1;
- if((c00==0xff) && (c05 & 0xFD) == 0x00 && (c9f==0xff))return 2;
- if((c00==0xff) && (c05 & 0xFD) == 0x00 && (c9f==0x00))return 3;
- if((c00==0xff) && (c05 & 0xFD) == 0x00 && (c9f==0x12))return 3; // NEW TYPE 3
- if((c00==0xff) && (c05 & 0xFD) == 0x00 && (c9f==0x13))return 3; // NEW TYPE 3+ 4Mbit
- if((c00==0xff) && (c05 & 0xFD) == 0x00 && (c9f==0x14))return 3; // NEW TYPE 3++ 8Mbit MK4-FLASH Memory
-
- return 0;
-}
-
-//---------------------------------------------------------------------------------
-uint32 cardEepromGetSize() {
-//---------------------------------------------------------------------------------
-
- int type = cardEepromGetType();
-
- if(type == -1)
- return 0;
- if(type == 0)
- return 8192;
- if(type == 1)
- return 512;
- if(type == 2) {
- static const uint32 offset0 = (8*1024-1); // 8KB
- static const uint32 offset1 = (2*8*1024-1); // 16KB
- u8 buf1; // +0k data read -> write
- u8 buf2; // +8k data read -> read
- u8 buf3; // +0k ~data write
- u8 buf4; // +8k data new comp buf2
- cardReadEeprom(offset0,&buf1,1,type);
- cardReadEeprom(offset1,&buf2,1,type);
- buf3=~buf1;
- cardWriteEeprom(offset0,&buf3,1,type);
- cardReadEeprom (offset1,&buf4,1,type);
- cardWriteEeprom(offset0,&buf1,1,type);
- if(buf4!=buf2) // +8k
- return 8*1024; // 8KB(64kbit)
- else
- return 64*1024; // 64KB(512kbit)
- }
- if(type == 3) {
- uint8 c9f;
- c9f=cardEepromCommand(0x9f,0);
-
- if(c9f==0x14)
- return 1024*1024; // NEW TYPE 3++ 8Mbit(1024KByte)
-
- if(c9f==0x13)
- return 512*1024; // NEW TYPE 3+ 4Mbit(512KByte)
-
- return 256*1024; // TYPE 3 2Mbit(256KByte)
- }
-
- return 0;
-}
-
-
-//---------------------------------------------------------------------------------
-void cardReadEeprom(uint32 address, uint8 *data, uint32 length, uint32 addrtype) {
-//---------------------------------------------------------------------------------
-
- CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40;
- CARD_EEPDATA = 0x03 | ((addrtype == 1) ? address>>8<<3 : 0);
- EepromWaitBusy();
-
- if (addrtype == 3) {
- CARD_EEPDATA = (address >> 16) & 0xFF;
- EepromWaitBusy();
- }
-
- if (addrtype >= 2) {
- CARD_EEPDATA = (address >> 8) & 0xFF;
- EepromWaitBusy();
- }
-
-
- CARD_EEPDATA = (address) & 0xFF;
- EepromWaitBusy();
-
- while (length > 0) {
- CARD_EEPDATA = 0;
- EepromWaitBusy();
- *data++ = CARD_EEPDATA;
- length--;
- }
-
- EepromWaitBusy();
- CARD_CR1 = /*MODE*/0x40;
-}
-
-
-//---------------------------------------------------------------------------------
-void cardWriteEeprom(uint32 address, uint8 *data, uint32 length, uint32 addrtype) {
-//---------------------------------------------------------------------------------
-
- uint32 address_end = address + length;
- int i;
- int maxblocks = 32;
- if(addrtype == 1) maxblocks = 16;
- if(addrtype == 2) maxblocks = 32;
- if(addrtype == 3) maxblocks = 256;
-
- while (address < address_end) {
- // set WEL (Write Enable Latch)
- CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40;
- CARD_EEPDATA = 0x06; EepromWaitBusy();
- CARD_CR1 = /*MODE*/0x40;
-
- // program maximum of 32 bytes
- CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40;
-
- if(addrtype == 1) {
- // WRITE COMMAND 0x02 + A8 << 3
- CARD_EEPDATA = 0x02 | (address & BIT(8)) >> (8-3) ;
- EepromWaitBusy();
- CARD_EEPDATA = address & 0xFF;
- EepromWaitBusy();
- }
- else if(addrtype == 2) {
- CARD_EEPDATA = 0x02;
- EepromWaitBusy();
- CARD_EEPDATA = address >> 8;
- EepromWaitBusy();
- CARD_EEPDATA = address & 0xFF;
- EepromWaitBusy();
- }
- else if(addrtype == 3) {
- CARD_EEPDATA = 0x02;
- EepromWaitBusy();
- CARD_EEPDATA = (address >> 16) & 0xFF;
- EepromWaitBusy();
- CARD_EEPDATA = (address >> 8) & 0xFF;
- EepromWaitBusy();
- CARD_EEPDATA = address & 0xFF;
- EepromWaitBusy();
- }
-
- for (i=0; address<address_end && i<maxblocks; i++, address++) {
- CARD_EEPDATA = *data++;
- EepromWaitBusy();
- }
- CARD_CR1 = /*MODE*/0x40;
-
- // wait programming to finish
- CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40;
- CARD_EEPDATA = 0x05; EepromWaitBusy();
- do { CARD_EEPDATA = 0; EepromWaitBusy(); } while (CARD_EEPDATA & 0x01); // WIP (Write In Progress) ?
- EepromWaitBusy();
- CARD_CR1 = /*MODE*/0x40;
- }
-}
-
-
-// Chip Erase : clear FLASH MEMORY (TYPE 3 ONLY)
-//---------------------------------------------------------------------------------
-void cardEepromChipErase(void) {
-//---------------------------------------------------------------------------------
- int sz;
- sz=cardEepromGetSize();
- cardEepromSectorErase(0x00000);
- cardEepromSectorErase(0x10000);
- cardEepromSectorErase(0x20000);
- cardEepromSectorErase(0x30000);
- if(sz==512*1024)
- {
- cardEepromSectorErase(0x40000);
- cardEepromSectorErase(0x50000);
- cardEepromSectorErase(0x60000);
- cardEepromSectorErase(0x70000);
- }
-}
-
-// COMMAND Sec.erase 0xD8
-void cardEepromSectorErase(uint32 address)
-{
- // set WEL (Write Enable Latch)
- CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40;
- CARD_EEPDATA = 0x06;
- EepromWaitBusy();
-
- CARD_CR1 = /*MODE*/0x40;
-
- // SectorErase 0xD8
- CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40;
- CARD_EEPDATA = 0xD8;
- EepromWaitBusy();
- CARD_EEPDATA = (address >> 16) & 0xFF;
- EepromWaitBusy();
- CARD_EEPDATA = (address >> 8) & 0xFF;
- EepromWaitBusy();
- CARD_EEPDATA = address & 0xFF;
- EepromWaitBusy();
-
- CARD_CR1 = /*MODE*/0x40;
-
- // wait erase to finish
- CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40;
- CARD_EEPDATA = 0x05;
- EepromWaitBusy();
-
- do
- {
- CARD_EEPDATA = 0;
- EepromWaitBusy();
- } while (CARD_EEPDATA & 0x01); // WIP (Write In Progress) ?
- CARD_CR1 = /*MODE*/0x40;
-}
-
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ Copyright (C) 2005
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ 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/card.h"
+#include "nds/dma.h"
+#include "nds/memory.h"
+
+
+//---------------------------------------------------------------------------------
+void cardWriteCommand(const uint8 * command) {
+//---------------------------------------------------------------------------------
+ int index;
+
+ CARD_CR1H = CARD_CR1_ENABLE | CARD_CR1_IRQ;
+
+ for (index = 0; index < 8; index++) {
+ CARD_COMMAND[7-index] = command[index];
+ }
+}
+
+
+//---------------------------------------------------------------------------------
+void cardPolledTransfer(uint32 flags, uint32 * destination, uint32 length, const uint8 * command) {
+//---------------------------------------------------------------------------------
+ u32 data;;
+ cardWriteCommand(command);
+ CARD_CR2 = flags;
+ uint32 * target = destination + length;
+ do {
+ // Read data if available
+ if (CARD_CR2 & CARD_DATA_READY) {
+ data=CARD_DATA_RD;
+ if (destination < target)
+ *destination = data;
+ destination++;
+ }
+ } while (CARD_CR2 & CARD_BUSY);
+}
+
+
+//---------------------------------------------------------------------------------
+void cardStartTransfer(const uint8 * command, uint32 * destination, int channel, uint32 flags) {
+//---------------------------------------------------------------------------------
+ cardWriteCommand(command);
+
+ // Set up a DMA channel to transfer a word every time the card makes one
+ DMA_SRC(channel) = (uint32)&CARD_DATA_RD;
+ DMA_DEST(channel) = (uint32)destination;
+ DMA_CR(channel) = DMA_ENABLE | DMA_START_CARD | DMA_32_BIT | DMA_REPEAT | DMA_SRC_FIX | 0x0001;;
+
+ CARD_CR2 = flags;
+}
+
+
+//---------------------------------------------------------------------------------
+uint32 cardWriteAndRead(const uint8 * command, uint32 flags) {
+//---------------------------------------------------------------------------------
+ cardWriteCommand(command);
+ CARD_CR2 = flags | CARD_ACTIVATE | CARD_nRESET | 0x07000000;
+ while (!(CARD_CR2 & CARD_DATA_READY)) ;
+ return CARD_DATA_RD;
+}
+
+
+//---------------------------------------------------------------------------------
+void cardRead00(uint32 address, uint32 * destination, uint32 length, uint32 flags) {
+//---------------------------------------------------------------------------------f
+ uint8 command[8];
+ command[7] = 0;
+ command[6] = (address >> 24) & 0xff;
+ command[5] = (address >> 16) & 0xff;
+ command[4] = (address >> 8) & 0xff;
+ command[3] = address & 0xff;
+ command[2] = 0;
+ command[1] = 0;
+ command[0] = 0;
+ cardPolledTransfer(flags, destination, length, command);
+}
+
+
+//---------------------------------------------------------------------------------
+void cardReadHeader(uint8 * header) {
+//---------------------------------------------------------------------------------
+ cardRead00(0, (uint32 *)header, 512, 0xA93F1FFF);
+}
+
+
+//---------------------------------------------------------------------------------
+int cardReadID(uint32 flags) {
+//---------------------------------------------------------------------------------
+ uint8 command[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90};
+ return cardWriteAndRead(command, flags);
+}
+
+
+//---------------------------------------------------------------------------------
+static inline void EepromWaitBusy() {
+//---------------------------------------------------------------------------------
+ while (CARD_CR1 & /*BUSY*/0x80);
+}
+
+//---------------------------------------------------------------------------------
+uint8 cardEepromReadID(uint8 i) {
+//---------------------------------------------------------------------------------
+ return cardEepromCommand(/*READID*/0xAB, i&1);
+}
+
+//---------------------------------------------------------------------------------
+uint8 cardEepromCommand(uint8 command, uint32 address) {
+//---------------------------------------------------------------------------------
+ uint8 retval;
+ int k;
+ CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40;
+
+ CARD_CR1 = 0xFFFF;
+ CARD_EEPDATA = command;
+
+ EepromWaitBusy();
+
+ CARD_EEPDATA = (address >> 16) & 0xFF;
+ EepromWaitBusy();
+
+ CARD_EEPDATA = (address >> 8) & 0xFF;
+ EepromWaitBusy();
+
+ CARD_EEPDATA = (address) & 0xFF;
+ EepromWaitBusy();
+
+ for(k=0;k<256;k++)
+ {
+ retval = CARD_EEPDATA;
+ if(retval!=0xFF)
+ break;
+ EepromWaitBusy();
+ }
+
+ CARD_CR1 = /*MODE*/0x40;
+ return retval;
+}
+
+//---------------------------------------------------------------------------------
+int cardEepromGetType(void)
+//---------------------------------------------------------------------------------
+{
+ uint8 c00;
+ uint8 c05;
+ uint8 c9f;
+ uint8 c03;
+
+#ifdef ARM9
+ sysSetBusOwners(BUS_OWNER_ARM9, BUS_OWNER_ARM9);
+#endif
+
+ c03=cardEepromCommand(0x03,0);
+ c05=cardEepromCommand(0x05,0);
+ c9f=cardEepromCommand(0x9f,0);
+ c00=cardEepromCommand(0x00,0);
+
+ if((c00==0x00) && (c9f==0x00)) return 0; // PassMe?
+ if((c00==0xff) && (c05==0xff) && (c9f==0xff))return -1;
+
+ if((c00==0xff) && (c05 & 0xFD) == 0xF0 && (c9f==0xff))return 1;
+ if((c00==0xff) && (c05 & 0xFD) == 0x00 && (c9f==0xff))return 2;
+ if((c00==0xff) && (c05 & 0xFD) == 0x00 && (c9f==0x00))return 3;
+ if((c00==0xff) && (c05 & 0xFD) == 0x00 && (c9f==0x12))return 3; // NEW TYPE 3
+ if((c00==0xff) && (c05 & 0xFD) == 0x00 && (c9f==0x13))return 3; // NEW TYPE 3+ 4Mbit
+ if((c00==0xff) && (c05 & 0xFD) == 0x00 && (c9f==0x14))return 3; // NEW TYPE 3++ 8Mbit MK4-FLASH Memory
+
+ return 0;
+}
+
+//---------------------------------------------------------------------------------
+uint32 cardEepromGetSize() {
+//---------------------------------------------------------------------------------
+
+ int type = cardEepromGetType();
+
+ if(type == -1)
+ return 0;
+ if(type == 0)
+ return 8192;
+ if(type == 1)
+ return 512;
+ if(type == 2) {
+ static const uint32 offset0 = (8*1024-1); // 8KB
+ static const uint32 offset1 = (2*8*1024-1); // 16KB
+ u8 buf1; // +0k data read -> write
+ u8 buf2; // +8k data read -> read
+ u8 buf3; // +0k ~data write
+ u8 buf4; // +8k data new comp buf2
+ cardReadEeprom(offset0,&buf1,1,type);
+ cardReadEeprom(offset1,&buf2,1,type);
+ buf3=~buf1;
+ cardWriteEeprom(offset0,&buf3,1,type);
+ cardReadEeprom (offset1,&buf4,1,type);
+ cardWriteEeprom(offset0,&buf1,1,type);
+ if(buf4!=buf2) // +8k
+ return 8*1024; // 8KB(64kbit)
+ else
+ return 64*1024; // 64KB(512kbit)
+ }
+ if(type == 3) {
+ uint8 c9f;
+ c9f=cardEepromCommand(0x9f,0);
+
+ if(c9f==0x14)
+ return 1024*1024; // NEW TYPE 3++ 8Mbit(1024KByte)
+
+ if(c9f==0x13)
+ return 512*1024; // NEW TYPE 3+ 4Mbit(512KByte)
+
+ return 256*1024; // TYPE 3 2Mbit(256KByte)
+ }
+
+ return 0;
+}
+
+
+//---------------------------------------------------------------------------------
+void cardReadEeprom(uint32 address, uint8 *data, uint32 length, uint32 addrtype) {
+//---------------------------------------------------------------------------------
+
+ CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40;
+ CARD_EEPDATA = 0x03 | ((addrtype == 1) ? address>>8<<3 : 0);
+ EepromWaitBusy();
+
+ if (addrtype == 3) {
+ CARD_EEPDATA = (address >> 16) & 0xFF;
+ EepromWaitBusy();
+ }
+
+ if (addrtype >= 2) {
+ CARD_EEPDATA = (address >> 8) & 0xFF;
+ EepromWaitBusy();
+ }
+
+
+ CARD_EEPDATA = (address) & 0xFF;
+ EepromWaitBusy();
+
+ while (length > 0) {
+ CARD_EEPDATA = 0;
+ EepromWaitBusy();
+ *data++ = CARD_EEPDATA;
+ length--;
+ }
+
+ EepromWaitBusy();
+ CARD_CR1 = /*MODE*/0x40;
+}
+
+
+//---------------------------------------------------------------------------------
+void cardWriteEeprom(uint32 address, uint8 *data, uint32 length, uint32 addrtype) {
+//---------------------------------------------------------------------------------
+
+ uint32 address_end = address + length;
+ int i;
+ int maxblocks = 32;
+ if(addrtype == 1) maxblocks = 16;
+ if(addrtype == 2) maxblocks = 32;
+ if(addrtype == 3) maxblocks = 256;
+
+ while (address < address_end) {
+ // set WEL (Write Enable Latch)
+ CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40;
+ CARD_EEPDATA = 0x06; EepromWaitBusy();
+ CARD_CR1 = /*MODE*/0x40;
+
+ // program maximum of 32 bytes
+ CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40;
+
+ if(addrtype == 1) {
+ // WRITE COMMAND 0x02 + A8 << 3
+ CARD_EEPDATA = 0x02 | (address & BIT(8)) >> (8-3) ;
+ EepromWaitBusy();
+ CARD_EEPDATA = address & 0xFF;
+ EepromWaitBusy();
+ }
+ else if(addrtype == 2) {
+ CARD_EEPDATA = 0x02;
+ EepromWaitBusy();
+ CARD_EEPDATA = address >> 8;
+ EepromWaitBusy();
+ CARD_EEPDATA = address & 0xFF;
+ EepromWaitBusy();
+ }
+ else if(addrtype == 3) {
+ CARD_EEPDATA = 0x02;
+ EepromWaitBusy();
+ CARD_EEPDATA = (address >> 16) & 0xFF;
+ EepromWaitBusy();
+ CARD_EEPDATA = (address >> 8) & 0xFF;
+ EepromWaitBusy();
+ CARD_EEPDATA = address & 0xFF;
+ EepromWaitBusy();
+ }
+
+ for (i=0; address<address_end && i<maxblocks; i++, address++) {
+ CARD_EEPDATA = *data++;
+ EepromWaitBusy();
+ }
+ CARD_CR1 = /*MODE*/0x40;
+
+ // wait programming to finish
+ CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40;
+ CARD_EEPDATA = 0x05; EepromWaitBusy();
+ do { CARD_EEPDATA = 0; EepromWaitBusy(); } while (CARD_EEPDATA & 0x01); // WIP (Write In Progress) ?
+ EepromWaitBusy();
+ CARD_CR1 = /*MODE*/0x40;
+ }
+}
+
+
+// Chip Erase : clear FLASH MEMORY (TYPE 3 ONLY)
+//---------------------------------------------------------------------------------
+void cardEepromChipErase(void) {
+//---------------------------------------------------------------------------------
+ int sz;
+ sz=cardEepromGetSize();
+ cardEepromSectorErase(0x00000);
+ cardEepromSectorErase(0x10000);
+ cardEepromSectorErase(0x20000);
+ cardEepromSectorErase(0x30000);
+ if(sz==512*1024)
+ {
+ cardEepromSectorErase(0x40000);
+ cardEepromSectorErase(0x50000);
+ cardEepromSectorErase(0x60000);
+ cardEepromSectorErase(0x70000);
+ }
+}
+
+// COMMAND Sec.erase 0xD8
+void cardEepromSectorErase(uint32 address)
+{
+ // set WEL (Write Enable Latch)
+ CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40;
+ CARD_EEPDATA = 0x06;
+ EepromWaitBusy();
+
+ CARD_CR1 = /*MODE*/0x40;
+
+ // SectorErase 0xD8
+ CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40;
+ CARD_EEPDATA = 0xD8;
+ EepromWaitBusy();
+ CARD_EEPDATA = (address >> 16) & 0xFF;
+ EepromWaitBusy();
+ CARD_EEPDATA = (address >> 8) & 0xFF;
+ EepromWaitBusy();
+ CARD_EEPDATA = address & 0xFF;
+ EepromWaitBusy();
+
+ CARD_CR1 = /*MODE*/0x40;
+
+ // wait erase to finish
+ CARD_CR1 = /*E*/0x8000 | /*SEL*/0x2000 | /*MODE*/0x40;
+ CARD_EEPDATA = 0x05;
+ EepromWaitBusy();
+
+ do
+ {
+ CARD_EEPDATA = 0;
+ EepromWaitBusy();
+ } while (CARD_EEPDATA & 0x01); // WIP (Write In Progress) ?
+ CARD_CR1 = /*MODE*/0x40;
+}
+
+
diff --git a/c/src/lib/libbsp/arm/nds/libnds/source/common/interruptDispatcher.S b/c/src/lib/libbsp/arm/nds/libnds/source/common/interruptDispatcher.S
index 4ef656f132..c971bb3b20 100644
--- a/c/src/lib/libbsp/arm/nds/libnds/source/common/interruptDispatcher.S
+++ b/c/src/lib/libbsp/arm/nds/libnds/source/common/interruptDispatcher.S
@@ -1,27 +1,45 @@
-/*---------------------------------------------------------------------------------
- $Id$
-
- Copyright (C) 2005
- Dave Murphy (WinterMute)
-
- 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.
-
+/*---------------------------------------------------------------------------------
+ $Id$
+
+ Copyright (C) 2005
+ Dave Murphy (WinterMute)
+
+ 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.
+
$Log$
+ Revision 1.1 2008/04/17 23:09:41 joel
+ 2008-04-17 Joel Sherrill <joel.sherrill@OARcorp.com>
+
+ * Makefile.am: Move .s files to .S
+ * dswifi/common/source/spinlock.S, libfat/source/disc_io/io_dldi.S,
+ libfat/source/disc_io/io_scsd_s.S, libnds/source/arm9/COS.S,
+ libnds/source/arm9/SIN.S, libnds/source/arm9/TAN.S,
+ libnds/source/arm9/dcache.S, libnds/source/arm9/default_font.S,
+ libnds/source/arm9/icache.S, libnds/source/common/biosCalls.S,
+ libnds/source/common/interruptDispatcher.S: New files.
+ * dswifi/common/source/spinlock.s, libfat/source/disc_io/io_dldi.s,
+ libfat/source/disc_io/io_scsd_s.s, libnds/source/arm9/COS.s,
+ libnds/source/arm9/SIN.s, libnds/source/arm9/TAN.s,
+ libnds/source/arm9/dcache.s, libnds/source/arm9/default_font.s,
+ libnds/source/arm9/exceptionHandler.s, libnds/source/arm9/icache.s,
+ libnds/source/common/biosCalls.s,
+ libnds/source/common/interruptDispatcher.s: Removed.
+
Revision 1.1 2008/04/16 18:37:33 joel
2008-04-16 Matthieu Bucchianeri <mbucchia@gmail.com>
@@ -159,132 +177,132 @@
touchscreen/reco.h, touchscreen/touchscreen.c,
touchscreen/touchscreen.h, wifi/compat.c, wifi/compat.h, wifi/wifi.c:
New files.
-
- Revision 1.10 2007/08/11 06:00:23 wntrmute
- make nesting really work
-
- Revision 1.9 2007/01/10 15:48:27 wntrmute
- remove unused code
-
- Revision 1.8 2006/12/16 09:10:02 wntrmute
- acknowledge interrupt before calling handler
-
- Revision 1.7 2006/04/26 05:11:31 wntrmute
- rebase dtcm, take __irq_flags and __irq_vector from linker script
- move arm7 irq vector & irq flags to actual locations
-
- Revision 1.6 2006/04/23 18:19:15 wntrmute
- reworked interrupt code to allow dtcm moving
-
- Revision 1.5 2005/12/12 13:01:55 wntrmute
- disable interrupts on return from user handler
-
- Revision 1.4 2005/10/21 22:43:42 wntrmute
- restore REG_IME on exit from null handler
-
- Revision 1.3 2005/09/27 18:21:53 wntrmute
- safer nested interrupt support
-
- Revision 1.2 2005/09/04 16:37:01 wntrmute
- check for NULL handler
-
- Revision 1.1 2005/09/03 17:09:35 wntrmute
- added interworking aware interrupt dispatcher
-
-
----------------------------------------------------------------------------------*/
-
-#ifdef ARM7
- .text
-#endif
-
-#ifdef ARM9
- .section .itcm,"ax",%progbits
-#endif
-
- .extern irqTable
- .code 32
-
- .global IntrMain
-@---------------------------------------------------------------------------------
-IntrMain:
-@---------------------------------------------------------------------------------
- mov r3, #0x4000000 @ REG_BASE
-
- ldr r1, [r3, #0x208] @ r1 = IME
- str r3, [r3, #0x208] @ disable IME
- mrs r0, spsr
- stmfd sp!, {r0-r1,r3,lr} @ {spsr, IME, REG_BASE, lr_irq}
-
- ldr r1, [r3,#0x210] @ REG_IE
- ldr r2, [r3,#0x214] @ REG_IF
- and r1,r1,r2
-
- ldr r0,=__irq_flags @ defined by linker script
-
- ldr r2,[r0]
- orr r2,r2,r1
- str r2,[r0]
-
- ldr r2,=irqTable
-@---------------------------------------------------------------------------------
-findIRQ:
-@---------------------------------------------------------------------------------
- ldr r0, [r2, #4]
- cmp r0,#0
- beq no_handler
- ands r0, r0, r1
- bne jump_intr
- add r2, r2, #8
- b findIRQ
-
-@---------------------------------------------------------------------------------
-no_handler:
-@---------------------------------------------------------------------------------
- str r1, [r3, #0x0214] @ IF Clear
- ldmfd sp!, {r0-r1,r3,lr} @ {spsr, IME, REG_BASE, lr_irq}
- str r1, [r3, #0x208] @ restore REG_IME
- mov pc,lr
-
-@---------------------------------------------------------------------------------
-jump_intr:
-@---------------------------------------------------------------------------------
- ldr r1, [r2] @ user IRQ handler address
- cmp r1, #0
- bne got_handler
- mov r1, r0
- b no_handler
-@---------------------------------------------------------------------------------
-got_handler:
-@---------------------------------------------------------------------------------
-
- mrs r2, cpsr
- bic r2, r2, #0xdf @ \__
- orr r2, r2, #0x1f @ / --> Enable IRQ & FIQ. Set CPU mode to System.
- msr cpsr,r2
-
- str r0, [r3, #0x0214] @ IF Clear
-
- push {lr}
- adr lr, IntrRet
- bx r1
-
-@---------------------------------------------------------------------------------
-IntrRet:
-@---------------------------------------------------------------------------------
- mov r3, #0x4000000 @ REG_BASE
- str r3, [r3, #0x208] @ disable IME
- pop {lr}
-
- mrs r3, cpsr
- bic r3, r3, #0xdf @ \__
- orr r3, r3, #0x92 @ / --> Disable IRQ. Enable FIQ. Set CPU mode to IRQ.
- msr cpsr, r3
-
- ldmfd sp!, {r0-r1,r3,lr} @ {spsr, IME, REG_BASE, lr_irq}
- msr spsr, r0 @ restore spsr
- str r1, [r3, #0x208] @ restore REG_IME
- mov pc,lr
-
- .pool
- .end
+
+ Revision 1.10 2007/08/11 06:00:23 wntrmute
+ make nesting really work
+
+ Revision 1.9 2007/01/10 15:48:27 wntrmute
+ remove unused code
+
+ Revision 1.8 2006/12/16 09:10:02 wntrmute
+ acknowledge interrupt before calling handler
+
+ Revision 1.7 2006/04/26 05:11:31 wntrmute
+ rebase dtcm, take __irq_flags and __irq_vector from linker script
+ move arm7 irq vector & irq flags to actual locations
+
+ Revision 1.6 2006/04/23 18:19:15 wntrmute
+ reworked interrupt code to allow dtcm moving
+
+ Revision 1.5 2005/12/12 13:01:55 wntrmute
+ disable interrupts on return from user handler
+
+ Revision 1.4 2005/10/21 22:43:42 wntrmute
+ restore REG_IME on exit from null handler
+
+ Revision 1.3 2005/09/27 18:21:53 wntrmute
+ safer nested interrupt support
+
+ Revision 1.2 2005/09/04 16:37:01 wntrmute
+ check for NULL handler
+
+ Revision 1.1 2005/09/03 17:09:35 wntrmute
+ added interworking aware interrupt dispatcher
+
+
+---------------------------------------------------------------------------------*/
+
+#ifdef ARM7
+ .text
+#endif
+
+#ifdef ARM9
+ .section .itcm,"ax",%progbits
+#endif
+
+ .extern irqTable
+ .code 32
+
+ .global IntrMain
+@---------------------------------------------------------------------------------
+IntrMain:
+@---------------------------------------------------------------------------------
+ mov r3, #0x4000000 @ REG_BASE
+
+ ldr r1, [r3, #0x208] @ r1 = IME
+ str r3, [r3, #0x208] @ disable IME
+ mrs r0, spsr
+ stmfd sp!, {r0-r1,r3,lr} @ {spsr, IME, REG_BASE, lr_irq}
+
+ ldr r1, [r3,#0x210] @ REG_IE
+ ldr r2, [r3,#0x214] @ REG_IF
+ and r1,r1,r2
+
+ ldr r0,=__irq_flags @ defined by linker script
+
+ ldr r2,[r0]
+ orr r2,r2,r1
+ str r2,[r0]
+
+ ldr r2,=irqTable
+@---------------------------------------------------------------------------------
+findIRQ:
+@---------------------------------------------------------------------------------
+ ldr r0, [r2, #4]
+ cmp r0,#0
+ beq no_handler
+ ands r0, r0, r1
+ bne jump_intr
+ add r2, r2, #8
+ b findIRQ
+
+@---------------------------------------------------------------------------------
+no_handler:
+@---------------------------------------------------------------------------------
+ str r1, [r3, #0x0214] @ IF Clear
+ ldmfd sp!, {r0-r1,r3,lr} @ {spsr, IME, REG_BASE, lr_irq}
+ str r1, [r3, #0x208] @ restore REG_IME
+ mov pc,lr
+
+@---------------------------------------------------------------------------------
+jump_intr:
+@---------------------------------------------------------------------------------
+ ldr r1, [r2] @ user IRQ handler address
+ cmp r1, #0
+ bne got_handler
+ mov r1, r0
+ b no_handler
+@---------------------------------------------------------------------------------
+got_handler:
+@---------------------------------------------------------------------------------
+
+ mrs r2, cpsr
+ bic r2, r2, #0xdf @ \__
+ orr r2, r2, #0x1f @ / --> Enable IRQ & FIQ. Set CPU mode to System.
+ msr cpsr,r2
+
+ str r0, [r3, #0x0214] @ IF Clear
+
+ push {lr}
+ adr lr, IntrRet
+ bx r1
+
+@---------------------------------------------------------------------------------
+IntrRet:
+@---------------------------------------------------------------------------------
+ mov r3, #0x4000000 @ REG_BASE
+ str r3, [r3, #0x208] @ disable IME
+ pop {lr}
+
+ mrs r3, cpsr
+ bic r3, r3, #0xdf @ \__
+ orr r3, r3, #0x92 @ / --> Disable IRQ. Enable FIQ. Set CPU mode to IRQ.
+ msr cpsr, r3
+
+ ldmfd sp!, {r0-r1,r3,lr} @ {spsr, IME, REG_BASE, lr_irq}
+ msr spsr, r0 @ restore spsr
+ str r1, [r3, #0x208] @ restore REG_IME
+ mov pc,lr
+
+ .pool
+ .end
diff --git a/c/src/lib/libbsp/arm/nds/touchscreen/reco.c b/c/src/lib/libbsp/arm/nds/touchscreen/reco.c
index 231c1a2c81..2ebf3c89a4 100644
--- a/c/src/lib/libbsp/arm/nds/touchscreen/reco.c
+++ b/c/src/lib/libbsp/arm/nds/touchscreen/reco.c
@@ -1,239 +1,239 @@
-
-#include <nds.h>
-#include "reco.h"
-
-PA_StylusPosition PA_StylusPos[20000];
-
-PA_RecoValues PA_Reco;
-
-char PA_RecoShape[16];
-
-u8 PA_UseGraffiti = true;
-
-u8 PA_CustomReco = 0; // number of custom shapes
-PA_FormType PA_CustomShape[200];
-
-PA_RecoInfos PA_RecoInfo;
-
-PA_FormType PA_Graffiti[PA_RECOTESTS] = {
- {' ', "AAAAAAAAAAAAAAA"},
- {'a', "FGGGGGFB;:;;;;;"},
- {'b', "JJJJJIGC>:8=<62"},
- {'c', "01234689;<>?@BC"},
- {'d', "=995KJIFB?=;853"},
- {'e', "1236;>@136;=?@A"},
- {'f', "121111399998779"},
- {'g', "235689;=@CFIJEA"},
- {'h', "8999999;HFEA><:"},
- {'i', "999999999999999"},
- {'j', "999999998653100"},
- {'k', "654320NIDCA?==="},
- {'l', "999999988<AA@@@"},
- {'m', "HGGEA<;EFDA=;99"},
- {'n', "HHHIE<;;;<GIHHH"},
- {'o', "4689;<?BDFHKMO0"},
- {'p', "<KJIIIHGEB>;853"},
- {'q', "4679<?CDFHKMJBA"},
- {'r', "999IIIIGC?:53<="},
- {'s', "0235:>?>>;73100"},
- {'t', "AAAA@@@;8999999"},
- {'u', "899:;<>ACEGHHIH"},
- {'v', ";;:::::?FGGHHGF"},
- {'w', "::;=BA<<@CDEFGH"},
- {'x', ";;;;;;;;;;;;;;;"},
- {'y', ">;=AFF899974OIF"},
- {'z', ">A@@>843348?@AA"},
- {'0', "35789;=AEGHIJKM"},
- {'1', "CDEFFE988889999"},
- {'2', "GDB@>:6546>AAAA"},
- {'3', "CA>833A@=953210"},
- {'4', "55558>@A@>97778"},
- {'5', "00037:@@=;7310O"},
- {'6', "346779;>@CFKN02"},
- {'7', "AAAAAA@>9655556"},
- {'8', "37;=;71MIECCGM1"},
- {'9', "8<@CGL28<<;6311"},
- {PA_BACKSPACE, "000000000000000"},
- {PA_ENTER, "555555555555555"},
- // {'?', "FCA@><8655799::"},
- {'.', "LLLLLLLLLLLLLLL"}
-};
-
-
-
-void PA_AddStylusPos(u8 x, u8 y){
- if (!((x == PA_StylusPos[PA_Reco.nvalues-1].x) && (y == PA_StylusPos[PA_Reco.nvalues-1].y))){
- PA_StylusPos[PA_Reco.nvalues].x = x;
- PA_StylusPos[PA_Reco.nvalues].y = y;
- PA_Reco.nvalues++;
- }
-}
-
-
-void PA_StylusLine(u8 x1, u8 y1, u8 x2, u8 y2){
- int i,dx,dy,sdx,sdy,dxabs,dyabs,x,y,px,py;
-
- dx=x2-x1; /* the horizontal distance of the line */
- dy=y2-y1; /* the vertical distance of the line */
- dxabs = dx;
- sdx = 1;
- if (dx < 0) {
- dxabs = -dx;
- sdx = -1;
- }
- dyabs = dy;
- sdy = 1;
- if (dy < 0) {
- dyabs = -dy;
- sdy = -1;
- }
-
- x=dyabs>>1;
- y=dxabs>>1;
- px=x1;
- py=y1;
-
- PA_AddStylusPos(px, py);
-
-
- if (dxabs>=dyabs) {
- for(i=0;i<dxabs;i++) {
- y+=dyabs;
- if (y>=dxabs) {
- y-=dxabs;
- py+=sdy;
- }
- px+=sdx;
- PA_AddStylusPos(px, py);
- }
- }
- else {
- for(i=0;i<dyabs;i++) {
- x+=dxabs;
- if (x>=dyabs) {
- x-=dyabs;
- px+=sdx;
- }
- py+=sdy;
- PA_AddStylusPos(px, py);
- }
- }
-}
-
-
-#define PA_ShapeAddPoint(i, value){ \
- points[i] = PA_StylusPos[value]; \
- if (points[i].x < PA_RecoInfo.minX) PA_RecoInfo.minX = points[i].x; \
- else if (points[i].x > PA_RecoInfo.maxX) PA_RecoInfo.maxX = points[i].x; \
- if (points[i].y < PA_RecoInfo.minY) PA_RecoInfo.minY = points[i].y; \
- else if (points[i].y > PA_RecoInfo.maxY) PA_RecoInfo.maxY = points[i].y; }
-
-
-
-
-char PA_AnalyzeShape(void){
- s32 i;
- // for (i = 0; i < 32; i++) PA_OutputSimpleText(1, 0, i, " ");
-
- PA_StylusPosition points[17];
- for (i = 0; i < 16; i++){
- PA_ShapeAddPoint(i, (PA_Reco.nvalues*i)>>4)
- }
- PA_ShapeAddPoint(16, PA_Reco.nvalues-1)
- //points[16] = PA_StylusPos[PA_Reco.nvalues-1];
- PA_RecoInfo.endX = PA_StylusPos[PA_Reco.nvalues-1].x; // last values
- PA_RecoInfo.endY = PA_StylusPos[PA_Reco.nvalues-1].y; // last values
- PA_RecoInfo.Length = PA_Reco.nvalues; // Total length
- PA_RecoInfo.Angle = PA_GetAngle(points[0].x, points[0].y, points[16].x, points[16].y);
-
- //Better values
- if (PA_RecoInfo.minX > 1) PA_RecoInfo.minX-=2;
- if (PA_RecoInfo.maxX <254) PA_RecoInfo.maxX+=2;
- if (PA_RecoInfo.minY > 1) PA_RecoInfo.minY-=2;
- if (PA_RecoInfo.maxY <190) PA_RecoInfo.maxY+=2;
-
- u16 angles[15];
- for (i = 0; i < 15; i++) angles[i] = PA_GetAngle(points[i+2].x, points[i+2].y, points[i].x, points[i].y);
-
- for (i = 0; i < 15; i++) PA_RecoShape[i] = '0' + (((angles[i]+16)&511)>>4);
- PA_RecoShape[15] = 0;
- // printk("%s\n", PA_RecoShape);
-
- u8 letter = 0; // 0 par défaut
- s32 diff = 65000; // Diff max par défaut
-
- u8 j;
-
- if(PA_UseGraffiti){
- for (j = 0; j < PA_RECOTESTS; j++){
- s32 tempvalue = 0;
- s32 tempdiff = 0;
- for (i = 0; i < 15; i++) {
- tempvalue = (PA_RecoShape[i]-PA_Graffiti[j].code[i])&31;
- tempvalue -= (tempvalue >> 4)<<5; // normalise
- if (tempvalue < 0) tempvalue = -tempvalue;
- tempdiff += tempvalue; // value
- }
-
- if (tempdiff < diff){ // Nouvelle lettre !
- diff = tempdiff;
- letter = PA_Graffiti[j].letter;
- }
- }
- }
- if (PA_CustomReco > 0){
- for (j = 0; j < PA_CustomReco; j++){
- s32 tempvalue = 0;
- s32 tempdiff = 0;
- for (i = 0; i < 15; i++) {
- tempvalue = (PA_RecoShape[i]-PA_CustomShape[j].code[i])&31;
- tempvalue -= (tempvalue >> 4)<<5; // normalise
- if (tempvalue < 0) tempvalue = -tempvalue;
- tempdiff += tempvalue; // value
- }
-
- if (tempdiff < diff){ // Nouvelle lettre !
- diff = tempdiff;
- letter = PA_CustomShape[j].letter;
- }
- }
-
- }
- PA_RecoInfo.Difference = diff; // Difference to perfect shape
- PA_RecoInfo.Shape = letter;
-
- return letter;
-}
-
-int old_down = 0;
-
-char PA_CheckLetter(int down, int x, int y){
- if(!old_down && down){
- PA_Reco.nvalues = 0; // Start over again
- PA_Reco.oldn = 0;
- PA_Reco.veryold = 0;
-
- PA_RecoInfo.startX = PA_StylusPos[PA_Reco.nvalues].x = x; // start values
- PA_RecoInfo.startY = PA_StylusPos[PA_Reco.nvalues].y = y;
- PA_RecoInfo.minX = PA_RecoInfo.maxX = PA_RecoInfo.startX;
- PA_RecoInfo.minY = PA_RecoInfo.maxY = PA_RecoInfo.startY;
- PA_Reco.nvalues++;
- }
- else if(old_down && down) {
- PA_StylusLine(PA_StylusPos[PA_Reco.nvalues-1].x, PA_StylusPos[PA_Reco.nvalues-1].y, x, y);
-
- }
-
-
- if(old_down && !down){ // Start analyzing...
- PA_Reco.nvalues = PA_Reco.veryold;
- old_down = down;
- return PA_AnalyzeShape();
- }
- PA_Reco.veryold = PA_Reco.oldn;
- PA_Reco.oldn = PA_Reco.nvalues;
- old_down = down;
- return 0;
-}
-
-
+
+#include <nds.h>
+#include "reco.h"
+
+PA_StylusPosition PA_StylusPos[20000];
+
+PA_RecoValues PA_Reco;
+
+char PA_RecoShape[16];
+
+u8 PA_UseGraffiti = true;
+
+u8 PA_CustomReco = 0; // number of custom shapes
+PA_FormType PA_CustomShape[200];
+
+PA_RecoInfos PA_RecoInfo;
+
+PA_FormType PA_Graffiti[PA_RECOTESTS] = {
+ {' ', "AAAAAAAAAAAAAAA"},
+ {'a', "FGGGGGFB;:;;;;;"},
+ {'b', "JJJJJIGC>:8=<62"},
+ {'c', "01234689;<>?@BC"},
+ {'d', "=995KJIFB?=;853"},
+ {'e', "1236;>@136;=?@A"},
+ {'f', "121111399998779"},
+ {'g', "235689;=@CFIJEA"},
+ {'h', "8999999;HFEA><:"},
+ {'i', "999999999999999"},
+ {'j', "999999998653100"},
+ {'k', "654320NIDCA?==="},
+ {'l', "999999988<AA@@@"},
+ {'m', "HGGEA<;EFDA=;99"},
+ {'n', "HHHIE<;;;<GIHHH"},
+ {'o', "4689;<?BDFHKMO0"},
+ {'p', "<KJIIIHGEB>;853"},
+ {'q', "4679<?CDFHKMJBA"},
+ {'r', "999IIIIGC?:53<="},
+ {'s', "0235:>?>>;73100"},
+ {'t', "AAAA@@@;8999999"},
+ {'u', "899:;<>ACEGHHIH"},
+ {'v', ";;:::::?FGGHHGF"},
+ {'w', "::;=BA<<@CDEFGH"},
+ {'x', ";;;;;;;;;;;;;;;"},
+ {'y', ">;=AFF899974OIF"},
+ {'z', ">A@@>843348?@AA"},
+ {'0', "35789;=AEGHIJKM"},
+ {'1', "CDEFFE988889999"},
+ {'2', "GDB@>:6546>AAAA"},
+ {'3', "CA>833A@=953210"},
+ {'4', "55558>@A@>97778"},
+ {'5', "00037:@@=;7310O"},
+ {'6', "346779;>@CFKN02"},
+ {'7', "AAAAAA@>9655556"},
+ {'8', "37;=;71MIECCGM1"},
+ {'9', "8<@CGL28<<;6311"},
+ {PA_BACKSPACE, "000000000000000"},
+ {PA_ENTER, "555555555555555"},
+ // {'?', "FCA@><8655799::"},
+ {'.', "LLLLLLLLLLLLLLL"}
+};
+
+
+
+void PA_AddStylusPos(u8 x, u8 y){
+ if (!((x == PA_StylusPos[PA_Reco.nvalues-1].x) && (y == PA_StylusPos[PA_Reco.nvalues-1].y))){
+ PA_StylusPos[PA_Reco.nvalues].x = x;
+ PA_StylusPos[PA_Reco.nvalues].y = y;
+ PA_Reco.nvalues++;
+ }
+}
+
+
+void PA_StylusLine(u8 x1, u8 y1, u8 x2, u8 y2){
+ int i,dx,dy,sdx,sdy,dxabs,dyabs,x,y,px,py;
+
+ dx=x2-x1; /* the horizontal distance of the line */
+ dy=y2-y1; /* the vertical distance of the line */
+ dxabs = dx;
+ sdx = 1;
+ if (dx < 0) {
+ dxabs = -dx;
+ sdx = -1;
+ }
+ dyabs = dy;
+ sdy = 1;
+ if (dy < 0) {
+ dyabs = -dy;
+ sdy = -1;
+ }
+
+ x=dyabs>>1;
+ y=dxabs>>1;
+ px=x1;
+ py=y1;
+
+ PA_AddStylusPos(px, py);
+
+
+ if (dxabs>=dyabs) {
+ for(i=0;i<dxabs;i++) {
+ y+=dyabs;
+ if (y>=dxabs) {
+ y-=dxabs;
+ py+=sdy;
+ }
+ px+=sdx;
+ PA_AddStylusPos(px, py);
+ }
+ }
+ else {
+ for(i=0;i<dyabs;i++) {
+ x+=dxabs;
+ if (x>=dyabs) {
+ x-=dyabs;
+ px+=sdx;
+ }
+ py+=sdy;
+ PA_AddStylusPos(px, py);
+ }
+ }
+}
+
+
+#define PA_ShapeAddPoint(i, value){ \
+ points[i] = PA_StylusPos[value]; \
+ if (points[i].x < PA_RecoInfo.minX) PA_RecoInfo.minX = points[i].x; \
+ else if (points[i].x > PA_RecoInfo.maxX) PA_RecoInfo.maxX = points[i].x; \
+ if (points[i].y < PA_RecoInfo.minY) PA_RecoInfo.minY = points[i].y; \
+ else if (points[i].y > PA_RecoInfo.maxY) PA_RecoInfo.maxY = points[i].y; }
+
+
+
+
+char PA_AnalyzeShape(void){
+ s32 i;
+ // for (i = 0; i < 32; i++) PA_OutputSimpleText(1, 0, i, " ");
+
+ PA_StylusPosition points[17];
+ for (i = 0; i < 16; i++){
+ PA_ShapeAddPoint(i, (PA_Reco.nvalues*i)>>4)
+ }
+ PA_ShapeAddPoint(16, PA_Reco.nvalues-1)
+ //points[16] = PA_StylusPos[PA_Reco.nvalues-1];
+ PA_RecoInfo.endX = PA_StylusPos[PA_Reco.nvalues-1].x; // last values
+ PA_RecoInfo.endY = PA_StylusPos[PA_Reco.nvalues-1].y; // last values
+ PA_RecoInfo.Length = PA_Reco.nvalues; // Total length
+ PA_RecoInfo.Angle = PA_GetAngle(points[0].x, points[0].y, points[16].x, points[16].y);
+
+ //Better values
+ if (PA_RecoInfo.minX > 1) PA_RecoInfo.minX-=2;
+ if (PA_RecoInfo.maxX <254) PA_RecoInfo.maxX+=2;
+ if (PA_RecoInfo.minY > 1) PA_RecoInfo.minY-=2;
+ if (PA_RecoInfo.maxY <190) PA_RecoInfo.maxY+=2;
+
+ u16 angles[15];
+ for (i = 0; i < 15; i++) angles[i] = PA_GetAngle(points[i+2].x, points[i+2].y, points[i].x, points[i].y);
+
+ for (i = 0; i < 15; i++) PA_RecoShape[i] = '0' + (((angles[i]+16)&511)>>4);
+ PA_RecoShape[15] = 0;
+ // printk("%s\n", PA_RecoShape);
+
+ u8 letter = 0; // 0 par défaut
+ s32 diff = 65000; // Diff max par défaut
+
+ u8 j;
+
+ if(PA_UseGraffiti){
+ for (j = 0; j < PA_RECOTESTS; j++){
+ s32 tempvalue = 0;
+ s32 tempdiff = 0;
+ for (i = 0; i < 15; i++) {
+ tempvalue = (PA_RecoShape[i]-PA_Graffiti[j].code[i])&31;
+ tempvalue -= (tempvalue >> 4)<<5; // normalise
+ if (tempvalue < 0) tempvalue = -tempvalue;
+ tempdiff += tempvalue; // value
+ }
+
+ if (tempdiff < diff){ // Nouvelle lettre !
+ diff = tempdiff;
+ letter = PA_Graffiti[j].letter;
+ }
+ }
+ }
+ if (PA_CustomReco > 0){
+ for (j = 0; j < PA_CustomReco; j++){
+ s32 tempvalue = 0;
+ s32 tempdiff = 0;
+ for (i = 0; i < 15; i++) {
+ tempvalue = (PA_RecoShape[i]-PA_CustomShape[j].code[i])&31;
+ tempvalue -= (tempvalue >> 4)<<5; // normalise
+ if (tempvalue < 0) tempvalue = -tempvalue;
+ tempdiff += tempvalue; // value
+ }
+
+ if (tempdiff < diff){ // Nouvelle lettre !
+ diff = tempdiff;
+ letter = PA_CustomShape[j].letter;
+ }
+ }
+
+ }
+ PA_RecoInfo.Difference = diff; // Difference to perfect shape
+ PA_RecoInfo.Shape = letter;
+
+ return letter;
+}
+
+int old_down = 0;
+
+char PA_CheckLetter(int down, int x, int y){
+ if(!old_down && down){
+ PA_Reco.nvalues = 0; // Start over again
+ PA_Reco.oldn = 0;
+ PA_Reco.veryold = 0;
+
+ PA_RecoInfo.startX = PA_StylusPos[PA_Reco.nvalues].x = x; // start values
+ PA_RecoInfo.startY = PA_StylusPos[PA_Reco.nvalues].y = y;
+ PA_RecoInfo.minX = PA_RecoInfo.maxX = PA_RecoInfo.startX;
+ PA_RecoInfo.minY = PA_RecoInfo.maxY = PA_RecoInfo.startY;
+ PA_Reco.nvalues++;
+ }
+ else if(old_down && down) {
+ PA_StylusLine(PA_StylusPos[PA_Reco.nvalues-1].x, PA_StylusPos[PA_Reco.nvalues-1].y, x, y);
+
+ }
+
+
+ if(old_down && !down){ // Start analyzing...
+ PA_Reco.nvalues = PA_Reco.veryold;
+ old_down = down;
+ return PA_AnalyzeShape();
+ }
+ PA_Reco.veryold = PA_Reco.oldn;
+ PA_Reco.oldn = PA_Reco.nvalues;
+ old_down = down;
+ return 0;
+}
+
+