diff --git a/desmume/src/ARM9.h b/desmume/src/ARM9.h index ced7a1bce..be45f6a33 100644 --- a/desmume/src/ARM9.h +++ b/desmume/src/ARM9.h @@ -24,7 +24,7 @@ struct ALIGN(16) ARM9_struct { u8 *textureSlotAddr[4]; - u8 *blank_memory[0x20000]; + u8 blank_memory[0x20000]; }; extern ARM9_struct ARM9Mem; diff --git a/desmume/src/MMU.cpp b/desmume/src/MMU.cpp index 066c8b6f8..cff954a99 100644 --- a/desmume/src/MMU.cpp +++ b/desmume/src/MMU.cpp @@ -461,18 +461,10 @@ void MMU_clearMem() osdA->setOffset(MainScreen.offset); osdB->setOffset(SubScreen.offset); - /* setup the texture slot pointers */ -#if 0 - ARM9Mem.textureSlotAddr[0] = ARM9Mem.blank_memory; - ARM9Mem.textureSlotAddr[1] = ARM9Mem.blank_memory; - ARM9Mem.textureSlotAddr[2] = ARM9Mem.blank_memory; - ARM9Mem.textureSlotAddr[3] = ARM9Mem.blank_memory; -#else - ARM9Mem.textureSlotAddr[0] = &ARM9Mem.ARM9_LCD[0x20000 * 0]; - ARM9Mem.textureSlotAddr[1] = &ARM9Mem.ARM9_LCD[0x20000 * 1]; - ARM9Mem.textureSlotAddr[2] = &ARM9Mem.ARM9_LCD[0x20000 * 2]; - ARM9Mem.textureSlotAddr[3] = &ARM9Mem.ARM9_LCD[0x20000 * 3]; -#endif + for(int i=0;i<4;i++) + ARM9Mem.textureSlotAddr[i] = ARM9Mem.blank_memory; + for(int i=0;i<6;i++) + ARM9Mem.texPalSlot[i] = ARM9Mem.blank_memory; LCDdst[0] = ARM9Mem.ARM9_LCD; // Bank A LCDdst[1] = ARM9Mem.ARM9_LCD + 0x20000; // Bank B @@ -581,6 +573,21 @@ static inline void MMU_VRAMmapControl(u8 block, u8 VRAMBankCnt) u32 vram_map_addr = 0xFFFFFFFF; u8 *LCD_addr = LCDdst[block]; + + //unmap texmem + for(int i=0;i<4;i++) + if(ARM9Mem.textureSlotAddr[i] == LCD_addr) + ARM9Mem.textureSlotAddr[i] = ARM9Mem.blank_memory; + + //unmap texpal mem. This is not a straightforward way to do it, + //but it is the only place we have this information stored. + for(int i=0;i<4;i++) + if(ARM9Mem.texPalSlot[i] == LCD_addr + 0x4000*i || ARM9Mem.texPalSlot[i] == LCD_addr) + ARM9Mem.texPalSlot[i] = ARM9Mem.blank_memory; + for(int i=4;i<6;i++) + if(ARM9Mem.texPalSlot[i] == LCD_addr) + ARM9Mem.texPalSlot[i] = ARM9Mem.blank_memory; + switch (VRAMBankCnt & 0x07) { diff --git a/desmume/src/OGLRender.cpp b/desmume/src/OGLRender.cpp index 9c7edb80b..54dadcffe 100644 --- a/desmume/src/OGLRender.cpp +++ b/desmume/src/OGLRender.cpp @@ -147,16 +147,9 @@ static MemSpan MemSpan_TexMem(u32 ofs, u32 len) ofs += curr.len; currofs += curr.len; u8* ptr = ARM9Mem.textureSlotAddr[slot]; - //this is just a guess. what happens if there is a gap in the mapping? lets put zeros - if(ptr == NULL) { - PROGINFO("Texture gap in memory mapping. Trying to accomodate.\n"); - static u8* emptyTextureSlot = 0; - if(emptyTextureSlot == NULL) { - emptyTextureSlot = new u8[128*1024]; - memset(emptyTextureSlot,0,128*1024); - } - ptr = emptyTextureSlot; - } + + if(ptr == ARM9Mem.blank_memory) + PROGINFO("Tried to reference unmapped texture memory: slot %d\n",slot); curr.ptr = ptr + curr.start; } @@ -185,16 +178,10 @@ static MemSpan MemSpan_TexPalette(u32 ofs, u32 len) //here is an actual test case of bank spanning currofs += curr.len; u8* ptr = ARM9Mem.texPalSlot[slot]; - //this is just a guess. what happens if there is a gap in the mapping? lets put zeros - if(ptr == NULL) { - PROGINFO("Texture palette gap in memory mapping. Trying to accomodate.\n"); - static u8* emptyTexturePalette = 0; - if(emptyTexturePalette == NULL) { - emptyTexturePalette = new u8[16*1024]; - memset(emptyTexturePalette,0,16*1024); - } - ptr = emptyTexturePalette; - } + + if(ptr == ARM9Mem.blank_memory) + PROGINFO("Tried to reference unmapped texture palette memory: 16k slot #%d\n",slot); + curr.ptr = ptr + curr.start; } return ret;