From 3e183219ab7b7c92e8683422dbbcbd4a1516d8d9 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Tue, 28 Nov 2017 09:16:52 +0300 Subject: [PATCH] Allow to load a map of tiles of any length, not only 32kb #412 --- src/console.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/console.c b/src/console.c index ea6ca91..5c6f74c 100644 --- a/src/console.c +++ b/src/console.c @@ -1349,15 +1349,21 @@ static void onImportSprites(const char* name, const void* buffer, size_t size, v commandDone(console); } +static void injectMap(Console* console, const void* buffer, s32 size) +{ + enum {Size = sizeof(tic_map)}; + + SDL_memset(&console->tic->cart.gfx.map, 0, Size); + SDL_memcpy(&console->tic->cart.gfx.map, buffer, SDL_min(size, Size)); +} + static void onImportMap(const char* name, const void* buffer, size_t size, void* data) { Console* console = (Console*)data; - enum {Size = sizeof(tic_map)}; - - if(name && buffer && size == Size) + if(name && buffer && size <= sizeof(tic_map)) { - memcpy(&console->tic->cart.gfx.map, buffer, size); + injectMap(console, buffer, size); printLine(console); printBack(console, "map successfully imported"); @@ -2761,9 +2767,9 @@ static void cmdInjectMap(Console* console, const char* param, const char* name) if(map) { - if(size == sizeof(tic_map)) + if(size <= sizeof(tic_map)) { - SDL_memcpy(embed.file.gfx.map.data, map, size); + injectMap(console, map, size); embed.yes = true; embed.fast = true;