Skip to content

Commit 12e1a66

Browse files
committed
Merge remote-tracking branch 'origin/main' into sokol
2 parents ab1a425 + 35bc7f7 commit 12e1a66

File tree

7 files changed

+71
-47
lines changed

7 files changed

+71
-47
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ include(cmake/runtime.cmake)
153153
include(cmake/gif.cmake)
154154
include(cmake/blipbuf.cmake)
155155
include(cmake/zlib.cmake)
156+
include(cmake/png.cmake)
156157
include(cmake/tools.cmake)
157158

158159
include(cmake/lua.cmake)
@@ -171,7 +172,6 @@ include(cmake/core.cmake)
171172
include(cmake/wave.cmake)
172173
include(cmake/argparse.cmake)
173174
include(cmake/naett.cmake)
174-
include(cmake/png.cmake)
175175
include(cmake/studio.cmake)
176176

177177
include(cmake/sdl.cmake)

build/android/app/src/main/AndroidManifest.xml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,31 @@
8989
</intent-filter>
9090

9191
<!-- Drop file event -->
92+
<!-- Handle .tic files -->
9293
<intent-filter>
9394
<action android:name="android.intent.action.VIEW" />
9495
<category android:name="android.intent.category.DEFAULT" />
96+
<data android:scheme="content" />
97+
<data android:scheme="file" />
98+
<data android:host="*" />
99+
<!-- case insensitive options is only available from Android 12, so we have to list all -->
95100
<data android:mimeType="*/*" android:pathPattern=".*\\.tic" />
96-
<data android:mimeType="*/*" android:pathPattern=".*\\.png" />
101+
<data android:mimeType="*/*" android:pathPattern=".*\\.Tic" />
102+
<data android:mimeType="*/*" android:pathPattern=".*\\.TIc" />
103+
<data android:mimeType="*/*" android:pathPattern=".*\\.TIC" />
104+
<data android:mimeType="*/*" android:pathPattern=".*\\.tIc" />
105+
<data android:mimeType="*/*" android:pathPattern=".*\\.tIC" />
106+
<data android:mimeType="*/*" android:pathPattern=".*\\.tiC" />
107+
<data android:mimeType="*/*" android:pathPattern=".*\\.TiC" />
108+
</intent-filter>
109+
110+
<!-- Handle .png files -->
111+
<intent-filter>
112+
<action android:name="android.intent.action.VIEW" />
113+
<category android:name="android.intent.category.DEFAULT" />
114+
<data android:scheme="content" />
115+
<data android:scheme="file" />
116+
<data android:mimeType="image/png" />
97117
</intent-filter>
98118

99119
</activity>

cmake/core.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ set(TIC80CORE_SRC
2929
${TIC80CORE_DIR}/ext/fft.c
3030
${TIC80CORE_DIR}/ext/kiss_fft.c
3131
${TIC80CORE_DIR}/ext/kiss_fftr.c
32+
${TIC80CORE_DIR}/ext/png.c
3233
)
3334

3435
if(BUILD_DEPRECATED)
@@ -55,6 +56,7 @@ target_include_directories(tic80core
5556
${CMAKE_SOURCE_DIR}/include
5657
${CMAKE_SOURCE_DIR}/src)
5758

59+
target_link_libraries(tic80core PRIVATE png)
5860
target_link_libraries(tic80core PRIVATE blipbuf)
5961

6062
if(BUILD_WITH_ZLIB)

cmake/studio.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ set(TIC80STUDIO_SRC
1313
${TIC80LIB_DIR}/studio/fs.c
1414
${TIC80LIB_DIR}/ext/md5.c
1515
${TIC80LIB_DIR}/ext/json.c
16+
${TIC80LIB_DIR}/ext/png.c
1617
)
1718

1819
if(BUILD_EDITORS)
@@ -28,7 +29,6 @@ if(BUILD_EDITORS)
2829
${TIC80LIB_DIR}/studio/net.c
2930
${TIC80LIB_DIR}/ext/history.c
3031
${TIC80LIB_DIR}/ext/gif.c
31-
${TIC80LIB_DIR}/ext/png.c
3232
)
3333
endif()
3434

src/cart.c

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <stdlib.h>
3333
#include "tic_assert.h"
3434
#include "tools.h"
35+
#include "ext/png.h"
3536

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

85+
static png_buffer getRawCartFromPng(png_buffer buffer)
86+
{
87+
png_buffer zip = png_decode(buffer);
88+
89+
if (zip.size)
90+
{
91+
png_buffer buf = png_create(sizeof(tic_cartridge));
92+
93+
buf.size = tic_tool_unzip(buf.data, buf.size, zip.data, zip.size);
94+
free(zip.data);
95+
96+
if(buf.size)
97+
return buf;
98+
99+
free(buf.data);
100+
}
101+
102+
return (png_buffer){.data = NULL, .size = 0};
103+
}
104+
105+
tic_cartridge* loadPngCart(png_buffer buffer)
106+
{
107+
png_buffer buf = getRawCartFromPng(buffer);
108+
109+
if(buf.data)
110+
{
111+
tic_cartridge* cart = malloc(sizeof(tic_cartridge));
112+
tic_cart_load(cart, buf.data, buf.size);
113+
free(buf.data);
114+
115+
return cart;
116+
}
117+
118+
return NULL;
119+
}
120+
84121
void tic_cart_load(tic_cartridge* cart, const u8* buffer, s32 size)
85122
{
86123
memset(cart, 0, sizeof(tic_cartridge));
@@ -90,27 +127,16 @@ void tic_cart_load(tic_cartridge* cart, const u8* buffer, s32 size)
90127
// check if this cartridge is in PNG format
91128
if (!memcmp(buffer, "\x89PNG", 4))
92129
{
93-
s32 siz;
94-
const u8* ptr = buffer + 8;
95-
// iterate on chunks until we find a cartridge
96-
while (ptr < end)
130+
png_buffer buf = getRawCartFromPng((png_buffer){.data = (u8*)buffer, .size = size});
131+
132+
if(buf.data)
97133
{
98-
siz = ((ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]);
99-
if (!memcmp(ptr + 4, "caRt", 4) && siz > 0)
100-
{
101-
chunk_cart = malloc(sizeof(tic_cartridge));
102-
if (chunk_cart)
103-
{
104-
size = tic_tool_unzip(chunk_cart, sizeof(tic_cartridge), ptr + 8, siz);
105-
buffer = chunk_cart;
106-
end = buffer + size;
107-
}
108-
break;
109-
}
110-
ptr += siz + 12;
134+
chunk_cart = buf.data;
135+
buffer = buf.data;
136+
size = buf.size;
137+
end = buffer + size;
111138
}
112-
// error, no TIC-80 cartridge chunk in PNG???
113-
if (!chunk_cart)
139+
else
114140
return;
115141
}
116142

src/studio/studio.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,30 +1542,6 @@ bool project_ext(const char* name)
15421542
return false;
15431543
}
15441544

1545-
tic_cartridge* loadPngCart(png_buffer buffer)
1546-
{
1547-
png_buffer zip = png_decode(buffer);
1548-
1549-
if (zip.size)
1550-
{
1551-
png_buffer buf = png_create(sizeof(tic_cartridge));
1552-
1553-
buf.size = tic_tool_unzip(buf.data, buf.size, zip.data, zip.size);
1554-
free(zip.data);
1555-
1556-
if(buf.size)
1557-
{
1558-
tic_cartridge* cart = malloc(sizeof(tic_cartridge));
1559-
tic_cart_load(cart, buf.data, buf.size);
1560-
free(buf.data);
1561-
1562-
return cart;
1563-
}
1564-
}
1565-
1566-
return NULL;
1567-
}
1568-
15691545
void studioRomSaved(Studio* studio)
15701546
{
15711547
updateTitle(studio);

src/system/libretro/tic80_libretro.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ RETRO_API void retro_get_system_info(struct retro_system_info *info)
336336
memset(info, 0, sizeof(*info));
337337
info->library_name = TIC_NAME;
338338
info->library_version = TIC_VERSION;
339-
info->valid_extensions = "tic";
339+
info->valid_extensions = "tic|png";
340340
info->need_fullpath = false;
341341
info->block_extract = false;
342342
}

0 commit comments

Comments
 (0)