-Noticed a couple of files with missing copyrights. I hope it's correct now.

-Added support for importing *.duc files. You just have to call NDS_ImportSave with a valid filename specified and it should load any *.duc file
This commit is contained in:
cyberwarriorx 2007-02-10 02:09:48 +00:00
parent e1d53d42dc
commit 392e879e52
3 changed files with 109 additions and 11 deletions

View File

@ -250,23 +250,21 @@ int NDS_LoadROM(const char *filename, int bmtype, u32 bmsize)
// Setup Backup Memory // Setup Backup Memory
if(type == ROM_DSGBA) if(type == ROM_DSGBA)
{
/* be sure that we dont overwrite anything before stringstart */ /* be sure that we dont overwrite anything before stringstart */
if (strlen(noext)>= strlen(DSGBA_EXTENSTION)) if (strlen(noext)>= strlen(DSGBA_EXTENSTION))
{ strncpy(noext + strlen(noext) - strlen(DSGBA_EXTENSTION), ".sav",strlen(DSGBA_EXTENSTION)+1);
strncpy(noext + strlen(noext) - strlen(DSGBA_EXTENSTION), ".sav",strlen(DSGBA_EXTENSTION)+1); else
} else
{
return -1 ; return -1 ;
} }
else else
{
/* be sure that we dont overwrite anything before stringstart */ /* be sure that we dont overwrite anything before stringstart */
if (strlen(noext)>=4) if (strlen(noext)>=4)
{ strncpy(noext + strlen(noext) - 4, ".sav",5);
strncpy(noext + strlen(noext) - 4, ".sav",5); else
} else
{
return -1 ; return -1 ;
} }
mc_realloc(&MMU.bupmem, bmtype, bmsize); mc_realloc(&MMU.bupmem, bmtype, bmsize);
mc_load_file(&MMU.bupmem, noext); mc_load_file(&MMU.bupmem, noext);
@ -446,6 +444,17 @@ void NDS_Reset(void)
execute = oldexecute; execute = oldexecute;
} }
int NDS_ImportSave(const char *filename)
{
if (strlen(filename) < 4)
return 0;
if (memcmp(filename+strlen(filename)-4, ".duc", 4) == 0)
return mc_load_duc(&MMU.bupmem, filename);
return 0;
}
typedef struct typedef struct
{ {
u32 size; u32 size;

View File

@ -1,3 +1,23 @@
/* Copyright (C) 2006 thoduv
Copyright (C) 2006-2007 Theo Berkau
This file is part of DeSmuME
DeSmuME 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.
DeSmuME 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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdlib.h> #include <stdlib.h>
#include "debug.h" #include "debug.h"
#include "types.h" #include "types.h"
@ -61,8 +81,8 @@ u8 *mc_alloc(memory_chip_t *mc, u32 size)
u8 *buffer; u8 *buffer;
buffer = malloc(size); buffer = malloc(size);
if(!buffer) { return NULL; }
mc->data = buffer; mc->data = buffer;
if(!buffer) { return NULL; }
mc->size = size; mc->size = size;
mc->writeable_buffer = TRUE; mc->writeable_buffer = TRUE;
} }
@ -194,6 +214,54 @@ void mc_load_file(memory_chip_t *mc, const char* filename)
mc->fp = file; mc->fp = file;
} }
int mc_load_duc(memory_chip_t *mc, const char* filename)
{
long size;
int type;
char id[16];
FILE* file = fopen(filename, "rb");
if(file == NULL)
return 0;
fseek(file, 0, SEEK_END);
size = ftell(file) - 500;
fseek(file, 0, SEEK_SET);
// Make sure we really have the right file
fread((void *)id, sizeof(char), 16, file);
if (memcmp(id, "ARDS000000000001", 16) != 0)
{
fclose(file);
return 0;
}
// Alright, it's time to load the file
if (mc->type == MC_TYPE_AUTODETECT)
{
if (size == MC_SIZE_4KBITS)
type = MC_TYPE_EEPROM1;
else if (size == MC_SIZE_64KBITS)
type = MC_TYPE_EEPROM2;
else if (size == MC_SIZE_256KBITS)
type = MC_TYPE_FRAM;
else if (size == MC_SIZE_512KBITS)
type = MC_TYPE_EEPROM2;
else if (size >= MC_SIZE_2MBITS)
type = MC_TYPE_FLASH;
mc_realloc(mc, type, size);
}
if (size > mc->size)
size = mc->size;
// Skip the rest of the header since we don't need it
fseek(file, 500, SEEK_SET);
fread (mc->data, 1, size, file);
fclose(file);
return 1;
}
u8 fw_transfer(memory_chip_t *mc, u8 data) u8 fw_transfer(memory_chip_t *mc, u8 data)
{ {
if(mc->com == FW_CMD_READ || mc->com == FW_CMD_PAGEWRITE) /* check if we are in a command that needs 3 bytes address */ if(mc->com == FW_CMD_READ || mc->com == FW_CMD_PAGEWRITE) /* check if we are in a command that needs 3 bytes address */

View File

@ -1,3 +1,23 @@
/* Copyright (C) 2006 thoduv
Copyright (C) 2006 Theo Berkau
This file is part of DeSmuME
DeSmuME 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.
DeSmuME 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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __FW_H__ #ifndef __FW_H__
#define __FW_H__ #define __FW_H__
@ -60,6 +80,7 @@ void mc_init(memory_chip_t *mc, int type); /* reset and init values for memor
u8 *mc_alloc(memory_chip_t *mc, u32 size); /* alloc mc memory */ u8 *mc_alloc(memory_chip_t *mc, u32 size); /* alloc mc memory */
void mc_realloc(memory_chip_t *mc, int type, u32 size); /* realloc mc memory */ void mc_realloc(memory_chip_t *mc, int type, u32 size); /* realloc mc memory */
void mc_load_file(memory_chip_t *mc, const char* filename); /* load save file and setup fp */ void mc_load_file(memory_chip_t *mc, const char* filename); /* load save file and setup fp */
int mc_load_duc(memory_chip_t *mc, const char* filename); /* load Action Replay DS save file */
void mc_free(memory_chip_t *mc); /* delete mc memory */ void mc_free(memory_chip_t *mc); /* delete mc memory */
void mc_reset_com(memory_chip_t *mc); /* reset communication with mc */ void mc_reset_com(memory_chip_t *mc); /* reset communication with mc */
u8 fw_transfer(memory_chip_t *mc, u8 data); /* transfer to, then receive data from firmware */ u8 fw_transfer(memory_chip_t *mc, u8 data); /* transfer to, then receive data from firmware */