From 116e6e6ca3a10a236a1d665893aba7864f9d43f8 Mon Sep 17 00:00:00 2001 From: cyberwarriorx Date: Tue, 3 Oct 2006 20:59:50 +0000 Subject: [PATCH] -saves.cpp/saves.hpp has been moved out of /src/windows since it isn't port specific. Code has also been made more portable and cleaned up. More work still needs to be done. --- desmume/src/saves.c | 125 ++++++++++++++++++++++++++++++++++++++++++++ desmume/src/saves.h | 25 +++++++++ 2 files changed, 150 insertions(+) create mode 100644 desmume/src/saves.c create mode 100644 desmume/src/saves.h diff --git a/desmume/src/saves.c b/desmume/src/saves.c new file mode 100644 index 000000000..fb49f3558 --- /dev/null +++ b/desmume/src/saves.c @@ -0,0 +1,125 @@ +#ifdef HAVE_LIBZ +#include +#endif +#include +#include "saves.h" +#include "MMU.hpp" + +u8 sram_read (u32 address) { + address = address - SRAM_ADDRESS; + + if ( address > SRAM_SIZE ) + return 0; + + return MMU.CART_RAM[address]; + +} + +void sram_write (u32 address, u8 value) { + + address = address - SRAM_ADDRESS; + + if ( address < SRAM_SIZE ) + MMU.CART_RAM[address] = value; + +} + +int sram_load (const char *file_name) { + + FILE *file; + + file = fopen ( file_name, "rb" ); + if( file == NULL ) + return 0; + + fread ( MMU.CART_RAM, SRAM_SIZE, 1, file ); + + fclose ( file ); + + return 1; + +} + +int sram_save (const char *file_name) { + + FILE *file; + + file = fopen ( file_name, "wb" ); + if( file == NULL ) + return 0; + + fwrite ( MMU.CART_RAM, SRAM_SIZE, 1, file ); + + fclose ( file ); + + return 1; + +} + +int savestate_load (const char *file_name) { +#ifdef HAVE_LIBZ + + gzFile file; + + file = gzopen( file_name, "rb" ); + if( file == NULL ) + return 0; + + gzread ( file, ARM9Mem.ARM9_ITCM, 0x8000 ); + gzread ( file, ARM9Mem.ARM9_DTCM, 0x4000 ); + ////fread ( MMU::ARM9_WRAM, 0x1000000, 1, file ); + gzread ( file, ARM9Mem.MAIN_MEM, 0x400000 ); + gzread ( file, ARM9Mem.ARM9_REG, 0x10000 ); + gzread ( file, ARM9Mem.ARM9_VMEM, 0x800 ); + gzread ( file, ARM9Mem.ARM9_OAM, 0x800 ); + + gzread ( file, ARM9Mem.ARM9_ABG, 0x80000 ); + gzread ( file, ARM9Mem.ARM9_BBG, 0x20000 ); + gzread ( file, ARM9Mem.ARM9_AOBJ, 0x40000 ); + gzread ( file, ARM9Mem.ARM9_BOBJ, 0x20000 ); + gzread ( file, ARM9Mem.ARM9_LCD, 0xA4000 ); + + //ARM7 memory + //gzread ( file, MMU::ARM7_ERAM, 0x10000 ); + //gzread ( file, MMU::ARM7_REG, 0x10000 ); + //gzread ( file, MMU::ARM7_WIRAM, 0x10000 ); + + gzclose ( file ); + + return 1; +#endif +} + +int savestate_save (const char *file_name) { +#ifdef HAVE_LIBZ + gzFile file; + + file = gzopen( file_name, "wb" ); + if( file == NULL ) + return 0; + + gzwrite ( file, ARM9Mem.ARM9_ITCM, 0x8000 ); + gzwrite ( file ,ARM9Mem.ARM9_DTCM, 0x4000 ); + ////fwrite ( MMU::ARM9_WRAM, 0x1000000, 1, file ); + gzwrite ( file, ARM9Mem.MAIN_MEM, 0x400000 ); + gzwrite ( file, ARM9Mem.ARM9_REG, 0x10000 ); + gzwrite ( file, ARM9Mem.ARM9_VMEM, 0x800 ); + gzwrite ( file, ARM9Mem.ARM9_OAM, 0x800 ); + + gzwrite ( file, ARM9Mem.ARM9_ABG, 0x80000 ); + gzwrite ( file, ARM9Mem.ARM9_BBG, 0x20000 ); + gzwrite ( file, ARM9Mem.ARM9_AOBJ, 0x40000 ); + gzwrite ( file, ARM9Mem.ARM9_BOBJ, 0x20000 ); + gzwrite ( file, ARM9Mem.ARM9_LCD, 0xA4000 ); + + //ARM7 memory + //gzwrite ( file, MMU::ARM7_ERAM, 0x10000 ); + //gzwrite ( file, MMU::ARM7_REG, 0x10000 ); + //gzwrite ( file, MMU::ARM7_WIRAM, 0x10000 ); + + gzclose ( file ); + + return 1; +#endif +} + diff --git a/desmume/src/saves.h b/desmume/src/saves.h new file mode 100644 index 000000000..98277d7dc --- /dev/null +++ b/desmume/src/saves.h @@ -0,0 +1,25 @@ +#ifndef _SRAM_H +#define _SRAM_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "types.h" + + #define SRAM_ADDRESS 0x0A000000 + #define SRAM_SIZE 0x10000 + + u8 sram_read (u32 address); + void sram_write (u32 address, u8 value); + int sram_load (const char *file_name); + int sram_save (const char *file_name); + + int savestate_load (const char *file_name); + int savestate_save (const char *file_name); + +#ifdef __cplusplus +} +#endif + +#endif