[Scummvm-cvs-logs] SF.net SVN: scummvm: [23991] scummvm/branches/branch-0-9-0/backends

agent-q at users.sourceforge.net agent-q at users.sourceforge.net
Tue Sep 26 00:12:40 CEST 2006


Revision: 23991
          http://svn.sourceforge.net/scummvm/?rev=23991&view=rev
Author:   agent-q
Date:     2006-09-25 15:10:54 -0700 (Mon, 25 Sep 2006)

Log Message:
-----------


Added Paths:
-----------
    scummvm/branches/branch-0-9-0/backends/ds/
    scummvm/branches/branch-0-9-0/backends/ds/Makefile
    scummvm/branches/branch-0-9-0/backends/ds/arm7/
    scummvm/branches/branch-0-9-0/backends/ds/arm7/Makefile
    scummvm/branches/branch-0-9-0/backends/ds/arm7/source/
    scummvm/branches/branch-0-9-0/backends/ds/arm7/source/main.cpp
    scummvm/branches/branch-0-9-0/backends/ds/arm9/
    scummvm/branches/branch-0-9-0/backends/ds/arm9/buildkeyboard.bat
    scummvm/branches/branch-0-9-0/backends/ds/arm9/data/
    scummvm/branches/branch-0-9-0/backends/ds/arm9/data/default_font.bin
    scummvm/branches/branch-0-9-0/backends/ds/arm9/data/icons.raw
    scummvm/branches/branch-0-9-0/backends/ds/arm9/data/icons.tga
    scummvm/branches/branch-0-9-0/backends/ds/arm9/data/keyboard.raw
    scummvm/branches/branch-0-9-0/backends/ds/arm9/data/keyboard_pal.raw
    scummvm/branches/branch-0-9-0/backends/ds/arm9/data/master.pal
    scummvm/branches/branch-0-9-0/backends/ds/arm9/lib/
    scummvm/branches/branch-0-9-0/backends/ds/arm9/lib/libmad.a
    scummvm/branches/branch-0-9-0/backends/ds/arm9/lib/readme.txt
    scummvm/branches/branch-0-9-0/backends/ds/arm9/makefile
    scummvm/branches/branch-0-9-0/backends/ds/arm9/ndsloader.bin
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/blitters.cpp
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/blitters.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/cdaudio.cpp
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/cdaudio.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/compressor/
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/compressor/lz.cpp
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/compressor/lz.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/console2.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/ds-fs.cpp
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/ds-fs.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/dsmain.cpp
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/dsmain.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/dsoptions.cpp
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/dsoptions.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/disc_io.c
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/disc_io.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/gba_nds_fat.c
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/gba_nds_fat.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_efa2.c
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_efa2.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_fcsr.c
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_fcsr.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_m3cf.c
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_m3cf.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_m3sd.c
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_m3sd.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_m3sd_asm.s
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_mmcf.c
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_mmcf.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_mpcf.c
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_mpcf.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_njsd.c
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_njsd.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_nmmc.c
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_nmmc.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_sccf.c
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_sccf.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_scsd.c
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_scsd.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_scsd_asm.s
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_sd_common.c
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/fat/io_sd_common.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/gbampsave.cpp
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/gbampsave.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/mad/
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/mad/mad.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/mad/readme.txt
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/osystem_ds.cpp
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/osystem_ds.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/portdefs.cpp
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/portdefs.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/ramsave.cpp
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/ramsave.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/scummconsole.c
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/scummconsole.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/scummhelp.cpp
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/scummhelp.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/touchkeyboard.cpp
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/touchkeyboard.h
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/zipreader.cpp
    scummvm/branches/branch-0-9-0/backends/ds/arm9/source/zipreader.h
    scummvm/branches/branch-0-9-0/backends/ds/commoninclude/
    scummvm/branches/branch-0-9-0/backends/ds/commoninclude/NDS/
    scummvm/branches/branch-0-9-0/backends/ds/commoninclude/NDS/scummvm_ipc.h
    scummvm/branches/branch-0-9-0/backends/ds/dist/
    scummvm/branches/branch-0-9-0/backends/ds/dist/builddata-a.bat
    scummvm/branches/branch-0-9-0/backends/ds/dist/builddata-b.bat
    scummvm/branches/branch-0-9-0/backends/ds/dist/builddata-c.bat
    scummvm/branches/branch-0-9-0/backends/ds/dist/readme.txt
    scummvm/branches/branch-0-9-0/backends/ds/logo.bmp
    scummvm/branches/branch-0-9-0/backends/ds/makedist.bat

Added: scummvm/branches/branch-0-9-0/backends/ds/Makefile
===================================================================
--- scummvm/branches/branch-0-9-0/backends/ds/Makefile	                        (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/ds/Makefile	2006-09-25 22:10:54 UTC (rev 23991)
@@ -0,0 +1,21 @@
+#SUBDIRS:= `ls | egrep -v '^(CVS|tools)$$'`
+
+
+
+
+export PATH	:=	$(DEVKITARM)/bin:$(PATH)
+
+export portdir = $(CURDIR)/arm9
+export srcdir = $(CURDIR)/../..
+
+
+SUBDIRS := arm7 arm9
+
+all:
+	@for i in $(SUBDIRS); do if test -d $$i; then make -C $$i; fi; done;
+clean:
+	@for i in $(SUBDIRS); do if test -d $$i; then make -C $$i clean; fi; done;
+
+export:
+	@for i in $(SUBDIRS); do if test -d $$i; then make -C $$i export; fi; done;
+


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/Makefile
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + LF

Added: scummvm/branches/branch-0-9-0/backends/ds/arm7/Makefile
===================================================================
--- scummvm/branches/branch-0-9-0/backends/ds/arm7/Makefile	                        (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/ds/arm7/Makefile	2006-09-25 22:10:54 UTC (rev 23991)
@@ -0,0 +1,230 @@
+#---------------------------------------------------------------------------------
+.SUFFIXES:
+#---------------------------------------------------------------------------------
+ 
+#---------------------------------------------------------------------------------
+# TARGET is the name of the output, if this ends with _mb generates a multiboot image
+# 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
+#---------------------------------------------------------------------------------
+TARGET	:=	arm7
+BUILD		:=	build
+SOURCES	:=	gfx source data  
+INCLUDES	:=	include build
+
+# Enable support for debugger (must be the same as in the arm9 makefile)
+#USE_DEBUGGER = 1
+ 
+#---------------------------------------------------------------------------------
+# options for code generation
+#---------------------------------------------------------------------------------
+ARCH	:=	-mthumb-interwork
+
+# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD
+# *insists* it has a FPU or VFP, and it won't take no for an answer!
+CFLAGS	:=	-g -Wall -O2\
+ 		-mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer\
+		-ffast-math \
+		$(ARCH)
+
+CFLAGS	+=	$(INCLUDE) -DARM7
+
+ifdef USE_DEBUGGER
+	CFLAGS += -DUSE_DEBUGGER
+endif
+	
+
+CXXFLAGS	:=	$(CFLAGS) -fno-exceptions -fno-rtti
+ASFLAGS	:=	-g $(ARCH)
+LDFLAGS	:=	-g $(ARCH) -mno-fpu
+
+#---------------------------------------------------------------------------------
+# path to tools - this can be deleted if you set the path in windows
+#---------------------------------------------------------------------------------
+# export PATH		:=	/d/dev/ds/devkitARM_r11/bin:/bin
+ 
+#---------------------------------------------------------------------------------
+# PATH to ndslib - just make a system variable called NDSLIBPATH and be done with it
+#---------------------------------------------------------------------------------
+# NDSLIBPATH	:=	/d/dev/ds/ndslib/
+ 
+#---------------------------------------------------------------------------------
+# the prefix on the compiler executables
+#---------------------------------------------------------------------------------
+PREFIX			:=	arm-eabi-
+#---------------------------------------------------------------------------------
+# any extra libraries we wish to link with the project
+#---------------------------------------------------------------------------------
+LIBS	:= -lnds7
+
+ifdef USE_DEBUGGER
+	LIBS += -ldswifi7
+endif
+ 
+ 
+#---------------------------------------------------------------------------------
+# list of directories containing libraries, this must be the top level containing
+# include and lib
+#---------------------------------------------------------------------------------
+LIBDIRS	:=	$(DEVKITPRO)/libnds $(DEVKITPRO)/libnds/nds
+ 
+ 
+#---------------------------------------------------------------------------------
+# no real need to edit anything past this point unless you need to add additional
+# rules for different file extensions
+#---------------------------------------------------------------------------------
+ifneq ($(BUILD),$(notdir $(CURDIR)))
+#---------------------------------------------------------------------------------
+ 
+export OUTPUT	:=	$(CURDIR)/$(TARGET)
+ 
+export VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
+ 
+export CC		:=	$(PREFIX)gcc
+export CXX		:=	$(PREFIX)g++
+export AR		:=	$(PREFIX)ar
+export OBJCOPY	:=	$(PREFIX)objcopy
+#---------------------------------------------------------------------------------
+# use CXX for linking C++ projects, CC for standard C
+#---------------------------------------------------------------------------------
+export LD		:=	$(CXX)
+#export LD		:=	$(CC)
+ 
+CFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
+CPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
+SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
+PCXFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.pcx)))
+BINFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.bin)))
+PALFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.pal)))
+RAWFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.raw)))
+MAPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.map)))
+ 
+export OFILES	:=	$(MAPFILES:.map=.o) $(RAWFILES:.raw=.o) $(PALFILES:.pal=.o) $(BINFILES:.bin=.o) $(PCXFILES:.pcx=.o)\
+					$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
+ 
+export INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) -I- -I$(CURDIR)/../commoninclude\
+					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
+					$(foreach dir,$(LIBDIRS),-I$(dir)/include/nds)\
+					-I$(CURDIR)/$(BUILD) 
+ 
+export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib)
+ 
+.PHONY: $(BUILD) clean
+ 
+#---------------------------------------------------------------------------------
+$(BUILD):
+	@[ -d $@ ] || mkdir -p $@
+	@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
+ 
+#---------------------------------------------------------------------------------
+clean:
+	@echo clean ...$(TARGET)
+	@rm -fr $(BUILD) *.bin
+ 
+ 
+#---------------------------------------------------------------------------------
+else
+ 
+DEPENDS	:=	$(OFILES:.o=.d)
+ 
+#---------------------------------------------------------------------------------
+# main targets
+#---------------------------------------------------------------------------------
+
+$(OUTPUT).bin	:	$(OUTPUT).elf
+ 
+$(OUTPUT).elf	:	$(OFILES)
+ 
+
+
+#---------------------------------------------------------------------------------
+%.bin: %.elf
+	@echo built ... $(notdir $@)
+	@$(OBJCOPY) -O binary  $(TARGET).elf $@
+ 
+#---------------------------------------------------------------------------------
+%.elf:
+	echo ELF
+	@$(LD)  $(LDFLAGS) -specs=ds_arm7.specs $(OFILES) $(LIBPATHS) $(LIBS) -o $(TARGET).elf
+ 
+ 
+ 
+#---------------------------------------------------------------------------------
+# Compile Targets for C/C++
+#---------------------------------------------------------------------------------
+ 
+#---------------------------------------------------------------------------------
+%.o : %.cpp
+	@echo $(notdir $<)
+	@echo $(CXX) -MM $(CXXFLAGS) -o $*.d $<
+	@$(CXX) -MM $(CXXFLAGS) -o $*.d $<
+	@$(CXX) $(CXXFLAGS) -c $< -o$@
+ 
+#---------------------------------------------------------------------------------
+%.o : %.c
+	@echo $(notdir $<)
+	@$(CC) -MM $(CFLAGS) -o $*.d $<
+	@$(CC)  $(CFLAGS) -c $< -o$@
+ 
+#---------------------------------------------------------------------------------
+%.o : %.s
+	@echo $(notdir $<)
+	@$(CC) -MM $(CFLAGS) -o $*.d $<
+	@$(CC)  $(ASFLAGS) -c $< -o$@
+ 
+define bin2o
+	cp $(<) $(*).tmp
+	$(OBJCOPY) -I binary -O elf32-littlearm -B arm \
+	--rename-section .data=.rodata \
+	--redefine-sym _binary_$*_tmp_start=$*\
+	--redefine-sym _binary_$*_tmp_end=$*_end\
+	--redefine-sym _binary_$*_tmp_size=$*_size\
+	$(*).tmp $(@)
+	echo "extern const u8" $(*)"[];" > $(*).h
+	echo "extern const u32" $(*)_size[]";" >> $(*).h
+	rm $(*).tmp
+endef
+ 
+#---------------------------------------------------------------------------------
+%.o	:	%.pcx
+#---------------------------------------------------------------------------------
+	@echo $(notdir $<)
+	@$(bin2o)
+ 
+#---------------------------------------------------------------------------------
+%.o	:	%.bin
+#---------------------------------------------------------------------------------
+	@echo $(notdir $<)
+	@$(bin2o)
+ 
+#---------------------------------------------------------------------------------
+%.o	:	%.raw
+#---------------------------------------------------------------------------------
+	@echo $(notdir $<)
+	@$(bin2o)
+ 
+#---------------------------------------------------------------------------------
+%.o	:	%.pal
+#---------------------------------------------------------------------------------
+	@echo $(notdir $<)
+	@$(bin2o)
+ 
+#---------------------------------------------------------------------------------
+%.o	:	%.map
+#---------------------------------------------------------------------------------
+	@echo $(notdir $<)
+	@$(bin2o)
+
+#---------------------------------------------------------------------------------
+%.o	:	%.mdl
+#---------------------------------------------------------------------------------
+	@echo $(notdir $<)
+	@$(bin2o)
+
+ 
+-include $(DEPENDS)
+ 
+#---------------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------------


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm7/Makefile
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + LF

Added: scummvm/branches/branch-0-9-0/backends/ds/arm7/source/main.cpp
===================================================================
--- scummvm/branches/branch-0-9-0/backends/ds/arm7/source/main.cpp	                        (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/ds/arm7/source/main.cpp	2006-09-25 22:10:54 UTC (rev 23991)
@@ -0,0 +1,633 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2005-2006 Neil Millstone
+ * Copyright (C) 2006 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * $Header: /cvsroot/scummvm/scummvm/backends/fs/fs.cpp,v 1.3.2.1 2004/12/18 02:33:52 fingolfin Exp $
+ */
+
+//////////////////////////////////////////////////////////////////////
+// Simple ARM7 stub (sends RTC, TSC, and X/Y data to the ARM 9)
+// -- joat
+// -- modified by Darkain and others
+//////////////////////////////////////////////////////////////////////
+
+ 
+#include <nds.h>
+ 
+#include <bios.h>
+#include <arm7/touch.h>
+#include <arm7/clock.h>
+#include <stdlib.h>
+#include <string.h>
+#include <registers_alt.h>
+#include <NDS/scummvm_ipc.h>
+//////////////////////////////////////////////////////////////////////
+#ifdef USE_DEBUGGER
+#include <dswifi7.h>
+#endif
+
+
+#define TOUCH_CAL_X1 (*(vs16*)0x027FFCD8)
+#define TOUCH_CAL_Y1 (*(vs16*)0x027FFCDA)
+#define TOUCH_CAL_X2 (*(vs16*)0x027FFCDE)
+#define TOUCH_CAL_Y2 (*(vs16*)0x027FFCE0)
+#define SCREEN_WIDTH    256
+#define SCREEN_HEIGHT   192
+s32 TOUCH_WIDTH  = TOUCH_CAL_X2 - TOUCH_CAL_X1;
+s32 TOUCH_HEIGHT = TOUCH_CAL_Y2 - TOUCH_CAL_Y1;
+s32 TOUCH_OFFSET_X = ( ((SCREEN_WIDTH -60) * TOUCH_CAL_X1) / TOUCH_WIDTH  ) - 28;
+s32 TOUCH_OFFSET_Y = ( ((SCREEN_HEIGHT-60) * TOUCH_CAL_Y1) / TOUCH_HEIGHT ) - 28;
+
+vu8* soundData;
+
+vu8* soundBuffer;
+vu8* arm9Buffer;
+bool soundFilled[4];
+
+int playingSection;
+
+bool needSleep = false;
+int temp;
+
+int adpcmBufferNum = 0;
+
+// those are pixel positions of the two points you click when calibrating
+#define TOUCH_CNTRL_X1   (*(vu8*)0x027FFCDC)
+#define TOUCH_CNTRL_Y1   (*(vu8*)0x027FFCDD)
+#define TOUCH_CNTRL_X2   (*(vu8*)0x027FFCE2)
+#define TOUCH_CNTRL_Y2   (*(vu8*)0x027FFCE3)
+
+
+//////////////////////////////////////////////////////////////////////
+
+/*
+void startSound(int sampleRate, const void* data, uint32 bytes, u8 channel=0, u8 vol=0x7F,  u8 pan=63, u8 format=0) {
+  SCHANNEL_TIMER(channel)  = SOUND_FREQ(sampleRate);
+  SCHANNEL_SOURCE(channel) = (uint32)data;
+  SCHANNEL_LENGTH(channel) = bytes;
+  SCHANNEL_CR(channel)     = SOUND_ENABLE | SOUND_ONE_SHOT | SOUND_VOL(vol) | SOUND_PAN(pan) | (format==1?SOUND_8BIT:SOUND_16BIT);
+}
+
+
+s8 getFreeSoundChannel() {
+  for (int i=0; i<16; i++) {
+    if ( (SCHANNEL_CR(i) & SOUND_ENABLE) == 0 ) return i;
+  }
+  return -1;
+}
+*/
+
+
+s8 getFreeSoundChannel() {
+//  return 0;
+  for (int i=0; i<16; i++) {
+    if ( (SCHANNEL_CR(i) & SCHANNEL_ENABLE) == 0 ) return i;
+  }
+  return -1;
+}
+
+void startSound(int sampleRate, const void* data, uint32 bytes, u8 channel=0, u8 vol=0x7F,  u8 pan=63, u8 format=0) {
+//  REG_IME = IME_DISABLE;
+
+  channel = getFreeSoundChannel();
+/*  if (format == 2) {
+	channel = 1;
+  } else {
+	channel = 0;
+  }*/
+  
+  if (channel > 1) channel = 1;
+  
+  bytes &= ~7;		// Multiple of 4 bytes!
+//  bytes += 4;
+  
+  SCHANNEL_CR(channel) = 0;
+  SCHANNEL_TIMER(channel)  = SOUND_FREQ(sampleRate);
+  SCHANNEL_SOURCE(channel) = ((uint32) (data));
+  SCHANNEL_LENGTH(channel) = ((bytes & 0x7FFFFFFF) >> 2);
+  SCHANNEL_REPEAT_POINT(channel) = 0;
+
+  SCHANNEL_CR(channel + 2) = 0;
+  SCHANNEL_TIMER(channel + 2)  = SOUND_FREQ(sampleRate);
+  SCHANNEL_SOURCE(channel + 2) = ((uint32) (data));
+  SCHANNEL_LENGTH(channel + 2) = ((bytes & 0x7FFFFFFF) >> 2);
+  SCHANNEL_REPEAT_POINT(channel + 2) = 0;
+  
+  uint32 flags = SCHANNEL_ENABLE | SOUND_VOL(vol) | SOUND_PAN(pan);
+
+  switch (format) {
+	case 1: {
+		flags |= SOUND_8BIT;
+		flags |= SOUND_REPEAT;// | (1 << 15);
+		break;
+	}
+	
+	case 0: {
+		flags |= SOUND_16BIT;
+		flags |= SOUND_REPEAT;// | (1 << 15);
+		break;
+	}
+	
+	case 2: {
+		flags |= SOUND_FORMAT_ADPCM;
+		flags |= SOUND_ONE_SHOT;// | (1 << 15);
+		
+		SCHANNEL_SOURCE(channel) = (unsigned int) IPC->adpcm.buffer[0];
+		//bytes += 32;
+		SCHANNEL_LENGTH(channel) = (((bytes + 4) & 0x7FFFFFFF) >> 2);
+		
+		SCHANNEL_CR(channel + 1) = 0;
+		SCHANNEL_SOURCE(channel + 1) = (unsigned int) IPC->adpcm.buffer[0];
+		SCHANNEL_LENGTH(channel + 1) = (((bytes + 4) & 0x7FFFFFFF) >> 2);
+		SCHANNEL_TIMER(channel + 1) = SOUND_FREQ(sampleRate);
+		SCHANNEL_REPEAT_POINT(channel + 1) = 0;
+		SCHANNEL_CR(channel + 1) = flags;
+		temp = bytes;
+		adpcmBufferNum = 0;
+		break;
+	}
+  }
+	
+  
+//  if (bytes & 0x80000000) {
+//    flags |= SOUND_REPEAT;
+//  } else {
+//  }
+
+  
+   
+  
+  soundData = (vu8* ) data;
+
+  SCHANNEL_CR(channel)     = flags;
+  SCHANNEL_CR(channel + 2)     = flags;
+
+
+
+  if (channel == 0) {
+	for (volatile int i = 0; i < 16384 * 2; i++) {
+		// Delay loop - this makes everything stay in sync!
+	}
+		
+	TIMER0_CR = 0;
+	TIMER0_DATA = SOUND_FREQ(sampleRate) * 2;
+	TIMER0_CR = TIMER_ENABLE | TIMER_DIV_1;
+		
+	TIMER1_CR = 0;
+	TIMER1_DATA = 65536 - ((bytes & 0x7FFFFFFF) >> 3);		// Trigger four times during the length of the buffer
+	TIMER1_CR = TIMER_ENABLE | TIMER_IRQ_REQ | TIMER_CASCADE;
+
+    playingSection = 0;
+  } else {
+	for (volatile int i = 0; i < 16384 * 2; i++) {
+		// Delay loop - this makes everything stay in sync!
+	}
+		
+	TIMER2_CR = 0;
+	TIMER2_DATA = SOUND_FREQ(sampleRate) * 2;
+	TIMER2_CR = TIMER_ENABLE | TIMER_DIV_1;
+		
+	TIMER3_CR = 0;
+	TIMER3_DATA = 65536 - ((bytes & 0x7FFFFFFF) >> 3);		// Trigger four times during the length of the buffer
+	TIMER3_CR = TIMER_ENABLE | TIMER_IRQ_REQ | TIMER_CASCADE;
+	
+	for (int r = 0; r < 4; r++) {
+//		IPC->streamFillNeeded[r] = true;
+	}
+	
+	IPC->streamPlayingSection = 0;
+  }
+
+
+
+//  IPC->fillSoundFirstHalf = true;
+//  IPC->fillSoundSecondHalf = true;
+//  soundFirstHalf = true;
+  
+//  REG_IME = IME_ENABLE;
+}
+
+void stopSound(int chan) {
+ SCHANNEL_CR(chan) = 0;
+}
+
+void DummyHandler() {
+	REG_IF = REG_IF;
+}
+
+uint16 powerManagerWrite(uint32 command, u32 data, bool enable) {
+
+  uint16 result;
+  SerialWaitBusy();
+
+  // Write the command and wait for it to complete
+  REG_SPICNT = SPI_ENABLE | SPI_BAUD_1MHz | (1 << 11);
+  REG_SPIDATA = command | 0x80;
+  SerialWaitBusy();
+
+  // Write the second command and clock in the data
+  REG_SPICNT = SPI_ENABLE | SPI_BAUD_1MHz;
+  REG_SPIDATA = 0;
+  SerialWaitBusy();
+  
+  result = REG_SPIDATA & 0xFF;
+
+
+
+  // Write the command and wait for it to complete
+  REG_SPICNT = SPI_ENABLE | SPI_BAUD_1MHz | (1 << 11);
+  REG_SPIDATA = command;
+  SerialWaitBusy();
+
+  // Write the second command and clock in the data
+  REG_SPICNT = SPI_ENABLE | SPI_BAUD_1MHz;
+  REG_SPIDATA = enable? (result | data): (result & ~data);
+  SerialWaitBusy();
+}
+
+/*
+void performSleep() {
+
+  powerManagerWrite(0, 0x30, true);
+
+  // Here, I set up a dummy interrupt handler, then trigger all interrupts.
+  // These are just aknowledged by the handler without doing anything else.
+  // Why?  Because without it the sleep mode will only happen once, and then
+  // never again.  I got the idea from reading the MoonShell source.
+  IME = 0;
+  u32 irq = (u32) IRQ_HANDLER;
+  IRQ_HANDLER = DummyHandler;
+  IF = ~0;
+  IME = 1;
+  
+  
+  // Now save which interrupts are enabled, then set only the screens unfolding
+  // interrupt to be enabled, so that the first interrupt that happens is the
+  // one I want.
+  int saveInts = IE;
+  
+  
+  
+  IE = IRQ_TIMER0;		// Screens unfolding interrupt
+
+  // Now call the sleep function in the bios
+  bool b;
+  do {
+    TIMER0_CR = 0;
+	TIMER0_DATA = TIMER_FREQ(20);
+	TIMER0_CR = TIMER_ENABLE | TIMER_DIV_64;
+	
+	swiDelay(100);
+  
+	swiSleep();
+
+	swiDelay(100);
+	
+	powerManagerWrite(0, 0x30, b = !b);	
+  } while (!(TIMER0_CR & TIMER_ENABLE));
+  
+  TIMER0_CR = 0;
+
+  // We're back from sleep, now restore the interrupt state and IRQ handler  
+  IRQ_HANDLER = (void (*)()) irq;
+  IE = saveInts;
+  IF = ~0;
+  IME = 1;
+
+  
+  
+  powerManagerWrite(0, 0x30, false);
+}
+
+*/
+void performSleep() {
+  powerManagerWrite(0, 0x30, true);
+
+  IPC->performArm9SleepMode = true;	// Tell ARM9 to sleep
+  
+//  u32 irq = (u32) IRQ_HANDLER;
+//  IRQ_HANDLER = DummyHandler;
+//  POWER_CR &= ~POWER_SOUND;
+  
+//  int saveInts = REG_IE;
+//  REG_IE = (1 << 22) | IRQ_VBLANK;		// Lid open
+//  *((u32*) (0x0380FFF8)) = *((u32*) (0x0380FFF8)) | (REG_IE & REG_IF);
+//  VBLANK_INTR_WAIT_FLAGS = IRQ_VBLANK;
+
+  
+  int r = 0;
+  while ((REG_KEYXY & (1 << 7))) {		// Wait for lid to open
+	swiDelay(1000000);
+	r++;
+  }
+  
+//  IRQ_HANDLER = (void (*)()) irq;
+  IPC->performArm9SleepMode = false;	// Tell ARM9 to wake up
+//  REG_IE = saveInts;
+  
+//  POWER_CR |= POWER_SOUND;
+ 
+  powerManagerWrite(0, 0x30, false);
+}
+
+void powerOff() {
+	powerManagerWrite(0, 0x40, true);
+}
+//////////////////////////////////////////////////////////////////////
+
+  
+  	
+void InterruptTimer1() {
+	
+	IPC->fillNeeded[playingSection] = true;
+	soundFilled[playingSection] = false;
+	  
+	if (playingSection == 3) {
+//		IME = IME_DISABLED;
+		
+	//	while (SCHANNEL_CR(0) & SCHANNEL_ENABLE) {
+	//	}
+//		SCHANNEL_CR(0) &= ~SCHANNEL_ENABLE;	
+		
+//		SCHANNEL_CR(0) |= SCHANNEL_ENABLE;
+//		TIMER1_CR = 0;
+//		TIMER1_CR = TIMER_ENABLE | TIMER_IRQ_REQ | TIMER_CASCADE;
+		
+		playingSection = 0;
+		
+//		IME = IME_ENABLED;
+	} else {
+		playingSection++;
+	}
+	
+	IPC->playingSection = playingSection;
+	
+/*	for (int r = 0; r < 4; r++) {
+		//if ((!soundFilled[r]) && (!IPC->fillNeeded[playingSection])) {
+			memcpy((void *) (soundBuffer + (r * 1024)), (void *) (arm9Buffer + (r * 1024)), 1024);
+
+			vu16* p = (vu16 *) (soundBuffer);
+			//for (int t = 0; t < 2048; t++) {
+		//		*(p + t) = (t & 1)? 0xF000: 0x0000;
+			//}
+			soundFilled[r] = true;
+		//}
+	}*/
+}	
+  
+void InterruptTimer3() {
+	while (IPC->adpcm.semaphore);		// Wait for buffer to become free if needed
+	IPC->adpcm.semaphore = true;		// Lock the buffer structure to prevent clashing with the ARM7
+		
+	IPC->streamFillNeeded[IPC->streamPlayingSection] = true;
+	  
+	if (IPC->streamPlayingSection == 3) {
+		IPC->streamPlayingSection = 0;
+	} else {
+		IPC->streamPlayingSection++;
+	}
+	
+	
+	IPC->adpcm.semaphore = false;
+}
+
+//  IPC->performArm9SleepMode = false;
+
+	// precalculate some values
+//  static int16 TOUCH_WIDTH  = TOUCH_CAL_X2 - TOUCH_CAL_X1;
+//  static int16 TOUCH_HEIGHT = TOUCH_CAL_Y2 - TOUCH_CAL_Y1;
+//  static int16 CNTRL_WIDTH  = TOUCH_CNTRL_X2 - (TOUCH_CNTRL_X1 - 8);
+//  static int16 CNTRL_HEIGHT = TOUCH_CNTRL_Y2 - (TOUCH_CNTRL_Y1 - 8);
+  
+  
+  
+ 
+ void InterruptVBlank() {
+    uint16 but=0, x=0, y=0, xpx=0, ypx=0, z1=0, z2=0, batt=0, aux=0;
+    int t1=0, t2=0;
+    uint32 temp=0;
+    uint8 ct[sizeof(IPC->curtime)];
+	static int heartbeat = 0;
+    
+    // Update the heartbeat
+    heartbeat++;
+ 
+    // Read the X/Y buttons and the /PENIRQ line
+    but = REG_KEYXY;
+    if (!(but & 0x40)) {
+      // Read the touch screen
+	  touchPosition p = touchReadXY();
+
+//      x = touchRead(TSC_MEASURE_X);
+ //     y = touchRead(TSC_MEASURE_Y);
+	  
+	  x = p.x;
+	  y = p.y;
+	  
+	  xpx = p.px;
+	  ypx = p.py;
+	  
+//      xpx = ( ((SCREEN_WIDTH -60) * x) / TOUCH_WIDTH  ) - TOUCH_OFFSET_X;
+  //    ypx = ( ((SCREEN_HEIGHT-60) * y) / TOUCH_HEIGHT ) - TOUCH_OFFSET_Y;
+	  
+//	  xpx = (IPC->touchX - (int16) TOUCH_CAL_X1) * CNTRL_WIDTH  / TOUCH_WIDTH  + (int16) (TOUCH_CNTRL_X1 - 8);
+	//  ypx = (IPC->touchY - (int16) TOUCH_CAL_Y1) * CNTRL_HEIGHT / TOUCH_HEIGHT + (int16) (TOUCH_CNTRL_Y1 - 8); 
+
+	  
+      z1 = touchRead(TSC_MEASURE_Z1);
+      z2 = touchRead(TSC_MEASURE_Z2);
+    }
+	
+    if (but & (1 << 7)) {		// Check if screen is folded
+	  needSleep = true;
+	}
+	
+
+    batt = touchRead(TSC_MEASURE_BATTERY);
+    aux  = touchRead(TSC_MEASURE_AUX);
+
+    // Read the time
+    rtcGetTime((uint8 *)ct);
+    BCDToInteger((uint8 *)&(ct[1]), 7);
+ 
+    // Read the temperature
+    temp = touchReadTemperature(&t1, &t2);
+ 
+ 
+    // Update the IPC struct
+    IPC->heartbeat = heartbeat;
+    IPC->buttons   = but;
+    IPC->touchX    = x;
+    IPC->touchY    = y;
+    IPC->touchXpx  = xpx;
+    IPC->touchYpx  = ypx;
+    IPC->touchZ1   = z1;
+    IPC->touchZ2   = z2;
+    IPC->battery   = batt;
+    IPC->aux       = aux;
+
+    for(u32 i=0; i<sizeof(ct); i++) {
+      IPC->curtime[i] = ct[i];
+    }
+
+    IPC->temperature = temp;
+    IPC->tdiode1 = t1;
+    IPC->tdiode2 = t2;
+
+   
+
+	//sound code  :)
+    TransferSound *snd = IPC->soundData;
+    IPC->soundData = 0;
+    if (snd) {
+      for (int i=0; i<snd->count; i++) {
+        s8 chan = getFreeSoundChannel();
+		if (snd->data[i].rate > 0) {
+			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);
+			}
+		} else {
+			stopSound(-snd->data[i].rate);
+		}
+      }
+    }
+    
+   
+ #ifdef USE_DEBUGGER
+    Wifi_Update(); // update wireless in vblank
+ #endif
+ }
+ 
+
+//////////////////////////////////////////////////////////////////////
+
+
+#ifdef USE_DEBUGGER
+
+// callback to allow wifi library to notify arm9
+void arm7_synctoarm9() { // send fifo message
+   REG_IPC_FIFO_TX = 0x87654321;
+}
+// interrupt handler to allow incoming notifications from arm9
+void arm7_fifo() { // check incoming fifo messages
+   u32 msg = REG_IPC_FIFO_RX;
+   if(msg==0x87654321) Wifi_Sync();
+}
+
+ 
+
+void initDebugger() {
+	
+	// set up the wifi irq
+	irqSet(IRQ_WIFI, Wifi_Interrupt); // set up wifi interrupt
+	irqEnable(IRQ_WIFI);
+
+    //get them talking together
+
+	// sync with arm9 and init wifi
+	u32 fifo_temp;
+
+	while(1) { // wait for magic number
+		while(REG_IPC_FIFO_CR&IPC_FIFO_RECV_EMPTY) swiWaitForVBlank();
+		fifo_temp=REG_IPC_FIFO_RX;
+		if(fifo_temp==0x12345678) break;
+   	}
+
+   	while(REG_IPC_FIFO_CR&IPC_FIFO_RECV_EMPTY) swiWaitForVBlank();
+   	fifo_temp=REG_IPC_FIFO_RX; // give next value to wifi_init
+   	Wifi_Init(fifo_temp);
+
+   	irqSet(IRQ_FIFO_NOT_EMPTY,arm7_fifo); // set up fifo irq
+   	irqEnable(IRQ_FIFO_NOT_EMPTY);
+   	REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_RECV_IRQ;
+
+   	Wifi_SetSyncHandler(arm7_synctoarm9); // allow wifi lib to notify arm9
+	// arm7 wifi init complete	
+
+}
+#endif
+
+int main(int argc, char ** argv) {
+	
+#ifdef USE_DEBUGGER
+  REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR;
+#endif
+  
+  // Reset the clock if needed
+  rtcReset();
+
+  //enable sound
+  powerON(POWER_SOUND);
+  SOUND_CR = SOUND_ENABLE | SOUND_VOL(0x7F);
+  IPC->soundData = 0;
+  IPC->reset = false;
+
+
+ 
+  
+  for (int r = 0; r < 8; r++) {
+	IPC->adpcm.arm7Buffer[r] = (u8 *) malloc(512);
+  }
+  
+  for (int r = 0; r < 4; r++) {
+	soundFilled[r] = false;
+  }
+
+ 
+  // Set up the interrupt handler
+  
+  irqInit();
+
+  irqSet(IRQ_VBLANK, InterruptVBlank);
+  irqEnable(IRQ_VBLANK);
+
+  irqSet(IRQ_TIMER1, InterruptTimer1);
+  irqEnable(IRQ_TIMER1);
+
+  irqSet(IRQ_TIMER3, InterruptTimer3);
+  irqEnable(IRQ_TIMER3);
+  
+/*  REG_IME = 0;
+  IRQ_HANDLER = &InterruptHandler;
+  REG_IE = IRQ_VBLANK | IRQ_TIMER1 | IRQ_TIMER3;
+  REG_IF = ~0;
+  DISP_SR = DISP_VBLANK_IRQ;
+  REG_IME = 1;
+  */
+
+ 
+#ifdef USE_DEBUGGER  
+  initDebugger();
+#endif  
+
+  // Keep the ARM7 out of main RAM
+  while (1) {
+	if (needSleep) {
+		performSleep();
+		needSleep = false;
+	}
+	if (IPC->reset) {
+		powerOff();
+	}
+	swiWaitForVBlank();
+  }
+  return 0;
+}
+
+ 
+//////////////////////////////////////////////////////////////////////
+


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm7/source/main.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + LF

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/buildkeyboard.bat
===================================================================
--- scummvm/branches/branch-0-9-0/backends/ds/arm9/buildkeyboard.bat	                        (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/ds/arm9/buildkeyboard.bat	2006-09-25 22:10:54 UTC (rev 23991)
@@ -0,0 +1,8 @@
+cd data
+..\tools\gfx2gba -c16 -t8 -M -pkeyboard_pal.raw ..\keyboard.bmp
+del keyboard.map
+pause
+cd data
+..\tools\gfx2gba -c16 -t8 -M -pkeyboard_pal.raw ..\keyboard.bmp
+del keyboard.map
+pause
\ No newline at end of file


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/buildkeyboard.bat
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + LF

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/data/default_font.bin
===================================================================
(Binary files differ)


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/data/default_font.bin
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/data/icons.raw
===================================================================
(Binary files differ)


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/data/icons.raw
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/data/icons.tga
===================================================================
(Binary files differ)


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/data/icons.tga
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/data/keyboard.raw
===================================================================
(Binary files differ)


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/data/keyboard.raw
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/data/keyboard_pal.raw
===================================================================
(Binary files differ)


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/data/keyboard_pal.raw
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/data/master.pal
===================================================================
(Binary files differ)


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/data/master.pal
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/lib/libmad.a
===================================================================
(Binary files differ)


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/lib/libmad.a
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/lib/readme.txt
===================================================================
--- scummvm/branches/branch-0-9-0/backends/ds/arm9/lib/readme.txt	                        (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/ds/arm9/lib/readme.txt	2006-09-25 22:10:54 UTC (rev 23991)
@@ -0,0 +1,2 @@
+If building with MAD enabled, put libmad.a in here.
+If building with MAD enabled, put libmad.a in here.
\ No newline at end of file


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/lib/readme.txt
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + LF

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/makefile
===================================================================
--- scummvm/branches/branch-0-9-0/backends/ds/arm9/makefile	                        (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/ds/arm9/makefile	2006-09-25 22:10:54 UTC (rev 23991)
@@ -0,0 +1,311 @@
+#BUILD_PLUGINS = 1
+libndsdir = $(DEVKITPRO)/libnds
+
+# Select the build you want by uncommenting one of the following lines:
+#DS_BUILD_A = 1
+#DS_BUILD_B = 1
+DS_BUILD_C = 1
+
+
+# Uncomment the following line to build in support for MP3 audio
+# using libmad:
+USE_MAD = 1
+
+# Uncomment the following line to enable support for the
+# ace DS Debugger (remembering to make the same change in the arm7 makefile):
+#USE_DEBUGGER = 1
+# NOTE: The header and libs for the debugger is assumed to be in the libnds
+# folder.
+
+VPATH = $(srcdir)
+
+# Command to build libmad is:
+# ./configure --host=arm-elf --enable-speed --enable-sso -enable-fpm=arm CFLAGS='-specs=ds_arm9.specs -mthumb-interwork'
+
+
+ifdef DS_BUILD_A
+	DEFINES = -DDS_SCUMM_BUILD -DDS_BUILD_A
+	DISABLE_HE = 1
+	#DISABLE_SCUMM = 1
+	DISABLE_SCUMM_7_8 = 1
+	DISABLE_SIMON = 1
+	DISABLE_SKY = 1
+	DISABLE_SWORD1 = 1
+	DISABLE_SWORD2 = 1
+	DISABLE_QUEEN = 1
+	DISABLE_SAGA = 1
+	DISABLE_KYRA = 1
+	DISABLE_GOB = 1
+	DISABLE_LURE = 1
+	DISABLE_CINE = 1
+	DISABLE_AGI = 1
+	BUILD=scummvm-A
+endif
+
+ifdef DS_BUILD_B
+	DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_B
+	DISABLE_HE = 1
+	DISABLE_SCUMM = 1
+	DISABLE_SCUMM_7_8 = 1
+	DISABLE_SIMON = 1
+	#DISABLE_SKY = 1
+	DISABLE_SWORD1 = 1
+	DISABLE_SWORD2 = 1
+	#DISABLE_QUEEN = 1
+	DISABLE_SAGA = 1
+	DISABLE_KYRA = 1
+	DISABLE_GOB = 1
+	DISABLE_LURE = 1
+	DISABLE_CINE = 1
+	DISABLE_AGI = 1
+	BUILD=scummvm-B
+endif
+
+ifdef DS_BUILD_C	
+	DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_C
+	DISABLE_HE = 1
+	DISABLE_SCUMM = 1
+	DISABLE_SCUMM_7_8 = 1
+	#DISABLE_SIMON = 1
+	DISABLE_SKY = 1
+	DISABLE_SWORD1 = 1
+	DISABLE_SWORD2 = 1
+	DISABLE_QUEEN = 1
+	DISABLE_SAGA = 1
+	#DISABLE_KYRA = 1
+	#DISABLE_GOB = 1
+	DISABLE_LURE = 1
+	DISABLE_CINE = 1
+	DISABLE_AGI = 1
+	BUILD=scummvm-C
+endif
+
+
+ARM7BIN	:= -7 $(CURDIR)/../../arm7/arm7.bin
+ICON 		:= -b ../../../logo.bmp "ScummVM;By Neil Millstone;"
+
+CC      = arm-eabi-gcc
+CXX     = arm-eabi-g++
+
+CFLAGS	=	-Wno-multichar -Wall -O2\
+		-Wno-multichar -mcpu=arm9tdmi -mtune=arm9tdmi \
+ 		-mcpu=arm9tdmi -mtune=arm9tdmi -fomit-frame-pointer\
+		-ffast-math -mthumb-interwork
+
+ifdef USE_DEBUGGER
+	DEFINES += -DUSE_DEBUGGER
+	CFLAGS += -g
+endif
+		
+CXXFLAGS=	$(CFLAGS) -Wno-non-virtual-dtor	 -Wno-non-virtual-dtor \
+		-fno-exceptions -fno-rtti
+
+ASFLAGS = -mcpu=arm9tdmi -mthumb-interwork
+DEFINES += -D__DS__ -DNDS -DARM9 -DNONSTANDARD_PORT -DDISABLE_FANCY_THEMES
+ifdef USE_MAD
+	DEFINES += -DUSE_MAD
+endif
+
+
+LDFLAGS = -specs=ds_arm9.specs -mthumb-interwork -mno-fpu -Wl,-Map,map.txt
+
+INCLUDES= -I./ -I$(portdir)/$(BUILD) -I$(srcdir) -I$(srcdir)/common -I$(portdir)/source -I$(portdir)/source/compressor -I$(portdir)/source/fat \
+			-I$(srcdir)/backends/fs  -I$(srcdir)/backends/fs/ds -I$(portdir)/data -I$(libndsdir)/include -I$(portdir)/../commoninclude\
+			-I$(srcdir)/scumm -I$(libndsdir)/include -I$(libndsdir)/include/nds -I$(srcdir)/engines -I$(portdir)/source/mad
+			
+
+LIBS	= -lm -L$(libndsdir)/lib -L$(portdir)/lib -lnds9
+ifdef USE_MAD
+	LIBS += -lmad
+endif
+ifdef USE_DEBUGGER
+	LIBS += -ldsdebugger -ldswifi9
+endif
+
+#-Lscumm -lscumm -Lbase -lbase -Lcommon -lcommon -Lgraphics -lgraphics -Lgui -lgui -Lsound -lsound
+EXECUTABLE = scummvm.elf
+PLUGIN_PREFIX =
+PLUGIN_SUFFIX = .plg
+PLUGIN_EXTRA_DEPS = plugin.x plugin.syms scummvm.elf
+PLUGIN_LDFLAGS = -nostartfiles -Wl,-q,-Tplugin.x,--just-symbols,scummvm.elf,--retain-symbols-file,plugin.syms -L$(ronindir)/lib
+MKDIR = mkdir -p
+RM = rm -f
+RM_REC = rm -rf
+AR = arm-eabi-ar cru
+RANLIB = arm-eabi-ranlib
+OBJCOPY = arm-eabi-objcopy
+AS = arm-eabi-as
+HAVE_GCC3 = true
+DISABLE_SCALERS = true
+
+ifdef BUILD_PLUGINS
+DEFINES += -DDYNAMIC_MODULES
+PRE_OBJS_FLAGS = -Wl,--whole-archive
+POST_OBJS_FLAGS = -Wl,--no-whole-archive
+endif
+
+PORT_OBJS :=	$(portdir)/source/blitters.o $(portdir)/source/cdaudio.o $(portdir)/source/dsmain.o \
+		$(portdir)/source/ds-fs.o $(portdir)/source/gbampsave.o $(portdir)/source/scummhelp.o\
+		$(portdir)/source/osystem_ds.o $(portdir)/source/portdefs.o $(portdir)/source/ramsave.o\
+		$(portdir)/source/scummconsole.o $(portdir)/source/touchkeyboard.o $(portdir)/source/zipreader.o\
+		$(portdir)/source/dsoptions.o
+		
+DATA_OBJS := $(portdir)/data/icons.o $(portdir)/data/keyboard.o $(portdir)/data/keyboard_pal.o $(portdir)/data/default_font.o
+			
+		
+COMPRESSOR_OBJS := $(portdir)/source/compressor/lz.o
+
+FAT_OBJS :=  $(portdir)/source/fat/disc_io.o $(portdir)/source/fat/gba_nds_fat.o\
+			$(portdir)/source/fat/io_fcsr.o $(portdir)/source/fat/io_m3cf.o\
+			$(portdir)/source/fat/io_mpcf.o $(portdir)/source/fat/io_sccf.o\
+			$(portdir)/source/fat/io_m3sd.o\
+			$(portdir)/source/fat/io_nmmc.o $(portdir)/source/fat/io_scsd.o \
+			$(portdir)/source/fat/io_m3sd_asm.o $(portdir)/source/fat/io_scsd_asm.o \
+			$(portdir)/source/fat/io_njsd.o \
+			$(portdir)/source/fat/io_mmcf.o \
+			$(portdir)/source/fat/io_sd_common.o 
+
+#			$(portdir)/source/fat/io_cf_common.o $(portdir)/source/fat/io_m3_common.o\
+#			$(portdir)/source/fat/io_sd_common.o $(portdir)/source/fat/io_scsd_s.o \
+#			$(portdir)/source/fat/io_sc_common.o 
+
+			
+			
+			
+OBJS := $(DATA_OBJS) $(PORT_OBJS) $(COMPRESSOR_OBJS) $(FAT_OBJS) 
+		
+
+		
+MODULE_DIRS += .
+
+ndsall:
+	@[ -d $(BUILD) ] || mkdir -p $(BUILD)
+	make -C ./$(BUILD) -f ../makefile scummvm.nds
+
+include $(srcdir)/Makefile.common
+
+clean:
+	$(RM) $(OBJS) $(EXECUTABLE)
+	rm -fr $(BUILD)
+
+plugin_dist :
+	find . -name '*.plg' | while read p; do \
+	  sh-elf-strip -g -o "`basename \"$$p\" | tr '[:lower:]' '[:upper:]'`" "$$p"; \
+	done
+
+dist : SCUMMVM.BIN plugins plugin_dist
+
+
+#---------------------------------------------------------------------------------
+# canned command sequence for binary data
+#---------------------------------------------------------------------------------
+#define bin2o
+#	bin2s $< | $(AS) -mthumb -mthumb-interwork -o $(@)
+#	echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_raw_end[];" > `(echo $(<F) | tr . _)`.h
+#	echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_raw[];" >> `(echo $(<F) | tr . _)`.h
+#	echo "extern const u32" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_raw_size";" >> `(echo $(<F) | tr . _)`.h
+#endef
+
+
+define bin2o
+	bin2s $< | $(AS) -mthumb -mthumb-interwork -o $(@)
+	echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(<F) | tr . _)`.h
+	echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(<F) | tr . _)`.h
+	echo "extern const u32" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(<F) | tr . _)`.h
+endef
+
+
+#define bin2o
+#	@echo $(*)
+#	cp $(<) $(*).tmp
+#	$(OBJCOPY) -I binary -O elf32-littlearm -B arm \
+#	--rename-section .data=.rodata \
+#	--redefine-sym _binary_$(subst .,_,$(subst /,_,$(*)))_tmp_start=$(notdir $*)\
+#	--redefine-sym _binary_$(subst .,_,$(subst /,_,$(*)))_tmp_end=$(notdir $*)_end\
+#	$(*).tmp $(@)
+#	echo "extern const u8" $(notdir $*)"[] __attribute__ ((aligned (4)));" > $(*).h
+#	echo "extern const u32" $(notdir $(*))_size[]";" >> $(*).h
+#	
+#	echo $(*).h
+#	rm $(*).tmp
+#endef
+
+##############
+# Replacement rule for the one in makefile.common
+##############
+ifndef HAVE_GCC3
+# If you use GCC, disable the above and enable this for intelligent
+# dependency tracking. 
+.cpp.o:
+	$(MKDIR) $(*D)/$(DEPDIR)
+	$(CXX) -Wp,-MMD,"$(*D)/$(DEPDIR)/$(*F).d2" $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o
+	$(ECHO) "$(*D)/" > $(*D)/$(DEPDIR)/$(*F).d
+	$(CAT) "$(*D)/$(DEPDIR)/$(*F).d2" >> "$(*D)/$(DEPDIR)/$(*F).d"
+	$(RM) "$(*D)/$(DEPDIR)/$(*F).d2"
+else
+# If you even have GCC 3.x, you can use this build rule, which is safer; the above
+# rule can get you into a bad state if you Ctrl-C at the wrong moment.
+# Also, with this GCC inserts additional dummy rules for the involved headers,
+# which ensures a smooth compilation even if said headers become obsolete.
+.cpp.o:
+	$(MKDIR) $(*D)/$(DEPDIR)
+#	$(CXX) -Wp,-MMD,"$(*D)/$(DEPDIR)/$(*F).d",-MQ,"$@",-MP $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o
+	$(CXX) -MMD -MF "$(*D)/$(DEPDIR)/$(*F).d"              $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o
+endif
+
+
+#---------------------------------------------------------------------------------
+ 
+#---------------------------------------------------------------------------------
+%.o	:	%.pcx
+#---------------------------------------------------------------------------------
+	@echo $(notdir $<)
+	@$(bin2o)
+ 
+#---------------------------------------------------------------------------------
+%.o	:	%.bin
+#---------------------------------------------------------------------------------
+	@echo $(notdir $<)
+	@$(bin2o)
+ 
+#---------------------------------------------------------------------------------
+%.o	:	%.raw
+#---------------------------------------------------------------------------------
+	@echo $(notdir $<)
+	@$(bin2o)
+ 
+#---------------------------------------------------------------------------------
+%.o	:	%.pal
+#---------------------------------------------------------------------------------
+	@echo $(notdir $<)
+	@$(bin2o)
+ 
+#---------------------------------------------------------------------------------
+%.o	:	%.map
+#---------------------------------------------------------------------------------
+	@echo $(notdir $<)
+	@$(bin2o)
+
+#---------------------------------------------------------------------------------
+%.o	:	%.mdl
+#---------------------------------------------------------------------------------
+	@echo $(notdir $<)
+	@$(bin2o)
+
+#---------------------------------------------------------------------------------
+%.nds: %.bin
+	@echo ndstool -c $@ -9 scummvm.bin $(ARM7BIN) -b ../../logo.bmp "$(shell basename $@);ScummVM 0.9.0;Port v0.6"
+	ndstool -c $@ -9 scummvm.bin $(ARM7BIN) -b ../../logo.bmp "$(shell basename $@);ScummVM 0.9.0;Port v0.6"
+	dsbuild $@ -l ../ndsloader.bin
+
+	padbin 16 $(basename $@).ds.gba
+
+#---------------------------------------------------------------------------------
+%.bin: %.elf
+	$(OBJCOPY) -S scummvm.elf scummvm-stripped.elf
+	$(OBJCOPY) -O binary scummvm-stripped.elf scummvm.bin
+
+#%.o: %.s
+#	$(MKDIR) $(*D)/$(DEPDIR)
+#	$(CXX) -Wp,-MMD,"$(*D)/$(DEPDIR)/$(*F).d",-MQ,"$@",-MP $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o
+	


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/makefile
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + LF

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/ndsloader.bin
===================================================================
(Binary files differ)


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/ndsloader.bin
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/source/blitters.cpp
===================================================================
--- scummvm/branches/branch-0-9-0/backends/ds/arm9/source/blitters.cpp	                        (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/ds/arm9/source/blitters.cpp	2006-09-25 22:10:54 UTC (rev 23991)
@@ -0,0 +1,137 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2005-2006 Neil Millstone
+ * Copyright (C) 2006 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ */
+ 
+#include "stdafx.h"
+#define CHARSET_MASK_TRANSPARENCY 253
+
+namespace DS {
+
+void asmDrawStripToScreen(int height, int width, byte const* text, byte const* src, byte* dst, 
+	int vsPitch, int vmScreenWidth, int textSurfacePitch) {
+
+
+	if (height <= 0) height = 1;
+	if (width < 4) return;
+	
+	
+	width &= ~4;
+//	src = (const byte *) (((int) (src)) & (~4));
+//	dst = (byte *) (((int) (dst)) & (~4));
+//	text = (const byte *) (((int) (text)) & (~4));
+	
+	asm (	"mov r5, %0\n"				// Height
+			"yLoop:\n"			
+			"mov r3, #0\n"				// X pos
+			
+			"xLoop:\n"
+			
+			"ldr r4, [%2, r3]\n"		// Load text layer word
+			"cmp r4, %5\n"
+			"bne singleByteCompare\n"
+			"ldr r4, [%3, r3]\n"
+			"str r4, [%4, r3]\n"
+			"add r3, r3, #4\n"
+			"cmp r3, %1\n"				// x == width?
+			"blt xLoop\n"
+			
+			"add %2, %2, %8\n"			// src += vs->pitch
+			"add %3, %3, %6\n"			// dst += _vm->_screenWidth
+			"add %4, %4, %7\n"			// text += _textSurface.pitch
+			"sub r5, r5, #1\n"			// y -= 1
+			"cmp r5, #0\n"				// y == 0?
+			"bne yLoop\n"
+			"b end\n"
+			
+			
+			"singleByteCompare:\n"
+			"ldrb r4, [%2, r3]\n"		// Load text byte
+			"cmps r4, %5, lsr #24\n"	// Compare with mask
+			"strneb r4, [%4, r3]\n"		// Store if not equal
+			"ldreqb r4, [%3, r3]\n"		// Otherwise Load src byte
+			"streqb r4, [%4, r3]\n"		// Store it
+			"add r3, r3, #1\n"
+
+			"ldrb r4, [%2, r3]\n"		// Load text byte
+			"cmps r4, %5, lsr #24\n"	// Compare with mask
+			"strneb r4, [%4, r3]\n"		// Store if not equal
+			"ldreqb r4, [%3, r3]\n"		// Otherwise Load src byte
+			"streqb r4, [%4, r3]\n"		// Store it
+			"add r3, r3, #1\n"
+			
+			"ldrb r4, [%2, r3]\n"		// Load text byte
+			"cmps r4, %5, lsr #24\n"	// Compare with mask
+			"strneb r4, [%4, r3]\n"		// Store if not equal
+			"ldreqb r4, [%3, r3]\n"		// Otherwise Load src byte
+			"streqb r4, [%4, r3]\n"		// Store it
+			"add r3, r3, #1\n"
+
+			"ldrb r4, [%2, r3]\n"		// Load text byte
+			"cmps r4, %5, lsr #24\n"	// Compare with mask
+			"strneb r4, [%4, r3]\n"		// Store if not equal
+			"ldreqb r4, [%3, r3]\n"		// Otherwise Load src byte
+			"streqb r4, [%4, r3]\n"		// Store it
+			"add r3, r3, #1\n"			
+
+			"cmps r3, %1\n"				// x == width?
+			"blt xLoop\n"				// Repeat
+			"add %2, %2, %8\n"			// src += vs->pitch
+			"add %3, %3, %6\n"			// dst += _vm->_screenWidth
+			"add %4, %4, %7\n"			// text += _textSurface.pitch
+			"sub r5, r5, #1\n"			// y -= 1
+			"cmp r5, #0\n"				// y == 0?
+			"bne yLoop\n"
+			
+			"end:\n"
+		: /* no output registers */
+		: "r" (height), "r" (width), "r" (text), "r" (src), "r" (dst), "r" (CHARSET_MASK_TRANSPARENCY | (CHARSET_MASK_TRANSPARENCY << 8) | (CHARSET_MASK_TRANSPARENCY << 16) | (CHARSET_MASK_TRANSPARENCY << 24)), 
+			"r" (vsPitch), "r" (vmScreenWidth), "r" (textSurfacePitch)
+		: "r5", "r3", "r4", "%2", "%3", "%4", "memory");
+}
+
+
+
+void asmCopy8Col(byte* dst, int dstPitch, const byte* src, int height) {
+	asm("ands r0, %3, #1\n"
+		 "addne %3, %3, #1\n"
+		 "bne roll2\n"
+			
+		 "yLoop2:\n"
+		 "ldr r0, [%2, #0]\n"
+		 "str r0, [%0, #0]\n"
+		 "ldr r0, [%2, #4]\n"
+		 "str r0, [%0, #4]\n"
+		 "add %0, %0, %1\n"
+		 "add %2, %2, %1\n"
+		 "roll2:\n"
+		 "ldr r0, [%2, #0]\n"
+		 "str r0, [%0, #0]\n"
+		 "ldr r0, [%2, #4]\n"
+		 "str r0, [%0, #4]\n"
+		 "add %0, %0, %1\n"
+		 "add %2, %2, %1\n"
+		 "subs %3, %3, #2\n"
+		 "bne yLoop2\n"		 
+
+		: /* no output registers */
+		: "r" (dst), "r" (dstPitch), "r" (src), "r" (height)
+		: "r0", "%0", "%2", "%3");
+}
+
+}


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/source/blitters.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + LF

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/source/blitters.h
===================================================================
--- scummvm/branches/branch-0-9-0/backends/ds/arm9/source/blitters.h	                        (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/ds/arm9/source/blitters.h	2006-09-25 22:10:54 UTC (rev 23991)
@@ -0,0 +1,32 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2005-2006 Neil Millstone
+ * Copyright (C) 2006 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ */
+ 
+ #ifndef _BLITTERS_H_
+ #define _BLITTERS_H_
+
+namespace DS {
+
+void asmDrawStripToScreen(int height, int width, byte const* text, byte const* src, byte* dst, 
+	int vsPitch, int vmScreenWidth, int textSurfacePitch);
+void asmCopy8Col(byte* dst, int dstPitch, const byte* src, int height);
+
+}
+	
+#endif


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/source/blitters.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + LF

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/source/cdaudio.cpp
===================================================================
--- scummvm/branches/branch-0-9-0/backends/ds/arm9/source/cdaudio.cpp	                        (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/ds/arm9/source/cdaudio.cpp	2006-09-25 22:10:54 UTC (rev 23991)
@@ -0,0 +1,484 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2005-2006 Neil Millstone
+ * Copyright (C) 2006 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ */
+ 
+#include "stdafx.h"
+#include "cdaudio.h"
+#include "ds-fs.h"
+#include "config-manager.h"
+#include "dsmain.h"
+#include "NDS/scummvm_ipc.h"
+#include "console2.h"
+
+#define WAV_FORMAT_IMA_ADPCM 0x14
+#define BUFFER_SIZE 8192
+#define BUFFER_CHUNK_SIZE (BUFFER_SIZE >> 2)
+
+namespace DS {
+namespace CD {
+
+struct WaveHeader {
+
+	char		riff[4];		// 'RIFF'
+	u32			size;			// Size of the file
+	char		wave[4];		// 'WAVE'
+
+	// fmt chunk
+	char		fmt[4];			// 'fmt '
+	u32			fmtSize;		// Chunk size
+	u16			fmtFormatTag;	// Format of this file
+	u16			fmtChannels;	// Num channels
+	u32			fmtSamPerSec;	// Samples per second
+	u32			fmtBytesPerSec; // Bytes per second
+	u16			fmtBlockAlign;	// Block alignment
+	u16			fmtBitsPerSam;	// Bits per sample
+
+	u16			fmtExtraData;	// Number of extra fmt bytes
+	u16			fmtExtra;		// Samples per block (only for IMA-ADPCM files)
+} __attribute__ ((packed));
+	
+struct chunkHeader {
+	char 		name[4];	
+	u32			size;
+} __attribute__ ((packed));
+
+struct Header {
+	s16 		firstSample;
+	char		stepTableIndex;
+	char		reserved;
+} __attribute__ ((packed));
+
+struct decoderFormat {
+	s16 initial;
+	unsigned char tableIndex;
+	unsigned char test;
+	unsigned char	sample[1024];
+} __attribute__ ((packed));
+
+bool active = false;
+WaveHeader waveHeader;
+Header blockHeader;
+FILE* file;
+int fillPos;
+bool isPlayingFlag = false;
+
+s16* audioBuffer;
+u32 sampleNum;
+s16* decompressionBuffer;
+int numLoops;
+int blockCount;
+int dataChunkStart;
+int blocksLeft;
+
+
+// These are from Microsoft's document on DVI ADPCM
+const int stepTab[ 89 ] = {
+7, 8, 9, 10, 11, 12, 13, 14,
+16, 17, 19, 21, 23, 25, 28, 31,
+34, 37, 41, 45, 50, 55, 60, 66,
+73, 80, 88, 97, 107, 118, 130, 143,
+157, 173, 190, 209, 230, 253, 279, 307,
+337, 371, 408, 449, 494, 544, 598, 658,
+724, 796, 876, 963, 1060, 1166, 1282, 1411,
+1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024,
+3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484,
+7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
+15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794,
+32767 };
+
+const int indexTab[ 16 ] = { -1, -1, -1, -1, 2, 4, 6, 8,
+-1, -1, -1, -1, 2, 4, 6, 8 };
+
+void playNextBlock();
+void decompressBlock();
+
+
+void allocBuffers() {
+	
+}
+
+void setActive(bool active) {
+	active = active;
+}
+
+bool getActive() {
+	return active;
+}
+
+void playTrack(int track, int numLoops, int startFrame, int duration) {
+	Common::String path = ConfMan.get("path");
+	
+	if (isPlayingFlag) {
+		stopTrack();
+	}
+	
+	
+	
+	
+	
+	char str[100];
+	sprintf(str, "/track%d.wav", track);
+	path = path + str;
+	
+	
+	//1820160
+	
+	file = DS::std_fopen(path.c_str(), "rb");
+	
+	if (!file) {
+		consolePrintf("Failed to open %s!\n", path.c_str());
+		return;
+	}
+	
+	
+	DS::std_fread((const void *) &waveHeader, sizeof(waveHeader), 1, file);
+	
+	consolePrintf("Playing track %d\n", track);
+	consolePrintf("Format: %d\n", waveHeader.fmtFormatTag);
+	consolePrintf("Rate  : %d\n", waveHeader.fmtSamPerSec);
+	consolePrintf("Bits  : %d\n", waveHeader.fmtBitsPerSam);
+	consolePrintf("BlkSz : %d\n", waveHeader.fmtExtra);
+	
+	if ((waveHeader.fmtFormatTag != 17) && (waveHeader.fmtFormatTag != 20)) {
+		consolePrintf("Wave file is in the wrong format!  You must use IMA-ADPCM 4-bit mono.\n");
+		return;
+	}
+	
+	for (int r = 0; r < 8; r++) {
+		IPC->adpcm.buffer[r] = (u8 * volatile) (decoderFormat *) malloc(waveHeader.fmtBlockAlign);
+		IPC->adpcm.filled[r] = false;
+		IPC->adpcm.arm7Dirty[r] = false;
+	}
+	
+	// Skip chunks until we reach the data chunk
+	chunkHeader chunk;
+	DS::std_fread((const void *) &chunk, sizeof(chunkHeader), 1, file);
+	
+	while (!((chunk.name[0] == 'd') && (chunk.name[1] == 'a') && (chunk.name[2] == 't') && (chunk.name[3] == 'a'))) {
+		DS::std_fseek(file, chunk.size, SEEK_CUR);
+		DS::std_fread((const void *) &chunk, sizeof(chunkHeader), 1, file);
+	}
+	
+	dataChunkStart = DS::std_ftell(file);
+	
+	
+	static bool started = false;
+	sampleNum = 0;
+	blockCount = 0;
+
+	IPC->streamFillNeeded[0] = true;
+	IPC->streamFillNeeded[1] = true;
+	IPC->streamFillNeeded[2] = true;
+	IPC->streamFillNeeded[3] = true;
+	if (!started) {
+		fillPos = 0;
+		audioBuffer = (s16 *) malloc(BUFFER_SIZE * 2);
+		decompressionBuffer = (s16 *) malloc(waveHeader.fmtExtra * 2);
+		started = true;
+//		consolePrintf("****Starting buffer*****\n");
+		memset(audioBuffer, 0, BUFFER_SIZE * 2);
+		memset(decompressionBuffer, 0, waveHeader.fmtExtra * 2);
+		DS::playSound(audioBuffer, BUFFER_SIZE * 2, false, false, waveHeader.fmtSamPerSec);
+		
+	}	
+	fillPos = (IPC->streamPlayingSection + 1) & 3;
+	isPlayingFlag = true;
+	
+	
+	// Startframe is a 75Hz timer.  Dunno why, since nothing else
+	// seems to run at that rate.
+	int tenths = (startFrame * 10) / 75;
+	
+	// Seek to the nearest block start to the start time
+	int samples = (tenths * waveHeader.fmtSamPerSec) / 10;
+	int block = samples / waveHeader.fmtExtra;
+	
+	
+	if (duration == 0) {
+		blocksLeft = 0;
+	} else {
+		blocksLeft = ((((duration * 100) / 75) * (waveHeader.fmtSamPerSec)) / (waveHeader.fmtExtra) / 100) + 10;
+	}
+//	consolePrintf("Playing %d blocks (%d)\n\n", blocksLeft, duration);
+	
+	// No need to seek if we're starting from the beginning
+	if (block != 0) {
+		DS::std_fseek(file, dataChunkStart + block * waveHeader.fmtBlockAlign, SEEK_SET);
+//		consolePrintf("Startframe: %d  msec: %d (%d,%d)\n", startFrame, tenthssec, samples, block);
+	}
+	
+	
+	//decompressBlock();
+	playNextBlock();
+	numLoops = numLoops;
+}
+
+void update() {
+	playNextBlock();
+}
+
+void decompressBlock() {
+	int block[2048];
+	bool loop = false;
+	
+	blockCount++;
+	
+	if (blockCount < 10) return;
+	
+	
+	do {
+		DS::std_fread((const void *) &blockHeader, sizeof(blockHeader), 1, file);
+	
+		DS::std_fread(&block[0], waveHeader.fmtBlockAlign - sizeof(blockHeader), 1, file);
+
+		if (DS::std_feof(file) ) {
+			// Reached end of file, so loop
+			
+			
+			if ((numLoops == -1) || (numLoops > 1)) {
+				// Seek file to first packet
+				if (numLoops != -1) {
+					numLoops--;
+				}
+				DS::std_fseek(file, dataChunkStart, SEEK_SET);
+				loop = true;
+			} else {
+				// Fill decompression buffer with zeros to prevent glitching
+				for (int r = 0; r < waveHeader.fmtExtra; r++) {
+					decompressionBuffer[r] = 0;
+				}
+//				consolePrintf("Stopping music\n");
+				stopTrack();
+				return;
+			}
+			
+		} else {
+			loop = false;
+		}
+		
+	} while (loop);
+		
+		
+	if (blocksLeft > 0) {
+		blocksLeft--;
+	//	consolePrintf("%d ", blocksLeft);
+		if (blocksLeft == 0) {
+			stopTrack();
+			return;
+		}
+	}
+		
+	// First sample is in header
+	decompressionBuffer[0] = blockHeader.firstSample;
+	
+	// Set up initial table indeces
+	int stepTableIndex = blockHeader.stepTableIndex;
+	int prevSample = blockHeader.firstSample;
+	
+//	consolePrintf("Decompressing block step=%d fs=%d\n", stepTableIndex, prevSample);
+
+	for (int r = 0; r < waveHeader.fmtExtra - 1; r++) {
+		
+		int word = block[r >> 3];
+		int offset = 0;
+		
+		switch (7 - (r & 0x0007)) {
+			case 0: {
+				offset = (word & 0xF0000000) >> 28;
+				break;
+			}
+			
+			case 1: {
+				offset = (word & 0x0F000000) >> 24;
+				break;
+			}
+			
+			case 2: {
+				offset = (word & 0x00F00000) >> 20;
+				break;
+			}
+			
+			case 3: {
+				offset = (word & 0x000F0000) >> 16;
+				break;
+			}
+
+			case 4: {
+				offset = (word & 0x0000F000) >> 12;
+				break;
+			}
+
+			case 5: {
+				offset = (word & 0x00000F00) >> 8;
+				break;
+			}
+
+			case 6: {
+				offset = (word & 0x000000F0) >> 4;
+				break;
+			}
+
+			case 7: {
+				offset = (word & 0x0000000F);
+				break;
+			}
+		}
+		
+		int diff = 0;
+		
+		if (offset & 4) {
+			diff = diff + stepTab[stepTableIndex];
+		}
+		
+		if (offset & 2) {
+			diff = diff + (stepTab[stepTableIndex] >> 1);
+		}
+		
+		if (offset & 1) {
+			diff = diff + (stepTab[stepTableIndex] >> 2);
+		}
+		
+		diff = diff + (stepTab[stepTableIndex] >> 3);
+		
+		if (offset & 8) {
+			diff = -diff;		
+		}
+		
+		int newSample = prevSample + diff;
+		
+		if (newSample > 32767) newSample = 32767;
+		if (newSample < -32768) newSample = -32768;
+		
+		decompressionBuffer[r + 1] = newSample;
+		
+		prevSample = newSample;
+		
+		stepTableIndex += indexTab[offset];
+		
+		if (stepTableIndex > 88) stepTableIndex = 88;
+		if (stepTableIndex < 0) stepTableIndex = 0;
+		
+
+	}
+}
+
+void playNextBlock() {
+	if (!isPlayingFlag) return;
+	int lastBlockId = -1;
+	
+	while (IPC->adpcm.semaphore);		// Wait for buffer to become free if needed
+	IPC->adpcm.semaphore = true;		// Lock the buffer structure to prevent clashing with the ARM7
+//	DC_FlushAll();
+	
+	//-8644, 25088
+	for (int block = fillPos + 1; block < fillPos + 4; block++) {
+
+		int blockId = block & 3;
+		
+		if (IPC->streamFillNeeded[blockId]) {
+			
+			IPC->streamFillNeeded[blockId] = false;
+//			DC_FlushAll();
+			
+/*			if (!(REG_KEYINPUT & KEY_R)) {
+				//consolePrintf("Align: %d First: %d  Step:%d  Res:%d\n", waveHeader.fmtBlockAlign, blockHeader.firstSample, blockHeader.stepTableIndex, blockHeader.reserved);
+				consolePrintf("Filling buffer %d\n", blockId);
+			}*/
+			for (int r = blockId * BUFFER_CHUNK_SIZE; r < (blockId + 1) * BUFFER_CHUNK_SIZE; r++) {
+				if (isPlayingFlag) {
+					audioBuffer[r] = decompressionBuffer[sampleNum++];
+					if (sampleNum >= waveHeader.fmtExtra) {
+						decompressBlock();
+						sampleNum = 0;
+					}
+				}
+			}
+			
+			lastBlockId = blockId;
+			IPC->streamFillNeeded[blockId] = false;
+//			DC_FlushAll();
+
+		}
+	
+		
+		
+	}
+	
+	
+	
+	if (lastBlockId != -1) {
+		fillPos = lastBlockId;
+/*		if (!(REG_KEYINPUT & KEY_R)) {
+			consolePrintf("Frame fill done\n");
+		}*/
+	}
+	IPC->adpcm.semaphore = false;		// Release the buffer structure
+//	DC_FlushAll();
+}
+
+void stopTrack() {
+	if (!isPlayingFlag) return;
+
+	DS::std_fclose(file);
+	
+	isPlayingFlag = false;
+	
+	for (int r = 0; r < BUFFER_SIZE; r++) {
+		audioBuffer[r] = 0;
+	}
+	
+	for (int r= 0; r < waveHeader.fmtExtra; r++) {
+		decompressionBuffer[r] = 0;
+	}
+//	DS::stopSound(1);
+	
+//	free(audioBuffer);
+//	free(decompressionBuffer);
+
+	DC_FlushAll();
+}
+
+bool checkCD() {
+	// Need to check whethe CD audio files are present - do this by trying to open Track1.wav.
+	consolePrintf("Attempted to open cd drive\n");
+
+	Common::String path = ConfMan.get("path");
+	path = path + "/track2.wav";
+	// 6577 153 154
+	consolePrintf("Looking for %s...", path.c_str());
+	
+	FILE* file;
+	if ((file = DS::std_fopen(path.c_str(), "r"))) {
+		consolePrintf("Success!\n");
+		setActive(true);
+		DS::std_fclose(file);
+		return true;
+	} else {
+		setActive(false);
+		consolePrintf("Failed!\n");
+		return false;
+	}
+}
+
+bool isPlaying() {
+	return isPlayingFlag;
+}
+
+}
+}


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/source/cdaudio.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + LF

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/source/cdaudio.h
===================================================================
--- scummvm/branches/branch-0-9-0/backends/ds/arm9/source/cdaudio.h	                        (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/ds/arm9/source/cdaudio.h	2006-09-25 22:10:54 UTC (rev 23991)
@@ -0,0 +1,38 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2005-2006 Neil Millstone
+ * Copyright (C) 2006 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ */
+ 
+ #ifndef _CDAUDIO_H_
+#define _CDAUDIO_H_
+
+namespace DS {
+namespace CD {
+
+void setActive(bool active);
+void playTrack(int track, int numLoops, int startFrame, int duration);
+void stopTrack();
+bool checkCD();
+bool getActive();
+bool isPlaying();
+void update();
+
+}
+}
+
+#endif


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/source/cdaudio.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + LF

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/source/compressor/lz.cpp
===================================================================
--- scummvm/branches/branch-0-9-0/backends/ds/arm9/source/compressor/lz.cpp	                        (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/ds/arm9/source/compressor/lz.cpp	2006-09-25 22:10:54 UTC (rev 23991)
@@ -0,0 +1,539 @@
+/*************************************************************************
+* Name:        lz.c
+* Author:      Marcus Geelnard
+* Description: LZ77 coder/decoder implementation.
+* Reentrant:   Yes
+* $Id: lz.cpp 23460 2006-07-09 14:46:04Z ender $
+*
+* The LZ77 compression scheme is a substitutional compression scheme
+* proposed by Abraham Lempel and Jakob Ziv in 1977. It is very simple in
+* its design, and uses no fancy bit level compression.
+*
+* This is my first attempt at an implementation of a LZ77 code/decoder.
+*
+* The principle of the LZ77 compression algorithm is to store repeated
+* occurrences of strings as references to previous occurrences of the same
+* string. The point is that the reference consumes less space than the
+* string itself, provided that the string is long enough (in this
+* implementation, the string has to be at least 4 bytes long, since the
+* minimum coded reference is 3 bytes long). Also note that the term
+* "string" refers to any kind of byte sequence (it does not have to be
+* an ASCII string, for instance).
+*
+* The coder uses a brute force approach to finding string matches in the
+* history buffer (or "sliding window", if you wish), which is very, very
+* slow. I recon the complexity is somewhere between O(n^2) and O(n^3),
+* depending on the input data.
+*
+* There is also a faster implementation that uses a large working buffer
+* in which a "jump table" is stored, which is used to quickly find
+* possible string matches (see the source code for LZ_CompressFast() for
+* more information). The faster method is an order of magnitude faster,
+* and also does a full string search in the entire input buffer (it does
+* not use a sliding window).
+*
+* The upside is that decompression is very fast, and the compression ratio
+* is often very good.
+*
+* The reference to a string is coded as a (length,offset) pair, where the
+* length indicates the length of the string, and the offset gives the
+* offset from the current data position. To distinguish between string
+* references and literal strings (uncompressed bytes), a string reference
+* is preceded by a marker byte, which is chosen as the least common byte
+* symbol in the input data stream (this marker byte is stored in the
+* output stream as the first byte).
+*
+* Occurrences of the marker byte in the stream are encoded as the marker
+* byte followed by a zero byte, which means that occurrences of the marker
+* byte have to be coded with two bytes.
+*
+* The lengths and offsets are coded in a variable length fashion, allowing
+* values of any magnitude (up to 4294967295 in this implementation).
+*
+* With this compression scheme, the worst case compression result is
+* (257/256)*insize + 1.
+*
+*-------------------------------------------------------------------------
+* Copyright (c) 2003-2004 Marcus Geelnard
+*
+* 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.
+*
+* Marcus Geelnard
+* marcus.geelnard at home.se
+*************************************************************************/
+
+
+/*************************************************************************
+* Constants used for LZ77 coding
+*************************************************************************/
+
+/* Maximum offset (can be any size < 2^32). Lower values gives faster
+   compression, while higher values gives better compression.
+   NOTE: LZ_CompressFast does not use this constant. */
+#define LZ_MAX_OFFSET 512
+
+
+
+/*************************************************************************
+*                           INTERNAL FUNCTIONS                           *
+*************************************************************************/
+
+
+/*************************************************************************
+* _LZ_StringCompare() - Return maximum length string match.
+*************************************************************************/
+
+inline static unsigned int _LZ_StringCompare( unsigned char * str1,
+  unsigned char * str2, unsigned int minlen, unsigned int maxlen )
+{
+    unsigned int len;
+
+    for( len = minlen; (len < maxlen) && (str1[len] == str2[len]); ++ len );
+
+    return len;
+}
+
+
+/*************************************************************************
+* _LZ_WriteVarSize() - Write unsigned integer with variable number of
+* bytes depending on value.
+*************************************************************************/
+
+inline static int _LZ_WriteVarSize( unsigned int x, unsigned char * buf )
+{
+    unsigned int y;
+    int num_bytes, i, b;
+
+    /* Determine number of bytes needed to store the number x */
+    y = x >> 3;
+    for( num_bytes = 5; num_bytes >= 2; -- num_bytes )
+    {
+        if( y & 0xfe000000 ) break;
+        y <<= 7;
+    }
+
+    /* Write all bytes, seven bits in each, with 8:th bit set for all */
+    /* but the last byte. */
+    for( i = num_bytes-1; i >= 0; -- i )
+    {
+        b = (x >> (i*7)) & 0x0000007f;
+        if( i > 0 )
+        {
+            b |= 0x00000080;
+        }
+        *buf ++ = (unsigned char) b;
+    }
+
+    /* Return number of bytes written */
+    return num_bytes;
+}
+
+
+/*************************************************************************
+* _LZ_ReadVarSize() - Read unsigned integer with variable number of
+* bytes depending on value.
+*************************************************************************/
+
+inline static int _LZ_ReadVarSize( unsigned int * x, unsigned char * buf )
+{
+    unsigned int y, b, num_bytes;
+
+    /* Read complete value (stop when byte contains zero in 8:th bit) */
+    y = 0;
+    num_bytes = 0;
+    do
+    {
+        b = (unsigned int) (*buf ++);
+        y = (y << 7) | (b & 0x0000007f);
+        ++ num_bytes;
+    }
+    while( b & 0x00000080 );
+
+    /* Store value in x */
+    *x = y;
+
+    /* Return number of bytes read */
+    return num_bytes;
+}
+
+
+
+/*************************************************************************
+*                            PUBLIC FUNCTIONS                            *
+*************************************************************************/
+
+
+/*************************************************************************
+* LZ_Compress() - Compress a block of data using an LZ77 coder.
+*  in     - Input (uncompressed) buffer.
+*  out    - Output (compressed) buffer. This buffer must be 0.4% larger
+*           than the input buffer, plus one byte.
+*  insize - Number of input bytes.
+* The function returns the size of the compressed data.
+*************************************************************************/
+
+int LZ_Compress( unsigned char *in, unsigned char *out,
+    unsigned int insize )
+{
+    unsigned char marker, symbol;
+    unsigned int  inpos, outpos, bytesleft, i;
+    unsigned int  maxoffset, offset, bestoffset;
+    unsigned int  maxlength, length, bestlength;
+    unsigned int  histogram[ 256 ];
+    unsigned char *ptr1, *ptr2;
+
+    /* Do we have anything to compress? */
+    if( insize < 1 )
+    {
+        return 0;
+    }
+
+    /* Create histogram */
+    for( i = 0; i < 256; ++ i )
+    {
+        histogram[ i ] = 0;
+    }
+    for( i = 0; i < insize; ++ i )
+    {
+        ++ histogram[ in[ i ] ];
+    }
+
+    /* Find the least common byte, and use it as the code marker */
+    marker = 0;
+    for( i = 1; i < 256; ++ i )
+    {
+        if( histogram[ i ] < histogram[ marker ] )
+        {
+            marker = i;
+        }
+    }
+
+    /* Remember the repetition marker for the decoder */
+    out[ 0 ] = marker;
+
+    /* Start of compression */
+    inpos = 0;
+    outpos = 1;
+
+    /* Main compression loop */
+    bytesleft = insize;
+    do
+    {
+        /* Determine most distant position */
+        if( inpos > LZ_MAX_OFFSET ) maxoffset = LZ_MAX_OFFSET;
+        else                        maxoffset = inpos;
+
+        /* Get pointer to current position */
+        ptr1 = &in[ inpos ];
+
+        /* Search history window for maximum length string match */
+        bestlength = 3;
+        bestoffset = 0;
+        for( offset = 3; offset <= maxoffset; ++ offset )
+        {
+            /* Get pointer to candidate string */
+            ptr2 = &ptr1[ -offset ];
+
+            /* Quickly determine if this is a candidate (for speed) */
+            if( (ptr1[ 0 ] == ptr2[ 0 ]) &&
+                (ptr1[ bestlength ] == ptr2[ bestlength ]) )
+            {
+                /* Determine maximum length for this offset */
+                maxlength = (bytesleft < offset ? bytesleft : offset);
+
+                /* Count maximum length match at this offset */
+                length = _LZ_StringCompare( ptr1, ptr2, 0, maxlength );
+
+                /* Better match than any previous match? */
+                if( length > bestlength )
+                {
+                    bestlength = length;
+                    bestoffset = offset;
+                }
+            }
+        }
+
+        /* Was there a good enough match? */
+        if( (bestlength >= 8) ||
+            ((bestlength == 4) && (bestoffset <= 0x0000007f)) ||
+            ((bestlength == 5) && (bestoffset <= 0x00003fff)) ||
+            ((bestlength == 6) && (bestoffset <= 0x001fffff)) ||
+            ((bestlength == 7) && (bestoffset <= 0x0fffffff)) )
+        {
+            out[ outpos ++ ] = (unsigned char) marker;
+            outpos += _LZ_WriteVarSize( bestlength, &out[ outpos ] );
+            outpos += _LZ_WriteVarSize( bestoffset, &out[ outpos ] );
+            inpos += bestlength;
+            bytesleft -= bestlength;
+        }
+        else
+        {
+            /* Output single byte (or two bytes if marker byte) */
+            symbol = in[ inpos ++ ];
+            out[ outpos ++ ] = symbol;
+            if( symbol == marker )
+            {
+                out[ outpos ++ ] = 0;
+            }
+            -- bytesleft;
+        }
+    }
+    while( bytesleft > 3 );
+
+    /* Dump remaining bytes, if any */
+    while( inpos < insize )
+    {
+        if( in[ inpos ] == marker )
+        {
+            out[ outpos ++ ] = marker;
+            out[ outpos ++ ] = 0;
+        }
+        else
+        {
+            out[ outpos ++ ] = in[ inpos ];
+        }
+        ++ inpos;
+    }
+
+    return outpos;
+}
+
+
+/*************************************************************************
+* LZ_CompressFast() - Compress a block of data using an LZ77 coder.
+*  in     - Input (uncompressed) buffer.
+*  out    - Output (compressed) buffer. This buffer must be 0.4% larger
+*           than the input buffer, plus one byte.
+*  insize - Number of input bytes.
+*  work   - Pointer to a temporary buffer (internal working buffer), which
+*           must be able to hold (insize+65536) unsigned integers.
+* The function returns the size of the compressed data.
+*************************************************************************/
+
+int LZ_CompressFast( unsigned char *in, unsigned char *out,
+    unsigned int insize, unsigned int *work )
+{
+    unsigned char marker, symbol;
+    unsigned int  inpos, outpos, bytesleft, i, index, symbols;
+    unsigned int  offset, bestoffset;
+    unsigned int  maxlength, length, bestlength;
+    unsigned int  histogram[ 256 ], *lastindex, *jumptable;
+    unsigned char *ptr1, *ptr2;
+
+    /* Do we have anything to compress? */
+    if( insize < 1 )
+    {
+        return 0;
+    }
+
+    /* Assign arrays to the working area */
+    lastindex = work;
+    jumptable = &work[ 65536 ];
+
+    /* Build a "jump table". Here is how the jump table works:
+       jumptable[i] points to the nearest previous occurrence of the same
+       symbol pair as in[i]:in[i+1], so in[i] == in[jumptable[i]] and
+       in[i+1] == in[jumptable[i]+1]. Following the jump table gives a
+       dramatic boost for the string search'n'match loop compared to doing
+       a brute force search. */
+    for( i = 0; i < 65536; ++ i )
+    {
+        lastindex[ i ] = 0xffffffff;
+    }
+    for( i = 0; i < insize-1; ++ i )
+    {
+        symbols = (((unsigned int)in[i]) << 8) | ((unsigned int)in[i+1]);
+        index = lastindex[ symbols ];
+        lastindex[ symbols ] = i;
+        jumptable[ i ] = index;
+    }
+    jumptable[ insize-1 ] = 0xffffffff;
+
+    /* Create histogram */
+    for( i = 0; i < 256; ++ i )
+    {
+        histogram[ i ] = 0;
+    }
+    for( i = 0; i < insize; ++ i )
+    {
+        ++ histogram[ in[ i ] ];
+    }
+
+    /* Find the least common byte, and use it as the code marker */
+    marker = 0;
+    for( i = 1; i < 256; ++ i )
+    {
+        if( histogram[ i ] < histogram[ marker ] )
+        {
+            marker = i;
+        }
+    }
+
+    /* Remember the repetition marker for the decoder */
+    out[ 0 ] = marker;
+
+    /* Start of compression */
+    inpos = 0;
+    outpos = 1;
+
+    /* Main compression loop */
+    bytesleft = insize;
+    do
+    {
+        /* Get pointer to current position */
+        ptr1 = &in[ inpos ];
+
+        /* Search history window for maximum length string match */
+        bestlength = 3;
+        bestoffset = 0;
+        index = jumptable[ inpos ];
+        while( index != 0xffffffff )
+        {
+            /* Get pointer to candidate string */
+            ptr2 = &in[ index ];
+
+            /* Quickly determine if this is a candidate (for speed) */
+            if( ptr2[ bestlength ] == ptr1[ bestlength ] )
+            {
+                /* Determine maximum length for this offset */
+                offset = inpos - index;
+                maxlength = (bytesleft < offset ? bytesleft : offset);
+
+                /* Count maximum length match at this offset */
+                length = _LZ_StringCompare( ptr1, ptr2, 2, maxlength );
+
+                /* Better match than any previous match? */
+                if( length > bestlength )
+                {
+                    bestlength = length;
+                    bestoffset = offset;
+                }
+            }
+
+            /* Get next possible index from jump table */
+            index = jumptable[ index ];
+        }
+
+        /* Was there a good enough match? */
+        if( (bestlength >= 8) ||
+            ((bestlength == 4) && (bestoffset <= 0x0000007f)) ||
+            ((bestlength == 5) && (bestoffset <= 0x00003fff)) ||
+            ((bestlength == 6) && (bestoffset <= 0x001fffff)) ||
+            ((bestlength == 7) && (bestoffset <= 0x0fffffff)) )
+        {
+            out[ outpos ++ ] = (unsigned char) marker;
+            outpos += _LZ_WriteVarSize( bestlength, &out[ outpos ] );
+            outpos += _LZ_WriteVarSize( bestoffset, &out[ outpos ] );
+            inpos += bestlength;
+            bytesleft -= bestlength;
+        }
+        else
+        {
+            /* Output single byte (or two bytes if marker byte) */
+            symbol = in[ inpos ++ ];
+            out[ outpos ++ ] = symbol;
+            if( symbol == marker )
+            {
+                out[ outpos ++ ] = 0;
+            }
+            -- bytesleft;
+        }
+    }
+    while( bytesleft > 3 );
+
+    /* Dump remaining bytes, if any */
+    while( inpos < insize )
+    {
+        if( in[ inpos ] == marker )
+        {
+            out[ outpos ++ ] = marker;
+            out[ outpos ++ ] = 0;
+        }
+        else
+        {
+            out[ outpos ++ ] = in[ inpos ];
+        }
+        ++ inpos;
+    }
+
+    return outpos;
+}
+
+
+/*************************************************************************
+* LZ_Uncompress() - Uncompress a block of data using an LZ77 decoder.
+*  in      - Input (compressed) buffer.
+*  out     - Output (uncompressed) buffer. This buffer must be large
+*            enough to hold the uncompressed data.
+*  insize  - Number of input bytes.
+*************************************************************************/
+
+void LZ_Uncompress( unsigned char *in, unsigned char *out,
+    unsigned int insize )
+{
+    unsigned char marker, symbol;
+    unsigned int  i, inpos, outpos, length, offset;
+
+    /* Do we have anything to compress? */
+    if( insize < 1 )
+    {
+        return;
+    }
+
+    /* Get marker symbol from input stream */
+    marker = in[ 0 ];
+    inpos = 1;
+
+    /* Main decompression loop */
+    outpos = 0;
+    do
+    {
+        symbol = in[ inpos ++ ];
+        if( symbol == marker )
+        {
+            /* We had a marker byte */
+            if( in[ inpos ] == 0 )
+            {
+                /* It was a single occurrence of the marker byte */
+                out[ outpos ++ ] = marker;
+                ++ inpos;
+            }
+            else
+            {
+                /* Extract true length and offset */
+                inpos += _LZ_ReadVarSize( &length, &in[ inpos ] );
+                inpos += _LZ_ReadVarSize( &offset, &in[ inpos ] );
+
+                /* Copy corresponding data from history window */
+                for( i = 0; i < length; ++ i )
+                {
+                    out[ outpos ] = out[ outpos - offset ];
+                    ++ outpos;
+                }
+            }
+        }
+        else
+        {
+            /* No marker, plain copy */
+            out[ outpos ++ ] = symbol;
+        }
+    }
+    while( inpos < insize );
+}


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/source/compressor/lz.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + LF

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/source/compressor/lz.h
===================================================================
--- scummvm/branches/branch-0-9-0/backends/ds/arm9/source/compressor/lz.h	                        (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/ds/arm9/source/compressor/lz.h	2006-09-25 22:10:54 UTC (rev 23991)
@@ -0,0 +1,100 @@
+/*************************************************************************
+* Name:        lz.h
+* Author:      Marcus Geelnard
+* Description: LZ77 coder/decoder interface.
+* Reentrant:   Yes
+* $Id: lz.h 23452 2006-07-09 11:47:17Z fingolfin $
+*-------------------------------------------------------------------------
+* Copyright (c) 2003-2004 Marcus Geelnard
+*
+* 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.
+*
+* Marcus Geelnard
+* marcus.geelnard at home.se
+*************************************************************************/
+
+#ifndef _lz_h_
+#define _lz_h_
+
+
+
+/*************************************************************************
+* Function prototypes
+*************************************************************************/
+
+int LZ_Compress( unsigned char *in, unsigned char *out,
+                 unsigned int insize );
+int LZ_CompressFast( unsigned char *in, unsigned char *out,
+                     unsigned int insize, unsigned int *work );
+void LZ_Uncompress( unsigned char *in, unsigned char *out,
+                    unsigned int insize );
+
+
+#endif /* _lz_h_ */
+/*************************************************************************
+* Name:        lz.h
+* Author:      Marcus Geelnard
+* Description: LZ77 coder/decoder interface.
+* Reentrant:   Yes
+* $Id: lz.h 23452 2006-07-09 11:47:17Z fingolfin $
+*-------------------------------------------------------------------------
+* Copyright (c) 2003-2004 Marcus Geelnard
+*
+* 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.
+*
+* Marcus Geelnard
+* marcus.geelnard at home.se
+*************************************************************************/
+
+#ifndef _lz_h_
+#define _lz_h_
+
+
+
+/*************************************************************************
+* Function prototypes
+*************************************************************************/
+
+int LZ_Compress( unsigned char *in, unsigned char *out,
+                 unsigned int insize );
+int LZ_CompressFast( unsigned char *in, unsigned char *out,
+                     unsigned int insize, unsigned int *work );
+void LZ_Uncompress( unsigned char *in, unsigned char *out,
+                    unsigned int insize );
+
+
+#endif /* _lz_h_ */


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/source/compressor/lz.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + LF

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/source/console2.h
===================================================================
--- scummvm/branches/branch-0-9-0/backends/ds/arm9/source/console2.h	                        (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/ds/arm9/source/console2.h	2006-09-25 22:10:54 UTC (rev 23991)
@@ -0,0 +1,124 @@
+//////////////////////////////////////////////////////////////////////
+//
+// consol.h --provides basic consol type print functionality
+//
+// version 0.1, February 14, 2005
+//
+//  Copyright (C) 2005 Michael Noland (joat) and Jason Rogers (dovoto)
+//
+//  This software is provided 'as-is', without any express or implied
+//  warranty.  In no event will the authors be held liable for any
+//  damages arising from the use of this software.
+//
+//  Permission is granted to anyone to use this software for any
+//  purpose, including commercial applications, and to alter it and
+//  redistribute it freely, subject to the following restrictions:
+//
+//  1. The origin of this software must not be misrepresented; you
+//     must not claim that you wrote the original software. If you use
+//     this software in a product, an acknowledgment in the product
+//     documentation would be appreciated but is not required.
+//  2. Altered source versions must be plainly marked as such, and
+//     must not be misrepresented as being the original software.
+//  3. This notice may not be removed or altered from any source
+//     distribution.
+//
+// Changelog:
+//   0.1: First version
+//	 0.2: Fixed sprite mapping bug.  1D mapping should work now.  
+//			Changed some register defines for consistency.
+//
+//////////////////////////////////////////////////////////////////////
+#ifndef CONSOLE_H2
+#define CONSOLE_H2
+
+#define CONSOLE_USE_COLOR255 16
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void consoleInit(u16* font, u16* charBase, u16 numCharacters, u8 charStart, u16* map, u8 pal, u8 bitDepth);
+void consoleInitDefault(u16* map, u16* charBase, u8 bitDepth);
+
+void consolePrintf(const char* s, ...);
+
+void consolePrintSet(int x, int y);
+
+void consolePrintChar(char c);
+
+void consolePutString(int x, int y, char* s);
+void consolePutInt(int x, int y, int d);
+void consolePutX(int x, int y, int d);
+void consolePutChar(int x, int y, char c);
+void consolePutBin(int x, int y, int b);
+
+void consoleClear(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+//////////////////////////////////////////////////////////////////////
+//
+// consol.h --provides basic consol type print functionality
+//
+// version 0.1, February 14, 2005
+//
+//  Copyright (C) 2005 Michael Noland (joat) and Jason Rogers (dovoto)
+//
+//  This software is provided 'as-is', without any express or implied
+//  warranty.  In no event will the authors be held liable for any
+//  damages arising from the use of this software.
+//
+//  Permission is granted to anyone to use this software for any
+//  purpose, including commercial applications, and to alter it and
+//  redistribute it freely, subject to the following restrictions:
+//
+//  1. The origin of this software must not be misrepresented; you
+//     must not claim that you wrote the original software. If you use
+//     this software in a product, an acknowledgment in the product
+//     documentation would be appreciated but is not required.
+//  2. Altered source versions must be plainly marked as such, and
+//     must not be misrepresented as being the original software.
+//  3. This notice may not be removed or altered from any source
+//     distribution.
+//
+// Changelog:
+//   0.1: First version
+//	 0.2: Fixed sprite mapping bug.  1D mapping should work now.  
+//			Changed some register defines for consistency.
+//
+//////////////////////////////////////////////////////////////////////
+#ifndef CONSOLE_H2
+#define CONSOLE_H2
+
+#define CONSOLE_USE_COLOR255 16
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void consoleInit(u16* font, u16* charBase, u16 numCharacters, u8 charStart, u16* map, u8 pal, u8 bitDepth);
+void consoleInitDefault(u16* map, u16* charBase, u8 bitDepth);
+
+void consolePrintf(const char* s, ...);
+
+void consolePrintSet(int x, int y);
+
+void consolePrintChar(char c);
+
+void consolePutString(int x, int y, char* s);
+void consolePutInt(int x, int y, int d);
+void consolePutX(int x, int y, int d);
+void consolePutChar(int x, int y, char c);
+void consolePutBin(int x, int y, int b);
+
+void consoleClear(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif


Property changes on: scummvm/branches/branch-0-9-0/backends/ds/arm9/source/console2.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + LF

Added: scummvm/branches/branch-0-9-0/backends/ds/arm9/source/ds-fs.cpp
===================================================================
--- scummvm/branches/branch-0-9-0/backends/ds/arm9/source/ds-fs.cpp	                        (rev 0)
+++ scummvm/branches/branch-0-9-0/backends/ds/arm9/source/ds-fs.cpp	2006-09-25 22:10:54 UTC (rev 23991)
@@ -0,0 +1,868 @@
+/* ScummVMDS - Scumm Interpreter DS Port
+ * Copyright (C) 2002-2004 The ScummVM project and Neil Millstone
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ */
+
+
+#include "stdafx.h"
+#include "str.h"
+#include "fs.h"
+#include "common/util.h"
+#include <NDS/ARM9/console.h> //basic print funcionality
+#include "ds-fs.h"
+#include "dsmain.h"
+#include "gba_nds_fat.h"
+
+namespace DS {
+
+//////////////////////////////////////////////////////////////
+// DSFileSystemNode - Flash ROM file system using Zip files
+//////////////////////////////////////////////////////////////
+
+ZipFile*   	DSFileSystemNode::_zipFile = NULL;
+char		currentDir[128];
+
+DSFileSystemNode::DSFileSystemNode() {
+	_displayName = "ds:/";
+	_path = "ds:/";
+	_isValid = true;
+	_isDirectory = true;
+	_path = "ds:/";
+
+/*	if (!_archive) {
+		_archive = (GBFS_FILE *) find_first_gbfs_file(scummdata);
+		if (!_archive) consolePrintf("No GBFS archive found!\n");
+	}*/
+	
+	if (!_zipFile) {
+		_zipFile = new ZipFile();
+	}
+}
+
+DSFileSystemNode::DSFileSystemNode(const String& path) {
+//	consolePrintf("--%s ",path.c_str());
+	
+	char disp[128];
+	char* pathStr = (char *) path.c_str();
+	
+	
+	int lastSlash = 3;
+	for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {
+		if (path[r] == '\\') {
+			lastSlash = r;
+		}
+	}
+	
+	strcpy(disp, pathStr + lastSlash + 1);
+	
+	_displayName = String(disp);
+	_path = path;
+//	_isValid = true;
+//	_isDirectory = false;
+
+
+
+	if (!strncmp(pathStr, "ds:/", 4)) {
+		pathStr += 4;
+	}
+	
+
+	if (*pathStr == '\0') {
+		_isValid = true;
+		_isDirectory = true;
+		return;
+	}
+	
+	_zipFile->setAllFilesVisible(true);
+	if (_zipFile->findFile(pathStr)) {
+		_isValid = true;
+		_isDirectory = _zipFile->isDirectory();
+	} else {
+		_isValid = false;
+		_isDirectory = false;
+	}
+	_zipFile->setAllFilesVisible(false);
+	
+//	consolePrintf("%s - Found: %d, Dir: %d\n", pathStr, _isValid, _isDirectory);
+}
+
+DSFileSystemNode::DSFileSystemNode(const String& path, bool isDir) {
+//	consolePrintf("--%s ",path.c_str());
+	
+	char disp[128];
+	char* pathStr = (char *) path.c_str();
+	int lastSlash = 3;
+	for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {
+		if (path[r] == '\\') {
+			lastSlash = r;
+		}
+	}
+	
+	strcpy(disp, pathStr + lastSlash + 1);
+	
+	_displayName = String(disp);
+	_path = path;
+	_isValid = true;
+	_isDirectory = isDir;
+	
+//	consolePrintf("Found: %d, Dir: %d\n", _isValid, _isDirectory);
+}
+
+DSFileSystemNode::DSFileSystemNode(const DSFileSystemNode* node) {
+
+}
+
+AbstractFilesystemNode* DSFileSystemNode::parent() const {
+//	consolePrintf("parent\n");
+	DSFileSystemNode *p;
+
+	if (_path != "ds:/") {  
+		char *path = (char *) _path.c_str();
+		int lastSlash = 4;
+		
+		for (int r = 4; r < (int) strlen((char *) path); r++) {
+			if (path[r] == '\\') {
+				lastSlash = r;
+			}
+		}
+
+		p = new DSFileSystemNode(String(path, lastSlash));
+		((DSFileSystemNode *) (p))->_isDirectory = true;
+	} else {
+		p = new DSFileSystemNode();
+	}
+
+	return p;
+
+}
+
+
+AbstractFilesystemNode *DSFileSystemNode::child(const Common::String& n) const {
+	if (_path.lastChar() == '\\') {
+		return new DSFileSystemNode(_path + n);
+	} else {
+		return new DSFileSystemNode(_path + "\\" + n);
+	}
+	
+	return NULL;
+}
+
+
+bool DSFileSystemNode::listDir(AbstractFSList &dirList, ListMode mode) const {
+//	consolePrintf("Listdir\n");
+
+	
+//	consolePrintf("Directory\n");
+
+	
+	char temp[128];
+	strcpy(temp, _path.c_str());
+
+//	consolePrintf("This dir: %s\n", temp);
+
+	if ((temp[0] == 'd') && (temp[1] == 's') && (temp[2] == ':') && (temp[3] == '/')) {
+		if (strlen(temp) != 4) {
+			_zipFile->changeDirectory(&temp[4]);
+		} else {
+			_zipFile->changeToRoot();
+			
+/*			// This is the root dir, so add the RAM folder
+			DSFileSystemNode* dsfsn = new DSFileSystemNode("ds:/ram");
+			dsfsn->_isDirectory = true;
+			dirList->push_back(wrap(dsfsn));*/
+		}
+	} else {
+		_zipFile->changeDirectory(temp);
+	}
+	
+	
+	
+	if (_zipFile->restartFile()) {
+		do {
+			char n[128];	
+			_zipFile->getFileName(n);
+	
+//			consolePrintf("file: %s\n", n);
+			if ( (_zipFile->isDirectory() && ((mode == FilesystemNode::kListDirectoriesOnly) || (mode == FilesystemNode::kListAll)) ) 
+				|| (!_zipFile->isDirectory() && ((mode == FilesystemNode::kListFilesOnly) || (mode == FilesystemNode::kListAll)) ) ) 
+			{
+				DSFileSystemNode* dsfsn = new DSFileSystemNode("ds:/" + String(n), _zipFile->isDirectory());
+				dsfsn->_isDirectory = _zipFile->isDirectory();
+				dirList.push_back((dsfsn));
+			}
+			
+		} while (_zipFile->skipFile());
+	}
+
+	return true;
+}
+
+
+
+
+/////////////////////////////////////////////////////////////////////////
+// GBAMPFileSystemNode - File system using GBA Movie Player and CF card
+/////////////////////////////////////////////////////////////////////////
+
+GBAMPFileSystemNode::GBAMPFileSystemNode() {
+	_displayName = "mp:/";
+	_path = "mp:/";
+	_isValid = true;
+	_isDirectory = true;
+	_path = "mp:/";
+}
+
+GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path) {
+//	consolePrintf("'%s'",path.c_str());
+	
+	char disp[128];
+	char* pathStr = (char *) path.c_str();
+	int lastSlash = 3;
+	for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {
+		if ((path[r] == '\\') || (path[r] == '/')) {
+			lastSlash = r;
+		}
+	}
+	
+	strcpy(disp, pathStr + lastSlash + 1);
+
+	char check[128];
+	int success;
+	
+	memset(check, 0, 128);
+	if (strlen(pathStr) > 3) {
+		strcpy(check, pathStr + 3);
+		if (check[strlen(check) - 1] == '/') {
+			check[strlen(check) - 1] = 0;
+		}
+		success = FAT_FileExists(check);
+	} else {
+		success = FT_DIR;
+	}
+//	consolePrintf("Path: %s  (%d)\n", check, success);
+	
+	_displayName = String(disp);
+	_path = path;
+	_isValid = success == FT_FILE;
+	_isDirectory = success == FT_DIR;
+}
+
+GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path, bool isDirectory) {
+//	consolePrintf("'%s'",path.c_str());
+	
+	char disp[128];
+	char* pathStr = (char *) path.c_str();
+	int lastSlash = 3;
+	for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {
+		if ((path[r] == '\\') || (path[r] == '/')) {
+			lastSlash = r;
+		}
+	}
+	
+	strcpy(disp, pathStr + lastSlash + 1);
+
+	_displayName = String(disp);
+	_path = path;
+	_isValid = true;
+	_isDirectory = isDirectory;
+}
+
+
+GBAMPFileSystemNode::GBAMPFileSystemNode(const GBAMPFileSystemNode* node) {
+
+}
+
+
+AbstractFilesystemNode* GBAMPFileSystemNode::parent() const {
+//	consolePrintf("parent\n");
+	GBAMPFileSystemNode *p;
+
+	if (_path != "mp:/") {  
+		char *path = (char *) _path.c_str();
+		int lastSlash = 4;
+		
+		for (int r = 4; r < (int) strlen((char *) path); r++) {
+			if (path[r] == '/') {
+				lastSlash = r;
+			}
+		}
+
+		p = new GBAMPFileSystemNode(String(path, lastSlash));
+		p->_isDirectory = true;
+	} else {
+		p = new GBAMPFileSystemNode();
+	}
+
+	return p;
+
+}
+
+AbstractFilesystemNode *GBAMPFileSystemNode::child(const Common::String& n) const {
+	if (_path.lastChar() == '\\') {
+		return new DSFileSystemNode(_path + n);
+	} else {
+		return new DSFileSystemNode(_path + "\\" + n);
+	}
+	
+	return NULL;
+}
+
+bool GBAMPFileSystemNode::listDir(AbstractFSList& dirList, ListMode mode) const {
+//	consolePrintf("Listdir\n");
+
+	enum { TYPE_NO_MORE = 0, TYPE_FILE = 1, TYPE_DIR = 2 };
+	
+	char temp[128], fname[128], *path, *pathTemp;
+	strcpy(temp, _path.c_str());
+	
+	path = temp + 3;
+	
+	pathTemp = path;
+	while (*pathTemp) {
+		if (*pathTemp == '\\') {
+			*pathTemp = '/';
+		}
+		pathTemp++;
+	}
+
+
+//	consolePrintf("This dir: %s\n", path);
+	FAT_chdir(path);
+	
+	int entryType = FAT_FindFirstFile(fname);
+	
+	while (entryType != TYPE_NO_MORE) {
+	
+		if ( ((entryType == TYPE_DIR) && ((mode == FilesystemNode::kListDirectoriesOnly) || (mode == FilesystemNode::kListAll)))
+		||   ((entryType == TYPE_FILE) && ((mode == FilesystemNode::kListFilesOnly) || (mode == FilesystemNode::kListAll))) ) {
+			GBAMPFileSystemNode* dsfsn;
+			
+			if (strcmp(fname, ".") && strcmp(fname, "..")) {
+				
+				if (!strcmp(path, "/")) {
+					dsfsn = new GBAMPFileSystemNode("mp:" + String(path) + String(fname), entryType == TYPE_DIR);
+				} else {
+					dsfsn = new GBAMPFileSystemNode("mp:" + String(path) + String("/") + String(fname), entryType == TYPE_DIR);
+				}
+				
+//				dsfsn->_isDirectory = entryType == DIR;
+				dirList.push_back((dsfsn));
+			}
+		
+		
+		} else {
+//			consolePrintf("Skipping %s\n", fname);
+		}
+		
+		entryType = FAT_FindNextFile(fname);
+	}
+	
+//	consolePrintf("No more");
+	
+	FAT_chdir("/");
+
+	return true;
+}
+
+
+// Stdio replacements
+#define MAX_FILE_HANDLES 32
+
+bool inited = false;
+DS::fileHandle handle[MAX_FILE_HANDLES];
+
+FILE* std_fopen(const char* name, const char* mode) {
+
+	
+
+	if (!inited) {
+		for (int r = 0; r < MAX_FILE_HANDLES; r++) {
+			handle[r].used = false;
+		}
+		inited = true;
+		currentDir[0] = '\0';
+	}
+
+
+	
+	
+	char* realName = (char *) name;
+	
+	// Remove file system prefix
+	if ((name[0] == 'd') && (name[1] == 's') && (name[2] == ':') && (name[3] == '/')) {
+		realName += 4;
+	}
+
+	if ((name[0] == 'm') && (name[1] == 'p') && (name[2] == ':') && (name[3] == '/')) {
+		realName += 4;
+	}
+
+//	consolePrintf("Open file:");
+//	consolePrintf("'%s', [%s]", realName, mode);
+
+
+	if (DS::isGBAMPAvailable()) {
+		FAT_chdir("/");
+		
+		char* p = realName;
+		while (*p) {
+			if (*p == '\\') *p = '/';
+			p++;
+		}
+		
+		FAT_FILE* result = FAT_fopen(realName, mode);
+		
+		if (result == 0) {
+//			consolePrintf("Error code %d\n", result);
+			//consolePrintf("Opening file %s\n", realName);
+		} else {
+//			consolePrintf("Opened file %d\n", result);
+		}
+//		MT_memoryReport();
+		
+		return (fileHandle *) result;
+	}
+
+	
+	// Fail to open file for writing.  It's in ROM!
+
+	// Allocate a file handle
+	int r = 0;
+	while (handle[r].used) r++;
+	
+	if (strchr(mode, 'w')) {
+//		consolePrintf("Writing %s\n", realName);
+		handle[r].sramFile = (DSSaveFile *) DSSaveFileManager::instance()->openSavefile(realName, true);
+	} else {
+//		consolePrintf("Reading %s\n", realName);
+		handle[r].sramFile = (DSSaveFile *) DSSaveFileManager::instance()->openSavefile(realName, false);
+	}
+
+	
+	if (handle[r].sramFile) {
+		handle[r].used = true;
+		handle[r].pos = 0;
+		handle[r].data = NULL;
+		handle[r].size = handle[r].sramFile->getSize();
+//		consolePrintf("Found it");
+		return &handle[r];
+	} 
+
+//	consolePrintf("Not in SRAM!");
+
+	char* data;
+	
+	ZipFile* zip = DSFileSystemNode::getZip();
+	if (!zip) {
+//		consolePrintf("No zip yet!");
+		return NULL;
+	}
+	
+	// Grab the data if it exists
+	
+	zip->setAllFilesVisible(true);
+	
+	if (currentDir[0] != 0) {
+		char nameWithPath[128];
+		sprintf(nameWithPath, "%s\%s", currentDir, realName);
+		strcpy(realName, nameWithPath);
+	}
+
+//	consolePrintf("fopen(%s, %s)\n", realName, name);
+		
+	if (zip->findFile(realName)) {
+		data = zip->getFile();
+		zip->setAllFilesVisible(false);
+		
+		// Allocate a file handle
+		int r = 0;
+		while (handle[r].used) r++;
+	
+	
+		handle[r].used = true;
+		handle[r].pos = 0;
+		handle[r].data = data;
+		handle[r].size = zip->getFileSize();
+
+//		consolePrintf("Opened file %d: %s (%s)   ", r, realName, name);
+		return &handle[r];
+	} else {
+		zip->setAllFilesVisible(false);
+//		consolePrintf("Not found: %s (%s)  ", realName, name);
+		return NULL;
+	}
+}
+void std_fclose(FILE* handle) {
+
+	if (DS::isGBAMPAvailable()) {

@@ Diff output truncated at 100000 characters. @@

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list