diff --git a/firmware/Bit2Bin.exe b/firmware/Bit2Bin.exe deleted file mode 100644 index 979b395..0000000 Binary files a/firmware/Bit2Bin.exe and /dev/null differ diff --git a/sdk/bin/.gitignore b/sdk/bin/.gitignore index 1400274..80525db 100644 --- a/sdk/bin/.gitignore +++ b/sdk/bin/.gitignore @@ -11,3 +11,4 @@ fpad fpoke GenRom AddItem +Bit2Bin diff --git a/sdk/bin/Bit2Bin.exe b/sdk/bin/Bit2Bin.exe new file mode 100755 index 0000000..b119cdd Binary files /dev/null and b/sdk/bin/Bit2Bin.exe differ diff --git a/sdk/bin/Bit2Bin.exe.license b/sdk/bin/Bit2Bin.exe.license new file mode 100644 index 0000000..77e1554 --- /dev/null +++ b/sdk/bin/Bit2Bin.exe.license @@ -0,0 +1,11 @@ +SPDX-FileName: Bit2Bin.exe + +SPDX-FileType: BINARY + +SPDX-FileChecksum: SHA1: f1484d968816b72f7c1a246e11a468c175e8822a + +SPDX-FileCopyrightText: Copyright (C) 2019-2021 Antonio Villena + +SPDX-License-Identifier: GPL-3.0-only + +SPDX-FileComment: Bit2Bin version 0.05 (2020-02-19) - strip .bit header and align binary to 16K. diff --git a/firmware/Bit2Bin.c b/sdk/src/tools/Bit2Bin.c similarity index 51% rename from firmware/Bit2Bin.c rename to sdk/src/tools/Bit2Bin.c index 8514c2d..e91f162 100644 --- a/firmware/Bit2Bin.c +++ b/sdk/src/tools/Bit2Bin.c @@ -1,99 +1,148 @@ -#include -#include - -FILE *fi, *fo; -int i, length; -unsigned char mem[0x4000]; -unsigned short j; - -int main(int argc, char *argv[]) { - if( argc==1 ) - printf("\n" - "Bit2Bin v0.05, strip .bit header and align binary to 16k, 2020-02-19\n\n" - " Bit2Bin \n\n" - " Input BIT file\n" - " Output BIN file\n\n" - "All params are mandatory\n\n"), - exit(0); - if( argc!=3 ) - printf("\nInvalid number of parameters\n"), - exit(-1); - fi= fopen(argv[1], "rb"); - if( !fi ) - printf("\nInput file not found: %s\n", argv[1]), - exit(-1); - fseek(fi, 0, SEEK_END); - i= ftell(fi); - fseek(fi, 0, SEEK_SET); - fread(mem, 1, 2, fi); - i-= (j= mem[1]|mem[0]<<8)+4; - fread(mem, 1, j+2, fi); - i-= (j= mem[j+1]|mem[j]<<8)+3; - fread(mem, 1, j+3, fi); - i-= (j= mem[j+1]|mem[j]<<8)+3; - fread(mem, 1, j+3, fi); - i-= (j= mem[j+1]|mem[j]<<8)+3; - fread(mem, 1, j+3, fi); - i-= (j= mem[j+1]|mem[j]<<8)+3; - fread(mem, 1, j+3, fi); - i-= (j= mem[j+1]|mem[j]<<8)+4; - fread(mem, 1, j+4, fi); - length= mem[j+3]|mem[j+2]<<8|mem[j+1]<<16|mem[j]<<24; - if( i!=length ) - printf("\nInvalid file length\n"), - exit(-1); - fo= fopen(argv[2], "wb+"); - if( !fo ) - printf("\nCannot create output file: %s\n", argv[2]), - exit(-1); - j= i>>14; - if( j>71 ){ - for ( i= 0; i<72; i++ ) - fread(mem, 1, 0x4000, fi), - fwrite(mem, 1, 0x4000, fo); - fclose(fo); - argv[2][strlen(argv[2])-5]++; - if(argv[2][strlen(argv[2])-5]==':') - if(strlen(argv[2])==9) - argv[2]= "CORE10.ZX3"; - else - argv[2][4]++, - argv[2][5]='0'; - fo= fopen(argv[2], "wb+"); - if( !fo ) - printf("\nCannot create output file: %s\n", argv[2]), - exit(-1); - for ( i= 0; i48 ) - for ( i= 0; i<71-j; i++ ) - fwrite(mem, 1, 0x4000, fo); - else if( j>28 ) - for ( i= 0; i<48-j; i++ ) - fwrite(mem, 1, 0x4000, fo); - else if( j>20 ) - for ( i= 0; i<28-j; i++ ) - fwrite(mem, 1, 0x4000, fo); - else - for ( i= 0; i<20-j; i++ ) - fwrite(mem, 1, 0x4000, fo); - } - printf("\nFile generated successfully\n"); -} +/* + * Bit2Bin - strip .bit header and align binary to 16K. + * + * Copyright (C) 2019-2021 Antonio Villena + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-FileCopyrightText: Copyright (C) 2019-2021 Antonio Villena + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include +#include +#include + +#include +#include +#include + +#define PROGRAM "Bit2Bin" +#define DESCRIPTION "strip .bit header and align binary to 16K." +#define VERSION "0.05 (2020-02-19)" +#define COPYRIGHT "Copyright (C) 2019-2021 Antonio Villena" +#define LICENSE \ +"This program is free software: you can redistribute it and/or modify\n" \ +"it under the terms of the GNU General Public License as published by\n" \ +"the Free Software Foundation, version 3." +#define HOMEPAGE "https://github.com/zxdos/zxuno/" + +FILE *fi, *fo; +int i, length; +unsigned char mem[0x4000]; +unsigned short j; + +void show_help() { + printf( + PROGRAM " version " VERSION " - " DESCRIPTION "\n" + COPYRIGHT "\n" + LICENSE "\n" + "Home page: " HOMEPAGE "\n" + "\n" + "Usage:\n" + " " PROGRAM " \n" + "\n" + " Input BIT file\n" + " Output BIN file\n" + "\n" + "All parameters are mandatory.\n" + ); +} + +int main(int argc, char *argv[]) { + if( argc==1 ) + show_help(), + exit(0); + if( argc!=3 ) + printf("Invalid number of parameters\n"), + exit(-1); + fi= fopen(argv[1], "rb"); + if( !fi ) + printf("Input file not found: %s\n", argv[1]), + exit(-1); + fseek(fi, 0, SEEK_END); + i= ftell(fi); + fseek(fi, 0, SEEK_SET); + fread(mem, 1, 2, fi); + i-= (j= mem[1]|mem[0]<<8)+4; + fread(mem, 1, j+2, fi); + i-= (j= mem[j+1]|mem[j]<<8)+3; + fread(mem, 1, j+3, fi); + i-= (j= mem[j+1]|mem[j]<<8)+3; + fread(mem, 1, j+3, fi); + i-= (j= mem[j+1]|mem[j]<<8)+3; + fread(mem, 1, j+3, fi); + i-= (j= mem[j+1]|mem[j]<<8)+3; + fread(mem, 1, j+3, fi); + i-= (j= mem[j+1]|mem[j]<<8)+4; + fread(mem, 1, j+4, fi); + length= mem[j+3]|mem[j+2]<<8|mem[j+1]<<16|mem[j]<<24; + if( i!=length ) + printf("Invalid file length\n"), + exit(-1); + fo= fopen(argv[2], "wb+"); + if( !fo ) + printf("Cannot create output file: %s\n", argv[2]), + exit(-1); + j= i>>14; + if( j>71 ){ + for ( i= 0; i<72; i++ ) + fread(mem, 1, 0x4000, fi), + fwrite(mem, 1, 0x4000, fo); + fclose(fo); + argv[2][strlen(argv[2])-5]++; + if(argv[2][strlen(argv[2])-5]==':') + if(strlen(argv[2])==9) + argv[2]= "CORE10.ZX3"; + else + argv[2][4]++, + argv[2][5]='0'; + fo= fopen(argv[2], "wb+"); + if( !fo ) + printf("Cannot create output file: %s\n", argv[2]), + exit(-1); + for ( i= 0; i48 ) + for ( i= 0; i<71-j; i++ ) + fwrite(mem, 1, 0x4000, fo); + else if( j>28 ) + for ( i= 0; i<48-j; i++ ) + fwrite(mem, 1, 0x4000, fo); + else if( j>20 ) + for ( i= 0; i<28-j; i++ ) + fwrite(mem, 1, 0x4000, fo); + else + for ( i= 0; i<20-j; i++ ) + fwrite(mem, 1, 0x4000, fo); + } + printf("File `%s' successfully created\n", argv[2]); +}