johannes-fetz / joengine

Jo Engine is an open source 2D and 3D game engine for the Sega Saturn written in C under MIT license
http://jo-engine.org/
MIT License
205 stars 32 forks source link

JO_COMPILE_WITH_RAM_CARD_SUPPORT RAM Banks Are Incorrect #70

Closed slinga-homebrew closed 1 year ago

slinga-homebrew commented 1 year ago

Hi Johannes,

The start addresses and sizes for the expansion RAM banks appear to be incorrect. In core.c:

static bool                 jo_init_memory(void)
{
    static unsigned char    global_memory[JO_GLOBAL_MEMORY_SIZE_FOR_MALLOC];

    jo_add_memory_zone(global_memory, sizeof(global_memory));
#ifdef JO_COMPILE_WITH_RAM_CARD_SUPPORT
    if (jo_get_extended_ram_cartridge_type() == CART_8MBits)
    {
        jo_enable_extended_ram_cartridge_support();
        jo_set_a_bus_register();
        jo_add_memory_zone((unsigned char *)0x2247ffff, 0x180000);
        jo_add_memory_zone((unsigned char *)0x2267ffff, 0x180000);
    }
    else if (jo_get_extended_ram_cartridge_type() == CART_32MBits)
    {
        jo_enable_extended_ram_cartridge_support();
        jo_set_a_bus_register();
        jo_add_memory_zone((unsigned char *)0x2247ffff, 0x180000);
        jo_add_memory_zone((unsigned char *)0x2267ffff, 0x180000);
        jo_add_memory_zone((unsigned char *)0x2287ffff, 0x180000);
        jo_add_memory_zone((unsigned char *)0x22a7ffff, 0x180000);
        jo_add_memory_zone((unsigned char *)0x22c7ffff, 0x180000);
        jo_add_memory_zone((unsigned char *)0x22e7ffff, 0x180000);
        jo_add_memory_zone((unsigned char *)0x2307ffff, 0x180000);
    }
#endif
#ifdef JO_DEBUG
    // We check if the Work RAM for malloc is on the user RAM area
    // It's not perfect but better than nothing
    if (!JO_IS_ARRAY_INSIDE_USER_RAM_AREA(global_memory))
        return (false);
#endif
    return (true);
}

For the 8Mbit cartridge the total ram should equal 1 MB. The size of each bank should be 0x80000 (512k) not 0x180000 (1.5MB). The start address should be 0x22400000. The RAM appears to be in two separate non-adjacent banks so it requires two calls:

jo_add_memory_zone((unsigned char *)0x22400000, 0x80000);
jo_add_memory_zone((unsigned char *)0x22600000, 0x80000);

For the 32 Mbit cartridge the total RAM should equal 4 MB. As the RAM appears to be adjacent it should be able to do a single call:

jo_add_memory_zone((unsigned char *)0x22400000, 0x200000);

Thanks in advance.

Thanks to Knight0fDragon for spotting.

johannes-fetz commented 1 year ago

Hi,

I'll check that

johannes-fetz commented 1 year ago

Fixed