From 28165a19e495020da43e8aeb1e361cf6a3201424 Mon Sep 17 00:00:00 2001 From: kub Date: Mon, 5 Jun 2023 18:04:24 +0000 Subject: [PATCH] core, always allocate a power of 2 for cartridges --- pico/cart.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pico/cart.c b/pico/cart.c index dee5485b..bcdf5529 100644 --- a/pico/cart.c +++ b/pico/cart.c @@ -713,21 +713,22 @@ static unsigned char *PicoCartAlloc(int filesize, int is_sms) { unsigned char *rom; + // make size power of 2 for easier banking handling + int s = 0, tmp = filesize; + while ((tmp >>= 1) != 0) + s++; + if (filesize > (1 << s)) + s++; + rom_alloc_size = 1 << s; + if (is_sms) { - // make size power of 2 for easier banking handling - int s = 0, tmp = filesize; - while ((tmp >>= 1) != 0) - s++; - if (filesize > (1 << s)) - s++; - rom_alloc_size = 1 << s; // be sure we can cover all address space if (rom_alloc_size < 0x10000) rom_alloc_size = 0x10000; } else { // align to 512K for memhandlers - rom_alloc_size = (filesize + 0x7ffff) & ~0x7ffff; + rom_alloc_size = (rom_alloc_size + 0x7ffff) & ~0x7ffff; } if (rom_alloc_size - filesize < 4) -- 2.39.5