static void ensure_empty_mapping( void ) { int i; libspectrum_byte *empty_chunk; if( empty_mapping_allocated ) return; empty_chunk = memory_pool_allocate_persistent( 0x4000, 1 ); memset( empty_chunk, 0xff, 0x4000 ); for( i = 0; i < MEMORY_PAGES_IN_16K; i++ ) { memory_page *page = &empty_mapping[i]; page->page = empty_chunk + i * MEMORY_PAGE_SIZE; page->writable = 0; page->contended = 0; page->source = memory_source_none; } empty_mapping_allocated = 1; }
static void spectranet_activate( void ) { if( !spectranet_memory_allocated ) { int i, j; libspectrum_byte *rom; libspectrum_byte *ram; libspectrum_byte *fake_bank = memory_pool_allocate_persistent( 0x1000, 1 ); memset( fake_bank, 0xff, 0x1000 ); /* Start of by mapping the fake data in everywhere */ for( i = 0; i < SPECTRANET_PAGES; i++ ) for( j = 0; j < MEMORY_PAGES_IN_4K; j++ ) { memory_page *page = &spectranet_full_map[i * MEMORY_PAGES_IN_4K + j]; page->writable = 0; page->contended = 0; page->source = spectranet_source; page->save_to_snapshot = 0; page->page_num = i; page->offset = j * MEMORY_PAGE_SIZE; page->page = fake_bank + page->offset; } /* Pages 0x00 to 0x1f are the flash ROM */ rom = memory_pool_allocate_persistent( SPECTRANET_ROM_LENGTH, 1 ); memset( rom, 0xff, SPECTRANET_ROM_LENGTH ); for( i = 0; i < SPECTRANET_ROM_LENGTH / SPECTRANET_PAGE_LENGTH; i++ ) { int base = (SPECTRANET_ROM_BASE + i) * MEMORY_PAGES_IN_4K; for( j = 0; j < MEMORY_PAGES_IN_4K; j++ ) { memory_page *page = &spectranet_full_map[base + j]; page->page = rom + (i * MEMORY_PAGES_IN_4K + j) * MEMORY_PAGE_SIZE; } } flash_am29f010_init( flash_rom, rom ); /* Pages 0x40 to 0x47 are the W5100 registers - handled in readbyte() and writebyte() */ /* Pages 0xc0 to 0xff are the RAM */ ram = memory_pool_allocate_persistent( SPECTRANET_RAM_LENGTH, 1 ); for( i = 0; i < SPECTRANET_RAM_LENGTH / SPECTRANET_PAGE_LENGTH; i++ ) { int base = (SPECTRANET_RAM_BASE + i) * MEMORY_PAGES_IN_4K; for( j = 0; j < MEMORY_PAGES_IN_4K; j++ ) { memory_page *page = &spectranet_full_map[base + j]; page->writable = 1; page->page = ram + (i * MEMORY_PAGES_IN_4K + j) * MEMORY_PAGE_SIZE; } } spectranet_memory_allocated = 1; spectranet_map_page( 0, 0x00 ); spectranet_map_page( 3, 0xc0 ); spectranet_hard_reset(); } }
/* Allocate some memory from the pool */ libspectrum_byte* memory_pool_allocate( size_t length ) { return memory_pool_allocate_persistent( length, 0 ); }