Search
lxdream.org :: lxdream :: r50:704b11c879cb
lxdream 0.9.1
released Jun 29
Download Now
changeset50:704b11c879cb
parent49:6290c467cfbd
child51:ed6c27067502
authornkeynes
dateWed Dec 28 22:47:44 2005 +0000 (17 years ago)
Implement mem_save_block
src/mem.c
1.1 --- a/src/mem.c Tue Dec 27 12:42:29 2005 +0000
1.2 +++ b/src/mem.c Wed Dec 28 22:47:44 2005 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: mem.c,v 1.9 2005-12-26 10:48:45 nkeynes Exp $
1.6 + * $Id: mem.c,v 1.10 2005-12-28 22:47:44 nkeynes Exp $
1.7 * mem.c is responsible for creating and maintaining the overall system memory
1.8 * map, as visible from the SH4 processor.
1.9 *
1.10 @@ -160,9 +160,33 @@
1.11 return 0;
1.12 }
1.13
1.14 -void mem_save_block( const gchar *file, uint32_t start, uint32_t length )
1.15 +int mem_save_block( const gchar *file, uint32_t start, uint32_t length )
1.16 {
1.17 + char *region;
1.18 + int len = 4096, total = 0;
1.19 + uint32_t addr = start;
1.20 + struct stat st;
1.21 + FILE *f = fopen(file,"w");
1.22
1.23 + if( f == NULL )
1.24 + return errno;
1.25 +
1.26 + while( total < length ) {
1.27 + region = mem_get_region(addr);
1.28 + len = 4096 - (addr & 0x0FFF);
1.29 + if( len > (length-total) )
1.30 + len = (length-total);
1.31 + if( fwrite( region, len, 1, f ) != 1 ) {
1.32 + ERROR( "Unexpected error: %d %d", len, errno );
1.33 + break;
1.34 + }
1.35 +
1.36 + addr += len;
1.37 + total += len;
1.38 + }
1.39 + fclose( f );
1.40 + INFO( "Loaded %d of %d bytes to %08X", total, length, start );
1.41 + return 0;
1.42 }
1.43
1.44 int mem_load_block( const gchar *file, uint32_t start, uint32_t length )
.