this repo has no description
0
fork

Configure Feed

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

#1089: added prj2cart tool

nesbox 6fb25a3e 07c54287

+311 -117
+11 -6
CMakeLists.txt
··· 572 572 set(CMAKE_DISABLE_TESTING ON CACHE BOOL "" FORCE) 573 573 add_subdirectory(${THIRDPARTY_DIR}/zip) 574 574 575 + set(TOOLS_DIR ${CMAKE_SOURCE_DIR}/build/tools) 576 + 575 577 ################################ 576 - # bin2txt 578 + # bin2txt cart2prj prj2cart 577 579 ################################ 578 580 579 581 if(BUILD_DEMO_CARTS) 580 - set(BIN2TXT_DIR ${CMAKE_SOURCE_DIR}/build/tools/bin2txt) 581 - set(BIN2TXT_SRC 582 - ${BIN2TXT_DIR}/bin2txt.c 583 - ) 582 + 583 + add_executable(cart2prj ${TOOLS_DIR}/cart2prj.c ${CMAKE_SOURCE_DIR}/src/project.c) 584 + target_include_directories(cart2prj PRIVATE ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/include) 585 + target_link_libraries(cart2prj tic80core) 584 586 585 - add_executable(bin2txt ${BIN2TXT_SRC}) 587 + add_executable(prj2cart ${TOOLS_DIR}/prj2cart.c ${CMAKE_SOURCE_DIR}/src/project.c) 588 + target_include_directories(prj2cart PRIVATE ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/include) 589 + target_link_libraries(prj2cart tic80core) 586 590 591 + add_executable(bin2txt ${TOOLS_DIR}/bin2txt.c) 587 592 target_link_libraries(bin2txt zlib) 588 593 589 594 file(GLOB DEMO_CARTS ${CMAKE_SOURCE_DIR}/demos/*.tic )
+98
build/tools/bin2txt.c
··· 1 + // MIT License 2 + 3 + // Copyright (c) 2020 Vadim Grigoruk @nesbox // grigoruk@gmail.com 4 + 5 + // Permission is hereby granted, free of charge, to any person obtaining a copy 6 + // of this software and associated documentation files (the "Software"), to deal 7 + // in the Software without restriction, including without limitation the rights 8 + // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 + // copies of the Software, and to permit persons to whom the Software is 10 + // furnished to do so, subject to the following conditions: 11 + 12 + // The above copyright notice and this permission notice shall be included in all 13 + // copies or substantial portions of the Software. 14 + 15 + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 + // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 + // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 + // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 + // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 + // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 + // SOFTWARE. 22 + 23 + #include <stdio.h> 24 + #include <stdlib.h> 25 + #include <stdbool.h> 26 + #include <string.h> 27 + #include <zlib.h> 28 + 29 + int main(int argc, char** argv) 30 + { 31 + int res = -1; 32 + 33 + if(argc >= 3) 34 + { 35 + bool useZip = false; 36 + 37 + if(argc == 4 && strcmp(argv[3], "-z") == 0) useZip = true; 38 + 39 + FILE* bin = fopen(argv[1], "rb"); 40 + 41 + if(bin) 42 + { 43 + fseek(bin, 0, SEEK_END); 44 + int size = ftell(bin); 45 + fseek(bin, 0, SEEK_SET); 46 + 47 + unsigned char* buffer = (unsigned char*)malloc(size); 48 + 49 + if(buffer) 50 + { 51 + fread(buffer, size, 1, bin); 52 + fclose(bin); 53 + 54 + if(useZip) 55 + { 56 + unsigned char* output = (unsigned char*)malloc(size); 57 + 58 + if(output) 59 + { 60 + unsigned long sizeComp = size; 61 + if(compress2(output, &sizeComp, buffer, size, Z_BEST_COMPRESSION) != Z_OK) 62 + { 63 + printf("compression error\n"); 64 + } 65 + else 66 + { 67 + size = sizeComp; 68 + memcpy(buffer, output, size); 69 + } 70 + 71 + free(output); 72 + } 73 + else printf("memory error :(\n"); 74 + } 75 + 76 + FILE* txt = fopen(argv[2], "wb"); 77 + 78 + if(txt) 79 + { 80 + for(int i = 0; i < size; i++) 81 + fprintf(txt, "0x%02x, ", buffer[i]); 82 + 83 + fclose(txt); 84 + 85 + res = 0; 86 + } 87 + else printf("cannot open text file\n"); 88 + 89 + free(buffer); 90 + } 91 + 92 + } 93 + else printf("cannot open bin file\n"); 94 + } 95 + else printf("usage: bin2txt <bin> <txt>\n"); 96 + 97 + return res; 98 + }
-76
build/tools/bin2txt/bin2txt.c
··· 1 - #include <stdio.h> 2 - #include <stdlib.h> 3 - #include <stdbool.h> 4 - #include <string.h> 5 - #include <zlib.h> 6 - 7 - int main(int argc, char** argv) 8 - { 9 - int res = -1; 10 - 11 - if(argc >= 3) 12 - { 13 - bool useZip = false; 14 - 15 - if(argc == 4 && strcmp(argv[3], "-z") == 0) useZip = true; 16 - 17 - FILE* bin = fopen(argv[1], "rb"); 18 - 19 - if(bin) 20 - { 21 - fseek(bin, 0, SEEK_END); 22 - int size = ftell(bin); 23 - fseek(bin, 0, SEEK_SET); 24 - 25 - unsigned char* buffer = (unsigned char*)malloc(size); 26 - 27 - if(buffer) 28 - { 29 - fread(buffer, size, 1, bin); 30 - fclose(bin); 31 - 32 - if(useZip) 33 - { 34 - unsigned char* output = (unsigned char*)malloc(size); 35 - 36 - if(output) 37 - { 38 - unsigned long sizeComp = size; 39 - if(compress2(output, &sizeComp, buffer, size, Z_BEST_COMPRESSION) != Z_OK) 40 - { 41 - printf("compression error\n"); 42 - } 43 - else 44 - { 45 - size = sizeComp; 46 - memcpy(buffer, output, size); 47 - } 48 - 49 - free(output); 50 - } 51 - else printf("memory error :(\n"); 52 - } 53 - 54 - FILE* txt = fopen(argv[2], "wb"); 55 - 56 - if(txt) 57 - { 58 - for(int i = 0; i < size; i++) 59 - fprintf(txt, "0x%02x, ", buffer[i]); 60 - 61 - fclose(txt); 62 - 63 - res = 0; 64 - } 65 - else printf("cannot open text file\n"); 66 - 67 - free(buffer); 68 - } 69 - 70 - } 71 - else printf("cannot open bin file\n"); 72 - } 73 - else printf("usage: bin2txt <bin> <txt>\n"); 74 - 75 - return res; 76 - }
+82
build/tools/cart2prj.c
··· 1 + // MIT License 2 + 3 + // Copyright (c) 2020 Vadim Grigoruk @nesbox // grigoruk@gmail.com 4 + 5 + // Permission is hereby granted, free of charge, to any person obtaining a copy 6 + // of this software and associated documentation files (the "Software"), to deal 7 + // in the Software without restriction, including without limitation the rights 8 + // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 + // copies of the Software, and to permit persons to whom the Software is 10 + // furnished to do so, subject to the following conditions: 11 + 12 + // The above copyright notice and this permission notice shall be included in all 13 + // copies or substantial portions of the Software. 14 + 15 + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 + // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 + // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 + // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 + // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 + // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 + // SOFTWARE. 22 + 23 + #include <stdio.h> 24 + #include <stdlib.h> 25 + #include "project.h" 26 + 27 + int main(int argc, char** argv) 28 + { 29 + int res = -1; 30 + 31 + if(argc == 3) 32 + { 33 + FILE* cartFile = fopen(argv[1], "rb"); 34 + 35 + if(cartFile) 36 + { 37 + fseek(cartFile, 0, SEEK_END); 38 + int size = ftell(cartFile); 39 + fseek(cartFile, 0, SEEK_SET); 40 + 41 + unsigned char* buffer = (unsigned char*)malloc(size); 42 + 43 + if(buffer) 44 + { 45 + fread(buffer, size, 1, cartFile); 46 + fclose(cartFile); 47 + 48 + tic_cartridge cart = {0}; 49 + 50 + tic_cart_load(&cart, buffer, size); 51 + 52 + FILE* project = fopen(argv[2], "wb"); 53 + 54 + if(project) 55 + { 56 + unsigned char* out = (unsigned char*)malloc(sizeof(tic_cartridge) * 3); 57 + 58 + if(out) 59 + { 60 + s32 outSize = tic_project_save(argv[2], out, &cart); 61 + 62 + fwrite(out, outSize, 1, project); 63 + 64 + free(out); 65 + } 66 + 67 + fclose(project); 68 + 69 + res = 0; 70 + } 71 + else printf("cannot open project file\n"); 72 + 73 + free(buffer); 74 + } 75 + 76 + } 77 + else printf("cannot open cartridge file\n"); 78 + } 79 + else printf("usage: cart2prj <cartridge> <project>\n"); 80 + 81 + return res; 82 + }
+82
build/tools/prj2cart.c
··· 1 + // MIT License 2 + 3 + // Copyright (c) 2020 Vadim Grigoruk @nesbox // grigoruk@gmail.com 4 + 5 + // Permission is hereby granted, free of charge, to any person obtaining a copy 6 + // of this software and associated documentation files (the "Software"), to deal 7 + // in the Software without restriction, including without limitation the rights 8 + // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 + // copies of the Software, and to permit persons to whom the Software is 10 + // furnished to do so, subject to the following conditions: 11 + 12 + // The above copyright notice and this permission notice shall be included in all 13 + // copies or substantial portions of the Software. 14 + 15 + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 + // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 + // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 + // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 + // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 + // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 + // SOFTWARE. 22 + 23 + #include <stdio.h> 24 + #include <stdlib.h> 25 + #include "project.h" 26 + 27 + int main(int argc, char** argv) 28 + { 29 + int res = -1; 30 + 31 + if(argc == 3) 32 + { 33 + FILE* project = fopen(argv[1], "rb"); 34 + 35 + if(project) 36 + { 37 + fseek(project, 0, SEEK_END); 38 + int size = ftell(project); 39 + fseek(project, 0, SEEK_SET); 40 + 41 + unsigned char* buffer = (unsigned char*)malloc(size); 42 + 43 + if(buffer) 44 + { 45 + fread(buffer, size, 1, project); 46 + fclose(project); 47 + 48 + tic_cartridge cart = {0}; 49 + 50 + tic_project_load(argv[1], buffer, size, &cart); 51 + 52 + FILE* cartFile = fopen(argv[2], "wb"); 53 + 54 + if(cartFile) 55 + { 56 + unsigned char* out = (unsigned char*)malloc(sizeof(tic_cartridge)); 57 + 58 + if(out) 59 + { 60 + int outSize = tic_cart_save(&cart, out); 61 + 62 + fwrite(out, outSize, 1, cartFile); 63 + 64 + free(out); 65 + } 66 + 67 + fclose(cartFile); 68 + 69 + res = 0; 70 + } 71 + else printf("cannot open cartridge file\n"); 72 + 73 + free(buffer); 74 + } 75 + 76 + } 77 + else printf("cannot open project file\n"); 78 + } 79 + else printf("usage: prj2cart <project> <cartridge>\n"); 80 + 81 + return res; 82 + }
+1 -1
src/map.c
··· 1047 1047 { 1048 1048 u8* data = malloc(size); 1049 1049 1050 - str2buf(clipboard, strlen(clipboard), data, true); 1050 + tic_tool_str2buf(clipboard, strlen(clipboard), data, true); 1051 1051 1052 1052 if(data[0] * data[1] == size - 2) 1053 1053 {
+1 -1
src/music.c
··· 685 685 { 686 686 u8* data = malloc(size); 687 687 688 - str2buf(clipboard, strlen(clipboard), data, true); 688 + tic_tool_str2buf(clipboard, strlen(clipboard), data, true); 689 689 690 690 ClipboardHeader header = {0}; 691 691
+3 -3
src/project.c
··· 21 21 // SOFTWARE. 22 22 23 23 #include "project.h" 24 - #include "studio.h" 24 + #include "tools.h" 25 25 26 26 #include <stdlib.h> 27 27 #include <stdio.h> ··· 224 224 if(index < count) 225 225 { 226 226 ptr += sizeof("-- 999:") - 1; 227 - str2buf(ptr, size*2, (u8*)dst + size*index, flip); 227 + tic_tool_str2buf(ptr, size*2, (u8*)dst + size*index, flip); 228 228 ptr += size*2 + 1; 229 229 230 230 ptr = getLineEnd(ptr); ··· 235 235 else 236 236 { 237 237 ptr += sizeof("-- 999:") - 1; 238 - str2buf(ptr, end - ptr, (u8*)dst, flip); 238 + tic_tool_str2buf(ptr, end - ptr, (u8*)dst, flip); 239 239 } 240 240 241 241 done = true;
+7
src/project.h
··· 24 24 25 25 #include "cart.h" 26 26 27 + #define PROJECT_LUA_EXT ".lua" 28 + #define PROJECT_MOON_EXT ".moon" 29 + #define PROJECT_JS_EXT ".js" 30 + #define PROJECT_WREN_EXT ".wren" 31 + #define PROJECT_SQUIRREL_EXT ".nut" 32 + #define PROJECT_FENNEL_EXT ".fnl" 33 + 27 34 bool tic_project_load(const char* name, const char* data, s32 size, tic_cartridge* dst); 28 35 s32 tic_project_save(const char* name, void* data, const tic_cartridge* cart);
+2 -23
src/studio.c
··· 36 36 #include "dialog.h" 37 37 #include "menu.h" 38 38 #include "surf.h" 39 + #include "project.h" 39 40 40 41 #include "fs.h" 41 42 ··· 539 540 } 540 541 } 541 542 542 - void str2buf(const char* str, s32 size, void* buf, bool flip) 543 - { 544 - char val[] = "0x00"; 545 - const char* ptr = str; 546 - 547 - for(s32 i = 0; i < size/2; i++) 548 - { 549 - if(flip) 550 - { 551 - val[3] = *ptr++; 552 - val[2] = *ptr++; 553 - } 554 - else 555 - { 556 - val[2] = *ptr++; 557 - val[3] = *ptr++; 558 - } 559 - 560 - ((u8*)buf)[i] = (u8)strtol(val, NULL, 16); 561 - } 562 - } 563 - 564 543 static void removeWhiteSpaces(char* str) 565 544 { 566 545 s32 i = 0; ··· 588 567 589 568 bool valid = strlen(clipboard) == size * 2; 590 569 591 - if(valid) str2buf(clipboard, strlen(clipboard), data, flip); 570 + if(valid) tic_tool_str2buf(clipboard, strlen(clipboard), data, flip); 592 571 593 572 getSystem()->freeClipboardText(clipboard); 594 573
-7
src/studio.h
··· 57 57 #define KEYMAP_DAT_PATH TIC_LOCAL_VERSION KEYMAP_DAT 58 58 59 59 #define CART_EXT ".tic" 60 - #define PROJECT_LUA_EXT ".lua" 61 - #define PROJECT_MOON_EXT ".moon" 62 - #define PROJECT_JS_EXT ".js" 63 - #define PROJECT_WREN_EXT ".wren" 64 - #define PROJECT_SQUIRREL_EXT ".nut" 65 - #define PROJECT_FENNEL_EXT ".fnl" 66 60 67 61 #define SHOW_TOOLTIP(FORMAT, ...) \ 68 62 { \ ··· 122 116 u32 zip(u8* dest, size_t destSize, const u8* source, size_t size); 123 117 u32 unzip(u8* dest, size_t bufSize, const u8* source, size_t size); 124 118 125 - void str2buf(const char* str, s32 size, void* buf, bool flip); 126 119 void toClipboard(const void* data, s32 size, bool flip); 127 120 bool fromClipboard(void* data, s32 size, bool flip, bool remove_white_spaces); 128 121
+23
src/tools.c
··· 23 23 #include "tools.h" 24 24 25 25 #include <string.h> 26 + #include <stdlib.h> 26 27 27 28 extern void tic_tool_poke4(void* addr, u32 index, u8 value); 28 29 extern u8 tic_tool_peek4(const void* addr, u32 index); ··· 157 158 158 159 return true; 159 160 } 161 + 162 + void tic_tool_str2buf(const char* str, s32 size, void* buf, bool flip) 163 + { 164 + char val[] = "0x00"; 165 + const char* ptr = str; 166 + 167 + for(s32 i = 0; i < size/2; i++) 168 + { 169 + if(flip) 170 + { 171 + val[3] = *ptr++; 172 + val[2] = *ptr++; 173 + } 174 + else 175 + { 176 + val[2] = *ptr++; 177 + val[3] = *ptr++; 178 + } 179 + 180 + ((u8*)buf)[i] = (u8)strtol(val, NULL, 16); 181 + } 182 + }
+1
src/tools.h
··· 82 82 s32 tic_tool_get_track_row_sfx(const tic_track_row* row); 83 83 void tic_tool_set_track_row_sfx(tic_track_row* row, s32 sfx); 84 84 bool tic_tool_is_noise(const tic_waveform* wave); 85 + void tic_tool_str2buf(const char* str, s32 size, void* buf, bool flip);