diff options
Diffstat (limited to 'backends')
-rw-r--r-- | backends/fs/ds/ds-fs.cpp | 51 | ||||
-rw-r--r-- | backends/fs/ds/ds-fs.h | 8 | ||||
-rw-r--r-- | backends/platform/ds/arm9/makefile | 76 | ||||
-rw-r--r-- | backends/platform/ds/arm9/source/compressor/lz.cpp | 539 | ||||
-rw-r--r-- | backends/platform/ds/arm9/source/compressor/lz.h | 50 | ||||
-rw-r--r-- | backends/platform/ds/arm9/source/dsmain.cpp | 109 | ||||
-rw-r--r-- | backends/platform/ds/arm9/source/gbampsave.h | 1 | ||||
-rw-r--r-- | backends/platform/ds/arm9/source/libcartreset/cartreset.c | 107 | ||||
-rw-r--r-- | backends/platform/ds/arm9/source/libcartreset/cartreset_nolibfat.h | 57 | ||||
-rw-r--r-- | backends/platform/ds/arm9/source/osystem_ds.cpp | 20 | ||||
-rw-r--r-- | backends/platform/ds/arm9/source/osystem_ds.h | 4 | ||||
-rw-r--r-- | backends/platform/ds/arm9/source/ramsave.cpp | 538 | ||||
-rw-r--r-- | backends/platform/ds/arm9/source/ramsave.h | 155 | ||||
-rw-r--r-- | backends/platform/ds/module.mk | 15 |
14 files changed, 64 insertions, 1666 deletions
diff --git a/backends/fs/ds/ds-fs.cpp b/backends/fs/ds/ds-fs.cpp index 43203eed54..675084ff56 100644 --- a/backends/fs/ds/ds-fs.cpp +++ b/backends/fs/ds/ds-fs.cpp @@ -542,27 +542,6 @@ FILE *std_fopen(const char *name, const char *mode) { assert(r < MAX_FILE_HANDLES); } -#ifdef GBA_SRAM_SAVE - if (strchr(mode, 'w')) { -// consolePrintf("Writing %s\n", realName); - s_handle[r].sramFile = DSSaveFileManager::instance()->openSavefile(realName, true); - } else { -// consolePrintf("Reading %s\n", realName); - s_handle[r].sramFile = DSSaveFileManager::instance()->openSavefile(realName, false); - } -#endif - - if (s_handle[r].sramFile) { - s_handle[r].used = true; - s_handle[r].pos = 0; - s_handle[r].data = NULL; - s_handle[r].size = s_handle[r].sramFile->getSize(); -// consolePrintf("Found it"); - return &s_handle[r]; - } - -// consolePrintf("Not in SRAM!"); - char *data; ZipFile *zip = DSFileSystemNode::getZip(); @@ -615,10 +594,6 @@ void std_fclose(FILE *handle) { } handle->used = false; - if (handle->sramFile) { - delete handle->sramFile; - handle->sramFile = NULL; - } } size_t std_fread(void *ptr, size_t size, size_t numItems, FILE *handle) { @@ -638,21 +613,6 @@ size_t std_fread(void *ptr, size_t size, size_t numItems, FILE *handle) { return numItems; } - if (handle->sramFile) { - int bytes = 0; - int result = 1; - //consolePrintf("fread size=", size * numItems); - for (int r = 0; (r < (s32) size * (s32) numItems) && (result > 0); r++) { - result = handle->sramFile->read((void *) ( ((char *) (ptr)) + r), 1); - bytes += result; - //consolePrintf("'%d',", ((char *) (ptr))[0]); - } - - handle->pos += bytes; - - return bytes / size; - } - if (handle->pos > handle->size) numItems = 0; else if ((int)(handle->pos + size * numItems) > handle->size) @@ -695,12 +655,7 @@ size_t std_fwrite(const void *ptr, size_t size, size_t numItems, FILE *handle) { return numItems; } - if (handle->sramFile) { - handle->sramFile->write(ptr, size); - return size; - } else { - return 0; - } + return 0; } bool std_feof(FILE *handle) { @@ -710,10 +665,6 @@ bool std_feof(FILE *handle) { return readPastEndOfFile && FAT_feof((FAT_FILE *) handle); } - if (handle->sramFile) { - return handle->sramFile->eos(); - } - // consolePrintf("feof %s", handle->pos >= handle->size? "true": "false"); return handle->pos >= handle->size; } diff --git a/backends/fs/ds/ds-fs.h b/backends/fs/ds/ds-fs.h index fadfb8a40d..6961022848 100644 --- a/backends/fs/ds/ds-fs.h +++ b/backends/fs/ds/ds-fs.h @@ -26,12 +26,12 @@ #ifndef _DS_FS_H #define _DS_FS_H -//#include <NDS/ARM9/console.h> #include "common/fs.h" +#include "common/stream.h" +#include "backends/fs/abstract-fs.h" + #include "zipreader.h" -#include "ramsave.h" #include "fat/gba_nds_fat.h" -#include "backends/fs/abstract-fs.h" namespace DS { @@ -166,8 +166,6 @@ struct fileHandle { bool used; char *data; int size; - - DSSaveFile *sramFile; }; diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index 31be40f680..703d5d69b7 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -253,7 +253,7 @@ endif INCLUDES= -I$(portdir)/$(BUILD) -I$(srcdir) -I$(srcdir)/engines \ -I$(portdir)/data -I$(portdir)/../commoninclude \ - -I$(portdir)/source -I$(portdir)/source/mad -I$(portdir)/source/libcartreset \ + -I$(portdir)/source -I$(portdir)/source/mad \ -I$(libndsdir)/include -include $(srcdir)/common/scummsys.h @@ -286,46 +286,58 @@ PRE_OBJS_FLAGS = -Wl,--whole-archive POST_OBJS_FLAGS = -Wl,--no-whole-archive endif -PORT_OBJS := $(portdir)/source/blitters_arm.o $(portdir)/source/cdaudio.o $(portdir)/source/dsmain.o \ - $(portdir)/../../../fs/ds/ds-fs.o $(portdir)/source/gbampsave.o $(portdir)/source/scummhelp.o\ - $(portdir)/source/osystem_ds.o $(portdir)/source/ramsave.o\ - $(portdir)/source/touchkeyboard.o $(portdir)/source/zipreader.o\ - $(portdir)/source/dsoptions.o $(portdir)/source/keys.o $(portdir)/source/wordcompletion.o\ - $(portdir)/source/interrupt.o +PORT_OBJS := \ + $(portdir)/source/blitters_arm.o \ + $(portdir)/source/cdaudio.o \ + $(portdir)/source/dsmain.o \ + $(portdir)/../../../fs/ds/ds-fs.o \ + $(portdir)/source/gbampsave.o \ + $(portdir)/source/scummhelp.o \ + $(portdir)/source/osystem_ds.o \ + $(portdir)/source/touchkeyboard.o \ + $(portdir)/source/zipreader.o \ + $(portdir)/source/dsoptions.o \ + $(portdir)/source/keys.o \ + $(portdir)/source/wordcompletion.o \ + $(portdir)/source/interrupt.o ifdef USE_PROFILER PORT_OBJS += $(portdir)/source/profiler/cyg-profile.o endif -DATA_OBJS := $(portdir)/data/icons.o $(portdir)/data/keyboard.o $(portdir)/data/keyboard_pal.o $(portdir)/data/default_font.o $(portdir)/data/8x8font_tga.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_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_m3_common.o \ - $(portdir)/source/fat/io_dldi.o \ - $(portdir)/source/fat/m3sd.o +DATA_OBJS := + $(portdir)/data/icons.o \ + $(portdir)/data/keyboard.o \ + $(portdir)/data/keyboard_pal.o \ + $(portdir)/data/default_font.o \ + $(portdir)/data/8x8font_tga.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_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_m3_common.o \ + $(portdir)/source/fat/io_dldi.o \ + $(portdir)/source/fat/m3sd.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 $(portdir)/source/fat/io_sd_common.o -LIBCARTRESET_OBJS := -#$(portdir)/source/libcartreset/cartreset.o - # Files in this list will be optimisied for speed, otherwise they will be optimised for space -OPTLIST := actor.cpp ds_main.cpp osystem_ds.cpp blitters.cpp mame.cpp rate.cpp isomap.cpp image.cpp gfx.cpp sprite.cpp actor_path.cpp actor_walk.cpp script.cpp +OPTLIST := actor.cpp dsmain.cpp osystem_ds.cpp blitters.cpp mame.cpp rate.cpp isomap.cpp image.cpp gfx.cpp sprite.cpp actor_path.cpp actor_walk.cpp script.cpp #OPTLIST := # Compiler options for files which should be optimised for speed @@ -333,18 +345,14 @@ ifdef DS_BUILD_E # Another attempt to save some RAM in ITE OPT_SPEED := -O3 -mthumb else - #OPT_SPEED := -O3 - OPT_SPEED := -Os -mthumb + OPT_SPEED := -O3 endif # Compiler options for files which should be optimised for space OPT_SIZE := -Os -mthumb -#-mthumb -fno-gcse -fno-schedule-insns2 - - -OBJS := $(DATA_OBJS) $(LIBCARTRESET_OBJS) $(PORT_OBJS) $(COMPRESSOR_OBJS) $(FAT_OBJS) +OBJS := $(DATA_OBJS) $(PORT_OBJS) $(FAT_OBJS) diff --git a/backends/platform/ds/arm9/source/compressor/lz.cpp b/backends/platform/ds/arm9/source/compressor/lz.cpp deleted file mode 100644 index 47a36646c6..0000000000 --- a/backends/platform/ds/arm9/source/compressor/lz.cpp +++ /dev/null @@ -1,539 +0,0 @@ -/************************************************************************* -* Name: lz.c -* Author: Marcus Geelnard -* Description: LZ77 coder/decoder implementation. -* Reentrant: Yes -* $Id$ -* -* 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 ); -} diff --git a/backends/platform/ds/arm9/source/compressor/lz.h b/backends/platform/ds/arm9/source/compressor/lz.h deleted file mode 100644 index e7ea1567ca..0000000000 --- a/backends/platform/ds/arm9/source/compressor/lz.h +++ /dev/null @@ -1,50 +0,0 @@ -/************************************************************************* -* Name: lz.h -* Author: Marcus Geelnard -* Description: LZ77 coder/decoder interface. -* Reentrant: Yes -* $Id$ -*------------------------------------------------------------------------- -* 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_ */ diff --git a/backends/platform/ds/arm9/source/dsmain.cpp b/backends/platform/ds/arm9/source/dsmain.cpp index 8d51eff3da..95bfdfe40a 100644 --- a/backends/platform/ds/arm9/source/dsmain.cpp +++ b/backends/platform/ds/arm9/source/dsmain.cpp @@ -73,8 +73,6 @@ -//#define USE_LIBCARTRESET - #include <nds.h> #include <nds/registers_alt.h> #include <nds/arm9/exceptions.h> @@ -100,9 +98,7 @@ #ifdef USE_DEBUGGER #include "user_debugger.h" #endif -#include "ramsave.h" #include "blitters.h" -#include "libcartreset/cartreset_nolibfat.h" #include "keys.h" #ifdef USE_PROFILER #include "profiler/cyg-profile.h" @@ -2775,31 +2771,6 @@ GLvector getPenPos() { return v; } -#ifdef GBA_SRAM_SAVE - -void formatSramOption() { - consolePrintf("The following files are present in save RAM:\n"); - DSSaveFileManager::instance()->listFiles(); - - consolePrintf("\nAre you sure you want to\n"); - consolePrintf("DELETE all files?\n"); - consolePrintf("A = Yes, X = No\n"); - - while (true) { - if (keysHeld() & KEY_A) { - DSSaveFileManager::instance()->formatSram(); - consolePrintf("SRAM cleared!\n"); - return; - } - - if (keysHeld() & KEY_X) { - consolePrintf("Whew, that was close!\n"); - return; - } - } -} -#endif - void setIndyFightState(bool st) { indyFightState = st; indyFightRight = true; @@ -2884,61 +2855,6 @@ void debug_print_stub(char *string) { } #endif -#ifdef USE_LIBCARTRESET - -struct cardTranslate { - int cartResetId; - int svmId; - char dldiId[5]; -}; - -cardTranslate cardReaderTable[] = { - {DEVICE_TYPE_M3SD, DEVICE_M3SD, "M3SD"}, - {DEVICE_TYPE_M3CF, DEVICE_M3CF, "M3CF"}, - {DEVICE_TYPE_MPCF, DEVICE_MPCF, "MPCF"}, - {DEVICE_TYPE_SCCF, DEVICE_SCCF, "SCCF"}, - {DEVICE_TYPE_SCSD, DEVICE_SCSD, "SCSD"}, - {DEVICE_TYPE_SCSD, DEVICE_SCSD, "SCLT"}, - {DEVICE_TYPE_NMMC, DEVICE_NMMC, "NMMC"}, -}; - -void reboot() { - int deviceType = -1; - - - if (disc_getDeviceId() == DEVICE_DLDI) { - - char id[6]; - disc_getDldiId(id); - - consolePrintf("DLDI Device ID: %s\n", id); - - for (int r = 0; r < ARRAYSIZE(cardReaderTable); r++) { - if (!stricmp(id, cardReaderTable[r].dldiId)) { - deviceType = cardReaderTable[r].cartResetId; - } - } - } else { - for (int r = 0; r < ARRAYSIZE(cardReaderTable); r++) { - if (disc_getDeviceId() == cardReaderTable[r].svmId) { - deviceType = cardReaderTable[r].cartResetId; - } - } - } - - - consolePrintf("Device number: %x\n", deviceType); - - if (deviceType == -1) { - IPC->reset = true; // Send message to ARM7 to turn power off - } else { - cartSetMenuMode(deviceType); - passmeloopEnter(); - } - - while (true); // Stop the program continuing beyond this point -} -#endif void powerOff() { while (keysHeld() != 0) { // Wait for all keys to be released. @@ -2953,12 +2869,10 @@ void powerOff() { while (true); } else { -#ifdef USE_LIBCARTRESET - reboot(); -#else IPC->reset = true; // Send message to ARM7 to turn power off - while (true); // Stop the program continuing beyond this point -#endif + while (true) { + // Stop the program from continuing beyond this point + } } } @@ -2979,7 +2893,7 @@ void dsExceptionHandler() { int offset = 8; - if ( currentMode == 0x17 ) { + if (currentMode == 0x17) { consolePrintf("\x1b[10Cdata abort!\n\n"); codeAddress = exceptionRegisters[15] - offset; if ( (codeAddress > 0x02000000 && codeAddress < 0x02400000) || @@ -3002,16 +2916,19 @@ void dsExceptionHandler() { int i; - for ( i=0; i < 8; i++ ) { + for (i = 0; i < 8; i++) { consolePrintf(" %s: %08X %s: %08X\n", registerNames[i], exceptionRegisters[i], registerNames[i+8],exceptionRegisters[i+8]); } - while(1); + + while(1) + ; // endles loop + u32 *stack = (u32 *)exceptionRegisters[13]; - for ( i=0; i<10; i++ ) { + for (i = 0; i < 10; i++) { consolePrintf("%08X %08X %08X\n", stack[i*3], stack[i*3+1], stack[(i*3)+2] ); } @@ -3262,12 +3179,6 @@ int main(void) { g_system = new OSystem_DS(); assert(g_system); -#ifdef GBA_SRAM_SAVE - if ((keysHeld() & KEY_L) && (keysHeld() & KEY_R)) { - formatSramOption(); - } -#endif - IPC->adpcm.semaphore = false; // printf("'%s'", Common::ConfigManager::kTransientDomain.c_str()); diff --git a/backends/platform/ds/arm9/source/gbampsave.h b/backends/platform/ds/arm9/source/gbampsave.h index fd16b72e4c..ad929236cd 100644 --- a/backends/platform/ds/arm9/source/gbampsave.h +++ b/backends/platform/ds/arm9/source/gbampsave.h @@ -27,6 +27,7 @@ #define _GBAMPSAVE_H_ #include "common/system.h" +#include "common/savefile.h" #include "backends/fs/ds/ds-fs.h" #define SAVE_BUFFER_SIZE 100000 diff --git a/backends/platform/ds/arm9/source/libcartreset/cartreset.c b/backends/platform/ds/arm9/source/libcartreset/cartreset.c deleted file mode 100644 index 6fb906b86d..0000000000 --- a/backends/platform/ds/arm9/source/libcartreset/cartreset.c +++ /dev/null @@ -1,107 +0,0 @@ -/********************************** - Copyright (C) Rick Wong (Lick) - http://licklick.wordpress.com/ -***********************************/ -#include <cartreset_nolibfat.h> - - -#ifdef ARM9 - -bool cartSetMenuMode(u32 _deviceType) -{ - *(vu16*)(0x04000204) &= ~0x0880; //sysSetBusOwners(true, true); - u32 deviceType = _deviceType; - - *((vu32*)0x027FFFF8) = 0x080000C0; // ARM7 reset address - - if(deviceType == DEVICE_TYPE_EFA2) - { - *(u16 *)0x9FE0000 = 0xD200; - *(u16 *)0x8000000 = 0x1500; - *(u16 *)0x8020000 = 0xD200; - *(u16 *)0x8040000 = 0x1500; - *(u16 *)0x9880000 = 1 << 15; - *(u16 *)0x9FC0000 = 0x1500; - return true; - } - else if(deviceType == DEVICE_TYPE_MPCF) - { - return true; - } - else if(deviceType == DEVICE_TYPE_EZSD) - { - return true; - } - else if(deviceType == DEVICE_TYPE_M3CF || deviceType == DEVICE_TYPE_M3SD) - { - u32 mode = 0x00400004; - vu16 tmp; - tmp = *(vu16*)(0x08E00002); - tmp = *(vu16*)(0x0800000E); - tmp = *(vu16*)(0x08801FFC); - tmp = *(vu16*)(0x0800104A); - tmp = *(vu16*)(0x08800612); - tmp = *(vu16*)(0x08000000); - tmp = *(vu16*)(0x08801B66); - tmp = *(vu16*)(0x08000000 + (mode << 1)); - tmp = *(vu16*)(0x0800080E); - tmp = *(vu16*)(0x08000000); - - tmp = *(vu16*)(0x080001E4); - tmp = *(vu16*)(0x080001E4); - tmp = *(vu16*)(0x08000188); - tmp = *(vu16*)(0x08000188); - return true; - } - else if(deviceType == DEVICE_TYPE_SCCF || deviceType == DEVICE_TYPE_SCSD) - { - *(vu16*)0x09FFFFFE = 0xA55A; - *(vu16*)0x09FFFFFE = 0xA55A; - *(vu16*)0x09FFFFFE = 0; - *(vu16*)0x09FFFFFE = 0; - *((vu32*)0x027FFFF8) = 0x08000000; // Special ARM7 reset address - return true; - } - - return false; -} - - - -void passmeloopEnter() -{ - *(vu16*)(0x04000208) = 0; //REG_IME = IME_DISABLE; - *(vu16*)(0x04000204) |= 0x0880; //sysSetBusOwners(false, false); - *((vu32*)0x027FFFFC) = 0; - *((vu32*)0x027FFE04) = (u32)0xE59FF018; - *((vu32*)0x027FFE24) = (u32)0x027FFE04; - asm("swi 0x00"); //swiSoftReset(); - asm("bx lr"); -} - -#endif - - -#ifdef ARM7 - -bool passmeloopQuery() -{ - if(*((vu32*)0x027FFE24) == (u32)0x027FFE04) - return true; - return false; -} - - - -void cartExecute() -{ - *(vu16*)(0x04000208) = 0; //REG_IME = IME_DISABLE; - *((vu32*)0x027FFE34) = *((vu32*)0x027FFFF8); - asm("swi 0x00"); //swiSoftReset(); - asm("bx lr"); -} - -#endif - - - diff --git a/backends/platform/ds/arm9/source/libcartreset/cartreset_nolibfat.h b/backends/platform/ds/arm9/source/libcartreset/cartreset_nolibfat.h deleted file mode 100644 index ddc4b1d4c2..0000000000 --- a/backends/platform/ds/arm9/source/libcartreset/cartreset_nolibfat.h +++ /dev/null @@ -1,57 +0,0 @@ -/********************************** - Copyright (C) Rick Wong (Lick) - http://licklick.wordpress.com/ -***********************************/ -#ifndef CARTRESET_H -#define CARTRESET_H - -//#include <fat.h> -#include <nds.h> - - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef ARM9 -// Auto detect: -#define DEVICE_TYPE_AUTO 0x00000000 // doesn't work in libcartreset "nolibfat" version - -// Not supported: -#define DEVICE_TYPE_FCSR 0x52534346 -#define DEVICE_TYPE_MMCF 0x46434D4D -#define DEVICE_TYPE_NJSD 0x44534A4E -#define DEVICE_TYPE_NMMC 0x434D4D4E - -// Supported: -#define DEVICE_TYPE_EFA2 0x32414645 -#define DEVICE_TYPE_MPCF 0x4643504D -#define DEVICE_TYPE_M3CF 0x4643334D -#define DEVICE_TYPE_M3SD 0x4453334D -#define DEVICE_TYPE_SCCF 0x46434353 -#define DEVICE_TYPE_SCSD 0x44534353 - -// Supported, but libfat doesn't detect the device: -#define DEVICE_TYPE_EZSD 0x44535A45 - - -bool cartSetMenuMode(u32 _deviceType); -void passmeloopEnter(); - -#endif - - -#ifdef ARM7 - -bool passmeloopQuery(); -void cartExecute(); - -#endif - - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/backends/platform/ds/arm9/source/osystem_ds.cpp b/backends/platform/ds/arm9/source/osystem_ds.cpp index 09617c17b0..55475b0bff 100644 --- a/backends/platform/ds/arm9/source/osystem_ds.cpp +++ b/backends/platform/ds/arm9/source/osystem_ds.cpp @@ -729,26 +729,10 @@ void OSystem_DS::quit() { } Common::SaveFileManager *OSystem_DS::getSavefileManager() { - bool forceSram; - - if (ConfMan.hasKey("forcesramsave", "ds")) { - forceSram = ConfMan.getBool("forcesramsave", "ds"); - } else { - forceSram = false; - } - if (forceSram) { - consolePrintf("Using SRAM save method!\n"); - } - - if (DS::isGBAMPAvailable() && (!forceSram)) { + if (DS::isGBAMPAvailable()) { return &mpSaveManager; - } else { -#ifdef GBA_SRAM_SAVE - return &saveManager; -#else - return NULL; -#endif } + return NULL; } diff --git a/backends/platform/ds/arm9/source/osystem_ds.h b/backends/platform/ds/arm9/source/osystem_ds.h index a899c966fc..65ac3f4f7e 100644 --- a/backends/platform/ds/arm9/source/osystem_ds.h +++ b/backends/platform/ds/arm9/source/osystem_ds.h @@ -30,7 +30,6 @@ #include "backends/base-backend.h" #include "common/events.h" #include "nds.h" -#include "ramsave.h" #include "gbampsave.h" #include "backends/saves/default/default-saves.h" #include "backends/timer/default/default-timer.h" @@ -47,9 +46,6 @@ protected: Common::Event eventQueue[96]; int queuePos; -#ifdef GBA_SRAM_SAVE - DSSaveFileManager saveManager; -#endif GBAMPSaveFileManager mpSaveManager; Audio::MixerImpl *_mixer; DefaultTimerManager *_timer; diff --git a/backends/platform/ds/arm9/source/ramsave.cpp b/backends/platform/ds/arm9/source/ramsave.cpp deleted file mode 100644 index d8e74d7445..0000000000 --- a/backends/platform/ds/arm9/source/ramsave.cpp +++ /dev/null @@ -1,538 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * 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. - * - */ -#ifdef GBA_SRAM_SAVE - - -#include "ramsave.h" -#include "nds.h" -#include "compressor/lz.h" - -#define CART_RAM ((vu8 *) (0x0A000000)) -#define SRAM_SAVE_MAX (65533) - -DSSaveFile::DSSaveFile() { - ptr = 0; - saveCompressed = false; - save.isValid = false; - ownsData = false; - isOpenFlag = true; - isTempFile = false; -} - -DSSaveFile::DSSaveFile(SCUMMSave *s, bool compressed, u8 *data) { - save = *s; - saveData = data; - ptr = 0; - saveCompressed = compressed; - isOpenFlag = true; - - if (saveCompressed) { - u8 *uncompressed = new unsigned char[save.size]; - if (!uncompressed) consolePrintf("Out of memory allocating %d!\n", save.size); - LZ_Uncompress(saveData, uncompressed, save.compressedSize); - saveData = uncompressed; - ownsData = true; - saveCompressed = false; -// consolePrintf("Decompressed. name=%s size=%d (%d)", save.name, save.size, save.compressedSize); - - } else { - ownsData = false; - origHeader = s; - } - - if (save.magic == (int) 0xBEEFCAFE) { - save.isValid = true; - } else { - save.isValid = false; - } - - isTempFile = false; - eosReached = false; -} - -DSSaveFile::~DSSaveFile() { - if (!ownsData) { - *origHeader = save; - DSSaveFileManager::instance()->flushToSaveRAM(); - } - if (ownsData) { - delete[] saveData; - } -} - -bool DSSaveFile::loadFromSaveRAM(vu8 *address) { - - SCUMMSave newSave; - - for (int t = 0; t < (int) sizeof(newSave); t++) { - ((char *) (&newSave))[t] = *(address + t); - } - - if (newSave.magic == 0xBEEFCAFE) { - newSave.isValid = true; - - *((u16 *) (0x4000204)) |= 0x3; - - saveData = new unsigned char[newSave.compressedSize]; - - for (int t = 0; t < (int) newSave.compressedSize; t++) { - ((char *) (saveData))[t] = *(address + t + sizeof(newSave)); - } - - if (ownsData) delete[] this->saveData; - save = newSave; - saveCompressed = true; - this->saveData = saveData; - ownsData = true; - ptr = 0; - - return true; - } - - return false; -} - -void DSSaveFile::compress() { - if (!saveCompressed) { - unsigned char *compBuffer = new unsigned char[(save.size * 110) / 100]; - int compSize = LZ_Compress((u8 *) saveData, compBuffer, save.size); - save.compressedSize = compSize; - - - - delete[] saveData; - - // Make the save smaller - saveData = (u8 *) realloc(compBuffer, save.compressedSize); - saveCompressed = true; - } -} - -int DSSaveFile::saveToSaveRAM(vu8 *address) { - - unsigned char *compBuffer; - bool failed; - - - int compSize; - - compress(); - - compSize = save.compressedSize; - compBuffer = saveData; - - if (DSSaveFileManager::instance()->getBytesFree() >= getRamUsage()) { - - DSSaveFileManager::instance()->addBytesFree(-getRamUsage()); - - // Write header - for (int t = 0; t < sizeof(save); t++) { - while (*(address + t) != ((char *) (&save))[t]) { - *(address + t) = ((char *) (&save))[t]; - } - } - - // Write compressed buffer - for (int t = sizeof(save); t < (int) sizeof(save) + compSize; t++) { - while (*(address + t) != compBuffer[t - sizeof(save)]) { - *(address + t) = compBuffer[t - sizeof(save)]; - } - } - - failed = false; - } else { - failed = true; - } - - - return failed? 0: compSize + sizeof(save); - -} - -void DSSaveFile::reset() { - ptr = 0; - eosReached = false; -} - -uint32 DSSaveFile::read(void *buf, uint32 size) { - if (ptr + size > save.size) { - size = save.size - ptr; - eosReached = true; - if (size < 0) size = 0; - } - memcpy(buf, saveData + ptr, size); -// consolePrintf("byte: %d ", ((u8 *) (buf))[0]); - - ptr += size; - return size; -} - -int32 DSSaveFile::pos() const { - return ptr; -} - -int32 DSSaveFile::size() const { - return save.size; -} - -bool DSSaveFile::seek(int32 pos, int whence) { - switch (whence) { - case SEEK_SET: { - ptr = pos; - break; - } - case SEEK_CUR: { - ptr += pos; - break; - } - case SEEK_END: { - ptr = save.size + pos; - break; - } - } - eosReached = false; - return true; -} - -bool DSSaveFile::eos() const { - return eosReached; -} - -void DSSaveFile::clearErr() { - eosReached = false; -} - -bool DSSaveFile::skip(uint32 bytes) { - ptr = ptr + bytes; - if (ptr > (int) save.size) ptr = save.size; - return true; -} - -uint32 DSSaveFile::write(const void *buf, uint32 size) { - - if (ptr + size > DS_MAX_SAVE_SIZE) { - size = DS_MAX_SAVE_SIZE - ptr; - } - - memcpy(saveData + ptr, buf, size); - ptr += size; - save.size += size; - return size; -} - -bool DSSaveFile::matches(const char *prefix, int num) { - char str[16]; - if (isValid()) { - sprintf(str, "%s%02d", prefix, num); - if (!strcmp(str, save.name)) { - return true; - } else { - return false; - } - } else { - return false; - } -} - -bool DSSaveFile::matches(const char *filename) { - if (isValid()) { - return !strcmp(save.name, filename); - } else { - return false; - } -} - -void DSSaveFile::setName(char *name) { - save.isValid = true; - save.magic = 0xBEEFCAFE; - ownsData = true; - save.size = 0; - save.compressedSize = 0; - saveData = new unsigned char[DS_MAX_SAVE_SIZE]; - strcpy(save.name, name); - - if ((strstr(name, ".s99")) || (strstr(name, ".c"))) { - isTempFile = true; - } else { - isTempFile = false; - } -} - -void DSSaveFile::clearData() { - save.size = 0; - - if (saveCompressed) { - if (ownsData) { - delete[] saveData; - DSSaveFileManager::instance()->addBytesFree(getRamUsage()); - } - saveData = new unsigned char[DS_MAX_SAVE_SIZE]; - saveCompressed = false; - ownsData = true; - } - -} - -void DSSaveFile::deleteFile() { - if (isValid()) { - if (ownsData) { - DSSaveFileManager::instance()->addBytesFree(getRamUsage()); - delete[] saveData; - saveData = NULL; - } - ptr = 0; - saveCompressed = false; - save.isValid = false; - ownsData = false; - isOpenFlag = true; - } -} - -DSSaveFileManager::DSSaveFileManager() { - instancePtr = this; - - *((u16 *) (0x4000204)) |= 0x3; - swiWaitForVBlank(); - - loadAllFromSRAM(); -} - -DSSaveFileManager::~DSSaveFileManager() { - instancePtr = NULL; -} - -void DSSaveFileManager::loadAllFromSRAM() { - int addr = 1; - - for (int r = 0; r < 8; r++) { - gbaSave[r].deleteFile(); - } - - sramBytesFree = SRAM_SAVE_MAX; - - // Try to find saves in save RAM - for (int r = 0; r < 8; r++) { - if (gbaSave[r].loadFromSaveRAM(CART_RAM + addr)) { - addr += gbaSave[r].getRamUsage(); - sramBytesFree -= gbaSave[r].getRamUsage(); - } - } - -} - -void DSSaveFileManager::formatSram() { - for (int r = 0; r < SRAM_SAVE_MAX; r++) { - *(CART_RAM + r) = 0; - } - - loadAllFromSRAM(); -} - -void DSSaveFileManager::listFiles() { - for (int r = 0; r < 8; r++) { - if (gbaSave[r].isValid()) { - consolePrintf("'%s': %d bytes\n", gbaSave[r].getName(), gbaSave[r].getRamUsage()); - } - } - consolePrintf("SRAM free: %d bytes\n", getBytesFree()); -} - -DSSaveFileManager *DSSaveFileManager::instancePtr = NULL; - -DSSaveFile *DSSaveFileManager::openSavefile(const char *filename, bool saveOrLoad) { - for (int r = 0; r < 8; r++) { - if (gbaSave[r].isValid() && (gbaSave[r].matches(filename))) { -// consolePrintf("Matched save %d (%d)\n", r, gbaSave[r].getSize()); - gbaSave[r].reset(); - //consolePrintf("reset "); - if (saveOrLoad) gbaSave[r].clearData(); -// consolePrintf("cleared "); - return gbaSave[r].clone(); - } - } - - if (saveOrLoad) { - return makeSaveFile(filename, saveOrLoad); - } else { - return NULL; - } -} - - - -DSSaveFile *DSSaveFile::clone() { -// consolePrintf("Clone %s %d\n", save.name, save.size); - return new DSSaveFile(&save, saveCompressed, saveData); -} - -void DSSaveFileManager::deleteFile(const char *name) { -// consolePrintf("Deleting %s", name); - for (int r = 0; r < 8; r++) { - if (gbaSave[r].isValid() && (gbaSave[r].matches(name))) { - gbaSave[r].deleteFile(); - } - } - flushToSaveRAM(); -} - -bool DSSaveFileManager::removeSavefile(const Common::String &filename) { - consolePrintf("DSSaveFileManager::removeSavefile : Not implemented yet.\n"); - assert(false); - //TODO: Implement this. Most likely, you just have to use the code of deleteFile? - return false; -} - - -Common::StringArray DSSaveFileManager::listSavefiles(const Common::String &pattern) { - consolePrintf("DSSaveFileManager::listSavefiles : Not implemented yet.\n"); - assert(false); - return Common::StringArray(); - /* - TODO: Implement this. If you don't understand what it should do, just ask - (e.g. on scummvm-devel or Fingolfin). It should be pretty simple if you - use Common::matchString from common/util.h and read the Doxygen docs, - then combine this with the old code below... - */ -} - - -/* -void DSSaveFileManager::listSavefiles(const char *prefix, bool *marks, int num) { - memset(marks, true, num * sizeof(bool)); - return; - - memset(marks, false, num*sizeof(bool)); - - for (int saveNum = 0; saveNum < num; saveNum++) { - for (int r = 0; r < 8; r++) { - if (gbaSave[r].isValid() && (gbaSave[r].matches(prefix, saveNum))) { - marks[saveNum] = true; - } - } - } - -} -*/ - - -DSSaveFile *DSSaveFileManager::makeSaveFile(const char *filename, bool saveOrLoad) { - - // Find a free save slot - int r = 0; - - while ((r < 8) && (gbaSave[r].isValid())) { - r++; - } - - if ((r == 8) && (gbaSave[r].isValid())) { - // No more saves - return NULL; - } else { - // Allocate this save -// consolePrintf("Allocated save %d\n", r); - gbaSave[r].setName((char *) filename); - gbaSave[r].reset(); - return gbaSave[r].clone(); - } -} - -void DSSaveFileManager::flushToSaveRAM() { - int cartAddr = 1; - int s; - int extraData = DSSaveFileManager::getExtraData(); - - *((u16 *) (0x4000204)) |= 0x3; - - swiWaitForVBlank(); - - int size = 0; - for (int r = 0; (r < 8); r++) { - if (gbaSave[r].isValid()) { - gbaSave[r].compress(); - if (!gbaSave[r].isTemp()) size += gbaSave[r].getRamUsage(); - } - } - - if (size <= SRAM_SAVE_MAX) { - - for (int r = 0; r < SRAM_SAVE_MAX; r++) { - *(CART_RAM + r) = 0; - } - - sramBytesFree = SRAM_SAVE_MAX; - - for (int r = 0; (r < 8); r++) { - if (gbaSave[r].isValid() && (!gbaSave[r].isTemp())) { - - cartAddr += s = gbaSave[r].saveToSaveRAM(CART_RAM + cartAddr); - - /* if (s == 0) { - consolePrintf("WARNING: Save didn't fit in cart RAM and has been lost!! Delete files and save again.", gbaSave[r].getName()); - failed = true; - }*/ - } - } - } else { - - consolePrintf("WARNING: Save didn't fit in cart RAM and has been lost!! Delete files and save again."); - loadAllFromSRAM(); - - } - - DSSaveFileManager::setExtraData(extraData); -// consolePrintf("SRAM free: %d bytes\n", getBytesFree()); -} - -void DSSaveFileManager::setExtraData(int data) { - // Offset of extra data is 31. This overlaps the padding and reserved bytes of the first save entry. - // which have not been used up until now. So it should be safe. - - vu8 *sram = CART_RAM + 31; - - *(sram + 0) = 0xF0; // This is an identifier to check - *(sram + 1) = 0x0D; // that extra data is present. - - *(sram + 2) = (data & 0xFF000000) >> 24; // Now write the actual data - *(sram + 3) = (data & 0x00FF0000) >> 16; // taking care to use single - *(sram + 4) = (data & 0x0000FF00) >> 8; // byte writes (it's an 8-bit bus) - *(sram + 5) = (data & 0x000000FF); -} - -bool DSSaveFileManager::isExtraDataPresent() { - vu8 *sram = CART_RAM + 31; - - // Check for the identifier - return ((*(sram + 0) == 0xF0) && (*(sram + 1) == 0x0D)); -} - -int DSSaveFileManager::getExtraData() { - vu8 *sram = CART_RAM + 31; - - if (isExtraDataPresent()) { - int value = (*(sram + 2) << 24) | (*(sram + 3) << 16) | (*(sram + 4) << 8) | (*(sram + 5)); - return value; - } else { - return 0; - } -} - -#endif diff --git a/backends/platform/ds/arm9/source/ramsave.h b/backends/platform/ds/arm9/source/ramsave.h deleted file mode 100644 index f2cfe0fc0b..0000000000 --- a/backends/platform/ds/arm9/source/ramsave.h +++ /dev/null @@ -1,155 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -#ifndef _RAMSAVE_H_ -#define _RAMSAVE_H_ - -#include <nds/ndstypes.h> -#include "common/system.h" -#include "common/savefile.h" - - -// SaveFileManager class - -#define DS_MAX_SAVE_SIZE 150000 - -class DSSaveFile : public Common::InSaveFile, public Common::OutSaveFile { - int address; - int ptr; - bool ownsData; - bool saveCompressed; - - struct SCUMMSave { - u32 magic; // 4 - bool isValid; // 5 - bool pad; // 6 - char name[16]; // 22 - u32 size; // 26 - u32 compressedSize; // 30 - u16 extraMagic; // 32 - u32 reserved; // 36 - } __attribute__ ((packed)); - - SCUMMSave save; - u8 *saveData; - SCUMMSave *origHeader; - bool isOpenFlag; - bool isTempFile; - bool eosReached; - -public: - DSSaveFile(); - DSSaveFile(SCUMMSave *s, bool saveCompressed, u8 *data); - ~DSSaveFile(); - - void reset(); - - bool isOpen() const { return isOpenFlag; } - virtual bool eos() const; - virtual void clearErr(); - virtual bool skip(uint32 size); - - virtual int32 pos() const; - virtual int32 size() const; - virtual bool seek(int32 pos, int whence); - - uint32 read(void *buf, uint32 size); - uint32 write(const void *buf, uint32 size); - - void setName(char *name); - char *getName() { return save.name; } - - bool isValid() { return save.isValid; } - bool isTemp() { return isTempFile; } - bool matches(const char *prefix, int num); - bool matches(const char *filename); - - void clearData(); - void compress(); - - int getRamUsage() { return sizeof(save) + save.compressedSize; } - char *getRamImage() { return (char *) &save; } - - int getSize() { return save.size; } - - DSSaveFile *clone(); - - bool loadFromSaveRAM(vu8 *address); - int saveToSaveRAM(vu8 *address); - - - - void deleteFile(); - - void operator delete(void *p) { -// consolePrintf("Finished! size=%d\n", ((DSSaveFile *) (p))->save->size); - } - - - -}; - - - -class DSSaveFileManager : public Common::SaveFileManager { - - DSSaveFile gbaSave[8]; - static DSSaveFileManager *instancePtr; - int sramBytesFree; - -public: - DSSaveFileManager(); - ~DSSaveFileManager(); - - static DSSaveFileManager *instance() { return instancePtr; } - - DSSaveFile *openSavefile(const char *filename, bool saveOrLoad); - - virtual Common::OutSaveFile *openForSaving(const Common::String &filename) { return openSavefile(filename.c_str(), true); } - virtual Common::InSaveFile *openForLoading(const Common::String &filename) { return openSavefile(filename.c_str(), false); } - - virtual bool removeSavefile(const Common::String &filename); - virtual Common::StringArray listSavefiles(const Common::String &pattern); - - void flushToSaveRAM(); - - void addBytesFree(int size) { sramBytesFree += size; } - int getBytesFree() { return sramBytesFree; } - - void deleteFile(char *name); - void listFiles(); - void formatSram(); - - void loadAllFromSRAM(); - - static bool isExtraDataPresent(); - static int getExtraData(); - static void setExtraData(int data); - -protected: - DSSaveFile *makeSaveFile(const Common::String &filename, bool saveOrLoad); -}; - -#endif diff --git a/backends/platform/ds/module.mk b/backends/platform/ds/module.mk index e3c18c7174..44cba006df 100644 --- a/backends/platform/ds/module.mk +++ b/backends/platform/ds/module.mk @@ -12,7 +12,6 @@ PORT_OBJS := \ arm9/source/gbampsave.o \ arm9/source/scummhelp.o \ arm9/source/osystem_ds.o \ - arm9/source/ramsave.o \ arm9/source/touchkeyboard.o \ arm9/source/zipreader.o \ arm9/source/dsoptions.o \ @@ -27,9 +26,9 @@ DATA_OBJS := \ arm9/data/default_font.o \ arm9/data/8x8font_tga.o -COMPRESSOR_OBJS := #arm9/source/compressor/lz.o - -FAT_OBJS := arm9/source/fat/disc_io.o arm9/source/fat/gba_nds_fat.o\ +FAT_OBJS := \ + arm9/source/fat/disc_io.o \ + arm9/source/fat/gba_nds_fat.o \ arm9/source/fat/io_fcsr.o \ arm9/source/fat/io_m3cf.o \ arm9/source/fat/io_mpcf.o \ @@ -50,12 +49,9 @@ FAT_OBJS := arm9/source/fat/disc_io.o arm9/source/fat/gba_nds_fat.o\ # arm9/source/fat/io_sd_common.o arm9/source/fat/io_scsd_s.o \ # arm9/source/fat/io_sc_common.o arm9/source/fat/io_sd_common.o -LIBCARTRESET_OBJS := \ -# arm9/source/libcartreset/cartreset.o - #MODULE_OBJS := $(PORT_OBJS) $(DATA_OBJS) $(FAT_OBJS) -MODULE_OBJS := $(DATA_OBJS) $(LIBCARTRESET_OBJS) $(PORT_OBJS) $(COMPRESSOR_OBJS) $(FAT_OBJS) +MODULE_OBJS := $(DATA_OBJS) $(PORT_OBJS) $(FAT_OBJS) #--------------------------------------------------------------------------------- @@ -113,8 +109,7 @@ MODULE_DIRS += \ backends/platform/ds/arm7/source/ \ backends/platform/ds/arm7/source/libcartreset/ \ backends/platform/ds/arm9/source/ \ - backends/platform/ds/arm9/source/fat/ \ - backends/platform/ds/arm9/source/libcartreset/ + backends/platform/ds/arm9/source/fat/ # We don't use the rules.mk here on purpose OBJS := $(addprefix $(MODULE)/, $(MODULE_OBJS)) $(OBJS) |