Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ include(cmake/gif.cmake)
include(cmake/blipbuf.cmake)
include(cmake/zlib.cmake)
include(cmake/zip.cmake)
include(cmake/png.cmake)
include(cmake/tools.cmake)

include(cmake/lua.cmake)
Expand All @@ -170,7 +171,6 @@ include(cmake/core.cmake)
include(cmake/wave.cmake)
include(cmake/argparse.cmake)
include(cmake/naett.cmake)
include(cmake/png.cmake)
include(cmake/studio.cmake)

include(cmake/sdl.cmake)
Expand Down
2 changes: 2 additions & 0 deletions cmake/core.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(TIC80CORE_SRC
${TIC80CORE_DIR}/ext/fft.c
${TIC80CORE_DIR}/ext/kiss_fft.c
${TIC80CORE_DIR}/ext/kiss_fftr.c
${TIC80CORE_DIR}/ext/png.c
)

if(BUILD_DEPRECATED)
Expand All @@ -55,6 +56,7 @@ target_include_directories(tic80core
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/src)

target_link_libraries(tic80core PRIVATE png)
target_link_libraries(tic80core PRIVATE blipbuf)

if(BUILD_WITH_ZLIB)
Expand Down
2 changes: 1 addition & 1 deletion cmake/studio.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(TIC80STUDIO_SRC
${TIC80LIB_DIR}/studio/fs.c
${TIC80LIB_DIR}/ext/md5.c
${TIC80LIB_DIR}/ext/json.c
${TIC80LIB_DIR}/ext/png.c
)

if(BUILD_EDITORS)
Expand All @@ -28,7 +29,6 @@ if(BUILD_EDITORS)
${TIC80LIB_DIR}/studio/net.c
${TIC80LIB_DIR}/ext/history.c
${TIC80LIB_DIR}/ext/gif.c
${TIC80LIB_DIR}/ext/png.c
)
endif()

Expand Down
64 changes: 45 additions & 19 deletions src/cart.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <stdlib.h>
#include "tic_assert.h"
#include "tools.h"
#include "ext/png.h"

typedef enum
{
Expand Down Expand Up @@ -81,6 +82,42 @@ static s32 chunkSize(const Chunk* chunk)
return chunk->size == 0 && (chunk->type == CHUNK_CODE || chunk->type == CHUNK_BINARY) ? TIC_BANK_SIZE : retro_le_to_cpu16(chunk->size);
}

static png_buffer getRawCartFromPng(png_buffer buffer)
{
png_buffer zip = png_decode(buffer);

if (zip.size)
{
png_buffer buf = png_create(sizeof(tic_cartridge));

buf.size = tic_tool_unzip(buf.data, buf.size, zip.data, zip.size);
free(zip.data);

if(buf.size)
return buf;

free(buf.data);
}

return (png_buffer){.data = NULL, .size = 0};
}

tic_cartridge* loadPngCart(png_buffer buffer)
{
png_buffer buf = getRawCartFromPng(buffer);

if(buf.data)
{
tic_cartridge* cart = malloc(sizeof(tic_cartridge));
tic_cart_load(cart, buf.data, buf.size);
free(buf.data);

return cart;
}

return NULL;
}

void tic_cart_load(tic_cartridge* cart, const u8* buffer, s32 size)
{
memset(cart, 0, sizeof(tic_cartridge));
Expand All @@ -90,27 +127,16 @@ void tic_cart_load(tic_cartridge* cart, const u8* buffer, s32 size)
// check if this cartridge is in PNG format
if (!memcmp(buffer, "\x89PNG", 4))
{
s32 siz;
const u8* ptr = buffer + 8;
// iterate on chunks until we find a cartridge
while (ptr < end)
png_buffer buf = getRawCartFromPng((png_buffer){.data = (u8*)buffer, .size = size});

if(buf.data)
{
siz = ((ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]);
if (!memcmp(ptr + 4, "caRt", 4) && siz > 0)
{
chunk_cart = malloc(sizeof(tic_cartridge));
if (chunk_cart)
{
size = tic_tool_unzip(chunk_cart, sizeof(tic_cartridge), ptr + 8, siz);
buffer = chunk_cart;
end = buffer + size;
}
break;
}
ptr += siz + 12;
chunk_cart = buf.data;
buffer = buf.data;
size = buf.size;
end = buffer + size;
}
// error, no TIC-80 cartridge chunk in PNG???
if (!chunk_cart)
else
return;
}

Expand Down
24 changes: 0 additions & 24 deletions src/studio/studio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1531,30 +1531,6 @@ bool project_ext(const char* name)
return false;
}

tic_cartridge* loadPngCart(png_buffer buffer)
{
png_buffer zip = png_decode(buffer);

if (zip.size)
{
png_buffer buf = png_create(sizeof(tic_cartridge));

buf.size = tic_tool_unzip(buf.data, buf.size, zip.data, zip.size);
free(zip.data);

if(buf.size)
{
tic_cartridge* cart = malloc(sizeof(tic_cartridge));
tic_cart_load(cart, buf.data, buf.size);
free(buf.data);

return cart;
}
}

return NULL;
}

void studioRomSaved(Studio* studio)
{
updateTitle(studio);
Expand Down
2 changes: 1 addition & 1 deletion src/system/libretro/tic80_libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ RETRO_API void retro_get_system_info(struct retro_system_info *info)
memset(info, 0, sizeof(*info));
info->library_name = TIC_NAME;
info->library_version = TIC_VERSION;
info->valid_extensions = "tic";
info->valid_extensions = "tic|png";
info->need_fullpath = false;
info->block_extract = false;
}
Expand Down
Loading