mask rom reads outside of range instead of returning 0xFF. clean up some other archaic memory map cruft

This commit is contained in:
zeromus 2010-09-25 08:00:53 +00:00
parent 7be2b0da6e
commit 042e584b20
6 changed files with 16 additions and 80 deletions

View File

@ -82,8 +82,6 @@ u32 _MMU_MAIN_MEM_MASK = 0x3FFFFF;
u32 _MMU_MAIN_MEM_MASK16 = 0x3FFFFF & ~1;
u32 _MMU_MAIN_MEM_MASK32 = 0x3FFFFF & ~3;
#define ROM_MASK 3
//#define _MMU_DEBUG
#ifdef _MMU_DEBUG
@ -174,7 +172,7 @@ u8 * MMU_struct::MMU_MEM[2][256] = {
/* 7X*/ DUP16(MMU.ARM9_OAM),
/* 8X*/ DUP16(NULL),
/* 9X*/ DUP16(NULL),
/* AX*/ DUP16(MMU.CART_RAM),
/* AX*/ DUP16(NULL),
/* BX*/ DUP16(MMU.UNUSED_RAM),
/* CX*/ DUP16(MMU.UNUSED_RAM),
/* DX*/ DUP16(MMU.UNUSED_RAM),
@ -195,7 +193,7 @@ u8 * MMU_struct::MMU_MEM[2][256] = {
/* 7X*/ DUP16(MMU.UNUSED_RAM),
/* 8X*/ DUP16(NULL),
/* 9X*/ DUP16(NULL),
/* AX*/ DUP16(MMU.CART_RAM),
/* AX*/ DUP16(NULL),
/* BX*/ DUP16(MMU.UNUSED_RAM),
/* CX*/ DUP16(MMU.UNUSED_RAM),
/* DX*/ DUP16(MMU.UNUSED_RAM),
@ -832,7 +830,6 @@ void MMU_Init(void) {
memset(&MMU, 0, sizeof(MMU_struct));
MMU.CART_ROM = MMU.UNUSED_RAM;
MMU.CART_ROM_MASK = 3;
//MMU.DTCMRegion = 0x027C0000;
//even though apps may change dtcm immediately upon startup, this is the correct hardware starting value:
@ -876,10 +873,6 @@ void MMU_DeInit(void) {
Mic_DeInit();
}
//Card rom & ram
u32 rom_mask = 0;
void MMU_Reset()
{
memset(MMU.ARM9_DTCM, 0, sizeof(MMU.ARM9_DTCM));
@ -988,15 +981,11 @@ void MMU_Reset()
void MMU_setRom(u8 * rom, u32 mask)
{
MMU.CART_ROM = rom;
MMU.CART_ROM_MASK = mask;
rom_mask = mask;
}
void MMU_unsetRom()
{
MMU.CART_ROM=MMU.UNUSED_RAM;
MMU.CART_ROM_MASK = 3;
rom_mask = ROM_MASK;
}
static void execsqrt() {

View File

@ -361,8 +361,6 @@ struct MMU_struct
//Card rom & ram
u8 * CART_ROM;
u32 CART_ROM_MASK;
u8 CART_RAM[0x10000];
//Unused ram
u8 UNUSED_RAM[4];

View File

@ -330,7 +330,7 @@ struct GameInfo
//now, we actually need to over-allocate, because bytes from anywhere protected by that mask
//could be read from the rom
allocatedSize = mask+1;
allocatedSize = mask+4;
romdata = new char[allocatedSize];
romsize = size;

View File

@ -120,14 +120,20 @@ static u32 read32_GCDATAIN(u8 PROCNUM)
card.address = (0x8000 + (card.address&0x1FF));
}
if(card.address >= gameInfo.romsize)
//it seems that etrian odyssey 3 doesnt work unless we mask this to cart size.
//but, a thought: does the internal rom address counter register wrap around? we may be making a mistake by keeping the extra precision
//but there is no test case yet
u32 address = card.address & (gameInfo.mask);
//as a sanity measure for funny-sized roms (homebrew and perhaps truncated retail roms)
//we need to protect ourselves by returning 0xFF for things still out of range
if(address >= gameInfo.romsize)
{
DEBUG_Notify.ReadBeyondEndOfCart(card.address,gameInfo.romsize);
DEBUG_Notify.ReadBeyondEndOfCart(address,gameInfo.romsize);
return 0xFFFFFFFF;
}
//but, this is actually handled by the cart rom buffer being oversized and full of 0xFF.
//is this a good idea? We think so.
return T1ReadLong(MMU.CART_ROM, card.address & MMU.CART_ROM_MASK);
return T1ReadLong(MMU.CART_ROM, address);
}
break;
default:

View File

@ -191,7 +191,6 @@ SFORMAT SF_MMU[]={
{ "M7RG", 1, sizeof(MMU.ARM7_REG), MMU.ARM7_REG},
{ "M7WI", 1, sizeof(MMU.ARM7_WIRAM), MMU.ARM7_WIRAM},
{ "MSWI", 1, sizeof(MMU.SWIRAM), MMU.SWIRAM},
{ "MCRA", 1, sizeof(MMU.CART_RAM), MMU.CART_RAM},
{ "M9RW", 1, 1, &MMU.ARM9_RW_MODE},
{ "MDTC", 4, 1, &MMU.DTCMRegion},
{ "MITC", 4, 1, &MMU.ITCMRegion},
@ -680,64 +679,6 @@ void loadstate_slot(int num)
}
}
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;
size_t elems_read;
file = fopen ( file_name, "rb" );
if( file == NULL )
return 0;
elems_read = fread ( MMU.CART_RAM, SRAM_SIZE, 1, file );
fclose ( file );
osd->setLineColor(255, 255, 255);
osd->addLine("Loaded SRAM");
return 1;
}
int sram_save (const char *file_name) {
FILE *file;
size_t elems_written;
file = fopen ( file_name, "wb" );
if( file == NULL )
return 0;
elems_written = fwrite ( MMU.CART_RAM, SRAM_SIZE, 1, file );
fclose ( file );
osd->setLineColor(255, 255, 255);
osd->addLine("Saved SRAM");
return 1;
}
// note: guessSF is so we don't have to do a linear search through the SFORMAT array every time
// in the (most common) case that we already know where the next entry is.

View File

@ -127,6 +127,7 @@ static MemSpan MemSpan_TexMem(u32 ofs, u32 len)
currofs += curr.len;
u8* ptr = MMU.texInfo.textureSlotAddr[slot];
//TODO - dont alert if the masterbrightnesses are max or min
if(ptr == MMU.blank_memory) {
PROGINFO("Tried to reference unmapped texture memory: slot %d\n",slot);
}
@ -158,6 +159,7 @@ static MemSpan MemSpan_TexPalette(u32 ofs, u32 len)
currofs += curr.len;
u8* ptr = MMU.texInfo.texPalSlot[slot];
//TODO - dont alert if the masterbrightnesses are max or min
if(ptr == MMU.blank_memory) {
PROGINFO("Tried to reference unmapped texture palette memory: 16k slot #%d\n",slot);
}