this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #2088 from bztsrc/main

Add png chunk loading

authored by

Vadim Grigoruk and committed by
GitHub
97b96fbc e48d6bd6

+31
+31
src/cart.c
··· 84 84 { 85 85 memset(cart, 0, sizeof(tic_cartridge)); 86 86 const u8* end = buffer + size; 87 + u8 *chunk_cart = NULL; 88 + 89 + // check if this cartridge is in PNG format 90 + if (!memcmp(buffer, "\x89PNG", 4)) 91 + { 92 + s32 siz; 93 + const u8* ptr = buffer + 8; 94 + // iterate on chunks until we find a cartridge 95 + while (ptr < end) 96 + { 97 + siz = ((ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]); 98 + if (!memcmp(ptr + 4, "caRt", 4) && siz > 0) 99 + { 100 + chunk_cart = malloc(sizeof(tic_cartridge)); 101 + if (chunk_cart) 102 + { 103 + size = tic_tool_unzip(chunk_cart, sizeof(tic_cartridge), ptr + 8, siz); 104 + buffer = chunk_cart; 105 + end = buffer + size; 106 + } 107 + break; 108 + } 109 + ptr += siz + 12; 110 + } 111 + // error, no TIC-80 cartridge chunk in PNG??? 112 + if (!chunk_cart) 113 + return; 114 + } 87 115 88 116 #define LOAD_CHUNK(to) memcpy(&to, ptr, MIN(sizeof(to), chunk->size ? retro_le_to_cpu16(chunk->size) : TIC_BANK_SIZE)) 89 117 ··· 219 247 } 220 248 } 221 249 } 250 + // if we have allocated the buffer from a PNG chunk 251 + if (chunk_cart) 252 + free(chunk_cart); 222 253 } 223 254 224 255