EDIT: FIXED MISTAKE in switch replacement
gbCopyMemory function is not echo-ram aware. Needs a check to see if the source address is in Echo Ram area, then subtract 0x2000 from the source address.
We don't need to validate the destination address, since it only DMAs to either OAM or VRAM.
Replace it with:
void gbCopyMemory(u16 d, u16 s, int count)
{
if (s>=0xE000 && s<0xFE00)
{
s-=0x2000;
}
while(count)
{
gbMemoryMap[d>>12][d & 0x0fff] = gbMemoryMap[s>>12][s & 0x0fff];
s++;
d++;
count--;
}
}
gbWriteMemory needs this change:
Replace this:
if(address < 0xfe00)
{
gbMemoryMap[address>>12][address & 0x0fff] = value;
return;
}
with this:
if (address<0xE000)
{
gbMemoryMap[address>>12][address & 0x0fff] = value;
return;
}
if(address < 0xfe00)
{
gbMemoryMap[(address-0x2000)>>12][address & 0x0fff] = value;
return;
}
gbReadOpcode is just really bad code, it has a major bug in that the switch statement doesn't do anything!
Replace the switch:
switch(address & 0xf000)
with this:
switch((address>>12) & 0x000f)
(this was edited)
Then right before the last return add this:
if (address>=0xE000 && address<0xFE00)
{
return gbMemoryMap[(address-0x2000)>>12][address & 0x0fff];
}
gbReadMemory needs this right before the last return:
if (address>=0xE000 && address<0xFE00)
{
return gbMemoryMap[(address-0x2000)>>12][address & 0x0fff];
}
This should fix the Echo Ram problem which plagued the SML2 run.