Search
lxdream.org :: lxdream/src/mem.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/mem.c
changeset 931:430048ea8b71
prev930:07e5b11419db
next932:2602c5603ce2
author nkeynes
date Tue Dec 23 05:48:05 2008 +0000 (11 years ago)
branchlxdream-mem
permissions -rw-r--r--
last change More refactoring and general cleanup. Most things should be working again now.
Split off cache and start real implementation, breaking save states in the process
file annotate diff log raw
1.1 --- a/src/mem.c Mon Dec 22 09:51:11 2008 +0000
1.2 +++ b/src/mem.c Tue Dec 23 05:48:05 2008 +0000
1.3 @@ -51,6 +51,35 @@
1.4
1.5 uint32_t num_io_rgns = 0, num_mem_rgns = 0;
1.6
1.7 +DEFINE_HOOK( mem_page_remapped_hook, mem_page_remapped_hook_t );
1.8 +static void mem_page_remapped( sh4addr_t addr, mem_region_fn_t fn )
1.9 +{
1.10 + CALL_HOOKS( mem_page_remapped_hook, addr, fn );
1.11 +}
1.12 +
1.13 +/********************* The "unmapped" address space ********************/
1.14 +/* Always reads as 0, writes have no effect */
1.15 +int32_t FASTCALL unmapped_read_long( sh4addr_t addr )
1.16 +{
1.17 + return 0;
1.18 +}
1.19 +void FASTCALL unmapped_write_long( sh4addr_t addr, uint32_t val )
1.20 +{
1.21 +}
1.22 +void FASTCALL unmapped_read_burst( unsigned char *dest, sh4addr_t addr )
1.23 +{
1.24 + memset( dest, 0, 32 );
1.25 +}
1.26 +void FASTCALL unmapped_write_burst( sh4addr_t addr, unsigned char *src )
1.27 +{
1.28 +}
1.29 +
1.30 +struct mem_region_fn mem_region_unmapped = {
1.31 + unmapped_read_long, unmapped_write_long,
1.32 + unmapped_read_long, unmapped_write_long,
1.33 + unmapped_read_long, unmapped_write_long,
1.34 + unmapped_read_burst, unmapped_write_burst };
1.35 +
1.36 void *mem_alloc_pages( int n )
1.37 {
1.38 void *mem = mmap( NULL, n * 4096,
1.39 @@ -253,6 +282,7 @@
1.40 for( i=0; i<size>>LXDREAM_PAGE_BITS; i++ ) {
1.41 page_map[(base>>LXDREAM_PAGE_BITS)+i] = mem + (i<<LXDREAM_PAGE_BITS);
1.42 ext_address_space[(base>>LXDREAM_PAGE_BITS)+i] = fn;
1.43 + mem_page_remapped( base + (i<<LXDREAM_PAGE_BITS), fn );
1.44 }
1.45 base += repeat_offset;
1.46 } while( base <= repeat_until );
1.47 @@ -260,6 +290,23 @@
1.48 return &mem_rgn[num_mem_rgns-1];
1.49 }
1.50
1.51 +void register_misc_region( uint32_t base, uint32_t size, const char *name, mem_region_fn_t fn )
1.52 +{
1.53 + mem_rgn[num_mem_rgns].base = base;
1.54 + mem_rgn[num_mem_rgns].size = size;
1.55 + mem_rgn[num_mem_rgns].flags = 0;
1.56 + mem_rgn[num_mem_rgns].name = name;
1.57 + mem_rgn[num_mem_rgns].mem = NULL;
1.58 + mem_rgn[num_mem_rgns].fn = fn;
1.59 + num_mem_rgns++;
1.60 +
1.61 + int count = size >> 12;
1.62 + mem_region_fn_t *ptr = &ext_address_space[base>>12];
1.63 + while( count-- > 0 ) {
1.64 + *ptr++ = fn;
1.65 + }
1.66 +}
1.67 +
1.68 void *mem_create_ram_region( uint32_t base, uint32_t size, const char *name, mem_region_fn_t fn )
1.69 {
1.70 return mem_create_repeating_ram_region( base, size, name, fn, size, base );
1.71 @@ -351,6 +398,7 @@
1.72 } else {
1.73 page_map[io->base>>12] = (sh4ptr_t)(uintptr_t)num_io_rgns;
1.74 ext_address_space[io->base>>12] = &io->fn;
1.75 + mem_page_remapped( io->base, &io->fn );
1.76 }
1.77 io_rgn[num_io_rgns] = io;
1.78 num_io_rgns++;
.