sdk: added `Bit2Bin` tool

This commit is contained in:
Ivan Tatarinov 2021-04-25 14:12:04 +03:00
parent d58ac43c82
commit 4ff18c37f4
5 changed files with 160 additions and 99 deletions

Binary file not shown.

1
sdk/bin/.gitignore vendored
View File

@ -11,3 +11,4 @@ fpad
fpoke fpoke
GenRom GenRom
AddItem AddItem
Bit2Bin

BIN
sdk/bin/Bit2Bin.exe Executable file

Binary file not shown.

View File

@ -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.

View File

@ -1,26 +1,75 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
* SPDX-FileCopyrightText: Copyright (C) 2019-2021 Antonio Villena
*
* SPDX-License-Identifier: GPL-3.0-only
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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; FILE *fi, *fo;
int i, length; int i, length;
unsigned char mem[0x4000]; unsigned char mem[0x4000];
unsigned short j; unsigned short j;
void show_help() {
printf(
PROGRAM " version " VERSION " - " DESCRIPTION "\n"
COPYRIGHT "\n"
LICENSE "\n"
"Home page: " HOMEPAGE "\n"
"\n"
"Usage:\n"
" " PROGRAM " <input_file> <output_file>\n"
"\n"
" <input_file> Input BIT file\n"
" <output_file> Output BIN file\n"
"\n"
"All parameters are mandatory.\n"
);
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if( argc==1 ) if( argc==1 )
printf("\n" show_help(),
"Bit2Bin v0.05, strip .bit header and align binary to 16k, 2020-02-19\n\n"
" Bit2Bin <input_file> <output_file>\n\n"
" <input_file> Input BIT file\n"
" <output_file> Output BIN file\n\n"
"All params are mandatory\n\n"),
exit(0); exit(0);
if( argc!=3 ) if( argc!=3 )
printf("\nInvalid number of parameters\n"), printf("Invalid number of parameters\n"),
exit(-1); exit(-1);
fi= fopen(argv[1], "rb"); fi= fopen(argv[1], "rb");
if( !fi ) if( !fi )
printf("\nInput file not found: %s\n", argv[1]), printf("Input file not found: %s\n", argv[1]),
exit(-1); exit(-1);
fseek(fi, 0, SEEK_END); fseek(fi, 0, SEEK_END);
i= ftell(fi); i= ftell(fi);
@ -40,11 +89,11 @@ int main(int argc, char *argv[]) {
fread(mem, 1, j+4, fi); fread(mem, 1, j+4, fi);
length= mem[j+3]|mem[j+2]<<8|mem[j+1]<<16|mem[j]<<24; length= mem[j+3]|mem[j+2]<<8|mem[j+1]<<16|mem[j]<<24;
if( i!=length ) if( i!=length )
printf("\nInvalid file length\n"), printf("Invalid file length\n"),
exit(-1); exit(-1);
fo= fopen(argv[2], "wb+"); fo= fopen(argv[2], "wb+");
if( !fo ) if( !fo )
printf("\nCannot create output file: %s\n", argv[2]), printf("Cannot create output file: %s\n", argv[2]),
exit(-1); exit(-1);
j= i>>14; j= i>>14;
if( j>71 ){ if( j>71 ){
@ -61,7 +110,7 @@ int main(int argc, char *argv[]) {
argv[2][5]='0'; argv[2][5]='0';
fo= fopen(argv[2], "wb+"); fo= fopen(argv[2], "wb+");
if( !fo ) if( !fo )
printf("\nCannot create output file: %s\n", argv[2]), printf("Cannot create output file: %s\n", argv[2]),
exit(-1); exit(-1);
for ( i= 0; i<j-72; i++ ) for ( i= 0; i<j-72; i++ )
fread(mem, 1, 0x4000, fi), fread(mem, 1, 0x4000, fi),
@ -95,5 +144,5 @@ int main(int argc, char *argv[]) {
for ( i= 0; i<20-j; i++ ) for ( i= 0; i<20-j; i++ )
fwrite(mem, 1, 0x4000, fo); fwrite(mem, 1, 0x4000, fo);
} }
printf("\nFile generated successfully\n"); printf("File `%s' successfully created\n", argv[2]);
} }