VOGONS


First post, by superfury

User metadata
Rank l33t++
Rank
l33t++

I'm trying to fix my x86 emulation (XT with 1MB memory and AT with exactly 6MB memory) to detect the right amount of memory (from the BIOS).

My current code:

OPTINLINE void applyMemoryHoles(uint_32 *realaddress, byte *nonexistant)
{
if (*realaddress >= LOW_MEMORYHOLE_END) //1MB+?
{
if ((*realaddress >= MID_MEMORYHOLE_START) && (*realaddress < MID_MEMORYHOLE_END)) //15-16M ISA memory hole?
{
*nonexistant = 1; //Non-existant memory!
}
else if (*realaddress<MID_MEMORYHOLE_START) //Mid memory(IBM AT memory range)?
{
*realaddress -= (LOW_MEMORYHOLE_END - LOW_MEMORYHOLE_START); //Patch to less memory to make memory linear!
}
else if (!((*realaddress>=MID_MEMORYHOLE_END) && (*realaddress<HIGH_MEMORYHOLE_START))) //Not High memory hole(32-bit memory range)?
{
*nonexistant = 1; //Non-existant memory!
}
else //High memory?
{
*realaddress -= (LOW_MEMORYHOLE_END - LOW_MEMORYHOLE_START)+(MID_MEMORYHOLE_END - MID_MEMORYHOLE_START); //Patch to less memory to make memory linear!
}
}
else if (*realaddress >= LOW_MEMORYHOLE_START) //640K ISA memory hole addressed?
{
*nonexistant = 1; //Non-existant memory!
}
}

And of course the defines of the memory holes themselves(their locations):

//Memory hole start/end locations!
#define LOW_MEMORYHOLE_START 0xA0000
#define LOW_MEMORYHOLE_END 0x100000
#define MID_MEMORYHOLE_START 0xF00000
#define MID_MEMORYHOLE_END 0x1000000
#define HIGH_MEMORYHOLE_START 0xC0000000

For some reason, the IBM AT BIOS detects 6144KB of RAM, instead of the 6MB actually installed. That's 144KB too much? Why does it detect 6144KB of RAM instead(0x24000 bytes of RAM)?
Edit: Calculating it again: 6(MB)*1024(KB/MB)=6144KB, so the memory calculation is correct?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io