EDIT 2: I also noticed that your cart example assumes all the memory in the cart is contiguous. The 8 Mbit cart is split into two 4 Mbit sections: 4 Mbit at 0x22400000, and 4 Mbit at 0x22600000. I don't know if the dram mirrors or not, but if it does, you could make the two sections contiguous by returning the area as the last mirror of the first section instead of the actually location.
EDIT 3: Actually, it only tests half the memory, so it doesn't run into the non-contiguous nature of the memory. The "ID" is the bank size for the DRAM, with each cart having two banks, one at 0x22400000 and the other at 0x22600000. I should change the address it uses for testing to check if the ram mirrors.
EDIT 4: HA! I was right! You can use the last mirror of the first bank of DRAM in the cart to make contiguous memory on the 8 Mbit cart... on real hardware. Yabuse doesn't support mirrors of the cart DRAM. I found a bug in Yabuse!
I calculate the cart start address like this:
Code:
cart = (uint32_t *)(dram_cartridge_area() + 0x200000 - dram_cartridge_size());
That gives 0x22580000 for the 8 Mbit cart, and 0x22400000 for the 32 Mbit cart.