···11+// MIT License
22+33+// Copyright (c) 2020 Vadim Grigoruk @nesbox // grigoruk@gmail.com
44+55+// Permission is hereby granted, free of charge, to any person obtaining a copy
66+// of this software and associated documentation files (the "Software"), to deal
77+// in the Software without restriction, including without limitation the rights
88+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99+// copies of the Software, and to permit persons to whom the Software is
1010+// furnished to do so, subject to the following conditions:
1111+1212+// The above copyright notice and this permission notice shall be included in all
1313+// copies or substantial portions of the Software.
1414+1515+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121+// SOFTWARE.
2222+2323+#include <stdio.h>
2424+#include <stdlib.h>
2525+#include <stdbool.h>
2626+#include <string.h>
2727+#include <zlib.h>
2828+2929+int main(int argc, char** argv)
3030+{
3131+ int res = -1;
3232+3333+ if(argc >= 3)
3434+ {
3535+ bool useZip = false;
3636+3737+ if(argc == 4 && strcmp(argv[3], "-z") == 0) useZip = true;
3838+3939+ FILE* bin = fopen(argv[1], "rb");
4040+4141+ if(bin)
4242+ {
4343+ fseek(bin, 0, SEEK_END);
4444+ int size = ftell(bin);
4545+ fseek(bin, 0, SEEK_SET);
4646+4747+ unsigned char* buffer = (unsigned char*)malloc(size);
4848+4949+ if(buffer)
5050+ {
5151+ fread(buffer, size, 1, bin);
5252+ fclose(bin);
5353+5454+ if(useZip)
5555+ {
5656+ unsigned char* output = (unsigned char*)malloc(size);
5757+5858+ if(output)
5959+ {
6060+ unsigned long sizeComp = size;
6161+ if(compress2(output, &sizeComp, buffer, size, Z_BEST_COMPRESSION) != Z_OK)
6262+ {
6363+ printf("compression error\n");
6464+ }
6565+ else
6666+ {
6767+ size = sizeComp;
6868+ memcpy(buffer, output, size);
6969+ }
7070+7171+ free(output);
7272+ }
7373+ else printf("memory error :(\n");
7474+ }
7575+7676+ FILE* txt = fopen(argv[2], "wb");
7777+7878+ if(txt)
7979+ {
8080+ for(int i = 0; i < size; i++)
8181+ fprintf(txt, "0x%02x, ", buffer[i]);
8282+8383+ fclose(txt);
8484+8585+ res = 0;
8686+ }
8787+ else printf("cannot open text file\n");
8888+8989+ free(buffer);
9090+ }
9191+9292+ }
9393+ else printf("cannot open bin file\n");
9494+ }
9595+ else printf("usage: bin2txt <bin> <txt>\n");
9696+9797+ return res;
9898+}
···11+// MIT License
22+33+// Copyright (c) 2020 Vadim Grigoruk @nesbox // grigoruk@gmail.com
44+55+// Permission is hereby granted, free of charge, to any person obtaining a copy
66+// of this software and associated documentation files (the "Software"), to deal
77+// in the Software without restriction, including without limitation the rights
88+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99+// copies of the Software, and to permit persons to whom the Software is
1010+// furnished to do so, subject to the following conditions:
1111+1212+// The above copyright notice and this permission notice shall be included in all
1313+// copies or substantial portions of the Software.
1414+1515+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121+// SOFTWARE.
2222+2323+#include <stdio.h>
2424+#include <stdlib.h>
2525+#include "project.h"
2626+2727+int main(int argc, char** argv)
2828+{
2929+ int res = -1;
3030+3131+ if(argc == 3)
3232+ {
3333+ FILE* cartFile = fopen(argv[1], "rb");
3434+3535+ if(cartFile)
3636+ {
3737+ fseek(cartFile, 0, SEEK_END);
3838+ int size = ftell(cartFile);
3939+ fseek(cartFile, 0, SEEK_SET);
4040+4141+ unsigned char* buffer = (unsigned char*)malloc(size);
4242+4343+ if(buffer)
4444+ {
4545+ fread(buffer, size, 1, cartFile);
4646+ fclose(cartFile);
4747+4848+ tic_cartridge cart = {0};
4949+5050+ tic_cart_load(&cart, buffer, size);
5151+5252+ FILE* project = fopen(argv[2], "wb");
5353+5454+ if(project)
5555+ {
5656+ unsigned char* out = (unsigned char*)malloc(sizeof(tic_cartridge) * 3);
5757+5858+ if(out)
5959+ {
6060+ s32 outSize = tic_project_save(argv[2], out, &cart);
6161+6262+ fwrite(out, outSize, 1, project);
6363+6464+ free(out);
6565+ }
6666+6767+ fclose(project);
6868+6969+ res = 0;
7070+ }
7171+ else printf("cannot open project file\n");
7272+7373+ free(buffer);
7474+ }
7575+7676+ }
7777+ else printf("cannot open cartridge file\n");
7878+ }
7979+ else printf("usage: cart2prj <cartridge> <project>\n");
8080+8181+ return res;
8282+}
+82
build/tools/prj2cart.c
···11+// MIT License
22+33+// Copyright (c) 2020 Vadim Grigoruk @nesbox // grigoruk@gmail.com
44+55+// Permission is hereby granted, free of charge, to any person obtaining a copy
66+// of this software and associated documentation files (the "Software"), to deal
77+// in the Software without restriction, including without limitation the rights
88+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99+// copies of the Software, and to permit persons to whom the Software is
1010+// furnished to do so, subject to the following conditions:
1111+1212+// The above copyright notice and this permission notice shall be included in all
1313+// copies or substantial portions of the Software.
1414+1515+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121+// SOFTWARE.
2222+2323+#include <stdio.h>
2424+#include <stdlib.h>
2525+#include "project.h"
2626+2727+int main(int argc, char** argv)
2828+{
2929+ int res = -1;
3030+3131+ if(argc == 3)
3232+ {
3333+ FILE* project = fopen(argv[1], "rb");
3434+3535+ if(project)
3636+ {
3737+ fseek(project, 0, SEEK_END);
3838+ int size = ftell(project);
3939+ fseek(project, 0, SEEK_SET);
4040+4141+ unsigned char* buffer = (unsigned char*)malloc(size);
4242+4343+ if(buffer)
4444+ {
4545+ fread(buffer, size, 1, project);
4646+ fclose(project);
4747+4848+ tic_cartridge cart = {0};
4949+5050+ tic_project_load(argv[1], buffer, size, &cart);
5151+5252+ FILE* cartFile = fopen(argv[2], "wb");
5353+5454+ if(cartFile)
5555+ {
5656+ unsigned char* out = (unsigned char*)malloc(sizeof(tic_cartridge));
5757+5858+ if(out)
5959+ {
6060+ int outSize = tic_cart_save(&cart, out);
6161+6262+ fwrite(out, outSize, 1, cartFile);
6363+6464+ free(out);
6565+ }
6666+6767+ fclose(cartFile);
6868+6969+ res = 0;
7070+ }
7171+ else printf("cannot open cartridge file\n");
7272+7373+ free(buffer);
7474+ }
7575+7676+ }
7777+ else printf("cannot open project file\n");
7878+ }
7979+ else printf("usage: prj2cart <project> <cartridge>\n");
8080+8181+ return res;
8282+}