├── AUTHORS ├── src ├── sidutils │ ├── MD5 │ │ ├── Makefile.am │ │ ├── MD5_Defs.h │ │ └── MD5.h │ ├── Makefile.am │ ├── ini │ │ ├── Makefile.am │ │ ├── list.h │ │ ├── keys.h │ │ ├── headings.h │ │ └── ini.h │ ├── SidTuneMod.cpp │ └── SidDatabase.cpp ├── sidtune │ ├── Makefile.am │ ├── SidTuneCfg.h │ ├── PP20_Defs.h │ ├── prg.cpp │ ├── PP20.h │ ├── SidTuneTools.h │ ├── p00.cpp │ ├── SidTuneTools.cpp │ └── PP20.cpp ├── Makefile.am ├── libpsid64 │ ├── stilview │ │ ├── stilcomm.h │ │ ├── stilcomm.cpp │ │ ├── stildefs.h │ │ └── STILView-config.patch │ ├── exomizer │ │ ├── exomizer.h │ │ ├── chunkpool.h │ │ ├── sfx.h │ │ ├── optimal.h │ │ ├── radix.h │ │ ├── output.h │ │ ├── chunkpool.c │ │ ├── match.h │ │ ├── search.h │ │ ├── log.h │ │ ├── radix.c │ │ ├── exomizer.c │ │ └── output.c │ ├── psidboot.h │ ├── Makefile.am │ ├── reloc65.h │ ├── sidid.h │ ├── psiddrv.h │ ├── screen.cpp │ ├── psidextboot.h │ ├── theme.h │ ├── screen.h │ ├── psidboot.a65 │ ├── sidid.cpp │ └── reloc65.cpp ├── ConsoleApp.h └── main.cpp ├── autogen.sh ├── Doxyfile.in ├── TODO ├── .gitignore ├── Makefile.am ├── include └── sidplay │ ├── utils │ ├── SidTuneMod.h │ ├── SidDatabase.h │ └── libini.h │ ├── sidconfig.h.in │ ├── sidtypes.h │ ├── Buffer.h │ └── SmartPtr.h ├── psid64.spec.in ├── configure.ac ├── NEWS.md ├── macros ├── ax_func_mkdir.m4 └── sidtune.m4 └── README.md /AUTHORS: -------------------------------------------------------------------------------- 1 | Roland Hermans 2 | -------------------------------------------------------------------------------- /src/sidutils/MD5/Makefile.am: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | 3 | AM_CXXFLAGS = $(WARNINGCXXFLAGS) 4 | 5 | noinst_LIBRARIES = libMD5.a 6 | 7 | libMD5_a_SOURCES = MD5.cpp MD5.h MD5_Defs.h 8 | -------------------------------------------------------------------------------- /src/sidutils/MD5/MD5_Defs.h: -------------------------------------------------------------------------------- 1 | #ifndef MD5_DEFS_H 2 | #define MD5_DEFS_H 3 | 4 | #include 5 | 6 | #ifdef SID_WORDS_BIGENDIAN 7 | #define MD5_WORDS_BIG_ENDIAN 8 | #endif 9 | 10 | #endif /* MD5_DEFS_H */ 11 | -------------------------------------------------------------------------------- /src/sidutils/Makefile.am: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | 3 | SUBDIRS = MD5 ini 4 | 5 | AM_CXXFLAGS = $(WARNINGCXXFLAGS) 6 | 7 | noinst_LIBRARIES = libsidutils.a 8 | 9 | libsidutils_a_SOURCES = SidDatabase.cpp SidTuneMod.cpp 10 | -------------------------------------------------------------------------------- /src/sidutils/ini/Makefile.am: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | 3 | # The library. 4 | AM_CXXFLAGS = $(WARNINGCXXFLAGS) 5 | 6 | noinst_LIBRARIES = libini.a 7 | 8 | libini_a_SOURCES = headings.h ini.cpp ini.h \ 9 | keys.h list.h 10 | 11 | EXTRA_DIST=headings.i keys.i list.i types.i 12 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SPDX-License-Identifier: GPL-2.0-or-later 3 | # 4 | # Run this to set up the build system: configure, makefiles, etc. 5 | 6 | srcdir=`dirname $0` 7 | test -z "$srcdir" && srcdir=. 8 | 9 | cd "$srcdir" 10 | 11 | exec autoreconf --force --install --make --verbose --warnings=all "$@" 12 | -------------------------------------------------------------------------------- /Doxyfile.in: -------------------------------------------------------------------------------- 1 | # This file describes the settings to be used by the documentation system 2 | # doxygen (www.doxygen.org) for a project 3 | # 4 | 5 | PROJECT_NAME = @PACKAGE@ 6 | PROJECT_NUMBER = @VERSION@ 7 | OUTPUT_DIRECTORY = doc 8 | #EXTRACT_ALL = YES 9 | #EXTRACT_PRIVATE = YES 10 | #EXTRACT_STATIC = YES 11 | INPUT = include/psid64 12 | -------------------------------------------------------------------------------- /src/sidtune/Makefile.am: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | 3 | noinst_LIBRARIES = libsidtune.a 4 | 5 | AM_CXXFLAGS = $(WARNINGCXXFLAGS) 6 | 7 | libsidtune_a_SOURCES = IconInfo.cpp \ 8 | InfoFile.cpp \ 9 | MUS.cpp \ 10 | p00.cpp \ 11 | PP20.cpp \ 12 | PP20.h \ 13 | PP20_Defs.h \ 14 | prg.cpp \ 15 | PSID.cpp \ 16 | SidTune.cpp \ 17 | SidTuneCfg.h \ 18 | SidTuneTools.cpp \ 19 | SidTuneTools.h 20 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | * Allow custom post reset function, e.g. to load a menu from disk. 2 | 3 | * Compatibility mode for PAL SIDs on an NTSC computer and vice versa. 4 | 5 | * Provide a default power on environment to the SIDs. 6 | 7 | * Display all PSID header information. 8 | 9 | * Investigate the use of PSID heuristics (e.g. Rockmonitor support). 10 | 11 | * Improve C64 demo: make it more colorful, add a better scroller, etc. 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.[oa] 2 | .deps 3 | .dirstamp 4 | Makefile 5 | Makefile.in 6 | 7 | /Doxyfile 8 | /aclocal.m4 9 | /autom4te.cache 10 | /compile 11 | /config.guess 12 | /config.log 13 | /config.status 14 | /config.sub 15 | /configure 16 | /configure~ 17 | /depcomp 18 | /install-sh 19 | /ltmain.sh 20 | /missing 21 | /psid64.spec 22 | 23 | /include/sidplay/sidconfig.h 24 | /include/sidplay/sidint.h 25 | 26 | /src/config.h 27 | /src/config.h.in 28 | /src/config.h.in~ 29 | /src/psid64 30 | /src/stamp-h1 31 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | 3 | # Process this file with automake to produce Makefile.in 4 | 5 | SUBDIRS = libpsid64 sidtune sidutils 6 | 7 | AM_CXXFLAGS = $(WARNINGCXXFLAGS) 8 | 9 | bin_PROGRAMS = psid64 10 | 11 | psid64_SOURCES = \ 12 | ConsoleApp.cpp \ 13 | ConsoleApp.h \ 14 | main.cpp 15 | 16 | psid64_LDADD = \ 17 | libpsid64/libpsid64.a \ 18 | sidtune/libsidtune.a \ 19 | sidutils/libsidutils.a \ 20 | sidutils/MD5/libMD5.a \ 21 | sidutils/ini/libini.a 22 | -------------------------------------------------------------------------------- /src/libpsid64/stilview/stilcomm.h: -------------------------------------------------------------------------------- 1 | // 2 | // STIL Common header 3 | // 4 | 5 | // 6 | // Contains some definitions common to STIL 7 | // 8 | 9 | #ifndef _STILCOMM_H 10 | #define _STILCOMM_H 11 | 12 | #include "stildefs.h" 13 | 14 | // convertSlashes() 15 | // 16 | // FUNCTION: Converts slashes to the one the OS uses to access files. 17 | // ARGUMENTS: 18 | // str - what to convert 19 | // RETURNS: 20 | // NONE 21 | // 22 | extern void convertSlashes(char *str); 23 | 24 | // convertToSlashes() 25 | // 26 | // FUNCTION: Converts OS specific dir separators to slashes. 27 | // ARGUMENTS: 28 | // str - what to convert 29 | // RETURNS: 30 | // NONE 31 | // 32 | extern void convertToSlashes(char *str); 33 | 34 | #endif // _STILCOMM_H 35 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | 3 | # Process this file with automake to produce Makefile.in 4 | 5 | SUBDIRS = src 6 | 7 | pkginclude_HEADERS = \ 8 | include/psid64/psid64.h 9 | 10 | noinst_HEADERS = \ 11 | include/sidplay/Buffer.h \ 12 | include/sidplay/SidTune.h \ 13 | include/sidplay/SmartPtr.h \ 14 | include/sidplay/sidconfig.h \ 15 | include/sidplay/sidconfig.h.in \ 16 | include/sidplay/sidendian.h \ 17 | include/sidplay/sidint.h \ 18 | include/sidplay/sidtypes.h \ 19 | include/sidplay/utils/libini.h \ 20 | include/sidplay/utils/SidDatabase.h \ 21 | include/sidplay/utils/SidTuneMod.h 22 | 23 | DISTCLEANFILES = \ 24 | include/sidplay/sidint.h 25 | 26 | EXTRA_DIST = \ 27 | Doxyfile \ 28 | psid64.spec \ 29 | macros/ax_create_stdint_h.m4 \ 30 | macros/ax_func_mkdir.m4 \ 31 | macros/sidtune.m4 32 | # AUTHORS COPYING INSTALL NEWS.md README.md TODO 33 | 34 | ACLOCAL_AMFLAGS = -I macros 35 | -------------------------------------------------------------------------------- /src/sidtune/SidTuneCfg.h: -------------------------------------------------------------------------------- 1 | /* SidTuneCfg.h (template) */ 2 | 3 | #ifndef SIDTUNECFG_H 4 | #define SIDTUNECFG_H 5 | 6 | #include "config.h" 7 | 8 | /* Define to add PSID2NG support */ 9 | #define SIDTUNE_PSID2NG 10 | 11 | /* Minimum load address for real c64 only tunes */ 12 | #define SIDTUNE_R64_MIN_LOAD_ADDR 0x07e8 13 | 14 | 15 | /* -------------------------------------------------------------------------- 16 | * Don't touch these! 17 | * -------------------------------------------------------------------------- 18 | */ 19 | #undef SIDTUNE_NO_STDIN_LOADER 20 | #undef SIDTUNE_REJECT_UNKNOWN_FIELDS 21 | 22 | 23 | /* Define the file/path separator(s) that your filesystem uses: 24 | SID_FS_IS_COLON_AND_BACKSLASH, SID_FS_IS_COLON_AND_SLASH, 25 | SID_FS_IS_BACKSLASH, SID_FS_IS_COLON, SID_FS_IS_SLASH */ 26 | #if defined(HAVE_MSWINDOWS) || defined(HAVE_MSDOS) || defined(HAVE_OS2) 27 | #define SID_FS_IS_COLON_AND_BACKSLASH_AND_SLASH 28 | #elif defined(HAVE_MACOS) 29 | #define SID_FS_IS_COLON 30 | #elif defined(HAVE_AMIGAOS) 31 | #define SID_FS_IS_COLON_AND_SLASH 32 | #else 33 | #define SID_FS_IS_SLASH 34 | #endif 35 | 36 | #endif /* SIDTUNECFG_H */ 37 | -------------------------------------------------------------------------------- /src/libpsid64/stilview/stilcomm.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // STIL - Common stuff 3 | // 4 | 5 | // 6 | // Common functions used for STIL handling. 7 | // See stilcomm.h for prologs. 8 | // 9 | 10 | #ifndef _STILCOMM 11 | #define _STILCOMM 12 | 13 | #include "stildefs.h" 14 | #include "stil.h" 15 | 16 | #include "stilcomm.h" 17 | 18 | const char *STIL::STIL_ERROR_STR[] = { 19 | "No error.", 20 | "Failed to open BUGlist.txt.", 21 | "Base dir path is not the HVSC base dir path.", 22 | "The entry was not found in STIL.txt.", 23 | "The entry was not found in BUGlist.txt.", 24 | "A section-global comment was asked for in the wrong way.", 25 | "", 26 | "", 27 | "", 28 | "", 29 | "CRITICAL ERROR", 30 | "Incorrect HVSC base dir length!", 31 | "Failed to open STIL.txt!", 32 | "Failed to determine EOL from STIL.txt!", 33 | "No STIL sections were found in STIL.txt!", 34 | "No STIL sections were found in BUGlist.txt!" 35 | }; 36 | 37 | void convertSlashes(char *str); 38 | void convertToSlashes(char *str); 39 | 40 | void convertSlashes(char *str) 41 | { 42 | while (*str) { 43 | if (*str == '/') { 44 | *str = SLASH; 45 | } 46 | str++; 47 | } 48 | } 49 | 50 | void convertToSlashes(char *str) 51 | { 52 | while (*str) { 53 | if (*str == SLASH) { 54 | *str = '/' ; 55 | } 56 | str++; 57 | } 58 | } 59 | 60 | 61 | #endif //_STILCOMM 62 | -------------------------------------------------------------------------------- /src/sidtune/PP20_Defs.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | * /home/ms/files/source/libsidtune/RCS/PP20_Defs.h,v 4 | * 5 | * PowerPacker (AMIGA) "PP20" format decompressor. 6 | * Copyright (C) Michael Schwendt 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | */ 22 | 23 | #ifndef PP_DECOMPRESSOR_DEFS_H 24 | #define PP_DECOMPRESSOR_DEFS_H 25 | 26 | #include "sidtypes.h" 27 | 28 | #ifdef HAVE_EXCEPTIONS 29 | #define PP20_HAVE_EXCEPTIONS 30 | #else 31 | #undef PP20_HAVE_EXCEPTIONS 32 | #endif 33 | 34 | // Wanted: 8-bit unsigned. 35 | typedef uint_least8_t ubyte_ppt; 36 | 37 | // Wanted: 32-bit unsigned. 38 | typedef uint_least32_t udword_ppt; 39 | 40 | #endif /* PP_DECOMPRESSOR_DEFS_H */ 41 | -------------------------------------------------------------------------------- /src/libpsid64/exomizer/exomizer.h: -------------------------------------------------------------------------------- 1 | #ifndef ALREADY_INCLUDED_EXOMIZER_H 2 | #define ALREADY_INCLUDED_EXOMIZER_H 3 | /* 4 | * Copyright (c) 2002 - 2004 Magnus Lind. 5 | * 6 | * This software is provided 'as-is', without any express or implied warranty. 7 | * In no event will the authors be held liable for any damages arising from 8 | * the use of this software. 9 | * 10 | * Permission is granted to anyone to use this software, alter it and re- 11 | * distribute it freely for any non-commercial, non-profit purpose subject to 12 | * the following restrictions: 13 | * 14 | * 1. The origin of this software must not be misrepresented; you must not 15 | * claim that you wrote the original software. If you use this software in a 16 | * product, an acknowledgment in the product documentation would be 17 | * appreciated but is not required. 18 | * 19 | * 2. Altered source versions must be plainly marked as such, and must not 20 | * be misrepresented as being the original software. 21 | * 22 | * 3. This notice may not be removed or altered from any distribution. 23 | * 24 | * 4. The names of this software and/or it's copyright holders may not be 25 | * used to endorse or promote products derived from this software without 26 | * specific prior written permission. 27 | * 28 | */ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | 35 | int exomizer(const unsigned char *srcbuf, int len, int load, int start, unsigned char *destbuf); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/sidutils/ini/list.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /*************************************************************************** 3 | list.h - Adds list support to ini files 4 | 5 | ------------------- 6 | begin : Fri Apr 21 2000 7 | copyright : (C) 2000 by Simon White 8 | email : s_a_white@email.com 9 | ***************************************************************************/ 10 | 11 | /*************************************************************************** 12 | * * 13 | * This program is free software; you can redistribute it and/or modify * 14 | * it under the terms of the GNU General Public License as published by * 15 | * the Free Software Foundation; either version 2 of the License, or * 16 | * (at your option) any later version. * 17 | * * 18 | ***************************************************************************/ 19 | 20 | #ifndef _list_h_ 21 | #define _list_h_ 22 | 23 | #include "ini.h" 24 | #ifdef INI_ADD_LIST_SUPPORT 25 | 26 | struct ini_t; 27 | static int __ini_listEval (struct ini_t *ini); 28 | static const char *__ini_listRead (struct ini_t *ini); 29 | static int __ini_listIndexLength (struct ini_t *ini); 30 | static int __ini_listDelims (struct ini_t *ini, const char *delims); 31 | 32 | #endif // INI_ADD_LIST_SUPPORT 33 | #endif // _list_h_ 34 | -------------------------------------------------------------------------------- /include/sidplay/utils/SidTuneMod.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | * This program is free software; you can redistribute it and/or modify 4 | * it under the terms of the GNU General Public License as published by 5 | * the Free Software Foundation; either version 2 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | */ 17 | 18 | #ifndef SIDTUNEMOD_H 19 | #define SIDTUNEMOD_H 20 | 21 | #include 22 | 23 | #define SIDTUNE_MD5_LENGTH 32 24 | 25 | 26 | class SID_EXTERN SidTuneMod : public SidTune 27 | { 28 | private: 29 | char m_md5[SIDTUNE_MD5_LENGTH+1]; 30 | 31 | public: // --------------------------------------------------------- public 32 | 33 | explicit SidTuneMod(const char* fileName) : SidTune(fileName) 34 | { m_md5[0] = '\0'; } 35 | 36 | // Not providing an md5 buffer will cause the internal one to be used 37 | const char *createMD5(char *md5 = 0); // Buffer must be SIDTUNE_MD5_LENGTH + 1 38 | // Not providing an md5 buffer will cause the internal one to be used 39 | const char *createNewMD5(char *md5 = 0); // Buffer must be SIDTUNE_MD5_LENGTH + 1 40 | }; 41 | 42 | #endif /* SIDTUNEMOD_H */ 43 | -------------------------------------------------------------------------------- /src/libpsid64/exomizer/chunkpool.h: -------------------------------------------------------------------------------- 1 | #ifndef ALREADY_INCLUDED_CHUNKPOOL_H 2 | #define ALREADY_INCLUDED_CHUNKPOOL_H 3 | 4 | /* 5 | * Copyright (c) 2003 Magnus Lind. 6 | * 7 | * This software is provided 'as-is', without any express or implied warranty. 8 | * In no event will the authors be held liable for any damages arising from 9 | * the use of this software. 10 | * 11 | * Permission is granted to anyone to use this software, alter it and re- 12 | * distribute it freely for any non-commercial, non-profit purpose subject to 13 | * the following restrictions: 14 | * 15 | * 1. The origin of this software must not be misrepresented; you must not 16 | * claim that you wrote the original software. If you use this software in a 17 | * product, an acknowledgment in the product documentation would be 18 | * appreciated but is not required. 19 | * 20 | * 2. Altered source versions must be plainly marked as such, and must not 21 | * be misrepresented as being the original software. 22 | * 23 | * 3. This notice may not be removed or altered from any distribution. 24 | * 25 | * 4. The names of this software and/or it's copyright holders may not be 26 | * used to endorse or promote products derived from this software without 27 | * specific prior written permission. 28 | * 29 | */ 30 | 31 | struct chunkpool { 32 | int chunk_size; 33 | int chunk; 34 | int chunk_pos; 35 | int chunk_max; 36 | void *chunks[32]; 37 | }; 38 | 39 | void 40 | chunkpool_init(struct chunkpool *ctx, int size); 41 | 42 | void 43 | chunkpool_free(struct chunkpool *ctx); 44 | 45 | void * 46 | chunkpool_malloc(struct chunkpool *ctx); 47 | 48 | void * 49 | chunkpool_calloc(struct chunkpool *ctx); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /include/sidplay/sidconfig.h.in: -------------------------------------------------------------------------------- 1 | /* sidconfig.h (template) */ 2 | #ifndef _sidconfig_h_ 3 | #define _sidconfig_h_ 4 | 5 | /* Define the sizeof of types in bytes */ 6 | #define SID_SIZEOF_CHAR @SID_SIZEOF_CHAR@ 7 | #define SID_SIZEOF_SHORT_INT @SID_SIZEOF_SHORT_INT@ 8 | #define SID_SIZEOF_INT @SID_SIZEOF_INT@ 9 | #define SID_SIZEOF_LONG_INT @SID_SIZEOF_LONG_INT@ 10 | 11 | /* Define SID_WORDS_BIGENDIAN if your processor stores words 12 | with the most significant byte first (like Motorola and SPARC, 13 | unlike Intel and VAX). */ 14 | /* Define SID_WORDS_LITTLEENDIAN if your processor stores words 15 | with the least significant byte first (like Intel and VAX). */ 16 | #define @SID_WORDS_ENDIANESS@ 17 | 18 | /* Define if your compiler supports type "bool". 19 | If not, a user-defined signed integral type will be used. */ 20 | @SID_HAVE_BOOL@ 21 | 22 | /* Define if your compiler supports AC99 header "stdbool.h" */ 23 | @SID_HAVE_STDBOOL_H@ 24 | 25 | /* DLL building support on win32 hosts */ 26 | #ifndef SID_EXTERN 27 | # ifdef DLL_EXPORT /* defined by libtool (if required) */ 28 | # define SID_EXTERN __declspec(dllexport) 29 | # endif 30 | # ifdef SID_DLL_IMPORT /* define if linking with this dll */ 31 | # define SID_EXTERN __declspec(dllimport) 32 | # endif 33 | # ifndef SID_EXTERN /* static linking or !_WIN32 */ 34 | # define SID_EXTERN 35 | # endif 36 | #endif 37 | 38 | /* Namespace support */ 39 | #define SIDPLAY2_NAMESPACE __sidplay2__ 40 | #ifdef SIDPLAY2_NAMESPACE 41 | # define SIDPLAY2_NAMESPACE_START \ 42 | namespace SIDPLAY2_NAMESPACE \ 43 | { 44 | # define SIDPLAY2_NAMESPACE_STOP \ 45 | } 46 | #else 47 | # define SIDPLAY2_NAMESPACE_START 48 | # define SIDPLAY2_NAMESPACE_STOP 49 | #endif 50 | 51 | #endif /* _sidconfig_h_ */ 52 | -------------------------------------------------------------------------------- /src/libpsid64/exomizer/sfx.h: -------------------------------------------------------------------------------- 1 | #ifndef ALREADY_INCLUDED_SFX_H 2 | #define ALREADY_INCLUDED_SFX_H 3 | 4 | /* 5 | * Copyright (c) 2002, 2003 Magnus Lind. 6 | * 7 | * This software is provided 'as-is', without any express or implied warranty. 8 | * In no event will the authors be held liable for any damages arising from 9 | * the use of this software. 10 | * 11 | * Permission is granted to anyone to use this software, alter it and re- 12 | * distribute it freely for any non-commercial, non-profit purpose subject to 13 | * the following restrictions: 14 | * 15 | * 1. The origin of this software must not be misrepresented; you must not 16 | * claim that you wrote the original software. If you use this software in a 17 | * product, an acknowledgment in the product documentation would be 18 | * appreciated but is not required. 19 | * 20 | * 2. Altered source versions must be plainly marked as such, and must not 21 | * be misrepresented as being the original software. 22 | * 23 | * 3. This notice may not be removed or altered from any distribution. 24 | * 25 | * 4. The names of this software and/or it's copyright holders may not be 26 | * used to endorse or promote products derived from this software without 27 | * specific prior written permission. 28 | * 29 | */ 30 | 31 | #include "output.h" 32 | typedef 33 | void sfx1_set_new_load_f(output_ctx out, /* IN/OUT */ 34 | unsigned short int load); /* IN */ 35 | 36 | typedef 37 | void sfx2_add_stages_f(output_ctx out, /* IN/OUT */ 38 | unsigned short int start); /* IN */ 39 | struct sfx_decruncher { 40 | sfx1_set_new_load_f *load; 41 | sfx2_add_stages_f *stages; 42 | const char *text; 43 | }; 44 | extern struct sfx_decruncher sfx_c64[]; 45 | extern struct sfx_decruncher sfx_c64ne[]; 46 | extern struct sfx_decruncher sfx_c264[]; 47 | extern struct sfx_decruncher sfx_c264ne[]; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/libpsid64/psidboot.h: -------------------------------------------------------------------------------- 1 | 0x01,0x00,0x6f,0x36,0x35,0x00,0x00,0x10,0x00,0x10,0xe3,0x00,0x00,0x04,0x00,0x00, 2 | 0x00,0x40,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x0f,0x00,0x70,0x73,0x69,0x64, 3 | 0x62,0x6f,0x6f,0x74,0x2e,0x6f,0x36,0x35,0x00,0x31,0x03,0x52,0x6f,0x6c,0x61,0x6e, 4 | 0x64,0x20,0x48,0x65,0x72,0x6d,0x61,0x6e,0x73,0x20,0x3c,0x72,0x6f,0x6c,0x61,0x6e, 5 | 0x64,0x68,0x40,0x75,0x73,0x65,0x72,0x73,0x2e,0x73,0x6f,0x75,0x72,0x63,0x65,0x66, 6 | 0x6f,0x72,0x67,0x65,0x2e,0x6e,0x65,0x74,0x3e,0x00,0x00,0xa9,0x00,0x4c,0x78,0x10, 7 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 8 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc6,0xf9,0xc6,0xfb, 9 | 0xb1,0xf8,0x91,0xfa,0xc8,0xd0,0xf9,0xc6,0xfc,0xd0,0xf1,0xa6,0xff,0xbd,0x00,0x01, 10 | 0x85,0xfa,0xbd,0x05,0x01,0x85,0xfb,0xa0,0x00,0xbd,0x0f,0x01,0xf0,0x11,0x85,0xfc, 11 | 0xb1,0xfd,0x91,0xfa,0xc8,0xd0,0xf9,0xe6,0xfe,0xe6,0xfb,0xc6,0xfc,0xd0,0xf1,0xbd, 12 | 0x0a,0x01,0xf0,0x15,0x85,0xfc,0xb1,0xfd,0x91,0xfa,0xc8,0xc4,0xfc,0xd0,0xf7,0x98, 13 | 0x18,0x65,0xfd,0x85,0xfd,0x90,0x02,0xe6,0xfe,0xca,0x10,0xc1,0xa9,0x37,0x85,0x01, 14 | 0x4c,0x00,0x00,0x78,0xa2,0xff,0x9a,0xd8,0x48,0xad,0xa6,0x02,0x29,0x01,0x48,0xa5, 15 | 0xa2,0x48,0xa9,0x37,0x85,0x01,0x20,0x84,0xff,0xa2,0x2e,0xbd,0xb4,0x10,0x9d,0xff, 16 | 0xcf,0xca,0xd0,0xf7,0xa9,0x34,0x85,0x01,0xa9,0x00,0x8d,0x28,0x03,0xa9,0x00,0x8d, 17 | 0x29,0x03,0xa0,0x73,0xb9,0x04,0x10,0x99,0xf7,0x00,0x88,0xd0,0xf7,0x4c,0x14,0x01, 18 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 19 | 0x00,0x6b,0x37,0x00,0x00,0x00,0x08,0x00,0x14,0x0f,0x00,0x00,0x00,0x00,0x00,0x00, 20 | 0x00,0x06,0x01,0x02,0x03,0x04,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x04,0x00, 21 | 0x73,0x6f,0x6e,0x67,0x00,0x70,0x6c,0x61,0x79,0x65,0x72,0x00,0x73,0x74,0x6f,0x70, 22 | 0x76,0x65,0x63,0x00,0x43,0x4f,0x4c,0x5f,0x42,0x4f,0x52,0x44,0x45,0x52,0x00,0x02, 23 | 0x20,0x00,0x00,0x02,0x82,0x73,0x80,0x01,0x00,0x1b,0x82,0x0d,0x20,0x02,0x00,0x05, 24 | 0x40,0x02,0x00,0x00,0x07,0x82,0x2b,0x20,0x03,0x00,0x00,0x00,0x00,0x00, 25 | -------------------------------------------------------------------------------- /include/sidplay/sidtypes.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /*************************************************************************** 3 | sidtypes.h - type definition file 4 | ------------------- 5 | begin : Mon Jul 3 2000 6 | copyright : (C) 2000 by Simon White 7 | email : s_a_white@email.com 8 | ***************************************************************************/ 9 | 10 | /*************************************************************************** 11 | * * 12 | * This program is free software; you can redistribute it and/or modify * 13 | * it under the terms of the GNU General Public License as published by * 14 | * the Free Software Foundation; either version 2 of the License, or * 15 | * (at your option) any later version. * 16 | * * 17 | ***************************************************************************/ 18 | 19 | #ifndef _sidtypes_h_ 20 | #define _sidtypes_h_ 21 | 22 | #include "sidint.h" 23 | #include "sidconfig.h" 24 | 25 | #if SID_SIZEOF_CHAR == 1 26 | # if (SID_SIZEOF_SHORT_INT == 2) || (SID_SIZEOF_INT == 2) 27 | # if (SID_SIZEOF_INT == 4) || (SID_SIZEOF_LONG_INT == 4) 28 | //# define SID_OPTIMISE_MEMORY_ACCESS 29 | # endif 30 | # endif 31 | #endif 32 | 33 | #if SID_SIZEOF_CHAR != 1 34 | # error Code cannot work correctly on this platform as no real 8 bit data type supported! 35 | #endif 36 | 37 | #ifndef SID_HAVE_BOOL 38 | # ifdef SID_HAVE_STDBOOL_H 39 | # include 40 | # else 41 | typedef int bool; 42 | # define true 1 43 | # define false 0 44 | # endif /* SID_HAVE_STDBOOL_H */ 45 | #endif /* SID_HAVE_BOOL */ 46 | 47 | /* Custom types */ 48 | 49 | typedef unsigned int uint; 50 | 51 | #endif /* _sidtypes_h_ */ 52 | -------------------------------------------------------------------------------- /src/libpsid64/Makefile.am: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | 3 | EXTRA_DIST = stilview/README.txt stilview/STILView-config.patch 4 | 5 | AM_CFLAGS = $(WARNINGCFLAGS) 6 | AM_CXXFLAGS = $(WARNINGCXXFLAGS) 7 | 8 | lib_LIBRARIES = libpsid64.a 9 | 10 | libpsid64_a_SOURCES = \ 11 | psid64.cpp \ 12 | psidboot.a65 \ 13 | psidboot.h \ 14 | psidextboot.h \ 15 | psiddrv.a65 \ 16 | psiddrv.h \ 17 | psidextdrv.h \ 18 | reloc65.cpp \ 19 | reloc65.h \ 20 | screen.cpp \ 21 | screen.h \ 22 | sidid.cpp \ 23 | sidid.h \ 24 | theme.cpp \ 25 | theme.h \ 26 | exomizer/chunkpool.c \ 27 | exomizer/chunkpool.h \ 28 | exomizer/exomizer.c \ 29 | exomizer/exomizer.h \ 30 | exomizer/log.h \ 31 | exomizer/match.c \ 32 | exomizer/match.h \ 33 | exomizer/optimal.c \ 34 | exomizer/optimal.h \ 35 | exomizer/output.c \ 36 | exomizer/output.h \ 37 | exomizer/radix.c \ 38 | exomizer/radix.h \ 39 | exomizer/search.c \ 40 | exomizer/search.h \ 41 | exomizer/sfx64ne.c \ 42 | exomizer/sfx.h \ 43 | stilview/stil.cpp \ 44 | stilview/stil.h \ 45 | stilview/stilcomm.cpp \ 46 | stilview/stilcomm.h \ 47 | stilview/stildefs.h 48 | 49 | BUILT_SOURCES = \ 50 | psidboot.h \ 51 | psidextboot.h \ 52 | psiddrv.h \ 53 | psidextdrv.h 54 | 55 | define my_xa_recipe 56 | set -o pipefail ; \ 57 | if xa -M -c -R -G $< -o - $(1) | \ 58 | od -v -An -tx1 | \ 59 | sed -re 's/[[:alnum:]]+/0x&,/g' -e 's/[[:space:]]+//g' -e '/^$$/d' > $(srcdir)/$@ ; \ 60 | then true ; \ 61 | else status=$$? ; $(RM) $(srcdir)/$@ ; exit $$status ; \ 62 | fi 63 | endef 64 | 65 | define my_xa_recipe_ext 66 | set -o pipefail ; \ 67 | if xa -M -c -R -G $< -o - -DSCREEN -DSMOOTH_SCROLL | \ 68 | od -v -An -tx1 | \ 69 | sed -re 's/[[:alnum:]]+/0x&,/g' -e 's/[[:space:]]+//g' -e '/^$$/d' > $(srcdir)/$@ ; \ 70 | then true ; \ 71 | else status=$$? ; $(RM) $(srcdir)/$@ ; exit $$status ; \ 72 | fi 73 | endef 74 | 75 | SUFFIXES = .a65 76 | 77 | .a65.h: 78 | $(my_xa_recipe) 79 | 80 | psidextboot.h: psidboot.a65 81 | $(my_xa_recipe_ext) 82 | 83 | psidextdrv.h: psiddrv.a65 84 | $(my_xa_recipe_ext) 85 | -------------------------------------------------------------------------------- /src/sidtune/prg.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | * C64 PRG file format support. 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include "SidTuneCfg.h" 21 | #include "SidTune.h" 22 | #include "SidTuneTools.h" 23 | 24 | static const char _sidtune_format_prg[] = "Tape image file (PRG)"; 25 | static const char _sidtune_truncated[] = "ERROR: File is most likely truncated"; 26 | 27 | 28 | SidTune::LoadStatus SidTune::PRG_fileSupport(const char *fileName, 29 | Buffer_sidtt& dataBuf) 30 | { 31 | const char *ext = SidTuneTools::fileExtOfPath(const_cast(fileName)); 32 | if ( (MYSTRICMP(ext,".prg")!=0) && 33 | (MYSTRICMP(ext,".c64")!=0) ) 34 | { 35 | return LOAD_NOT_MINE; 36 | } 37 | 38 | info.formatString = _sidtune_format_prg; 39 | if (dataBuf.len() < 2) 40 | { 41 | info.formatString = _sidtune_truncated; 42 | return LOAD_ERROR; 43 | } 44 | 45 | // Automatic settings 46 | info.songs = 1; 47 | info.startSong = 1; 48 | info.compatibility = SIDTUNE_COMPATIBILITY_BASIC; 49 | info.numberOfInfoStrings = 0; 50 | 51 | // Create the speed/clock setting table. 52 | convertOldStyleSpeedToTables(~0, info.clockSpeed); 53 | return LOAD_OK; 54 | } 55 | -------------------------------------------------------------------------------- /src/libpsid64/exomizer/optimal.h: -------------------------------------------------------------------------------- 1 | #ifndef ALREADY_INCLUDED_OPTIMAL_H 2 | #define ALREADY_INCLUDED_OPTIMAL_H 3 | 4 | /* 5 | * Copyright (c) 2002, 2003 Magnus Lind. 6 | * 7 | * This software is provided 'as-is', without any express or implied warranty. 8 | * In no event will the authors be held liable for any damages arising from 9 | * the use of this software. 10 | * 11 | * Permission is granted to anyone to use this software, alter it and re- 12 | * distribute it freely for any non-commercial, non-profit purpose subject to 13 | * the following restrictions: 14 | * 15 | * 1. The origin of this software must not be misrepresented; you must not 16 | * claim that you wrote the original software. If you use this software in a 17 | * product, an acknowledgment in the product documentation would be 18 | * appreciated but is not required. 19 | * 20 | * 2. Altered source versions must be plainly marked as such, and must not 21 | * be misrepresented as being the original software. 22 | * 23 | * 3. This notice may not be removed or altered from any distribution. 24 | * 25 | * 4. The names of this software and/or it's copyright holders may not be 26 | * used to endorse or promote products derived from this software without 27 | * specific prior written permission. 28 | * 29 | */ 30 | 31 | #include "search.h" 32 | #include "output.h" 33 | 34 | float optimal_encode(const_matchp mp, /* IN */ 35 | encode_match_data emp); /* IN */ 36 | 37 | void optimal_init(encode_match_data emp); /* IN/OUT */ 38 | 39 | void optimal_free(encode_match_data emd); /* IN */ 40 | 41 | void optimal_optimize(encode_match_data emd, /* IN/OUT */ 42 | matchp_enum_get_next_f * f, /* IN */ 43 | void *priv); /* IN */ 44 | 45 | void optimal_fixup(encode_match_data emd, /* IN/OUT */ 46 | int max_len, /* IN */ 47 | int max_offset); /* IN */ 48 | 49 | void optimal_dump(encode_match_data emp); /* IN */ 50 | 51 | void optimal_out(output_ctx out, /* IN/OUT */ 52 | encode_match_data emd); /* IN */ 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /include/sidplay/utils/SidDatabase.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /*************************************************************************** 3 | SidDatabase.h - songlength database support 4 | ------------------- 5 | begin : Sun Mar 11 2001 6 | copyright : (C) 2001 by Simon White 7 | email : s_a_white@email.com 8 | ***************************************************************************/ 9 | 10 | /*************************************************************************** 11 | * * 12 | * This program is free software; you can redistribute it and/or modify * 13 | * it under the terms of the GNU General Public License as published by * 14 | * the Free Software Foundation; either version 2 of the License, or * 15 | * (at your option) any later version. * 16 | * * 17 | ***************************************************************************/ 18 | 19 | #ifndef _siddatabase_h_ 20 | #define _siddatabase_h_ 21 | 22 | #include "SidTuneMod.h" 23 | #include "libini.h" 24 | 25 | class SID_EXTERN SidDatabase 26 | { 27 | private: 28 | static const char *ERR_DATABASE_CORRUPT; 29 | static const char *ERR_NO_DATABASE_LOADED; 30 | static const char *ERR_NO_SELECTED_SONG; 31 | static const char *ERR_MEM_ALLOC; 32 | static const char *ERR_UNABLE_TO_LOAD_DATABASE; 33 | 34 | ini_fd_t database; 35 | const char *errorString; 36 | 37 | int_least32_t parseTimeStamp (const char* arg); 38 | uint_least8_t timesFound (char *str); 39 | 40 | public: 41 | SidDatabase () : database (0), errorString(NULL) {;} 42 | ~SidDatabase (); 43 | 44 | int open (const char *filename); 45 | void close (); 46 | int_least32_t length (SidTuneMod &tune); 47 | int_least32_t length (const char *md5, uint_least16_t song); 48 | const char * error (void) { return errorString; } 49 | }; 50 | 51 | #endif // _siddatabase_h_ 52 | -------------------------------------------------------------------------------- /src/libpsid64/reloc65.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | psid64 - PlaySID player for a real C64 environment 4 | Copyright (C) 2001-2003 Roland Hermans 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #ifndef RELOC65_H 22 | #define RELOC65_H 23 | 24 | ////////////////////////////////////////////////////////////////////////////// 25 | // I N C L U D E S 26 | ////////////////////////////////////////////////////////////////////////////// 27 | 28 | #include 29 | #include 30 | 31 | 32 | ////////////////////////////////////////////////////////////////////////////// 33 | // F O R W A R D D E C L A R A T O R S 34 | ////////////////////////////////////////////////////////////////////////////// 35 | 36 | 37 | ////////////////////////////////////////////////////////////////////////////// 38 | // D A T A D E C L A R A T O R S 39 | ////////////////////////////////////////////////////////////////////////////// 40 | 41 | typedef std::map globals_t; 42 | 43 | 44 | ////////////////////////////////////////////////////////////////////////////// 45 | // F U N C T I O N D E C L A R A T O R S 46 | ////////////////////////////////////////////////////////////////////////////// 47 | 48 | extern int reloc65 (char **buf, int *fsize, int addr, globals_t *globals); 49 | 50 | #endif // RELOC65_H 51 | -------------------------------------------------------------------------------- /psid64.spec.in: -------------------------------------------------------------------------------- 1 | Summary: A PSID file converter and native Commodore 64 music player. 2 | Name: @PACKAGE@ 3 | Version: @VERSION@ 4 | Release: 1%{?dist} 5 | License: GPL 6 | URL: http://psid64.sourceforge.net/ 7 | Group: Applications/Multimedia 8 | Source: http://sourceforge.net/projects/psid64/files/%{name}/%{version}/%{name}-%{version}.tar.gz 9 | Buildroot: %{_tmppath}/%{name}-%{version}-root 10 | 11 | %description 12 | PSID64 is a program that makes it possible to listen to your favourite 13 | SID music on a real Commodore 64 computer. It automatically generates 14 | a C64 self extracting executable from a PSID file. The executable 15 | contains the PSID data, a pre-relocated player and may also - if there 16 | is enough space available in the C64 environment - contain a 17 | demonstration program with information about the PSID file. 18 | 19 | %package devel 20 | Summary: Header files and libraries for PSID64 development. 21 | Group: Development/Libraries 22 | 23 | %description devel 24 | The @PACKAGE@-devel package contains the header files and libraries needed 25 | to develop programs that use the PSID64 library. 26 | 27 | %prep 28 | %setup -q 29 | 30 | %build 31 | %configure 32 | make %{?_smp_mflags} 33 | 34 | %install 35 | rm -rf %{buildroot} 36 | make DESTDIR=%{buildroot} install 37 | 38 | %files 39 | %defattr(-,root,root) 40 | %doc AUTHORS COPYING INSTALL NEWS.md README.md TODO 41 | %{_bindir}/psid64 42 | 43 | %files devel 44 | %defattr(-,root,root) 45 | %doc AUTHORS COPYING INSTALL NEWS.md README.md TODO 46 | %{_includedir}/psid64/psid64.h 47 | %{_libdir}/libpsid64.a 48 | 49 | %changelog 50 | * Thu Aug 3 2023 Roland Hermans 1.3-1 51 | - convert README and NEWS to Markdown 52 | - remove superfluous %clean section 53 | 54 | * Sat Feb 24 2007 Roland Hermans 0.8-1 55 | - upgraded to RPM 4.4 56 | - separate development package for header files and libraries 57 | - Fedora packaging guidelines and rpmlint fixes 58 | 59 | * Thu Nov 7 2002 Roland Hermans 0.5-1 60 | - upgraded to RPM 4.1 61 | 62 | * Sat Sep 8 2001 Roland Hermans 0.1-1 63 | - initial RPM release 64 | -------------------------------------------------------------------------------- /src/libpsid64/exomizer/radix.h: -------------------------------------------------------------------------------- 1 | #ifndef ALREADY_INCLUDED_RADIX_H 2 | #define ALREADY_INCLUDED_RADIX_H 3 | /* 4 | * Copyright (c) 2002, 2003 Magnus Lind. 5 | * 6 | * This software is provided 'as-is', without any express or implied warranty. 7 | * In no event will the authors be held liable for any damages arising from 8 | * the use of this software. 9 | * 10 | * Permission is granted to anyone to use this software, alter it and re- 11 | * distribute it freely for any non-commercial, non-profit purpose subject to 12 | * the following restrictions: 13 | * 14 | * 1. The origin of this software must not be misrepresented; you must not 15 | * claim that you wrote the original software. If you use this software in a 16 | * product, an acknowledgment in the product documentation would be 17 | * appreciated but is not required. 18 | * 19 | * 2. Altered source versions must be plainly marked as such, and must not 20 | * be misrepresented as being the original software. 21 | * 22 | * 3. This notice may not be removed or altered from any distribution. 23 | * 24 | * 4. The names of this software and/or it's copyright holders may not be 25 | * used to endorse or promote products derived from this software without 26 | * specific prior written permission. 27 | * 28 | */ 29 | 30 | #include "chunkpool.h" 31 | 32 | typedef struct _radix_node *radix_nodep; 33 | 34 | struct _radix_root { 35 | int depth; 36 | radix_nodep root; 37 | struct chunkpool mem[1]; 38 | }; 39 | 40 | typedef struct _radix_root radix_root[1]; 41 | typedef struct _radix_root *radix_rootp; 42 | 43 | 44 | typedef void free_callback(void *data, void *priv); 45 | 46 | /* *f will be called even for null pointers */ 47 | void radix_tree_free(radix_root rr, /* IN */ 48 | free_callback * f, /* IN */ 49 | void *priv); /* IN */ 50 | 51 | void radix_tree_init(radix_root rr); /* IN */ 52 | 53 | void radix_node_set(radix_rootp rrp, /* IN */ 54 | unsigned int index, /* IN */ 55 | void *data); /* IN */ 56 | 57 | void *radix_node_get(radix_root rr, /* IN */ 58 | unsigned int index); /* IN */ 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/ConsoleApp.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | psid64 - create a C64 executable from a PSID file 4 | Copyright (C) 2001-2023 Roland Hermans 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | ////////////////////////////////////////////////////////////////////////////// 22 | // I N C L U D E S 23 | ////////////////////////////////////////////////////////////////////////////// 24 | 25 | #ifndef CONSOLEAPP_H 26 | #define CONSOLEAPP_H 27 | 28 | #include 29 | 30 | #include 31 | 32 | class ConsoleApp 33 | { 34 | public: 35 | ConsoleApp(); 36 | ~ConsoleApp(); 37 | 38 | bool main(int argc, char **argv); 39 | 40 | private: 41 | const std::string m_sidPostfix; 42 | const std::string m_prgPostfix; 43 | 44 | bool m_verbose; 45 | std::string m_outputPathName; 46 | 47 | Psid64 m_psid64; 48 | 49 | static void printUsage(); 50 | static void printHelp(); 51 | 52 | static bool isdir(const std::string& path); 53 | static std::string basename(const std::string& path); 54 | std::string buildOutputFileName(const std::string& sidFileName, const std::string& outputPathName) const; 55 | bool convertFile(const std::string& inputFileName, const std::string& outputFileName); 56 | bool convertDir(const std::string& inputDirName, const std::string& outputDirName); 57 | bool convert(const std::string& pathName); 58 | }; 59 | 60 | #endif // CONSOLEAPP_H 61 | -------------------------------------------------------------------------------- /src/sidtune/PP20.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | * /home/ms/files/source/libsidtune/RCS/PP20.h,v 4 | * 5 | * PowerPacker (AMIGA) "PP20" format decompressor. 6 | * Copyright (C) Michael Schwendt 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | */ 22 | 23 | #ifndef PP_DECOMPRESSOR_H 24 | #define PP_DECOMPRESSOR_H 25 | 26 | #include "PP20_Defs.h" 27 | 28 | class PP20 29 | { 30 | public: 31 | 32 | PP20(); 33 | 34 | bool isCompressed(const void* source, const udword_ppt size); 35 | 36 | // If successful, allocates a new buffer containing the 37 | // uncompresse data and returns the uncompressed length. 38 | // Else, returns 0. 39 | udword_ppt decompress(const void* source, 40 | udword_ppt size, 41 | ubyte_ppt** destRef); 42 | 43 | const char* getStatusString() { return statusString; } 44 | 45 | private: 46 | bool checkEfficiency(const void* source); 47 | 48 | void bytesTOdword(); 49 | udword_ppt readBits(int count); 50 | void bytes(); 51 | void sequence(); 52 | 53 | static const char* PP_ID; 54 | 55 | ubyte_ppt efficiency[4]; 56 | 57 | const ubyte_ppt* sourceBeg; 58 | const ubyte_ppt* readPtr; 59 | 60 | const ubyte_ppt* destBeg; 61 | ubyte_ppt* writePtr; 62 | 63 | udword_ppt current; // compressed data longword 64 | int bits; // number of bits in 'current' to evaluate 65 | 66 | bool globalError; // exception-free version of code 67 | 68 | const char* statusString; 69 | }; 70 | 71 | #endif /* PP_DECOMPRESSOR_H */ 72 | -------------------------------------------------------------------------------- /src/libpsid64/stilview/stildefs.h: -------------------------------------------------------------------------------- 1 | // 2 | // STIL - Common defines 3 | // 4 | 5 | #ifndef _STILDEFS_H 6 | #define _STILDEFS_H 7 | 8 | #if defined(__linux__) || defined(__FreeBSD__) || defined(solaris2) || defined(sun) || defined(sparc) || defined(sgi) || defined(__APPLE__) 9 | #define UNIX 10 | #endif 11 | 12 | #if defined(__MACOS__) 13 | #define MAC 14 | #endif 15 | 16 | #if defined(__amigaos__) 17 | #define AMIGA 18 | #endif 19 | 20 | // 21 | // Here you should define: 22 | // - what the pathname separator is on your system (attempted to be defined 23 | // automatically), 24 | // - what function compares strings case-insensitively, 25 | // - what function compares portions of strings case-insensitively. 26 | // 27 | 28 | #ifdef UNIX 29 | #define SLASH '/' 30 | #elif MAC 31 | #define SLASH ':' 32 | #elif AMIGA 33 | #define SLASH '/' 34 | #else // WinDoze 35 | #define SLASH '\\' 36 | #endif 37 | 38 | // Define which one of the following two is supported on your system. 39 | #define HAVE_STRCASECMP 1 40 | // #define HAVE_STRICMP 1 41 | 42 | // Define which one of the following two is supported on your system. 43 | #define HAVE_STRNCASECMP 1 44 | // #define HAVE_STRNICMP 1 45 | 46 | // Now let's do the actual definitions. 47 | 48 | #ifdef HAVE_STRCASECMP 49 | #define MYSTRICMP strcasecmp 50 | #elif HAVE_STRICMP 51 | #define MYSTRICMP stricmp 52 | #else 53 | #error Neither strcasecmp nor stricmp is available. 54 | #endif 55 | 56 | #ifdef HAVE_STRNCASECMP 57 | #define MYSTRNICMP strncasecmp 58 | #elif HAVE_STRNICMP 59 | #define MYSTRNICMP strnicmp 60 | #else 61 | #error Neither strncasecmp nor strnicmp is available. 62 | #endif 63 | 64 | // These are the hardcoded STIL/BUG field names. 65 | const char _NAME_STR[]=" NAME: "; 66 | const char _AUTHOR_STR[]=" AUTHOR: "; 67 | const char _TITLE_STR[]=" TITLE: "; 68 | const char _ARTIST_STR[]=" ARTIST: "; 69 | const char _COMMENT_STR[]="COMMENT: "; 70 | const char _BUG_STR[]="BUG: "; 71 | 72 | // Maximum size of a single line in STIL - also accounts for some extra 73 | // padding, just in case. 74 | #define STIL_MAX_LINE_SIZE 91 75 | 76 | // Maximum size of a single STIL entry (in bytes). 77 | #define STIL_MAX_ENTRY_SIZE STIL_MAX_LINE_SIZE*100 78 | 79 | // HVSC path to STIL. 80 | const char PATH_TO_STIL[]="/DOCUMENTS/STIL.txt"; 81 | 82 | // HVSC path to BUGlist. 83 | const char PATH_TO_BUGLIST[]="/DOCUMENTS/BUGlist.txt"; 84 | 85 | #endif // _STILDEFS_H 86 | -------------------------------------------------------------------------------- /src/sidutils/ini/keys.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /*************************************************************************** 3 | keys.h - Key Manipulation Functions 4 | 5 | ------------------- 6 | begin : Fri Apr 21 2000 7 | copyright : (C) 2000 by Simon White 8 | email : s_a_white@email.com 9 | ***************************************************************************/ 10 | 11 | /*************************************************************************** 12 | * * 13 | * This program is free software; you can redistribute it and/or modify * 14 | * it under the terms of the GNU General Public License as published by * 15 | * the Free Software Foundation; either version 2 of the License, or * 16 | * (at your option) any later version. * 17 | * * 18 | ***************************************************************************/ 19 | 20 | #ifndef _keys_h_ 21 | #define _keys_h_ 22 | 23 | #include 24 | #include "ini.h" 25 | 26 | //******************************************************************************************************************* 27 | // Data structure definitions 28 | //******************************************************************************************************************* 29 | struct ini_t; 30 | struct section_tag; 31 | 32 | // Linked list structure for holding key information. 33 | struct key_tag 34 | { 35 | char *key; 36 | long pos; 37 | size_t length; 38 | struct key_tag *pNext; 39 | struct key_tag *pPrev; 40 | 41 | #ifdef INI_USE_HASH_TABLE 42 | unsigned long crc; 43 | struct key_tag *pNext_Acc; 44 | struct key_tag *pPrev_Acc; 45 | #endif // INI_USE_HASH_TABLE 46 | }; 47 | 48 | static struct key_tag *__ini_addKey (struct ini_t *ini, char *key); 49 | static struct key_tag *__ini_faddKey (struct ini_t *ini, FILE *file, long pos, size_t length); 50 | static struct key_tag *__ini_createKey (struct ini_t *ini, char *key); 51 | static void __ini_deleteKey (struct ini_t *ini); 52 | static struct key_tag *__ini_locateKey (struct ini_t *ini, const char *key); 53 | static size_t __ini_averageLengthKey (struct section_tag *current_h); 54 | 55 | #endif // _keys_h_ 56 | -------------------------------------------------------------------------------- /src/sidutils/ini/headings.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /*************************************************************************** 3 | headings.h - Section Heading Manipulation Functions 4 | 5 | ------------------- 6 | begin : Fri Apr 21 2000 7 | copyright : (C) 2000 by Simon White 8 | email : s_a_white@email.com 9 | ***************************************************************************/ 10 | 11 | /*************************************************************************** 12 | * * 13 | * This program is free software; you can redistribute it and/or modify * 14 | * it under the terms of the GNU General Public License as published by * 15 | * the Free Software Foundation; either version 2 of the License, or * 16 | * (at your option) any later version. * 17 | * * 18 | ***************************************************************************/ 19 | 20 | #ifndef _headings_h_ 21 | #define _headings_h_ 22 | 23 | #include 24 | #include "ini.h" 25 | 26 | //******************************************************************************************************************* 27 | // Data structure definitions 28 | //******************************************************************************************************************* 29 | struct keys_tag; 30 | struct ini_t; 31 | 32 | // Linked list structure for holding section/heading information. 33 | struct section_tag 34 | { 35 | char *heading; 36 | struct key_tag *first; 37 | struct key_tag *last; 38 | struct key_tag *selected; 39 | struct section_tag *pNext; 40 | struct section_tag *pPrev; 41 | 42 | #ifdef INI_USE_HASH_TABLE 43 | unsigned long crc; 44 | struct key_tag *keys[256]; 45 | struct section_tag *pNext_Acc; 46 | struct section_tag *pPrev_Acc; 47 | #endif // INI_USE_HASH_TABLE 48 | }; 49 | 50 | static struct section_tag *__ini_addHeading (struct ini_t *ini, char *heading); 51 | static struct section_tag *__ini_faddHeading (struct ini_t *ini, FILE *file, long pos, size_t length); 52 | static struct section_tag *__ini_createHeading (struct ini_t *ini, char *heading); 53 | static void __ini_deleteHeading (struct ini_t *ini); 54 | static struct section_tag *__ini_locateHeading (struct ini_t *ini, const char *heading); 55 | 56 | #endif // _headings_h_ 57 | -------------------------------------------------------------------------------- /src/libpsid64/stilview/STILView-config.patch: -------------------------------------------------------------------------------- 1 | *** stildefs.h.orig Sat Nov 17 13:29:03 2001 2 | --- stildefs.h Sat Nov 17 13:41:13 2001 3 | *************** 4 | *** 5,47 **** 5 | #ifndef _STILDEFS_H 6 | #define _STILDEFS_H 7 | 8 | ! #if defined(__linux__) || defined(__FreeBSD__) || defined(solaris2) || defined(sun) || defined(sparc) || defined(sgi) 9 | ! #define UNIX 10 | ! #endif 11 | ! 12 | ! #if defined(__MACOS__) 13 | ! #define MAC 14 | ! #endif 15 | ! 16 | ! #if defined(__amigaos__) 17 | ! #define AMIGA 18 | ! #endif 19 | 20 | // On a per OS basis: 21 | // - Define what the pathname separator is. 22 | // - Define what the function is to compare strings case-insensitively. 23 | // - Define what the function is to compare portions of strings case-insensitively. 24 | // 25 | ! #ifdef UNIX 26 | ! #define SLASH '/' 27 | ! #define MYSTRCMP strcasecmp 28 | ! #define MYSTRNCMP strncasecmp 29 | ! #else 30 | ! #ifdef MAC 31 | ! #define SLASH ':' 32 | ! #define MYSTRCMP stricmp 33 | ! #define MYSTRNCMP strnicmp 34 | #else 35 | ! #ifdef AMIGA 36 | ! #define SLASH '/' 37 | ! #define MYSTRCMP stricmp 38 | ! #define MYSTRNCMP strnicmp 39 | ! #else // WinDoze 40 | ! #define SLASH '\\' 41 | ! #define MYSTRCMP stricmp 42 | ! #define MYSTRNCMP strnicmp 43 | ! #endif 44 | #endif 45 | #endif 46 | 47 | // Common definition for boolean 48 | --- 5,27 ---- 49 | #ifndef _STILDEFS_H 50 | #define _STILDEFS_H 51 | 52 | ! #include "config.h" 53 | 54 | // On a per OS basis: 55 | // - Define what the pathname separator is. 56 | // - Define what the function is to compare strings case-insensitively. 57 | // - Define what the function is to compare portions of strings case-insensitively. 58 | // 59 | ! #define SLASH '/' 60 | ! #ifdef HAVE_STRCASECMP 61 | ! #define MYSTRCMP strcasecmp 62 | #else 63 | ! #define MYSTRCMP stricmp 64 | #endif 65 | + #ifdef HAVE_STRNCASECMP 66 | + #define MYSTRNCMP strncasecmp 67 | + #else 68 | + #define MYSTRNCMP strnicmp 69 | #endif 70 | 71 | // Common definition for boolean 72 | *************** 73 | *** 60,66 **** 74 | 75 | // Maximum size of a single line in STIL - also accounts for some extra 76 | // padding, just in case. 77 | ! #define STIL_MAX_LINE_SIZE 91 78 | 79 | // Maximum size of a single STIL entry (in bytes). 80 | #define STIL_MAX_ENTRY_SIZE STIL_MAX_LINE_SIZE*100 81 | --- 40,46 ---- 82 | 83 | // Maximum size of a single line in STIL - also accounts for some extra 84 | // padding, just in case. 85 | ! #define STIL_MAX_LINE_SIZE 129 86 | 87 | // Maximum size of a single STIL entry (in bytes). 88 | #define STIL_MAX_ENTRY_SIZE STIL_MAX_LINE_SIZE*100 89 | -------------------------------------------------------------------------------- /src/sidutils/ini/ini.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /*************************************************************************** 3 | ini.h - Ini database definition 4 | 5 | ------------------- 6 | begin : Fri Apr 21 2000 7 | copyright : (C) 2000 by Simon White 8 | email : s_a_white@email.com 9 | ***************************************************************************/ 10 | 11 | /*************************************************************************** 12 | * * 13 | * This program is free software; you can redistribute it and/or modify * 14 | * it under the terms of the GNU General Public License as published by * 15 | * the Free Software Foundation; either version 2 of the License, or * 16 | * (at your option) any later version. * 17 | * * 18 | ***************************************************************************/ 19 | 20 | #ifndef _ini_h_ 21 | #define _ini_h_ 22 | 23 | #define INI_USE_HASH_TABLE 24 | 25 | #include "libini.h" 26 | #include "keys.h" 27 | #include "headings.h" 28 | #ifdef INI_ADD_LIST_SUPPORT 29 | # include "list.h" 30 | #endif 31 | 32 | typedef enum {INI_NEW, INI_EXIST, INI_READ} ini_mode_t; 33 | 34 | enum 35 | { 36 | INI_NONE = 0, 37 | INI_MODIFIED = 1 << 0, 38 | INI_NEWFILE = 1 << 1, 39 | INI_BACKUP = 1 << 2, // Create backup file 40 | INI_CASE = 1 << 3 // Case sensitive 41 | }; 42 | 43 | // Database containing all information about an ini file. 44 | typedef struct ini_t 45 | { 46 | char *filename; 47 | FILE *ftmp; // Temporary work file 48 | ini_mode_t mode; // Access mode 49 | int flags; 50 | 51 | struct section_tag *first; 52 | struct section_tag *last; 53 | struct section_tag *selected; 54 | char *heading; // Last written section in tmp file. 55 | struct section_tag tmpSection; 56 | struct key_tag tmpKey; 57 | 58 | #ifdef INI_USE_HASH_TABLE 59 | struct section_tag *sections[256]; 60 | #endif 61 | 62 | #ifdef INI_ADD_LIST_SUPPORT 63 | // Rev 1.1 Added - New for list accessing 64 | char *list; // Accelerator for accessing same list (When all list read, will be freed) 65 | char *listDelims; // list sperators 66 | char *listIndexPtr; // current element we wish to access (will auto increment) 67 | unsigned int listLength; 68 | unsigned int listIndex; 69 | #endif // INI_ADD_LIST_SUPPORT 70 | } ini_t; 71 | 72 | static void __ini_strtrim (char *str); 73 | #ifdef INI_USE_HASH_TABLE 74 | static unsigned long __ini_createCrc32 (const char *str, bool strcase); 75 | #endif 76 | 77 | #endif // _ini_h_ 78 | -------------------------------------------------------------------------------- /src/libpsid64/exomizer/output.h: -------------------------------------------------------------------------------- 1 | #ifndef ALREADY_INCLUDED_OUTPUT_H 2 | #define ALREADY_INCLUDED_OUTPUT_H 3 | 4 | /* 5 | * Copyright (c) 2002, 2003 Magnus Lind. 6 | * 7 | * This software is provided 'as-is', without any express or implied warranty. 8 | * In no event will the authors be held liable for any damages arising from 9 | * the use of this software. 10 | * 11 | * Permission is granted to anyone to use this software, alter it and re- 12 | * distribute it freely for any non-commercial, non-profit purpose subject to 13 | * the following restrictions: 14 | * 15 | * 1. The origin of this software must not be misrepresented; you must not 16 | * claim that you wrote the original software. If you use this software in a 17 | * product, an acknowledgment in the product documentation would be 18 | * appreciated but is not required. 19 | * 20 | * 2. Altered source versions must be plainly marked as such, and must not 21 | * be misrepresented as being the original software. 22 | * 23 | * 3. This notice may not be removed or altered from any distribution. 24 | * 25 | * 4. The names of this software and/or it's copyright holders may not be 26 | * used to endorse or promote products derived from this software without 27 | * specific prior written permission. 28 | * 29 | */ 30 | 31 | #include 32 | 33 | struct _output_ctx { 34 | unsigned int bitbuf; 35 | unsigned short int pos; 36 | unsigned short int start; 37 | unsigned char flags; 38 | unsigned char buf[65536]; 39 | }; 40 | 41 | typedef struct _output_ctx output_ctx[1]; 42 | typedef struct _output_ctx *output_ctxp; 43 | 44 | void output_ctx_init(output_ctx ctx); /* IN/OUT */ 45 | 46 | void output_ctx_set_start(output_ctx ctx, /* IN/OUT */ 47 | unsigned int pos); /* IN */ 48 | 49 | void output_ctx_set_reverse(output_ctx ctx); /* IN/OUT */ 50 | 51 | unsigned int output_ctx_close(output_ctx ctx, /* IN */ 52 | FILE * out); /* OUT */ 53 | 54 | unsigned int output_get_pos(output_ctx ctx); /* IN */ 55 | 56 | void output_set_pos(output_ctx ctx, /* IN */ 57 | unsigned int pos); /* IN */ 58 | 59 | void output_copy_bytes(output_ctx ctx, /* IN */ 60 | unsigned int src_pos, /* IN */ 61 | unsigned int len); /* IN */ 62 | 63 | void output_byte(output_ctx ctx, /* IN/OUT */ 64 | unsigned char byte); /* IN */ 65 | 66 | void output_word(output_ctx ctx, /* IN/OUT */ 67 | unsigned short int word); /* IN */ 68 | 69 | void output_bits_flush(output_ctx ctx); /* IN/OUT */ 70 | 71 | void output_bits(output_ctx ctx, /* IN/OUT */ 72 | int count, /* IN */ 73 | int val); /* IN */ 74 | 75 | void output_gamma_code(output_ctx ctx, /* IN/OUT */ 76 | int code); /* IN */ 77 | #endif 78 | -------------------------------------------------------------------------------- /src/libpsid64/sidid.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | psid64 - create a C64 executable from a PSID file 4 | Copyright (C) 2015 Roland Hermans 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #ifndef SIDID_H 22 | #define SIDID_H 23 | 24 | ////////////////////////////////////////////////////////////////////////////// 25 | // I N C L U D E S 26 | ////////////////////////////////////////////////////////////////////////////// 27 | 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | 34 | ////////////////////////////////////////////////////////////////////////////// 35 | // F O R W A R D D E C L A R A T O R S 36 | ////////////////////////////////////////////////////////////////////////////// 37 | 38 | 39 | ////////////////////////////////////////////////////////////////////////////// 40 | // D A T A D E C L A R A T O R S 41 | ////////////////////////////////////////////////////////////////////////////// 42 | 43 | class SidId 44 | { 45 | class Pattern 46 | { 47 | std::vector m_values; 48 | public: 49 | void clear(); 50 | void pushValue(uint_least16_t value); 51 | bool match(const std::vector& buffer) const; 52 | }; 53 | 54 | class Player 55 | { 56 | std::string m_name; 57 | std::vector m_patterns; 58 | public: 59 | explicit Player(const std::string& name); 60 | void addPattern(const Pattern& pattern); 61 | const std::string& name() const; 62 | bool match(const std::vector& buffer) const; 63 | }; 64 | 65 | std::vector m_players; 66 | 67 | static const uint_least16_t MATCH_WILDCARD_ONE = 0x100; 68 | static const uint_least16_t MATCH_WILDCARD_MULTIPLE = 0x101; 69 | static const uint_least16_t MATCH_END = 0x102; 70 | 71 | static std::string trim(const std::string& str, 72 | const std::string& whitespace = " \t\n\r"); 73 | public: 74 | bool readConfigFile(const std::string& filename); 75 | std::string identify(const std::vector& buffer); 76 | }; 77 | 78 | #endif // SIDID_H 79 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | psid64 - create a C64 executable from a PSID file 4 | Copyright (C) 2001-2003 Roland Hermans 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | 20 | 21 | The relocating PSID driver is based on a reference implementation written 22 | by Dag Lem, using Andre Fachat's relocating cross assembler, xa. The 23 | original driver code was introduced in VICE 1.7. 24 | */ 25 | 26 | ////////////////////////////////////////////////////////////////////////////// 27 | // I N C L U D E S 28 | ////////////////////////////////////////////////////////////////////////////// 29 | 30 | #ifdef HAVE_CONFIG_H 31 | #include "config.h" 32 | #endif 33 | 34 | #include "ConsoleApp.h" 35 | 36 | 37 | /**************************************************************************** 38 | * G L O B A L D A T A * 39 | ****************************************************************************/ 40 | 41 | 42 | /**************************************************************************** 43 | * L O C A L D E F I N I T I O N S * 44 | ****************************************************************************/ 45 | 46 | 47 | /**************************************************************************** 48 | * L O C A L D A T A * 49 | ****************************************************************************/ 50 | 51 | 52 | /**************************************************************************** 53 | * L O C A L F U N C T I O N S * 54 | ****************************************************************************/ 55 | 56 | 57 | /**************************************************************************** 58 | * G L O B A L F U N C T I O N S * 59 | ****************************************************************************/ 60 | 61 | int 62 | main(int argc, char **argv) 63 | { 64 | int retval = 0; 65 | ConsoleApp app; 66 | 67 | if (app.main(argc, argv) == false) 68 | { 69 | retval = 1; 70 | } 71 | 72 | return retval; 73 | } 74 | -------------------------------------------------------------------------------- /src/libpsid64/exomizer/chunkpool.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003 Magnus Lind. 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. 5 | * In no event will the authors be held liable for any damages arising from 6 | * the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software, alter it and re- 9 | * distribute it freely for any non-commercial, non-profit purpose subject to 10 | * the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software in a 14 | * product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not 18 | * be misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any distribution. 21 | * 22 | * 4. The names of this software and/or it's copyright holders may not be 23 | * used to endorse or promote products derived from this software without 24 | * specific prior written permission. 25 | * 26 | */ 27 | 28 | #include 29 | #include 30 | #include "chunkpool.h" 31 | #include "log.h" 32 | 33 | void 34 | chunkpool_init(struct chunkpool *ctx, int size) 35 | { 36 | ctx->chunk_size = size; 37 | ctx->chunk = -1; 38 | ctx->chunk_pos = 0; 39 | ctx->chunk_max = (0x1fffff / size) * size; 40 | } 41 | 42 | void 43 | chunkpool_free(struct chunkpool *ctx) 44 | { 45 | while(ctx->chunk >= 0) 46 | { 47 | free(ctx->chunks[ctx->chunk]); 48 | ctx->chunk -= 1; 49 | } 50 | ctx->chunk_pos = 0; 51 | } 52 | 53 | void * 54 | chunkpool_malloc(struct chunkpool *ctx) 55 | { 56 | void *p; 57 | if(ctx->chunk_pos == 0) 58 | { 59 | void *m; 60 | if(ctx->chunk == 31) 61 | { 62 | LOG(LOG_ERROR, ("out of chunks in file %s, line %d\n", 63 | __FILE__, __LINE__)); 64 | LOG(LOG_BRIEF, ("chunk_size %d\n", ctx->chunk_size)); 65 | LOG(LOG_BRIEF, ("chunk_max %d\n", ctx->chunk_max)); 66 | LOG(LOG_BRIEF, ("chunk %d\n", ctx->chunk)); 67 | exit(1); 68 | } 69 | m = malloc(ctx->chunk_max); 70 | if (m == NULL) 71 | { 72 | LOG(LOG_ERROR, ("out of memory error in file %s, line %d\n", 73 | __FILE__, __LINE__)); 74 | exit(1); 75 | } 76 | ctx->chunk += 1; 77 | ctx->chunks[ctx->chunk] = m; 78 | } 79 | p = (char*)ctx->chunks[ctx->chunk] + ctx->chunk_pos; 80 | ctx->chunk_pos += ctx->chunk_size; 81 | if(ctx->chunk_pos >= ctx->chunk_max) 82 | { 83 | ctx->chunk_pos = 0; 84 | } 85 | return p; 86 | } 87 | 88 | void * 89 | chunkpool_calloc(struct chunkpool *ctx) 90 | { 91 | void *p = chunkpool_malloc(ctx); 92 | memset(p, 0, ctx->chunk_size); 93 | return p; 94 | } 95 | -------------------------------------------------------------------------------- /src/libpsid64/exomizer/match.h: -------------------------------------------------------------------------------- 1 | #ifndef ALREADY_INCLUDED_MATCH_H 2 | #define ALREADY_INCLUDED_MATCH_H 3 | /* 4 | * Copyright (c) 2002 - 2004 Magnus Lind. 5 | * 6 | * This software is provided 'as-is', without any express or implied warranty. 7 | * In no event will the authors be held liable for any damages arising from 8 | * the use of this software. 9 | * 10 | * Permission is granted to anyone to use this software, alter it and re- 11 | * distribute it freely for any non-commercial, non-profit purpose subject to 12 | * the following restrictions: 13 | * 14 | * 1. The origin of this software must not be misrepresented; you must not 15 | * claim that you wrote the original software. If you use this software in a 16 | * product, an acknowledgment in the product documentation would be 17 | * appreciated but is not required. 18 | * 19 | * 2. Altered source versions must be plainly marked as such, and must not 20 | * be misrepresented as being the original software. 21 | * 22 | * 3. This notice may not be removed or altered from any distribution. 23 | * 24 | * 4. The names of this software and/or it's copyright holders may not be 25 | * used to endorse or promote products derived from this software without 26 | * specific prior written permission. 27 | * 28 | */ 29 | 30 | #include "chunkpool.h" 31 | 32 | struct match { 33 | unsigned short int offset; 34 | unsigned short int len; 35 | struct match *next; 36 | }; 37 | 38 | typedef struct match match[1]; 39 | typedef struct match *matchp; 40 | typedef const struct match *const_matchp; 41 | 42 | struct pre_calc { 43 | struct match_node *single; 44 | const struct match *cache; 45 | }; 46 | 47 | typedef struct pre_calc pre_calc[1]; 48 | 49 | struct match_ctx { 50 | struct chunkpool m_pool[1]; 51 | pre_calc info[65536]; 52 | unsigned short int rle[65536]; 53 | unsigned short int rle_r[65536]; 54 | const unsigned char *buf; 55 | int len; 56 | int max_offset; 57 | }; 58 | 59 | typedef struct match_ctx match_ctx[1]; 60 | typedef struct match_ctx *match_ctxp; 61 | 62 | void match_ctx_init(match_ctx ctx, /* IN/OUT */ 63 | const unsigned char *buf, /* IN */ 64 | int buf_len, /* IN */ 65 | int max_offset); /* IN */ 66 | 67 | void match_ctx_free(match_ctx ctx); /* IN/OUT */ 68 | 69 | /* this needs to be called with the indexes in 70 | * reverse order */ 71 | const_matchp matches_get(match_ctx ctx, /* IN/OUT */ 72 | unsigned short int index); /* IN */ 73 | 74 | void match_delete(match_ctx ctx, /* IN/OUT */ 75 | matchp mp); /* IN */ 76 | 77 | struct matchp_cache_enum { 78 | match_ctxp ctx; 79 | const_matchp next; 80 | match tmp1; 81 | match tmp2; 82 | int pos; 83 | }; 84 | 85 | typedef struct matchp_cache_enum matchp_cache_enum[1]; 86 | typedef struct matchp_cache_enum *matchp_cache_enump; 87 | 88 | void matchp_cache_get_enum(match_ctx ctx, /* IN */ 89 | matchp_cache_enum mpce); /* IN/OUT */ 90 | 91 | typedef const_matchp matchp_enum_get_next_f(void *matchp_enum); /* IN/OUT */ 92 | 93 | const_matchp matchp_cache_enum_get_next(void *matchp_cache_enum); /* IN */ 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | dnl Process this file with autoconf to produce a configure script. 2 | AC_INIT([psid64],[1.3],,,[https://www.psid64.org/]) 3 | AC_CONFIG_SRCDIR(src/main.cpp) 4 | AC_CONFIG_HEADERS([src/config.h]) 5 | AC_CONFIG_MACRO_DIRS([macros]) 6 | AM_INIT_AUTOMAKE([subdir-objects]) 7 | 8 | dnl Checks for programs. 9 | AC_PROG_CXX 10 | AC_PROG_INSTALL 11 | AC_PROG_LN_S 12 | AC_PROG_RANLIB 13 | 14 | dnl Checks for header files. 15 | AC_CHECK_HEADERS([getopt.h limits.h stdlib.h string.h unistd.h]) 16 | AC_CHECK_HEADER_STDBOOL 17 | 18 | dnl Checks for typedefs, structures, and compiler characteristics. 19 | AC_C_CONST 20 | AC_C_INLINE 21 | AC_TYPE_SIZE_T 22 | AC_TYPE_UINT16_T 23 | AC_TYPE_UINT8_T 24 | 25 | dnl Checks for library functions. 26 | AC_FUNC_MEMCMP 27 | AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK 28 | AC_CHECK_FUNCS([getopt_long lstat memmove memset mkdir snprintf strcasecmp strchr strdup strerror strncasecmp strrchr strstr]) 29 | AX_FUNC_MKDIR 30 | 31 | dnl 32 | dnl BEGIN_SIDTUNE_TESTS 33 | dnl 34 | 35 | dnl Check for AC99 headers 36 | AC_CHECK_HEADERS(stdbool.h) 37 | if test "$ac_cv_header_stdbool_h" = yes; then 38 | MY_SUBST_DEF(SID_HAVE_STDBOOL_H) 39 | else 40 | MY_SUBST_UNDEF(SID_HAVE_STDBOOL_H) 41 | fi 42 | AX_CREATE_STDINT_H(include/sidplay/sidint.h) 43 | 44 | dnl Checks for typedefs, structures, and compiler characteristics. 45 | AC_C_BIGENDIAN( 46 | [MY_SUBST(SID_WORDS_ENDIANESS,SID_WORDS_BIGENDIAN)], 47 | [MY_SUBST(SID_WORDS_ENDIANESS,SID_WORDS_LITTLEENDIAN)] 48 | ) 49 | 50 | AC_CHECK_SIZEOF(char) 51 | AC_CHECK_SIZEOF(short int) 52 | AC_CHECK_SIZEOF(int) 53 | AC_CHECK_SIZEOF(long int) 54 | 55 | MY_SUBST(SID_SIZEOF_CHAR,$ac_cv_sizeof_char) 56 | MY_SUBST(SID_SIZEOF_SHORT_INT,$ac_cv_sizeof_short_int) 57 | MY_SUBST(SID_SIZEOF_INT,$ac_cv_sizeof_int) 58 | MY_SUBST(SID_SIZEOF_LONG_INT,$ac_cv_sizeof_long_int) 59 | 60 | dnl Use C++ for other tests. 61 | AC_LANG(C++) 62 | 63 | dnl Checks for C++ library functions. 64 | AC_CHECK_HEADER(sstream,[AC_DEFINE(HAVE_SSTREAM,, 65 | [Define if you have the header file.])],[]) 66 | 67 | dnl Check whether the compiler has bool. 68 | MY_CHECK_BOOL 69 | if test "$test_cv_have_bool" = yes; then 70 | MY_SUBST_DEF(SID_HAVE_BOOL) 71 | else 72 | MY_SUBST_UNDEF(SID_HAVE_BOOL) 73 | fi 74 | 75 | dnl Check for exceptions. 76 | MY_CHECK_EXCEPTIONS 77 | 78 | dnl Check ANSI C++ ios features 79 | MY_CHECK_IOS_BIN 80 | MY_CHECK_IOS_OPENMODE 81 | 82 | dnl Add absolute directory for header files 83 | CXXFLAGS="$CXXFLAGS -I\$(top_srcdir)/include -I\$(top_srcdir)/include/sidplay\ 84 | -I\$(top_srcdir)/include/sidplay/utils" 85 | 86 | dnl 87 | dnl END_SIDTUNE_TESTS 88 | dnl 89 | 90 | dnl enable warnings and turn them into errors to enforce warning free code 91 | AC_SUBST([WARNINGCFLAGS],['-Wall -Werror']) 92 | AC_SUBST([WARNINGCXXFLAGS],['-Wall -Werror']) 93 | 94 | AC_CONFIG_FILES([Doxyfile 95 | Makefile 96 | psid64.spec 97 | include/sidplay/sidconfig.h 98 | src/Makefile 99 | src/libpsid64/Makefile 100 | src/sidtune/Makefile 101 | src/sidutils/Makefile 102 | src/sidutils/MD5/Makefile 103 | src/sidutils/ini/Makefile]) 104 | AC_OUTPUT 105 | -------------------------------------------------------------------------------- /src/sidtune/SidTuneTools.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | * /home/ms/files/source/libsidtune/RCS/SidTuneTools.h,v 4 | * 5 | * Copyright (C) Michael Schwendt 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | */ 21 | 22 | #ifndef TOOLS_H 23 | #define TOOLS_H 24 | 25 | #include "SidTuneCfg.h" 26 | #include "sidtypes.h" 27 | 28 | #include 29 | #if defined(HAVE_SSTREAM) 30 | # include 31 | #else 32 | # include 33 | # undef istringstream 34 | # define istringstream istrstream 35 | #endif 36 | 37 | #if defined(HAVE_STRINGS_H) 38 | # include 39 | #endif 40 | 41 | #if defined(HAVE_STRCASECMP) 42 | # define MYSTRICMP strcasecmp 43 | #else 44 | # define MYSTRICMP stricmp 45 | #endif 46 | 47 | #if defined(HAVE_STRNCASECMP) 48 | # define MYSTRNICMP strncasecmp 49 | #else 50 | # define MYSTRNICMP strnicmp 51 | #endif 52 | 53 | class SidTuneTools 54 | { 55 | public: 56 | 57 | // Wrapper for ``strnicmp'' without third argument. 58 | static int myStrNcaseCmp(const char* s1, const char* s2) 59 | { 60 | return MYSTRNICMP(s1,s2,strlen(s2)); 61 | } 62 | 63 | // Own version of strdup, which uses new instead of malloc. 64 | static char* myStrDup(const char *source); 65 | 66 | // Return pointer to file name position in complete path. 67 | static char* fileNameWithoutPath(char* s); 68 | 69 | // Return pointer to file name position in complete path. 70 | // Special version: file separator = forward slash. 71 | static char* slashedFileNameWithoutPath(char* s); 72 | 73 | // Return pointer to file name extension in path. 74 | // Searching backwards until first dot is found. 75 | static char* fileExtOfPath(char* s); 76 | 77 | // Parse input string stream. Read and convert a hexa-decimal number up 78 | // to a ``,'' or ``:'' or ``\0'' or end of stream. 79 | static uint_least32_t readHex(std::istringstream& parseStream); 80 | 81 | // Parse input string stream. Read and convert a decimal number up 82 | // to a ``,'' or ``:'' or ``\0'' or end of stream. 83 | static uint_least32_t readDec(std::istringstream& parseStream); 84 | 85 | // Search terminated string for next newline sequence. 86 | // Skip it and return pointer to start of next line. 87 | static const char* returnNextLine(const char* s, uint_least32_t len); 88 | 89 | // Skip any characters in an input string stream up to '='. 90 | static void skipToEqu(std::istringstream& parseStream); 91 | 92 | // Start at first character behind '=' and copy rest of string. 93 | static void copyStringValueToEOL(const char* pSourceStr, char* pDestStr, int destMaxLen); 94 | }; 95 | 96 | #endif /* TOOLS_H */ 97 | -------------------------------------------------------------------------------- /src/libpsid64/psiddrv.h: -------------------------------------------------------------------------------- 1 | 0x01,0x00,0x6f,0x36,0x35,0x00,0x03,0x10,0x00,0x10,0xf3,0x01,0x00,0x04,0x00,0x00, 2 | 0x00,0x40,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x0e,0x00,0x70,0x73,0x69,0x64, 3 | 0x64,0x72,0x76,0x2e,0x6f,0x36,0x35,0x00,0x1c,0x03,0x44,0x61,0x67,0x20,0x4c,0x65, 4 | 0x6d,0x20,0x3c,0x72,0x65,0x73,0x69,0x64,0x40,0x6e,0x69,0x6d,0x72,0x6f,0x64,0x2e, 5 | 0x6e,0x6f,0x3e,0x00,0x00,0x4c,0x53,0x10,0x4c,0xfd,0x10,0x60,0x00,0x00,0x60,0x00, 6 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x4a,0x10,0x0d,0x11, 7 | 0x52,0x10,0xad,0x00,0xdc,0x48,0xa5,0x01,0x48,0xad,0x13,0x10,0x85,0x01,0xa9,0x00, 8 | 0x20,0x09,0x10,0x68,0x85,0x01,0xa9,0x7f,0x8d,0x00,0xdc,0xad,0x01,0xdc,0x29,0x02, 9 | 0xd0,0x03,0x4c,0x21,0x10,0x68,0x8d,0x00,0xdc,0xad,0x19,0xd0,0x8d,0x19,0xd0,0xad, 10 | 0x0d,0xdc,0x68,0xa8,0x68,0xaa,0x68,0x40,0x68,0x8d,0x16,0x10,0x68,0x8d,0x15,0x10, 11 | 0x68,0x8d,0x14,0x10,0x78,0xd8,0xa2,0xff,0x9a,0xa5,0x01,0x29,0x03,0xd0,0x02,0xa9, 12 | 0x01,0x09,0x34,0x85,0x01,0x20,0x1d,0x11,0xae,0x11,0x10,0x30,0x09,0xbd,0x17,0x10, 13 | 0x9d,0x14,0x03,0xca,0x10,0xf7,0xa9,0x0b,0xa2,0x00,0x8d,0x11,0xd0,0x8e,0x12,0xd0, 14 | 0xad,0x15,0x10,0xf0,0x06,0xa9,0x25,0xa2,0x40,0xd0,0x04,0xa9,0x95,0xa2,0x42,0x8d, 15 | 0x04,0xdc,0x8e,0x05,0xdc,0xac,0x14,0x10,0xcc,0x0c,0x10,0x90,0x02,0xa0,0x00,0x98, 16 | 0x48,0xad,0x12,0x10,0xf0,0x1e,0xc0,0x20,0x90,0x02,0xa0,0x1f,0xa9,0x00,0xaa,0x38, 17 | 0x2a,0x90,0x02,0x2a,0xe8,0x88,0x10,0xf8,0x3d,0x0d,0x10,0xd0,0x07,0xa9,0x81,0x8d, 18 | 0x1a,0xd0,0xd0,0x05,0xa9,0x81,0x8d,0x0d,0xdc,0xa9,0x01,0x8d,0x0e,0xdc,0xad,0x13, 19 | 0x10,0xf0,0x05,0xa9,0x1d,0x8d,0x14,0x03,0xa9,0x2f,0x85,0x00,0xad,0x12,0x10,0xd0, 20 | 0x03,0xa9,0x37,0x58,0x85,0x01,0x68,0xae,0x16,0x10,0xa0,0x00,0xca,0xd0,0xfb,0x20, 21 | 0x06,0x10,0xad,0x12,0x10,0xf0,0x0f,0xad,0x13,0x10,0xf0,0x09,0xa9,0x37,0x85,0x01, 22 | 0xd0,0x03,0xa2,0xff,0x9a,0x58,0x20,0x5f,0x11,0x08,0x78,0x20,0x68,0x11,0x28,0x4c, 23 | 0x11,0x11,0xa2,0x00,0x8e,0x1a,0xd0,0xad,0x19,0xd0,0x8d,0x19,0xd0,0xa9,0x7f,0x8d, 24 | 0x0d,0xdc,0x8d,0x0d,0xdd,0xad,0x0d,0xdc,0xad,0x0d,0xdd,0xa9,0x08,0x8d,0x0e,0xdc, 25 | 0x8d,0x0e,0xdd,0x8d,0x0f,0xdc,0x8d,0x0f,0xdd,0x8d,0x04,0xd4,0x8d,0x0b,0xd4,0x8d, 26 | 0x12,0xd4,0x8a,0xa2,0x17,0x9d,0x00,0xd4,0x9d,0x00,0x00,0xca,0x10,0xf7,0xa9,0x0f, 27 | 0x8d,0x18,0xd4,0x60,0xa2,0x0e,0x88,0xd0,0xfd,0xca,0xd0,0xfa,0x60,0xae,0xa8,0x11, 28 | 0x30,0x0e,0xbd,0xa9,0x11,0x8d,0x00,0xdc,0xad,0x01,0xdc,0x3d,0xce,0x11,0xf0,0x1e, 29 | 0xad,0x0c,0x10,0xc9,0x25,0x90,0x02,0xa9,0x24,0xaa,0xbd,0xa9,0x11,0x8d,0x00,0xdc, 30 | 0xad,0x01,0xdc,0x3d,0xce,0x11,0xf0,0x07,0xca,0x10,0xef,0x8e,0xa8,0x11,0x60,0x8e, 31 | 0xa8,0x11,0x8a,0xd0,0x03,0x4c,0x1d,0x11,0xca,0x8a,0x4c,0x5c,0x10,0xff,0x7f,0x7f, 32 | 0x7f,0xfd,0xfd,0xfb,0xfb,0xf7,0xf7,0xef,0xef,0xfd,0xf7,0xfb,0xfb,0xfd,0xfb,0xf7, 33 | 0xf7,0xef,0xef,0xef,0xdf,0xef,0xef,0xef,0xdf,0x7f,0xfb,0xfd,0xfb,0xf7,0xf7,0xfd, 34 | 0xfb,0xf7,0xfd,0x80,0x01,0x08,0x01,0x08,0x01,0x08,0x01,0x08,0x01,0x08,0x04,0x10, 35 | 0x10,0x04,0x40,0x20,0x04,0x20,0x02,0x04,0x20,0x04,0x10,0x80,0x40,0x02,0x40,0x02, 36 | 0x20,0x40,0x40,0x80,0x02,0x80,0x02,0x10,0x01,0x00,0x73,0x69,0x64,0x32,0x62,0x61, 37 | 0x73,0x65,0x00,0x02,0x82,0x03,0x82,0x13,0x82,0x02,0x82,0x02,0x82,0x0a,0x82,0x07, 38 | 0x82,0x12,0x82,0x17,0x82,0x04,0x82,0x04,0x82,0x14,0x82,0x03,0x82,0x05,0x82,0x13, 39 | 0x82,0x15,0x82,0x03,0x82,0x09,0x82,0x17,0x82,0x16,0x82,0x05,0x22,0x09,0x82,0x0b, 40 | 0x82,0x08,0x82,0x03,0x82,0x05,0x82,0x0f,0x82,0x05,0x82,0x04,0x82,0x39,0x80,0x00, 41 | 0x00,0x15,0x82,0x05,0x82,0x09,0x82,0x05,0x82,0x0a,0x82,0x09,0x82,0x08,0x82,0x04, 42 | 0x82,0x06,0x82,0x05,0x82,0x00,0x00,0x00,0x00, 43 | -------------------------------------------------------------------------------- /include/sidplay/Buffer.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | * /home/ms/files/source/libsidtune/RCS/Buffer.h,v 4 | * 5 | * Copyright (C) Michael Schwendt 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | */ 21 | 22 | #ifndef BUFFER_H 23 | #define BUFFER_H 24 | 25 | #include 26 | #include "sidtypes.h" 27 | 28 | template class Buffer_sidtt 29 | { 30 | public: 31 | Buffer_sidtt(void) : dummy(0) 32 | { 33 | kill(); 34 | } 35 | 36 | Buffer_sidtt(T* inBuf, uint_least32_t inLen) : dummy(0) 37 | { 38 | kill(); 39 | if (inBuf!=0 && inLen!=0) 40 | { 41 | buf = inBuf; 42 | bufLen = inLen; 43 | } 44 | } 45 | 46 | bool assign(T* newBuf, uint_least32_t newLen) 47 | { 48 | erase(); 49 | buf = newBuf; 50 | bufLen = newLen; 51 | return (buf!=0); 52 | } 53 | 54 | T* get(void) const { return buf; } 55 | uint_least32_t len(void) const { return bufLen; } 56 | 57 | T* xferPtr(void) 58 | { 59 | T* tmpBuf = buf; 60 | buf = 0; 61 | return tmpBuf; 62 | } 63 | 64 | uint_least32_t xferLen(void) 65 | { 66 | uint_least32_t tmpBufLen = bufLen; 67 | bufLen = 0; 68 | return tmpBufLen; 69 | } 70 | 71 | T& operator[](uint_least32_t index) 72 | { 73 | if (index < bufLen) 74 | return buf[index]; 75 | else 76 | return dummy; 77 | } 78 | 79 | bool isEmpty(void) const { return (buf==0); } 80 | 81 | void erase(void) 82 | { 83 | if (buf!=0 && bufLen!=0) 84 | { 85 | #ifndef SID_HAVE_BAD_COMPILER 86 | delete[] buf; 87 | #else 88 | delete[] (void *) buf; 89 | #endif 90 | } 91 | kill(); 92 | } 93 | 94 | ~Buffer_sidtt(void) 95 | { 96 | erase(); 97 | } 98 | 99 | private: 100 | T* buf; 101 | uint_least32_t bufLen; 102 | T dummy; 103 | 104 | void kill(void) 105 | { 106 | buf = 0; 107 | bufLen = 0; 108 | } 109 | 110 | private: // prevent copying 111 | Buffer_sidtt(const Buffer_sidtt&); 112 | Buffer_sidtt& operator=(Buffer_sidtt& b); 113 | }; 114 | 115 | #endif /* BUFFER_H */ 116 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | PSID64 NEWS 2 | =========== 3 | 4 | 2023-08-03: PSID64 1.3 5 | ---------------------- 6 | * Added support for new song length file format. 7 | * Use Songlengths.md5 default filename when HVSC root directory is specified. 8 | * When converting a directory to a specified output directory, use a trailing 9 | slash or backslash to never append the basename to the output directory. 10 | * Avoid grey dot artifacts on 8565 VIC-II. 11 | * Fixed missing argument in --root command line option description. 12 | * Added more extensive usage description and examples to README. 13 | 14 | 2016-01-23: PSID64 1.2 15 | ---------------------- 16 | * Added PSID/RSID v4 support (Triple SID). 17 | * Added support for player identification based on SID ID. 18 | * More verbose error messages in console application. 19 | * Fixed issue with non-bitwise moveable objects. 20 | 21 | 2015-06-07: PSID64 1.1 22 | ---------------------- 23 | * Added song length and progress bar support. 24 | * Accept directory as input and/or output path. 25 | * Use song length database from HVSC directory if no database was specified. 26 | * Added -t option to specify a driver theme. 27 | 28 | 2014-08-30: PSID64 1.0 29 | ---------------------- 30 | * Added -n option to convert a SID without including driver code ("sid2prg"). 31 | * Reduced footprint of extended driver in case character ROM must be copied. 32 | * Fixed compression issue on Raspberry Pi. 33 | * Prebuilt binary for 32-bit and 64-bit Windows available. 34 | * When applicable initialize the second SID. 35 | 36 | 2011-12-23: PSID64 0.9 37 | ---------------------- 38 | * Added support for PSID/RSID v3 formats. 39 | * When applicable display info for second SID. 40 | * Prebuilt binary for OS X (Lion) available. 41 | 42 | 2007-02-24: PSID64 0.8 43 | ---------------------- 44 | * Built-in support for Exomizer. 45 | * Added support for a joystick in port two to control the player. 46 | * Added clock to indicated running time. 47 | * Added -i option to override the initial song to play. 48 | * Added support for SID tunes written in BASIC. 49 | 50 | 2005-05-05: PSID64 0.7 51 | ---------------------- 52 | * Improved RSID compatibility. 53 | * Use INST/DEL to toggle screen on and off. 54 | * Use + and - keys to select next and previous song respectively. 55 | * Display the song number of song currently being played. 56 | * Show all 31 characters of the PSID header. 57 | * Fixed NMI bank register bug. 58 | * Pass default song number via boot loader. 59 | 60 | 2003-04-22: PSID64 0.6 61 | ---------------------- 62 | * Ported all code to C++. 63 | * Created the libpsid64 library. 64 | * Fixed some small incompatibility problems. 65 | 66 | 2002-11-07: PSID64 0.5 67 | ---------------------- 68 | * Added preliminary support of RSID format. 69 | * Implemented screen blanking to improve audio quality when using the RF 70 | modulated output of your C64. 71 | * Implemented feature request 534453: handle init functions that jump to $A7AE. 72 | * Extended information line area: show the intended SID model and video mode. 73 | * Updated source code to automake 1.6.3 and gcc 3.2. 74 | 75 | 2002-03-24: PSID64 0.4 76 | ---------------------- 77 | * Display STIL information if available. 78 | * Fixed a number of potential problems related to the bank selection register. 79 | 80 | 2001-11-11: PSID64 0.3 81 | ---------------------- 82 | * Fixed a classic bug in release 0.2. On Windows machines without Cygwin 83 | installed, all files are treated as text files by default. This results in 84 | corrupt program files where a carriage return character is inserted before 85 | each new line character. 86 | 87 | 2001-11-10: PSID64 0.2 88 | ---------------------- 89 | * Ported to Windows/Cygwin platform. 90 | * Supports screens located in the memory ranges $4000-$8000 and $c000-$d000. 91 | * Supports long option formats on systems with getopt_long(). 92 | * Possible to specify multiple PSID files to be converted on the command line. 93 | 94 | 2001-09-08: PSID64 0.1 95 | ---------------------- 96 | * Initial release. 97 | -------------------------------------------------------------------------------- /src/libpsid64/exomizer/search.h: -------------------------------------------------------------------------------- 1 | #ifndef ALREADY_INCLUDED_SEARCH_H 2 | #define ALREADY_INCLUDED_SEARCH_H 3 | 4 | /* 5 | * Copyright (c) 2002, 2003 Magnus Lind. 6 | * 7 | * This software is provided 'as-is', without any express or implied warranty. 8 | * In no event will the authors be held liable for any damages arising from 9 | * the use of this software. 10 | * 11 | * Permission is granted to anyone to use this software, alter it and re- 12 | * distribute it freely for any non-commercial, non-profit purpose subject to 13 | * the following restrictions: 14 | * 15 | * 1. The origin of this software must not be misrepresented; you must not 16 | * claim that you wrote the original software. If you use this software in a 17 | * product, an acknowledgment in the product documentation would be 18 | * appreciated but is not required. 19 | * 20 | * 2. Altered source versions must be plainly marked as such, and must not 21 | * be misrepresented as being the original software. 22 | * 23 | * 3. This notice may not be removed or altered from any distribution. 24 | * 25 | * 4. The names of this software and/or it's copyright holders may not be 26 | * used to endorse or promote products derived from this software without 27 | * specific prior written permission. 28 | * 29 | */ 30 | 31 | #include "match.h" 32 | #include "output.h" 33 | 34 | struct _search_node { 35 | int index; 36 | match match; 37 | float match_score; 38 | float total_score; 39 | struct _search_node *prev; 40 | }; 41 | 42 | typedef struct _search_node search_node[1]; 43 | typedef struct _search_node *search_nodep; 44 | typedef const struct _search_node *const_search_nodep; 45 | 46 | struct _encode_match_data { 47 | output_ctxp out; 48 | void *priv; 49 | }; 50 | 51 | typedef struct _encode_match_data encode_match_data[1]; 52 | typedef struct _encode_match_data *encode_match_datap; 53 | 54 | /* example of what may be used for priv data 55 | * field in the encode_match_data struct */ 56 | typedef 57 | float encode_int_f(int val, void *priv, output_ctxp out); /* IN */ 58 | 59 | struct _encode_match_priv { 60 | int lit_num; 61 | int seq_num; 62 | int rle_num; 63 | float lit_bits; 64 | float seq_bits; 65 | float rle_bits; 66 | 67 | encode_int_f *offset_f; 68 | encode_int_f *len_f; 69 | void *offset_f_priv; 70 | void *len_f_priv; 71 | 72 | output_ctxp out; 73 | }; 74 | 75 | typedef struct _encode_match_priv encode_match_priv[1]; 76 | typedef struct _encode_match_priv *encode_match_privp; 77 | /* end of example */ 78 | 79 | typedef 80 | float encode_match_f(const_matchp mp, encode_match_data emd); /* IN */ 81 | 82 | void search_node_dump(search_nodep snp); /* IN */ 83 | 84 | void search_node_free(search_nodep snp); /* IN/OUT */ 85 | 86 | search_nodep search_buffer(match_ctx ctx, /* IN */ 87 | encode_match_f * f, /* IN */ 88 | encode_match_data emd); /* IN */ 89 | 90 | struct _matchp_snp_enum { 91 | const_search_nodep startp; 92 | const_search_nodep currp; 93 | }; 94 | 95 | typedef struct _matchp_snp_enum matchp_snp_enum[1]; 96 | typedef struct _matchp_snp_enum *matchp_snp_enump; 97 | 98 | void matchp_snp_get_enum(const_search_nodep snp, /* IN */ 99 | matchp_snp_enum snpe); /* IN/OUT */ 100 | 101 | const_matchp matchp_snp_enum_get_next(void *matchp_snp_enum); 102 | 103 | 104 | struct _matchp_snp_rle_enum { 105 | const_search_nodep startp; 106 | const_search_nodep currp; 107 | const_search_nodep lastp; 108 | match m; 109 | }; 110 | 111 | typedef struct _matchp_snp_rle_enum matchp_snp_rle_enum[1]; 112 | typedef struct _matchp_snp_rle_enum *matchp_snp_rle_enump; 113 | 114 | void matchp_snp_rle_get_enum(const_search_nodep snp, /* IN */ 115 | matchp_snp_rle_enum snpe); /* IN/OUT */ 116 | 117 | const_matchp matchp_snp_rle_enum_get_next(void *matchp_snp_enum); 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /src/libpsid64/screen.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | psid64 - create a C64 executable from a PSID file 4 | Copyright (C) 2001-2023 Roland Hermans 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | ////////////////////////////////////////////////////////////////////////////// 22 | // I N C L U D E S 23 | ////////////////////////////////////////////////////////////////////////////// 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "screen.h" 31 | 32 | 33 | ////////////////////////////////////////////////////////////////////////////// 34 | // G L O B A L D A T A 35 | ////////////////////////////////////////////////////////////////////////////// 36 | 37 | 38 | ////////////////////////////////////////////////////////////////////////////// 39 | // L O C A L D E F I N I T I O N S 40 | ////////////////////////////////////////////////////////////////////////////// 41 | 42 | 43 | ////////////////////////////////////////////////////////////////////////////// 44 | // L O C A L D A T A 45 | ////////////////////////////////////////////////////////////////////////////// 46 | 47 | 48 | ////////////////////////////////////////////////////////////////////////////// 49 | // L O C A L F U N C T I O N S 50 | ////////////////////////////////////////////////////////////////////////////// 51 | 52 | 53 | ////////////////////////////////////////////////////////////////////////////// 54 | // G L O B A L F U N C T I O N S 55 | ////////////////////////////////////////////////////////////////////////////// 56 | 57 | // constructor 58 | 59 | Screen::Screen() : 60 | m_x(0), 61 | m_y(0) 62 | { 63 | clear(); 64 | } 65 | 66 | 67 | // destructor 68 | 69 | Screen::~Screen() 70 | { 71 | } 72 | 73 | 74 | // public member functions 75 | 76 | void Screen::clear() 77 | { 78 | uint_least8_t c = iso2scr(' '); 79 | for (unsigned int i = 0; i < m_screenSize; ++i) 80 | { 81 | m_screen[i] = c; 82 | } 83 | } 84 | 85 | 86 | void Screen::moveTo(unsigned int x, unsigned int y) 87 | { 88 | if ((x < m_width) && (y < m_height)) 89 | { 90 | m_x = x; 91 | m_y = y; 92 | } 93 | } 94 | 95 | 96 | void Screen::putchar(char c) 97 | { 98 | if (c == '\n') 99 | { 100 | m_x = 0; 101 | moveDown(); 102 | } 103 | else 104 | { 105 | unsigned int offs = offset(m_x, m_y); 106 | m_screen[offs] = iso2scr((uint_least8_t) c); 107 | moveRight(); 108 | } 109 | } 110 | 111 | 112 | void Screen::write(const char *str) 113 | { 114 | while (*str) 115 | { 116 | putchar(*str); 117 | ++str; 118 | } 119 | } 120 | 121 | 122 | void Screen::poke(unsigned int x, unsigned int y, uint_least8_t value) 123 | { 124 | if ((x < m_width) && (y < m_height)) 125 | { 126 | unsigned int offs = offset(x, y); 127 | m_screen[offs] = value; 128 | } 129 | } 130 | 131 | 132 | void Screen::poke(unsigned int offs, uint_least8_t value) 133 | { 134 | if (offs < m_screenSize) 135 | { 136 | m_screen[offs] = value; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/sidutils/SidTuneMod.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | * This program is free software; you can redistribute it and/or modify 4 | * it under the terms of the GNU General Public License as published by 5 | * the Free Software Foundation; either version 2 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | */ 17 | 18 | #include 19 | #include 20 | #include "config.h" 21 | #include "SidTuneMod.h" 22 | #include "MD5/MD5.h" 23 | 24 | const char *SidTuneMod::createMD5(char *md5) 25 | { 26 | if (!md5) 27 | md5 = m_md5; 28 | *md5 = '\0'; 29 | 30 | if (status) 31 | { // Include C64 data. 32 | MD5 myMD5; 33 | md5_byte_t tmp[2]; 34 | myMD5.append (cache.get()+fileOffset,info.c64dataLen); 35 | // Include INIT and PLAY address. 36 | endian_little16 (tmp,info.initAddr); 37 | myMD5.append (tmp,sizeof(tmp)); 38 | endian_little16 (tmp,info.playAddr); 39 | myMD5.append (tmp,sizeof(tmp)); 40 | // Include number of songs. 41 | endian_little16 (tmp,info.songs); 42 | myMD5.append (tmp,sizeof(tmp)); 43 | { // Include song speed for each song. 44 | uint_least16_t currentSong = info.currentSong; 45 | for (uint_least16_t s = 1; s <= info.songs; s++) 46 | { 47 | selectSong (s); 48 | myMD5.append (&info.songSpeed,sizeof(info.songSpeed)); 49 | } 50 | // Restore old song 51 | selectSong (currentSong); 52 | } 53 | // Deal with PSID v2NG clock speed flags: Let only NTSC 54 | // clock speed change the MD5 fingerprint. That way the 55 | // fingerprint of a PAL-speed sidtune in PSID v1, v2, and 56 | // PSID v2NG format is the same. 57 | if (info.clockSpeed == SIDTUNE_CLOCK_NTSC) 58 | myMD5.append (&info.clockSpeed,sizeof(info.clockSpeed)); 59 | // NB! If the fingerprint is used as an index into a 60 | // song-lengths database or cache, modify above code to 61 | // allow for PSID v2NG files which have clock speed set to 62 | // SIDTUNE_CLOCK_ANY. If the SID player program fully 63 | // supports the SIDTUNE_CLOCK_ANY setting, a sidtune could 64 | // either create two different fingerprints depending on 65 | // the clock speed chosen by the player, or there could be 66 | // two different values stored in the database/cache. 67 | 68 | myMD5.finish(); 69 | // Construct fingerprint. 70 | char *m = md5; 71 | for (int di = 0; di < 16; ++di) 72 | { 73 | #ifdef HAVE_SNPRINTF 74 | snprintf (m, 3, "%02x", (int) myMD5.getDigest()[di]); 75 | #else 76 | sprintf (m, "%02x", (int) myMD5.getDigest()[di]); 77 | #endif 78 | m += 2; 79 | } 80 | } 81 | return md5; 82 | } 83 | 84 | const char *SidTuneMod::createNewMD5(char *md5) 85 | { 86 | if (!md5) 87 | md5 = m_md5; 88 | *md5 = '\0'; 89 | 90 | if (status) 91 | { 92 | MD5 myMD5; 93 | myMD5.append (cache.get(),cache.len()); 94 | myMD5.finish(); 95 | // Construct fingerprint. 96 | char *m = md5; 97 | for (int di = 0; di < 16; ++di) 98 | { 99 | #ifdef HAVE_SNPRINTF 100 | snprintf (m, 3, "%02x", (int) myMD5.getDigest()[di]); 101 | #else 102 | sprintf (m, "%02x", (int) myMD5.getDigest()[di]); 103 | #endif 104 | m += 2; 105 | } 106 | } 107 | return md5; 108 | } 109 | -------------------------------------------------------------------------------- /macros/ax_func_mkdir.m4: -------------------------------------------------------------------------------- 1 | dnl SPDX-License-Identifier: GPL-2.0-or-later WITH Autoconf-exception-macro 2 | dnl 3 | # =========================================================================== 4 | # https://www.gnu.org/software/autoconf-archive/ax_func_mkdir.html 5 | # =========================================================================== 6 | # 7 | # SYNOPSIS 8 | # 9 | # AX_FUNC_MKDIR 10 | # 11 | # DESCRIPTION 12 | # 13 | # Check whether mkdir() is mkdir or _mkdir, and whether it takes one or 14 | # two arguments. 15 | # 16 | # This macro can define HAVE_MKDIR, HAVE__MKDIR, and MKDIR_TAKES_ONE_ARG, 17 | # which are expected to be used as follows: 18 | # 19 | # #if HAVE_MKDIR 20 | # # if MKDIR_TAKES_ONE_ARG 21 | # /* MinGW32 */ 22 | # # define mkdir(a, b) mkdir(a) 23 | # # endif 24 | # #else 25 | # # if HAVE__MKDIR 26 | # /* plain Windows 32 */ 27 | # # define mkdir(a, b) _mkdir(a) 28 | # # else 29 | # # error "Don't know how to create a directory on this system." 30 | # # endif 31 | # #endif 32 | # 33 | # LICENSE 34 | # 35 | # Copyright (c) 2008 Alexandre Duret-Lutz 36 | # 37 | # This program is free software; you can redistribute it and/or modify it 38 | # under the terms of the GNU General Public License as published by the 39 | # Free Software Foundation; either version 2 of the License, or (at your 40 | # option) any later version. 41 | # 42 | # This program is distributed in the hope that it will be useful, but 43 | # WITHOUT ANY WARRANTY; without even the implied warranty of 44 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 45 | # Public License for more details. 46 | # 47 | # You should have received a copy of the GNU General Public License along 48 | # with this program. If not, see . 49 | # 50 | # As a special exception, the respective Autoconf Macro's copyright owner 51 | # gives unlimited permission to copy, distribute and modify the configure 52 | # scripts that are the output of Autoconf when processing the Macro. You 53 | # need not follow the terms of the GNU General Public License when using 54 | # or distributing such scripts, even though portions of the text of the 55 | # Macro appear in them. The GNU General Public License (GPL) does govern 56 | # all other use of the material that constitutes the Autoconf Macro. 57 | # 58 | # This special exception to the GPL applies to versions of the Autoconf 59 | # Macro released by the Autoconf Archive. When you make and distribute a 60 | # modified version of the Autoconf Macro, you may extend this special 61 | # exception to the GPL to apply to your modified version as well. 62 | 63 | #serial 6 64 | 65 | AU_ALIAS([AC_FUNC_MKDIR], [AX_FUNC_MKDIR]) 66 | AC_DEFUN([AX_FUNC_MKDIR], 67 | [AC_CHECK_FUNCS([mkdir _mkdir]) 68 | AC_CACHE_CHECK([whether mkdir takes one argument], 69 | [ac_cv_mkdir_takes_one_arg], 70 | [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 71 | #include 72 | #if HAVE_UNISTD_H 73 | # include 74 | #endif 75 | ]], [[mkdir (".");]])], 76 | [ac_cv_mkdir_takes_one_arg=yes], [ac_cv_mkdir_takes_one_arg=no])]) 77 | if test x"$ac_cv_mkdir_takes_one_arg" = xyes; then 78 | AC_DEFINE([MKDIR_TAKES_ONE_ARG], 1, 79 | [Define if mkdir takes only one argument.]) 80 | fi 81 | ]) 82 | 83 | dnl Note: 84 | dnl ===== 85 | dnl I have not implemented the following suggestion because I don't have 86 | dnl access to such a broken environment to test the macro. So I'm just 87 | dnl appending the comments here in case you have, and want to fix 88 | dnl AX_FUNC_MKDIR that way. 89 | dnl 90 | dnl |Thomas E. Dickey (dickey@herndon4.his.com) said: 91 | dnl | it doesn't cover the problem areas (compilers that mistreat mkdir 92 | dnl | may prototype it in dir.h and dirent.h, for instance). 93 | dnl | 94 | dnl |Alexandre: 95 | dnl | Would it be sufficient to check for these headers and #include 96 | dnl | them in the AC_COMPILE_IFELSE block? (and is AC_HEADER_DIRENT 97 | dnl | suitable for this?) 98 | dnl | 99 | dnl |Thomas: 100 | dnl | I think that might be a good starting point (with the set of recommended 101 | dnl | ifdef's and includes for AC_HEADER_DIRENT, of course). 102 | -------------------------------------------------------------------------------- /src/sidutils/MD5/MD5.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Zlib 2 | /* 3 | * This code has been derived by Michael Schwendt 4 | * from original work by L. Peter Deutsch . 5 | * 6 | * The original C code (md5.c, md5.h) is available here: 7 | * ftp://ftp.cs.wisc.edu/ghost/packages/md5.tar.gz 8 | */ 9 | 10 | /* 11 | Copyright (C) 1999 Aladdin Enterprises. All rights reserved. 12 | 13 | This software is provided 'as-is', without any express or implied 14 | warranty. In no event will the authors be held liable for any damages 15 | arising from the use of this software. 16 | 17 | Permission is granted to anyone to use this software for any purpose, 18 | including commercial applications, and to alter it and redistribute it 19 | freely, subject to the following restrictions: 20 | 21 | 1. The origin of this software must not be misrepresented; you must not 22 | claim that you wrote the original software. If you use this software 23 | in a product, an acknowledgment in the product documentation would be 24 | appreciated but is not required. 25 | 2. Altered source versions must be plainly marked as such, and must not be 26 | misrepresented as being the original software. 27 | 3. This notice may not be removed or altered from any source distribution. 28 | 29 | L. Peter Deutsch 30 | ghost@aladdin.com 31 | */ 32 | 33 | #ifndef MD5_H 34 | #define MD5_H 35 | 36 | #include "MD5_Defs.h" 37 | 38 | typedef unsigned char md5_byte_t; // 8-bit byte 39 | typedef unsigned int md5_word_t; // 32-bit word 40 | 41 | class MD5 42 | { 43 | public: 44 | // Initialize the algorithm. Reset starting values. 45 | MD5(); 46 | 47 | // Append a string to the message. 48 | void append(const void* data, int nbytes); 49 | 50 | // Finish the message. 51 | void finish(); 52 | 53 | // Return pointer to 16-byte fingerprint. 54 | const md5_byte_t* getDigest(); 55 | 56 | // Initialize the algorithm. Reset starting values. 57 | void reset(); 58 | 59 | private: 60 | 61 | /* Define the state of the MD5 Algorithm. */ 62 | md5_word_t count[2]; /* message length in bits, lsw first */ 63 | md5_word_t abcd[4]; /* digest buffer */ 64 | md5_byte_t buf[64]; /* accumulate block */ 65 | 66 | md5_byte_t digest[16]; 67 | 68 | md5_word_t tmpBuf[16]; 69 | const md5_word_t* X; 70 | 71 | void 72 | process(const md5_byte_t data[64]); 73 | 74 | md5_word_t 75 | ROTATE_LEFT(const md5_word_t x, const int n); 76 | 77 | md5_word_t 78 | F(const md5_word_t x, const md5_word_t y, const md5_word_t z); 79 | 80 | md5_word_t 81 | G(const md5_word_t x, const md5_word_t y, const md5_word_t z); 82 | 83 | md5_word_t 84 | H(const md5_word_t x, const md5_word_t y, const md5_word_t z); 85 | 86 | md5_word_t 87 | I(const md5_word_t x, const md5_word_t y, const md5_word_t z); 88 | 89 | typedef md5_word_t (MD5::*md5func)(const md5_word_t x, const md5_word_t y, const md5_word_t z); 90 | 91 | void 92 | SET(md5func func, md5_word_t& a, const md5_word_t& b, const md5_word_t& c, 93 | const md5_word_t& d, const int k, const int s, 94 | const md5_word_t Ti); 95 | }; 96 | 97 | inline md5_word_t 98 | MD5::ROTATE_LEFT(const md5_word_t x, const int n) 99 | { 100 | return ( (x<>(32-n)) ); 101 | } 102 | 103 | inline md5_word_t 104 | MD5::F(const md5_word_t x, const md5_word_t y, const md5_word_t z) 105 | { 106 | return ( (x&y) | (~x&z) ); 107 | } 108 | 109 | inline md5_word_t 110 | MD5::G(const md5_word_t x, const md5_word_t y, const md5_word_t z) 111 | { 112 | return ( (x&z) | (y&~z) ); 113 | } 114 | 115 | inline md5_word_t 116 | MD5::H(const md5_word_t x, const md5_word_t y, const md5_word_t z) 117 | { 118 | return ( x^y^z ); 119 | } 120 | 121 | inline md5_word_t 122 | MD5::I(const md5_word_t x, const md5_word_t y, const md5_word_t z) 123 | { 124 | return ( y ^ (x|~z) ); 125 | } 126 | 127 | inline void 128 | MD5::SET(md5func func, md5_word_t& a, const md5_word_t& b, const md5_word_t& c, 129 | const md5_word_t& d, const int k, const int s, 130 | const md5_word_t Ti) 131 | { 132 | md5_word_t t = a + (this->*func)(b,c,d) + X[k] + Ti; 133 | a = ROTATE_LEFT(t, s) + b; 134 | } 135 | 136 | #endif /* MD5_H */ 137 | -------------------------------------------------------------------------------- /macros/sidtune.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([MY_SUBST_DEF], 2 | [ 3 | eval "$1=\"#define $1\"" 4 | AC_SUBST($1) 5 | ]) 6 | 7 | AC_DEFUN([MY_SUBST_UNDEF], 8 | [ 9 | eval "$1=\"#undef $1\"" 10 | AC_SUBST($1) 11 | ]) 12 | 13 | AC_DEFUN([MY_SUBST], 14 | [ 15 | eval "$1=$2" 16 | AC_SUBST($1) 17 | ]) 18 | 19 | 20 | 21 | 22 | 23 | dnl ------------------------------------------------------------------------- 24 | dnl Check whether compiler has a working ``bool'' type. 25 | dnl Will substitute @HAVE_BOOL@ with either a def or undef line. 26 | dnl ------------------------------------------------------------------------- 27 | 28 | AC_DEFUN([MY_CHECK_BOOL], 29 | [ 30 | AC_MSG_CHECKING([for bool]) 31 | AC_CACHE_VAL(test_cv_have_bool, 32 | [ 33 | AC_COMPILE_IFELSE( 34 | [AC_LANG_PROGRAM( 35 | [[]], 36 | [[bool aBool = true;]] 37 | )], 38 | [test_cv_have_bool=yes], 39 | [test_cv_have_bool=no] 40 | ) 41 | ]) 42 | AC_MSG_RESULT($test_cv_have_bool) 43 | if test "$test_cv_have_bool" = yes; then 44 | AC_DEFINE(HAVE_BOOL,,[Define if the C++ compiler supports BOOL]) 45 | fi 46 | ]) 47 | 48 | dnl ------------------------------------------------------------------------- 49 | dnl Check whether C++ library has member ios::bin instead of ios::binary. 50 | dnl Will substitute @HAVE_IOS_BIN@ with either a def or undef line. 51 | dnl ------------------------------------------------------------------------- 52 | 53 | AC_DEFUN([MY_CHECK_IOS_BIN], 54 | [ 55 | AC_MSG_CHECKING([whether standard member ios::binary is available]) 56 | AC_CACHE_VAL(test_cv_have_ios_binary, 57 | [ 58 | AC_COMPILE_IFELSE( 59 | [AC_LANG_PROGRAM( 60 | [[#include ]], 61 | [[std::ifstream myTest("",std::ios::in|std::ios::binary);]] 62 | )], 63 | [test_cv_have_ios_binary=yes], 64 | [test_cv_have_ios_binary=no] 65 | ) 66 | ]) 67 | AC_MSG_RESULT($test_cv_have_ios_binary) 68 | if test "$test_cv_have_ios_binary" = no; then 69 | AC_DEFINE(HAVE_IOS_BIN,, 70 | [Define if standard member ``ios::binary'' is called ``ios::bin''.] 71 | ) 72 | fi 73 | ]) 74 | 75 | dnl ------------------------------------------------------------------------- 76 | dnl Check whether C++ library has member ios::bin instead of ios::binary. 77 | dnl Will substitute @HAVE_IOS_OPENMODE@ with either a def or undef line. 78 | dnl ------------------------------------------------------------------------- 79 | 80 | AC_DEFUN([MY_CHECK_IOS_OPENMODE], 81 | [ 82 | AC_MSG_CHECKING([whether standard member ios::openmode is available]) 83 | AC_CACHE_VAL(test_cv_have_ios_openmode, 84 | [ 85 | AC_COMPILE_IFELSE( 86 | [AC_LANG_PROGRAM( 87 | [[#include 88 | #include ]], 89 | [[std::ios::openmode myTest = std::ios::in;]])], 90 | [test_cv_have_ios_openmode=yes], 91 | [test_cv_have_ios_openmode=no] 92 | ) 93 | ]) 94 | AC_MSG_RESULT($test_cv_have_ios_openmode) 95 | if test "$test_cv_have_ios_openmode" = yes; then 96 | AC_DEFINE(HAVE_IOS_OPENMODE,, 97 | [Define if ``ios::openmode'' is supported.] 98 | ) 99 | fi 100 | ]) 101 | 102 | dnl ------------------------------------------------------------------------- 103 | dnl Check whether C++ environment provides the "nothrow allocator". 104 | dnl Will substitute @HAVE_EXCEPTIONS@ if test code compiles. 105 | dnl ------------------------------------------------------------------------- 106 | 107 | AC_DEFUN([MY_CHECK_EXCEPTIONS], 108 | [ 109 | AC_MSG_CHECKING([whether exceptions are available]) 110 | AC_CACHE_VAL(test_cv_have_exceptions, 111 | [ 112 | AC_COMPILE_IFELSE( 113 | [AC_LANG_PROGRAM( 114 | [[#include ]], 115 | [[char* buf = std::new(nothrow) char[1024];]] 116 | )], 117 | [test_cv_have_exceptions=yes], 118 | [test_cv_have_exceptions=no] 119 | ) 120 | ]) 121 | AC_MSG_RESULT($test_cv_have_exceptions) 122 | if test "$test_cv_have_exceptions" = yes; then 123 | AC_DEFINE(HAVE_EXCEPTIONS,, 124 | [Define if your C++ compiler implements exception-handling.] 125 | ) 126 | fi 127 | ]) 128 | -------------------------------------------------------------------------------- /src/libpsid64/exomizer/log.h: -------------------------------------------------------------------------------- 1 | #ifndef ALREADY_INCLUDED_LOG_H 2 | #define ALREADY_INCLUDED_LOG_H 3 | /* 4 | * Copyright (c) 2002, 2003 Magnus Lind. 5 | * 6 | * This software is provided 'as-is', without any express or implied warranty. 7 | * In no event will the authors be held liable for any damages arising from 8 | * the use of this software. 9 | * 10 | * Permission is granted to anyone to use this software, alter it and re- 11 | * distribute it freely for any non-commercial, non-profit purpose subject to 12 | * the following restrictions: 13 | * 14 | * 1. The origin of this software must not be misrepresented; you must not 15 | * claim that you wrote the original software. If you use this software in a 16 | * product, an acknowledgment in the product documentation would be 17 | * appreciated but is not required. 18 | * 19 | * 2. Altered source versions must be plainly marked as such, and must not 20 | * be misrepresented as being the original software. 21 | * 22 | * 3. This notice may not be removed or altered from any distribution. 23 | * 24 | * 4. The names of this software and/or it's copyright holders may not be 25 | * used to endorse or promote products derived from this software without 26 | * specific prior written permission. 27 | * 28 | */ 29 | 30 | #if 0 /* RH */ 31 | #include 32 | #include 33 | #endif /* RH */ 34 | 35 | enum log_level { 36 | LOG_MIN = -99, 37 | LOG_FATAL = -40, 38 | LOG_ERROR = -30, 39 | LOG_WARNING = -20, 40 | LOG_BRIEF = -10, 41 | LOG_NORMAL = 0, 42 | LOG_VERBOSE = 10, 43 | LOG_TRACE = 20, 44 | LOG_DEBUG = 30, 45 | LOG_DUMP = 40, 46 | LOG_MAX = 99 47 | }; 48 | 49 | #if 0 /* RH */ 50 | typedef 51 | void log_formatter_f(FILE * out, /* IN */ 52 | enum log_level level, /* IN */ 53 | const char *context, /* IN */ 54 | const char *); /* IN */ 55 | 56 | /* 57 | * this log output function adds nothing 58 | */ 59 | void raw_log_formatter(FILE * out, /* IN */ 60 | enum log_level level, /* IN */ 61 | const char *context, /* IN */ 62 | const char *log); /* IN */ 63 | 64 | 65 | struct log_output; 66 | 67 | struct log_ctx; 68 | 69 | struct log_ctx *log_new(void); 70 | 71 | /* log_delete closes all added output streams 72 | * and files except for stdout and stderr 73 | */ 74 | void log_delete(struct log_ctx *ctx); 75 | 76 | void log_set_level(struct log_ctx *ctx, /* IN/OUT */ 77 | enum log_level level); /* IN */ 78 | 79 | void log_add_output_stream(struct log_ctx *ctx, /* IN/OUT */ 80 | enum log_level min, /* IN */ 81 | enum log_level max, /* IN */ 82 | log_formatter_f * default_f, /* IN */ 83 | FILE * out_stream); /* IN */ 84 | 85 | void log_vlog(struct log_ctx *ctx, /* IN */ 86 | enum log_level level, /* IN */ 87 | const char *context, /* IN */ 88 | log_formatter_f * f, /* IN */ 89 | const char *printf_str, /* IN */ 90 | va_list argp); 91 | 92 | 93 | void log_log_default(const char *printf_str, /* IN */ 94 | ...); 95 | 96 | /* some helper macros */ 97 | 98 | extern struct log_ctx *G_log_ctx; 99 | extern enum log_level G_log_level; 100 | extern enum log_level G_log_log_level; 101 | 102 | #define LOG_SET_LEVEL(L) \ 103 | do { \ 104 | log_set_level(G_log_ctx, (L)); \ 105 | G_log_level = (L); \ 106 | } while(0) 107 | 108 | #define LOG_INIT(L) \ 109 | do { \ 110 | G_log_ctx = log_new(); \ 111 | log_set_level(G_log_ctx, (L)); \ 112 | G_log_level = (L); \ 113 | } while(0) 114 | 115 | #define LOG_INIT_CONSOLE(X) \ 116 | do { \ 117 | G_log_ctx = log_new(); \ 118 | log_set_level(G_log_ctx, (X)); \ 119 | G_log_level = (X); \ 120 | log_add_output_stream(G_log_ctx, LOG_WARNING, LOG_MAX, NULL, stdout); \ 121 | log_add_output_stream(G_log_ctx, LOG_MIN, LOG_WARNING - 1, NULL, stderr); \ 122 | } while(0) 123 | 124 | #define LOG_FREE log_delete(G_log_ctx) 125 | 126 | #define LOG(L, M) \ 127 | do { \ 128 | if(G_log_level >= (L)) { \ 129 | G_log_log_level = (L); \ 130 | log_log_default M; \ 131 | } \ 132 | } while(0) 133 | 134 | #endif 135 | #endif /* RH */ 136 | 137 | /* RH: disable all logging */ 138 | #define LOG(L, M) 139 | -------------------------------------------------------------------------------- /src/libpsid64/psidextboot.h: -------------------------------------------------------------------------------- 1 | 0x01,0x00,0x6f,0x36,0x35,0x00,0x00,0x10,0x00,0x10,0x77,0x01,0x00,0x04,0x00,0x00, 2 | 0x00,0x40,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x0f,0x00,0x70,0x73,0x69,0x64, 3 | 0x62,0x6f,0x6f,0x74,0x2e,0x6f,0x36,0x35,0x00,0x31,0x03,0x52,0x6f,0x6c,0x61,0x6e, 4 | 0x64,0x20,0x48,0x65,0x72,0x6d,0x61,0x6e,0x73,0x20,0x3c,0x72,0x6f,0x6c,0x61,0x6e, 5 | 0x64,0x68,0x40,0x75,0x73,0x65,0x72,0x73,0x2e,0x73,0x6f,0x75,0x72,0x63,0x65,0x66, 6 | 0x6f,0x72,0x67,0x65,0x2e,0x6e,0x65,0x74,0x3e,0x00,0x00,0xa9,0x00,0x4c,0xaa,0x10, 7 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 8 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc6,0xf9,0xc6, 9 | 0xfb,0xb1,0xf8,0x91,0xfa,0xc8,0xd0,0xf9,0xc6,0xfc,0xd0,0xf1,0xa6,0xff,0xbd,0x00, 10 | 0x01,0x85,0xfa,0xbd,0x05,0x01,0x85,0xfb,0xa0,0x00,0xbd,0x0f,0x01,0xf0,0x11,0x85, 11 | 0xfc,0xb1,0xfd,0x91,0xfa,0xc8,0xd0,0xf9,0xe6,0xfe,0xe6,0xfb,0xc6,0xfc,0xd0,0xf1, 12 | 0xbd,0x0a,0x01,0xf0,0x15,0x85,0xfc,0xb1,0xfd,0x91,0xfa,0xc8,0xc4,0xfc,0xd0,0xf7, 13 | 0x98,0x18,0x65,0xfd,0x85,0xfd,0x90,0x02,0xe6,0xfe,0xca,0x10,0xc1,0xa5,0xf7,0xf0, 14 | 0x28,0x85,0xfb,0xa9,0xd8,0x85,0xfe,0xa0,0x00,0x84,0xfd,0x84,0xfa,0xa2,0x03,0xc6, 15 | 0x01,0xb1,0xfd,0x91,0xfa,0xc8,0xd0,0xf9,0xe6,0xfe,0xe6,0xfb,0xca,0x10,0xf2,0x8a, 16 | 0xc6,0xfb,0xa0,0xf8,0x91,0xfa,0xc8,0xd0,0xfb,0xa9,0x00,0x8d,0xf8,0x03,0xa9,0x37, 17 | 0x85,0x01,0x4c,0x00,0x00,0x78,0xa2,0xff,0x9a,0xd8,0x48,0xad,0xa6,0x02,0x29,0x01, 18 | 0x48,0xa5,0xa2,0x48,0xa9,0x37,0x85,0x01,0x20,0x84,0xff,0xa2,0x2e,0xbd,0x39,0x11, 19 | 0x9d,0xff,0xcf,0xca,0xd0,0xf7,0xa9,0x00,0x8d,0x00,0xdd,0xa9,0x00,0x9d,0x00,0xd8, 20 | 0x9d,0x00,0xd9,0x9d,0x00,0xda,0x9d,0x00,0xdb,0xe8,0xd0,0xf1,0xa2,0x1d,0xa9,0x00, 21 | 0x9d,0x2d,0xd8,0xca,0x10,0xfa,0xa2,0x0e,0xbd,0x68,0x11,0x9d,0x5c,0xd8,0xca,0x10, 22 | 0xf7,0xa0,0xf0,0xa2,0x27,0xa9,0x00,0xe0,0x07,0xf0,0x05,0xb0,0x05,0xa9,0x00,0x2c, 23 | 0xa9,0x00,0x88,0x99,0xa0,0xd8,0x99,0x40,0xd9,0xca,0x10,0xeb,0x98,0xd0,0xe4,0xa9, 24 | 0x00,0x99,0x58,0xda,0xc8,0xc0,0xa0,0xd0,0xf8,0xa9,0x34,0x85,0x01,0xa9,0x00,0x8d, 25 | 0x28,0x03,0xa9,0x00,0x8d,0x29,0x03,0xa0,0xa5,0xb9,0x04,0x10,0x99,0xf6,0x00,0x88, 26 | 0xd0,0xf7,0x4c,0x14,0x01,0x00,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 27 | 0x00,0x00,0x00,0x00,0x00,0x00,0x6b,0x37,0x00,0x00,0x01,0x08,0x00,0x00,0x0f,0x00, 28 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x00,0x00,0x02,0x03,0x04, 29 | 0x05,0x06,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 30 | 0x00,0x00,0x1e,0x00,0x73,0x6f,0x6e,0x67,0x00,0x62,0x61,0x72,0x73,0x70,0x72,0x70, 31 | 0x74,0x72,0x00,0x73,0x63,0x72,0x65,0x65,0x6e,0x00,0x70,0x6c,0x61,0x79,0x65,0x72, 32 | 0x00,0x64,0x64,0x30,0x30,0x00,0x43,0x4f,0x4c,0x5f,0x42,0x41,0x43,0x4b,0x47,0x52, 33 | 0x4f,0x55,0x4e,0x44,0x00,0x43,0x4f,0x4c,0x5f,0x54,0x49,0x54,0x4c,0x45,0x00,0x43, 34 | 0x4f,0x4c,0x5f,0x56,0x41,0x4c,0x55,0x45,0x00,0x43,0x4f,0x4c,0x5f,0x50,0x41,0x52, 35 | 0x41,0x4d,0x45,0x54,0x45,0x52,0x00,0x43,0x4f,0x4c,0x5f,0x43,0x4f,0x4c,0x4f,0x4e, 36 | 0x00,0x43,0x4f,0x4c,0x5f,0x4c,0x45,0x47,0x45,0x4e,0x44,0x00,0x73,0x74,0x6f,0x70, 37 | 0x76,0x65,0x63,0x00,0x64,0x30,0x31,0x38,0x00,0x43,0x4f,0x4c,0x5f,0x42,0x4f,0x52, 38 | 0x44,0x45,0x52,0x00,0x43,0x4f,0x4c,0x5f,0x42,0x41,0x52,0x5f,0x46,0x47,0x00,0x43, 39 | 0x4f,0x4c,0x5f,0x4c,0x49,0x4e,0x45,0x5f,0x30,0x00,0x43,0x4f,0x4c,0x5f,0x4c,0x49, 40 | 0x4e,0x45,0x5f,0x31,0x00,0x43,0x4f,0x4c,0x5f,0x4c,0x49,0x4e,0x45,0x5f,0x32,0x00, 41 | 0x43,0x4f,0x4c,0x5f,0x4c,0x49,0x4e,0x45,0x5f,0x33,0x00,0x43,0x4f,0x4c,0x5f,0x4c, 42 | 0x49,0x4e,0x45,0x5f,0x34,0x00,0x43,0x4f,0x4c,0x5f,0x4c,0x49,0x4e,0x45,0x5f,0x35, 43 | 0x00,0x43,0x4f,0x4c,0x5f,0x4c,0x49,0x4e,0x45,0x5f,0x36,0x00,0x43,0x4f,0x4c,0x5f, 44 | 0x4c,0x49,0x4e,0x45,0x5f,0x37,0x00,0x43,0x4f,0x4c,0x5f,0x4c,0x49,0x4e,0x45,0x5f, 45 | 0x38,0x00,0x43,0x4f,0x4c,0x5f,0x4c,0x49,0x4e,0x45,0x5f,0x39,0x00,0x43,0x4f,0x4c, 46 | 0x5f,0x4c,0x49,0x4e,0x45,0x5f,0x31,0x30,0x00,0x43,0x4f,0x4c,0x5f,0x4c,0x49,0x4e, 47 | 0x45,0x5f,0x31,0x31,0x00,0x43,0x4f,0x4c,0x5f,0x4c,0x49,0x4e,0x45,0x5f,0x31,0x32, 48 | 0x00,0x43,0x4f,0x4c,0x5f,0x4c,0x49,0x4e,0x45,0x5f,0x31,0x33,0x00,0x43,0x4f,0x4c, 49 | 0x5f,0x4c,0x49,0x4e,0x45,0x5f,0x31,0x34,0x00,0x02,0x20,0x00,0x00,0x02,0x82,0x9c, 50 | 0x20,0x01,0x00,0x02,0x80,0x02,0x00,0x07,0x80,0x03,0x00,0x1b,0x82,0x09,0x20,0x04, 51 | 0x00,0x05,0x20,0x05,0x00,0x13,0x20,0x06,0x00,0x0a,0x82,0x0d,0x20,0x07,0x00,0x08, 52 | 0x20,0x08,0x00,0x03,0x20,0x09,0x00,0x0f,0x20,0x0a,0x00,0x0e,0x20,0x0b,0x00,0x05, 53 | 0x40,0x0b,0x00,0x00,0x07,0x82,0x23,0x20,0x0c,0x00,0x08,0x20,0x0d,0x00,0x01,0x20, 54 | 0x05,0x00,0x06,0x20,0x0e,0x00,0x07,0x20,0x0f,0x00,0x01,0x20,0x10,0x00,0x01,0x20, 55 | 0x11,0x00,0x01,0x20,0x12,0x00,0x01,0x20,0x13,0x00,0x01,0x20,0x14,0x00,0x01,0x20, 56 | 0x15,0x00,0x01,0x20,0x16,0x00,0x01,0x20,0x17,0x00,0x01,0x20,0x18,0x00,0x01,0x20, 57 | 0x19,0x00,0x01,0x20,0x1a,0x00,0x01,0x20,0x1b,0x00,0x01,0x20,0x1c,0x00,0x01,0x20, 58 | 0x1d,0x00,0x00,0x00,0x00,0x00, 59 | -------------------------------------------------------------------------------- /src/libpsid64/exomizer/radix.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002, 2003 Magnus Lind. 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. 5 | * In no event will the authors be held liable for any damages arising from 6 | * the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software, alter it and re- 9 | * distribute it freely for any non-commercial, non-profit purpose subject to 10 | * the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software in a 14 | * product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not 18 | * be misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any distribution. 21 | * 22 | * 4. The names of this software and/or it's copyright holders may not be 23 | * used to endorse or promote products derived from this software without 24 | * specific prior written permission. 25 | * 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "log.h" 32 | #include "radix.h" 33 | #include "chunkpool.h" 34 | 35 | #define RADIX_TREE_NODE_RADIX 11U 36 | #define RADIX_TREE_NODE_MASK ((1U << RADIX_TREE_NODE_RADIX) - 1U) 37 | 38 | struct _radix_node { 39 | struct _radix_node *rn; 40 | }; 41 | 42 | void radix_tree_init(radix_root rr) /* IN */ 43 | { 44 | rr->depth = 0; 45 | rr->root = NULL; 46 | 47 | chunkpool_init(rr->mem, (1 << RADIX_TREE_NODE_RADIX) * sizeof(void *)); 48 | } 49 | 50 | static 51 | void radix_tree_free_helper(int depth, radix_nodep rnp, free_callback * f, /* IN */ 52 | void *priv) /* IN */ 53 | { 54 | int i; 55 | do 56 | { 57 | if (depth == 0) 58 | { 59 | /* do something to the data pointer? */ 60 | if (f != NULL) 61 | { 62 | f(rnp, priv); 63 | } 64 | break; 65 | } 66 | if (rnp == NULL) 67 | { 68 | /* tree not grown here */ 69 | break; 70 | } 71 | 72 | for (i = RADIX_TREE_NODE_MASK; i >= 0; --i) 73 | { 74 | radix_tree_free_helper(depth - 1, rnp[i].rn, f, priv); 75 | rnp[i].rn = NULL; 76 | } 77 | } 78 | while (0); 79 | } 80 | 81 | void radix_tree_free(radix_root rr, /* IN */ 82 | free_callback * f, /* IN */ 83 | void *priv) /* IN */ 84 | { 85 | radix_tree_free_helper(rr->depth, rr->root, f, priv); 86 | rr->depth = 0; 87 | rr->root = NULL; 88 | chunkpool_free(rr->mem); 89 | } 90 | 91 | void radix_node_set(radix_rootp rrp, /* IN */ 92 | unsigned int index, /* IN */ 93 | void *data) /* IN */ 94 | { 95 | radix_nodep rnp; 96 | radix_nodep *rnpp; 97 | unsigned int mask; 98 | int depth; 99 | 100 | mask = ~0U << (RADIX_TREE_NODE_RADIX * rrp->depth); 101 | while (index & mask) 102 | { 103 | /*LOG(LOG_DUMP, ("calloc called\n")); */ 104 | /* not deep enough, let's deepen the tree */ 105 | rnp = chunkpool_calloc(rrp->mem); 106 | 107 | rnp[0].rn = rrp->root; 108 | rrp->root = rnp; 109 | rrp->depth += 1; 110 | 111 | mask = ~0U << (RADIX_TREE_NODE_RADIX * rrp->depth); 112 | } 113 | 114 | /* go down */ 115 | rnpp = &rrp->root; 116 | for (depth = rrp->depth - 1; depth >= 0; --depth) 117 | { 118 | unsigned int node_index; 119 | 120 | if (*rnpp == NULL) 121 | { 122 | /*LOG(LOG_DUMP, ("calloc called\n")); */ 123 | /* tree is not grown in this interval */ 124 | *rnpp = chunkpool_calloc(rrp->mem); 125 | } 126 | node_index = ((index >> (RADIX_TREE_NODE_RADIX * depth)) & 127 | RADIX_TREE_NODE_MASK); 128 | 129 | rnpp = &((*rnpp)[node_index].rn); 130 | } 131 | *rnpp = data; 132 | } 133 | 134 | void *radix_node_get(radix_root rr, /* IN */ 135 | unsigned int index) /* IN */ 136 | { 137 | radix_nodep rnp; 138 | unsigned short int depth; 139 | 140 | /* go down */ 141 | rnp = rr->root; 142 | for (depth = rr->depth - 1; depth < 0xffff; --depth) 143 | { 144 | unsigned short int node_index; 145 | 146 | if (rnp == NULL) 147 | { 148 | /* tree is not grown in this interval */ 149 | break; 150 | } 151 | node_index = ((index >> (RADIX_TREE_NODE_RADIX * depth)) & 152 | RADIX_TREE_NODE_MASK); 153 | 154 | rnp = rnp[node_index].rn; 155 | } 156 | return rnp; 157 | } 158 | -------------------------------------------------------------------------------- /src/libpsid64/theme.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | psid64 - create a C64 executable from a PSID file 4 | Copyright (C) 2014 Roland Hermans 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #ifndef THEME_H 22 | #define THEME_H 23 | 24 | ////////////////////////////////////////////////////////////////////////////// 25 | // I N C L U D E S 26 | ////////////////////////////////////////////////////////////////////////////// 27 | 28 | 29 | ////////////////////////////////////////////////////////////////////////////// 30 | // F O R W A R D D E C L A R A T O R S 31 | ////////////////////////////////////////////////////////////////////////////// 32 | 33 | 34 | ////////////////////////////////////////////////////////////////////////////// 35 | // D A T A D E C L A R A T O R S 36 | ////////////////////////////////////////////////////////////////////////////// 37 | 38 | #define NUM_LINE_COLORS 15 39 | #define NUM_SCROLLER_COLORS 8 40 | #define NUM_FOOTER_COLORS 16 41 | 42 | class DriverTheme 43 | { 44 | public: 45 | DriverTheme(int borderColor, int backgroundColor, int rasterTimeColor, 46 | int titleColor, const int* lineColors, 47 | int fieldNameColor, int fieldColonColor, int fieldValueColor, 48 | int legendColor, 49 | int progressBarFillColor, int progressBarBackgroundColor, 50 | int scrollerColor, const int* scrollerColors, 51 | const int* footerColors); 52 | virtual ~DriverTheme(); 53 | 54 | // factory methods 55 | static DriverTheme* createBlueTheme(); 56 | static DriverTheme* createC1541UltimateTheme(); 57 | static DriverTheme* createCoalTheme(); 58 | static DriverTheme* createDefaultTheme(); 59 | static DriverTheme* createDutchTheme(); 60 | static DriverTheme* createKernalTheme(); 61 | static DriverTheme* createLightTheme(); 62 | static DriverTheme* createMondriaanTheme(); 63 | static DriverTheme* createOceanTheme(); 64 | static DriverTheme* createPencilTheme(); 65 | static DriverTheme* createRainbowTheme(); 66 | 67 | int getBorderColor() const 68 | { 69 | return m_borderColor; 70 | } 71 | 72 | int getBackgroundColor() const 73 | { 74 | return m_backgroundColor; 75 | } 76 | 77 | int getRasterTimeColor() const 78 | { 79 | return m_rasterTimeColor; 80 | } 81 | 82 | int getTitleColor() const 83 | { 84 | return m_titleColor; 85 | } 86 | 87 | const int* getLineColors() const 88 | { 89 | return m_lineColors; 90 | } 91 | 92 | int getFieldNameColor() const 93 | { 94 | return m_fieldNameColor; 95 | } 96 | 97 | int getFieldColonColor() const 98 | { 99 | return m_fieldColonColor; 100 | } 101 | 102 | int getFieldValueColor() const 103 | { 104 | return m_fieldValueColor; 105 | } 106 | 107 | int getLegendColor() const 108 | { 109 | return m_legendColor; 110 | } 111 | 112 | int getProgressBarFillColor() const 113 | { 114 | return m_progressBarFillColor; 115 | } 116 | 117 | int getProgressBarBackgroundColor() const 118 | { 119 | return m_progressBarBackgroundColor; 120 | } 121 | 122 | int getScrollerColor() const 123 | { 124 | return m_scrollerColor; 125 | } 126 | 127 | const int* getScrollerColors() const 128 | { 129 | return m_scrollerColors; 130 | } 131 | 132 | const int* getFooterColors() const 133 | { 134 | return m_footerColors; 135 | } 136 | 137 | private: 138 | int m_borderColor; 139 | int m_backgroundColor; 140 | int m_rasterTimeColor; 141 | int m_titleColor; 142 | int m_lineColors[NUM_LINE_COLORS]; 143 | int m_fieldNameColor; 144 | int m_fieldColonColor; 145 | int m_fieldValueColor; 146 | int m_legendColor; 147 | int m_progressBarFillColor; 148 | int m_progressBarBackgroundColor; 149 | int m_scrollerColor; 150 | int m_scrollerColors[NUM_SCROLLER_COLORS]; 151 | int m_footerColors[NUM_FOOTER_COLORS]; 152 | }; 153 | 154 | #endif // THEME_H 155 | -------------------------------------------------------------------------------- /src/sidtune/p00.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | * C64 P00 file format support. 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include "SidTuneCfg.h" 21 | #include "SidTune.h" 22 | #include "SidTuneTools.h" 23 | 24 | #define X00_ID_LEN 8 25 | #define X00_NAME_LEN 17 26 | 27 | // File format from PC64. PC64 automatically generates 28 | // the filename from the cbm name (16 to 8 conversion) 29 | // but we only need to worry about that when writing files 30 | // should we want pc64 compatibility. The extension numbers 31 | // are just an index to try to avoid repeats. Name conversion 32 | // works by creating an initial filename from alphanumeric 33 | // and ' ', '-' characters only with the later two being 34 | // converted to '_'. Then it parses the filename 35 | // from end to start removing characters stopping as soon 36 | // as the filename becomes <= 8. The removal of characters 37 | // occurs in three passes, the first removes all '_', then 38 | // vowels and finally numerics. If the filename is still 39 | // greater than 8 it is trucated. struct X00Header 40 | struct X00Header 41 | { 42 | char id[X00_ID_LEN]; // C64File 43 | char name[X00_NAME_LEN]; // C64 name 44 | uint8_t length; // Rel files only (Bytes/Record), 45 | // should be 0 for all other types 46 | }; 47 | 48 | typedef enum 49 | { 50 | X00_UNKNOWN, 51 | X00_DEL, 52 | X00_SEQ, 53 | X00_PRG, 54 | X00_USR, 55 | X00_REL 56 | } X00Format; 57 | 58 | static const char _sidtune_id[] = "C64File"; 59 | static const char _sidtune_format_del[] = "Unsupported tape image file (DEL)"; 60 | static const char _sidtune_format_seq[] = "Unsupported tape image file (SEQ)"; 61 | static const char _sidtune_format_prg[] = "Tape image file (PRG)"; 62 | static const char _sidtune_format_usr[] = "Unsupported USR file (USR)"; 63 | static const char _sidtune_format_rel[] = "Unsupported tape image file (REL)"; 64 | static const char _sidtune_truncated[] = "ERROR: File is most likely truncated"; 65 | 66 | 67 | SidTune::LoadStatus SidTune::X00_fileSupport(const char *fileName, 68 | Buffer_sidtt& dataBuf) 69 | { 70 | const char *ext = SidTuneTools::fileExtOfPath(const_cast(fileName)); 71 | const char *format = 0; 72 | const X00Header *pHeader = reinterpret_cast(dataBuf.get()); 73 | uint_least32_t bufLen = dataBuf.len (); 74 | 75 | // Combined extension & magic field identification 76 | if (strlen (ext) != 4) 77 | return LOAD_NOT_MINE; 78 | if (!isdigit(ext[2]) || !isdigit(ext[3])) 79 | return LOAD_NOT_MINE; 80 | 81 | X00Format type = X00_UNKNOWN; 82 | switch (toupper(ext[1])) 83 | { 84 | case 'D': 85 | type = X00_DEL; 86 | format = _sidtune_format_del; 87 | break; 88 | case 'S': 89 | type = X00_SEQ; 90 | format = _sidtune_format_seq; 91 | break; 92 | case 'P': 93 | type = X00_PRG; 94 | format = _sidtune_format_prg; 95 | break; 96 | case 'U': 97 | type = X00_USR; 98 | format = _sidtune_format_usr; 99 | break; 100 | case 'R': 101 | type = X00_REL; 102 | format = _sidtune_format_rel; 103 | break; 104 | } 105 | 106 | if (type == X00_UNKNOWN) 107 | return LOAD_NOT_MINE; 108 | 109 | // Verify the file is what we think it is 110 | if (bufLen < X00_ID_LEN) 111 | return LOAD_NOT_MINE; 112 | else if (strcmp (pHeader->id, _sidtune_id)) 113 | return LOAD_NOT_MINE; 114 | 115 | info.formatString = format; 116 | 117 | // File types current supported 118 | if (type != X00_PRG) 119 | return LOAD_ERROR; 120 | 121 | if (bufLen < sizeof(X00Header)+2) 122 | { 123 | info.formatString = _sidtune_truncated; 124 | return LOAD_ERROR; 125 | } 126 | 127 | { // Decode file name 128 | SmartPtr_sidtt spPet((const uint8_t*)pHeader->name,X00_NAME_LEN); 129 | convertPetsciiToAscii(spPet,infoString[0]); 130 | } 131 | 132 | // Automatic settings 133 | fileOffset = sizeof(X00Header); 134 | info.songs = 1; 135 | info.startSong = 1; 136 | info.compatibility = SIDTUNE_COMPATIBILITY_BASIC; 137 | info.numberOfInfoStrings = 1; 138 | info.infoString[0] = infoString[0]; 139 | 140 | // Create the speed/clock setting table. 141 | convertOldStyleSpeedToTables(~0, info.clockSpeed); 142 | return LOAD_OK; 143 | } 144 | -------------------------------------------------------------------------------- /src/sidutils/SidDatabase.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /*************************************************************************** 3 | dbget.cpp - Get time from database 4 | ------------------- 5 | begin : Fri Jun 2 2000 6 | copyright : (C) 2000 by Simon White 7 | email : s_a_white@email.com 8 | ***************************************************************************/ 9 | 10 | /*************************************************************************** 11 | * * 12 | * This program is free software; you can redistribute it and/or modify * 13 | * it under the terms of the GNU General Public License as published by * 14 | * the Free Software Foundation; either version 2 of the License, or * 15 | * (at your option) any later version. * 16 | * * 17 | ***************************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "config.h" 24 | #include "SidDatabase.h" 25 | #include "MD5/MD5.h" 26 | 27 | const char *SidDatabase::ERR_DATABASE_CORRUPT = "SID DATABASE ERROR: Database seems to be corrupt."; 28 | const char *SidDatabase::ERR_NO_DATABASE_LOADED = "SID DATABASE ERROR: Songlength database not loaded."; 29 | const char *SidDatabase::ERR_NO_SELECTED_SONG = "SID DATABASE ERROR: No song selected for retrieving song length."; 30 | const char *SidDatabase::ERR_MEM_ALLOC = "SID DATABASE ERROR: Memory Allocation Failure."; 31 | const char *SidDatabase::ERR_UNABLE_TO_LOAD_DATABASE = "SID DATABASE ERROR: Unable to load the songlength database."; 32 | 33 | 34 | SidDatabase::~SidDatabase () 35 | { 36 | close (); 37 | } 38 | 39 | 40 | int_least32_t SidDatabase::parseTimeStamp(const char* arg) 41 | { 42 | /* Read in m:s format at most. 43 | * Could use a system function if available. 44 | */ 45 | int_least32_t seconds = 0; 46 | int passes = 2; // minutes, seconds 47 | bool gotDigits = false; 48 | while ( passes-- ) 49 | { 50 | if ( isdigit(*arg) ) 51 | { 52 | int t = atoi(arg); 53 | seconds += t; 54 | gotDigits = true; 55 | } 56 | while ( isdigit(*arg) ) 57 | { 58 | ++arg; 59 | } 60 | if ( *arg==':' ) 61 | { 62 | seconds *= 60; 63 | ++arg; 64 | } 65 | } 66 | 67 | // Handle -:-- time stamps and old 0:00 entries which 68 | // need to be rounded up by one second. 69 | if ( !gotDigits ) 70 | seconds = 0; 71 | else if ( seconds==0 ) 72 | ++seconds; 73 | 74 | return seconds; 75 | } 76 | 77 | 78 | uint_least8_t SidDatabase::timesFound (char *str) 79 | { 80 | /* Try and determine the number of times read back. 81 | * Used to check validility of times in database. 82 | */ 83 | uint_least8_t count = 0; 84 | while (*str) 85 | { 86 | if (*str++ == ':') 87 | count++; 88 | } 89 | return count; 90 | } 91 | 92 | 93 | int SidDatabase::open (const char *filename) 94 | { 95 | close (); 96 | database = ini_open (filename, "r", ";"); 97 | if (!database) 98 | { 99 | errorString = ERR_UNABLE_TO_LOAD_DATABASE; 100 | return -1; 101 | } 102 | 103 | return 0; 104 | } 105 | 106 | void SidDatabase::close () 107 | { 108 | if (database) 109 | ini_close (database); 110 | } 111 | 112 | int_least32_t SidDatabase::length (SidTuneMod &tune) 113 | { 114 | char md5[SIDTUNE_MD5_LENGTH+1]; 115 | uint_least16_t song = tune.getInfo().currentSong; 116 | if (!song) 117 | { 118 | errorString = ERR_NO_SELECTED_SONG; 119 | return -1; 120 | } 121 | tune.createMD5 (md5); 122 | return length (md5, song); 123 | } 124 | 125 | int_least32_t SidDatabase::length (const char *md5, uint_least16_t song) 126 | { 127 | int_least32_t time = 0; 128 | 129 | if (!database) 130 | { 131 | errorString = ERR_NO_DATABASE_LOADED; 132 | return -1; 133 | } 134 | 135 | // Now set up array access 136 | if (ini_listDelims (database, " ") == -1) 137 | { 138 | errorString = ERR_MEM_ALLOC; 139 | return -1; 140 | } 141 | 142 | // Read Time (and check times before hand) 143 | (void) ini_locateHeading (database, "Database"); 144 | (void) ini_locateKey (database, md5); 145 | // If length return is -1 then no entry found in database 146 | if ((song > 0) && (ini_dataLength (database) != -1)) 147 | { 148 | char timeStamp[10]; 149 | 150 | for (uint_least16_t i = 0; i < song; i++) 151 | { 152 | if (ini_readString (database, timeStamp, sizeof (timeStamp)) == -1) 153 | { // No time found 154 | errorString = ERR_DATABASE_CORRUPT; 155 | return -1; 156 | } 157 | 158 | // Validate Time 159 | if (timesFound (timeStamp) != 1) 160 | { 161 | errorString = ERR_DATABASE_CORRUPT; 162 | return -1; 163 | } 164 | } 165 | 166 | // Parse timestamp 167 | time = parseTimeStamp (timeStamp); 168 | } 169 | 170 | return time; 171 | } 172 | -------------------------------------------------------------------------------- /src/libpsid64/screen.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | psid64 - create a C64 executable from a PSID file 4 | Copyright (C) 2001-2023 Roland Hermans 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #ifndef SCREEN_H 22 | #define SCREEN_H 23 | 24 | ////////////////////////////////////////////////////////////////////////////// 25 | // I N C L U D E S 26 | ////////////////////////////////////////////////////////////////////////////// 27 | 28 | #include 29 | 30 | #include 31 | 32 | 33 | ////////////////////////////////////////////////////////////////////////////// 34 | // F O R W A R D D E C L A R A T O R S 35 | ////////////////////////////////////////////////////////////////////////////// 36 | 37 | 38 | ////////////////////////////////////////////////////////////////////////////// 39 | // D A T A D E C L A R A T O R S 40 | ////////////////////////////////////////////////////////////////////////////// 41 | 42 | class Screen 43 | { 44 | public: 45 | Screen(); 46 | ~Screen(); 47 | 48 | void clear(); 49 | void moveTo(unsigned int x, unsigned int y); 50 | void putchar(char c); 51 | void write(const char *str); 52 | 53 | inline void write(const std::string& str) 54 | { 55 | write(str.c_str()); 56 | } 57 | 58 | void poke(unsigned int x, unsigned int y, uint_least8_t value); 59 | void poke(unsigned int offs, uint_least8_t value); 60 | 61 | inline const uint_least8_t *getData() const 62 | { 63 | return m_screen; 64 | } 65 | 66 | inline unsigned int getDataSize() const 67 | { 68 | return m_screenSize; 69 | } 70 | 71 | inline unsigned int getX() const 72 | { 73 | return m_x; 74 | } 75 | 76 | inline unsigned int getY() const 77 | { 78 | return m_y; 79 | } 80 | 81 | inline void moveRight() 82 | { 83 | if (m_x < (m_width - 1)) 84 | { 85 | ++m_x; 86 | } 87 | } 88 | 89 | inline void moveDown() 90 | { 91 | if (m_y < (m_height - 1)) 92 | { 93 | ++m_y; 94 | } 95 | } 96 | 97 | static inline uint_least8_t iso2scr(uint_least8_t c) 98 | { 99 | static const uint_least8_t scrtab[] = { 100 | 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, // 0x00 101 | 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, // 0x08 102 | 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, // 0x10 103 | 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, // 0x18 104 | 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, // 0x20 !"#$%&' 105 | 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, // 0x28 ()*+,-./ 106 | 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // 0x30 01234567 107 | 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, // 0x38 89:;<=>? 108 | 0x00, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, // 0x40 @ABCDEFG 109 | 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, // 0x48 HIJKLMNO 110 | 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, // 0x50 PQRSTUVW 111 | 0x58, 0x59, 0x5a, 0x1b, 0xbf, 0x1d, 0x1e, 0x64, // 0x58 XYZ[\]^_ 112 | 0x27, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // 0x60 `abcdefg 113 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, // 0x68 hijklmno 114 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, // 0x70 pqrstuvw 115 | 0x18, 0x19, 0x1a, 0x1b, 0x5d, 0x1d, 0x1f, 0x20, // 0x78 xyz{|}~ 116 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, // 0x80 117 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, // 0x88 118 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, // 0x90 119 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, // 0x98 120 | 0x20, 0x21, 0x03, 0x1c, 0xbf, 0x59, 0x5d, 0xbf, // 0xa0  ¡¢£€¥Š§ 121 | 0x22, 0x43, 0x01, 0x3c, 0xbf, 0x2d, 0x52, 0x63, // 0xa8 š©ª«¬­®¯ 122 | 0x0f, 0xbf, 0x32, 0x33, 0x27, 0x15, 0xbf, 0xbf, // 0xb0 °±²³Žµ¶· 123 | 0x2c, 0x31, 0x0f, 0x3e, 0xbf, 0xbf, 0xbf, 0x3f, // 0xb8 ž¹º»ŒœŸ¿ 124 | 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x43, // 0xc0 ÀÁÂÃÄÅÆÇ 125 | 0x45, 0x45, 0x45, 0x45, 0x49, 0x49, 0x49, 0x49, // 0xc8 ÈÉÊËÌÍÎÏ 126 | 0xbf, 0x4e, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x18, // 0xd0 ÐÑÒÓÔÕÖ× 127 | 0x4f, 0x55, 0x55, 0x55, 0x55, 0x59, 0xbf, 0xbf, // 0xd8 ØÙÚÛÜÝÞß 128 | 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03, // 0xe0 àáâãäåæç 129 | 0x05, 0x05, 0x05, 0x05, 0x09, 0x09, 0x09, 0x09, // 0xe8 èéêëìíîï 130 | 0xbf, 0x0e, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xbf, // 0xf0 ðñòóôõö÷ 131 | 0x0f, 0x15, 0x15, 0x15, 0x15, 0x19, 0xbf, 0x19 // 0xf8 øùúûüýþÿ 132 | }; 133 | 134 | return scrtab[c]; 135 | } 136 | 137 | private: 138 | static const unsigned int m_width = 40; 139 | static const unsigned int m_height = 25; 140 | static const unsigned int m_screenSize = m_width * m_height; 141 | 142 | uint_least8_t m_screen[m_screenSize]; 143 | unsigned int m_x; 144 | unsigned int m_y; 145 | 146 | inline unsigned int offset(unsigned int x, unsigned int y) 147 | { 148 | return x + (m_width * y); 149 | } 150 | }; 151 | 152 | #endif // SCREEN_H 153 | -------------------------------------------------------------------------------- /src/libpsid64/exomizer/exomizer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002, 2003 Magnus Lind. 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. 5 | * In no event will the authors be held liable for any damages arising from 6 | * the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software, alter it and re- 9 | * distribute it freely for any non-commercial, non-profit purpose subject to 10 | * the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software in a 14 | * product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not 18 | * be misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any distribution. 21 | * 22 | * 4. The names of this software and/or it's copyright holders may not be 23 | * used to endorse or promote products derived from this software without 24 | * specific prior written permission. 25 | * 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "log.h" 34 | #include "search.h" 35 | #include "optimal.h" 36 | #include "output.h" 37 | #include "sfx.h" 38 | 39 | #include "exomizer.h" 40 | 41 | static 42 | int 43 | generate_output(match_ctx ctx, 44 | search_nodep snp, 45 | struct sfx_decruncher *decr, 46 | encode_match_f * f, 47 | encode_match_data emd, 48 | int load, int len, int start, unsigned char *buf) 49 | { 50 | int pos; 51 | int pos_diff; 52 | int max_diff; 53 | int diff; 54 | static output_ctx out; 55 | output_ctxp old; 56 | 57 | output_ctx_init(out); 58 | 59 | old = emd->out; 60 | emd->out = out; 61 | 62 | pos = output_get_pos(out); 63 | 64 | pos_diff = pos; 65 | max_diff = 0; 66 | 67 | output_gamma_code(out, 16); 68 | output_bits(out, 1, 0); /* 1 bit out */ 69 | 70 | diff = output_get_pos(out) - pos_diff; 71 | if(diff > max_diff) 72 | { 73 | max_diff = diff; 74 | } 75 | 76 | while (snp != NULL) 77 | { 78 | const_matchp mp; 79 | 80 | mp = snp->match; 81 | if (mp != NULL && mp->len > 0) 82 | { 83 | if (mp->offset == 0) 84 | { 85 | /* literal */ 86 | output_byte(out, ctx->buf[snp->index]); 87 | output_bits(out, 1, 1); 88 | } 89 | else 90 | { 91 | f(mp, emd); 92 | output_bits(out, 1, 0); 93 | } 94 | 95 | pos_diff += mp->len; 96 | diff = output_get_pos(out) - pos_diff; 97 | if(diff > max_diff) 98 | { 99 | max_diff = diff; 100 | } 101 | } 102 | snp = snp->prev; 103 | } 104 | 105 | /* output header here */ 106 | optimal_out(out, emd); 107 | 108 | output_bits_flush(out); 109 | 110 | output_word(out, (unsigned short int) (load + len)); 111 | 112 | len = output_get_pos(out); 113 | decr->load(out, (unsigned short int) load - max_diff); 114 | output_copy_bytes(out, 0, len); 115 | 116 | /* second stage of decruncher */ 117 | decr->stages(out, (unsigned short int) start); 118 | 119 | /*len = output_ctx_close(out, of);*/ 120 | len = out->pos - out->start; 121 | memcpy(buf, out->buf + out->start, len); 122 | 123 | emd->out = old; 124 | 125 | return len; 126 | } 127 | 128 | static 129 | search_nodep 130 | do_compress(match_ctx ctx, encode_match_data emd, int max_passes) 131 | { 132 | matchp_cache_enum mpce; 133 | matchp_snp_enum snpe; 134 | search_nodep snp; 135 | search_nodep best_snp; 136 | int pass; 137 | float old_size; 138 | 139 | pass = 1; 140 | 141 | matchp_cache_get_enum(ctx, mpce); 142 | optimal_optimize(emd, matchp_cache_enum_get_next, mpce); 143 | 144 | best_snp = NULL; 145 | old_size = 1000000.0; 146 | 147 | for (;;) 148 | { 149 | snp = search_buffer(ctx, optimal_encode, emd); 150 | if (snp == NULL) 151 | { 152 | fprintf(stderr, "error: search_buffer() returned NULL\n"); 153 | exit(-1); 154 | } 155 | 156 | float size = snp->total_score; 157 | if (size >= old_size) 158 | { 159 | #if 0 /* RH */ 160 | search_node_free(snp); 161 | #endif /* RH */ 162 | break; 163 | } 164 | 165 | #if 0 /* RH */ 166 | if (best_snp != NULL) 167 | { 168 | search_node_free(best_snp); 169 | } 170 | #endif /* RH */ 171 | best_snp = snp; 172 | old_size = size; 173 | ++pass; 174 | 175 | if (pass > max_passes) 176 | { 177 | break; 178 | } 179 | 180 | optimal_free(emd); 181 | optimal_init(emd); 182 | 183 | matchp_snp_get_enum(snp, snpe); 184 | optimal_optimize(emd, matchp_snp_enum_get_next, snpe); 185 | } 186 | 187 | return best_snp; 188 | } 189 | 190 | 191 | int exomizer(const unsigned char *srcbuf, int len, int load, int start, unsigned char *destbuf) 192 | { 193 | int destlen; 194 | int max_offset = 65536; 195 | int max_passes = 65536; 196 | static match_ctx ctx; 197 | encode_match_data emd; 198 | encode_match_priv optimal_priv; 199 | search_nodep snp; 200 | 201 | match_ctx_init(ctx, srcbuf, len, max_offset); 202 | 203 | emd->out = NULL; 204 | emd->priv = optimal_priv; 205 | 206 | optimal_init(emd); 207 | 208 | snp = do_compress(ctx, emd, max_passes); 209 | 210 | destlen = generate_output(ctx, snp, sfx_c64ne, optimal_encode, emd, 211 | load, len, start, destbuf); 212 | optimal_free(emd); 213 | 214 | #if 0 /* RH */ 215 | search_node_free(snp); 216 | #endif /* RH */ 217 | match_ctx_free(ctx); 218 | 219 | return destlen; 220 | } 221 | -------------------------------------------------------------------------------- /src/libpsid64/exomizer/output.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002, 2003 Magnus Lind. 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. 5 | * In no event will the authors be held liable for any damages arising from 6 | * the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software, alter it and re- 9 | * distribute it freely for any non-commercial, non-profit purpose subject to 10 | * the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software in a 14 | * product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not 18 | * be misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any distribution. 21 | * 22 | * 4. The names of this software and/or it's copyright holders may not be 23 | * used to endorse or promote products derived from this software without 24 | * specific prior written permission. 25 | * 26 | */ 27 | 28 | #include 29 | #include "log.h" 30 | #include "output.h" 31 | 32 | #define OUTPUT_FLAG_REVERSE 1 33 | 34 | void output_ctx_init(output_ctx ctx) /* IN/OUT */ 35 | { 36 | ctx->bitbuf = 1; 37 | ctx->pos = 0; 38 | ctx->start = 0; 39 | ctx->flags = 0; 40 | } 41 | 42 | void output_ctx_set_start(output_ctx ctx, /* IN/OUT */ 43 | unsigned int pos) /* IN */ 44 | { 45 | ctx->start = pos; 46 | } 47 | 48 | #if 0 /* RH */ 49 | void output_ctx_set_reverse(output_ctx ctx) /* IN/OUT */ 50 | { 51 | ctx->flags |= OUTPUT_FLAG_REVERSE; 52 | } 53 | 54 | 55 | static void reverse(unsigned char *start, int len) 56 | { 57 | unsigned char *end = start + len - 1; 58 | unsigned char tmp; 59 | 60 | while (start < end) 61 | { 62 | tmp = *start; 63 | *start = *end; 64 | *end = tmp; 65 | 66 | ++start; 67 | --end; 68 | } 69 | } 70 | 71 | unsigned int output_ctx_close(output_ctx ctx, /* IN */ 72 | FILE * out) /* OUT */ 73 | { 74 | int rval; 75 | int len; 76 | 77 | rval = 0; 78 | /* flush the buffer */ 79 | len = ctx->pos - ctx->start; 80 | 81 | if (ctx->start + len > sizeof(ctx->buf)) 82 | { 83 | LOG(LOG_ERROR, ("error: out of range in output_ctx_close()\n")); 84 | exit(1); 85 | } 86 | 87 | if (ctx->flags & OUTPUT_FLAG_REVERSE) 88 | { 89 | reverse(ctx->buf + ctx->start, len); 90 | ctx->flags &= ~OUTPUT_FLAG_REVERSE; 91 | } 92 | 93 | fwrite(ctx->buf + ctx->start, 1, len, out); 94 | return len; 95 | } 96 | #endif /* RH */ 97 | 98 | unsigned int output_get_pos(output_ctx ctx) /* IN */ 99 | { 100 | return ctx->pos; 101 | } 102 | 103 | void output_set_pos(output_ctx ctx, /* IN */ 104 | unsigned int pos) /* IN */ 105 | { 106 | ctx->pos = pos; 107 | } 108 | 109 | void output_byte(output_ctx ctx, /* IN/OUT */ 110 | unsigned char byte) /* IN */ 111 | { 112 | /*LOG(LOG_DUMP, ("output_byte: $%02X\n", byte)); */ 113 | ctx->buf[ctx->pos] = byte; 114 | ++(ctx->pos); 115 | } 116 | 117 | void output_copy_bytes(output_ctx ctx, /* IN */ 118 | unsigned int src_pos, /* IN */ 119 | unsigned int len) /* IN */ 120 | { 121 | int i; 122 | if(src_pos > ctx->pos) 123 | { 124 | for (i = 0; (unsigned int)i < len; ++i) 125 | { 126 | ctx->buf[ctx->pos + i] = ctx->buf[src_pos + i]; 127 | } 128 | } 129 | else if(src_pos < ctx->pos) 130 | { 131 | for (i = len - 1; i >= 0; --i) 132 | { 133 | ctx->buf[ctx->pos + i] = ctx->buf[src_pos + i]; 134 | } 135 | } 136 | ctx->pos += len; 137 | } 138 | 139 | void output_word(output_ctx ctx, /* IN/OUT */ 140 | unsigned short int word) /* IN */ 141 | { 142 | output_byte(ctx, (unsigned char) (word & 0xff)); 143 | output_byte(ctx, (unsigned char) (word >> 8)); 144 | } 145 | 146 | 147 | void output_bits_flush(output_ctx ctx) /* IN/OUT */ 148 | { 149 | /* flush the bitbuf including 150 | * the extra 1 bit acting as eob flag */ 151 | output_byte(ctx, (unsigned char) (ctx->bitbuf & 0xFF)); 152 | if (ctx->bitbuf & 0x100) 153 | { 154 | output_byte(ctx, 1); 155 | } 156 | /*LOG(LOG_DUMP, ("bitstream flushed 0x%02X\n", ctx->bitbuf & 0xFF)); */ 157 | 158 | /* reset it */ 159 | ctx->bitbuf = 1; 160 | } 161 | 162 | #if 0 /* RH */ 163 | void bits_dump(int count, int val) 164 | { 165 | static char buf[1024]; 166 | char *pek; 167 | pek = buf; 168 | if (count > 0) 169 | { 170 | pek += sprintf(pek, "0x%04X, % 2d: ", val, count); 171 | } 172 | while (count-- > 0) 173 | { 174 | *(pek++) = val & (1 << count) ? '1' : '0'; 175 | } 176 | *(pek++) = '\0'; 177 | LOG(LOG_NORMAL, ("%s\n", buf)); 178 | } 179 | #endif /* RH */ 180 | 181 | void output_bits(output_ctx ctx, /* IN/OUT */ 182 | int count, /* IN */ 183 | int val) /* IN */ 184 | { 185 | /*LOG(LOG_DUMP, ("output_bits: count = %d, val = %d\n", count, val)); */ 186 | /* this makes the bits appear in reversed 187 | * big endian order in the output stream */ 188 | while (count-- > 0) 189 | { 190 | ctx->bitbuf <<= 1; 191 | ctx->bitbuf |= val & 0x1; 192 | val >>= 1; 193 | if (ctx->bitbuf & 0x100) 194 | { 195 | /* full byte, flush it */ 196 | output_byte(ctx, (unsigned char) (ctx->bitbuf & 0xFF)); 197 | /*LOG(LOG_DUMP, 198 | ("bitstream byte 0x%02X\n", ctx->bitbuf & 0xFF)); */ 199 | ctx->bitbuf = 1; 200 | } 201 | } 202 | } 203 | 204 | void output_gamma_code(output_ctx ctx, /* IN/OUT */ 205 | int code) /* IN */ 206 | { 207 | output_bits(ctx, 1, 1); 208 | while (code-- > 0) 209 | { 210 | output_bits(ctx, 1, 0); 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /src/libpsid64/psidboot.a65: -------------------------------------------------------------------------------- 1 | ; SPDX-License-Identifier: GPL-2.0-or-later 2 | 3 | ; psid64 - create a C64 executable from a PSID file 4 | ; Copyright (C) 2001-2015 Roland Hermans 5 | ; 6 | ; This program is free software; you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation; either version 2 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program; if not, write to the Free Software 18 | ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | 20 | .fopt 0, "psidboot.o65", 0 21 | .fopt 3, "Roland Hermans ", 0 22 | 23 | #define MAX_BLOCKS 5 24 | 25 | #ifdef SCREEN 26 | r1_org = $00f7 27 | #else /* SCREEN */ 28 | r1_org = $00f8 29 | #endif /* SCREEN */ 30 | 31 | 32 | lda #stopvec 234 | sta $0329 235 | 236 | ldy #r1_len 237 | copyr1 lda r1_src-1,y 238 | sta r1_org-1,y 239 | dey 240 | bne copyr1 241 | 242 | jmp memmove 243 | 244 | 245 | #ifdef SCREEN 246 | vicdata .byte $00,$9a,$00,$00,$00,$00,$00,$00 247 | .byte $00,$00,$00,$00,$00,$00,$00,$00 248 | .byte $00,$6b,$37,$00,$00,$01,$08,$00 249 | .byte 9 | class SmartPtrBase_sidtt 10 | { 11 | public: 12 | 13 | /* --- constructors --- */ 14 | 15 | SmartPtrBase_sidtt(T* buffer, ulint_smartpt bufferLen, bool bufOwner = false) : dummy(0) 16 | { 17 | doFree = bufOwner; 18 | if ( bufferLen >= 1 ) 19 | { 20 | pBufCurrent = ( bufBegin = buffer ); 21 | bufEnd = bufBegin + bufferLen; 22 | bufLen = bufferLen; 23 | status = true; 24 | } 25 | else 26 | { 27 | pBufCurrent = ( bufBegin = ( bufEnd = 0 )); 28 | bufLen = 0; 29 | status = false; 30 | } 31 | } 32 | 33 | /* --- destructor --- */ 34 | 35 | virtual ~SmartPtrBase_sidtt() 36 | { 37 | if ( doFree && (bufBegin != 0) ) 38 | { 39 | #ifndef SID_HAVE_BAD_COMPILER 40 | delete[] bufBegin; 41 | #else 42 | delete[] (void*)bufBegin; 43 | #endif 44 | } 45 | } 46 | 47 | /* --- public member functions --- */ 48 | 49 | virtual T* tellBegin() { return bufBegin; } 50 | virtual ulint_smartpt tellLength() { return bufLen; } 51 | virtual ulint_smartpt tellPos() { return (ulint_smartpt)(pBufCurrent-bufBegin); } 52 | 53 | virtual bool checkIndex(ulint_smartpt index) 54 | { 55 | return ((pBufCurrent+index)= 1 ) 61 | { 62 | pBufCurrent = bufBegin; 63 | return (status = true); 64 | } 65 | else 66 | { 67 | return (status = false); 68 | } 69 | } 70 | 71 | virtual bool good() 72 | { 73 | return (pBufCurrent= bufBegin) 144 | { 145 | pBufCurrent -= offset; 146 | } 147 | else 148 | { 149 | status = false; 150 | } 151 | } 152 | 153 | virtual T operator*() 154 | { 155 | if ( good() ) 156 | { 157 | return *pBufCurrent; 158 | } 159 | else 160 | { 161 | status = false; 162 | return dummy; 163 | } 164 | } 165 | 166 | virtual T& operator [](ulint_smartpt index) 167 | { 168 | if (checkIndex(index)) 169 | { 170 | return pBufCurrent[index]; 171 | } 172 | else 173 | { 174 | status = false; 175 | return dummy; 176 | } 177 | } 178 | 179 | virtual operator bool() { return status; } 180 | 181 | protected: 182 | 183 | T* bufBegin; 184 | T* bufEnd; 185 | T* pBufCurrent; 186 | ulint_smartpt bufLen; 187 | bool status; 188 | bool doFree; 189 | T dummy; 190 | }; 191 | 192 | 193 | template 194 | class SmartPtr_sidtt : public SmartPtrBase_sidtt 195 | { 196 | public: 197 | 198 | /* --- constructors --- */ 199 | 200 | SmartPtr_sidtt(T* buffer, ulint_smartpt bufferLen, bool bufOwner = false) 201 | : SmartPtrBase_sidtt(buffer, bufferLen, bufOwner) 202 | { 203 | } 204 | 205 | SmartPtr_sidtt() 206 | : SmartPtrBase_sidtt(0,0) 207 | { 208 | } 209 | 210 | void setBuffer(T* buffer, ulint_smartpt bufferLen) 211 | { 212 | if ( bufferLen >= 1 ) 213 | { 214 | this->pBufCurrent = ( this->bufBegin = buffer ); 215 | this->bufEnd = buffer + bufferLen; 216 | this->bufLen = bufferLen; 217 | this->status = true; 218 | } 219 | else 220 | { 221 | this->pBufCurrent = this->bufBegin = this->bufEnd = 0; 222 | this->bufLen = 0; 223 | this->status = false; 224 | } 225 | } 226 | }; 227 | 228 | #endif /* SMARTPTR_H */ 229 | -------------------------------------------------------------------------------- /src/sidtune/SidTuneTools.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | * /home/ms/files/source/libsidtune/RCS/SidTuneTools.cpp,v 4 | * 5 | * Copyright (C) Michael Schwendt 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | */ 21 | 22 | #include "SidTuneTools.h" 23 | 24 | #ifdef HAVE_EXCEPTIONS 25 | # include 26 | #endif 27 | #include 28 | #include 29 | 30 | // Own version of strdup, which uses new instead of malloc. 31 | char* SidTuneTools::myStrDup(const char *source) 32 | { 33 | char *dest; 34 | #ifdef HAVE_EXCEPTIONS 35 | if ( (dest = new(std::nothrow) char[strlen(source)+1]) != 0) 36 | #else 37 | if ( (dest = new char[strlen(source)+1]) != 0) 38 | #endif 39 | { 40 | strcpy(dest,source); 41 | } 42 | return dest; 43 | } 44 | 45 | // Return pointer to file name position in complete path. 46 | char* SidTuneTools::fileNameWithoutPath(char* s) 47 | { 48 | int last_slash_pos = -1; 49 | for ( uint_least32_t pos = 0; pos < strlen(s); pos++ ) 50 | { 51 | #if defined(SID_FS_IS_COLON_AND_BACKSLASH_AND_SLASH) 52 | if ( s[pos] == ':' || s[pos] == '\\' || 53 | s[pos] == '/' ) 54 | #elif defined(SID_FS_IS_COLON_AND_SLASH) 55 | if ( s[pos] == ':' || s[pos] == '/' ) 56 | #elif defined(SID_FS_IS_SLASH) 57 | if ( s[pos] == '/' ) 58 | #elif defined(SID_FS_IS_BACKSLASH) 59 | if ( s[pos] == '\\' ) 60 | #elif defined(SID_FS_IS_COLON) 61 | if ( s[pos] == ':' ) 62 | #else 63 | #error Missing file/path separator definition. 64 | #endif 65 | { 66 | last_slash_pos = pos; 67 | } 68 | } 69 | return( &s[last_slash_pos +1] ); 70 | } 71 | 72 | // Return pointer to file name position in complete path. 73 | // Special version: file separator = forward slash. 74 | char* SidTuneTools::slashedFileNameWithoutPath(char* s) 75 | { 76 | int last_slash_pos = -1; 77 | for ( uint_least32_t pos = 0; pos < strlen(s); pos++ ) 78 | { 79 | if ( s[pos] == '/' ) 80 | { 81 | last_slash_pos = pos; 82 | } 83 | } 84 | return( &s[last_slash_pos +1] ); 85 | } 86 | 87 | // Return pointer to file name extension in path. 88 | // The backwards-version. 89 | char* SidTuneTools::fileExtOfPath(char* s) 90 | { 91 | uint_least32_t last_dot_pos = strlen(s); // assume no dot and append 92 | for ( int pos = last_dot_pos; pos >= 0; --pos ) 93 | { 94 | if ( s[pos] == '.' ) 95 | { 96 | last_dot_pos = pos; 97 | break; 98 | } 99 | } 100 | return( &s[last_dot_pos] ); 101 | } 102 | 103 | // Parse input string stream. Read and convert a hexa-decimal number up 104 | // to a ``,'' or ``:'' or ``\0'' or end of stream. 105 | uint_least32_t SidTuneTools::readHex( std::istringstream& hexin ) 106 | { 107 | uint_least32_t hexLong = 0; 108 | char c; 109 | do 110 | { 111 | hexin >> c; 112 | if ( !hexin ) 113 | break; 114 | if (( c != ',') && ( c != ':' ) && ( c != 0 )) 115 | { 116 | // machine independed to_upper 117 | c &= 0xdf; 118 | ( c < 0x3a ) ? ( c &= 0x0f ) : ( c -= ( 0x41 - 0x0a )); 119 | hexLong <<= 4; 120 | hexLong |= (uint_least32_t)c; 121 | } 122 | else 123 | { 124 | if ( c == 0 ) 125 | hexin.putback(c); 126 | break; 127 | } 128 | } while ( hexin ); 129 | return hexLong; 130 | } 131 | 132 | // Parse input string stream. Read and convert a decimal number up 133 | // to a ``,'' or ``:'' or ``\0'' or end of stream. 134 | uint_least32_t SidTuneTools::readDec( std::istringstream& decin ) 135 | { 136 | uint_least32_t hexLong = 0; 137 | char c; 138 | do 139 | { 140 | decin >> c; 141 | if ( !decin ) 142 | break; 143 | if (( c != ',') && ( c != ':' ) && ( c != 0 )) 144 | { 145 | c &= 0x0f; 146 | hexLong *= 10; 147 | hexLong += (uint_least32_t)c; 148 | } 149 | else 150 | { 151 | if ( c == 0 ) 152 | decin.putback(c); 153 | break; 154 | } 155 | } while ( decin ); 156 | return hexLong; 157 | } 158 | 159 | // Search terminated string for next newline sequence. 160 | // Skip it and return pointer to start of next line. 161 | const char* SidTuneTools::returnNextLine(const char* s, uint_least32_t len) 162 | { 163 | // Unix: LF = 0x0A 164 | // Windows, DOS: CR,LF = 0x0D,0x0A 165 | // Mac: CR = 0x0D 166 | char c; 167 | while (len && ((c = *s) != 0)) 168 | { 169 | len--; 170 | s++; // skip read character 171 | if (c == 0x0A) 172 | { 173 | break; // LF found 174 | } 175 | else if (c == 0x0D) 176 | { 177 | if (len && (*s == 0x0A)) 178 | { 179 | len--; 180 | s++; // CR,LF found, skip LF 181 | } 182 | break; // CR or CR,LF found 183 | } 184 | } 185 | if ((len == 0) || (*s == 0)) // end of string ? 186 | { 187 | return 0; // no next line available 188 | } 189 | return s; // next line available 190 | } 191 | 192 | // Skip any characters in an input string stream up to '='. 193 | void SidTuneTools::skipToEqu( std::istringstream& parseStream ) 194 | { 195 | char c; 196 | do 197 | { 198 | parseStream >> c; 199 | } 200 | while ( c != '=' ); 201 | } 202 | 203 | void SidTuneTools::copyStringValueToEOL(const char* pSourceStr, char* pDestStr, int DestMaxLen ) 204 | { 205 | // Start at first character behind '='. 206 | while ( *pSourceStr != '=' ) 207 | { 208 | pSourceStr++; 209 | } 210 | pSourceStr++; // Skip '='. 211 | while (( DestMaxLen > 0 ) && ( *pSourceStr != 0 ) 212 | && ( *pSourceStr != '\n' ) && ( *pSourceStr != '\r' )) 213 | { 214 | *pDestStr++ = *pSourceStr++; 215 | DestMaxLen--; 216 | } 217 | *pDestStr++ = 0; 218 | } 219 | -------------------------------------------------------------------------------- /src/libpsid64/sidid.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | psid64 - create a C64 executable from a PSID file 4 | Copyright (C) 2015 Roland Hermans 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | ////////////////////////////////////////////////////////////////////////////// 22 | // I N C L U D E S 23 | ////////////////////////////////////////////////////////////////////////////// 24 | 25 | #include "sidid.h" 26 | 27 | #include 28 | #include 29 | 30 | 31 | ////////////////////////////////////////////////////////////////////////////// 32 | // G L O B A L D A T A 33 | ////////////////////////////////////////////////////////////////////////////// 34 | 35 | 36 | ////////////////////////////////////////////////////////////////////////////// 37 | // L O C A L D E F I N I T I O N S 38 | ////////////////////////////////////////////////////////////////////////////// 39 | 40 | 41 | 42 | ////////////////////////////////////////////////////////////////////////////// 43 | // L O C A L D A T A 44 | ////////////////////////////////////////////////////////////////////////////// 45 | 46 | 47 | ////////////////////////////////////////////////////////////////////////////// 48 | // L O C A L F U N C T I O N S 49 | ////////////////////////////////////////////////////////////////////////////// 50 | 51 | 52 | ////////////////////////////////////////////////////////////////////////////// 53 | // G L O B A L F U N C T I O N S 54 | ////////////////////////////////////////////////////////////////////////////// 55 | 56 | void SidId::Pattern::clear() 57 | { 58 | m_values.clear(); 59 | } 60 | 61 | 62 | void SidId::Pattern::pushValue(uint_least16_t value) 63 | { 64 | m_values.push_back(value); 65 | } 66 | 67 | 68 | bool SidId::Pattern::match(const std::vector& buffer) const 69 | { 70 | const uint_least8_t* p_buffer = &buffer.front(); 71 | const uint_least16_t* p_values = &m_values.front(); 72 | size_t buffer_size = buffer.size(); 73 | size_t i = 0; 74 | size_t j = 0; 75 | 76 | while (true) 77 | { 78 | // search for first matching byte 79 | while ((i < buffer_size) && (p_buffer[i] != p_values[j])) 80 | { 81 | ++i; 82 | } 83 | if (i == buffer_size) 84 | { 85 | break; 86 | } 87 | size_t saved_i = i; 88 | size_t saved_j = j; 89 | 90 | // check if subsequent bytes match as well 91 | while ((i < buffer_size) 92 | && ((p_buffer[i] == p_values[j]) 93 | || (p_values[j] == MATCH_WILDCARD_ONE))) 94 | { 95 | ++i; 96 | ++j; 97 | } 98 | 99 | if (p_values[j] == MATCH_END) 100 | { 101 | // all parts matched 102 | break; 103 | } 104 | else if (p_values[j] == MATCH_WILDCARD_MULTIPLE) 105 | { 106 | // this part did match, continue with next part 107 | ++j; 108 | } 109 | else 110 | { 111 | // retry matching after first byte of current match attempt 112 | i = saved_i + 1; 113 | j = saved_j; 114 | } 115 | } 116 | 117 | return (p_values[j] == MATCH_END); 118 | } 119 | 120 | 121 | SidId::Player::Player(const std::string& name) : m_name(name) 122 | { 123 | // do nothing 124 | } 125 | 126 | 127 | void SidId::Player::addPattern(const Pattern& pattern) 128 | { 129 | m_patterns.push_back(pattern); 130 | } 131 | 132 | 133 | const std::string& SidId::Player::name() const 134 | { 135 | return m_name; 136 | } 137 | 138 | 139 | bool SidId::Player::match(const std::vector& buffer) const 140 | { 141 | for (std::vector::const_iterator iter = m_patterns.begin(); 142 | iter != m_patterns.end(); ++iter) 143 | { 144 | if (iter->match(buffer)) 145 | { 146 | return true; 147 | } 148 | } 149 | return false; 150 | } 151 | 152 | 153 | std::string SidId::trim(const std::string& str, const std::string& whitespace) 154 | { 155 | const size_t begin_pos = str.find_first_not_of(whitespace); 156 | if (begin_pos == std::string::npos) 157 | { 158 | return ""; 159 | } 160 | const size_t end_pos = str.find_last_not_of(whitespace); 161 | return str.substr(begin_pos, end_pos - begin_pos + 1); 162 | } 163 | 164 | 165 | bool SidId::readConfigFile(const std::string& filename) 166 | { 167 | m_players.clear(); 168 | std::ifstream f; 169 | f.open(filename.c_str()); 170 | if (!f) 171 | { 172 | return false; 173 | } 174 | std::string line; 175 | while (std::getline(f, line)) 176 | { 177 | line = trim(line); 178 | if (!line.empty()) 179 | { 180 | Pattern pattern; 181 | std::istringstream line_ss(line); 182 | std::string token; 183 | while (line_ss >> token) 184 | { 185 | if (token == "??") 186 | { 187 | pattern.pushValue(MATCH_WILDCARD_ONE); 188 | } 189 | else if (token == "AND") 190 | { 191 | pattern.pushValue(MATCH_WILDCARD_MULTIPLE); 192 | } 193 | else if (token == "END") 194 | { 195 | pattern.pushValue(MATCH_END); 196 | if (m_players.empty()) 197 | { 198 | // first player definition did not start with a name 199 | return false; 200 | } 201 | m_players.back().addPattern(pattern); 202 | pattern.clear(); 203 | } 204 | else if ((token.size() == 2) 205 | && isxdigit(token[0]) && isxdigit(token[1])) 206 | { 207 | uint_least16_t i; 208 | std::stringstream token_ss(token); 209 | token_ss >> std::hex >> i; 210 | 211 | pattern.pushValue(i); 212 | } 213 | else 214 | { 215 | // start of new player definition 216 | m_players.push_back(Player(token)); 217 | } 218 | } 219 | } 220 | } 221 | 222 | return true; 223 | } 224 | 225 | 226 | std::string SidId::identify(const std::vector& buffer) 227 | { 228 | for (std::vector::const_iterator iter = m_players.begin(); 229 | iter != m_players.end(); ++iter) 230 | { 231 | if (iter->match(buffer)) 232 | { 233 | return iter->name(); 234 | } 235 | } 236 | 237 | return ""; 238 | } 239 | -------------------------------------------------------------------------------- /include/sidplay/utils/libini.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /*************************************************************************** 3 | libini.h - Header file of functions to 4 | manipulate an ini file. 5 | ------------------- 6 | begin : Fri Apr 21 2000 7 | copyright : (C) 2000 by Simon White 8 | email : s_a_white@email.com 9 | ***************************************************************************/ 10 | 11 | /*************************************************************************** 12 | * * 13 | * This program is free software; you can redistribute it and/or modify * 14 | * it under the terms of the GNU General Public License as published by * 15 | * the Free Software Foundation; either version 2 of the License, or * 16 | * (at your option) any later version. * 17 | * * 18 | ***************************************************************************/ 19 | 20 | #ifndef _libini_h_ 21 | #define _libini_h_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #include 28 | 29 | #define INI_ADD_EXTRAS 30 | #define INI_ADD_LIST_SUPPORT 31 | 32 | #ifdef SWIG 33 | %ignore ini_readString; 34 | %include typemaps.i 35 | %apply int *INOUT { int *value }; 36 | %apply long *INOUT { long *value }; 37 | %apply double *INOUT { double *value }; 38 | %rename (ini_readString) ini_readFileToBuffer; 39 | #define INI_EXTERN 40 | #define INI_STATIC 41 | #endif /* SWIG */ 42 | 43 | /*#ifdef _WINDOWS 44 | # define INI_LINKAGE __stdcall 45 | #else*/ 46 | # define INI_LINKAGE 47 | /*#endif*/ 48 | 49 | /* DLL building support on win32 hosts */ 50 | #ifndef INI_EXTERN 51 | # ifdef DLL_EXPORT /* defined by libtool (if required) */ 52 | # define INI_EXTERN __declspec(dllexport) 53 | # endif 54 | # ifdef LIBINI_DLL_IMPORT /* define if linking with this dll */ 55 | # define INI_EXTERN extern __declspec(dllimport) 56 | # endif 57 | # ifndef INI_EXTERN /* static linking or !_WIN32 */ 58 | # define INI_EXTERN extern 59 | # endif 60 | #endif 61 | 62 | #ifndef INI_ADD_EXTRAS 63 | #undef INI_ADD_LIST_SUPPORT 64 | #endif 65 | 66 | /* Compatibility with future C++ code */ 67 | #ifndef ini_fd_t 68 | #define ini_fd_t ini_fd_t 69 | typedef void* ini_fd_t; 70 | #endif 71 | 72 | 73 | /* Rev 1.2 Added new fuction */ 74 | INI_EXTERN ini_fd_t INI_LINKAGE ini_open (const char *name, const char *mode, 75 | const char *comment); 76 | INI_EXTERN int INI_LINKAGE ini_close (ini_fd_t fd); 77 | INI_EXTERN int INI_LINKAGE ini_flush (ini_fd_t fd); 78 | INI_EXTERN int INI_LINKAGE ini_delete (ini_fd_t fd); 79 | 80 | /* Rev 1.2 Added these functions to make life a bit easier, can still be implemented 81 | * through ini_writeString though. */ 82 | INI_EXTERN int INI_LINKAGE ini_locateKey (ini_fd_t fd, const char *key); 83 | INI_EXTERN int INI_LINKAGE ini_locateHeading (ini_fd_t fd, const char *heading); 84 | INI_EXTERN int INI_LINKAGE ini_deleteKey (ini_fd_t fd); 85 | INI_EXTERN int INI_LINKAGE ini_deleteHeading (ini_fd_t fd); 86 | 87 | INI_EXTERN const char * INI_LINKAGE ini_currentKey (ini_fd_t fd); 88 | INI_EXTERN const char * INI_LINKAGE ini_currentHeading (ini_fd_t fd); 89 | 90 | /* Returns the number of bytes required to be able to read the key as a 91 | * string from the file. (1 should be added to this length to account 92 | * for a NULL character). If delimiters are used, returns the length 93 | * of the next data element in the key to be read */ 94 | INI_EXTERN int INI_LINKAGE ini_dataLength (ini_fd_t fd); 95 | 96 | /* Default Data Type Operations 97 | * Arrays implemented to help with reading, for writing you should format the 98 | * complete array as a string and perform an ini_writeString. */ 99 | INI_EXTERN int INI_LINKAGE ini_readString (ini_fd_t fd, char *str, size_t size); 100 | INI_EXTERN int INI_LINKAGE ini_writeString (ini_fd_t fd, const char *str); 101 | INI_EXTERN int INI_LINKAGE ini_readInt (ini_fd_t fd, int *value); 102 | 103 | 104 | #ifdef INI_ADD_EXTRAS 105 | /* Read Operations */ 106 | INI_EXTERN int INI_LINKAGE ini_readLong (ini_fd_t fd, long *value); 107 | INI_EXTERN int INI_LINKAGE ini_readDouble (ini_fd_t fd, double *value); 108 | INI_EXTERN int INI_LINKAGE ini_readBool (ini_fd_t fd, int *value); 109 | 110 | /* Write Operations */ 111 | INI_EXTERN int INI_LINKAGE ini_writeInt (ini_fd_t fd, int value); 112 | INI_EXTERN int INI_LINKAGE ini_writeLong (ini_fd_t fd, long value); 113 | INI_EXTERN int INI_LINKAGE ini_writeDouble (ini_fd_t fd, double value); 114 | INI_EXTERN int INI_LINKAGE ini_writeBool (ini_fd_t fd, int value); 115 | 116 | /* Extra Functions */ 117 | INI_EXTERN int INI_LINKAGE ini_append (ini_fd_t fddst, ini_fd_t fdsrc); 118 | #endif /* INI_ADD_EXTRAS */ 119 | 120 | 121 | #ifdef INI_ADD_LIST_SUPPORT 122 | /* Rev 1.1 Added - List Operations (Used for read operations only) 123 | * Be warned, once delimiters are set, every key that is read will be checked for the 124 | * presence of sub strings. This will incure a speed hit and therefore once a line 125 | * has been read and list/array functionality is not required, set delimiters 126 | * back to NULL. 127 | */ 128 | 129 | /* Returns the number of elements in an list being seperated by the provided delimiters */ 130 | INI_EXTERN int INI_LINKAGE ini_listLength (ini_fd_t fd); 131 | /* Change delimiters, default "" */ 132 | INI_EXTERN int INI_LINKAGE ini_listDelims (ini_fd_t fd, const char *delims); 133 | /* Set index to access in a list. When read the index will automatically increment */ 134 | INI_EXTERN int INI_LINKAGE ini_listIndex (ini_fd_t fd, unsigned long index); 135 | #endif /* INI_ADD_LIST_SUPPORT */ 136 | 137 | 138 | #ifdef SWIG 139 | %{ 140 | #include 141 | #include 142 | #define INI_STATIC static 143 | typedef struct 144 | { 145 | char *buffer; 146 | size_t size; 147 | } ini_buffer_t; 148 | %} 149 | 150 | %inline %{ 151 | /************************************************************* 152 | * SWIG helper functions to create C compatible string buffers 153 | *************************************************************/ 154 | INI_STATIC ini_buffer_t *ini_createBuffer (unsigned int size) 155 | { 156 | ini_buffer_t *b; 157 | /* Allocate memory to structure */ 158 | if (size == ( ((unsigned) -1 << 1) >> 1 )) 159 | return 0; /* Size is too big */ 160 | b = malloc (sizeof (ini_buffer_t)); 161 | if (!b) 162 | return 0; 163 | 164 | /* Allocate memory to buffer */ 165 | b->buffer = malloc (sizeof (char) * (size + 1)); 166 | if (!b->buffer) 167 | { 168 | free (b); 169 | return 0; 170 | } 171 | b->size = size; 172 | b->buffer[0] = '\0'; 173 | 174 | /* Returns address to tcl */ 175 | return b; 176 | } 177 | 178 | INI_STATIC void ini_deleteBuffer (ini_buffer_t *buffer) 179 | { 180 | if (!buffer) 181 | return; 182 | free (buffer->buffer); 183 | free (buffer); 184 | } 185 | 186 | INI_STATIC int ini_readFileToBuffer (ini_fd_t fd, ini_buffer_t *buffer) 187 | { 188 | if (!buffer) 189 | return -1; 190 | return ini_readString (fd, buffer->buffer, buffer->size + 1); 191 | } 192 | 193 | INI_STATIC char *ini_getBuffer (ini_buffer_t *buffer) 194 | { 195 | if (!buffer) 196 | return ""; 197 | return buffer->buffer; 198 | } 199 | 200 | INI_STATIC int ini_setBuffer (ini_buffer_t *buffer, const char *str) 201 | { 202 | size_t len; 203 | if (!buffer) 204 | return -1; 205 | len = strlen (str); 206 | if (len > buffer->size) 207 | len = buffer->size; 208 | 209 | memcpy (buffer->buffer, str, len); 210 | buffer->buffer[len] = '\0'; 211 | return len; 212 | } 213 | %} 214 | #endif /* SWIG */ 215 | 216 | #ifdef __cplusplus 217 | } 218 | #endif 219 | 220 | #endif /* _libini_h_ */ 221 | -------------------------------------------------------------------------------- /src/sidtune/PP20.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | * /home/ms/files/source/libsidtune/RCS/PP20.cpp,v 4 | * 5 | * PowerPacker (AMIGA) "PP20" format decompressor. 6 | * Copyright (C) Michael Schwendt 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | */ 22 | 23 | #include "PP20.h" 24 | 25 | #include 26 | #ifdef PP20_HAVE_EXCEPTIONS 27 | #include 28 | #endif 29 | 30 | /* Read a big-endian 32-bit word from four bytes in memory. 31 | No endian-specific optimizations applied. */ 32 | inline udword_ppt readBEdword(const ubyte_ppt ptr[4]) 33 | { 34 | return ( (((udword_ppt)ptr[0])<<24) + (((udword_ppt)ptr[1])<<16) + 35 | (((udword_ppt)ptr[2])<<8) + ((udword_ppt)ptr[3]) ); 36 | } 37 | 38 | const char _pp20_txt_packeddatacorrupt[] = "PowerPacker: Packed data is corrupt"; 39 | const char _pp20_txt_unrecognized[] = "PowerPacker: Unrecognized compression method"; 40 | const char _pp20_txt_uncompressed[] = "Not compressed with PowerPacker (PP20)"; 41 | const char _pp20_txt_notenoughmemory[] = "Not enough free memory"; 42 | const char _pp20_txt_fast[] = "PowerPacker: fast compression"; 43 | const char _pp20_txt_mediocre[] = "PowerPacker: mediocre compression"; 44 | const char _pp20_txt_good[] = "PowerPacker: good compression"; 45 | const char _pp20_txt_verygood[] = "PowerPacker: very good compression"; 46 | const char _pp20_txt_best[] = "PowerPacker: best compression"; 47 | 48 | const char* PP20::PP_ID = "PP20"; 49 | 50 | PP20::PP20() : 51 | efficiency(), 52 | sourceBeg(NULL), 53 | readPtr(NULL), 54 | destBeg(NULL), 55 | writePtr(NULL), 56 | current(0), 57 | bits(0), 58 | globalError(false) 59 | { 60 | statusString = _pp20_txt_uncompressed; 61 | } 62 | 63 | bool PP20::isCompressed(const void* source, const udword_ppt size) 64 | { 65 | // Check minimum input size, PP20 ID, and efficiency table. 66 | if ( size<8 ) 67 | { 68 | return false; 69 | } 70 | // We hope that every file with a valid signature and a valid 71 | // efficiency table is PP-compressed actually. 72 | const char* idPtr = (const char*)source; 73 | if ( strncmp(idPtr,PP_ID,4) != 0 ) 74 | { 75 | statusString = _pp20_txt_uncompressed; 76 | return false; 77 | } 78 | return checkEfficiency(idPtr+4); 79 | } 80 | 81 | bool PP20::checkEfficiency(const void* source) 82 | { 83 | const udword_ppt PP_BITS_FAST = 0x09090909; 84 | const udword_ppt PP_BITS_MEDIOCRE = 0x090a0a0a; 85 | const udword_ppt PP_BITS_GOOD = 0x090a0b0b; 86 | const udword_ppt PP_BITS_VERYGOOD = 0x090a0c0c; 87 | const udword_ppt PP_BITS_BEST = 0x090a0c0d; 88 | 89 | // Copy efficiency table. 90 | memcpy(efficiency,(const ubyte_ppt*)source,4); 91 | udword_ppt eff = readBEdword(efficiency); 92 | if (( eff != PP_BITS_FAST ) && 93 | ( eff != PP_BITS_MEDIOCRE ) && 94 | ( eff != PP_BITS_GOOD ) && 95 | ( eff != PP_BITS_VERYGOOD ) && 96 | ( eff != PP_BITS_BEST )) 97 | { 98 | statusString = _pp20_txt_unrecognized; 99 | return false; 100 | } 101 | 102 | // Define string describing compression encoding used. 103 | switch ( eff) 104 | { 105 | case PP_BITS_FAST: 106 | statusString = _pp20_txt_fast; 107 | break; 108 | case PP_BITS_MEDIOCRE: 109 | statusString = _pp20_txt_mediocre; 110 | break; 111 | case PP_BITS_GOOD: 112 | statusString = _pp20_txt_good; 113 | break; 114 | case PP_BITS_VERYGOOD: 115 | statusString = _pp20_txt_verygood; 116 | break; 117 | case PP_BITS_BEST: 118 | statusString = _pp20_txt_best; 119 | break; 120 | } 121 | 122 | return true; 123 | } 124 | 125 | // Move four bytes to Motorola big-endian double-word. 126 | inline void PP20::bytesTOdword() 127 | { 128 | readPtr -= 4; 129 | if ( readPtr < sourceBeg ) 130 | { 131 | statusString = _pp20_txt_packeddatacorrupt; 132 | globalError = true; 133 | } 134 | else 135 | { 136 | current = readBEdword(readPtr); 137 | } 138 | } 139 | 140 | inline udword_ppt PP20::readBits(int count) 141 | { 142 | udword_ppt data = 0; 143 | // read 'count' bits of packed data 144 | for (; count > 0; count--) 145 | { 146 | // equal to shift left 147 | data += data; 148 | // merge bit 0 149 | data |= (current&1); 150 | current >>= 1; 151 | if (--bits == 0) 152 | { 153 | bytesTOdword(); 154 | bits = 32; 155 | } 156 | } 157 | return data; 158 | } 159 | 160 | inline void PP20::bytes() 161 | { 162 | udword_ppt count, add; 163 | count = (add = readBits(2)); 164 | while (add == 3) 165 | { 166 | add = readBits(2); 167 | count += add; 168 | } 169 | for ( ++count; count > 0 ; count--) 170 | { 171 | if (writePtr > destBeg) 172 | { 173 | *(--writePtr) = (ubyte_ppt)readBits(8); 174 | } 175 | else 176 | { 177 | statusString = _pp20_txt_packeddatacorrupt; 178 | globalError = true; 179 | } 180 | } 181 | } 182 | 183 | inline void PP20::sequence() 184 | { 185 | udword_ppt offset; 186 | udword_ppt length = readBits(2); // is length-2 187 | int offsetBitLen = (int)efficiency[length]; 188 | length += 2; 189 | if ( length != 5 ) 190 | offset = readBits( offsetBitLen ); 191 | else 192 | { 193 | if ( readBits(1) == 0 ) 194 | offsetBitLen = 7; 195 | offset = readBits( offsetBitLen ); 196 | udword_ppt add = readBits(3); 197 | length += add; 198 | while ( add == 7 ) 199 | { 200 | add = readBits(3); 201 | length += add; 202 | } 203 | } 204 | for ( ; length > 0 ; length-- ) 205 | { 206 | if ( writePtr > destBeg ) 207 | { 208 | --writePtr; 209 | *writePtr = *(writePtr+1+offset); 210 | } 211 | else 212 | { 213 | statusString = _pp20_txt_packeddatacorrupt; 214 | globalError = true; 215 | } 216 | } 217 | } 218 | 219 | udword_ppt PP20::decompress(const void* source, 220 | udword_ppt size, 221 | ubyte_ppt** destRef) 222 | { 223 | globalError = false; // assume no error 224 | 225 | sourceBeg = (const ubyte_ppt*)source; 226 | readPtr = sourceBeg; 227 | 228 | if ( !isCompressed(readPtr,size) ) 229 | { 230 | return 0; 231 | } 232 | 233 | // Uncompressed size is stored at end of source file. 234 | // Backwards decompression. 235 | readPtr += (size-4); 236 | 237 | udword_ppt lastDword = readBEdword(readPtr); 238 | // Uncompressed length in bits 31-8 of last dword. 239 | udword_ppt outputLen = lastDword>>8; 240 | 241 | // Allocate memory for output data. 242 | ubyte_ppt* dest; 243 | #ifdef PP20_HAVE_EXCEPTIONS 244 | if (( dest = new(std::nothrow) ubyte_ppt[outputLen]) == 0 ) 245 | #else 246 | if (( dest = new ubyte_ppt[outputLen]) == 0 ) 247 | #endif 248 | { 249 | statusString = _pp20_txt_notenoughmemory; 250 | return 0; 251 | } 252 | 253 | // Lowest dest. address for range-checks. 254 | destBeg = dest; 255 | // Put destptr to end of uncompressed data. 256 | writePtr = dest+outputLen; 257 | 258 | // Read number of unused bits in 1st data dword 259 | // from lowest bits 7-0 of last dword. 260 | bits = 32 - (lastDword&0xFF); 261 | 262 | // Main decompression loop. 263 | bytesTOdword(); 264 | if ( bits != 32 ) 265 | current >>= (32-bits); 266 | do 267 | { 268 | if ( readBits(1) == 0 ) 269 | bytes(); 270 | if ( writePtr > dest ) 271 | sequence(); 272 | if ( globalError ) 273 | { 274 | // statusString already set. 275 | outputLen = 0; // unsuccessful decompression 276 | break; 277 | } 278 | } while ( writePtr > dest ); 279 | 280 | // Finished. 281 | 282 | if (outputLen > 0) // successful 283 | { 284 | // Free any previously existing destination buffer. 285 | if ( *destRef != 0 ) 286 | { 287 | delete[] *destRef; 288 | } 289 | *destRef = dest; 290 | } 291 | else 292 | { 293 | delete[] dest; 294 | } 295 | 296 | return outputLen; 297 | } 298 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PSID64 README 2 | ============= 3 | 4 | Introduction 5 | ------------ 6 | 7 | PSID64 is a program that automatically generates a C64 self extracting 8 | executable from a PSID file. The executable contains the PSID data, a 9 | pre-relocated player and may also - if there is enough space available in the 10 | C64 environment - contain a demonstration program with information about the 11 | PSID file. 12 | 13 | PSID files contain music code and data originally generated on the Commodore 64 14 | (C64). If you're new to PSID files please refer to the introduction chapter of 15 | the High Voltage SID Collection documentation for a brief introduction into SID 16 | music. 17 | 18 | Before PSID64, playing PSID files on a C64 or a C64 emulator has been a rather 19 | frustrating experience. The fundamental problem of where to locate the PSID 20 | driver has simply not been appropriately addressed. Actually, having a PSID 21 | file play at all has been pure luck, since there has been made no attempt to 22 | find a memory range that is not written to by the music code. Not surprisingly, 23 | a large number of PSID files could not be played at all using existing C64 24 | computers and C64 emulator SID players. 25 | 26 | The document "Proposal for C64 compatible PSID files", written by Dag Lem and 27 | Simon White extends the PSID format with relocation information. PSID64 is the 28 | first implementation of a PSID player intended for playback on a real C64 or 29 | C64 environment that uses this relocation information stored in the PSID 30 | header. 31 | 32 | 33 | Usage 34 | ----- 35 | 36 | PSID64 is invoked from the command line as follows: 37 | 38 | psid64 [OPTION]... PSID_FILE... 39 | 40 | where PSID_FILE is the names of one or more the PSID files or directories. 41 | 42 | If a name designates a file, the resulting C64 executable is written to the 43 | current directory, or to the file or directory specified by the -o option. 44 | 45 | If a name designates a directory, PSID64 processes all the .sid files in that 46 | directory and all of its subdirectories. Without using the -o option, each 47 | resulting C64 executable is written to the same location as its source .sid 48 | file. With the -o option, the basename of the PSID_FILE name is created in the 49 | specified output directory. If the PSID_FILE name ends in a slash or backslash, 50 | or if the specified output directory does not yet exist, this changes the 51 | behavior and the basename directory is not created. The subdirectories of 52 | PSID_FILE that contain .sid files are created in the output location. 53 | 54 | Options available: 55 | 56 | -b, --blank-screen use a minimal driver that blanks the screen 57 | -c, --compress compress output file with Exomizer 58 | -g, --global-comment include the global comment STIL text 59 | -i, --initial-song=NUM override the initial song to play 60 | -n, --no-driver convert SID to C64 program file without driver code 61 | -o, --output=PATH specify output file or directory 62 | -p, --player-id=FILE specify SID ID config file for player identification 63 | -r, --root=PATH specify HVSC root directory 64 | -s, --songlengths=FILE specify HVSC song length database 65 | -t, --theme=THEME specify a visual theme for the driver 66 | use `help' to show the list of available themes 67 | -v, --verbose explain what is being done 68 | -h, --help display this help and exit 69 | -V, --version output version information and exit 70 | 71 | The HVSC path recognition is a bit rudimentary. For this to work properly it is 72 | required to include the HVSC path in the filename of the files or directories 73 | to be converted. If the path strings don't match, the STIL info will not be 74 | included in the generated .prg files. 75 | 76 | 77 | Example usage 78 | ------------- 79 | 80 | Convert a single file and write the output to the current directory: 81 | 82 | psid64 input.sid 83 | 84 | Convert a single file and write the output to output.prg: 85 | 86 | psid64 -o output.prg input.sid 87 | 88 | Convert multiple files, write all the outputs to the current directory: 89 | 90 | psid64 input1.sid a/input2.sid b/input3.sid 91 | 92 | Convert all files in current directory and all subdirectories: 93 | 94 | psid64 . 95 | 96 | On a UNIX-like system, convert the complete HVSC collection with STIL, song 97 | length, and player ID information to the directory hvsc_as_prg: 98 | 99 | psid64 -v -c -p sidid.cfg -r ~/C64Music -o hvsc_as_prg ~/C64Music/ 100 | 101 | On a Windows-like system, convert the complete HVSC collection with STIL, song 102 | length, and player ID information to the directory hvsc_as_prg: 103 | 104 | psid64 -v -c -p sidid.cfg -r C:\C64Music -o hvsc_as_prg C:\C64Music\ 105 | 106 | 107 | Environment variables 108 | --------------------- 109 | 110 | HVSC_BASE Default HVSC root directory 111 | HVSC_SONGLENGTHS Default HVSC song length database 112 | SIDIDCFG Default SID ID configuration file 113 | 114 | 115 | Keyboard control 116 | ---------------- 117 | 118 | 1-0, A-Z Select song 1-36 119 | + Select next song (2) 120 | - Select previous song (2) 121 | INST/DEL Toggle screen blanking on/off (2) 122 | RUN/STOP Stop playback 123 | LEFT ARROW Fast forward (1) 124 | SHIFT LEFT / LOCK Show rastertime used by player (1) 125 | CONTROL + CBM + DEL Reset computer (2) 126 | 127 | (1) not available for custom players (i.e. play address is $0000). 128 | 129 | (2) not available in minimal driver (i.e. the driver that blanks the screen) 130 | 131 | 132 | Joystick control 133 | ---------------- 134 | 135 | Except when using the minimal driver, a joystick connected to port two can be 136 | used to control some functions of the player. 137 | 138 | Up Select next song 139 | Down Select previous song 140 | Left Stop playback 141 | Right Restart current song 142 | Fire button Fast forward (1) 143 | 144 | (1) not available for custom players (i.e. play address is $0000). 145 | 146 | 147 | Credits 148 | ------- 149 | 150 | PSID64 contains the following contributed or derived work. In the order they 151 | first supplied contributions or code was derived from their work: 152 | 153 | Dag Lem PSID driver reference implementation 154 | Simon White SidUtils library 155 | Michael Schwendt SidTune library 156 | LaLa STILView library 157 | Magnus Lind Exomizer compressor 158 | 159 | Credit where credit is due, so if I missed anyone please let me know. 160 | 161 | 162 | Known problems and limitations 163 | ------------------------------ 164 | 165 | At least two free 256 byte pages are required for the minimal driver and at 166 | least nine 256 byte pages are required for the extended driver. 167 | 168 | The accuracy of the clock cannot be guaranteed while fast forwarding a song. 169 | This is due to the fact that the driver does not know how often the play 170 | function is called. PSID64 assumes that the play function called 50 times per 171 | second on a PAL machine and 60 times per second on an NTSC machine. 172 | 173 | The scroller might show some artifacts when interrupts occur just before or just 174 | after the scroller area. To guarantee maximal compatibility with SID tunes it's 175 | neither feasible nor desired to program a scroller based on code that generates 176 | interrupts. Any ideas on how to improve the scroller code are welcome. 177 | 178 | 179 | Other tools 180 | ----------- 181 | 182 | Andre Fachat's relocating 6502 cross assembler XA is used to create the 183 | relocatable driver code. 184 | 185 | https://www.floodgap.com/retrotech/xa/ 186 | 187 | The DJGPP cross-compiler djcross-gcc-12.2.0 has been used to build the MS-DOS 188 | executable. 189 | 190 | https://www.delorie.com/djgpp/ 191 | 192 | https://www.delorie.com/pub/djgpp/rpms/ 193 | 194 | UPX is a free, portable, extendable, high-performance executable packer for 195 | several different executable formats. It has been used to create the compressed 196 | executable of the MS-DOS release. 197 | 198 | https://upx.sourceforge.net/ 199 | 200 | The Fedora MinGW-w64 cross-compiler environment has been used to build the 201 | Windows 32-bit and 64-bit executables. 202 | 203 | https://fedoraproject.org/wiki/MinGW 204 | 205 | https://www.mingw-w64.org/ 206 | 207 | 208 | Copyright and licensing 209 | ----------------------- 210 | 211 | SPDX-License-Identifier: GPL-2.0-or-later 212 | 213 | Copyright 2001-2023 Roland Hermans 214 | 215 | This program is free software; you can redistribute it and/or 216 | modify it under the terms of the GNU General Public License 217 | as published by the Free Software Foundation; either version 2 218 | of the License, or (at your option) any later version. 219 | 220 | This program is distributed in the hope that it will be useful, 221 | but WITHOUT ANY WARRANTY; without even the implied warranty of 222 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 223 | GNU General Public License for more details. 224 | 225 | You should have received a copy of the GNU General Public License 226 | along with this program; if not, write to the Free Software 227 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 228 | 229 | 230 | Website 231 | ------- 232 | 233 | https://www.psid64.org/ or https://psid64.sourceforge.io/ 234 | -------------------------------------------------------------------------------- /src/libpsid64/reloc65.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | /* 3 | xa65 - 6502 cross assembler and utility suite 4 | reloc65 - relocates 'o65' files 5 | Copyright (C) 1997 André Fachat (a.fachat@physik.tu-chemnitz.de) 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | */ 21 | 22 | /* 23 | Modified by Dag Lem 24 | Relocate and extract text segment from memory buffer instead of file. 25 | For use with VICE VSID. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "reloc65.h" 33 | 34 | 35 | #define BUF (9*2+8) /* 16 bit header */ 36 | 37 | struct file65 { 38 | char *fname; 39 | size_t fsize; 40 | unsigned char *buf; 41 | int tbase, tlen, dbase, dlen, bbase, blen, zbase, zlen; 42 | int tdiff, ddiff, bdiff, zdiff; 43 | int nundef; 44 | char **ud; 45 | unsigned char *segt; 46 | unsigned char *segd; 47 | unsigned char *utab; 48 | unsigned char *rttab; 49 | unsigned char *rdtab; 50 | unsigned char *extab; 51 | globals_t *globals; 52 | }; 53 | 54 | 55 | int read_options(const unsigned char *f); 56 | int read_undef(const unsigned char *f, file65 *fp); 57 | unsigned char *reloc_seg(unsigned char *f, int len, unsigned char *rtab, file65 *fp); 58 | unsigned char *reloc_globals(unsigned char *, file65 *fp); 59 | 60 | file65 file; 61 | unsigned char cmp[] = { 1, 0, 'o', '6', '5' }; 62 | 63 | int reloc65(char** buf, int* fsize, int addr, globals_t* globals) 64 | { 65 | int mode, hlen; 66 | 67 | int tflag=0, dflag=0, bflag=0, zflag=0; 68 | int tbase=0, dbase=0, bbase=0, zbase=0; 69 | int extract = 0; 70 | 71 | file.globals = globals; 72 | 73 | file.buf = (unsigned char *) *buf; 74 | file.fsize = *fsize; 75 | tflag= 1; 76 | tbase = addr; 77 | extract = 1; 78 | 79 | if (memcmp(file.buf, cmp, 5) != 0) { 80 | return 0; 81 | } 82 | 83 | mode=file.buf[7]*256+file.buf[6]; 84 | if(mode & 0x2000) { 85 | return 0; 86 | } else if(mode & 0x4000) { 87 | return 0; 88 | } 89 | 90 | hlen = BUF+read_options(file.buf+BUF); 91 | 92 | file.tbase = file.buf[ 9]*256+file.buf[ 8]; 93 | file.tlen = file.buf[11]*256+file.buf[10]; 94 | file.tdiff = tflag? tbase - file.tbase : 0; 95 | file.dbase = file.buf[13]*256+file.buf[12]; 96 | file.dlen = file.buf[15]*256+file.buf[14]; 97 | file.ddiff = dflag? dbase - file.dbase : 0; 98 | file.bbase = file.buf[17]*256+file.buf[16]; 99 | file.blen = file.buf[19]*256+file.buf[18]; 100 | file.bdiff = bflag? bbase - file.bbase : 0; 101 | file.zbase = file.buf[21]*256+file.buf[20]; 102 | file.zlen = file.buf[23]*256+file.buf[21]; 103 | file.zdiff = zflag? zbase - file.zbase : 0; 104 | 105 | file.segt = file.buf + hlen; 106 | file.segd = file.segt + file.tlen; 107 | 108 | file.utab = file.segd + file.dlen; 109 | 110 | file.rttab = file.utab + read_undef(file.utab, &file); 111 | 112 | file.rdtab = reloc_seg(file.segt, file.tlen, file.rttab, &file); 113 | file.extab = reloc_seg(file.segd, file.dlen, file.rdtab, &file); 114 | 115 | reloc_globals(file.extab, &file); 116 | 117 | if(tflag) { 118 | file.buf[ 9]= (tbase>>8)&255; 119 | file.buf[ 8]= tbase & 255; 120 | } 121 | if(dflag) { 122 | file.buf[13]= (dbase>>8)&255; 123 | file.buf[12]= dbase & 255; 124 | } 125 | if(bflag) { 126 | file.buf[17]= (bbase>>8)&255; 127 | file.buf[16]= bbase & 255; 128 | } 129 | if(zflag) { 130 | file.buf[21]= (zbase>>8)&255; 131 | file.buf[20]= zbase & 255; 132 | } 133 | 134 | /* free array with names of undefined labels */ 135 | free(file.ud); 136 | 137 | switch(extract) { 138 | case 0: /* whole file */ 139 | return 1; 140 | case 1: /* text segment */ 141 | *buf = (char *) file.segt; 142 | *fsize = file.tlen; 143 | return 1; 144 | case 2: 145 | *buf = (char *) file.segd; 146 | *fsize = file.dlen; 147 | return 1; 148 | default: 149 | return 0; 150 | } 151 | } 152 | 153 | 154 | int read_options(const unsigned char *buf) { 155 | int c, l=0; 156 | 157 | c=buf[0]; 158 | while(c && c!=EOF) { 159 | c&=255; 160 | l+=c; 161 | c=buf[l]; 162 | } 163 | return ++l; 164 | } 165 | 166 | int read_undef(const unsigned char *buf, file65 *fp) { 167 | int i, n, l = 2; 168 | 169 | n = buf[0] + 256*buf[1]; 170 | 171 | fp->nundef = n; 172 | fp->ud = (char **) calloc(n, sizeof(char *)); 173 | 174 | /*printf("number of undefined labels = %d\n", fp->nundef);*/ 175 | i=0; 176 | while(iud[i] = (char*) buf+l; 178 | /*printf("undefined label %d = '%s'\n", i, fp->ud[i]);*/ 179 | while(buf[l++]); 180 | i++; 181 | } 182 | return l; 183 | } 184 | 185 | static int find_global(const unsigned char *bp, const file65 *fp) { 186 | const char *name; 187 | int nl = bp[0]+256*bp[1]; 188 | 189 | name = fp->ud[nl]; 190 | globals_t::iterator iter = fp->globals->find(name); 191 | if (iter != fp->globals->end()) 192 | { 193 | return iter->second; 194 | } 195 | fprintf(stderr,"Warning: undefined label '%s'\n", name); 196 | return 0; 197 | } 198 | 199 | #define reldiff(s) (((s)==2)?fp->tdiff:(((s)==3)?fp->ddiff:(((s)==4)?fp->bdiff:(((s)==5)?fp->zdiff:0)))) 200 | 201 | unsigned char *reloc_seg(unsigned char *buf, int len, unsigned char *rtab, file65 *fp) { 202 | int adr = -1; 203 | int type, seg, old, n_new; 204 | /*printf("tdiff=%04x, ddiff=%04x, bdiff=%04x, zdiff=%04x\n", 205 | fp->tdiff, fp->ddiff, fp->bdiff, fp->zdiff);*/ 206 | while(*rtab) { 207 | if((*rtab & 255) == 255) { 208 | adr += 254; 209 | rtab++; 210 | } else { 211 | adr += *rtab & 255; 212 | rtab++; 213 | type = *rtab & 0xe0; 214 | seg = *rtab & 0x07; 215 | /*printf("reloc entry @ rtab=%p (offset=%d), adr=%04x, type=%02x, seg=%d\n",rtab-1, *(rtab-1), adr, type, seg);*/ 216 | rtab++; 217 | switch(type) { 218 | case 0x80: 219 | // two byte address 220 | old = buf[adr] + 256*buf[adr+1]; 221 | if (seg) n_new = old + reldiff(seg); 222 | else n_new = old + find_global(rtab, fp); 223 | buf[adr] = n_new & 255; 224 | buf[adr+1] = (n_new>>8)&255; 225 | break; 226 | case 0x40: 227 | // high byte of an address 228 | old = buf[adr]*256 + *rtab; 229 | if (seg) n_new = old + reldiff(seg); 230 | else n_new = old + find_global(rtab, fp); 231 | buf[adr] = (n_new>>8)&255; 232 | // FIXME: I don't understand the line below. Why should we write data do the 233 | // relocation table? 234 | // *rtab = n_new & 255; 235 | rtab++; 236 | break; 237 | case 0x20: 238 | // low byte of an address 239 | old = buf[adr]; 240 | if (seg) n_new = old + reldiff(seg); 241 | else n_new = old + find_global(rtab, fp); 242 | buf[adr] = n_new & 255; 243 | break; 244 | } 245 | if(seg==0) rtab+=2; 246 | } 247 | } 248 | if(adr > len) { 249 | /* 250 | fprintf(stderr,"reloc65: %s: Warning: relocation table entries past segment end!\n", 251 | fp->fname); 252 | */ 253 | } 254 | return ++rtab; 255 | } 256 | 257 | unsigned char *reloc_globals(unsigned char *buf, file65 *fp) { 258 | int n, n_new; 259 | 260 | n = buf[0] + 256*buf[1]; 261 | buf +=2; 262 | 263 | while(n) { 264 | /*printf("relocating %s, ", buf);*/ 265 | while(*(buf++)); 266 | int seg = *buf; 267 | int old = buf[1] + 256*buf[2]; 268 | 269 | if (seg) n_new = old + reldiff(seg); 270 | else n_new = old + find_global(buf+1, fp); 271 | /*printf("old=%04x, seg=%d, rel=%04x, n_new=%04x\n", old, seg, reldiff(seg), n_new);*/ 272 | buf[1] = n_new & 255; 273 | buf[2] = (n_new>>8) & 255; 274 | buf +=3; 275 | n--; 276 | } 277 | return buf; 278 | } 279 | --------------------------------------------------------------------------------