sdk: added `AddItem` tool to SDK

This commit is contained in:
Ivan Tatarinov 2021-04-14 16:25:23 +03:00
parent 4fee4cfef7
commit 02ab6a26b8
11 changed files with 147 additions and 72 deletions

View File

@ -1,68 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
FILE *fi, *fo;
int i;
unsigned char mem[0x4004], core;
unsigned short j, k;
int main(int argc, char *argv[]) {
if( argc==1 )
printf("\n"
"AddItem v0.02, simulates Machine and ROM addition to the ZX-Uno flash image\n\n"
" AddItem <type> <input_file> <slot>\n\n"
" <type> ROM or COREX, when 2<=X<=45, i.e. CORE5\n"
" <input_file> Input .TAP file generate with GenRom\n"
" <slot> Number of slot from 0 to 63, only when type is ROM\n\n"
"All modifications occur in the file FLASH.ZX1\n\n"),
exit(0);
fo= fopen("FLASH.ZX1", "rb+");
if( strstr(argv[1], "CORE")==argv[1] && strlen(argv[1])<=6 && strlen(argv[1])>=5 && argc==3 ){
core= (strlen(argv[1])==5 ? argv[1][4] : (argv[1][4]-'0')*10+argv[1][5])-'2';
if( core>43 )
printf("\nCore number out of range: %d\n", core+2),
exit(-1);
fi= fopen(argv[2], "rb");
if( !fi )
printf("\nInput file not found: %s\n", argv[2]),
exit(-1);
fread(mem, 1, 0x58, fi);
fseek(fo, 0x7100+(core<<5), SEEK_SET);
fwrite(mem+0x34, 1, 0x20, fo);
j= mem[3];
fseek(fo, (core>7?0x160000:0xac000)+core*0x54000, SEEK_SET);
for ( i=0; i<j; i++ )
fread(mem, 1, 0x4004, fi),
fwrite(mem, 1, 0x4000, fo);
}
else if( !strcmp(argv[1], "ROM") && argc==4 ){
fi= fopen(argv[3], "rb");
if( !fi )
printf("\nInput file not found: %s\n", argv[3]),
exit(-1);
fseek(fo, 0x7000, SEEK_SET);
fread(mem, 1, 0x40, fo);
for ( i= 0; i<0x40; i++ )
if( mem[i]==0xff )
break;
mem[i]= i;
fseek(fo, 0x7000, SEEK_SET);
fwrite(mem, 1, 0x40, fo);
fread(mem, 1, 0x58, fi);
fseek(fo, 0x6000|i<<6, SEEK_SET);
k= mem[2]= atoi(argv[2]);
fwrite(mem+2, 1, 0x20, fo);
fwrite(mem+0x34, 1, 0x20, fo);
j= mem[3];
for ( i=0; i<j; i++ )
fseek(fo, (k<19?0xc000:0x300000)+k*0x4000, SEEK_SET),
k= (k+1)&0x3f,
fread(mem, 1, 0x4004, fi),
fwrite(mem, 1, 0x4000, fo);
}
else
printf("\nInvalid parameters\n"),
exit(-1);
printf("\nDone\n");
}

Binary file not shown.

View File

@ -49,6 +49,7 @@ FCUT := fcut$(EXECEXT)
FPAD := fpad$(EXECEXT) FPAD := fpad$(EXECEXT)
FPOKE := fpoke$(EXECEXT) FPOKE := fpoke$(EXECEXT)
GENROM := GenRom$(EXECEXT) GENROM := GenRom$(EXECEXT)
ADDITEM := AddItem$(EXECEXT)
TOOLS:=\ TOOLS:=\
bin/$(SJASMPLUS) \ bin/$(SJASMPLUS) \
@ -56,7 +57,8 @@ TOOLS:=\
bin/$(FCUT) \ bin/$(FCUT) \
bin/$(FPAD) \ bin/$(FPAD) \
bin/$(FPOKE) \ bin/$(FPOKE) \
bin/$(GENROM) bin/$(GENROM) \
bin/$(ADDITEM)
.PHONY: all .PHONY: all
all: $(TOOLS) all: $(TOOLS)

View File

@ -33,6 +33,7 @@ Command | Target
`make bin/fpad` | **fpad** `make bin/fpad` | **fpad**
`make bin/fpoke` | **fpoke** `make bin/fpoke` | **fpoke**
`make bin/GenRom` | **GenRom** `make bin/GenRom` | **GenRom**
`make bin/AddItem` | **AddItem**
To build using MinGW add this parameter for `make` tool: To build using MinGW add this parameter for `make` tool:
@ -114,6 +115,7 @@ This has the same behavior as the inclusion of `common.mk` file in a Makefile.
* fpad * fpad
* fpoke * fpoke
* GenRom * GenRom
* AddItem
on Windows platform is disabled right now because of presence of precompiled binaries of them in repository. on Windows platform is disabled right now because of presence of precompiled binaries of them in repository.
*By default* they are not deleted when cleaning. *By default* they are not deleted when cleaning.

1
sdk/bin/.gitignore vendored
View File

@ -8,3 +8,4 @@ fcut
fpad fpad
fpoke fpoke
GenRom GenRom
AddItem

BIN
sdk/bin/AddItem.exe Normal file

Binary file not shown.

View File

@ -0,0 +1,11 @@
SPDX-FileName: AddItem.exe
SPDX-FileType: BINARY
SPDX-FileChecksum: SHA1: 4c0298aa44631d46b241f90471d36775b536d844
SPDX-FileCopyrightText: Copyright (C) 2019, 2021 Antonio Villena
SPDX-License-Identifier: GPL-3.0-only
SPDX-FileComment: AddItem version 0.02 - simulates Machine and ROM addition to the ZX-Uno flash image.

View File

@ -28,6 +28,7 @@ FCUT := fcut$(EXECEXT)
FPAD := fpad$(EXECEXT) FPAD := fpad$(EXECEXT)
FPOKE := fpoke$(EXECEXT) FPOKE := fpoke$(EXECEXT)
GENROM := GenRom$(EXECEXT) GENROM := GenRom$(EXECEXT)
ADDITEM := AddItem$(EXECEXT)
TOOLS:= \ TOOLS:= \
../bin/$(SJASMPLUS) \ ../bin/$(SJASMPLUS) \
@ -35,7 +36,8 @@ TOOLS:= \
../bin/$(FCUT) \ ../bin/$(FCUT) \
../bin/$(FPAD) \ ../bin/$(FPAD) \
../bin/$(FPOKE) \ ../bin/$(FPOKE) \
../bin/$(GENROM) ../bin/$(GENROM) \
../bin/$(ADDITEM)
.PHONY: all .PHONY: all
all: $(TOOLS) all: $(TOOLS)
@ -94,10 +96,14 @@ zx7b/$(ZX7B): | zx7b
../bin/$(GENROM): tools/$(GENROM) ../bin/$(GENROM): tools/$(GENROM)
cp $< $@ cp $< $@
../bin/$(ADDITEM): tools/$(ADDITEM)
cp $< $@
tools/$(FCUT) \ tools/$(FCUT) \
tools/$(FPAD) \ tools/$(FPAD) \
tools/$(FPOKE) \ tools/$(FPOKE) \
tools/$(GENROM): | tools tools/$(GENROM) \
tools/$(ADDITEM): | tools
$(MAKE) -w -C $| $(MAKE) -w -C $|
endif endif

View File

@ -10,3 +10,5 @@ fpoke
fpoke.exe fpoke.exe
GenRom GenRom
GenRom.exe GenRom.exe
AddItem
AddItem.exe

114
sdk/src/tools/AddItem.c Normal file
View File

@ -0,0 +1,114 @@
/*
* AddItem - simulates Machine and ROM addition to the ZX-Uno flash image.
*
* 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 <stdlib.h>
#include <string.h>
#define PROGRAM "AddItem"
#define DESCRIPTION "simulates Machine and ROM addition to the ZX-Uno flash image."
#define VERSION "0.02"
#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/"
#define OUTPUT_FILE "FLASH.ZX1"
FILE *fi, *fo;
int i;
unsigned char mem[0x4004], core;
unsigned short j, k;
void show_help() {
printf(
PROGRAM " version " VERSION " - " DESCRIPTION "\n"
COPYRIGHT "\n"
LICENSE "\n"
"Home page: " HOMEPAGE "\n"
"\n"
"Usage:\n"
" " PROGRAM " <type> <input_file> <slot>\n"
"\n"
" <type> ROM or COREX, where 2<=X<=45, i.e. CORE5\n"
" <input_file> Input .TAP file generated with GenRom\n"
" <slot> Slot's number from 0 to 63, only when type is ROM\n"
"\n"
"All modifications occur in the file `" OUTPUT_FILE "'.\n"
);
}
int main(int argc, char *argv[]) {
if( argc==1 )
show_help(),
exit(0);
fo= fopen(OUTPUT_FILE, "rb+");
if( strstr(argv[1], "CORE")==argv[1] && strlen(argv[1])<=6 && strlen(argv[1])>=5 && argc==3 ){
core= (strlen(argv[1])==5 ? argv[1][4] : (argv[1][4]-'0')*10+argv[1][5])-'2';
if( core>43 )
printf("\nCore number out of range: %d\n", core+2),
exit(-1);
fi= fopen(argv[2], "rb");
if( !fi )
printf("\nInput file not found: %s\n", argv[2]),
exit(-1);
fread(mem, 1, 0x58, fi);
fseek(fo, 0x7100+(core<<5), SEEK_SET);
fwrite(mem+0x34, 1, 0x20, fo);
j= mem[3];
fseek(fo, (core>7?0x160000:0xac000)+core*0x54000, SEEK_SET);
for ( i=0; i<j; i++ )
fread(mem, 1, 0x4004, fi),
fwrite(mem, 1, 0x4000, fo);
}
else if( !strcmp(argv[1], "ROM") && argc==4 ){
fi= fopen(argv[3], "rb");
if( !fi )
printf("\nInput file not found: %s\n", argv[3]),
exit(-1);
fseek(fo, 0x7000, SEEK_SET);
fread(mem, 1, 0x40, fo);
for ( i= 0; i<0x40; i++ )
if( mem[i]==0xff )
break;
mem[i]= i;
fseek(fo, 0x7000, SEEK_SET);
fwrite(mem, 1, 0x40, fo);
fread(mem, 1, 0x58, fi);
fseek(fo, 0x6000|i<<6, SEEK_SET);
k= mem[2]= atoi(argv[2]);
fwrite(mem+2, 1, 0x20, fo);
fwrite(mem+0x34, 1, 0x20, fo);
j= mem[3];
for ( i=0; i<j; i++ )
fseek(fo, (k<19?0xc000:0x300000)+k*0x4000, SEEK_SET),
k= (k+1)&0x3f,
fread(mem, 1, 0x4004, fi),
fwrite(mem, 1, 0x4000, fo);
}
else
printf("\nInvalid parameters\n"),
exit(-1);
printf("File `" OUTPUT_FILE "' is successfully updated.\n");
}

View File

@ -24,12 +24,14 @@ FCUT := fcut$(EXECEXT)
FPAD := fpad$(EXECEXT) FPAD := fpad$(EXECEXT)
FPOKE := fpoke$(EXECEXT) FPOKE := fpoke$(EXECEXT)
GENROM := GenRom$(EXECEXT) GENROM := GenRom$(EXECEXT)
ADDITEM := AddItem$(EXECEXT)
TOOLS:=\ TOOLS:=\
$(FCUT) \ $(FCUT) \
$(FPAD) \ $(FPAD) \
$(FPOKE) \ $(FPOKE) \
$(GENROM) $(GENROM) \
$(ADDITEM)
.PHONY: all .PHONY: all
all: $(TOOLS) all: $(TOOLS)
@ -46,6 +48,9 @@ $(FPOKE): fpoke.c
$(GENROM): GenRom.c $(GENROM): GenRom.c
$(CC) $(CFLAGS) -o $@ $< $(CC) $(CFLAGS) -o $@ $<
$(ADDITEM): AddItem.c
$(CC) $(CFLAGS) -o $@ $<
.PHONY: clean .PHONY: clean
clean: clean:
rm -f $(TOOLS) rm -f $(TOOLS)