diff --git a/firmware/fcut.c.url b/firmware/fcut.c.url deleted file mode 100644 index 5a813a4..0000000 --- a/firmware/fcut.c.url +++ /dev/null @@ -1 +0,0 @@ -https://sourceforge.net/p/emuscriptoria/code/HEAD/tree/desprot/fcut.c \ No newline at end of file diff --git a/firmware/generaflash_multi.bat b/firmware/generaflash_multi.bat index e627170..20b9360 100644 --- a/firmware/generaflash_multi.bat +++ b/firmware/generaflash_multi.bat @@ -1,3 +1,4 @@ +@call ..\sdk\setvars.bat set output=\Google Drive\Proyecto ZX-Uno\cores_%2\ echo define version %1 > version.asm call make.bat diff --git a/hardware/kartusho/amstrad/fcut.exe b/hardware/kartusho/amstrad/fcut.exe deleted file mode 100644 index 4a466ae..0000000 Binary files a/hardware/kartusho/amstrad/fcut.exe and /dev/null differ diff --git a/hardware/kartusho/roms/fcut.exe b/hardware/kartusho/roms/fcut.exe deleted file mode 100644 index 7316022..0000000 Binary files a/hardware/kartusho/roms/fcut.exe and /dev/null differ diff --git a/hardware/kartusho/snapshots/fcut.exe b/hardware/kartusho/snapshots/fcut.exe deleted file mode 100644 index 7316022..0000000 Binary files a/hardware/kartusho/snapshots/fcut.exe and /dev/null differ diff --git a/modflash/make.bat b/modflash/make.bat index 89304dc..18223a3 100644 --- a/modflash/make.bat +++ b/modflash/make.bat @@ -1,6 +1,8 @@ @rem SPDX-FileCopyrightText: 2019 Antonio Villena <_@antoniovillena.es> @rem @rem SPDX-FileContributor: 2021 Ivan Tatarinov +@rem +@rem SPDX-License-Identifier: GPL-3.0-only copy /Y FLASHempty.ZX1 FLASH.ZX1 call addroms.bat call addcores.bat diff --git a/sdk/Makefile b/sdk/Makefile index 3d04af9..728b8f7 100644 --- a/sdk/Makefile +++ b/sdk/Makefile @@ -3,22 +3,58 @@ # SPDX-License-Identifier: GPL-3.0-or-later # # Supported environments: -# * GNU/Linux -# * Windows NT (using MinGW/MSYS/Cygwin/WSL) +# * GNU on Linux, FreeBSD etc. +# * GNU on Windows NT (using MinGW/MSYS/Cygwin/WSL) +# +# Build: +# make [BUILD=] [FORCEBUILD=] [] +# Clean: +# make [BUILD=] [FORCECLEAN=] clean +# +# where: +# is one of: mingw32, mingw64. +# is 1 to force build, otherwise do not (default). +# is 1 to force clean, otherwise do not (default). +# is one of values of TOOLS variable (see below). +# +# Notes: +# BUILD, FORCEBUILD, FORCECLEAN variables may be set in user's environment. include common.mk -ifeq ($(OS),Windows_NT) -SJASMPLUS := sjasmplus.exe -ZX7B := zx7b.exe +ifeq ($(BUILD),mingw32) +FORCEBUILD:=1 +else ifeq ($(BUILD),mingw64) +FORCEBUILD:=1 else -SJASMPLUS := sjasmplus -ZX7B := zx7b +BUILD:= +FORCEBUILD:=0 endif +ifdef $(FORCECLEAN) +ifneq ($(FORCECLEAN),1) +FORCECLEAN:=0 +else +FORCECLEAN:=0 +endif +endif + +export BUILD +export FORCEBUILD +export FORCECLEAN + +SJASMPLUS := sjasmplus$(EXECEXT) +ZX7B := zx7b$(EXECEXT) +FCUT := fcut$(EXECEXT) +FPAD := fpad$(EXECEXT) +FPOKE := fpoke$(EXECEXT) + TOOLS:=\ bin/$(SJASMPLUS) \ - bin/$(ZX7B) + bin/$(ZX7B) \ + bin/$(FCUT) \ + bin/$(FPAD) \ + bin/$(FPOKE) .PHONY: all all: $(TOOLS) diff --git a/sdk/README.md b/sdk/README.md index 7169cfd..32c70fd 100644 --- a/sdk/README.md +++ b/sdk/README.md @@ -29,6 +29,28 @@ Command | Target `make` | all tools `make bin/sjasmplus` | **sjasmplus** `make bin/zx7b` | **zx7b** +`make bin/fcut` | **fcut** +`make bin/fpad` | **fpad** +`make bin/fpoke` | **fpoke** + +To build using MinGW add this parameter for **make** tool: + +Parameter | Target system +----|---- +`BUILD=mingw32` | Windows with i686 architecture (32-bits) +`BUILD=mingw64` | Windows with AMD64 architecture (64-bits) + +Remember to specify proper file extension (".exe") for target when building with MinGW. Example: + +```bash +make BUILD=mingw64 bin/fcut.exe bin/fpad.exe bin/fpoke.exe +``` + +Then you may use **strip** tool to strip debug information from file and thus shrink file's size: + +```bash +strip bin/fcut.exe bin/fpad.exe bin/fpoke.exe +``` ## 2.2. Clean tools @@ -38,6 +60,12 @@ To clean everything type: make clean ``` +To clean MinGW builds use appropriate `BUILD` parameter as described in [2.1](#21-build-tools). Example: + +```bash +make BUILD=mingw64 clean +``` + ## 2.3. Tools usage These tools are supposed to be used mainly in Makefiles and Bash scripts invoked from Makefiles. @@ -77,30 +105,38 @@ This has the same behavior as the inclusion of `common.mk` file in a Makefile. # 3. Using SDK in GNU environment on Windows -**NOTE**: compilation of the following tools: +**NOTE**: *by default* compilation of the following tools: * sjasmplus * zx7b +* fcut +* fpad +* fpoke -on Windows platform is disabled right now because of presence of precompiled binaries of them in repository. They are not deleted when cleaning. +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. ## 3.1. Build tools -The building process is similar to one for GNU on Linux, FreeBSD etc. See [2.1](#21-build-tools). +The building process is similar to one for GNU on Linux, FreeBSD etc. +See [2.1](#21-build-tools) with addition that you should provide correct target name (specify file extension ".exe") and also specify parameter `FORCEBUILD=1`. ## 3.2. Clean tools -The cleaning process is similar to one for GNU on Linux, FreeBSD etc. See [2.2](#22-clean-tools). +The cleaning process is similar to one for GNU on Linux, FreeBSD etc. +See [2.2](#22-clean-tools) with addition that you should specify parameter `FORCECLEAN=1`. ## 3.3. Tools usage ### 3.3.1. In Makefiles -The usage is similar to one for GNU/Linux, FreeBSD etc. See [2.3.1](#231-in-makefiles). +The usage is similar to one for GNU on Linux, FreeBSD etc. +See [2.3.1](#231-in-makefiles). ### 3.3.2. In Bash scripts -The usage is similar to one for GNU/Linux, FreeBSD etc. See [2.3.2](#232-in-bash-scripts). +The usage is similar to one for GNU on Linux, FreeBSD etc. +See [2.3.2](#232-in-bash-scripts). # 4. Using SDK on Windows without GNU environment diff --git a/sdk/bin/.gitignore b/sdk/bin/.gitignore index 0590ff0..6d8327c 100644 --- a/sdk/bin/.gitignore +++ b/sdk/bin/.gitignore @@ -1,2 +1,9 @@ +# SPDX-FileCopyrightText: 2021 Ivan Tatarinov +# +# SPDX-License-Identifier: CC0-1.0 + sjasmplus zx7b +fcut +fpad +fpoke diff --git a/sdk/bin/fcut.exe b/sdk/bin/fcut.exe new file mode 100644 index 0000000..4e8244b Binary files /dev/null and b/sdk/bin/fcut.exe differ diff --git a/sdk/bin/fcut.exe.license b/sdk/bin/fcut.exe.license new file mode 100644 index 0000000..92aa9db --- /dev/null +++ b/sdk/bin/fcut.exe.license @@ -0,0 +1,11 @@ +SPDX-FileName: fcut.exe + +SPDX-FileType: BINARY + +SPDX-FileChecksum: SHA1: 57dc4b8241477fe9bfdf03b249575b38876da7f2 + +SPDX-FileCopyrightText: Copyright (C) 2015, 2021 Antonio Villena + +SPDX-License-Identifier: GPL-3.0-only + +SPDX-FileComment: fcut version 1.00 (20 Jun 2015) - a file hexadecimal cutter. diff --git a/sdk/bin/fpad.exe b/sdk/bin/fpad.exe new file mode 100644 index 0000000..0aa0462 Binary files /dev/null and b/sdk/bin/fpad.exe differ diff --git a/sdk/bin/fpad.exe.license b/sdk/bin/fpad.exe.license new file mode 100644 index 0000000..d4b7e90 --- /dev/null +++ b/sdk/bin/fpad.exe.license @@ -0,0 +1,11 @@ +SPDX-FileName: fpad.exe + +SPDX-FileType: BINARY + +SPDX-FileChecksum: SHA1: 1aa7d48a742da3ffaff2c29bcb8acceb7eb8042c + +SPDX-FileCopyrightText: Copyright (C) 2016, 2021 Antonio Villena + +SPDX-License-Identifier: GPL-3.0-only + +SPDX-FileComment: fpad version 1.00 (24 Apr 2016) - generate a file with padded values. diff --git a/sdk/bin/fpoke.exe b/sdk/bin/fpoke.exe new file mode 100644 index 0000000..38d7909 Binary files /dev/null and b/sdk/bin/fpoke.exe differ diff --git a/sdk/bin/fpoke.exe.license b/sdk/bin/fpoke.exe.license new file mode 100644 index 0000000..10b306a --- /dev/null +++ b/sdk/bin/fpoke.exe.license @@ -0,0 +1,11 @@ +SPDX-FileName: fpoke.exe + +SPDX-FileType: BINARY + +SPDX-FileChecksum: SHA1: 59c8b1ea5221e31d7c23573591bdb4bb61878d9a + +SPDX-FileCopyrightText: Copyright (C) 2016, 2021 Antonio Villena + +SPDX-License-Identifier: GPL-3.0-only + +SPDX-FileComment: fpoke version 1.0 (11 May 2016) - tool that overwrites bytes in a file. diff --git a/sdk/bin/zx7b.exe b/sdk/bin/zx7b.exe index be47c4e..357f91e 100644 Binary files a/sdk/bin/zx7b.exe and b/sdk/bin/zx7b.exe differ diff --git a/sdk/bin/zx7b.exe.license b/sdk/bin/zx7b.exe.license index 88d00ee..8edec1a 100644 --- a/sdk/bin/zx7b.exe.license +++ b/sdk/bin/zx7b.exe.license @@ -2,12 +2,15 @@ SPDX-FileName: zx7b.exe SPDX-FileType: BINARY -SPDX-FileChecksum: SHA1: de47984d9d155eb89153052297caac5ffef5e720 +SPDX-FileChecksum: SHA1: 0068364b1463d8f27c29a8a183ea348af12cf456 -SPDX-LicenseConcluded: BSD-3-Clause +SPDX-FileCopyrightText: Copyright (c) 2013, 2021 Antonio Villena. All rights reserved. -SPDX-LicenseComments: The concluded license is taken from https://github.com/antoniovillena/zx7b/raw/master/zx7b.c +SPDX-FileNotice: Based on ZX7 +SPDX-FileNotice: ZX7 is Copyright (c) 2012 Einar Saukas. All rights reserved. -SPDX-FileCopyrightText: Einar Saukas/AntonioVillena, 28 Dec 2013 +SPDX-License-Identifier: BSD-3-Clause -SPDX-FileComment: ZX7 Backwards compressor v1.01 by Einar Saukas/AntonioVillena, 28 Dec 2013 +SPDX-LicenseComments: License's text equals to one from https://directory.fsf.org/wiki/License:BSD-3-Clause + +SPDX-FileComment: zx7b version 1.01 (28 Dec 2013) - backwards compressor. diff --git a/sdk/common.mk b/sdk/common.mk index ff29570..1504d52 100644 --- a/sdk/common.mk +++ b/sdk/common.mk @@ -5,8 +5,8 @@ # SPDX-License-Identifier: GPL-3.0-or-later # # Supported environments: -# * GNU/Linux -# * Windows NT (using MinGW/MSYS/Cygwin/WSL) +# * GNU on Linux, FreeBSD etc. +# * GNU on Windows NT (using MinGW/MSYS/Cygwin/WSL) ifndef ZXUNOSDK @@ -17,3 +17,17 @@ export ZXUNOSDK export PATH endif + +ifeq ($(OS),Windows_NT) +EXECEXT := .exe +else +EXECEXT := +endif + +ifeq ($(BUILD),mingw32) +CC := i686-w64-mingw32-gcc +EXECEXT := .exe +else ifeq ($(BUILD),mingw64) +CC := x86_64-w64-mingw32-gcc +EXECEXT := .exe +endif diff --git a/sdk/src/.gitignore b/sdk/src/.gitignore index e4d3c65..43b40b3 100644 --- a/sdk/src/.gitignore +++ b/sdk/src/.gitignore @@ -1 +1,5 @@ +# SPDX-FileCopyrightText: 2021 Ivan Tatarinov +# +# SPDX-License-Identifier: CC0-1.0 + sjasmplus diff --git a/sdk/src/Makefile b/sdk/src/Makefile index 62b8865..4d608ff 100644 --- a/sdk/src/Makefile +++ b/sdk/src/Makefile @@ -3,25 +3,62 @@ # SPDX-License-Identifier: GPL-3.0-or-later # # Supported environments: -# * GNU/Linux -# * Windows NT (using MinGW/MSYS/Cygwin/WSL) +# * GNU on Linux, FreeBSD etc. +# * GNU on Windows NT (using MinGW/MSYS/Cygwin/WSL) +# +# Build: +# make [BUILD=] [FORCEBUILD=] [] +# Clean: +# make [BUILD=] [FORCECLEAN=] clean +# +# where: +# is one of: mingw32, mingw64. +# is 1 to force build, otherwise do not (default). +# is 1 to force clean, otherwise do not (default). +# is one of values of TOOLS variable (see below). +# +# Notes: +# BUILD, FORCEBUILD, FORCECLEAN variables may be set in user's environment. include ../common.mk -ifeq ($(OS),Windows_NT) -SJASMPLUS := sjasmplus.exe -ZX7B := zx7b.exe -else -SJASMPLUS := sjasmplus -ZX7B := zx7b -endif +SJASMPLUS := sjasmplus$(EXECEXT) +ZX7B := zx7b$(EXECEXT) +FCUT := fcut$(EXECEXT) +FPAD := fpad$(EXECEXT) +FPOKE := fpoke$(EXECEXT) + +TOOLS:= \ + ../bin/$(SJASMPLUS) \ + ../bin/$(ZX7B) \ + ../bin/$(FCUT) \ + ../bin/$(FPAD) \ + ../bin/$(FPOKE) .PHONY: all -all: \ - ../bin/$(SJASMPLUS) \ - ../bin/$(ZX7B) +all: $(TOOLS) -ifneq ($(OS),Windows_NT) +ifeq ($(OS),Windows_NT) +ifeq ($(FORCEBUILD),1) +_DoBuild:=1 +else +_DoBuild:=0 +endif +else +_DoBuild:=1 +endif + +ifeq ($(OS),Windows_NT) +ifeq ($(FORCECLEAN),1) +_DoClean:=1 +else +_DoClean:=0 +endif +else +_DoClean:=1 +endif + +ifeq ($(_DoBuild),1) ../bin/$(SJASMPLUS): sjasmplus/build/$(SJASMPLUS) cp $< $@ @@ -42,14 +79,29 @@ sjasmplus: zx7b/$(ZX7B): | zx7b $(MAKE) -w -C $| + +../bin/$(FCUT): tools/$(FCUT) + cp $< $@ + +../bin/$(FPAD): tools/$(FPAD) + cp $< $@ + +../bin/$(FPOKE): tools/$(FPOKE) + cp $< $@ + +tools/$(FCUT) \ +tools/$(FPAD) \ +tools/$(FPOKE): | tools + $(MAKE) -w -C $| endif .PHONY: clean -ifeq ($(OS),Windows_NT) +ifneq ($(_DoClean),1) clean:; else -clean: | sjasmplus sjasmplus.mk zx7b +clean: | sjasmplus sjasmplus.mk zx7b tools $(MAKE) -w -C sjasmplus -f ../sjasmplus.mk clean $(MAKE) -w -C zx7b clean - rm -f ../bin/$(SJASMPLUS) ../bin/$(ZX7B) + $(MAKE) -w -C tools clean + rm -f $(TOOLS) endif diff --git a/sdk/src/sjasmplus.mk b/sdk/src/sjasmplus.mk index 859cc39..0fce22c 100644 --- a/sdk/src/sjasmplus.mk +++ b/sdk/src/sjasmplus.mk @@ -3,29 +3,50 @@ # SPDX-License-Identifier: GPL-3.0-or-later # # Supported environments: -# * GNU/Linux -# * Windows NT (using MinGW/MSYS/Cygwin/WSL) +# * GNU on Linux, FreeBSD etc. +# * GNU on Windows NT (using MinGW/MSYS/Cygwin/WSL) # # Build: -# make -w -C sjasmplus -f ../sjasmplus.mk +# make [BUILD=] -w -C sjasmplus -f ../sjasmplus.mk # Clean: -# make -w -C sjasmplus -f ../sjasmplus.mk clean +# make [BUILD=] -w -C sjasmplus -f ../sjasmplus.mk clean +# +# where: +# is one of: mingw32, mingw64. +# +# Notes: +# BUILD variable may be set in user's environment. -ifeq ($(OS),Windows_NT) -SJASMPLUS := sjasmplus.exe -else -SJASMPLUS := sjasmplus + +include ../../common.mk + +CMAKEFLAGS := + +ifeq ($(BUILD),mingw32) +CMAKEFLAGS += CMAKE_SYSTEM_NAME=Windows +CMAKEFLAGS += CMAKE_SYSTEM_PROCESSOR=x86 +CMAKEFLAGS += CMAKE_C_COMPILER=i686-w64-mingw32-gcc +CMAKEFLAGS += CMAKE_CXX_COMPILER=i686-w64-mingw32-g++ +CMAKEFLAGS := $(patsubst %,-D%,$(CMAKEFLAGS)) +else ifeq ($(BUILD),mingw64) +CMAKEFLAGS += CMAKE_SYSTEM_NAME=Windows +CMAKEFLAGS += CMAKE_SYSTEM_PROCESSOR=AMD64 +CMAKEFLAGS += CMAKE_C_COMPILER=x86_64-w64-mingw32-gcc +CMAKEFLAGS += CMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ +CMAKEFLAGS := $(patsubst %,-D%,$(CMAKEFLAGS)) endif +SJASMPLUS := sjasmplus$(EXECEXT) + build/$(SJASMPLUS): | build/Makefile $(MAKE) -w -C build build/Makefile: | build - cd build && cmake .. + cd build && cmake $(CMAKEFLAGS) .. build: - mkdir -p build + mkdir $@ .PHONY: clean -clean: | build/Makefile - $(MAKE) -w -C build clean +clean: + rm -rf build diff --git a/sdk/src/tools/.gitignore b/sdk/src/tools/.gitignore new file mode 100644 index 0000000..0da2f7c --- /dev/null +++ b/sdk/src/tools/.gitignore @@ -0,0 +1,10 @@ +# SPDX-FileCopyrightText: 2021 Ivan Tatarinov +# +# SPDX-License-Identifier: CC0-1.0 + +fcut +fcut.exe +fpad +fpad.exe +fpoke +fpoke.exe diff --git a/sdk/src/tools/Makefile b/sdk/src/tools/Makefile new file mode 100644 index 0000000..7f4c22c --- /dev/null +++ b/sdk/src/tools/Makefile @@ -0,0 +1,46 @@ +# SPDX-FileCopyrightText: 2021 Ivan Tatarinov +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# Supported environments: +# * GNU on Linux, FreeBSD etc. +# * GNU on Windows NT (using MinGW/MSYS/Cygwin/WSL) +# +# Build: +# make [BUILD=] [] +# Clean: +# make [BUILD=] clean +# +# where: +# is one of: mingw32, mingw64. +# is one of values for TOOLS variable (see below). +# +# Notes: +# BUILD variable may be set in user's environment. + +include ../../common.mk + +FCUT := fcut$(EXECEXT) +FPAD := fpad$(EXECEXT) +FPOKE := fpoke$(EXECEXT) + +TOOLS:=\ + $(FCUT) \ + $(FPAD) \ + $(FPOKE) + +.PHONY: all +all: $(TOOLS) + +$(FCUT): fcut.c + $(CC) $(CFLAGS) -o $@ $< + +$(FPAD): fpad.c + $(CC) $(CFLAGS) -o $@ $< + +$(FPOKE): fpoke.c + $(CC) $(CFLAGS) -o $@ $< + +.PHONY: clean +clean: + rm -f $(TOOLS) diff --git a/sdk/src/tools/fcut.c b/sdk/src/tools/fcut.c new file mode 100644 index 0000000..a0064e1 --- /dev/null +++ b/sdk/src/tools/fcut.c @@ -0,0 +1,96 @@ +/* + * fcut - a file hexadecimal cutter. + * + * Copyright (C) 2015, 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) 2015, 2021 Antonio Villena + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include +#include + +#define PROGRAM "fcut" +#define DESCRIPTION "a file hexadecimal cutter." +#define VERSION "1.00 (20 Jun 2015)" +#define COPYRIGHT "Copyright (C) 2015, 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/" + +void show_help() { + printf( + PROGRAM " version " VERSION " - " DESCRIPTION "\n" + COPYRIGHT "\n" + LICENSE "\n" + "Home page: " HOMEPAGE "\n" + "\n" + "Usage:\n" + " " PROGRAM " \n" + "\n" + " Origin file to cut\n" + " In hexadecimal, is the start offset of the segment\n" + " In hexadecimal, is the length of the segment\n" + " Genetated output file\n" + "\n" + " negative value assumes a negative offset from the end of the file.\n" + " negative value will substract file size result to that parameter.\n" + ); +} + +int main(int argc, char* argv[]){ + unsigned char *mem= (unsigned char *) malloc (0x10000); + FILE *fi, *fo; + long start, length, size; + if( argc==1 ) + show_help(), + exit(0); + if( argc!=5 ) + 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); + fo= fopen(argv[4], "wb+"); + if( !fo ) + printf("\nCannot create output file: %s\n", argv[4]), + exit(-1); + fseek(fi, 0, SEEK_END); + size= ftell(fi); + rewind(fi); + start= strtol(argv[2], NULL, 16); + if( start<0 ) + start+= size; + length= strtol(argv[3], NULL, 16); + if( length<0 ) + length+= size; + if( start+length>size + || start>size ) + printf("\nOut of input file\n"), + exit(-1); + fseek(fi, start, SEEK_SET); + for ( size= 0; size>16; size++ ) + fread(mem, 1, 0x10000, fi), + fwrite(mem, 1, 0x10000, fo); + fread(mem, 1, length&0xffff, fi); + fwrite(mem, 1, length&0xffff, fo); + fclose(fi); + fclose(fo); + printf("\n0x%lx bytes written (%lu) at offset 0x%lx (%lu)\n", length, length, start, start); +} diff --git a/sdk/src/tools/fpad.c b/sdk/src/tools/fpad.c new file mode 100644 index 0000000..f81bbb8 --- /dev/null +++ b/sdk/src/tools/fpad.c @@ -0,0 +1,74 @@ +/* + * fpad - generate a file with padded values. + * + * Copyright (C) 2016, 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) 2016, 2021 Antonio Villena + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include +#include +#include + +#define PROGRAM "fpad" +#define DESCRIPTION "generate a file with padded values." +#define VERSION "1.00 (24 Apr 2016)" +#define COPYRIGHT "Copyright (C) 2016, 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/" + +void show_help() { + printf( + PROGRAM " version " VERSION " - " DESCRIPTION "\n" + COPYRIGHT "\n" + LICENSE "\n" + "Home page: " HOMEPAGE "\n" + "\n" + "Usage:\n" + " " PROGRAM " \n" + "\n" + " In hexadecimal, is the length of the future file\n" + " In hexadecimal, is the value of the padding\n" + " Genetated output file\n" + ); +} + +int main(int argc, char* argv[]){ + unsigned char mem[0x10000]; + FILE *fo; + long length, size; + if( argc==1 ) + show_help(), + exit(0); + if( argc!=4 ) + printf("\nInvalid number of parameters\n"), + exit(-1); + fo= fopen(argv[3], "wb+"); + if( !fo ) + printf("\nCannot create output file: %s\n", argv[3]), + exit(-1); + memset(mem, strtol(argv[2], NULL, 16), 0x10000); + length= strtol(argv[1], NULL, 16); + for ( size= 0; size>16; size++ ) + fwrite(mem, 1, 0x10000, fo); + fwrite(mem, 1, length&0xffff, fo); + fclose(fo); + printf("\nDone\n"); +} diff --git a/sdk/src/tools/fpoke.c b/sdk/src/tools/fpoke.c new file mode 100644 index 0000000..c59326d --- /dev/null +++ b/sdk/src/tools/fpoke.c @@ -0,0 +1,164 @@ +/* + * fpoke - tool that overwrites bytes in a file. + * + * Copyright (C) 2016, 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) 2016, 2021 Antonio Villena + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include +#include +#include + +#define PROGRAM "fpoke" +#define DESCRIPTION "tool that overwrites bytes in a file." +#define VERSION "1.0 (11 May 2016)" +#define COPYRIGHT "Copyright (C) 2016, 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 BUFFER_LENGTH 0x60000 + +void show_help() { + printf( + PROGRAM " version " VERSION " - " DESCRIPTION "\n" + COPYRIGHT "\n" + LICENSE "\n" + "Home page: " HOMEPAGE "\n" + "\n" + "Usage:\n" + " " PROGRAM " [x] [ [x]] ..\n" + "\n" + " Origin and target file to poke\n" + " In hexadecimal, address of the first byte to poke\n" + " Number of repetitions, also in hex\n" + " Even digits in hex or single quotation string like 'hello'\n" + " file:filename Equivalent to [x] but with a file\n" + "\n" + "At least one sequence of is mandatory ( is optional). The\n" + "first char of can be g or l to indicate biG endian or Little endian,\n" + "default is little endian. Example:hello.txt 48 65 6C 6C 6F 20 57 6F 72 6C 64 21\n" + " " PROGRAM " hello.txt 2 12 48 65 12 6C 6F 20 57 6F 72 6C 64 21\n" + " " PROGRAM " hello.txt 3 1234 48 65 6C 34 12 20 57 6F 72 6C 64 21\n" + " " PROGRAM " hello.txt 4 g123456 0 l1234 34 12 6C 6C 12 34 56 6F 72 6C 64 21\n" + " " PROGRAM " hello.txt 5 3xab 48 65 6C 6C 6F AB AB AB 72 6C 64 21\n" + " " PROGRAM " hello.txt 6 'Earth' 48 65 6C 6C 6F 20 45 61 72 74 68 21\n" + " " PROGRAM " hello.txt 6 file:hi.bin\n" + ); +} + +char char2hex(char value){ + if( value<'0' || value>'f' || value<'A' && value>'9' || value<'a' && value>'F' ) + printf("\nInvalid character %c\n", value), + exit(-1); + return value>'9' ? 9+(value&7) : value-'0'; +} + +int main(int argc, char* argv[]){ + unsigned char *mem= (unsigned char *) malloc (BUFFER_LENGTH); + FILE *fi, *fi2; + char *bytes; + long start, size, rep, length, i, j, k; + if( argc==1 ) + show_help(), + exit(0); + if( argc&1 ) + 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); + size= ftell(fi); + while ( argc > 2 ){ + start= strtol(argv++[2], NULL, 16); + if( start<0 ) + start+= size; + if( bytes= strchr(argv[2], ':') ) + rep= -1, + argv++; + else if( strchr(argv[2], 'x') || strchr(argv[2], 'X') ) + rep= strtol(strtok(argv++[2], "xX"), NULL, 16), + bytes= strtok(NULL, "xX"); + else + rep= 1, + bytes= argv++[2]; + if( bytes[0]=='g' || bytes[0]=='l' || bytes[0]=='\'' ) + bytes++; + if( bytes[-1]=='\'' ) + bytes= strtok(bytes, "'"), + length= strlen(bytes); + else if( rep==-1 ){ + fi2= fopen(++bytes, "rb+"); + if( !fi2 ) + printf("\nInput file not found: %s\n", bytes), + exit(-1); + fseek(fi2, 0, SEEK_END); + length= ftell(fi2); + fseek(fi2, 0, SEEK_SET); + } + else{ + length= strlen(bytes); + if( length&1 ) + printf("\nIncorrect length %X (%s), must be even, in address %X\n", length, bytes, start), + exit(-1); + length>>= 1; + } + if( length*rep+start > size ) + printf("\nOut of file\n"), + exit(-1); + if( length>BUFFER_LENGTH ) + printf("\nOut of buffer\n"), + exit(-1); + if( rep==-1 ) + printf("hola %d %d %d\n", argc, length, fread(mem, 1, length, fi2)), + fclose(fi2); + else if( bytes[-1]=='g' ) + for ( i= 0; i < length; i++ ) + mem[i]= char2hex(bytes[i<<1|1]) | char2hex(bytes[i<<1]) << 4; + else if( bytes[-1]=='\'' ) + for ( i= 0; i < length; i++ ) + mem[i]= bytes[i]; + else + for ( i= 0; i < length; i++ ) + mem[length-i-1]= char2hex(bytes[i<<1|1]) | char2hex(bytes[i<<1]) << 4; + for ( i= 1; i < rep; i++ ) + if( i*length > BUFFER_LENGTH ) + break; + if( --i > 1 ) + for ( j= 1; j < i; j++ ) + for ( k= 0; k < length; k++ ) + mem[k+j*length]= mem[k]; + fseek(fi, start, SEEK_SET); + if( i ){ + j= rep/i; + for ( k= 0; k < j; k++ ) + fwrite(mem, 1, length*i, fi); + if( rep%i ) + fwrite(mem, 1, length*(rep%i), fi); + } + else + fwrite(mem, 1, length, fi); + argc-= 2; + } + printf("\nFile correctly modified\n"); + fclose(fi); +} diff --git a/sdk/src/tools/tools.url b/sdk/src/tools/tools.url new file mode 100644 index 0000000..82e3211 --- /dev/null +++ b/sdk/src/tools/tools.url @@ -0,0 +1,6 @@ +# SPDX-FileCopyrightText: 20219 Ivan Tatarinov +# +# SPDX-License-Identifier: CC0-1.0 + +https://sourceforge.net/p/emuscriptoria/code/HEAD/tree/desprot/ +https://github.com/antoniovillena/EmuScriptoria/tree/master/desprot diff --git a/sdk/src/zx7b/.gitignore b/sdk/src/zx7b/.gitignore index f7948c5..8a1f2e9 100644 --- a/sdk/src/zx7b/.gitignore +++ b/sdk/src/zx7b/.gitignore @@ -1,2 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Ivan Tatarinov +# +# SPDX-License-Identifier: CC0-1.0 + zx7b zx7b.exe diff --git a/sdk/src/zx7b/Makefile b/sdk/src/zx7b/Makefile index 9a92b79..04ece1f 100644 --- a/sdk/src/zx7b/Makefile +++ b/sdk/src/zx7b/Makefile @@ -5,27 +5,28 @@ # Supported environments: # * GNU on Linux, FreeBSD etc. # * GNU on Windows NT (using MinGW/MSYS/Cygwin/WSL) +# +# Build: +# make [BUILD=] [] +# Clean: +# make [BUILD=] clean +# +# where: +# is one of: mingw32, mingw64. +# is one of values of TOOLS variable (see below). +# +# Notes: +# BUILD variable may be set in user's environment. include ../../common.mk -ifeq ($(OS),Windows_NT) -ZX7B := zx7b.exe -else -ZX7B := zx7b -endif +ZX7B := zx7b$(EXECEXT) -ifneq ($(OS),Windows_NT) $(ZX7B): zx7b.c $(CC) $(CFLAGS) -o $@ $< zx7b.c: wget -c https://github.com/antoniovillena/zx7b/raw/master/zx7b.c -endif -.PHONY: clean -ifeq ($(OS),Windows_NT) -clean:; -else clean: rm -f $(ZX7B) -endif diff --git a/sdk/src/zx7b/zx7b.c b/sdk/src/zx7b/zx7b.c index 9a63080..3cd5d39 100644 --- a/sdk/src/zx7b/zx7b.c +++ b/sdk/src/zx7b/zx7b.c @@ -1,8 +1,10 @@ /* - * ZX7b (c) Copyright 2013 by Antonio Villena. All rights reserved. + * zx7b - backwards compressor. + * + * Copyright (c) 2013, 2021 Antonio Villena. All rights reserved. * * Based on ZX7 - * (c) Copyright 2012 by Einar Saukas. All rights reserved. + * ZX7 is Copyright (c) 2012 Einar Saukas. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -25,20 +27,30 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * SPDX-FileCopyrightText: ZX7b (c) Copyright 2013 by Antonio Villena. All rights reserved. + * SPDX-FileCopyrightText: Copyright (c) 2013, 2021 Antonio Villena. All rights reserved. * * SPDX-FileNotice: Based on ZX7 - * SPDX-FileNotice: (c) Copyright 2012 by Einar Saukas. All rights reserved. + * SPDX-FileNotice: ZX7 is Copyright (c) 2012 Einar Saukas. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * - * SPDX-LicenseComments: License's text is equals to one from https://directory.fsf.org/wiki/License:BSD-3-Clause + * SPDX-LicenseComments: License's text equals to one from https://directory.fsf.org/wiki/License:BSD-3-Clause */ #include #include #include +#define PROGRAM "zx7b" +#define DESCRIPTION "backwards compressor." +#define VERSION "1.01 (28 Dec 2013)" +#define COPYRIGHT "Copyright (c) 2013, 2021 Antonio Villena. All rights reserved.\n" \ +"Based on ZX7 \n" \ +"ZX7 is Copyright (c) 2012 Einar Saukas. All rights reserved." +#define LICENSE \ +"Distributed under BSD 3-clause license." +#define HOMEPAGE "https://github.com/antoniovillena/zx7b/" + #define MAX_OFFSET 2176 /* range 1..2176 */ #define MAX_LEN 65536 /* range 2..65536 */ @@ -53,6 +65,23 @@ typedef struct optimal_t { int len; } Optimal; +void show_help() { + printf( + PROGRAM " version " VERSION " - " DESCRIPTION "\n" + COPYRIGHT "\n" + LICENSE "\n" + "Home page: " HOMEPAGE "\n" + "\n" + "Usage:\n" + " " PROGRAM " \n" + "\n" + " Raw input file\n" + " Compressed output file\n" + "\n" + "Example: " PROGRAM " Cobra.scr Cobra.zx7b\n" + ); +} + Optimal *optimize(unsigned char *input_data, size_t input_size); unsigned char *compress(Optimal *optimal, unsigned char *input_data, size_t input_size, size_t *output_size); @@ -70,11 +99,7 @@ int main(int argc, char *argv[]) { int i, j; if( argc==1 ) - printf("\nZX7 Backwards compressor v1.01 by Einar Saukas/AntonioVillena, 28 Dec 2013\n\n" - " zx7b \n\n" - " Raw input file\n" - " Compressed output file\n\n" - "Example: zx7b Cobra.scr Cobra.zx7b\n"), + show_help(), exit(0); if( argc!=3 ) printf("\nInvalid number of parameters\n"),