From ced0fcd86a08924c5608a17e4820f8ea4acd38e0 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 11:53:00 +0200 Subject: [PATCH 01/39] Start moving to c++ --- CMakeLists.txt | 2 +- src/{gconsole.c => console.cpp} | 35 ++++++++++++++++++++++++++------- src/{gconsole.h => console.h} | 32 +++++++++++++++++++++++++++--- src/loadtrk.h | 2 +- 4 files changed, 59 insertions(+), 12 deletions(-) rename src/{gconsole.c => console.cpp} (92%) rename src/{gconsole.h => console.h} (58%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7940522..6da38bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,7 @@ set(LOADTRK_SOURCES src/greloc.c src/ghelp.c src/gsound.c - src/gconsole.c + src/console.cpp src/gsid.cpp src/asm/asmtab.c src/asm/chnkpool.c diff --git a/src/gconsole.c b/src/console.cpp similarity index 92% rename from src/gconsole.c rename to src/console.cpp index e7c6dad..e0c8bc6 100644 --- a/src/gconsole.c +++ b/src/console.cpp @@ -1,16 +1,37 @@ /* - * ============================================================================= - * "console" output routines - * ============================================================================= + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define GCONSOLE_C +// ============================================================================= +// "console" output routines +// ============================================================================= +// + +#define CONSOLE_C + +extern "C" { #include "loadtrk.h" -#include -#include -#include +} + +#include +#include +#include int gfxinitted = 0; unsigned *scrbuffer = NULL; diff --git a/src/gconsole.h b/src/console.h similarity index 58% rename from src/gconsole.h rename to src/console.h index 2e8f217..2f6b2b9 100644 --- a/src/gconsole.h +++ b/src/console.h @@ -1,11 +1,33 @@ -#ifndef GCONSOLE_H -#define GCONSOLE_H +/* + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef CONSOLE_H +#define CONSOLE_H #define MAX_COLUMNS 128 #define MAX_ROWS 40 #define HOLDDELAY 24 #define DOUBLECLICKDELAY 15 +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { int channelsX; @@ -43,7 +65,7 @@ void printbg(int x, int y, int color, int length); void getkey(void); void initDisplayPositions(void); -#ifndef GCONSOLE_C +#ifndef CONSOLE_C extern int key, rawkey, shiftpressed, altpressed, cursorflashdelay; extern int mouseb, prevmouseb; extern int mouseheld; @@ -51,4 +73,8 @@ extern int mousex, mousey; extern POSITIONS dpos; #endif +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/loadtrk.h b/src/loadtrk.h index 82b5435..adc2f96 100644 --- a/src/loadtrk.h +++ b/src/loadtrk.h @@ -12,7 +12,7 @@ #include "bme.h" #include "gcommon.h" -#include "gconsole.h" +#include "console.h" #include "gsound.h" #include "gsid.h" #include "gsong.h" From f1036a387451d9262e65c9878f3a74fea38a63b6 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 12:02:01 +0200 Subject: [PATCH 02/39] Update --- src/console.cpp | 126 +++++++++++++++++++++--------------------------- src/console.h | 12 ++--- 2 files changed, 62 insertions(+), 76 deletions(-) diff --git a/src/console.cpp b/src/console.cpp index e0c8bc6..aa62042 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -19,7 +19,6 @@ // ============================================================================= // "console" output routines // ============================================================================= -// #define CONSOLE_C @@ -33,10 +32,10 @@ extern "C" { #include #include -int gfxinitted = 0; -unsigned *scrbuffer = NULL; -unsigned *prevscrbuffer = NULL; -unsigned char *chardata = NULL; +bool gfxinitted = false; +unsigned *scrbuffer = nullptr; +unsigned *prevscrbuffer = nullptr; +unsigned char *chardata = nullptr; int key = 0; int rawkey = 0; int shiftpressed = 0; @@ -100,7 +99,7 @@ int initscreen(void) if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) return 0; - win_openwindow(xsize, ysize, "LoadTracker", NULL); + win_openwindow(xsize, ysize, "LoadTracker", nullptr); win_setmousemode(MOUSE_ALWAYS_HIDDEN); initicon(); @@ -115,7 +114,7 @@ int initscreen(void) prevscrbuffer = (unsigned*)malloc(MAX_COLUMNS * MAX_ROWS * sizeof(unsigned)); if ((!scrbuffer) || (!prevscrbuffer)) return 0; - memset(region, 0, sizeof region); + std::memset(region, 0, sizeof region); chardata = (unsigned char*)malloc(4096); if (!chardata) return 0; @@ -130,7 +129,7 @@ int initscreen(void) gfx_loadsprites(0, "cursor.bin"); - gfxinitted = 1; + gfxinitted = true; clearscreen(); atexit(closescreen); return 1; @@ -141,23 +140,23 @@ void loadexternalpalette(void) FILE *ext_f; if ((ext_f = fopen("custom.pal", "rt"))) { - int p = 0; char ln[100]; - strcpy(ln, ""); - fgets(ln, sizeof(ln), ext_f); + std::strcpy(ln, ""); + std::fgets(ln, sizeof(ln), ext_f); - if (strncmp("JASC-PAL", ln, 8) == 0) + if (std::strncmp("JASC-PAL", ln, 8) == 0) { int colors; - fgets(ln, sizeof(ln), ext_f); - fgets(ln, sizeof(ln), ext_f); - if (sscanf(ln, "%d", &colors) == 1 && colors == 256) + int p = 0; + std::fgets(ln, sizeof(ln), ext_f); + std::fgets(ln, sizeof(ln), ext_f); + if (std::sscanf(ln, "%d", &colors) == 1 && colors == 256) { while (!feof(ext_f)) { int r, g, b; - if (!fgets(ln, sizeof(ln), ext_f)) break; - if (sscanf(ln, "%d %d %d", &r, &g, &b) == 3) + if (!std::fgets(ln, sizeof(ln), ext_f)) break; + if (std::sscanf(ln, "%d %d %d", &r, &g, &b) == 3) { // JASC palette is 8-bit and goat palette is 6-bit gfx_palette[p++] = r / 4; @@ -180,20 +179,15 @@ void initicon(void) int handle = io_open("loadtrk.bmp"); if (handle != -1) { - SDL_IOStream *rw; - SDL_Surface *icon; - char *iconbuffer; - int size; - - size = io_lseek(handle, 0, SEEK_END); + int size = io_lseek(handle, 0, SEEK_END); io_lseek(handle, 0, SEEK_SET); - iconbuffer = (char*)malloc(size); + char *iconbuffer = (char*)malloc(size); if (iconbuffer) { io_read(handle, iconbuffer, size); io_close(handle); - rw = SDL_IOFromMem(iconbuffer, size); - icon = SDL_LoadBMP_IO(rw, 0); + SDL_IOStream *rw = SDL_IOFromMem(iconbuffer, size); + SDL_Surface *icon = SDL_LoadBMP_IO(rw, 0); SDL_SetWindowIcon(win_window, icon); free(iconbuffer); } @@ -204,30 +198,29 @@ void closescreen(void) if (scrbuffer) { free(scrbuffer); - scrbuffer = NULL; + scrbuffer = nullptr; } if (prevscrbuffer) { free(prevscrbuffer); - prevscrbuffer = NULL; + prevscrbuffer = nullptr; } if (chardata) { free(chardata); - chardata = NULL; + chardata = nullptr; } - gfxinitted = 0; + gfxinitted = false; } void clearscreen(void) { - int c; - unsigned *dptr = scrbuffer; - if (!gfxinitted) return; - for (c = 0; c < MAX_ROWS * MAX_COLUMNS; c++) + unsigned *dptr = scrbuffer; + + for (int c = 0; c < MAX_ROWS * MAX_COLUMNS; c++) { setcharcolor(dptr, 0x20, 0x7); dptr++; @@ -236,11 +229,11 @@ void clearscreen(void) void printtext(int x, int y, int color, const char *text) { + if (!gfxinitted) return; + if ((y < 0) || (y >= MAX_ROWS)) return; + unsigned *dptr = scrbuffer + (x + y * MAX_COLUMNS); - if (!gfxinitted) return; - if (y < 0) return; - if (y >= MAX_ROWS) return; while (*text) { setcharcolor(dptr, *text, color); @@ -251,14 +244,14 @@ void printtext(int x, int y, int color, const char *text) void printtextc(int y, int color, const char *text) { - int x = (MAX_COLUMNS - strlen(text)) / 2; + int x = (MAX_COLUMNS - std::strlen(text)) / 2; printtext(x, y, color, text); } void printtextcp(int cp, int y, int color, const char *text) { - int x = cp - (strlen(text) / 2); + int x = cp - (std::strlen(text) / 2); printtext(x, y, color, text); } @@ -266,11 +259,11 @@ void printtextcp(int cp, int y, int color, const char *text) void printblank(int x, int y, int length) { + if (!gfxinitted) return; + if ((y < 0) | (y >= MAX_ROWS)) return; + unsigned *dptr = scrbuffer + (x + y * MAX_COLUMNS); - if (!gfxinitted) return; - if (y < 0) return; - if (y >= MAX_ROWS) return; while (length--) { setcharcolor(dptr, 0x20, 0x7); @@ -280,11 +273,11 @@ void printblank(int x, int y, int length) void printblankc(int x, int y, int color, int length) { + if (!gfxinitted) return; + if ((y < 0) || (y >= MAX_ROWS)) return; + unsigned *dptr = scrbuffer + (x + y * MAX_COLUMNS); - if (!gfxinitted) return; - if (y < 0) return; - if (y >= MAX_ROWS) return; while (length--) { setcharcolor(dptr, 0x20, color); @@ -294,19 +287,15 @@ void printblankc(int x, int y, int color, int length) void drawbox(int x, int y, int color, int sx, int sy) { - unsigned *dptr; - unsigned *dptr2; - int counter; - if (!gfxinitted) return; if (y < 0) return; if (y >= MAX_ROWS) return; if (y+sy > MAX_ROWS) return; if ((!sx) || (!sy)) return; - dptr = scrbuffer + (x + y * MAX_COLUMNS); - dptr2 = scrbuffer + ((x+sx-1) + y * MAX_COLUMNS); - counter = sy; + unsigned *dptr = scrbuffer + (x + y * MAX_COLUMNS); + unsigned *dptr2 = scrbuffer + ((x+sx-1) + y * MAX_COLUMNS); + int counter = sy; while (counter--) { @@ -343,11 +332,11 @@ void drawbox(int x, int y, int color, int sx, int sy) void printbg(int x, int y, int color, int length) { + if (!gfxinitted) return; + if ((y < 0) || (y >= MAX_ROWS)) return; + unsigned *dptr = scrbuffer + (x + y * MAX_COLUMNS); - if (!gfxinitted) return; - if (y < 0) return; - if (y >= MAX_ROWS) return; while (length--) { setcolor(dptr, 15 | (color << 4)); @@ -357,12 +346,11 @@ void printbg(int x, int y, int color, int length) void fliptoscreen(void) { + if (!gfxinitted) return; + unsigned *sptr = scrbuffer; unsigned *cmpptr = prevscrbuffer; - int x,y; - int regionschanged = 0; - - if (!gfxinitted) return; + bool regionschanged = false; // Mark previous mousecursor area changed if mouse moved if ((mousepixelx != oldmousepixelx) || (mousepixely != oldmousepixely)) @@ -375,9 +363,9 @@ void fliptoscreen(void) if (ey >= MAX_ROWS) ey = MAX_ROWS - 1; if (ex >= MAX_COLUMNS) ex = MAX_COLUMNS - 1; - for (y = sy; y <= ey; y++) + for (int y = sy; y <= ey; y++) { - for (x = sx; x <= ex; x++) + for (int x = sx; x <= ex; x++) prevscrbuffer[y*MAX_COLUMNS+x] = 0xffffffff; } } @@ -386,22 +374,22 @@ void fliptoscreen(void) if (gfx_redraw) { gfx_redraw = 0; - memset(prevscrbuffer, 0xff, MAX_COLUMNS*MAX_ROWS*sizeof(unsigned)); + std::memset(prevscrbuffer, 0xff, MAX_COLUMNS*MAX_ROWS*sizeof(unsigned)); } if (!gfx_lock()) return; // Now redraw text on changed areas - for (y = 0; y < MAX_ROWS; y++) + for (int y = 0; y < MAX_ROWS; y++) { - for (x = 0; x < MAX_COLUMNS; x++) + for (int x = 0; x < MAX_COLUMNS; x++) { // Check if char changed if (*sptr != *cmpptr) { *cmpptr = *sptr; region[y] = 1; - regionschanged = 1; + regionschanged = true; { unsigned char *chptr = &chardata[(*sptr & 0xffff)*16]; @@ -441,7 +429,6 @@ void fliptoscreen(void) } } - // Redraw mouse if text was redrawn if (regionschanged) { @@ -450,7 +437,7 @@ void fliptoscreen(void) if (ey >= MAX_ROWS) ey = MAX_ROWS - 1; gfx_drawsprite(mousepixelx, mousepixely, 0x1); - for (y = sy; y <= ey; y++) + for (int y = sy; y <= ey; y++) region[y] = 1; } @@ -465,7 +452,6 @@ void fliptoscreen(void) void getkey(void) { - int c; win_asciikey = 0; cursorflashdelay += win_getspeed(50); @@ -481,7 +467,7 @@ void getkey(void) key = win_asciikey; rawkey = 0; - for (c = 0; c < SDL_SCANCODE_COUNT; c++) + for (int c = 0; c < SDL_SCANCODE_COUNT; c++) { if (win_keytable[c]) { @@ -527,7 +513,7 @@ void getkey(void) if (rawkey == SDL_SCANCODE_KP_9) key = '9'; } -void initDisplayPositions(void) +void initDisplayPositions() { if (numsids == 1) { diff --git a/src/console.h b/src/console.h index 2f6b2b9..9f87b7f 100644 --- a/src/console.h +++ b/src/console.h @@ -51,10 +51,10 @@ typedef struct } POSITIONS; -int initscreen(void); -void closescreen(void); -void clearscreen(void); -void fliptoscreen(void); +int initscreen(); +void closescreen(); +void clearscreen(); +void fliptoscreen(); void printtext(int x, int y, int color, const char *text); void printtextc(int y, int color, const char *text); void printtextcp(int cp, int y, int color, const char *text); @@ -62,8 +62,8 @@ void printblank(int x, int y, int length); void printblankc(int x, int y, int color, int length); void drawbox(int x, int y, int color, int sx, int sy); void printbg(int x, int y, int color, int length); -void getkey(void); -void initDisplayPositions(void); +void getkey(); +void initDisplayPositions(); #ifndef CONSOLE_C extern int key, rawkey, shiftpressed, altpressed, cursorflashdelay; From d215769f4abcffe2816a4460836e965b063ef76e Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 12:05:07 +0200 Subject: [PATCH 03/39] Update --- CMakeLists.txt | 2 +- src/{gdisplay.c => gdisplay.cpp} | 6 +++++- src/gdisplay.h | 8 ++++++++ src/loadtrk.h | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) rename src/{gdisplay.c => gdisplay.cpp} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6da38bf..82abb0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ set(LOADTRK_SOURCES src/ginstr.c src/gtable.c src/gplay.c - src/gdisplay.c + src/gdisplay.cpp src/gfile.c src/greloc.c src/ghelp.c diff --git a/src/gdisplay.c b/src/gdisplay.cpp similarity index 99% rename from src/gdisplay.c rename to src/gdisplay.cpp index dae8867..643def6 100644 --- a/src/gdisplay.c +++ b/src/gdisplay.cpp @@ -6,9 +6,13 @@ #define GDISPLAY_C +extern "C" { + #include "loadtrk.h" -char *notename[] = +} + +const char *notename[] = {"C-0", "C#0", "D-0", "D#0", "E-0", "F-0", "F#0", "G-0", "G#0", "A-0", "A#0", "B-0", "C-1", "C#1", "D-1", "D#1", "E-1", "F-1", "F#1", "G-1", "G#1", "A-1", "A#1", "B-1", "C-2", "C#2", "D-2", "D#2", "E-2", "F-2", "F#2", "G-2", "G#2", "A-2", "A#2", "B-2", diff --git a/src/gdisplay.h b/src/gdisplay.h index 241e2de..b88a4d5 100644 --- a/src/gdisplay.h +++ b/src/gdisplay.h @@ -18,6 +18,10 @@ #define CYELLOW 0xE #define CWHITE 0xF +#ifdef __cplusplus +extern "C" { +#endif + void initcolorscheme(int dark); void printmainscreen(void); void displayupdate(void); @@ -25,4 +29,8 @@ void printstatus(void); void resettime(void); void incrementtime(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/loadtrk.h b/src/loadtrk.h index adc2f96..44c08f4 100644 --- a/src/loadtrk.h +++ b/src/loadtrk.h @@ -92,7 +92,7 @@ extern char instrfilter[MAX_FILENAME]; extern char instrpath[MAX_PATHNAME]; extern char packedpath[MAX_PATHNAME]; extern char *programname; -extern char *notename[]; +extern const char *notename[]; extern char textbuffer[MAX_PATHNAME]; extern unsigned char hexkeytbl[16]; extern unsigned char datafile[]; From f06dec26eaa3fd8c7324903e3eef3665c92ebe79 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 12:06:53 +0200 Subject: [PATCH 04/39] Update --- CMakeLists.txt | 2 +- src/{gdisplay.cpp => display.cpp} | 22 +++++++++++-- src/display.h | 54 +++++++++++++++++++++++++++++++ src/gdisplay.h | 36 --------------------- src/loadtrk.h | 2 +- 5 files changed, 75 insertions(+), 41 deletions(-) rename src/{gdisplay.cpp => display.cpp} (95%) create mode 100644 src/display.h delete mode 100644 src/gdisplay.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 82abb0b..5d4bb0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ set(LOADTRK_SOURCES src/ginstr.c src/gtable.c src/gplay.c - src/gdisplay.cpp + src/display.cpp src/gfile.c src/greloc.c src/ghelp.c diff --git a/src/gdisplay.cpp b/src/display.cpp similarity index 95% rename from src/gdisplay.cpp rename to src/display.cpp index 643def6..0a1b996 100644 --- a/src/gdisplay.cpp +++ b/src/display.cpp @@ -1,9 +1,25 @@ /* - * ============================================================================= - * screen display routines - * ============================================================================= + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +// ============================================================================= +// screen display routines +// ============================================================================= + #define GDISPLAY_C extern "C" { diff --git a/src/display.h b/src/display.h new file mode 100644 index 0000000..e2c8728 --- /dev/null +++ b/src/display.h @@ -0,0 +1,54 @@ +/* + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef GDISPLAY_H +#define GDISPLAY_H + +#define CBLACK 0x0 +#define CDBLUE 0x1 +#define CDGREEN 0x2 +#define CDGREY 0x3 +#define CDRED 0x4 +#define CDBROWN 0x5 +#define CLBROWN 0x6 +#define CLGREY 0x7 +#define CGREY 0x8 +#define CLBLUE 0x9 +#define CLGREEN 0xA +#define CCYAN 0xB +#define CLRED 0xC +#define CPURPLE 0xD +#define CYELLOW 0xE +#define CWHITE 0xF + +#ifdef __cplusplus +extern "C" { +#endif + +void initcolorscheme(int dark); +void printmainscreen(void); +void displayupdate(void); +void printstatus(void); +void resettime(void); +void incrementtime(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gdisplay.h b/src/gdisplay.h deleted file mode 100644 index b88a4d5..0000000 --- a/src/gdisplay.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef GDISPLAY_H -#define GDISPLAY_H - -#define CBLACK 0x0 -#define CDBLUE 0x1 -#define CDGREEN 0x2 -#define CDGREY 0x3 -#define CDRED 0x4 -#define CDBROWN 0x5 -#define CLBROWN 0x6 -#define CLGREY 0x7 -#define CGREY 0x8 -#define CLBLUE 0x9 -#define CLGREEN 0xA -#define CCYAN 0xB -#define CLRED 0xC -#define CPURPLE 0xD -#define CYELLOW 0xE -#define CWHITE 0xF - -#ifdef __cplusplus -extern "C" { -#endif - -void initcolorscheme(int dark); -void printmainscreen(void); -void displayupdate(void); -void printstatus(void); -void resettime(void); -void incrementtime(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/loadtrk.h b/src/loadtrk.h index 44c08f4..c6557ef 100644 --- a/src/loadtrk.h +++ b/src/loadtrk.h @@ -17,7 +17,7 @@ #include "gsid.h" #include "gsong.h" #include "gplay.h" -#include "gdisplay.h" +#include "display.h" #include "greloc.h" #include "gfile.h" #include "gpattern.h" From da3294cb4140c73ada64a173e14745f0e2f6c77d Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 12:09:19 +0200 Subject: [PATCH 05/39] Update --- CMakeLists.txt | 2 +- src/{gfile.c => gfile.cpp} | 4 ++++ src/gfile.h | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) rename src/{gfile.c => gfile.cpp} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d4bb0f..84d7646 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ set(LOADTRK_SOURCES src/gtable.c src/gplay.c src/display.cpp - src/gfile.c + src/gfile.cpp src/greloc.c src/ghelp.c src/gsound.c diff --git a/src/gfile.c b/src/gfile.cpp similarity index 99% rename from src/gfile.c rename to src/gfile.cpp index 9e295fc..9bc19f4 100644 --- a/src/gfile.c +++ b/src/gfile.cpp @@ -10,8 +10,12 @@ #include #endif +extern "C" { + #include "loadtrk.h" +} + DIRENTRY direntry[MAX_DIRFILES]; void initpaths(void) diff --git a/src/gfile.h b/src/gfile.h index 561221c..25d295c 100644 --- a/src/gfile.h +++ b/src/gfile.h @@ -5,6 +5,10 @@ #define MAX_FILENAME 60 #define MAX_PATHNAME 256 +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { char *name; @@ -16,5 +20,9 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode void editstring(char *buffer, int maxlength); int cmpname(char *string1, char *string2); +#ifdef __cplusplus +} +#endif + #endif From 37478681646f040458ea7fb17f1bd595bfd87c6f Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 12:16:14 +0200 Subject: [PATCH 06/39] Update --- CMakeLists.txt | 2 +- src/display.cpp | 2 +- src/display.h | 4 +- src/{gfile.cpp => file.cpp} | 91 +++++++++++++++++++++++-------------- src/file.h | 46 +++++++++++++++++++ src/gfile.h | 28 ------------ src/loadtrk.h | 2 +- 7 files changed, 107 insertions(+), 68 deletions(-) rename src/{gfile.cpp => file.cpp} (86%) create mode 100644 src/file.h delete mode 100644 src/gfile.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 84d7646..9cb222e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ set(LOADTRK_SOURCES src/gtable.c src/gplay.c src/display.cpp - src/gfile.cpp + src/file.cpp src/greloc.c src/ghelp.c src/gsound.c diff --git a/src/display.cpp b/src/display.cpp index 0a1b996..8859210 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -20,7 +20,7 @@ // screen display routines // ============================================================================= -#define GDISPLAY_C +#define DISPLAY_C extern "C" { diff --git a/src/display.h b/src/display.h index e2c8728..edf13d0 100644 --- a/src/display.h +++ b/src/display.h @@ -16,8 +16,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef GDISPLAY_H -#define GDISPLAY_H +#ifndef DISPLAY_H +#define DISPLAY_H #define CBLACK 0x0 #define CDBLUE 0x1 diff --git a/src/gfile.cpp b/src/file.cpp similarity index 86% rename from src/gfile.cpp rename to src/file.cpp index 9bc19f4..c09db9b 100644 --- a/src/gfile.cpp +++ b/src/file.cpp @@ -1,14 +1,26 @@ /* - * ============================================================================= - * file selector - * ============================================================================= + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define GFILE_C +// ============================================================================= +// file selector +// ============================================================================= -#ifdef __WIN32__ -#include -#endif +#define FILE_C extern "C" { @@ -16,27 +28,36 @@ extern "C" { } +#include +#include + +#include + +#ifdef __WIN32__ +#include +#endif + DIRENTRY direntry[MAX_DIRFILES]; void initpaths(void) { int c; - + for (c = 0; c < MAX_DIRFILES; c++) direntry[c].name = NULL; - memset(loadedsongfilename, 0, sizeof loadedsongfilename); - memset(songfilename, 0, sizeof songfilename); - memset(instrfilename, 0, sizeof instrfilename); - memset(songpath, 0, sizeof songpath); - memset(instrpath, 0, sizeof instrpath); - memset(packedpath, 0, sizeof packedpath); - strcpy(songfilter, "*.sng"); - strcpy(instrfilter, "*.ins"); + std::memset(loadedsongfilename, 0, sizeof loadedsongfilename); + std::memset(songfilename, 0, sizeof songfilename); + std::memset(instrfilename, 0, sizeof instrfilename); + std::memset(songpath, 0, sizeof songpath); + std::memset(instrpath, 0, sizeof instrpath); + std::memset(packedpath, 0, sizeof packedpath); + std::strcpy(songfilter, "*.sng"); + std::strcpy(instrfilter, "*.ins"); getcwd(songpath, MAX_PATHNAME); - strcpy(instrpath, songpath); - strcpy(packedpath, songpath); + std::strcpy(instrpath, songpath); + std::strcpy(packedpath, songpath); } int fileselector(char *name, char *path, char *filter, char *title, int filemode) @@ -66,14 +87,14 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode if (strlen(path)) chdir(path); // Scan for all existing drives - #ifdef __WIN32__ +#ifdef __WIN32__ for (c = 0; c < 26; c++) { drivestr[0] = 'A'+c; if (GetDriveType(drivestr) > 1) driveexists[c] = 1; else driveexists[c] = 0; } - #endif +#endif // Read new directory NEWPATH: @@ -88,7 +109,7 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode direntry[c].name = NULL; } } - #ifdef __WIN32__ +#ifdef __WIN32__ // Create drive letters for (c = 0; c < 26; c++) { @@ -100,21 +121,21 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode files++; } } - #endif +#endif // Process directory - #ifdef __amigaos__ +#ifdef __amigaos__ dir = opendir(""); - #else +#else dir = opendir("."); - #endif +#endif if (dir) { char *filtptr = strstr(filter, "*"); if (!filtptr) filtptr = filter; else filtptr++; for (i = 0; i < strlen(filter); i++) - filter[i] = tolower(filter[i]); + filter[i] = std::tolower(filter[i]); while ((de = readdir(dir))) { @@ -137,7 +158,7 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode else { for (i = 0; i < strlen(cmpbuf); i++) - cmpbuf[i] = tolower(cmpbuf[i]); + cmpbuf[i] = std::tolower(cmpbuf[i]); if (strstr(cmpbuf, filtptr)) files++; else @@ -253,15 +274,15 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode { if (((key >= '0') && (key <= '0')) || ((key >= 'a') && (key <= 'z')) || ((key >= 'A') && (key <= 'Z'))) { - char k = tolower(key); + char k = std::tolower(key); int oldfilepos = filepos; for (filepos = oldfilepos + 1; filepos < files; filepos++) - if (tolower(direntry[filepos].name[0]) == k) break; + if (std::tolower(direntry[filepos].name[0]) == k) break; if (filepos >= files) { for (filepos = 0; filepos < oldfilepos; filepos++) - if (tolower(direntry[filepos].name[0]) == k) break; + if (std::tolower(direntry[filepos].name[0]) == k) break; } if (!direntry[filepos].attribute) strcpy(name, direntry[filepos].name); @@ -277,11 +298,11 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode case KEY_BACKSPACE: if (!filemode) { - #ifdef __amigaos__ +#ifdef __amigaos__ chdir("/"); - #else +#else chdir(".."); - #endif +#endif goto NEWPATH; } break; @@ -522,8 +543,8 @@ int cmpname(char *string1, char *string2) { for (;;) { - unsigned char char1 = tolower(*string1++); - unsigned char char2 = tolower(*string2++); + unsigned char char1 = std::tolower(*string1++); + unsigned char char2 = std::tolower(*string2++); if (char1 < char2) return -1; if (char1 > char2) return 1; if ((!char1) || (!char2)) return 0; diff --git a/src/file.h b/src/file.h new file mode 100644 index 0000000..5f972c6 --- /dev/null +++ b/src/file.h @@ -0,0 +1,46 @@ +/* + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef FILE_H +#define FILE_H + +#define MAX_DIRFILES 16384 +#define MAX_FILENAME 60 +#define MAX_PATHNAME 256 + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct +{ + char *name; + int attribute; +} DIRENTRY; + +void initpaths(void); +int fileselector(char *name, char *path, char *filter, char *title, int filemode); +void editstring(char *buffer, int maxlength); +int cmpname(char *string1, char *string2); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/src/gfile.h b/src/gfile.h deleted file mode 100644 index 25d295c..0000000 --- a/src/gfile.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef GFILE_H -#define GFILE_H - -#define MAX_DIRFILES 16384 -#define MAX_FILENAME 60 -#define MAX_PATHNAME 256 - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct -{ - char *name; - int attribute; -} DIRENTRY; - -void initpaths(void); -int fileselector(char *name, char *path, char *filter, char *title, int filemode); -void editstring(char *buffer, int maxlength); -int cmpname(char *string1, char *string2); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/src/loadtrk.h b/src/loadtrk.h index c6557ef..9b517d3 100644 --- a/src/loadtrk.h +++ b/src/loadtrk.h @@ -19,7 +19,7 @@ #include "gplay.h" #include "display.h" #include "greloc.h" -#include "gfile.h" +#include "file.h" #include "gpattern.h" #include "gorder.h" #include "ginstr.h" From 6fc9ddbbb35bd39f511f6b92d2bfffae0e350710 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 12:18:33 +0200 Subject: [PATCH 07/39] Update --- CMakeLists.txt | 2 +- src/{ghelp.c => ghelp.cpp} | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) rename src/{ghelp.c => ghelp.cpp} (98%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cb222e..fec93e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ set(LOADTRK_SOURCES src/display.cpp src/file.cpp src/greloc.c - src/ghelp.c + src/ghelp.cpp src/gsound.c src/console.cpp src/gsid.cpp diff --git a/src/ghelp.c b/src/ghelp.cpp similarity index 98% rename from src/ghelp.c rename to src/ghelp.cpp index 9a5fc77..839f5ee 100644 --- a/src/ghelp.c +++ b/src/ghelp.cpp @@ -6,12 +6,16 @@ #define GHELP_C +extern "C" { + #include "loadtrk.h" +} + #define HELP_HEADER 15 #define HELP_NORMAL 7 -int printrows(int column, int row, int color, char *strings[] ) { +int printrows(int column, int row, int color, const char *strings[] ) { int n = 0; while(strings[n]) { printtext(column, row++, color, strings[n++]); @@ -21,7 +25,7 @@ int printrows(int column, int row, int color, char *strings[] ) { void onlinehelp(int standalone,int context) { - char *genkeys[] = { + const char *genkeys[] = { "F1 Play from beginning", "F2 Play from current position", "F3 Play current pattern", @@ -51,7 +55,7 @@ void onlinehelp(int standalone,int context) NULL }; - char *patternkeys[] = { + const char *patternkeys[] = { "Enter notes like on piano (PT or DMC)", "0-9 & A-F to enter commands", "SPC Switch between jam/editmode", @@ -78,7 +82,7 @@ void onlinehelp(int standalone,int context) NULL }; - char *songkeys[] = { + const char *songkeys[] = { "0-9 & A-F to enter pattern numbers", "SPC Set start position for F2 key", "BACKSPC Set end position for F2 key", @@ -93,7 +97,7 @@ void onlinehelp(int standalone,int context) NULL }; - char *instkeys[] = { + const char *instkeys[] = { "0-9 & A-F to enter parameters", "SPC Play test note", "SHIFT+SPC Silence test note", @@ -116,7 +120,7 @@ void onlinehelp(int standalone,int context) NULL }; - char *pattcmds[] = { + const char *pattcmds[] = { " ", "Command 0XY: Do nothing. Databyte will always be 00. ", " ", @@ -163,7 +167,7 @@ void onlinehelp(int standalone,int context) NULL }; - char *instparm[] = { + const char *instparm[] = { " ", "Attack/Decay 0 is fastest attack or decay, F is slowest ", " ", @@ -199,7 +203,7 @@ void onlinehelp(int standalone,int context) NULL }; - char *tables[] = { + const char *tables[] = { " ", "Wavetable left side: 00 Leave waveform unchanged ", " 01-0F Delay this step by 1-15 frames ", From 1ca36fac5ec72090e754ec73d6987c35d6ef3e70 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 12:19:48 +0200 Subject: [PATCH 08/39] Update --- CMakeLists.txt | 2 +- src/{ghelp.cpp => help.cpp} | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) rename src/{ghelp.cpp => help.cpp} (95%) diff --git a/CMakeLists.txt b/CMakeLists.txt index fec93e0..05f58a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ set(LOADTRK_SOURCES src/display.cpp src/file.cpp src/greloc.c - src/ghelp.cpp + src/help.cpp src/gsound.c src/console.cpp src/gsid.cpp diff --git a/src/ghelp.cpp b/src/help.cpp similarity index 95% rename from src/ghelp.cpp rename to src/help.cpp index 839f5ee..76ca9de 100644 --- a/src/ghelp.cpp +++ b/src/help.cpp @@ -1,10 +1,26 @@ /* - * ============================================================================= - * online help - * ============================================================================= + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define GHELP_C +// ============================================================================= +// online help +// ============================================================================= + +#define HELP_C extern "C" { @@ -415,7 +431,7 @@ void onlinehelp(int standalone,int context) if (hview < -(lastrow-MAX_ROWS+1)) hview = -(lastrow-MAX_ROWS+1); if ((mouseb) && (!prevmouseb) && (!mousey)) break; } - EXITHELP: ; +EXITHELP: ; if(!standalone) { printmainscreen(); key = 0; From ed628916f9426cb4159077bc85be15371d61bc41 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 12:20:59 +0200 Subject: [PATCH 09/39] Update --- CMakeLists.txt | 2 +- src/{ginstr.c => ginstr.cpp} | 4 ++++ src/ginstr.h | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) rename src/{ginstr.c => ginstr.cpp} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 05f58a6..798dc7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ set(LOADTRK_SOURCES src/gsong.c src/gorder.c src/gpattern.c - src/ginstr.c + src/ginstr.cpp src/gtable.c src/gplay.c src/display.cpp diff --git a/src/ginstr.c b/src/ginstr.cpp similarity index 99% rename from src/ginstr.c rename to src/ginstr.cpp index e4f81c5..89cf1a4 100644 --- a/src/ginstr.c +++ b/src/ginstr.cpp @@ -6,8 +6,12 @@ #define GINSTR_C +extern "C" { + #include "loadtrk.h" +} + INSTR instrcopybuffer; int cutinstr = -1; diff --git a/src/ginstr.h b/src/ginstr.h index 04c46c4..97a2dd0 100644 --- a/src/ginstr.h +++ b/src/ginstr.h @@ -1,6 +1,10 @@ #ifndef GINSTR_H #define GINSTR_H +#ifdef __cplusplus +extern "C" { +#endif + #ifndef GINSTR_C extern int einum; extern int eipos; @@ -15,4 +19,8 @@ void clearinstr(int num); void gotoinstr(int i); void showinstrtable(void); +#ifdef __cplusplus +} +#endif + #endif From bc4be00c55551637fe41c5889d168ce32ec2ba98 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 12:24:23 +0200 Subject: [PATCH 10/39] Update --- CMakeLists.txt | 2 +- src/ginstr.h | 26 --------------------- src/{ginstr.cpp => instr.cpp} | 43 +++++++++++++++++++++++----------- src/instr.h | 44 +++++++++++++++++++++++++++++++++++ src/loadtrk.h | 2 +- 5 files changed, 75 insertions(+), 42 deletions(-) delete mode 100644 src/ginstr.h rename src/{ginstr.cpp => instr.cpp} (76%) create mode 100644 src/instr.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 798dc7e..205c26a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ set(LOADTRK_SOURCES src/gsong.c src/gorder.c src/gpattern.c - src/ginstr.cpp + src/instr.cpp src/gtable.c src/gplay.c src/display.cpp diff --git a/src/ginstr.h b/src/ginstr.h deleted file mode 100644 index 97a2dd0..0000000 --- a/src/ginstr.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef GINSTR_H -#define GINSTR_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef GINSTR_C -extern int einum; -extern int eipos; -extern int eicolumn; -extern INSTR instrcopybuffer; -#endif - -void instrumentcommands(void); -void nextinstr(void); -void previnstr(void); -void clearinstr(int num); -void gotoinstr(int i); -void showinstrtable(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/ginstr.cpp b/src/instr.cpp similarity index 76% rename from src/ginstr.cpp rename to src/instr.cpp index 89cf1a4..46955b6 100644 --- a/src/ginstr.cpp +++ b/src/instr.cpp @@ -1,10 +1,26 @@ /* - * ============================================================================= - * instrument editor - * ============================================================================= + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define GINSTR_C +// ============================================================================= +// instrument editor +// ============================================================================= + +#define INSTR_C extern "C" { @@ -12,6 +28,8 @@ extern "C" { } +#include + INSTR instrcopybuffer; int cutinstr = -1; @@ -36,7 +54,7 @@ void instrumentcommands(void) if ((einum) && (shiftpressed) && (eipos < 9)) { cutinstr = einum; - memcpy(&instrcopybuffer, &instr[einum], sizeof(INSTR)); + std::memcpy(&instrcopybuffer, &instr[einum], sizeof(INSTR)); clearinstr(einum); } break; @@ -45,14 +63,14 @@ void instrumentcommands(void) if ((einum) && (shiftpressed) && (eipos < 9)) { cutinstr = -1; - memcpy(&instrcopybuffer, &instr[einum], sizeof(INSTR)); + std::memcpy(&instrcopybuffer, &instr[einum], sizeof(INSTR)); } break; case KEY_S: if ((einum) && (shiftpressed) && (eipos < 9)) { - memcpy(&instr[einum], &instrcopybuffer, sizeof(INSTR)); + std::memcpy(&instr[einum], &instrcopybuffer, sizeof(INSTR)); if (cutinstr != -1) { int c, d; @@ -68,7 +86,7 @@ void instrumentcommands(void) case KEY_V: if ((einum) && (shiftpressed) && (eipos < 9)) { - memcpy(&instr[einum], &instrcopybuffer, sizeof(INSTR)); + std::memcpy(&instr[einum], &instrcopybuffer, sizeof(INSTR)); } break; @@ -215,7 +233,7 @@ void instrumentcommands(void) void clearinstr(int num) { - memset(&instr[num], 0, sizeof(INSTR)); + std::memset(&instr[num], 0, sizeof(INSTR)); if (num) { if (multiplier) @@ -229,8 +247,7 @@ void clearinstr(int num) void gotoinstr(int i) { - if (i < 0) return; - if (i >= MAX_INSTR) return; + if ((i < 0) || (i >= MAX_INSTR)) return; einum = i; showinstrtable(); @@ -256,9 +273,7 @@ void showinstrtable(void) { if (!etlock) { - int c; - - for (c = MAX_TABLES-1; c >= 0; c--) + for (int c = MAX_TABLES-1; c >= 0; c--) { if (instr[einum].ptr[c]) settableviewfirst(c, instr[einum].ptr[c] - 1); diff --git a/src/instr.h b/src/instr.h new file mode 100644 index 0000000..8fa2952 --- /dev/null +++ b/src/instr.h @@ -0,0 +1,44 @@ +/* + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef INSTR_H +#define INSTR_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef INSTR_C +extern int einum; +extern int eipos; +extern int eicolumn; +extern INSTR instrcopybuffer; +#endif + +void instrumentcommands(void); +void nextinstr(void); +void previnstr(void); +void clearinstr(int num); +void gotoinstr(int i); +void showinstrtable(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/loadtrk.h b/src/loadtrk.h index 9b517d3..73147bc 100644 --- a/src/loadtrk.h +++ b/src/loadtrk.h @@ -22,7 +22,7 @@ #include "file.h" #include "gpattern.h" #include "gorder.h" -#include "ginstr.h" +#include "instr.h" #include "gtable.h" #define EDIT_PATTERN 0 From c72c00ce290801c9a9948b973cfaa14129d16f3e Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 12:26:34 +0200 Subject: [PATCH 11/39] Update --- CMakeLists.txt | 2 +- src/{gorder.c => gorder.cpp} | 4 ++++ src/gorder.h | 8 ++++++++ src/instr.cpp | 5 ++--- 4 files changed, 15 insertions(+), 4 deletions(-) rename src/{gorder.c => gorder.cpp} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 205c26a..9833530 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ set(LOADTRK_SOURCES ${CMAKE_BINARY_DIR}/src/goatdata.c src/loadtrk.c src/gsong.c - src/gorder.c + src/gorder.cpp src/gpattern.c src/instr.cpp src/gtable.c diff --git a/src/gorder.c b/src/gorder.cpp similarity index 99% rename from src/gorder.c rename to src/gorder.cpp index f4d5b3b..a88c678 100644 --- a/src/gorder.c +++ b/src/gorder.cpp @@ -6,8 +6,12 @@ #define GORDER_C +extern "C" { + #include "loadtrk.h" +} + unsigned char trackcopybuffer[MAX_SONGLEN+2]; int trackcopyrows = 0; int trackcopywhole; diff --git a/src/gorder.h b/src/gorder.h index 5440ad5..e2f0657 100644 --- a/src/gorder.h +++ b/src/gorder.h @@ -1,6 +1,10 @@ #ifndef GORDER_H #define GORDER_H +#ifdef __cplusplus +extern "C" { +#endif + #ifndef GORDER_C extern int espos[MAX_CHN]; extern int esend[MAX_CHN]; @@ -31,4 +35,8 @@ void orderright_stereo(void); void deleteorder_stereo(void); void insertorder_stereo(unsigned char byte); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/instr.cpp b/src/instr.cpp index 46955b6..17903e4 100644 --- a/src/instr.cpp +++ b/src/instr.cpp @@ -73,10 +73,9 @@ void instrumentcommands(void) std::memcpy(&instr[einum], &instrcopybuffer, sizeof(INSTR)); if (cutinstr != -1) { - int c, d; - for (c = 0; c < MAX_PATT; c++) + for (int c = 0; c < MAX_PATT; c++) { - for (d = 0; d < pattlen[c]; d++) + for (int d = 0; d < pattlen[c]; d++) if (pattern[c][d*4+1] == cutinstr) pattern[c][d*4+1] = einum; } } From 948fce4a4dcba40694073db06c4b60616ce10be4 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 12:28:00 +0200 Subject: [PATCH 12/39] Update --- CMakeLists.txt | 2 +- src/gorder.h | 42 ------------------------ src/loadtrk.h | 2 +- src/{gorder.cpp => order.cpp} | 24 +++++++++++--- src/order.h | 60 +++++++++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 48 deletions(-) delete mode 100644 src/gorder.h rename src/{gorder.cpp => order.cpp} (97%) create mode 100644 src/order.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9833530..e8b0820 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ set(LOADTRK_SOURCES ${CMAKE_BINARY_DIR}/src/goatdata.c src/loadtrk.c src/gsong.c - src/gorder.cpp + src/order.cpp src/gpattern.c src/instr.cpp src/gtable.c diff --git a/src/gorder.h b/src/gorder.h deleted file mode 100644 index e2f0657..0000000 --- a/src/gorder.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef GORDER_H -#define GORDER_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef GORDER_C -extern int espos[MAX_CHN]; -extern int esend[MAX_CHN]; -extern int eseditpos; -extern int esview; -extern int escolumn; -extern int eschn; -extern int esnum; -extern int esmarkchn; -extern int esmarkstart; -extern int esmarkend; -extern int enpos; -#endif - -void updateviewtopos(void); -void orderlistcommands(void); -void orderlistcommands_stereo(void); -void namecommands(void); -void nextsong(void); -void prevsong(void); -void songchange(void); -void orderleft(void); -void orderright(void); -void deleteorder(void); -void insertorder(unsigned char byte); -void orderleft_stereo(void); -void orderright_stereo(void); -void deleteorder_stereo(void); -void insertorder_stereo(unsigned char byte); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/loadtrk.h b/src/loadtrk.h index 73147bc..65079d8 100644 --- a/src/loadtrk.h +++ b/src/loadtrk.h @@ -21,7 +21,7 @@ #include "greloc.h" #include "file.h" #include "gpattern.h" -#include "gorder.h" +#include "order.h" #include "instr.h" #include "gtable.h" diff --git a/src/gorder.cpp b/src/order.cpp similarity index 97% rename from src/gorder.cpp rename to src/order.cpp index a88c678..f5bee26 100644 --- a/src/gorder.cpp +++ b/src/order.cpp @@ -1,10 +1,26 @@ /* - * ============================================================================= - * orderlist & songname editor - * ============================================================================= + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define GORDER_C +// ============================================================================= +// orderlist & songname editor +// ============================================================================= + +#define ORDER_C extern "C" { diff --git a/src/order.h b/src/order.h new file mode 100644 index 0000000..88cbe54 --- /dev/null +++ b/src/order.h @@ -0,0 +1,60 @@ +/* + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef ORDER_H +#define ORDER_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef ORDER_C +extern int espos[MAX_CHN]; +extern int esend[MAX_CHN]; +extern int eseditpos; +extern int esview; +extern int escolumn; +extern int eschn; +extern int esnum; +extern int esmarkchn; +extern int esmarkstart; +extern int esmarkend; +extern int enpos; +#endif + +void updateviewtopos(void); +void orderlistcommands(void); +void orderlistcommands_stereo(void); +void namecommands(void); +void nextsong(void); +void prevsong(void); +void songchange(void); +void orderleft(void); +void orderright(void); +void deleteorder(void); +void insertorder(unsigned char byte); +void orderleft_stereo(void); +void orderright_stereo(void); +void deleteorder_stereo(void); +void insertorder_stereo(unsigned char byte); + +#ifdef __cplusplus +} +#endif + +#endif From 6deb48980d3b721ba154b33750eee103cb62520a Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 12:33:35 +0200 Subject: [PATCH 13/39] Update --- src/order.cpp | 93 ++++++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 50 deletions(-) diff --git a/src/order.cpp b/src/order.cpp index f5bee26..1b5f69e 100644 --- a/src/order.cpp +++ b/src/order.cpp @@ -28,6 +28,8 @@ extern "C" { } +#include + unsigned char trackcopybuffer[MAX_SONGLEN+2]; int trackcopyrows = 0; int trackcopywhole; @@ -51,7 +53,6 @@ void namecommands(void); void orderlistcommands(void) { - int c, scrrep; int maxChns = 3; if (hexnybble >= 0) @@ -174,7 +175,7 @@ void orderlistcommands(void) songlen[esnum][schn] = songlen[esnum][tchn]; songlen[esnum][tchn] = lentemp; - for (c = 0; c < MAX_SONGLEN+2; c++) + for (int c = 0; c < MAX_SONGLEN+2; c++) { unsigned char temp = songorder[esnum][schn][c]; songorder[esnum][schn][c] = songorder[esnum][tchn][c]; @@ -195,14 +196,14 @@ void orderlistcommands(void) if (esmarkstart <= esmarkend) { eseditpos = esmarkstart; - for (c = esmarkstart; c <= esmarkend; c++) + for (int c = esmarkstart; c <= esmarkend; c++) trackcopybuffer[d++] = songorder[esnum][eschn][c]; trackcopyrows = d; } else { eseditpos = esmarkend; - for (c = esmarkend; c <= esmarkstart; c++) + for (int c = esmarkend; c <= esmarkstart; c++) trackcopybuffer[d++] = songorder[esnum][eschn][c]; trackcopyrows = d; } @@ -212,7 +213,7 @@ void orderlistcommands(void) trackcopyrpos = songorder[esnum][eschn][songlen[esnum][eschn]+1]; } else trackcopywhole = 0; - for (c = 0; c < trackcopyrows; c++) deleteorder(); + for (int c = 0; c < trackcopyrows; c++) deleteorder(); esmarkchn = -1; } } @@ -226,13 +227,13 @@ void orderlistcommands(void) int d = 0; if (esmarkstart <= esmarkend) { - for (c = esmarkstart; c <= esmarkend; c++) + for (int c = esmarkstart; c <= esmarkend; c++) trackcopybuffer[d++] = songorder[esnum][eschn][c]; trackcopyrows = d; } else { - for (c = esmarkend; c <= esmarkstart; c++) + for (int c = esmarkend; c <= esmarkstart; c++) trackcopybuffer[d++] = songorder[esnum][eschn][c]; trackcopyrows = d; } @@ -251,15 +252,15 @@ void orderlistcommands(void) if (shiftpressed) { int oldlen = songlen[esnum][eschn]; - + if (eseditpos < songlen[esnum][eschn]) { - for (c = trackcopyrows-1; c >= 0; c--) + for (int c = trackcopyrows-1; c >= 0; c--) insertorder(trackcopybuffer[c]); } else { - for (c = 0; c < trackcopyrows; c++) + for (int c = 0; c < trackcopyrows; c++) insertorder(trackcopybuffer[c]); } if ((trackcopywhole) && (!oldlen)) @@ -289,7 +290,7 @@ void orderlistcommands(void) } else { - for (c = 0; c < maxChns; c++) + for (int c = 0; c < maxChns; c++) { if (eseditpos < songlen[esnum][c]) espos[c] = eseditpos; if (esend[c] < espos[c]) esend[c] = 0; @@ -310,14 +311,14 @@ void orderlistcommands(void) { if ((esend[eschn] != eseditpos) && (eseditpos > espos[eschn])) { - for (c = 0; c < maxChns; c++) + for (int c = 0; c < maxChns; c++) { if (eseditpos < songlen[esnum][c]) esend[c] = eseditpos; } } else { - for (c = 0; c < maxChns; c++) esend[c] = 0; + for (int c = 0; c < maxChns; c++) esend[c] = 0; } } break; @@ -332,16 +333,14 @@ void orderlistcommands(void) } else { - int c, d; - - for (c = 0; c < maxChns; c++) + for (int c = 0; c < maxChns; c++) { int start; if (eseditpos != espos[eschn]) start = eseditpos; else start = espos[c]; - for (d = start; d < songlen[esnum][c]; d++) + for (int d = start; d < songlen[esnum][c]; d++) { if (songorder[esnum][c][d] < MAX_PATT) { @@ -383,12 +382,12 @@ void orderlistcommands(void) break; case KEY_PGUP: - for (scrrep = PGUPDNREPEAT * 2; scrrep; scrrep--) + for (int scrrep = PGUPDNREPEAT * 2; scrrep; scrrep--) orderleft(); break; case KEY_PGDN: - for (scrrep = PGUPDNREPEAT * 2; scrrep; scrrep--) + for (int scrrep = PGUPDNREPEAT * 2; scrrep; scrrep--) orderright(); break; @@ -434,7 +433,6 @@ void orderlistcommands(void) void orderlistcommands_stereo(void) { - int c, scrrep; int maxChns = MAX_CHN; int visibleOrderlist = 14; @@ -558,7 +556,7 @@ void orderlistcommands_stereo(void) songlen_stereo[esnum][schn] = songlen_stereo[esnum][tchn]; songlen_stereo[esnum][tchn] = lentemp; - for (c = 0; c < MAX_SONGLEN+2; c++) + for (int c = 0; c < MAX_SONGLEN+2; c++) { unsigned char temp = songorder_stereo[esnum][schn][c]; songorder_stereo[esnum][schn][c] = songorder_stereo[esnum][tchn][c]; @@ -579,14 +577,14 @@ void orderlistcommands_stereo(void) if (esmarkstart <= esmarkend) { eseditpos = esmarkstart; - for (c = esmarkstart; c <= esmarkend; c++) + for (int c = esmarkstart; c <= esmarkend; c++) trackcopybuffer[d++] = songorder_stereo[esnum][eschn][c]; trackcopyrows = d; } else { eseditpos = esmarkend; - for (c = esmarkend; c <= esmarkstart; c++) + for (int c = esmarkend; c <= esmarkstart; c++) trackcopybuffer[d++] = songorder_stereo[esnum][eschn][c]; trackcopyrows = d; } @@ -596,7 +594,7 @@ void orderlistcommands_stereo(void) trackcopyrpos = songorder_stereo[esnum][eschn][songlen_stereo[esnum][eschn]+1]; } else trackcopywhole = 0; - for (c = 0; c < trackcopyrows; c++) deleteorder_stereo(); + for (int c = 0; c < trackcopyrows; c++) deleteorder_stereo(); esmarkchn = -1; } } @@ -610,13 +608,13 @@ void orderlistcommands_stereo(void) int d = 0; if (esmarkstart <= esmarkend) { - for (c = esmarkstart; c <= esmarkend; c++) + for (int c = esmarkstart; c <= esmarkend; c++) trackcopybuffer[d++] = songorder_stereo[esnum][eschn][c]; trackcopyrows = d; } else { - for (c = esmarkend; c <= esmarkstart; c++) + for (int c = esmarkend; c <= esmarkstart; c++) trackcopybuffer[d++] = songorder_stereo[esnum][eschn][c]; trackcopyrows = d; } @@ -638,12 +636,12 @@ void orderlistcommands_stereo(void) if (eseditpos < songlen_stereo[esnum][eschn]) { - for (c = trackcopyrows-1; c >= 0; c--) + for (int c = trackcopyrows-1; c >= 0; c--) insertorder_stereo(trackcopybuffer[c]); } else { - for (c = 0; c < trackcopyrows; c++) + for (int c = 0; c < trackcopyrows; c++) insertorder_stereo(trackcopybuffer[c]); } if ((trackcopywhole) && (!oldlen)) @@ -673,7 +671,7 @@ void orderlistcommands_stereo(void) } else { - for (c = 0; c < maxChns; c++) + for (int c = 0; c < maxChns; c++) { if (eseditpos < songlen_stereo[esnum][c]) espos[c] = eseditpos; if (esend[c] < espos[c]) esend[c] = 0; @@ -694,14 +692,14 @@ void orderlistcommands_stereo(void) { if ((esend[eschn] != eseditpos) && (eseditpos > espos[eschn])) { - for (c = 0; c < maxChns; c++) + for (int c = 0; c < maxChns; c++) { if (eseditpos < songlen_stereo[esnum][c]) esend[c] = eseditpos; } } else { - for (c = 0; c < maxChns; c++) esend[c] = 0; + for (int c = 0; c < maxChns; c++) esend[c] = 0; } } break; @@ -767,12 +765,12 @@ void orderlistcommands_stereo(void) break; case KEY_PGUP: - for (scrrep = PGUPDNREPEAT * 2; scrrep; scrrep--) + for (int scrrep = PGUPDNREPEAT * 2; scrrep; scrrep--) orderleft_stereo(); break; case KEY_PGDN: - for (scrrep = PGUPDNREPEAT * 2; scrrep; scrrep--) + for (int scrrep = PGUPDNREPEAT * 2; scrrep; scrrep--) orderright_stereo(); break; @@ -851,21 +849,20 @@ void insertorder(unsigned char byte) { if ((songlen[esnum][eschn] - eseditpos)-1 >= 0) { - int len; if (songlen[esnum][eschn] < MAX_SONGLEN) { - len = songlen[esnum][eschn]+1; + int len = songlen[esnum][eschn]+1; songorder[esnum][eschn][len+1] = songorder[esnum][eschn][len]; songorder[esnum][eschn][len] = LOOPSONG; if (len) songorder[esnum][eschn][len-1] = byte; countthispattern(); } - memmove(&songorder[esnum][eschn][eseditpos+1], + std::memmove(&songorder[esnum][eschn][eseditpos+1], &songorder[esnum][eschn][eseditpos], (songlen[esnum][eschn] - eseditpos)-1); songorder[esnum][eschn][eseditpos] = byte; - len = songlen[esnum][eschn]+1; + int len = songlen[esnum][eschn]+1; if ((songorder[esnum][eschn][len] > eseditpos) && (songorder[esnum][eschn][len] < (len-2))) songorder[esnum][eschn][len]++; @@ -891,21 +888,20 @@ void insertorder_stereo(unsigned char byte) { if ((songlen_stereo[esnum][eschn] - eseditpos)-1 >= 0) { - int len; if (songlen_stereo[esnum][eschn] < MAX_SONGLEN) { - len = songlen_stereo[esnum][eschn]+1; + int len = songlen_stereo[esnum][eschn]+1; songorder_stereo[esnum][eschn][len+1] = songorder_stereo[esnum][eschn][len]; songorder_stereo[esnum][eschn][len] = LOOPSONG; if (len) songorder_stereo[esnum][eschn][len-1] = byte; countthispattern(); } - memmove(&songorder_stereo[esnum][eschn][eseditpos+1], + std::memmove(&songorder_stereo[esnum][eschn][eseditpos+1], &songorder_stereo[esnum][eschn][eseditpos], (songlen_stereo[esnum][eschn] - eseditpos)-1); songorder_stereo[esnum][eschn][eseditpos] = byte; - len = songlen_stereo[esnum][eschn]+1; + int len = songlen_stereo[esnum][eschn]+1; if ((songorder_stereo[esnum][eschn][len] > eseditpos) && (songorder_stereo[esnum][eschn][len] < (len-2))) songorder_stereo[esnum][eschn][len]++; @@ -931,8 +927,7 @@ void deleteorder(void) { if ((songlen[esnum][eschn] - eseditpos)-1 >= 0) { - int len; - memmove(&songorder[esnum][eschn][eseditpos], + std::memmove(&songorder[esnum][eschn][eseditpos], &songorder[esnum][eschn][eseditpos+1], (songlen[esnum][eschn] - eseditpos)-1); songorder[esnum][eschn][songlen[esnum][eschn]-1] = 0x00; @@ -945,7 +940,7 @@ void deleteorder(void) countthispattern(); } if (eseditpos == songlen[esnum][eschn]) eseditpos++; - len = songlen[esnum][eschn]+1; + int len = songlen[esnum][eschn]+1; if ((songorder[esnum][eschn][len] > eseditpos) && (songorder[esnum][eschn][len] > 0)) songorder[esnum][eschn][len]--; @@ -972,7 +967,7 @@ void deleteorder_stereo(void) if ((songlen_stereo[esnum][eschn] - eseditpos)-1 >= 0) { int len; - memmove(&songorder_stereo[esnum][eschn][eseditpos], + std::memmove(&songorder_stereo[esnum][eschn][eseditpos], &songorder_stereo[esnum][eschn][eseditpos+1], (songlen_stereo[esnum][eschn] - eseditpos)-1); songorder_stereo[esnum][eschn][songlen_stereo[esnum][eschn]-1] = 0x00; @@ -1128,7 +1123,6 @@ void prevsong(void) void songchange(void) { - int c; int maxChns = MAX_CHN; if (numsids == 1) maxChns = 3; int currentSonglen = 0; @@ -1141,7 +1135,7 @@ void songchange(void) currentSonglen = songlen_stereo[esnum][eschn]; } - for (c = 0; c < maxChns; c++) + for (int c = 0; c < maxChns; c++) { espos[c] = 0; esend[c] = 0; @@ -1161,13 +1155,12 @@ void songchange(void) void updateviewtopos(void) { - int c, d; int maxChns = MAX_CHN; if (numsids == 1) maxChns = 3; int currentSonglen = 0; int currentSongorder = 0; - for (c = 0; c < maxChns; c++) + for (int c = 0; c < maxChns; c++) { if (numsids == 1) { @@ -1177,7 +1170,7 @@ void updateviewtopos(void) { currentSonglen = songlen_stereo[esnum][c]; } - for (d = espos[c]; d < currentSonglen; d++) + for (int d = espos[c]; d < currentSonglen; d++) { if (numsids == 1) { From d687bdd6e19333aa8179351b7d9fe7f384d4a66b Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 14:04:47 +0200 Subject: [PATCH 14/39] Update --- CMakeLists.txt | 2 +- src/{gpattern.c => gpattern.cpp} | 5 +++++ src/gpattern.h | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) rename src/{gpattern.c => gpattern.cpp} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e8b0820..4cf92f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ set(LOADTRK_SOURCES src/loadtrk.c src/gsong.c src/order.cpp - src/gpattern.c + src/gpattern.cpp src/instr.cpp src/gtable.c src/gplay.c diff --git a/src/gpattern.c b/src/gpattern.cpp similarity index 99% rename from src/gpattern.c rename to src/gpattern.cpp index 3fdbc49..b7ce132 100644 --- a/src/gpattern.c +++ b/src/gpattern.cpp @@ -6,7 +6,9 @@ #define GPATTERN_C +extern "C" { #include "loadtrk.h" +} unsigned char notekeytbl1[] = {KEY_Z, KEY_S, KEY_X, KEY_D, KEY_C, KEY_V, KEY_G, KEY_B, KEY_H, KEY_N, KEY_J, KEY_M, KEY_COMMA, KEY_L, KEY_COLON}; @@ -38,6 +40,8 @@ int epmarkchn = -1; int epmarkstart; int epmarkend; +extern "C" { // used in bme_snd for midi input + void insertnote(int newnote) { if ((recordmode) && (eppos < pattlen[epnum[epchn]])) { @@ -70,6 +74,7 @@ void insertnote(int newnote) { } playtestnote(newnote, einum, epchn); } +} void patterncommands(void) { diff --git a/src/gpattern.h b/src/gpattern.h index 2891a4d..253b4df 100644 --- a/src/gpattern.h +++ b/src/gpattern.h @@ -1,6 +1,10 @@ #ifndef GPATTERN_H #define GPATTERN_H +#ifdef __cplusplus +extern "C" { +#endif + #ifndef GPATTERN_C extern int epnum[MAX_CHN]; extern int eppos; @@ -23,4 +27,8 @@ void expandpattern(void); void splitpattern(void); void joinpattern(void); +#ifdef __cplusplus +} +#endif + #endif From 77b59d644fa665631857b1e8a420e94b6f4718aa Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 14:10:58 +0200 Subject: [PATCH 15/39] Update --- CMakeLists.txt | 2 +- src/gpattern.h | 34 -------- src/loadtrk.h | 2 +- src/{gpattern.cpp => pattern.cpp} | 124 ++++++++++++++++-------------- src/pattern.h | 52 +++++++++++++ 5 files changed, 120 insertions(+), 94 deletions(-) delete mode 100644 src/gpattern.h rename src/{gpattern.cpp => pattern.cpp} (90%) create mode 100644 src/pattern.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4cf92f2..69d500f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ set(LOADTRK_SOURCES src/loadtrk.c src/gsong.c src/order.cpp - src/gpattern.cpp + src/pattern.cpp src/instr.cpp src/gtable.c src/gplay.c diff --git a/src/gpattern.h b/src/gpattern.h deleted file mode 100644 index 253b4df..0000000 --- a/src/gpattern.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef GPATTERN_H -#define GPATTERN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef GPATTERN_C -extern int epnum[MAX_CHN]; -extern int eppos; -extern int epview; -extern int epcolumn; -extern int epchn; -extern int epoctave; -extern int epmarkchn; -extern int epmarkstart; -extern int epmarkend; -#endif - -void patterncommands(void); -void nextpattern(void); -void prevpattern(void); -void patternup(void); -void patterndown(void); -void shrinkpattern(void); -void expandpattern(void); -void splitpattern(void); -void joinpattern(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/loadtrk.h b/src/loadtrk.h index 65079d8..4912c4e 100644 --- a/src/loadtrk.h +++ b/src/loadtrk.h @@ -20,7 +20,7 @@ #include "display.h" #include "greloc.h" #include "file.h" -#include "gpattern.h" +#include "pattern.h" #include "order.h" #include "instr.h" #include "gtable.h" diff --git a/src/gpattern.cpp b/src/pattern.cpp similarity index 90% rename from src/gpattern.cpp rename to src/pattern.cpp index b7ce132..6abd4c4 100644 --- a/src/gpattern.cpp +++ b/src/pattern.cpp @@ -1,15 +1,33 @@ /* - * ============================================================================= - * pattern editor - * ============================================================================= + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define GPATTERN_C +// ============================================================================= +// pattern editor +// ============================================================================= + +#define PATTERN_C extern "C" { #include "loadtrk.h" } +#include + unsigned char notekeytbl1[] = {KEY_Z, KEY_S, KEY_X, KEY_D, KEY_C, KEY_V, KEY_G, KEY_B, KEY_H, KEY_N, KEY_J, KEY_M, KEY_COMMA, KEY_L, KEY_COLON}; @@ -78,8 +96,6 @@ void insertnote(int newnote) { void patterncommands(void) { - size_t i; - int c, scrrep; int maxChns = MAX_CHN; if (numsids == 1) maxChns = 3; @@ -104,14 +120,14 @@ void patterncommands(void) switch (keypreset) { case KEY_TRACKER: - for (i = 0; i < sizeof(notekeytbl1); i++) + for (size_t i = 0; i < sizeof(notekeytbl1); i++) { if ((rawkey == notekeytbl1[i]) && (!epcolumn) && (!shiftpressed) && (!altpressed)) { newnote = FIRSTNOTE+i+epoctave*12; } } - for (i = 0; i < sizeof(notekeytbl2); i++) + for (size_t i = 0; i < sizeof(notekeytbl2); i++) { if ((rawkey == notekeytbl2[i]) && (!epcolumn) && (!shiftpressed) && (!altpressed)) { @@ -121,7 +137,7 @@ void patterncommands(void) break; case KEY_DMC: - for (i = 0; i < sizeof(dmckeytbl); i++) + for (size_t i = 0; i < sizeof(dmckeytbl); i++) { if ((rawkey == dmckeytbl[i]) && (!epcolumn) && (!shiftpressed) && (!altpressed)) { @@ -131,14 +147,14 @@ void patterncommands(void) break; case KEY_JANKO: - for (i = 0; i < sizeof(jankokeytbl1); i++) + for (size_t i = 0; i < sizeof(jankokeytbl1); i++) { if ((rawkey == jankokeytbl1[i]) && (!epcolumn) && (!shiftpressed) && (!altpressed)) { newnote = FIRSTNOTE+i+epoctave*12; } } - for (i = 0; i < sizeof(jankokeytbl2); i++) + for (size_t i = 0; i < sizeof(jankokeytbl2); i++) { if ((rawkey == jankokeytbl2[i]) && (!epcolumn) && (!shiftpressed) && (!altpressed)) { @@ -375,7 +391,7 @@ void patterncommands(void) if (epmarkstart < epmarkend) { int d = 0; - for (c = epmarkstart; c <= epmarkend; c++) + for (int c = epmarkstart; c <= epmarkend; c++) { if (c >= pattlen[epnum[epmarkchn]]) break; cmdcopybuffer[d*4+2] = pattern[epnum[epmarkchn]][c*4+2]; @@ -387,7 +403,7 @@ void patterncommands(void) else { int d = 0; - for (c = epmarkend; c <= epmarkstart; c++) + for (int c = epmarkend; c <= epmarkstart; c++) { if (c >= pattlen[epnum[epmarkchn]]) break; cmdcopybuffer[d*4+2] = pattern[epnum[epmarkchn]][c*4+2]; @@ -413,7 +429,7 @@ void patterncommands(void) case KEY_R: if (shiftpressed) { - for (c = 0; c < cmdcopyrows; c++) + for (int c = 0; c < cmdcopyrows; c++) { if (eppos >= pattlen[epnum[epchn]]) break; pattern[epnum[epchn]][eppos*4+2] = cmdcopybuffer[c*4+2]; @@ -426,17 +442,16 @@ void patterncommands(void) case KEY_I: if (shiftpressed) { - int d, e; char temp; if (epmarkchn != -1) { if (epmarkstart <= epmarkend) { - e = epmarkend; - for (c = epmarkstart; c <= epmarkend; c++) + int e = epmarkend; + for (int c = epmarkstart; c <= epmarkend; c++) { if (c >= pattlen[epnum[epmarkchn]]) break; - for (d = 0; d < 4; d++) + for (int d = 0; d < 4; d++) { temp = pattern[epnum[epmarkchn]][c*4+d]; pattern[epnum[epmarkchn]][c*4+d] = pattern[epnum[epmarkchn]][e*4+d]; @@ -448,11 +463,11 @@ void patterncommands(void) } else { - e = epmarkstart; - for (c = epmarkend; c <= epmarkstart; c++) + int e = epmarkstart; + for (int c = epmarkend; c <= epmarkstart; c++) { if (c >= pattlen[epnum[epmarkchn]]) break; - for (d = 0; d < 4; d++) + for (int d = 0; d < 4; d++) { temp = pattern[epnum[epmarkchn]][c*4+d]; pattern[epnum[epmarkchn]][c*4+d] = pattern[epnum[epmarkchn]][e*4+d]; @@ -465,10 +480,10 @@ void patterncommands(void) } else { - e = pattlen[epnum[epchn]] - 1; - for (c = 0; c < pattlen[epnum[epchn]]; c++) + int e = pattlen[epnum[epchn]] - 1; + for (int c = 0; c < pattlen[epnum[epchn]]; c++) { - for (d = 0; d < 4; d++) + for (int d = 0; d < 4; d++) { temp = pattern[epnum[epchn]][c*4+d]; pattern[epnum[epchn]][c*4+d] = pattern[epnum[epchn]][e*4+d]; @@ -488,7 +503,7 @@ void patterncommands(void) { if (epmarkstart <= epmarkend) { - for (c = epmarkstart; c <= epmarkend; c++) + for (int c = epmarkstart; c <= epmarkend; c++) { if (c >= pattlen[epnum[epmarkchn]]) break; if ((pattern[epnum[epmarkchn]][c*4] < LASTNOTE) && @@ -498,7 +513,7 @@ void patterncommands(void) } else { - for (c = epmarkend; c <= epmarkstart; c++) + for (int c = epmarkend; c <= epmarkstart; c++) { if (c >= pattlen[epnum[epmarkchn]]) break; if ((pattern[epnum[epmarkchn]][c*4] < LASTNOTE) && @@ -509,7 +524,7 @@ void patterncommands(void) } else { - for (c = 0; c < pattlen[epnum[epchn]]; c++) + for (int c = 0; c < pattlen[epnum[epchn]]; c++) { if ((pattern[epnum[epchn]][c*4] < LASTNOTE) && (pattern[epnum[epchn]][c*4] >= FIRSTNOTE)) @@ -526,7 +541,7 @@ void patterncommands(void) { if (epmarkstart <= epmarkend) { - for (c = epmarkstart; c <= epmarkend; c++) + for (int c = epmarkstart; c <= epmarkend; c++) { if (c >= pattlen[epnum[epmarkchn]]) break; if ((pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && @@ -536,7 +551,7 @@ void patterncommands(void) } else { - for (c = epmarkend; c <= epmarkstart; c++) + for (int c = epmarkend; c <= epmarkstart; c++) { if (c >= pattlen[epnum[epmarkchn]]) break; if ((pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && @@ -547,7 +562,7 @@ void patterncommands(void) } else { - for (c = 0; c < pattlen[epnum[epchn]]; c++) + for (int c = 0; c < pattlen[epnum[epchn]]; c++) { if ((pattern[epnum[epchn]][c*4] <= LASTNOTE) && (pattern[epnum[epchn]][c*4] > FIRSTNOTE)) @@ -564,7 +579,7 @@ void patterncommands(void) { if (epmarkstart <= epmarkend) { - for (c = epmarkstart; c <= epmarkend; c++) + for (int c = epmarkstart; c <= epmarkend; c++) { if (c >= pattlen[epnum[epmarkchn]]) break; if ((pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && @@ -578,7 +593,7 @@ void patterncommands(void) } else { - for (c = epmarkend; c <= epmarkstart; c++) + for (int c = epmarkend; c <= epmarkstart; c++) { if (c >= pattlen[epnum[epmarkchn]]) break; if ((pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && @@ -593,7 +608,7 @@ void patterncommands(void) } else { - for (c = 0; c < pattlen[epnum[epchn]]; c++) + for (int c = 0; c < pattlen[epnum[epchn]]; c++) { if ((pattern[epnum[epchn]][c*4] <= LASTNOTE) && (pattern[epnum[epchn]][c*4] >= FIRSTNOTE)) @@ -614,7 +629,7 @@ void patterncommands(void) { if (epmarkstart <= epmarkend) { - for (c = epmarkstart; c <= epmarkend; c++) + for (int c = epmarkstart; c <= epmarkend; c++) { if (c >= pattlen[epnum[epmarkchn]]) break; if ((pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && @@ -628,7 +643,7 @@ void patterncommands(void) } else { - for (c = epmarkend; c <= epmarkstart; c++) + for (int c = epmarkend; c <= epmarkstart; c++) { if (c >= pattlen[epnum[epmarkchn]]) break; if ((pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && @@ -643,7 +658,7 @@ void patterncommands(void) } else { - for (c = 0; c < pattlen[epnum[epchn]]; c++) + for (int c = 0; c < pattlen[epnum[epchn]]; c++) { if ((pattern[epnum[epchn]][c*4] <= LASTNOTE) && (pattern[epnum[epchn]][c*4] >= FIRSTNOTE)) @@ -676,6 +691,7 @@ void patterncommands(void) case KEY_H: if (shiftpressed) { + int c; switch (pattern[epnum[epchn]][eppos*4+2]) { case CMD_PORTAUP: @@ -691,18 +707,14 @@ void patterncommands(void) if ((pattern[epnum[epchn]][c*4] >= FIRSTNOTE) && (pattern[epnum[epchn]][c*4] <= LASTNOTE)) { - int delta; - int pitch1; - int pitch2; - int pos; int note = pattern[epnum[epchn]][c*4] - FIRSTNOTE; int right = pattern[epnum[epchn]][eppos*4+3] & 0xf; int left = pattern[epnum[epchn]][eppos*4+3] >> 4; if (note > MAX_NOTES-1) note--; - pitch1 = freqtbllo[note] | (freqtblhi[note] << 8); - pitch2 = freqtbllo[note+1] | (freqtblhi[note+1] << 8); - delta = pitch2 - pitch1; + int pitch1 = freqtbllo[note] | (freqtblhi[note] << 8); + int pitch2 = freqtbllo[note+1] | (freqtblhi[note+1] << 8); + int delta = pitch2 - pitch1; while (left--) delta <<= 1; while (right--) delta >>= 1; @@ -711,7 +723,7 @@ void patterncommands(void) { if (delta > 0xff) delta = 0xff; } - pos = makespeedtable(delta, MST_RAW, 1); + int pos = makespeedtable(delta, MST_RAW, 1); pattern[epnum[epchn]][eppos*4+3] = pos + 1; break; } @@ -743,7 +755,7 @@ void patterncommands(void) if (epmarkstart <= epmarkend) { int d = 0; - for (c = epmarkstart; c <= epmarkend; c++) + for (int c = epmarkstart; c <= epmarkend; c++) { if (c >= pattlen[epnum[epmarkchn]]) break; patterncopybuffer[d*4] = pattern[epnum[epmarkchn]][c*4]; @@ -764,7 +776,7 @@ void patterncommands(void) else { int d = 0; - for (c = epmarkend; c <= epmarkstart; c++) + for (int c = epmarkend; c <= epmarkstart; c++) { if (c >= pattlen[epnum[epmarkchn]]) break; patterncopybuffer[d*4] = pattern[epnum[epmarkchn]][c*4]; @@ -787,7 +799,7 @@ void patterncommands(void) else { int d = 0; - for (c = 0; c < pattlen[epnum[epchn]]; c++) + for (int c = 0; c < pattlen[epnum[epchn]]; c++) { patterncopybuffer[d*4] = pattern[epnum[epchn]][c*4]; patterncopybuffer[d*4+1] = pattern[epnum[epchn]][c*4+1]; @@ -810,7 +822,7 @@ void patterncommands(void) case KEY_V: if ((shiftpressed) && (patterncopyrows)) { - for (c = 0; c < patterncopyrows; c++) + for (int c = 0; c < patterncopyrows; c++) { if (eppos >= pattlen[epnum[epchn]]) break; pattern[epnum[epchn]][eppos*4] = patterncopybuffer[c*4]; @@ -893,9 +905,7 @@ void patterncommands(void) { if (eseditpos != espos[eschn]) { - int c; - - for (c = 0; c < maxChns; c++) + for (int c = 0; c < maxChns; c++) { if (eseditpos < songlen[esnum][c]) espos[c] = eseditpos; if (esend[c] <= espos[c]) esend[c] = 0; @@ -963,12 +973,12 @@ void patterncommands(void) break; case KEY_PGUP: - for (scrrep = PGUPDNREPEAT; scrrep; scrrep--) + for (int scrrep = PGUPDNREPEAT; scrrep; scrrep--) patternup(); break; case KEY_PGDN: - for (scrrep = PGUPDNREPEAT; scrrep; scrrep--) + for (int scrrep = PGUPDNREPEAT; scrrep; scrrep--) patterndown(); break; @@ -1180,7 +1190,6 @@ void expandpattern(void) int c = epnum[epchn]; int l = pattlen[c]; int nl = l*2; - int d; unsigned char temp[MAX_PATTROWS*4+4]; if (nl > MAX_PATTROWS) return; @@ -1188,7 +1197,7 @@ void expandpattern(void) stopsong(); - for (d = 0; d <= nl; d++) + for (int d = 0; d <= nl; d++) { if (d & 1) { @@ -1206,7 +1215,7 @@ void expandpattern(void) } } - memcpy(pattern[c], temp, (nl+1)*4); + std::memcpy(pattern[c], temp, (nl+1)*4); eppos *= 2; @@ -1217,7 +1226,6 @@ void splitpattern(void) { int c = epnum[epchn]; int l = pattlen[c]; - int d; int maxChns = MAX_CHN; if (numsids == 1) maxChns = 3; @@ -1232,7 +1240,7 @@ void splitpattern(void) int oldeschn = eschn; int oldeseditpos = eseditpos; - for (d = eppos; d <= l; d++) + for (int d = eppos; d <= l; d++) { pattern[c+1][(d-eppos)*4] = pattern[c][d*4]; pattern[c+1][(d-eppos)*4+1] = pattern[c][d*4+1]; diff --git a/src/pattern.h b/src/pattern.h new file mode 100644 index 0000000..690a866 --- /dev/null +++ b/src/pattern.h @@ -0,0 +1,52 @@ +/* + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PATTERN_H +#define PATTERN_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef PATTERN_C +extern int epnum[MAX_CHN]; +extern int eppos; +extern int epview; +extern int epcolumn; +extern int epchn; +extern int epoctave; +extern int epmarkchn; +extern int epmarkstart; +extern int epmarkend; +#endif + +void patterncommands(void); +void nextpattern(void); +void prevpattern(void); +void patternup(void); +void patterndown(void); +void shrinkpattern(void); +void expandpattern(void); +void splitpattern(void); +void joinpattern(void); + +#ifdef __cplusplus +} +#endif + +#endif From 2ef2fdc0b3539905f6cadd0430ed6af25c49f088 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 14:11:59 +0200 Subject: [PATCH 16/39] Update --- CMakeLists.txt | 2 +- src/{gplay.c => gplay.cpp} | 2 ++ src/gplay.h | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) rename src/{gplay.c => gplay.cpp} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69d500f..4d17e93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ set(LOADTRK_SOURCES src/pattern.cpp src/instr.cpp src/gtable.c - src/gplay.c + src/gplay.cpp src/display.cpp src/file.cpp src/greloc.c diff --git a/src/gplay.c b/src/gplay.cpp similarity index 99% rename from src/gplay.c rename to src/gplay.cpp index 963070e..fe101ce 100644 --- a/src/gplay.c +++ b/src/gplay.cpp @@ -6,7 +6,9 @@ #define GPLAY_C +extern "C" { #include "loadtrk.h" +} unsigned char freqtbllo[] = { 0x17,0x27,0x39,0x4b,0x5f,0x74,0x8a,0xa1,0xba,0xd4,0xf0,0x0e, diff --git a/src/gplay.h b/src/gplay.h index de92e68..71b6b66 100644 --- a/src/gplay.h +++ b/src/gplay.h @@ -8,6 +8,10 @@ #define PLAY_STOP 0x04 #define PLAY_STOPPED 0x80 +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { unsigned char trans; @@ -59,4 +63,8 @@ int isplaying(void); void playroutine(void); void playroutine_stereo(void); +#ifdef __cplusplus +} +#endif + #endif From c3a8cfedc7ab5be309f6a000913bbd9756c31b6a Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 14:15:49 +0200 Subject: [PATCH 17/39] Update --- CMakeLists.txt | 2 +- src/loadtrk.h | 2 +- src/{gplay.cpp => play.cpp} | 45 ++++++++++++++++++++++++------------- src/{gplay.h => play.h} | 24 +++++++++++++++++--- 4 files changed, 53 insertions(+), 20 deletions(-) rename src/{gplay.cpp => play.cpp} (98%) rename src/{gplay.h => play.h} (64%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d17e93..41c812c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ set(LOADTRK_SOURCES src/pattern.cpp src/instr.cpp src/gtable.c - src/gplay.cpp + src/play.cpp src/display.cpp src/file.cpp src/greloc.c diff --git a/src/loadtrk.h b/src/loadtrk.h index 4912c4e..1bf5307 100644 --- a/src/loadtrk.h +++ b/src/loadtrk.h @@ -16,7 +16,7 @@ #include "gsound.h" #include "gsid.h" #include "gsong.h" -#include "gplay.h" +#include "play.h" #include "display.h" #include "greloc.h" #include "file.h" diff --git a/src/gplay.cpp b/src/play.cpp similarity index 98% rename from src/gplay.cpp rename to src/play.cpp index fe101ce..71dcb97 100644 --- a/src/gplay.cpp +++ b/src/play.cpp @@ -1,15 +1,33 @@ /* - * ============================================================================= - * playroutine - * ============================================================================= + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define GPLAY_C +// ============================================================================= +// playroutine +// ============================================================================= + +#define PLAY_C extern "C" { #include "loadtrk.h" } +#include + unsigned char freqtbllo[] = { 0x17,0x27,0x39,0x4b,0x5f,0x74,0x8a,0xa1,0xba,0xd4,0xf0,0x0e, 0x2d,0x4e,0x71,0x96,0xbe,0xe8,0x14,0x43,0x74,0xa9,0xe1,0x1c, @@ -61,14 +79,13 @@ void sequencer_stereo(int c, CHN *cptr); void initchannels(void) { - int c; int maxChns = MAX_CHN; if (numsids == 1) maxChns = 3; CHN *cptr = &chn[0]; - memset(chn, 0, sizeof chn); + std::memset(chn, 0, sizeof chn); - for (c = 0; c < maxChns; c++) + for (int c = 0; c < maxChns; c++) { chn[c].trans = 0; chn[c].instr = 1; @@ -176,7 +193,6 @@ void playroutine(void) { INSTR *iptr; CHN *cptr = &chn[0]; - int c; int maxChns = 3; if (songinit == PLAY_STOP) @@ -197,7 +213,7 @@ void playroutine(void) songinit = 0x01; } - for (c = 0; c < maxChns; c++) + for (int c = 0; c < maxChns; c++) { cptr->songptr = 0; cptr->command = 0; @@ -316,7 +332,7 @@ void playroutine(void) sidreg[0x17] = filterctrl; sidreg[0x18] = filtertype | masterfader; - for (c = 0; c < maxChns; c++) + for (int c = 0; c < maxChns; c++) { iptr = &instr[cptr->instr]; @@ -955,7 +971,7 @@ void playroutine(void) } } } - NEXTCHN: +NEXTCHN: if (cptr->mute) sidreg[0x4+7*c] = cptr->wave = 0x08; else @@ -1030,7 +1046,6 @@ void playroutine_stereo(void) { INSTR *iptr; CHN *cptr = &chn[0]; - int c; if (songinit == PLAY_STOP) followplay = 0; @@ -1048,14 +1063,14 @@ void playroutine_stereo(void) if ((songinit == 0x02) || (songinit == 0x03)) { - for (c = 0; c< MAX_CHN; c++) + for (int c = 0; c< MAX_CHN; c++) { if (espos[c] >= songlen_stereo[psnum][c]) songinit = 0x01; } } - for (c = 0; c < MAX_CHN; c++) + for (int c = 0; c < MAX_CHN; c++) { cptr->songptr = 0; cptr->command = 0; @@ -1227,7 +1242,7 @@ void playroutine_stereo(void) sidreg2[0x17] = filter2ctrl; sidreg2[0x18] = filter2type | masterfader; - for (c = 0; c < MAX_CHN; c++) + for (int c = 0; c < MAX_CHN; c++) { iptr = &instr[cptr->instr]; diff --git a/src/gplay.h b/src/play.h similarity index 64% rename from src/gplay.h rename to src/play.h index 71b6b66..63eab5a 100644 --- a/src/gplay.h +++ b/src/play.h @@ -1,5 +1,23 @@ -#ifndef GPLAY_H -#define GPLAY_H +/* + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PLAY_H +#define PLAY_H #define PLAY_PLAYING 0x00 #define PLAY_BEGINNING 0x01 @@ -43,7 +61,7 @@ typedef struct unsigned char gatetimer; } CHN; -#ifndef GPLAY_C +#ifndef PLAY_C extern CHN chn[MAX_CHN]; extern unsigned char masterfader; extern unsigned char freqtbllo[]; From ad86f84fd04f3c99b7d1cf6ea013149712e69f33 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 14:29:39 +0200 Subject: [PATCH 18/39] Update --- src/file.cpp | 65 +++++++++++++++++++++++----------------------------- src/file.h | 2 +- 2 files changed, 30 insertions(+), 37 deletions(-) diff --git a/src/file.cpp b/src/file.cpp index c09db9b..c829a90 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -31,6 +31,7 @@ extern "C" { #include #include +#include #include #ifdef __WIN32__ @@ -41,10 +42,8 @@ DIRENTRY direntry[MAX_DIRFILES]; void initpaths(void) { - int c; - - for (c = 0; c < MAX_DIRFILES; c++) - direntry[c].name = NULL; + for (int c = 0; c < MAX_DIRFILES; c++) + direntry[c].name = nullptr; std::memset(loadedsongfilename, 0, sizeof loadedsongfilename); std::memset(songfilename, 0, sizeof songfilename); @@ -60,18 +59,12 @@ void initpaths(void) std::strcpy(packedpath, songpath); } -int fileselector(char *name, char *path, char *filter, char *title, int filemode) +int fileselector(char *name, char *path, char *filter, const char *title, int filemode) { - size_t i; - int c, d, scrrep; - int color; - int files; int filepos = 0; int fileview = 0; int lastclick = 0; int lastfile = 0; - int lowest; - int exitfilesel; DIR *dir; struct dirent *de; @@ -84,7 +77,7 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode char tempname[MAX_PATHNAME]; // Set initial path (if any) - if (strlen(path)) chdir(path); + if (std::strlen(path)) chdir(path); // Scan for all existing drives #ifdef __WIN32__ @@ -99,14 +92,14 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode // Read new directory NEWPATH: getcwd(path, MAX_PATHNAME); - files = 0; + int files = 0; // Deallocate old names - for (c = 0; c < MAX_DIRFILES; c++) + for (int c = 0; c < MAX_DIRFILES; c++) { if (direntry[c].name) { free(direntry[c].name); - direntry[c].name = NULL; + direntry[c].name = nullptr; } } #ifdef __WIN32__ @@ -134,12 +127,12 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode char *filtptr = strstr(filter, "*"); if (!filtptr) filtptr = filter; else filtptr++; - for (i = 0; i < strlen(filter); i++) + for (size_t i = 0; i < std::strlen(filter); i++) filter[i] = std::tolower(filter[i]); while ((de = readdir(dir))) { - if ((files < MAX_DIRFILES) && (strlen(de->d_name) < MAX_FILENAME)) + if ((files < MAX_DIRFILES) && (std::strlen(de->d_name) < MAX_FILENAME)) { direntry[files].name = strdup(de->d_name); direntry[files].attribute = 0; @@ -153,18 +146,18 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode { // If a file, must match filter strcpy(cmpbuf, de->d_name); - if ((!strcmp(filtptr, "*")) || (!strcmp(filtptr, ".*"))) + if ((!std::strcmp(filtptr, "*")) || (!strcmp(filtptr, ".*"))) files++; else { - for (i = 0; i < strlen(cmpbuf); i++) + for (size_t i = 0; i < strlen(cmpbuf); i++) cmpbuf[i] = std::tolower(cmpbuf[i]); - if (strstr(cmpbuf, filtptr)) + if (std::strstr(cmpbuf, filtptr)) files++; else { free(direntry[files].name); - direntry[files].name = NULL; + direntry[files].name = nullptr; } } } @@ -173,10 +166,10 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode closedir(dir); } // Sort the filelist in a most horrible fashion - for (c = 0; c < files; c++) + for (int c = 0; c < files; c++) { - lowest = c; - for (d = c+1; d < files; d++) + int lowest = c; + for (int d = c+1; d < files; d++) { if (direntry[d].attribute < direntry[lowest].attribute) { @@ -204,7 +197,7 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode // Search for the current filename fileview = 0; filepos = 0; - for (c = 0; c < files; c++) + for (int c = 0; c < files; c++) { if ((!direntry[c].attribute) && (!cmpname(name, direntry[c].name))) { @@ -212,7 +205,7 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode } } - exitfilesel = -1; + int exitfilesel = -1; while (exitfilesel < 0) { int cc = cursorcolortable[cursorflash]; @@ -229,12 +222,12 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode if (win_quitted) { exitprogram = 1; - for (c = 0; c < MAX_DIRFILES; c++) + for (int c = 0; c < MAX_DIRFILES; c++) { if (direntry[c].name) { free(direntry[c].name); - direntry[c].name = NULL; + direntry[c].name = nullptr; } } return 0; @@ -324,7 +317,7 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode break; case KEY_PGUP: - for (scrrep = PGUPDNREPEAT; scrrep; scrrep--) + for (int scrrep = PGUPDNREPEAT; scrrep; scrrep--) { if ((!filemode) && (filepos > 0)) { @@ -343,7 +336,7 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode break; case KEY_PGDN: - for (scrrep = PGUPDNREPEAT; scrrep; scrrep--) + for (int scrrep = PGUPDNREPEAT; scrrep; scrrep--) { if ((!filemode) && (filepos < files-1)) { @@ -437,7 +430,7 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode // Refresh fileselector display if (isplaying()) printstatus(); - for (c = 0; c < VISIBLEFILES+7; c++) + for (int c = 0; c < VISIBLEFILES+7; c++) { printblank(dpos.loadboxX-(MAX_FILENAME+10)/2, dpos.loadboxY+c, MAX_FILENAME+10); } @@ -445,7 +438,7 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode printblankc(dpos.loadboxX-(MAX_FILENAME+10)/2+1, dpos.loadboxY+1, colors.CHEADER, MAX_FILENAME+8); printtext(dpos.loadboxX-(MAX_FILENAME+10)/2+1, dpos.loadboxY+1, colors.CHEADER, title); - for (c = 0; c < VISIBLEFILES; c++) + for (int c = 0; c < VISIBLEFILES; c++) { if ((fileview+c >= 0) && (fileview+c < files)) { @@ -468,7 +461,7 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode { sprintf(textbuffer, " "); } - color = colors.CNORMAL; + int color = colors.CNORMAL; if ((fileview+c) == filepos) color = colors.CEDIT; textbuffer[68] = 0; printtext(dpos.loadboxX-(MAX_FILENAME+10)/2+1, dpos.loadboxY+2+c, color, textbuffer); @@ -478,7 +471,7 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode printtext(dpos.loadboxX-(MAX_FILENAME+10)/2+1, dpos.loadboxY+3+VISIBLEFILES, 15, "PATH: "); sprintf(textbuffer, "%-60s", path); textbuffer[MAX_FILENAME] = 0; - color = (filemode == 1) ? colors.CEDIT : colors.CNORMAL; + int color = (filemode == 1) ? colors.CEDIT : colors.CNORMAL; printtext(dpos.loadboxX-(MAX_FILENAME+10)/2+9, dpos.loadboxY+3+VISIBLEFILES, color, textbuffer); if ((filemode == 1) && (strlen(path) < MAX_FILENAME)) printbg(dpos.loadboxX-(MAX_FILENAME+10)/2+9+strlen(path), dpos.loadboxY+3+VISIBLEFILES, cc, 1); @@ -506,12 +499,12 @@ int fileselector(char *name, char *path, char *filter, char *title, int filemode } // Deallocate all used names - for (c = 0; c < MAX_DIRFILES; c++) + for (int c = 0; c < MAX_DIRFILES; c++) { if (direntry[c].name) { free(direntry[c].name); - direntry[c].name = NULL; + direntry[c].name = nullptr; } } diff --git a/src/file.h b/src/file.h index 5f972c6..7879f12 100644 --- a/src/file.h +++ b/src/file.h @@ -34,7 +34,7 @@ typedef struct } DIRENTRY; void initpaths(void); -int fileselector(char *name, char *path, char *filter, char *title, int filemode); +int fileselector(char *name, char *path, char *filter, const char *title, int filemode); void editstring(char *buffer, int maxlength); int cmpname(char *string1, char *string2); From a483e11b21722c231bfa675a1bbdc30b69f509e6 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 16:23:02 +0200 Subject: [PATCH 19/39] Update --- CMakeLists.txt | 2 +- src/{gsong.c => gsong.cpp} | 2 ++ src/gsong.h | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) rename src/{gsong.c => gsong.cpp} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 41c812c..eba809c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ endif() set(LOADTRK_SOURCES ${CMAKE_BINARY_DIR}/src/goatdata.c src/loadtrk.c - src/gsong.c + src/gsong.cpp src/order.cpp src/pattern.cpp src/instr.cpp diff --git a/src/gsong.c b/src/gsong.cpp similarity index 99% rename from src/gsong.c rename to src/gsong.cpp index fe325d6..981fa60 100644 --- a/src/gsong.c +++ b/src/gsong.cpp @@ -6,7 +6,9 @@ #define GSONG_C +extern "C" { #include "loadtrk.h" +} INSTR instr[MAX_INSTR]; unsigned char ltable[MAX_TABLES][MAX_TABLELEN]; diff --git a/src/gsong.h b/src/gsong.h index 42bee12..26464d2 100644 --- a/src/gsong.h +++ b/src/gsong.h @@ -1,6 +1,10 @@ #ifndef GSONG_H #define GSONG_H +#ifdef __cplusplus +extern "C" { +#endif + #ifndef GSONG_C extern INSTR instr[MAX_INSTR]; extern unsigned char ltable[MAX_TABLES][MAX_TABLELEN]; @@ -33,4 +37,8 @@ void findusedpatterns(void); void findduplicatepatterns(void); void optimizeeverything(int oi, int ot); +#ifdef __cplusplus +} +#endif + #endif From f8630934f648806f004f771dcacbaa8ed0f5a345 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 16:34:51 +0200 Subject: [PATCH 20/39] Update --- CMakeLists.txt | 2 +- src/loadtrk.h | 2 +- src/{gsong.cpp => song.cpp} | 294 ++++++++++++++++++------------------ src/{gsong.h => song.h} | 24 ++- 4 files changed, 167 insertions(+), 155 deletions(-) rename src/{gsong.cpp => song.cpp} (88%) rename src/{gsong.h => song.h} (59%) diff --git a/CMakeLists.txt b/CMakeLists.txt index eba809c..14e5cb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ endif() set(LOADTRK_SOURCES ${CMAKE_BINARY_DIR}/src/goatdata.c src/loadtrk.c - src/gsong.cpp + src/song.cpp src/order.cpp src/pattern.cpp src/instr.cpp diff --git a/src/loadtrk.h b/src/loadtrk.h index 1bf5307..a46a77b 100644 --- a/src/loadtrk.h +++ b/src/loadtrk.h @@ -15,7 +15,7 @@ #include "console.h" #include "gsound.h" #include "gsid.h" -#include "gsong.h" +#include "song.h" #include "play.h" #include "display.h" #include "greloc.h" diff --git a/src/gsong.cpp b/src/song.cpp similarity index 88% rename from src/gsong.cpp rename to src/song.cpp index 981fa60..c1a4fd5 100644 --- a/src/gsong.cpp +++ b/src/song.cpp @@ -1,15 +1,33 @@ /* - * ============================================================================= - * song data model, loading/saving/conversion - * ============================================================================= + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define GSONG_C +// ============================================================================= +// song data model, loading/saving/conversion +// ============================================================================= + +#define SONG_C extern "C" { #include "loadtrk.h" } +#include + INSTR instr[MAX_INSTR]; unsigned char ltable[MAX_TABLES][MAX_TABLELEN]; unsigned char rtable[MAX_TABLES][MAX_TABLELEN]; @@ -29,7 +47,6 @@ int determinechannels(FILE* handle); int savesong(void) { - int c; char ident[] = {'G', 'T', 'S', '5'}; FILE *handle; @@ -39,7 +56,7 @@ int savesong(void) if (strlen(songfilename) < MAX_FILENAME-4) { int extfound = 0; - for (c = strlen(songfilename)-1; c >= 0; c--) + for (int c = strlen(songfilename)-1; c >= 0; c--) { if (songfilename[c] == '.') extfound = 1; } @@ -48,7 +65,6 @@ int savesong(void) handle = fopen(songfilename, "wb"); if (handle) { - int d; int length; int amount; int writebytes; @@ -56,7 +72,7 @@ int savesong(void) // Determine amount of patterns & instruments countpatternlengths(); - for (c = 1; c < MAX_INSTR; c++) + for (int c = 1; c < MAX_INSTR; c++) { if ((instr[c].ad) || (instr[c].sr) || (instr[c].ptr[0]) || (instr[c].ptr[1]) || (instr[c].ptr[2]) || (instr[c].vibdelay) || (instr[c].ptr[3])) @@ -71,7 +87,7 @@ int savesong(void) fwrite(copyrightname, sizeof copyrightname, 1, handle); // Determine amount of songs to be saved - c = MAX_SONGS - 1; + int c = MAX_SONGS - 1; if (numsids == 1) { for (;;) @@ -98,9 +114,9 @@ int savesong(void) fwrite8(handle, amount); // Write songorderlists - for (d = 0; d < amount; d++) + for (int d = 0; d < amount; d++) { - for (c = 0; c < maxChns; c++) + for (int c = 0; c < maxChns; c++) { if (numsids == 1) { @@ -123,7 +139,7 @@ int savesong(void) // Write amount of instruments fwrite8(handle, highestusedinstr); // Write instruments - for (c = 1; c <= highestusedinstr; c++) + for (int c = 1; c <= highestusedinstr; c++) { fwrite8(handle, instr[c].ad); fwrite8(handle, instr[c].sr); @@ -137,7 +153,7 @@ int savesong(void) fwrite(&instr[c].name, MAX_INSTRNAMELEN, 1, handle); } // Write tables - for (c = 0; c < MAX_TABLES; c++) + for (int c = 0; c < MAX_TABLES; c++) { writebytes = gettablelen(c); fwrite8(handle, writebytes); @@ -162,14 +178,13 @@ int savesong(void) int saveinstrument(void) { - int c; char ident[] = {'G', 'T', 'I', '5'}; FILE *handle; if (strlen(instrfilename) < MAX_FILENAME-4) { int extfound = 0; - for (c = strlen(instrfilename)-1; c >= 0; c--) + for (int c = strlen(instrfilename)-1; c >= 0; c--) { if (instrfilename[c] == '.') extfound = 1; } @@ -192,7 +207,7 @@ int saveinstrument(void) fwrite8(handle, instr[einum].gatetimer); fwrite8(handle, instr[einum].firstwave); fwrite(&instr[einum].name, MAX_INSTRNAMELEN, 1, handle); - for (c = 0; c < MAX_TABLES; c++) + for (int c = 0; c < MAX_TABLES; c++) { if (instr[einum].ptr[c]) { @@ -212,7 +227,6 @@ int saveinstrument(void) void loadsong(void) { - int c; int ok = 0; char ident[4]; FILE *handle; @@ -225,9 +239,8 @@ void loadsong(void) if (handle) { fread(ident, 4, 1, handle); - if ((!memcmp(ident, "GTS3", 4)) || (!memcmp(ident, "GTS4", 4)) || (!memcmp(ident, "GTS5", 4))) + if ((!std::memcmp(ident, "GTS3", 4)) || (!std::memcmp(ident, "GTS4", 4)) || (!std::memcmp(ident, "GTS5", 4))) { - int d; int length; int amount; int loadsize; @@ -242,9 +255,9 @@ void loadsong(void) // Read songorderlists channelstoload = determinechannels(handle); amount = fread8(handle); - for (d = 0; d < amount; d++) + for (int d = 0; d < amount; d++) { - for (c = 0; c < channelstoload; c++) + for (int c = 0; c < channelstoload; c++) { length = fread8(handle); loadsize = length; @@ -261,7 +274,7 @@ void loadsong(void) } // Read instruments amount = fread8(handle); - for (c = 1; c <= amount; c++) + for (int c = 1; c <= amount; c++) { instr[c].ad = fread8(handle); instr[c].sr = fread8(handle); @@ -275,7 +288,7 @@ void loadsong(void) fread(&instr[c].name, MAX_INSTRNAMELEN, 1, handle); } // Read tables - for (c = 0; c < MAX_TABLES; c++) + for (int c = 0; c < MAX_TABLES; c++) { loadsize = fread8(handle); fread(ltable[c], loadsize, 1, handle); @@ -283,7 +296,7 @@ void loadsong(void) } // Read patterns amount = fread8(handle); - for (c = 0; c < amount; c++) + for (int c = 0; c < amount; c++) { length = fread8(handle) * 4; fread(pattern[c], length, 1, handle); @@ -293,9 +306,8 @@ void loadsong(void) } // Goattracker v2.xx (3-table) import - if (!memcmp(ident, "GTS2", 4)) + if (!std::memcmp(ident, "GTS2", 4)) { - int d; int length; int amount; int loadsize; @@ -310,9 +322,9 @@ void loadsong(void) // Read songorderlists channelstoload = determinechannels(handle); amount = fread8(handle); - for (d = 0; d < amount; d++) + for (int d = 0; d < amount; d++) { - for (c = 0; c < channelstoload; c++) + for (int c = 0; c < channelstoload; c++) { length = fread8(handle); loadsize = length; @@ -329,7 +341,7 @@ void loadsong(void) } // Read instruments amount = fread8(handle); - for (c = 1; c <= amount; c++) + for (int c = 1; c <= amount; c++) { instr[c].ad = fread8(handle); instr[c].sr = fread8(handle); @@ -343,7 +355,7 @@ void loadsong(void) fread(&instr[c].name, MAX_INSTRNAMELEN, 1, handle); } // Read tables - for (c = 0; c < MAX_TABLES-1; c++) + for (int c = 0; c < MAX_TABLES-1; c++) { loadsize = fread8(handle); fread(ltable[c], loadsize, 1, handle); @@ -351,14 +363,13 @@ void loadsong(void) } // Read patterns amount = fread8(handle); - for (c = 0; c < amount; c++) + for (int c = 0; c < amount; c++) { - int d; length = fread8(handle) * 4; fread(pattern[c], length, 1, handle); // Convert speedtable-requiring commands - for (d = 0; d < length; d++) + for (int d = 0; d < length; d++) { switch (pattern[c][d*4+2]) { @@ -382,9 +393,8 @@ void loadsong(void) songchange(); } // Goattracker 1.xx import - if (!memcmp(ident, "GTS!", 4)) + if (!std::memcmp(ident, "GTS!", 4)) { - int d; int length; int amount; int loadsize; @@ -410,9 +420,9 @@ void loadsong(void) // Read songorderlists channelstoload = determinechannels(handle); amount = fread8(handle); - for (d = 0; d < amount; d++) + for (int d = 0; d < amount; d++) { - for (c = 0; c < channelstoload; c++) + for (int c = 0; c < channelstoload; c++) { length = fread8(handle); loadsize = length; @@ -429,7 +439,7 @@ void loadsong(void) } // Convert instruments - for (c = 1; c < 32; c++) + for (int c = 1; c < 32; c++) { unsigned char wavelen; @@ -448,7 +458,7 @@ void loadsong(void) instr[c].ptr[WTBL] = fw+1; // Convert wavetable - for (d = 0; d < wavelen; d++) + for (int d = 0; d < wavelen; d++) { if (fw < MAX_TABLELEN) { @@ -484,7 +494,7 @@ void loadsong(void) int pulsetime, pulsedist, hlpos; // Check for duplicate pulse settings - for (d = 1; d < c; d++) + for (int d = 1; d < c; d++) { if ((pulse[d] == pulse[c]) && (pulseadd[d] == pulseadd[c]) && (pulselimitlow[d] == pulselimitlow[c]) && (pulselimithigh[d] == pulselimithigh[c])) @@ -604,10 +614,10 @@ void loadsong(void) } // Convert patterns amount = fread8(handle); - for (c = 0; c < amount; c++) + for (int c = 0; c < amount; c++) { length = fread8(handle); - for (d = 0; d < length/3; d++) + for (int d = 0; d < length/3; d++) { unsigned char note, cmd, data, instr; note = fread8(handle); @@ -665,7 +675,7 @@ void loadsong(void) fread(filtertable, 256, 1, handle); // Convert filtertable - for (c = 0; c < 64; c++) + for (int c = 0; c < 64; c++) { filterjumppos[c] = -1; filtermap[c] = 0; @@ -674,7 +684,7 @@ void loadsong(void) if (numfilter > 63) numfilter = 63; - for (c = 1; c <= numfilter; c++) + for (int c = 1; c <= numfilter; c++) { filtermap[c] = ff+1; @@ -721,22 +731,22 @@ void loadsong(void) } // Now fix jumps as the filterstep mapping is known - for (c = 1; c <= numfilter; c++) + for (int c = 1; c <= numfilter; c++) { if (filterjumppos[c] != -1) rtable[FTBL][filterjumppos[c]] = filtermap[rtable[FTBL][filterjumppos[c]]]; } // Fix filterpointers in instruments - for (c = 1; c < 32; c++) + for (int c = 1; c < 32; c++) instr[c].ptr[FTBL] = filtermap[instr[c].ptr[FTBL]]; // Now fix pattern commands - memset(arpmap, 0, sizeof arpmap); - for (c = 0; c < MAX_PATT; c++) + std::memset(arpmap, 0, sizeof arpmap); + for (int c = 0; c < MAX_PATT; c++) { unsigned char i = 0; - for (d = 0; d <= MAX_PATTROWS; d++) + for (int d = 0; d <= MAX_PATTROWS; d++) { if (pattern[c][d*4+1]) i = pattern[c][d*4+1]; @@ -871,15 +881,15 @@ void loadsong(void) } if (ok) { - strcpy(loadedsongfilename, songfilename); + std::strcpy(loadedsongfilename, songfilename); // Reset table views - for (c = 0; c < MAX_TABLES; c++) settableview(c, 0); + for (int c = 0; c < MAX_TABLES; c++) settableview(c, 0); // Convert pulsemodulation speed of < v2.4 songs if (ident[3] < '4') { - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if ((ltable[PTBL][c] < 0x80) && (rtable[PTBL][c])) { @@ -895,7 +905,7 @@ void loadsong(void) // Convert old legato/nohr parameters if (ident[3] < '5') { - for (c = 1; c < MAX_INSTR; c++) + for (int c = 1; c < MAX_INSTR; c++) { if (instr[c].firstwave >= 0x80) { @@ -912,7 +922,7 @@ void loadsong(void) int emptypatt = MAX_PATT-1; findusedpatterns(); - for (c = 0; c < MAX_PATT; c++) + for (int c = 0; c < MAX_PATT; c++) { if (!pattused[c]) { @@ -933,12 +943,11 @@ void loadsong(void) } } - for (c = 0; c < MAX_SONGS; c++) + for (int c = 0; c < MAX_SONGS; c++) { if (songlen_stereo[c][0]) { - int d; - for (d = channelstoload; d < MAX_CHN; d++) + for (int d = channelstoload; d < MAX_CHN; d++) { songorder_stereo[c][d][0] = emptypatt; songorder_stereo[c][d][1] = 0xff; @@ -956,7 +965,6 @@ void loadinstrument(void) { char ident[4]; FILE *handle; - int c,d; int pulsestart = -1; int pulseend = -1; @@ -966,7 +974,7 @@ void loadinstrument(void) stopsong(); fread(ident, 4, 1, handle); - if ((!memcmp(ident, "GTI3", 4)) || (!memcmp(ident, "GTI4", 4)) || (!memcmp(ident, "GTI5", 4))) + if ((!std::memcmp(ident, "GTI3", 4)) || (!std::memcmp(ident, "GTI4", 4)) || (!std::memcmp(ident, "GTI5", 4))) { unsigned char optr[4]; @@ -985,13 +993,14 @@ void loadinstrument(void) deleteinstrtable(einum); // Load new tabledata - for (c = 0; c < MAX_TABLES; c++) + for (int c = 0; c < MAX_TABLES; c++) { int start = gettablelen(c); int len = fread8(handle); if (len) { + int d; for (d = start; (d < start+len) && (d < MAX_TABLELEN); d++) ltable[c][d] = fread8(handle); while (d < start+len) @@ -1008,7 +1017,7 @@ void loadinstrument(void) } if (c != STBL) { - for (d = start; (d < start+len) && (d < MAX_TABLELEN); d++) + for (int d = start; (d < start+len) && (d < MAX_TABLELEN); d++) { if (ltable[c][d] == 0xff) { @@ -1029,7 +1038,7 @@ void loadinstrument(void) } // Goattracker v2.xx (3-table) import - if (!memcmp(ident, "GTI2", 4)) + if (!std::memcmp(ident, "GTI2", 4)) { unsigned char optr[3]; @@ -1048,13 +1057,14 @@ void loadinstrument(void) deleteinstrtable(einum); // Load new tabledata - for (c = 0; c < MAX_TABLES-1; c++) + for (int c = 0; c < MAX_TABLES-1; c++) { int start = gettablelen(c); int len = fread8(handle); if (len) { + int d; for (d = start; (d < start+len) && (d < MAX_TABLELEN); d++) ltable[c][d] = fread8(handle); while (d < start+len) @@ -1069,7 +1079,7 @@ void loadinstrument(void) fread8(handle); d++; } - for (d = start; (d < start+len) && (d < MAX_TABLELEN); d++) + for (int d = start; (d < start+len) && (d < MAX_TABLELEN); d++) { if (ltable[c][d] == 0xff) { @@ -1088,7 +1098,7 @@ void loadinstrument(void) } } // Goattracker 1.xx import - if (!memcmp(ident, "GTI!", 4)) + if (!std::memcmp(ident, "GTI!", 4)) { unsigned char pulse, pulseadd, pulselimitlow, pulselimithigh, wavelen; @@ -1120,7 +1130,7 @@ void loadinstrument(void) instr[einum].ptr[WTBL] = fw+1; // Convert wavetable - for (d = 0; d < wavelen; d++) + for (int d = 0; d < wavelen; d++) { if (fw < MAX_TABLELEN) { @@ -1303,13 +1313,13 @@ void loadinstrument(void) ff++; } } - + fclose(handle); // Convert pulsemodulation speed of < v2.4 instruments if ((ident[3] < '4') && (pulsestart != -1)) { - for (c = pulsestart; (c < pulseend) && (c < MAX_TABLELEN); c++) + for (int c = pulsestart; (c < pulseend) && (c < MAX_TABLELEN); c++) { if ((ltable[PTBL][c] < 0x80) && (rtable[PTBL][c])) { @@ -1361,12 +1371,12 @@ void clearsong(int cs, int cp, int ci, int ct, int cn) chn[c].pattptr = 0; if (cs) { - memset(loadedsongfilename, 0, sizeof loadedsongfilename); + std::memset(loadedsongfilename, 0, sizeof loadedsongfilename); for (d = 0; d < MAX_SONGS; d++) { if (numsids == 1) { - memset(&songorder[d][c][0], 0, MAX_SONGLEN+2); + std::memset(&songorder[d][c][0], 0, MAX_SONGLEN+2); if (!d) { songorder[d][c][0] = c; @@ -1379,7 +1389,7 @@ void clearsong(int cs, int cp, int ci, int ct, int cn) } else if (numsids == 2) { - memset(&songorder_stereo[d][c][0], 0, MAX_SONGLEN+2); + std::memset(&songorder_stereo[d][c][0], 0, MAX_SONGLEN+2); if (!d) { songorder_stereo[d][c][0] = c; @@ -1417,14 +1427,14 @@ void clearsong(int cs, int cp, int ci, int ct, int cn) } if (cn) { - memset(songname, 0, sizeof songname); - memset(authorname, 0, sizeof authorname); - memset(copyrightname, 0, sizeof copyrightname); + std::memset(songname, 0, sizeof songname); + std::memset(authorname, 0, sizeof authorname); + std::memset(copyrightname, 0, sizeof copyrightname); enpos = 0; } if (cp) { - memset(loadedsongfilename, 0, sizeof loadedsongfilename); + std::memset(loadedsongfilename, 0, sizeof loadedsongfilename); for (c = 0; c < MAX_PATT; c++) clearpattern(c); } @@ -1432,7 +1442,7 @@ void clearsong(int cs, int cp, int ci, int ct, int cn) { for (c = 0; c < MAX_INSTR; c++) clearinstr(c); - memset(&instrcopybuffer, 0, sizeof(INSTR)); + std::memset(&instrcopybuffer, 0, sizeof(INSTR)); eipos = 0; eicolumn = 0; einum = 1; @@ -1441,8 +1451,8 @@ void clearsong(int cs, int cp, int ci, int ct, int cn) { for (c = MAX_TABLES-1; c >= 0; c--) { - memset(ltable[c], 0, MAX_TABLELEN); - memset(rtable[c], 0, MAX_TABLELEN); + std::memset(ltable[c], 0, MAX_TABLELEN); + std::memset(rtable[c], 0, MAX_TABLELEN); settableview(c, 0); } } @@ -1550,7 +1560,6 @@ void countthispattern(void) int insertpattern(int p) { - int c, d, e; int tmp = 0; int maxChns = MAX_CHN; if (numsids == 1) maxChns = 3; @@ -1558,16 +1567,16 @@ int insertpattern(int p) findusedpatterns(); if (p >= MAX_PATT-2) return 0; if (pattused[MAX_PATT-1]) return 0; - memmove(pattern[p+2], pattern[p+1], (MAX_PATT-p-2)*(MAX_PATTROWS*4+4)); + std::memmove(pattern[p+2], pattern[p+1], (MAX_PATT-p-2)*(MAX_PATTROWS*4+4)); countpatternlengths(); - for (c = 0; c < MAX_SONGS; c++) + for (int c = 0; c < MAX_SONGS; c++) { if (((numsids==1)&&(songlen[c][0])&&(songlen[c][1])&&(songlen[c][2]))|| ((numsids==2)&&(songlen_stereo[c][0])&& (songlen_stereo[c][1])&&(songlen_stereo[c][2]))) { - for (d = 0; d < maxChns; d++) + for (int d = 0; d < maxChns; d++) { if (numsids == 1) { @@ -1577,7 +1586,7 @@ int insertpattern(int p) { tmp = songlen_stereo[c][d]; } - for (e = 0; e < tmp; e++) + for (int e = 0; e < tmp; e++) { if (numsids == 1) { @@ -1602,7 +1611,7 @@ int insertpattern(int p) } } - for (c = 0; c < maxChns; c++) + for (int c = 0; c < maxChns; c++) { if ((epnum[c] > p) && (epnum[c] != MAX_PATT-1)) epnum[c]++; } @@ -1612,24 +1621,23 @@ int insertpattern(int p) void deletepattern(int p) { - int c, d, e; int tmp; int maxChns = MAX_CHN; if (numsids == 1) maxChns = 3; if (p == MAX_PATT-1) return; - memmove(pattern[p], pattern[p+1], (MAX_PATT-p-1)*(MAX_PATTROWS*4+4)); + std::memmove(pattern[p], pattern[p+1], (MAX_PATT-p-1)*(MAX_PATTROWS*4+4)); clearpattern(MAX_PATT-1); countpatternlengths(); - for (c = 0; c < MAX_SONGS; c++) + for (int c = 0; c < MAX_SONGS; c++) { if (((numsids==1)&&(songlen[c][0])&&(songlen[c][1])&&(songlen[c][2]))|| ((numsids==2)&&(songlen_stereo[c][0])&& (songlen_stereo[c][1])&&(songlen_stereo[c][2]))) { - for (d = 0; d < maxChns; d++) + for (int d = 0; d < maxChns; d++) { if (numsids == 1) { @@ -1639,7 +1647,7 @@ void deletepattern(int p) { tmp = songlen_stereo[c][d]; } - for (e = 0; e < tmp; e++) + for (int e = 0; e < tmp; e++) { if (numsids == 1) { @@ -1661,8 +1669,8 @@ void deletepattern(int p) } } } - - for (c = 0; c < maxChns; c++) + + for (int c = 0; c < maxChns; c++) { if (epnum[c] > p) epnum[c]--; } @@ -1670,29 +1678,26 @@ void deletepattern(int p) void clearpattern(int p) { - int c; - - memset(pattern[p], 0, MAX_PATTROWS*4); - for (c = 0; c < defaultpatternlength; c++) pattern[p][c*4] = REST; - for (c = defaultpatternlength; c <= MAX_PATTROWS; c++) pattern[p][c*4] = ENDPATT; + std::memset(pattern[p], 0, MAX_PATTROWS*4); + for (int c = 0; c < defaultpatternlength; c++) pattern[p][c*4] = REST; + for (int c = defaultpatternlength; c <= MAX_PATTROWS; c++) pattern[p][c*4] = ENDPATT; } void findusedpatterns(void) { - int c, d, e; int tmp; int maxChns = MAX_CHN; if (numsids == 1) maxChns = 3; countpatternlengths(); - memset(pattused, 0, sizeof pattused); - for (c = 0; c < MAX_SONGS; c++) + std::memset(pattused, 0, sizeof pattused); + for (int c = 0; c < MAX_SONGS; c++) { if (((numsids==1)&&(songlen[c][0])&&(songlen[c][1])&&(songlen[c][2]))|| ((numsids==2)&&(songlen_stereo[c][0])&& (songlen_stereo[c][1])&&(songlen_stereo[c][2]))) { - for (d = 0; d < maxChns; d++) + for (int d = 0; d < maxChns; d++) { if (numsids == 1) { @@ -1702,7 +1707,7 @@ void findusedpatterns(void) { tmp = songlen_stereo[c][d]; } - for (e = 0; e < tmp; e++) + for (int e = 0; e < tmp; e++) { if (numsids == 1) { @@ -1726,7 +1731,6 @@ void findusedpatterns(void) void findduplicatepatterns(void) { - int c, d; int maxChns = MAX_CHN; if (numsids == 1) maxChns = 3; @@ -1734,27 +1738,25 @@ void findduplicatepatterns(void) if (numsids == 1) { - for (c = 0; c < MAX_PATT; c++) + for (int c = 0; c < MAX_PATT; c++) { if (pattused[c]) { - for (d = c+1; d < MAX_PATT; d++) + for (int d = c+1; d < MAX_PATT; d++) { if (pattlen[d] == pattlen[c]) { - if (!memcmp(pattern[c], pattern[d], pattlen[c]*4)) + if (!std::memcmp(pattern[c], pattern[d], pattlen[c]*4)) { - int f, g, h; - - for (f = 0; f < MAX_SONGS; f++) + for (int f = 0; f < MAX_SONGS; f++) { if ((songlen[f][0]) && (songlen[f][1]) && (songlen[f][2])) { - for (g = 0; g < maxChns; g++) + for (int g = 0; g < maxChns; g++) { - for (h = 0; h < songlen[f][g]; h++) + for (int h = 0; h < songlen[f][g]; h++) { if (songorder[f][g][h] == d) songorder[f][g][h] = c; @@ -1762,7 +1764,7 @@ void findduplicatepatterns(void) } } } - for (f = 0; f < maxChns; f++) + for (int f = 0; f < maxChns; f++) if (epnum[f] == d) epnum[f] = c; } } @@ -1772,27 +1774,25 @@ void findduplicatepatterns(void) } else if (numsids == 2) { - for (c = 0; c < MAX_PATT; c++) + for (int c = 0; c < MAX_PATT; c++) { if (pattused[c]) { - for (d = c+1; d < MAX_PATT; d++) + for (int d = c+1; d < MAX_PATT; d++) { if (pattlen[d] == pattlen[c]) { - if (!memcmp(pattern[c], pattern[d], pattlen[c]*4)) + if (!std::memcmp(pattern[c], pattern[d], pattlen[c]*4)) { - int f, g, h; - - for (f = 0; f < MAX_SONGS; f++) + for (int f = 0; f < MAX_SONGS; f++) { if ((songlen_stereo[f][0]) && (songlen_stereo[f][1]) && (songlen_stereo[f][2])) { - for (g = 0; g < maxChns; g++) + for (int g = 0; g < maxChns; g++) { - for (h = 0; h < songlen_stereo[f][g]; h++) + for (int h = 0; h < songlen_stereo[f][g]; h++) { if (songorder_stereo[f][g][h] == d) { @@ -1802,7 +1802,7 @@ void findduplicatepatterns(void) } } } - for (f = 0; f < maxChns; f++) + for (int f = 0; f < maxChns; f++) if (epnum[f] == d) epnum[f] = c; } } @@ -1816,19 +1816,17 @@ void findduplicatepatterns(void) void optimizeeverything(int oi, int ot) { - int c, d, e; - stopsong(); findduplicatepatterns(); - memset(instrused, 0, sizeof instrused); + std::memset(instrused, 0, sizeof instrused); - for (c = MAX_PATT-1; c >= 0; c--) + for (int c = MAX_PATT-1; c >= 0; c--) { if (pattused[c]) { - for (d = 0; d < MAX_PATTROWS; d++) + for (int d = 0; d < MAX_PATTROWS; d++) { if (pattern[c][d*4] == ENDPATT) break; if (pattern[c][d*4+1]) @@ -1842,7 +1840,7 @@ void optimizeeverything(int oi, int ot) if (oi) { - for (c = MAX_INSTR-2; c >= 1; c--) + for (int c = MAX_INSTR-2; c >= 1; c--) { if (!instrused[c]) { @@ -1850,11 +1848,11 @@ void optimizeeverything(int oi, int ot) if (c < MAX_INSTR-2) { - memmove(&instr[c], &instr[c+1], (MAX_INSTR-2-c) * sizeof(INSTR)); + std::memmove(&instr[c], &instr[c+1], (MAX_INSTR-2-c) * sizeof(INSTR)); clearinstr(MAX_INSTR-2); - for (d = 0; d < MAX_PATT; d++) + for (int d = 0; d < MAX_PATT; d++) { - for (e = 0; e < pattlen[d]; e++) + for (int e = 0; e < pattlen[d]; e++) { if ((pattern[d][e*4+1] > c) && (pattern[d][e*4+1] != MAX_INSTR-1)) pattern[d][e*4+1]--; @@ -1867,13 +1865,12 @@ void optimizeeverything(int oi, int ot) if (ot) { - for (c = 0; c < MAX_TABLES; c++) optimizetable(c); + for (int c = 0; c < MAX_TABLES; c++) optimizetable(c); } } void mergesong(void) { - int c; char ident[4]; FILE *handle; int songbase; @@ -1884,7 +1881,7 @@ void mergesong(void) // Determine amount of patterns & instruments countpatternlengths(); highestusedinstr = 0; - for (c = 1; c < MAX_INSTR; c++) + for (int c = 1; c < MAX_INSTR; c++) { if ((instr[c].ad) || (instr[c].sr) || (instr[c].ptr[0]) || (instr[c].ptr[1]) || (instr[c].ptr[2]) || (instr[c].vibdelay) || (instr[c].ptr[3])) @@ -1894,7 +1891,7 @@ void mergesong(void) } // Determine amount of songs - c = MAX_SONGS - 1; + int c = MAX_SONGS - 1; if (numsids == 1) { for (;;) @@ -1922,7 +1919,7 @@ void mergesong(void) instrbase = highestusedinstr; songbase = c + 1; - for (c = 0; c < MAX_TABLES; c++) + for (int c = 0; c < MAX_TABLES; c++) { tablebase[c] = gettablelen(c); } @@ -1932,10 +1929,8 @@ void mergesong(void) if (handle) { fread(ident, 4, 1, handle); - if ((!memcmp(ident, "GTS3", 4)) || (!memcmp(ident, "GTS4", 4)) || (!memcmp(ident, "GTS5", 4))) + if ((!std::memcmp(ident, "GTS3", 4)) || (!std::memcmp(ident, "GTS4", 4)) || (!std::memcmp(ident, "GTS5", 4))) { - int d; - int e; int length; int amount; int loadsize; @@ -1949,9 +1944,9 @@ void mergesong(void) amount = fread8(handle); if (amount + songbase > MAX_SONGS) goto ABORT; - for (d = 0; d < amount; d++) + for (int d = 0; d < amount; d++) { - for (c = 0; c < channelstoload; c++) + for (int c = 0; c < channelstoload; c++) { length = fread8(handle); loadsize = length; @@ -1970,7 +1965,7 @@ void mergesong(void) ); } // Remap patterns - for (e = 0; e < loadsize - 1; e++) + for (int e = 0; e < loadsize - 1; e++) { if (numsids == 1) { @@ -1989,7 +1984,7 @@ void mergesong(void) amount = fread8(handle); if (amount + instrbase > MAX_INSTR) goto ABORT; - for (c = 1; c <= amount; c++) + for (int c = 1; c <= amount; c++) { instr[c + instrbase].ad = fread8(handle); instr[c + instrbase].sr = fread8(handle); @@ -2011,7 +2006,7 @@ void mergesong(void) fread(&instr[c + instrbase].name, MAX_INSTRNAMELEN, 1, handle); } // Read tables - for (c = 0; c < MAX_TABLES; c++) + for (int c = 0; c < MAX_TABLES; c++) { loadsize = fread8(handle); if (loadsize + tablebase[c] > MAX_TABLELEN) @@ -2019,7 +2014,7 @@ void mergesong(void) fread(<able[c][tablebase[c]], loadsize, 1, handle); fread(&rtable[c][tablebase[c]], loadsize, 1, handle); // Remap jumps and tablecommands - for (d = tablebase[c]; d < tablebase[c] + loadsize; d++) + for (int d = tablebase[c]; d < tablebase[c] + loadsize; d++) { if (ltable[c][d] == 0xff && rtable[c][d] > 0) rtable[c][d] += tablebase[c]; @@ -2042,12 +2037,12 @@ void mergesong(void) if (amount + pattbase > MAX_PATT) goto ABORT; - for (c = 0; c < amount; c++) + for (int c = 0; c < amount; c++) { length = fread8(handle) * 4; fread(pattern[c + pattbase], length, 1, handle); // Remap pattern instruments and commands - for (d = 0; d < length; d += 4) + for (int d = 0; d < length; d += 4) { if (pattern[c + pattbase][d + 1] > 0) pattern[c + pattbase][d + 1] += instrbase; @@ -2065,7 +2060,7 @@ void mergesong(void) } } - ABORT: +ABORT: fclose(handle); countpatternlengths(); songchange(); @@ -2074,17 +2069,16 @@ void mergesong(void) int determinechannels(FILE* handle) { int returnpos = ftell(handle); - int c, d; int songs = fread8(handle); unsigned char songbuffer[257]; - for (d = 0; d < songs; d++) + for (int d = 0; d < songs; d++) { - for (c = 0; c < MAX_CHN; c++) + for (int c = 0; c < MAX_CHN; c++) { int loadsize = fread8(handle); loadsize++; - memset(songbuffer, 0, 257); + std::memset(songbuffer, 0, 257); fread(songbuffer, loadsize, 1, handle); // Check that each track of each song has a valid endmark. diff --git a/src/gsong.h b/src/song.h similarity index 59% rename from src/gsong.h rename to src/song.h index 26464d2..6645d94 100644 --- a/src/gsong.h +++ b/src/song.h @@ -1,11 +1,29 @@ -#ifndef GSONG_H -#define GSONG_H +/* + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef SONG_H +#define SONG_H #ifdef __cplusplus extern "C" { #endif -#ifndef GSONG_C +#ifndef SONG_C extern INSTR instr[MAX_INSTR]; extern unsigned char ltable[MAX_TABLES][MAX_TABLELEN]; extern unsigned char rtable[MAX_TABLES][MAX_TABLELEN]; From a9a5c79ebce0c7a47670472321a189dfd81f0f5b Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 16:38:58 +0200 Subject: [PATCH 21/39] Update --- CMakeLists.txt | 2 +- src/gsid.h | 29 ------------------------ src/loadtrk.h | 2 +- src/{gsid.cpp => sid.cpp} | 35 +++++++++++++++++++++-------- src/sid.h | 47 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 40 deletions(-) delete mode 100644 src/gsid.h rename src/{gsid.cpp => sid.cpp} (85%) create mode 100644 src/sid.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 14e5cb7..ad693f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ set(LOADTRK_SOURCES src/help.cpp src/gsound.c src/console.cpp - src/gsid.cpp + src/sid.cpp src/asm/asmtab.c src/asm/chnkpool.c src/asm/expr.c diff --git a/src/gsid.h b/src/gsid.h deleted file mode 100644 index 9ea401b..0000000 --- a/src/gsid.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef GSID_H -#define GSID_H - -#define NUMSIDREGS 0x19 -#define SIDWRITEDELAY 14 // lda $xxxx,x 4 cycles, sta $d400,x 5 cycles, dex 2 cycles, bpl 3 cycles -#define SIDWAVEDELAY 4 // and $xxxx,x 4 cycles extra - -#ifdef __cplusplus -extern "C" { -#endif - -void sid_init(int speed, unsigned m, - unsigned ntsc, unsigned interpolate, - unsigned customclockrate, unsigned numsids, - float filterbias, unsigned combwaves); -int sid_fillbuffer(short *ptr, int samples); -int sid_fillbuffer_stereo(short *lptr, short *rptr, int samples); -unsigned char sid_getorder(unsigned char index); - -#ifndef GSID_C -extern unsigned char sidreg[NUMSIDREGS]; -extern unsigned char sidreg2[NUMSIDREGS]; -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/loadtrk.h b/src/loadtrk.h index a46a77b..15f6d43 100644 --- a/src/loadtrk.h +++ b/src/loadtrk.h @@ -14,7 +14,7 @@ #include "gcommon.h" #include "console.h" #include "gsound.h" -#include "gsid.h" +#include "sid.h" #include "song.h" #include "play.h" #include "display.h" diff --git a/src/gsid.cpp b/src/sid.cpp similarity index 85% rename from src/gsid.cpp rename to src/sid.cpp index 02aa6a1..307e0e5 100644 --- a/src/gsid.cpp +++ b/src/sid.cpp @@ -1,18 +1,35 @@ /* - * ============================================================================= - * reSIDfp interface - * ============================================================================= + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define GSID_C +// ============================================================================= +// reSIDfp interface +// ============================================================================= -#include -#include -#include +#define SID_C + +#include "sid.h" -#include "gsid.h" #include "gsound.h" +#include + +#include + int clockrate; int samplerate; unsigned char sidreg[NUMSIDREGS]; @@ -128,7 +145,7 @@ int sid_fillbuffer(short *ptr, int samples) int result = 0; int total = 0; - int badline = rand() % NUMSIDREGS; + int badline = std::rand() % NUMSIDREGS; int tdelta = clockrate * samples / samplerate; if (tdelta <= 0) return total; diff --git a/src/sid.h b/src/sid.h new file mode 100644 index 0000000..ffc0d75 --- /dev/null +++ b/src/sid.h @@ -0,0 +1,47 @@ +/* + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef SID_H +#define SID_H + +#define NUMSIDREGS 0x19 +#define SIDWRITEDELAY 14 // lda $xxxx,x 4 cycles, sta $d400,x 5 cycles, dex 2 cycles, bpl 3 cycles +#define SIDWAVEDELAY 4 // and $xxxx,x 4 cycles extra + +#ifdef __cplusplus +extern "C" { +#endif + +void sid_init(int speed, unsigned m, + unsigned ntsc, unsigned interpolate, + unsigned customclockrate, unsigned numsids, + float filterbias, unsigned combwaves); +int sid_fillbuffer(short *ptr, int samples); +int sid_fillbuffer_stereo(short *lptr, short *rptr, int samples); +unsigned char sid_getorder(unsigned char index); + +#ifndef SID_C +extern unsigned char sidreg[NUMSIDREGS]; +extern unsigned char sidreg2[NUMSIDREGS]; +#endif + +#ifdef __cplusplus +} +#endif + +#endif From c3489915e24cfb07050997bd25fb19cad41954c3 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 16:40:15 +0200 Subject: [PATCH 22/39] Update --- CMakeLists.txt | 2 +- src/{gsound.c => gsound.cpp} | 30 ++++++++++++++++-------------- src/gsound.h | 8 ++++++++ 3 files changed, 25 insertions(+), 15 deletions(-) rename src/{gsound.c => gsound.cpp} (92%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad693f1..02b4056 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ set(LOADTRK_SOURCES src/file.cpp src/greloc.c src/help.cpp - src/gsound.c + src/gsound.cpp src/console.cpp src/sid.cpp src/asm/asmtab.c diff --git a/src/gsound.c b/src/gsound.cpp similarity index 92% rename from src/gsound.c rename to src/gsound.cpp index 882c479..9f42e46 100644 --- a/src/gsound.c +++ b/src/gsound.cpp @@ -14,17 +14,19 @@ # include #endif +extern "C" { #include "loadtrk.h" +} // General / reSID output int playspeed; int useexsid = 0; int initted = 0; unsigned framerate = PALFRAMERATE; -Sint16 *buffer = NULL; -Sint16 *lbuffer = NULL; -Sint16 *rbuffer = NULL; -FILE *writehandle = NULL; +Sint16 *buffer = nullptr; +Sint16 *lbuffer = nullptr; +Sint16 *rbuffer = nullptr; +FILE *writehandle = nullptr; SDL_TimerID timer = 0; void sound_playrout(void); @@ -32,7 +34,7 @@ void sound_mixer(Sint32 *dest, unsigned samples); Uint32 sound_timer(void *userdata, SDL_TimerID timerID, Uint32 interval); #ifdef USE_EXSID -void* exsidfd = NULL; +void* exsidfd = nullptr; unsigned exsidDelay = 0; #endif @@ -102,7 +104,7 @@ int sound_init(unsigned mr, unsigned writer, unsigned m, unsigned ntsc, exsidDelay -= SIDWRITEDELAY*NUMSIDREGS; useexsid = 1; - timer = SDL_AddTimer(1000 / framerate, sound_timer, NULL); + timer = SDL_AddTimer(1000 / framerate, sound_timer, nullptr); goto SOUNDOK; } #endif @@ -153,38 +155,38 @@ void sound_uninit(void) } else { - snd_setcustommixer(NULL); - snd_player = NULL; + snd_setcustommixer(nullptr); + snd_player = nullptr; } if (writehandle) { fclose(writehandle); - writehandle = NULL; + writehandle = nullptr; } if (buffer) { free(buffer); - buffer = NULL; + buffer = nullptr; } if (lbuffer) { free(lbuffer); - lbuffer = NULL; + lbuffer = nullptr; } if (rbuffer) { free(rbuffer); - rbuffer = NULL; + rbuffer = nullptr; } #ifdef USE_EXSID if (useexsid) { - if (exsidfd != NULL) + if (exsidfd != nullptr) { for (c = 0; c < NUMSIDREGS; c++) { @@ -196,7 +198,7 @@ void sound_uninit(void) exSID_exit(exsidfd); exSID_free(exsidfd); - exsidfd = NULL; + exsidfd = nullptr; } #endif } diff --git a/src/gsound.h b/src/gsound.h index 6705881..d7f4920 100644 --- a/src/gsound.h +++ b/src/gsound.h @@ -12,9 +12,17 @@ #define MIXBUFFERSIZE 65536 +#ifdef __cplusplus +extern "C" { +#endif + int sound_init(unsigned mr, unsigned writer, unsigned m, unsigned ntsc, unsigned multiplier, unsigned interpolate, unsigned customclockrate, unsigned exsid, float filterbias, unsigned combwaves); void sound_uninit(void); +#ifdef __cplusplus +} +#endif + #endif From f1d5bfc337e68dbc8c7db26b1bc8f4e9d349a82d Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 16:45:52 +0200 Subject: [PATCH 23/39] Update --- CMakeLists.txt | 2 +- src/gsound.h | 28 --------------- src/loadtrk.h | 2 +- src/sid.cpp | 2 +- src/{gsound.cpp => sound.cpp} | 64 ++++++++++++++++++++++------------- src/sound.h | 46 +++++++++++++++++++++++++ 6 files changed, 90 insertions(+), 54 deletions(-) delete mode 100644 src/gsound.h rename src/{gsound.cpp => sound.cpp} (79%) create mode 100644 src/sound.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 02b4056..6bffa17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ set(LOADTRK_SOURCES src/file.cpp src/greloc.c src/help.cpp - src/gsound.cpp + src/sound.cpp src/console.cpp src/sid.cpp src/asm/asmtab.c diff --git a/src/gsound.h b/src/gsound.h deleted file mode 100644 index d7f4920..0000000 --- a/src/gsound.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef GSOUND_H -#define GSOUND_H - -#define MINMIXRATE 11025 -#define MAXMIXRATE 48000 -#define DEFAULTMIXRATE 48000 - -#define PALFRAMERATE 50 -#define PALCLOCKRATE 985248 -#define NTSCFRAMERATE 60 -#define NTSCCLOCKRATE 1022727 - -#define MIXBUFFERSIZE 65536 - -#ifdef __cplusplus -extern "C" { -#endif - -int sound_init(unsigned mr, unsigned writer, unsigned m, unsigned ntsc, - unsigned multiplier, unsigned interpolate, unsigned customclockrate, - unsigned exsid, float filterbias, unsigned combwaves); -void sound_uninit(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/loadtrk.h b/src/loadtrk.h index 15f6d43..6e14398 100644 --- a/src/loadtrk.h +++ b/src/loadtrk.h @@ -13,7 +13,7 @@ #include "gcommon.h" #include "console.h" -#include "gsound.h" +#include "sound.h" #include "sid.h" #include "song.h" #include "play.h" diff --git a/src/sid.cpp b/src/sid.cpp index 307e0e5..31582c5 100644 --- a/src/sid.cpp +++ b/src/sid.cpp @@ -24,7 +24,7 @@ #include "sid.h" -#include "gsound.h" +#include "sound.h" #include diff --git a/src/gsound.cpp b/src/sound.cpp similarity index 79% rename from src/gsound.cpp rename to src/sound.cpp index 9f42e46..03cc1a9 100644 --- a/src/gsound.cpp +++ b/src/sound.cpp @@ -1,10 +1,30 @@ /* - * ============================================================================= - * sound routines - * ============================================================================= + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define GSOUND_C +// ============================================================================= +// sound routines +// ============================================================================= + +#define SOUND_C + +extern "C" { +#include "loadtrk.h" +} #ifdef __WIN32__ #include @@ -14,14 +34,12 @@ # include #endif -extern "C" { -#include "loadtrk.h" -} +#include // General / reSID output int playspeed; -int useexsid = 0; -int initted = 0; +bool useexsid = false; +bool initted = false; unsigned framerate = PALFRAMERATE; Sint16 *buffer = nullptr; Sint16 *lbuffer = nullptr; @@ -103,7 +121,7 @@ int sound_init(unsigned mr, unsigned writer, unsigned m, unsigned ntsc, exsidDelay /= framerate; exsidDelay -= SIDWRITEDELAY*NUMSIDREGS; - useexsid = 1; + useexsid = true; timer = SDL_AddTimer(1000 / framerate, sound_timer, nullptr); goto SOUNDOK; } @@ -135,15 +153,17 @@ int sound_init(unsigned mr, unsigned writer, unsigned m, unsigned ntsc, snd_player = &sound_playrout; snd_setcustommixer(sound_mixer); +#ifdef USE_EXSID SOUNDOK: - initted = 1; +#endif + initted = true; return 1; } void sound_uninit(void) { if (!initted) return; - initted = 0; + initted = false; // Apparently a delay is needed to make sure the sound timer thread is // not mixing stuff anymore, and we can safely delete related structures @@ -167,19 +187,19 @@ void sound_uninit(void) if (buffer) { - free(buffer); + std::free(buffer); buffer = nullptr; } if (lbuffer) { - free(lbuffer); + std::free(lbuffer); lbuffer = nullptr; } if (rbuffer) { - free(rbuffer); + std::free(rbuffer); rbuffer = nullptr; } @@ -188,7 +208,7 @@ void sound_uninit(void) { if (exsidfd != nullptr) { - for (c = 0; c < NUMSIDREGS; c++) + for (int c = 0; c < NUMSIDREGS; c++) { exSID_clkdwrite(exsidfd, SIDWRITEDELAY, c, 0x00); } @@ -225,7 +245,7 @@ void sound_playrout(void) if (useexsid) { exSID_delay(exsidfd, exsidDelay); - for (c = 0; c < NUMSIDREGS; c++) + for (int c = 0; c < NUMSIDREGS; c++) { unsigned o = sid_getorder(c); exSID_clkdwrite(exsidfd, SIDWRITEDELAY, o, sidreg[o]); @@ -236,8 +256,6 @@ void sound_playrout(void) void sound_mixer(Sint32 *dest, unsigned samples) { - int c; - if (!initted) return; if (samples > MIXBUFFERSIZE) return; @@ -250,7 +268,7 @@ void sound_mixer(Sint32 *dest, unsigned samples) fwrite(buffer, samples * sizeof(Uint16), 1, writehandle); } - for (c = 0; c < samples; c++) + for (unsigned c = 0; c < samples; c++) { dest[c] = buffer[c]; } @@ -260,7 +278,7 @@ void sound_mixer(Sint32 *dest, unsigned samples) sid_fillbuffer_stereo(lbuffer, rbuffer, samples); if (writehandle) { - for (c = 0; c < samples; c++) + for (unsigned c = 0; c < samples; c++) { fwrite(&lbuffer[c], sizeof(Sint16), 1, writehandle); fwrite(&rbuffer[c], sizeof(Sint16), 1, writehandle); @@ -268,7 +286,7 @@ void sound_mixer(Sint32 *dest, unsigned samples) } if (monomode) { - for (c = 0; c < samples; c++) + for (unsigned c = 0; c < samples; c++) { dest[c*2] = lbuffer[c] / 2 + rbuffer[c] / 2; dest[c*2+1] = dest[c*2]; @@ -276,7 +294,7 @@ void sound_mixer(Sint32 *dest, unsigned samples) } else { - for (c = 0; c < samples; c++) + for (unsigned c = 0; c < samples; c++) { dest[c*2] = lbuffer[c] * panning + rbuffer[c] * (1-panning); dest[c*2+1] = rbuffer[c] * panning + lbuffer[c] * (1-panning); diff --git a/src/sound.h b/src/sound.h new file mode 100644 index 0000000..93ed275 --- /dev/null +++ b/src/sound.h @@ -0,0 +1,46 @@ +/* + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef SOUND_H +#define SOUND_H + +#define MINMIXRATE 11025 +#define MAXMIXRATE 48000 +#define DEFAULTMIXRATE 48000 + +#define PALFRAMERATE 50 +#define PALCLOCKRATE 985248 +#define NTSCFRAMERATE 60 +#define NTSCCLOCKRATE 1022727 + +#define MIXBUFFERSIZE 65536 + +#ifdef __cplusplus +extern "C" { +#endif + +int sound_init(unsigned mr, unsigned writer, unsigned m, unsigned ntsc, + unsigned multiplier, unsigned interpolate, unsigned customclockrate, + unsigned exsid, float filterbias, unsigned combwaves); +void sound_uninit(void); + +#ifdef __cplusplus +} +#endif + +#endif From a52200501404ba05dfdcfc8f7e318b8b5f34f303 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 16:46:40 +0200 Subject: [PATCH 24/39] Update --- CMakeLists.txt | 2 +- src/{gtable.c => gtable.cpp} | 2 ++ src/gtable.h | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) rename src/{gtable.c => gtable.cpp} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bffa17..4e13db4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ set(LOADTRK_SOURCES src/order.cpp src/pattern.cpp src/instr.cpp - src/gtable.c + src/gtable.cpp src/play.cpp src/display.cpp src/file.cpp diff --git a/src/gtable.c b/src/gtable.cpp similarity index 99% rename from src/gtable.c rename to src/gtable.cpp index e92475c..5bf54b7 100644 --- a/src/gtable.c +++ b/src/gtable.cpp @@ -6,7 +6,9 @@ #define GTABLE_C +extern "C" { #include "loadtrk.h" +} unsigned char ltablecopybuffer[MAX_TABLELEN]; unsigned char rtablecopybuffer[MAX_TABLELEN]; diff --git a/src/gtable.h b/src/gtable.h index ca34ddf..955f6ca 100644 --- a/src/gtable.h +++ b/src/gtable.h @@ -7,6 +7,10 @@ #define MST_PORTAMENTO 3 #define MST_RAW 4 +#ifdef __cplusplus +extern "C" { +#endif + #ifndef GTABLE_C extern int etview[MAX_TABLES]; extern int etnum; @@ -35,4 +39,8 @@ void validatetableview(void); void exectable(int num, int ptr); int findfreespeedtable(void); +#ifdef __cplusplus +} +#endif + #endif From 0f41d2336d6f0d79cfda7355c724b26c0e82da4e Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 16:51:49 +0200 Subject: [PATCH 25/39] Update --- CMakeLists.txt | 2 +- src/loadtrk.h | 2 +- src/{gtable.cpp => table.cpp} | 106 ++++++++++++++++++---------------- src/{gtable.h => table.h} | 24 +++++++- 4 files changed, 79 insertions(+), 55 deletions(-) rename src/{gtable.cpp => table.cpp} (91%) rename src/{gtable.h => table.h} (53%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e13db4..cc3417a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ set(LOADTRK_SOURCES src/order.cpp src/pattern.cpp src/instr.cpp - src/gtable.cpp + src/table.cpp src/play.cpp src/display.cpp src/file.cpp diff --git a/src/loadtrk.h b/src/loadtrk.h index 6e14398..4b2ed93 100644 --- a/src/loadtrk.h +++ b/src/loadtrk.h @@ -23,7 +23,7 @@ #include "pattern.h" #include "order.h" #include "instr.h" -#include "gtable.h" +#include "table.h" #define EDIT_PATTERN 0 #define EDIT_ORDERLIST 1 diff --git a/src/gtable.cpp b/src/table.cpp similarity index 91% rename from src/gtable.cpp rename to src/table.cpp index 5bf54b7..b010380 100644 --- a/src/gtable.cpp +++ b/src/table.cpp @@ -1,15 +1,33 @@ /* - * ============================================================================= - * table editor - * ============================================================================= + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define GTABLE_C +// ============================================================================= +// table editor +// ============================================================================= + +#define TABLE_C extern "C" { #include "loadtrk.h" } +#include + unsigned char ltablecopybuffer[MAX_TABLELEN]; unsigned char rtablecopybuffer[MAX_TABLELEN]; int tablecopyrows = 0; @@ -25,8 +43,6 @@ int etmarkend; void tablecommands(void) { - int c; - switch(rawkey) { case KEY_Q: @@ -53,7 +69,7 @@ void tablecommands(void) rtable[etnum][etpos] = speed & 0xff; } break; - + case KEY_W: if ((shiftpressed) && (etnum == STBL)) { @@ -74,7 +90,7 @@ void tablecommands(void) rtable[etnum][etpos] = speed; } break; - + case KEY_S: if ((shiftpressed) && (etnum == STBL)) { @@ -129,17 +145,17 @@ void tablecommands(void) case KEY_HOME: while (etpos != 0) tableup(); break; - + case KEY_END: while (etpos != MAX_TABLELEN-1) tabledown(); break; case KEY_PGUP: - for (c = 0; c < PGUPDNREPEAT; c++) tableup(); + for (int c = 0; c < PGUPDNREPEAT; c++) tableup(); break; case KEY_PGDN: - for (c = 0; c < PGUPDNREPEAT; c++) tabledown(); + for (int c = 0; c < PGUPDNREPEAT; c++) tabledown(); break; case KEY_UP: @@ -159,7 +175,7 @@ void tablecommands(void) int d = 0; if (etmarkstart <= etmarkend) { - for (c = etmarkstart; c <= etmarkend; c++) + for (int c = etmarkstart; c <= etmarkend; c++) { ltablecopybuffer[d] = ltable[etmarknum][c]; rtablecopybuffer[d] = rtable[etmarknum][c]; @@ -173,7 +189,7 @@ void tablecommands(void) } else { - for (c = etmarkend; c <= etmarkstart; c++) + for (int c = etmarkend; c <= etmarkstart; c++) { ltablecopybuffer[d] = ltable[etmarknum][c]; rtablecopybuffer[d] = rtable[etmarknum][c]; @@ -196,7 +212,7 @@ void tablecommands(void) { if (tablecopyrows) { - for (c = 0; c < tablecopyrows; c++) + for (int c = 0; c < tablecopyrows; c++) { ltable[etnum][etpos] = ltablecopybuffer[c]; rtable[etnum][etpos] = rtablecopybuffer[c]; @@ -246,7 +262,6 @@ void tablecommands(void) case KEY_L: if (etnum == PTBL) { - int c; int currentpulse = -1; int targetpulse = ltable[etnum][etpos] << 4; int speed = rtable[etnum][etpos]; @@ -255,6 +270,7 @@ void tablecommands(void) if (!speed) break; + int c; // Follow the chain of pulse commands backwards to the nearest set command so we know what current pulse is for (c = etpos-1; c >= 0; c--) { @@ -294,7 +310,7 @@ void tablecommands(void) while (time) { - if (abs(speed) < 128) + if (std::abs(speed) < 128) { if (time < 127) ltable[etnum][etpos] = time; else ltable[etnum][etpos] = 127; @@ -314,7 +330,6 @@ void tablecommands(void) } if (etnum == FTBL) { - int c; int currentfilter = -1; int targetfilter = ltable[etnum][etpos]; int speed = rtable[etnum][etpos] & 0x7f; @@ -323,6 +338,7 @@ void tablecommands(void) if (!speed) break; + int c; // Follow the chain of filter commands backwards to the nearest set command so we know what current pulse is for (c = etpos-1; c >= 0; c--) { @@ -494,7 +510,7 @@ void tablecommands(void) return; } break; - + case KEY_APOST2: if (shiftpressed) { @@ -629,10 +645,8 @@ void deletetable(int num, int pos) void inserttable(int num, int pos, int mode) { - int c, d; - // Shift tablepointers in instruments - for (c = 1; c < MAX_INSTR; c++) + for (int c = 1; c < MAX_INSTR; c++) { if (!mode) { @@ -645,7 +659,7 @@ void inserttable(int num, int pos, int mode) } // Shift tablepointers in wavetable commands - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if ((ltable[WTBL][c] >= WAVECMD) && (ltable[WTBL][c] <= WAVELASTCMD)) { @@ -684,9 +698,9 @@ void inserttable(int num, int pos, int mode) // Shift tablepointers in patterns - for (c = 0; c < MAX_PATT; c++) + for (int c = 0; c < MAX_PATT; c++) { - for (d = 0; d <= MAX_PATTROWS; d++) + for (int d = 0; d <= MAX_PATTROWS; d++) { if (num < STBL) { @@ -723,7 +737,7 @@ void inserttable(int num, int pos, int mode) // Shift jumppointers in the table itself if (num != STBL) { - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if (ltable[num][c] == 0xff) { @@ -739,7 +753,7 @@ void inserttable(int num, int pos, int mode) } } - for (c = MAX_TABLELEN-1; c >= pos; c--) + for (int c = MAX_TABLELEN-1; c >= pos; c--) { if (c > pos) { @@ -765,7 +779,6 @@ void inserttable(int num, int pos, int mode) int gettablelen(int num) { int c; - for (c = MAX_TABLELEN-1; c >= 0; c--) { if (ltable[num][c] | rtable[num][c]) break; @@ -775,11 +788,10 @@ int gettablelen(int num) int gettablepartlen(int num, int pos) { - int c; - if (pos < 0) return 0; if (num == STBL) return 1; + int c; for (c = pos; c < MAX_TABLELEN; c++) { if (ltable[num][c] == 0xff) @@ -793,13 +805,11 @@ int gettablepartlen(int num, int pos) void optimizetable(int num) { - int c,d; + std::memset(tableused, 0, sizeof tableused); - memset(tableused, 0, sizeof tableused); - - for (c = 0; c < MAX_PATT; c++) + for (int c = 0; c < MAX_PATT; c++) { - for (d = 0; d < pattlen[c]; d++) + for (int d = 0; d < pattlen[c]; d++) { if ((pattern[c][d*4+2] >= CMD_SETWAVEPTR) && (pattern[c][d*4+2] <= CMD_SETFILTERPTR)) exectable(pattern[c][d*4+2] - CMD_SETWAVEPTR, pattern[c][d*4+3]); @@ -810,21 +820,21 @@ void optimizetable(int num) } } - for (c = 0; c < MAX_INSTR; c++) + for (int c = 0; c < MAX_INSTR; c++) { - for (d = 0; d < MAX_TABLES; d++) + for (int d = 0; d < MAX_TABLES; d++) { exectable(d, instr[c].ptr[d]); } } - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if (tableused[WTBL][c+1]) { if ((ltable[WTBL][c] >= WAVECMD) && (ltable[WTBL][c] <= WAVELASTCMD)) { - d = -1; + int d = -1; switch(ltable[WTBL][c] - WAVECMD) { @@ -849,6 +859,7 @@ void optimizetable(int num) } } + int c; for (c = MAX_TABLELEN-1; c >= 0; c--) { if ((ltable[num][c]) || (rtable[num][c])) break; @@ -861,7 +872,6 @@ void optimizetable(int num) int makespeedtable(unsigned data, int mode, int makenew) { - int c; unsigned char l = 0, r = 0; if (!data) return -1; @@ -887,7 +897,7 @@ int makespeedtable(unsigned data, int mode, int makenew) l = (data << 2) >> 8; r = (data << 2) & 0xff; break; - + case MST_RAW: r = data & 0xff; l = data >> 8; @@ -896,14 +906,14 @@ int makespeedtable(unsigned data, int mode, int makenew) if (makenew == 0) { - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if ((ltable[STBL][c] == l) && (rtable[STBL][c] == r)) return c; } } - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if ((!ltable[STBL][c]) && (!rtable[STBL][c])) { @@ -919,10 +929,9 @@ int makespeedtable(unsigned data, int mode, int makenew) void deleteinstrtable(int i) { - int c,d; int eraseok = 1; - for (c = 0; c < MAX_TABLES; c++) + for (int c = 0; c < MAX_TABLES; c++) { if (instr[i].ptr[c]) { @@ -930,7 +939,7 @@ void deleteinstrtable(int i) int len = gettablepartlen(c, pos); // Check that this table area isn't used by another instrument - for (d = 1; d < MAX_INSTR; d++) + for (int d = 1; d < MAX_INSTR; d++) { if ((d != i) && (instr[d].ptr[c])) { @@ -974,9 +983,7 @@ void validatetableview(void) // Table view lock? if (etlock) { - int c; - - for (c = 0; c < MAX_TABLES; c++) etview[c] = etview[etnum]; + for (int c = 0; c < MAX_TABLES; c++) etview[c] = etview[etnum]; } } @@ -1051,8 +1058,7 @@ void exectable(int num, int ptr) int findfreespeedtable(void) { - int c; - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if ((!ltable[STBL][c]) && (!rtable[STBL][c])) { diff --git a/src/gtable.h b/src/table.h similarity index 53% rename from src/gtable.h rename to src/table.h index 955f6ca..f8fd733 100644 --- a/src/gtable.h +++ b/src/table.h @@ -1,5 +1,23 @@ -#ifndef GTABLE_H -#define GTABLE_H +/* + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef TABLE_H +#define TABLE_H #define MST_NOFINEVIB 0 #define MST_FINEVIB 1 @@ -11,7 +29,7 @@ extern "C" { #endif -#ifndef GTABLE_C +#ifndef TABLE_C extern int etview[MAX_TABLES]; extern int etnum; extern int etpos; From ddade6e084774b1efad285c8e3e29b74f880cad3 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 16:55:13 +0200 Subject: [PATCH 26/39] Update --- CMakeLists.txt | 2 +- src/{greloc.c => greloc.cpp} | 22 ++++++++++++---------- src/greloc.h | 10 +++++++++- 3 files changed, 22 insertions(+), 12 deletions(-) rename src/{greloc.c => greloc.cpp} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc3417a..530c099 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ set(LOADTRK_SOURCES src/play.cpp src/display.cpp src/file.cpp - src/greloc.c + src/greloc.cpp src/help.cpp src/sound.cpp src/console.cpp diff --git a/src/greloc.c b/src/greloc.cpp similarity index 99% rename from src/greloc.c rename to src/greloc.cpp index 425a49e..5ebf950 100644 --- a/src/greloc.c +++ b/src/greloc.cpp @@ -6,11 +6,13 @@ #define GRELOC_C +extern "C" { #include "loadtrk.h" #include "membuf.h" #include "parse.h" +} -char *playeroptname[] = +const char *playeroptname[] = { "Buffered SID-writes", "Sound effect support", @@ -21,13 +23,13 @@ char *playeroptname[] = "Full SID buffering" }; -char *tableleftname[] = { +const char *tableleftname[] = { "mt_wavetbl", "mt_pulsetimetbl", "mt_filttimetbl", "mt_speedlefttbl"}; -char *tablerightname[] = { +const char *tablerightname[] = { "mt_notetbl", "mt_pulsespdtbl", "mt_filtspdtbl", @@ -99,7 +101,7 @@ void relocator(void) char packedfilter[MAX_FILENAME]; unsigned char *packeddata = NULL; - char *playername = "player.s"; + const char *playername = "player.s"; int tableerrortype = TYPE_NONE; int tableerrorcause = CAUSE_NONE; @@ -1958,7 +1960,7 @@ unsigned char swapnybbles(unsigned char n) return (lownybble << 4) | highnybble; } -int insertfile(char *name) +int insertfile(const char *name) { int size; int handle = io_open(name); @@ -2181,7 +2183,7 @@ void relocator_stereo(void) char packedsongname[MAX_FILENAME]; char packedfilter[MAX_FILENAME]; unsigned char *packeddata = NULL; - char *playername = "player_s.s"; + const char *playername = "player_s.s"; int tableerrortype = TYPE_NONE; int tableerrorcause = CAUSE_NONE; @@ -2705,7 +2707,7 @@ void relocator_stereo(void) // Allocate memory for song-orderlists songtblsize = songs*6; - songwork = malloc(songdatasize); + songwork = (unsigned char*)std::malloc(songdatasize); if (!songwork) { clearscreen(); @@ -2795,7 +2797,7 @@ void relocator_stereo(void) } patttblsize = patterns*2; - pattwork = malloc(pattdatasize); + pattwork = (unsigned char*)std::malloc(pattdatasize); if (!pattwork) { clearscreen(); @@ -2821,7 +2823,7 @@ void relocator_stereo(void) // Then process instruments instrsize = instruments*9; - instrwork = malloc(instrsize); + instrwork = (unsigned char*)std::malloc(instrsize); if (!instrwork) { clearscreen(); @@ -3453,7 +3455,7 @@ void relocator_stereo(void) // Assemble; on error fail in a rude way (the parser does so too) if (assemble(&src, &dest)) exit(1); - packeddata = membuf_get(&dest); + packeddata = (unsigned char*)membuf_get(&dest); packedsize = membuf_memlen(&dest); playersize = packedsize - songtblsize - songdatasize - patttblsize - pattdatasize - instrsize - wavetblsize - pulsetblsize - filttblsize - speedtblsize; diff --git a/src/greloc.h b/src/greloc.h index 507a0ee..a3649b6 100644 --- a/src/greloc.h +++ b/src/greloc.h @@ -26,6 +26,10 @@ #define MAX_BYTES_PER_ROW 16 +#ifdef __cplusplus +extern "C" { +#endif + #ifndef GRELOC_C extern unsigned char pattused[MAX_PATT]; extern unsigned char instrused[MAX_INSTR]; @@ -45,7 +49,7 @@ void findtableduplicates(int num); int isusedandselfcontained(int num, int start); void calcspeedtest(unsigned char pos); -int insertfile(char *name); +int insertfile(const char *name); void inserttext(const char *text); void insertdefine(const char *name, int value); void insertlabel(const char *name); @@ -54,4 +58,8 @@ void insertbytes(const unsigned char *bytes, int size); void insertaddrlo(const char *name); void insertaddrhi(const char *name); +#ifdef __cplusplus +} +#endif + #endif From 29390340ee3fdbbd88f1dda1798de1db4877a3fe Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 17:11:48 +0200 Subject: [PATCH 27/39] Update --- CMakeLists.txt | 2 +- src/{gcommon.h => common.h} | 0 src/ins2snd2.c | 2 +- src/loadtrk.h | 4 +- src/{greloc.cpp => reloc.cpp} | 279 ++++++++++++++++++---------------- src/{greloc.h => reloc.h} | 28 +++- src/sngspli2.c | 2 +- 7 files changed, 174 insertions(+), 143 deletions(-) rename src/{gcommon.h => common.h} (100%) rename src/{greloc.cpp => reloc.cpp} (94%) rename src/{greloc.h => reloc.h} (64%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 530c099..4fb6cc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ set(LOADTRK_SOURCES src/play.cpp src/display.cpp src/file.cpp - src/greloc.cpp + src/reloc.cpp src/help.cpp src/sound.cpp src/console.cpp diff --git a/src/gcommon.h b/src/common.h similarity index 100% rename from src/gcommon.h rename to src/common.h diff --git a/src/ins2snd2.c b/src/ins2snd2.c index 3bea903..b2a05f3 100644 --- a/src/ins2snd2.c +++ b/src/ins2snd2.c @@ -7,7 +7,7 @@ #include #include #include "bme_end.h" -#include "gcommon.h" +#include "common.h" unsigned char swapnybbles(unsigned char n); void outputbyte(unsigned char c); diff --git a/src/loadtrk.h b/src/loadtrk.h index 4b2ed93..95b2659 100644 --- a/src/loadtrk.h +++ b/src/loadtrk.h @@ -11,14 +11,14 @@ #include #include "bme.h" -#include "gcommon.h" +#include "common.h" #include "console.h" #include "sound.h" #include "sid.h" #include "song.h" #include "play.h" #include "display.h" -#include "greloc.h" +#include "reloc.h" #include "file.h" #include "pattern.h" #include "order.h" diff --git a/src/greloc.cpp b/src/reloc.cpp similarity index 94% rename from src/greloc.cpp rename to src/reloc.cpp index 5ebf950..b33cabe 100644 --- a/src/greloc.cpp +++ b/src/reloc.cpp @@ -1,10 +1,26 @@ /* - * ============================================================================= - * packer/relocator - * ============================================================================= + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define GRELOC_C +// ============================================================================= +// packer/relocator +// ============================================================================= + +#define RELOC_C extern "C" { #include "loadtrk.h" @@ -12,6 +28,8 @@ extern "C" { #include "parse.h" } +#include + const char *playeroptname[] = { "Buffered SID-writes", @@ -95,7 +113,7 @@ int ciaval; struct membuf src = STATIC_MEMBUF_INIT; struct membuf dest = STATIC_MEMBUF_INIT; -void relocator(void) +void relocator() { char packedsongname[MAX_FILENAME]; char packedfilter[MAX_FILENAME]; @@ -137,10 +155,7 @@ void relocator(void) #endif unsigned char speedcode[] = {0xa2,0x00,0x8e,0x04,0xdc,0xa2,0x00,0x8e,0x05,0xdc}; -#ifndef GT2RELOC - size_t i; -#endif - int c,d,e; + int d; unsigned char patttemp[512]; unsigned char *songwork = NULL; @@ -187,12 +202,12 @@ void relocator(void) stopsong(); - memset(pattused, 0, sizeof pattused); - memset(instrused, 0, sizeof instrused); - memset(chnused, 0, sizeof chnused); - memset(chnused_stereo, 0, sizeof chnused_stereo); - memset(tableused, 0, sizeof tableused); - memset(tablemap, 0, sizeof tablemap); + std::memset(pattused, 0, sizeof pattused); + std::memset(instrused, 0, sizeof instrused); + std::memset(chnused, 0, sizeof chnused); + std::memset(chnused_stereo, 0, sizeof chnused_stereo); + std::memset(tableused, 0, sizeof tableused); + std::memset(tablemap, 0, sizeof tablemap); tableerror = 0; membuf_free(&src); @@ -203,25 +218,24 @@ void relocator(void) // Process song-orderlists countpatternlengths(); // Calculate amount of songs with nonzero length - for (c = 0; c < MAX_SONGS; c++) + for (int c = 0; c < MAX_SONGS; c++) { if ((songlen[c][0]) && (songlen[c][1]) && (songlen[c][2])) { // See which patterns are used in this song - for (d = 0; d < maxChns; d++) + for (int d = 0; d < maxChns; d++) { songdatasize += songlen[c][d]+2; - for (e = 0; e < songlen[c][d]; e++) + for (int e = 0; e < songlen[c][d]; e++) { if (songorder[c][d][e] < REPEAT) { - int f; int num = songorder[c][d][e]; pattused[num] = 1; - for (f = 0; f < pattlen[num]; f++) + for (int f = 0; f < pattlen[num]; f++) { if ((pattern[num][f*4] != REST) || (pattern[num][f*4+1]) || (pattern[num][f*4+2])) chnused[d] = 1; @@ -278,7 +292,7 @@ void relocator(void) // Build the pattern-mapping // Instrument 1 is always used instrused[1] = 1; - for (c = 0; c < MAX_PATT; c++) + for (int c = 0; c < MAX_PATT; c++) { if (pattused[c]) { @@ -345,7 +359,7 @@ void relocator(void) // Count amount of normal, nohr, and legato instruments // Also see if special first wave parameters are used - for (c = 0; c < MAX_INSTR; c++) + for (int c = 0; c < MAX_INSTR; c++) { if (instrused[c]) { @@ -364,7 +378,7 @@ void relocator(void) freelegato = freenohr + numnohr; // Build the instrument-mapping - for (c = 0; c < MAX_INSTR; c++) + for (int c = 0; c < MAX_INSTR; c++) { if (instrused[c]) { @@ -392,13 +406,13 @@ void relocator(void) } // Execute tableprograms invoked from wavetable commands - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if (tableused[WTBL][c+1]) { if ((ltable[WTBL][c] >= WAVECMD) && (ltable[WTBL][c] <= WAVELASTCMD)) { - d = -1; + int d = -1; tableerror = 0; switch(ltable[WTBL][c] - WAVECMD) @@ -415,7 +429,7 @@ void relocator(void) d = PTBL; nopulse = 0; break; - + case CMD_SETFILTERPTR: d = FTBL; nofilter = 0; @@ -446,10 +460,10 @@ void relocator(void) } // Build the table-mapping - for (c = 0; c < MAX_TABLES; c++) + for (int c = 0; c < MAX_TABLES; c++) { int e = 1; - for (d = 0; d < MAX_TABLELEN; d++) + for (int d = 0; d < MAX_TABLELEN; d++) { if (tableused[c][d+1]) { @@ -489,18 +503,18 @@ void relocator(void) switch (tableerrorsource2) { case WTBL: - strcat(textbuffer, "WAVE"); + std::strcat(textbuffer, "WAVE"); break; case PTBL: - strcat(textbuffer, "PULSE"); + std::strcat(textbuffer, "PULSE"); break; case FTBL: - strcat(textbuffer, "FILTER"); + std::strcat(textbuffer, "FILTER"); break; } - strcat(textbuffer, ")"); + std::strcat(textbuffer, ")"); break; } printtextc(MAX_ROWS/2, colors.CTITLE, textbuffer); @@ -511,7 +525,7 @@ void relocator(void) } // Find duplicate ranges in tables - for (c = 0; c < MAX_TABLES; c++) + for (int c = 0; c < MAX_TABLES; c++) findtableduplicates(c); // Select playroutine options @@ -540,7 +554,7 @@ void relocator(void) selectdone = 0; while (!selectdone) { - for (c = 0; c < MAX_OPTIONS; c++) + for (int c = 0; c < MAX_OPTIONS; c++) { int color = (opt == c) ? colors.CEDIT : colors.CNORMAL; @@ -665,17 +679,18 @@ void relocator(void) // Generate songorderlists & songtable songdatasize = 0; - for (c = 0; c < songs; c++) + for (int c = 0; c < songs; c++) { if ((songlen[c][0]) && (songlen[c][1]) && (songlen[c][2])) { - for (d = 0; d < maxChns; d++) + for (int d = 0; d < maxChns; d++) { songoffset[c][d] = songdatasize; songsize[c][d] = songlen[c][d] + 2; + int e; for (e = 0; e < songlen[c][d]; e++) { // Pattern @@ -714,7 +729,7 @@ void relocator(void) } else { - for (d = 0; d < maxChns; d++) + for (int d = 0; d < maxChns; d++) { songoffset[c][d] = songdatasize; songsize[c][d] = 0; @@ -723,7 +738,7 @@ void relocator(void) } // Calculate total size of patterns - for (c = 0; c < MAX_PATT; c++) + for (int c = 0; c < MAX_PATT; c++) { if (pattused[c]) { @@ -756,7 +771,7 @@ void relocator(void) // This time pack the patterns for real pattdatasize = 0; d = 0; - for (c = 0; c < MAX_PATT; c++) + for (int c = 0; c < MAX_PATT; c++) { if (pattused[c]) { @@ -779,7 +794,7 @@ void relocator(void) goto PRCLEANUP; } - for (c = 1; c < MAX_INSTR; c++) + for (int c = 1; c < MAX_INSTR; c++) { if (instrused[c]) { @@ -836,7 +851,7 @@ void relocator(void) if (nofilter) instrsize -= instruments; // Process tables - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if (tableused[WTBL][c+1]) { @@ -914,7 +929,7 @@ void relocator(void) } } } - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if (tableused[PTBL][c+1]) { @@ -930,7 +945,7 @@ void relocator(void) } } } - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if (tableused[FTBL][c+1]) { @@ -938,7 +953,7 @@ void relocator(void) if (ltable[FTBL][c] < 0x80) nofiltermod = 0; } } - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if (tableused[STBL][c+1]) speedtblsize += 2; } @@ -1173,18 +1188,17 @@ void relocator(void) waitkeynoupdate(); goto PRCLEANUP; } - + // Modify ghostregs to not be zeropage if needed if ((playerversion & PLAYER_FULLBUFFERED) && (playerversion & PLAYER_ZPGHOSTREGS) == 0) { int bufsize = membuf_get_size(&src); char* bufdata = (char*)membuf_get(&src); - int c; - for (c = 0; c < bufsize; c++) + for (int c = 0; c < bufsize; c++) { if (bufdata[c] == '<') { - if (memcmp(bufdata + c + 1, "ghost", 5) == 0) + if (std::memcmp(bufdata + c + 1, "ghost", 5) == 0) bufdata[c] = ' '; } } @@ -1198,13 +1212,13 @@ void relocator(void) // Insert songtable insertlabel("mt_songtbllo"); - for (c = 0; c < songs*3; c++) + for (int c = 0; c < songs*3; c++) { sprintf(textbuffer, "mt_song%d", c); insertaddrlo(textbuffer); } insertlabel("mt_songtblhi"); - for (c = 0; c < songs*3; c++) + for (int c = 0; c < songs*3; c++) { sprintf(textbuffer, "mt_song%d", c); insertaddrhi(textbuffer); @@ -1212,13 +1226,13 @@ void relocator(void) // Insert patterntable insertlabel("mt_patttbllo"); - for (c = 0; c < patterns; c++) + for (int c = 0; c < patterns; c++) { sprintf(textbuffer, "mt_patt%d", c); insertaddrlo(textbuffer); } insertlabel("mt_patttblhi"); - for (c = 0; c < patterns; c++) + for (int c = 0; c < patterns; c++) { sprintf(textbuffer, "mt_patt%d", c); insertaddrhi(textbuffer); @@ -1257,7 +1271,7 @@ void relocator(void) } // Insert tables - for (c = 0; c < MAX_TABLES; c++) + for (int c = 0; c < MAX_TABLES; c++) { if ((c == PTBL) && (nopulse)) goto SKIPTABLE; if ((c == FTBL) && (nofilter)) goto SKIPTABLE; @@ -1269,7 +1283,7 @@ void relocator(void) insertlabel(tableleftname[c]); // Table data - for (d = 0; d < MAX_TABLELEN; d++) + for (int d = 0; d < MAX_TABLELEN; d++) { if (tableused[c][d+1]) { @@ -1313,7 +1327,7 @@ void relocator(void) // Table label insertlabel(tablerightname[c]); - for (d = 0; d < MAX_TABLELEN; d++) + for (int d = 0; d < MAX_TABLELEN; d++) { if (tableused[c][d+1]) { @@ -1389,9 +1403,9 @@ void relocator(void) } // Insert orderlists - for (c = 0; c < songs; c++) + for (int c = 0; c < songs; c++) { - for (d = 0; d < maxChns; d++) + for (int d = 0; d < maxChns; d++) { sprintf(textbuffer, "mt_song%d", c*3+d); insertlabel(textbuffer); @@ -1400,7 +1414,7 @@ void relocator(void) } // Insert patterns - for (c = 0; c < patterns; c++) + for (int c = 0; c < patterns; c++) { sprintf(textbuffer, "mt_patt%d", c); insertlabel(textbuffer); @@ -1423,7 +1437,7 @@ void relocator(void) // Copy author info if (playerversion & PLAYER_AUTHORINFO) { - for (c = 0; c < 32; c++) + for (int c = 0; c < 32; c++) { packeddata[32+c] = authorname[c]; // Convert 0 to space @@ -1474,17 +1488,17 @@ void relocator(void) { case FORMAT_SID: printtext(1, 14, colors.CEDIT, "SID - SIDPlay music file format "); - strcpy(packedfilter, "*.sid"); + std::strcpy(packedfilter, "*.sid"); break; case FORMAT_PRG: printtext(1, 14, colors.CEDIT, "PRG - C64 native format "); - strcpy(packedfilter, "*.prg"); + std::strcpy(packedfilter, "*.prg"); break; case FORMAT_BIN: printtext(1, 14, colors.CEDIT, "BIN - Raw binary format (no startaddress)"); - strcpy(packedfilter, "*.bin"); + std::strcpy(packedfilter, "*.bin"); break; } @@ -1523,8 +1537,8 @@ void relocator(void) if (selectdone == -1) goto PRCLEANUP; // By default, copy loaded song name up to the extension - memset(packedsongname, 0, sizeof packedsongname); - for (i = 0; i < strlen(loadedsongfilename); i++) + std::memset(packedsongname, 0, sizeof packedsongname); + for (size_t i = 0; i < std::strlen(loadedsongfilename); i++) { if (loadedsongfilename[i] == '.') break; packedsongname[i] = loadedsongfilename[i]; @@ -1532,15 +1546,15 @@ void relocator(void) switch (fileformat) { case FORMAT_PRG: - strcat(packedsongname, ".prg"); + std::strcat(packedsongname, ".prg"); break; case FORMAT_BIN: - strcat(packedsongname, ".bin"); + std::strcat(packedsongname, ".bin"); break; case FORMAT_SID: - strcat(packedsongname, ".sid"); + std::strcat(packedsongname, ".sid"); break; } @@ -1553,7 +1567,7 @@ void relocator(void) if (strlen(packedsongname) < MAX_FILENAME-4) { int extfound = 0; - for (c = strlen(packedsongname)-1; c >= 0; c--) + for (int c = strlen(packedsongname)-1; c >= 0; c--) { if (packedsongname[c] == '.') extfound = 1; } @@ -1562,15 +1576,15 @@ void relocator(void) switch (fileformat) { case FORMAT_PRG: - strcat(packedsongname, ".prg"); + std::strcat(packedsongname, ".prg"); break; case FORMAT_BIN: - strcat(packedsongname, ".bin"); + std::strcat(packedsongname, ".bin"); break; case FORMAT_SID: - strcat(packedsongname, ".sid"); + std::strcat(packedsongname, ".sid"); break; } } @@ -2140,13 +2154,12 @@ int isusedandselfcontained(int num, int start) { int len = gettablepartlen(num, start - 1); int end = start + len - 1; - int c; // Don't use jumps only if (len == 1) return 0; // Check that whole table is used - for (c = start; c <= end; c++) + for (int c = start; c <= end; c++) { if (tableused[num][c] == 0) return 0; } @@ -2156,9 +2169,9 @@ int isusedandselfcontained(int num, int start) if ((rtable[num][end-1] < start) || (rtable[num][end-1] > end)) return 0; } // Check for jump from outside - for (c = 1; c < start; c++) + for (int c = 1; c < start; c++) if ((tableused[num][c]) && (ltable[num][c-1] == 0xff) && (rtable[num][c-1] >= start) && (rtable[num][c-1] <= end)) return 0; - for (c = end+1; c <= MAX_TABLELEN; c++) + for (int c = end+1; c <= MAX_TABLELEN; c++) if ((tableused[num][c]) && (ltable[num][c-1] == 0xff) && (rtable[num][c-1] >= start) && (rtable[num][c-1] <= end)) return 0; // OK! @@ -2178,7 +2191,7 @@ void calcspeedtest(unsigned char pos) } -void relocator_stereo(void) +void relocator_stereo() { char packedsongname[MAX_FILENAME]; char packedfilter[MAX_FILENAME]; @@ -2215,7 +2228,7 @@ void relocator_stereo(void) int selectdone; int opt = 0; unsigned char speedcode[] = {0xa2,0x00,0x8e,0x04,0xdc,0xa2,0x00,0x8e,0x05,0xdc}; - int c,d,e; + int d; unsigned char patttemp[512]; unsigned char *songwork = NULL; unsigned char *pattwork = NULL; @@ -2260,11 +2273,11 @@ void relocator_stereo(void) stopsong(); - memset(pattused, 0, sizeof pattused); - memset(instrused, 0, sizeof instrused); - memset(chnused_stereo, 0, sizeof chnused_stereo); - memset(tableused, 0, sizeof tableused); - memset(tablemap, 0, sizeof tablemap); + std::memset(pattused, 0, sizeof pattused); + std::memset(instrused, 0, sizeof instrused); + std::memset(chnused_stereo, 0, sizeof chnused_stereo); + std::memset(tableused, 0, sizeof tableused); + std::memset(tablemap, 0, sizeof tablemap); tableerror = 0; membuf_free(&src); @@ -2273,25 +2286,24 @@ void relocator_stereo(void) // Process song-orderlists countpatternlengths(); // Calculate amount of songs with nonzero length - for (c = 0; c < MAX_SONGS; c++) + for (int c = 0; c < MAX_SONGS; c++) { if ((songlen_stereo[c][0]) && (songlen_stereo[c][1]) && (songlen_stereo[c][2])) { // See which patterns are used in this song - for (d = 0; d < MAX_CHN; d++) + for (int d = 0; d < MAX_CHN; d++) { songdatasize += songlen_stereo[c][d]+2; - for (e = 0; e < songlen_stereo[c][d]; e++) + for (int e = 0; e < songlen_stereo[c][d]; e++) { if (songorder_stereo[c][d][e] < REPEAT) { - int f; int num = songorder_stereo[c][d][e]; pattused[num] = 1; - for (f = 0; f < pattlen[num]; f++) + for (int f = 0; f < pattlen[num]; f++) { if ((pattern[num][f*4] != REST) || (pattern[num][f*4+1]) || (pattern[num][f*4+2])) chnused_stereo[d] = 1; @@ -2342,7 +2354,7 @@ void relocator_stereo(void) // Build the pattern-mapping // Instrument 1 is always used instrused[1] = 1; - for (c = 0; c < MAX_PATT; c++) + for (int c = 0; c < MAX_PATT; c++) { if (pattused[c]) { @@ -2350,7 +2362,7 @@ void relocator_stereo(void) patterns++; // See which instruments/tablecommands are used - for (d = 0; d < pattlen[c]; d++) + for (int d = 0; d < pattlen[c]; d++) { tableerror = 0; @@ -2409,7 +2421,7 @@ void relocator_stereo(void) // Count amount of normal, nohr, and legato instruments // Also see if special first wave parameters are used - for (c = 0; c < MAX_INSTR; c++) + for (int c = 0; c < MAX_INSTR; c++) { if (instrused[c]) { @@ -2428,7 +2440,7 @@ void relocator_stereo(void) freelegato = freenohr + numnohr; // Build the instrument-mapping - for (c = 0; c < MAX_INSTR; c++) + for (int c = 0; c < MAX_INSTR; c++) { if (instrused[c]) { @@ -2456,13 +2468,13 @@ void relocator_stereo(void) } // Execute tableprograms invoked from wavetable commands - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if (tableused[WTBL][c+1]) { if ((ltable[WTBL][c] >= WAVECMD) && (ltable[WTBL][c] <= WAVELASTCMD)) { - d = -1; + int d = -1; tableerror = 0; switch(ltable[WTBL][c] - WAVECMD) @@ -2510,10 +2522,10 @@ void relocator_stereo(void) } // Build the table-mapping - for (c = 0; c < MAX_TABLES; c++) + for (int c = 0; c < MAX_TABLES; c++) { int e = 1; - for (d = 0; d < MAX_TABLELEN; d++) + for (int d = 0; d < MAX_TABLELEN; d++) { if (tableused[c][d+1]) { @@ -2553,18 +2565,18 @@ void relocator_stereo(void) switch (tableerrorsource2) { case WTBL: - strcat(textbuffer, "WAVE"); + std::strcat(textbuffer, "WAVE"); break; case PTBL: - strcat(textbuffer, "PULSE"); + std::strcat(textbuffer, "PULSE"); break; case FTBL: - strcat(textbuffer, "FILTER"); + std::strcat(textbuffer, "FILTER"); break; } - strcat(textbuffer, ")"); + std::strcat(textbuffer, ")"); break; } printtextc(MAX_ROWS/2, colors.CTITLE, textbuffer); @@ -2575,7 +2587,7 @@ void relocator_stereo(void) } // Find duplicate ranges in tables - for (c = 0; c < MAX_TABLES; c++) + for (int c = 0; c < MAX_TABLES; c++) findtableduplicates(c); // Select playroutine options @@ -2595,7 +2607,7 @@ void relocator_stereo(void) selectdone = 0; while (!selectdone) { - for (c = 0; c < (MAX_OPTIONS-1); c++) + for (int c = 0; c < (MAX_OPTIONS-1); c++) { int color = colors.CNORMAL; if (opt == c) color = colors.CEDIT; @@ -2719,7 +2731,7 @@ void relocator_stereo(void) // Generate songorderlists & songtable songdatasize = 0; - for (c = 0; c < songs; c++) + for (int c = 0; c < songs; c++) { if ((songlen_stereo[c][0]) && (songlen_stereo[c][1]) && @@ -2730,6 +2742,7 @@ void relocator_stereo(void) songoffset_stereo[c][d] = songdatasize; songsize_stereo[c][d] = songlen_stereo[c][d] + 2; + int e; for (e = 0; e < songlen_stereo[c][d]; e++) { // Pattern @@ -2768,7 +2781,7 @@ void relocator_stereo(void) } else { - for (d = 0; d < MAX_CHN; d++) + for (int d = 0; d < MAX_CHN; d++) { songoffset_stereo[c][d] = songdatasize; songsize_stereo[c][d] = 0; @@ -2777,7 +2790,7 @@ void relocator_stereo(void) } // Calculate total size of patterns - for (c = 0; c < MAX_PATT; c++) + for (int c = 0; c < MAX_PATT; c++) { if (pattused[c]) { @@ -2810,7 +2823,7 @@ void relocator_stereo(void) // This time pack the patterns for real pattdatasize = 0; d = 0; - for (c = 0; c < MAX_PATT; c++) + for (int c = 0; c < MAX_PATT; c++) { if (pattused[c]) { @@ -2833,7 +2846,7 @@ void relocator_stereo(void) goto PRCLEANUP_S; } - for (c = 1; c < MAX_INSTR; c++) + for (int c = 1; c < MAX_INSTR; c++) { if (instrused[c]) { @@ -2890,7 +2903,7 @@ void relocator_stereo(void) if (nofilter) instrsize -= instruments; // Process tables - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if (tableused[WTBL][c+1]) { @@ -2968,7 +2981,7 @@ void relocator_stereo(void) } } } - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if (tableused[PTBL][c+1]) { @@ -2984,7 +2997,7 @@ void relocator_stereo(void) } } } - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if (tableused[FTBL][c+1]) { @@ -2992,7 +3005,7 @@ void relocator_stereo(void) if (ltable[FTBL][c] < 0x80) nofiltermod = 0; } } - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if (tableused[STBL][c+1]) speedtblsize += 2; } @@ -3236,13 +3249,13 @@ void relocator_stereo(void) // Insert songtable insertlabel("mt_songtbllo"); - for (c = 0; c < songs*6; c++) + for (int c = 0; c < songs*6; c++) { sprintf(textbuffer, "mt_song%d", c); insertaddrlo(textbuffer); } insertlabel("mt_songtblhi"); - for (c = 0; c < songs*6; c++) + for (int c = 0; c < songs*6; c++) { sprintf(textbuffer, "mt_song%d", c); insertaddrhi(textbuffer); @@ -3250,13 +3263,13 @@ void relocator_stereo(void) // Insert patterntable insertlabel("mt_patttbllo"); - for (c = 0; c < patterns; c++) + for (int c = 0; c < patterns; c++) { sprintf(textbuffer, "mt_patt%d", c); insertaddrlo(textbuffer); } insertlabel("mt_patttblhi"); - for (c = 0; c < patterns; c++) + for (int c = 0; c < patterns; c++) { sprintf(textbuffer, "mt_patt%d", c); insertaddrhi(textbuffer); @@ -3295,7 +3308,7 @@ void relocator_stereo(void) } // Insert tables - for (c = 0; c < MAX_TABLES; c++) + for (int c = 0; c < MAX_TABLES; c++) { if ((c == PTBL) && (nopulse)) goto SKIPTABLE_S; if ((c == FTBL) && (nofilter)) goto SKIPTABLE_S; @@ -3351,7 +3364,7 @@ void relocator_stereo(void) // Table label insertlabel(tablerightname[c]); - for (d = 0; d < MAX_TABLELEN; d++) + for (int d = 0; d < MAX_TABLELEN; d++) { if (tableused[c][d+1]) { @@ -3428,9 +3441,9 @@ void relocator_stereo(void) } // Insert orderlists - for (c = 0; c < songs; c++) + for (int c = 0; c < songs; c++) { - for (d = 0; d < MAX_CHN; d++) + for (int d = 0; d < MAX_CHN; d++) { sprintf(textbuffer, "mt_song%d", c*6+d); insertlabel(textbuffer); @@ -3439,7 +3452,7 @@ void relocator_stereo(void) } // Insert patterns - for (c = 0; c < patterns; c++) + for (int c = 0; c < patterns; c++) { sprintf(textbuffer, "mt_patt%d", c); insertlabel(textbuffer); @@ -3462,7 +3475,7 @@ void relocator_stereo(void) // Copy author info if (playerversion & PLAYER_AUTHORINFO) { - for (c = 0; c < 32; c++) + for (int c = 0; c < 32; c++) { packeddata[32+c] = authorname[c]; // Convert 0 to space @@ -3513,17 +3526,17 @@ void relocator_stereo(void) { case FORMAT_SID: printtext(1, 14, colors.CEDIT, "SID - SIDPlay music file format "); - strcpy(packedfilter, "*.sid"); + std::strcpy(packedfilter, "*.sid"); break; case FORMAT_PRG: printtext(1, 14, colors.CEDIT, "PRG - C64 native format "); - strcpy(packedfilter, "*.prg"); + std::strcpy(packedfilter, "*.prg"); break; case FORMAT_BIN: printtext(1, 14, colors.CEDIT, "BIN - Raw binary format (no startaddress)"); - strcpy(packedfilter, "*.bin"); + std::strcpy(packedfilter, "*.bin"); break; } @@ -3562,8 +3575,8 @@ void relocator_stereo(void) if (selectdone == -1) goto PRCLEANUP_S; // By default, copy loaded song name up to the extension - memset(packedsongname, 0, sizeof packedsongname); - for (c = 0; c < strlen(loadedsongfilename); c++) + std::memset(packedsongname, 0, sizeof packedsongname); + for (size_t c = 0; c < std::strlen(loadedsongfilename); c++) { if (loadedsongfilename[c] == '.') break; packedsongname[c] = loadedsongfilename[c]; @@ -3571,15 +3584,15 @@ void relocator_stereo(void) switch (fileformat) { case FORMAT_PRG: - strcat(packedsongname, ".prg"); + std::strcat(packedsongname, ".prg"); break; case FORMAT_BIN: - strcat(packedsongname, ".bin"); + std::strcat(packedsongname, ".bin"); break; case FORMAT_SID: - strcat(packedsongname, ".sid"); + std::strcat(packedsongname, ".sid"); break; } @@ -3589,10 +3602,10 @@ void relocator_stereo(void) if (!fileselector(packedsongname, packedpath, packedfilter, "Save Music+Playroutine", 3)) goto PRCLEANUP_S; - if (strlen(packedsongname) < MAX_FILENAME-4) + if (std::strlen(packedsongname) < MAX_FILENAME-4) { int extfound = 0; - for (c = strlen(packedsongname)-1; c >= 0; c--) + for (int c = std::strlen(packedsongname)-1; c >= 0; c--) { if (packedsongname[c] == '.') extfound = 1; } @@ -3601,15 +3614,15 @@ void relocator_stereo(void) switch (fileformat) { case FORMAT_PRG: - strcat(packedsongname, ".prg"); + std::strcat(packedsongname, ".prg"); break; case FORMAT_BIN: - strcat(packedsongname, ".bin"); + std::strcat(packedsongname, ".bin"); break; case FORMAT_SID: - strcat(packedsongname, ".sid"); + std::strcat(packedsongname, ".sid"); break; } } diff --git a/src/greloc.h b/src/reloc.h similarity index 64% rename from src/greloc.h rename to src/reloc.h index a3649b6..b9c4d39 100644 --- a/src/greloc.h +++ b/src/reloc.h @@ -1,5 +1,23 @@ -#ifndef GRELOC_H -#define GRELOC_H +/* + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef RELOC_H +#define RELOC_H #define FORMAT_SID 0 #define FORMAT_PRG 1 @@ -30,7 +48,7 @@ extern "C" { #endif -#ifndef GRELOC_C +#ifndef RELOC_C extern unsigned char pattused[MAX_PATT]; extern unsigned char instrused[MAX_INSTR]; extern unsigned char tableused[MAX_TABLES][MAX_TABLELEN+1]; @@ -40,8 +58,8 @@ extern unsigned char tablemap[MAX_TABLES][MAX_TABLELEN+1]; extern int tableerror; #endif -void relocator(void); -void relocator_stereo(void); +void relocator(); +void relocator_stereo(); int testoverlap(int area1start, int area1size, int area2start, int area2size); int packpattern(unsigned char *dest, unsigned char *src, int rows); unsigned char swapnybbles(unsigned char n); diff --git a/src/sngspli2.c b/src/sngspli2.c index 727c248..aa88b43 100644 --- a/src/sngspli2.c +++ b/src/sngspli2.c @@ -7,7 +7,7 @@ #include #include #include "bme_end.h" -#include "gcommon.h" +#include "common.h" #define MAX_SPLITS 16 From 5a2c737203e9e5f2d6ea913a7eb95dd2ad23fd5e Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 17:22:56 +0200 Subject: [PATCH 28/39] Update --- CMakeLists.txt | 2 +- src/{loadtrk.c => loadtrk.cpp} | 176 ++++++++++++++++----------------- src/loadtrk.h | 21 +++- 3 files changed, 104 insertions(+), 95 deletions(-) rename src/{loadtrk.c => loadtrk.cpp} (92%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fb6cc5..3a041d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ endif() set(LOADTRK_SOURCES ${CMAKE_BINARY_DIR}/src/goatdata.c - src/loadtrk.c + src/loadtrk.cpp src/song.cpp src/order.cpp src/pattern.cpp diff --git a/src/loadtrk.c b/src/loadtrk.cpp similarity index 92% rename from src/loadtrk.c rename to src/loadtrk.cpp index c0f6948..a7618fe 100644 --- a/src/loadtrk.c +++ b/src/loadtrk.cpp @@ -23,10 +23,16 @@ #endif #include "loadtrk.h" + +extern "C" { #include "bme.h" +} #include +#include +#include + // Increase if configuration has incompatible changes #define CFG_VERSION 2 @@ -88,7 +94,7 @@ char instrpath[MAX_PATHNAME]; char packedpath[MAX_PATHNAME]; extern char *notename[]; -char *programname = "$VER: LoadTracker v1.99"; +const char *programname = "$VER: LoadTracker v1.99"; char specialnotenames[186]; char scalatuningfilepath[MAX_PATHNAME]; char tuningname[64]; @@ -102,7 +108,7 @@ extern unsigned char datafile[]; COLORS colors; -char* usage[] = { +const char* usage[] = { "Usage: loadtrk [songname] [options]", "Options:", "-Axx Set ADSR parameter for hardrestart in hex. DEFAULT=0F00", @@ -140,7 +146,6 @@ int main(int argc, char **argv) { char filename[MAX_PATHNAME]; FILE *configfile; - int c,d; int dark = 0; @@ -155,18 +160,18 @@ int main(int argc, char **argv) filename[strlen(filename)-2] = 'f'; filename[strlen(filename)-1] = 'g'; #elif __amigaos__ - strcpy(filename, "PROGDIR:loadtrk.cfg"); + std::strcpy(filename, "PROGDIR:loadtrk.cfg"); #else char* xdg_home = getenv("XDG_CONFIG_HOME"); if (xdg_home) { - strcpy(filename, xdg_home); - strcat(filename, "/loadtrk/loadtrk.cfg"); + std::strcpy(filename, xdg_home); + std::strcat(filename, "/loadtrk/loadtrk.cfg"); } else { - strcpy(filename, getenv("HOME")); - strcat(filename, "/.config/loadtrk/loadtrk.cfg"); + std::strcpy(filename, getenv("HOME")); + std::strcat(filename, "/.config/loadtrk/loadtrk.cfg"); } #endif specialnotenames[0] = 0; @@ -217,7 +222,7 @@ int main(int argc, char **argv) initpaths(); // Scan command line - for (c = 1; c < argc; c++) + for (int c = 1; c < argc; c++) { #ifdef __WIN32__ if ((argv[c][0] == '-') || (argv[c][0] == '/')) @@ -225,11 +230,10 @@ int main(int argc, char **argv) if (argv[c][0] == '-') #endif { - int y; switch (argv[c][1]) //switch (toupper(argv[c][1])) { case '-': - if (strcmp(argv[c], "--dark") == 0) + if (std::strcmp(argv[c], "--dark") == 0) { dark = 1; break; @@ -248,45 +252,45 @@ int main(int argc, char **argv) #ifdef __WIN32__ if (!initscreen()) return EXIT_FAILURE; - for (y = 0; y < usagelen; ++y) + for (int y = 0; y < usagelen; ++y) printtext(0,y,15,usage[y]); waitkeynoupdate(); #else - for (y = 0; y < usagelen; ++y) + for (int y = 0; y < usagelen; ++y) printf("%s\n", usage[y]); #endif return EXIT_SUCCESS; case 'Z': - sscanf(&argv[c][2], "%u", &residdelay); + std::sscanf(&argv[c][2], "%u", &residdelay); break; case 'A': - sscanf(&argv[c][2], "%x", &adparam); + std::sscanf(&argv[c][2], "%x", &adparam); break; case 'S': - sscanf(&argv[c][2], "%u", &multiplier); + std::sscanf(&argv[c][2], "%u", &multiplier); break; case 'D': - sscanf(&argv[c][2], "%u", &patterndispmode); + std::sscanf(&argv[c][2], "%u", &patterndispmode); break; case 'E': - sscanf(&argv[c][2], "%u", &sidmodel); + std::sscanf(&argv[c][2], "%u", &sidmodel); break; case 'I': - sscanf(&argv[c][2], "%u", &interpolate); + std::sscanf(&argv[c][2], "%u", &interpolate); break; case 'K': - sscanf(&argv[c][2], "%u", &keypreset); + std::sscanf(&argv[c][2], "%u", &keypreset); break; case 'L': - sscanf(&argv[c][2], "%x", &sidaddress); + std::sscanf(&argv[c][2], "%x", &sidaddress); break; case 'N': @@ -300,23 +304,23 @@ int main(int argc, char **argv) break; case 'F': - sscanf(&argv[c][2], "%u", &customclockrate); + std::sscanf(&argv[c][2], "%u", &customclockrate); break; case 'M': - sscanf(&argv[c][2], "%u", &mr); + std::sscanf(&argv[c][2], "%u", &mr); break; case 'O': - sscanf(&argv[c][2], "%u", &optimizepulse); + std::sscanf(&argv[c][2], "%u", &optimizepulse); break; case 'R': - sscanf(&argv[c][2], "%u", &optimizerealtime); + std::sscanf(&argv[c][2], "%u", &optimizerealtime); break; case 'V': - sscanf(&argv[c][2], "%u", &finevibrato); + std::sscanf(&argv[c][2], "%u", &finevibrato); break; case 'W': @@ -324,35 +328,35 @@ int main(int argc, char **argv) break; case 'X': - sscanf(&argv[c][2], "%d", &win_fullscreen); + std::sscanf(&argv[c][2], "%d", &win_fullscreen); break; case 'G': - sscanf(&argv[c][2], "%f", &basepitch); + std::sscanf(&argv[c][2], "%f", &basepitch); break; case 'b': - sscanf(&argv[c][2], "%f", &filterbias); + std::sscanf(&argv[c][2], "%f", &filterbias); break; case 'c': - sscanf(&argv[c][2], "%u", &combwaves); + std::sscanf(&argv[c][2], "%u", &combwaves); break; case 'Q': - sscanf(&argv[c][2], "%f", &equaldivisionsperoctave); + std::sscanf(&argv[c][2], "%f", &equaldivisionsperoctave); break; case 'J': - sscanf(&argv[c][2], "%s", specialnotenames); + std::sscanf(&argv[c][2], "%s", specialnotenames); break; case 'Y': - sscanf(&argv[c][2], "%s", scalatuningfilepath); + std::sscanf(&argv[c][2], "%s", scalatuningfilepath); break; case 'x': - sscanf(&argv[c][2], "%u", &exsid); + std::sscanf(&argv[c][2], "%u", &exsid); break; } } @@ -360,12 +364,12 @@ int main(int argc, char **argv) { char startpath[MAX_PATHNAME]; - strcpy(songfilename, argv[c]); - for (d = strlen(argv[c])-1; d >= 0; d--) + std::strcpy(songfilename, argv[c]); + for (int d = strlen(argv[c])-1; d >= 0; d--) { if ((argv[c][d] == '/') || (argv[c][d] == '\\')) { - strcpy(startpath, argv[c]); + std::strcpy(startpath, argv[c]); startpath[d+1] = 0; chdir(startpath); initpaths(); @@ -453,25 +457,25 @@ int main(int argc, char **argv) sound_uninit(); // Save configuration - #ifndef __WIN32__ - #ifdef __amigaos__ +#ifndef __WIN32__ +# ifdef __amigaos__ strcpy(filename, "PROGDIR:loadtrk.cfg"); - #else +# else xdg_home = getenv("XDG_CONFIG_HOME"); if (xdg_home) { - strcpy(filename, xdg_home); - strcat(filename, "/loadtrk"); + std::strcpy(filename, xdg_home); + std::strcat(filename, "/loadtrk"); } else { - strcpy(filename, getenv("HOME")); - strcat(filename, "/.config/loadtrk"); + std::strcpy(filename, getenv("HOME")); + std::strcat(filename, "/.config/loadtrk"); } mkdir(filename, S_IRUSR | S_IWUSR | S_IXUSR); - strcat(filename, "/loadtrk.cfg"); - #endif - #endif + std::strcat(filename, "/loadtrk.cfg"); +# endif +#endif configfile = fopen(filename, "wt"); if (configfile) { @@ -668,7 +672,6 @@ void docommand(void) void mousecommands(void) { - int c; int maxChns = MAX_CHN; if (numsids == 1) maxChns = 3; @@ -699,7 +702,7 @@ void mousecommands(void) if (!mouseb) return; // Pattern editpos & pattern number selection - for (c = 0; c < maxChns; c++) + for (int c = 0; c < maxChns; c++) { if ((mousey == dpos.patternsY) && (mousex >= dpos.patternsX + 10 + c*13) && @@ -859,7 +862,7 @@ void mousecommands(void) } // Table editpos - for (c = 0; c < MAX_TABLES; c++) + for (int c = 0; c < MAX_TABLES; c++) { if ((mousey >= dpos.instrumentsY+7) && (mousey <= dpos.instrumentsY+8+VISIBLETABLEROWS) && @@ -917,7 +920,7 @@ void mousecommands(void) { recordmode ^= 1; } - for (c = 0; c < maxChns; c++) + for (int c = 0; c < maxChns; c++) { if ((!prevmouseb) && (mousey >= dpos.channelsY) && @@ -1013,7 +1016,6 @@ void mousecommands(void) void generalcommands(void) { - int c; int maxChns = MAX_CHN; if (numsids == 1) maxChns = 3; int visibleOrderlist = 14; @@ -1070,7 +1072,7 @@ void generalcommands(void) break; case ';': - for (c = 0; c < maxChns; c++) + for (int c = 0; c < maxChns; c++) { if (espos[c]) espos[c]--; if (espos[c] < esview) @@ -1088,7 +1090,7 @@ void generalcommands(void) { visibleOrderlist = VISIBLEORDERLIST; } - for (c = 0; c < maxChns; c++) + for (int c = 0; c < maxChns; c++) { if (numsids == 1) { @@ -1561,7 +1563,7 @@ void editbpm(void) { case KEY_F7: if (!shiftpressed) break; - + // fall through case KEY_ESC: case KEY_ENTER: case KEY_TAB: @@ -1573,6 +1575,7 @@ void editbpm(void) case KEY_BACKSPACE: if (!eacolumn) break; + // fall through case KEY_LEFT: eacolumn--; break; @@ -1594,16 +1597,14 @@ void editbpm(void) void getparam(FILE *handle, unsigned *value) { - char *configptr; - for (;;) { if (feof(handle)) return; - fgets(configbuf, MAX_PATHNAME, handle); + std::fgets(configbuf, MAX_PATHNAME, handle); if ((configbuf[0]) && (configbuf[0] != ';') && (configbuf[0] != ' ') && (configbuf[0] != 13) && (configbuf[0] != 10)) break; } - configptr = configbuf; + char *configptr = configbuf; if (*configptr == '$') { *value = 0; @@ -1646,34 +1647,30 @@ void getparam(FILE *handle, unsigned *value) void getfloatparam(FILE *handle, float *value) { - char *configptr; - for (;;) { if (feof(handle)) return; - fgets(configbuf, MAX_PATHNAME, handle); + std::fgets(configbuf, MAX_PATHNAME, handle); if ((configbuf[0]) && (configbuf[0] != ';') && (configbuf[0] != ' ') && (configbuf[0] != 13) && (configbuf[0] != 10)) break; } - configptr = configbuf; + char *configptr = configbuf; *value = 0.0f; - sscanf(configptr, "%f", value); + std::sscanf(configptr, "%f", value); } void getstringparam(FILE *handle, char *value) { - char *configptr; - for (;;) { if (feof(handle)) return; - fgets(configbuf, MAX_PATHNAME, handle); + std::fgets(configbuf, MAX_PATHNAME, handle); if ((configbuf[0]) && (configbuf[0] != ';') && (configbuf[0] != ' ') && (configbuf[0] != 13) && (configbuf[0] != 10)) break; } - configptr = configbuf; + char *configptr = configbuf; - sscanf(configptr, "%s", value); + std::sscanf(configptr, "%s", value); } void prevmultiplier(void) @@ -1699,15 +1696,13 @@ void calculatefreqtable() double basefreq = (double)basepitch * (16777216.0 / 985248.0) * pow(2.0, 0.25) / 32.0; double cyclebasefreq = basefreq; double freq = basefreq; - int c; - int i; if (tuningcount) { - c = 0; + int c = 0; while (c < 96) { - for (i = 0; i < tuningcount; i++) + for (int i = 0; i < tuningcount; i++) { if (c < 96) { @@ -1725,7 +1720,7 @@ void calculatefreqtable() } else { - for (c = 0; c < 8*12 ; c++) + for (int c = 0; c < 8*12 ; c++) { double note = c; double freq = basefreq * pow(2.0, note/(double)equaldivisionsperoctave); @@ -1740,26 +1735,22 @@ void calculatefreqtable() void setspecialnotenames() { - int i; - int j; - int oct; - char *name; char octave[11]; - - i = 0; - oct = 0; + + int i = 0; + int oct = 0; while (i < 93) { - for (j = 0; j < 186; j += 2) + for (int j = 0; j < 186; j += 2) { if (specialnotenames[j] == '\0') break; if (i < 93) { - name = malloc(4); - strncpy(name, specialnotenames + j, 2); + char *name = (char*)std::malloc(4); + std::strncpy(name, specialnotenames + j, 2); sprintf(octave, "%d", oct); - strcpy(name + 2, octave); + std::strcpy(name + 2, octave); notename[i] = name; i++; } @@ -1774,7 +1765,6 @@ void readscalatuningfile() char *configptr; char strbuf[64]; char name[3]; - int i; double numerator; double denominator; double centvalue; @@ -1790,7 +1780,7 @@ void readscalatuningfile() if ((configbuf[0]) && (configbuf[0] != '!') && (configbuf[0] != 13) && (configbuf[0] != 10)) break; } configptr = configbuf; - sscanf(configptr, "%63[^\t\n]", tuningname); + std::sscanf(configptr, "%63[^\t\n]", tuningname); // Tuning count for (;;) @@ -1800,10 +1790,10 @@ void readscalatuningfile() if ((configbuf[0]) && (configbuf[0] != '!') && (configbuf[0] != 13) && (configbuf[0] != 10)) break; } configptr = configbuf; - sscanf(configptr, "%d", &tuningcount); + std::sscanf(configptr, "%d", &tuningcount); // Tunings - for (i = 0; i < tuningcount; i++) + for (int i = 0; i < tuningcount; i++) { for (;;) { @@ -1813,7 +1803,7 @@ void readscalatuningfile() } configptr = configbuf; name[0] = '\0'; - sscanf(configptr, "%63s %2s", strbuf, name); + std::sscanf(configptr, "%63s %2s", strbuf, name); if (!i) { strcpy(specialnotenames, name); @@ -1834,16 +1824,16 @@ void readscalatuningfile() } if (!strchr(strbuf, '.')) { - sscanf(strbuf, "%lf", &numerator); + std::sscanf(strbuf, "%lf", &numerator); if (strchr(strbuf, '/')) { - sscanf(strchr(strbuf, '/') + 1, "%lf", &denominator); + std::sscanf(strchr(strbuf, '/') + 1, "%lf", &denominator); tuning[i] = numerator / denominator; } } else { - sscanf(configptr, "%lf", ¢value); + std::sscanf(configptr, "%lf", ¢value); tuning[i] = pow(2.0, centvalue / 1200.0); } } diff --git a/src/loadtrk.h b/src/loadtrk.h index 95b2659..dc7951c 100644 --- a/src/loadtrk.h +++ b/src/loadtrk.h @@ -9,8 +9,19 @@ #include #include #include + + +#ifdef __cplusplus +extern "C" { +#endif + #include "bme.h" +#ifdef __cplusplus +} +#endif + + #include "common.h" #include "console.h" #include "sound.h" @@ -42,6 +53,10 @@ #define PGUPDNREPEAT 8 +#ifdef __cplusplus +extern "C" { +#endif + #ifndef LOADTRK_C extern int menu; extern int editmode; @@ -91,7 +106,7 @@ extern char instrfilename[MAX_FILENAME]; extern char instrfilter[MAX_FILENAME]; extern char instrpath[MAX_PATHNAME]; extern char packedpath[MAX_PATHNAME]; -extern char *programname; +extern const char *programname; extern const char *notename[]; extern char textbuffer[MAX_PATHNAME]; extern unsigned char hexkeytbl[16]; @@ -124,4 +139,8 @@ void setspecialnotenames(void); void readscalatuningfile(void); void switchMode(void); +#ifdef __cplusplus +} +#endif + #endif From 0fa9500e6734951bf56f82ff26ae01ae54602213 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 17:36:24 +0200 Subject: [PATCH 29/39] Update --- src/display.cpp | 98 +++++++++++++++++++++++++------------------------ src/file.cpp | 26 +++++++------ src/help.cpp | 4 +- src/loadtrk.cpp | 50 ++++++++++++++----------- src/loadtrk.h | 28 +++++++++----- src/play.cpp | 1 + src/reloc.cpp | 64 ++++++++++++++++---------------- src/song.cpp | 25 +++++++------ src/sound.cpp | 11 +++--- src/table.cpp | 5 ++- 10 files changed, 170 insertions(+), 142 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index 8859210..158e4e1 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -28,6 +28,8 @@ extern "C" { } +#include + const char *notename[] = {"C-0", "C#0", "D-0", "D#0", "E-0", "F-0", "F#0", "G-0", "G#0", "A-0", "A#0", "B-0", "C-1", "C#1", "D-1", "D#1", "E-1", "F-1", "F#1", "G-1", "G#1", "A-1", "A#1", "B-1", @@ -106,9 +108,9 @@ void printstatus(void) printtext(dpos.statusTopX+14, dpos.statusTopY, CDRED|(colors.CHDRBG<<4), "\"\"\" "); if (!strlen(loadedsongfilename)) - sprintf(textbuffer, "%s", programname); + std::sprintf(textbuffer, "%s", programname); else - sprintf(textbuffer, "%s - %s", programname, loadedsongfilename); + std::sprintf(textbuffer, "%s - %s", programname, loadedsongfilename); textbuffer[49] = 0; printtext(dpos.statusTopX+19, dpos.statusTopY, colors.CHEADER, textbuffer); @@ -134,20 +136,20 @@ void printstatus(void) else printtext(dpos.statusTopFvX+14, dpos.statusTopY, colors.CHEADER, "8580"); - sprintf(textbuffer, "HR:%04X", adparam); + std::sprintf(textbuffer, "HR:%04X", adparam); printtext(dpos.statusTopFvX+19, dpos.statusTopY, colors.CHEADER, textbuffer); if (eamode && !ebmode) printbg(dpos.statusTopFvX+22+eacolumn, dpos.statusTopY, cc, 1); if (multiplier) { - sprintf(textbuffer, "%2dX", multiplier); + std::sprintf(textbuffer, "%2dX", multiplier); printtext(dpos.statusTopFvX+27, dpos.statusTopY, colors.CHEADER, textbuffer); } else printtext(dpos.statusTopFvX+27, dpos.statusTopY, colors.CHEADER, "25Hz"); if (multiplier == 1) { - sprintf(textbuffer, "%03dBPM", snd_bpmtempo); + std::sprintf(textbuffer, "%03dBPM", snd_bpmtempo); printtext(dpos.statusTopFvX+31, dpos.statusTopY, colors.CHEADER, textbuffer); if (eamode && ebmode) printbg(dpos.statusTopFvX+31+eacolumn, dpos.statusTopY, cc, 1); @@ -206,13 +208,13 @@ void printstatus(void) for (c = 0; c < maxChns; c++) { - sprintf(textbuffer, "CH."); + std::sprintf(textbuffer, "CH."); printtext(dpos.patternsX+c*13, dpos.patternsY, colors.CTITLE, textbuffer); - sprintf(textbuffer, "%d", c+1); + std::sprintf(textbuffer, "%d", c+1); printtext(dpos.patternsX+3+c*13, dpos.patternsY, colors.CTITLE, textbuffer); - sprintf(textbuffer, "PATT."); + std::sprintf(textbuffer, "PATT."); printtext(dpos.patternsX+5+c*13, dpos.patternsY, colors.CTITLE, textbuffer); - sprintf(textbuffer, "%02X", epnum[c]); + std::sprintf(textbuffer, "%02X", epnum[c]); printtext(dpos.patternsX+10+c*13, dpos.patternsY, colors.CTITLE, textbuffer); for (d = 0; d < VISIBLEPATTROWS; d++) @@ -230,28 +232,28 @@ void printstatus(void) if (p == eppos) color = colors.CEDIT; if ((p < 0) || (p > pattlen[epnum[c]])) { - sprintf(textbuffer, " "); + std::sprintf(textbuffer, " "); } else { if (!(patterndispmode & 1)) { if (p < 100) - sprintf(textbuffer, " %02d", p); + std::sprintf(textbuffer, " %02d", p); else - sprintf(textbuffer, "%03d", p); + std::sprintf(textbuffer, "%03d", p); } else - sprintf(textbuffer, " %02X", p); + std::sprintf(textbuffer, " %02X", p); if (pattern[epnum[c]][p*4] == ENDPATT) { - sprintf(&textbuffer[3], " PATT. END"); + std::sprintf(&textbuffer[3], " PATT. END"); if (color == colors.CNORMAL) color = colors.CCOMMAND; } else { - sprintf(&textbuffer[3], " %s %02X%01X%02X", + std::sprintf(&textbuffer[3], " %s %02X%01X%02X", notename[pattern[epnum[c]][p*4]-FIRSTNOTE], pattern[epnum[c]][p*4+1], pattern[epnum[c]][p*4+2], @@ -311,20 +313,20 @@ void printstatus(void) } } - sprintf(textbuffer, "CHN ORDERLIST (SUBTUNE "); + std::sprintf(textbuffer, "CHN ORDERLIST (SUBTUNE "); printtext(dpos.orderlistX, dpos.orderlistY, colors.CTITLE, textbuffer); - sprintf(textbuffer, "%02X", esnum); + std::sprintf(textbuffer, "%02X", esnum); printtext(dpos.orderlistX+23, dpos.orderlistY, colors.CEDIT, textbuffer); - sprintf(textbuffer, ", POS "); + std::sprintf(textbuffer, ", POS "); printtext(dpos.orderlistX+25, dpos.orderlistY, colors.CTITLE, textbuffer); - sprintf(textbuffer, "%02X", eseditpos); + std::sprintf(textbuffer, "%02X", eseditpos); printtext(dpos.orderlistX+31, dpos.orderlistY, colors.CEDIT, textbuffer); - sprintf(textbuffer, ")"); + std::sprintf(textbuffer, ")"); printtext(dpos.orderlistX+33, dpos.orderlistY, colors.CTITLE, textbuffer); for (c = 0; c < maxChns; c++) { - sprintf(textbuffer, " %d ", c+1); + std::sprintf(textbuffer, " %d ", c+1); printtext(dpos.orderlistX, dpos.orderlistY+1+c, colors.CTITLE, textbuffer); for (d = 0; d < visibleOrderlist; d++) { @@ -354,7 +356,7 @@ void printstatus(void) if ((p < 0) || (p > (currentSonglen+1)) || (p > MAX_SONGLEN+1)) { - sprintf(textbuffer, " "); + std::sprintf(textbuffer, " "); } else { @@ -362,26 +364,26 @@ void printstatus(void) { if ((currentSongorder < REPEAT) || (p >= currentSonglen)) { - sprintf(textbuffer, "%02X ", currentSongorder); + std::sprintf(textbuffer, "%02X ", currentSongorder); if ((p >= currentSonglen) && (color == colors.CNORMAL)) color = colors.CCOMMAND; } else { if (currentSongorder >= TRANSUP) { - sprintf(textbuffer, "+%01X ", currentSongorder&0xf); + std::sprintf(textbuffer, "+%01X ", currentSongorder&0xf); if (color == colors.CNORMAL) color = colors.CCOMMAND; } else { if (currentSongorder >= TRANSDOWN) { - sprintf(textbuffer, "-%01X ", 16-(currentSongorder & 0x0f)); + std::sprintf(textbuffer, "-%01X ", 16-(currentSongorder & 0x0f)); if (color == colors.CNORMAL) color = colors.CCOMMAND; } else { - sprintf(textbuffer, "R%01X ", (currentSongorder+1) & 0x0f); + std::sprintf(textbuffer, "R%01X ", (currentSongorder+1) & 0x0f); if (color == colors.CNORMAL) color = colors.CCOMMAND; } } @@ -389,7 +391,7 @@ void printstatus(void) } if (currentSongorder == LOOPSONG) { - sprintf(textbuffer, "RST"); + std::sprintf(textbuffer, "RST"); if (color == colors.CNORMAL) color = colors.CCOMMAND; } } @@ -425,42 +427,42 @@ void printstatus(void) } } - sprintf(textbuffer, "INSTRUMENT NUM. %02X %-16s", einum, instr[einum].name); + std::sprintf(textbuffer, "INSTRUMENT NUM. %02X %-16s", einum, instr[einum].name); printtext(dpos.instrumentsX, dpos.instrumentsY, colors.CTITLE, textbuffer); - sprintf(textbuffer, "Attack/Decay %02X", instr[einum].ad); + std::sprintf(textbuffer, "Attack/Decay %02X", instr[einum].ad); if (eipos == 0) color = colors.CEDIT; else color = colors.CNORMAL; printtext(dpos.instrumentsX, dpos.instrumentsY+1, color, textbuffer); - sprintf(textbuffer, "Sustain/Release %02X", instr[einum].sr); + std::sprintf(textbuffer, "Sustain/Release %02X", instr[einum].sr); if (eipos == 1) color = colors.CEDIT; else color = colors.CNORMAL; printtext(dpos.instrumentsX, dpos.instrumentsY+2, color, textbuffer); - sprintf(textbuffer, "Wavetable Pos %02X", instr[einum].ptr[WTBL]); + std::sprintf(textbuffer, "Wavetable Pos %02X", instr[einum].ptr[WTBL]); if (eipos == 2) color = colors.CEDIT; else color = colors.CNORMAL; printtext(dpos.instrumentsX, dpos.instrumentsY+3, color, textbuffer); - sprintf(textbuffer, "Pulsetable Pos %02X", instr[einum].ptr[PTBL]); + std::sprintf(textbuffer, "Pulsetable Pos %02X", instr[einum].ptr[PTBL]); if (eipos == 3) color = colors.CEDIT; else color = colors.CNORMAL; printtext(dpos.instrumentsX, dpos.instrumentsY+4, color, textbuffer); - sprintf(textbuffer, "Filtertable Pos %02X", instr[einum].ptr[FTBL]); + std::sprintf(textbuffer, "Filtertable Pos %02X", instr[einum].ptr[FTBL]); if (eipos == 4) color = colors.CEDIT; else color = colors.CNORMAL; printtext(dpos.instrumentsX, dpos.instrumentsY+5, color, textbuffer); - sprintf(textbuffer, "Vibrato Param %02X", instr[einum].ptr[STBL]); + std::sprintf(textbuffer, "Vibrato Param %02X", instr[einum].ptr[STBL]); if (eipos == 5) color = colors.CEDIT; else color = colors.CNORMAL; printtext(dpos.instrumentsX+20, dpos.instrumentsY+1, color, textbuffer); - sprintf(textbuffer, "Vibrato Delay %02X", instr[einum].vibdelay); + std::sprintf(textbuffer, "Vibrato Delay %02X", instr[einum].vibdelay); if (eipos == 6) color = colors.CEDIT; else color = colors.CNORMAL; printtext(dpos.instrumentsX+20, dpos.instrumentsY+2, color, textbuffer); - sprintf(textbuffer, "HR/Gate Timer %02X", instr[einum].gatetimer); + std::sprintf(textbuffer, "HR/Gate Timer %02X", instr[einum].gatetimer); if (eipos == 7) color = colors.CEDIT; else color = colors.CNORMAL; printtext(dpos.instrumentsX+20, dpos.instrumentsY+3, color, textbuffer); - sprintf(textbuffer, "1stFrame Wave %02X", instr[einum].firstwave); + std::sprintf(textbuffer, "1stFrame Wave %02X", instr[einum].firstwave); if (eipos == 8) color = colors.CEDIT; else color = colors.CNORMAL; printtext(dpos.instrumentsX+20, dpos.instrumentsY+4, color, textbuffer); @@ -476,7 +478,7 @@ void printstatus(void) } } - sprintf(textbuffer, "WAVE TBL PULSETBL FILT.TBL SPEEDTBL"); + std::sprintf(textbuffer, "WAVE TBL PULSETBL FILT.TBL SPEEDTBL"); printtext(dpos.instrumentsX, dpos.instrumentsY+7, colors.CTITLE, textbuffer); for (c = 0; c < MAX_TABLES; c++) @@ -501,7 +503,7 @@ void printstatus(void) break; } if ((p == etpos) && (etnum == c)) color = colors.CEDIT; - sprintf(textbuffer, "%02X:%02X %02X", p+1, ltable[c][p], rtable[c][p]); + std::sprintf(textbuffer, "%02X:%02X %02X", p+1, ltable[c][p], rtable[c][p]); if (patterndispmode & 2) { if (!ltable[c][p] && !rtable[c][p] && !ltable[c][p+1] && !rtable[c][p+1]) @@ -534,15 +536,15 @@ void printstatus(void) } printtext(dpos.instrumentsX, dpos.instrumentsY+8+VISIBLETABLEROWS+1, colors.CTITLE, "NAME "); - sprintf(textbuffer, "%-32s", songname); + std::sprintf(textbuffer, "%-32s", songname); printtext(dpos.instrumentsX+9, dpos.instrumentsY+8+VISIBLETABLEROWS+1, colors.CEDIT, textbuffer); printtext(dpos.instrumentsX, dpos.instrumentsY+8+VISIBLETABLEROWS+2, colors.CTITLE, "AUTHOR "); - sprintf(textbuffer, "%-32s", authorname); + std::sprintf(textbuffer, "%-32s", authorname); printtext(dpos.instrumentsX+9, dpos.instrumentsY+8+VISIBLETABLEROWS+2, colors.CEDIT, textbuffer); printtext(dpos.instrumentsX, dpos.instrumentsY+8+VISIBLETABLEROWS+3, colors.CTITLE, "RELEASED "); - sprintf(textbuffer, "%-32s", copyrightname); + std::sprintf(textbuffer, "%-32s", copyrightname); printtext(dpos.instrumentsX+9, dpos.instrumentsY+8+VISIBLETABLEROWS+3, colors.CEDIT, textbuffer); if ((editmode == EDIT_NAMES) && (!eamode)) @@ -560,7 +562,7 @@ void printstatus(void) break; } } - sprintf(textbuffer, "OCTAVE %d", epoctave); + std::sprintf(textbuffer, "OCTAVE %d", epoctave); printtext(dpos.octaveX, dpos.octaveY, colors.CTITLE, textbuffer); switch(autoadvance) @@ -586,16 +588,16 @@ void printstatus(void) if (multiplier) { if (!ntsc) - sprintf(textbuffer, " %02d%c%02d ", timemin, timechar[timeframe/(25*multiplier) & 1], timesec); + std::sprintf(textbuffer, " %02d%c%02d ", timemin, timechar[timeframe/(25*multiplier) & 1], timesec); else - sprintf(textbuffer, " %02d%c%02d ", timemin, timechar[timeframe/(30*multiplier) & 1], timesec); + std::sprintf(textbuffer, " %02d%c%02d ", timemin, timechar[timeframe/(30*multiplier) & 1], timesec); } else { if (!ntsc) - sprintf(textbuffer, " %02d%c%02d ", timemin, timechar[(timeframe/13) & 1], timesec); + std::sprintf(textbuffer, " %02d%c%02d ", timemin, timechar[(timeframe/13) & 1], timesec); else - sprintf(textbuffer, " %02d%c%02d ", timemin, timechar[(timeframe/15) & 1], timesec); + std::sprintf(textbuffer, " %02d%c%02d ", timemin, timechar[(timeframe/15) & 1], timesec); } printtext(dpos.octaveX+10, dpos.octaveY+1, colors.CEDIT, textbuffer); @@ -627,7 +629,7 @@ void printstatus(void) if (chnrow > pattlen[chn[c].pattnum]) chnrow = pattlen[chn[c].pattnum]; if (chnrow >= 100) chnrow -= 100; - sprintf(textbuffer, "%03X/%02X", + std::sprintf(textbuffer, "%03X/%02X", chnpos,chnrow); printtext(dpos.channelsX+7*c, dpos.channelsY+1, chn[c].mute ? colors.CMUTE : colors.CEDIT, textbuffer); } diff --git a/src/file.cpp b/src/file.cpp index c829a90..499ac14 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -30,9 +30,13 @@ extern "C" { #include #include +#include +#include #include #include +#include +#include #ifdef __WIN32__ #include @@ -98,7 +102,7 @@ int fileselector(char *name, char *path, char *filter, const char *title, int fi { if (direntry[c].name) { - free(direntry[c].name); + std::free(direntry[c].name); direntry[c].name = nullptr; } } @@ -156,7 +160,7 @@ int fileselector(char *name, char *path, char *filter, const char *title, int fi files++; else { - free(direntry[files].name); + std::free(direntry[files].name); direntry[files].name = nullptr; } } @@ -226,7 +230,7 @@ int fileselector(char *name, char *path, char *filter, const char *title, int fi { if (direntry[c].name) { - free(direntry[c].name); + std::free(direntry[c].name); direntry[c].name = nullptr; } } @@ -445,21 +449,21 @@ int fileselector(char *name, char *path, char *filter, const char *title, int fi switch (direntry[fileview+c].attribute) { case 0: - sprintf(textbuffer, "%-60s ", direntry[fileview+c].name); + std::sprintf(textbuffer, "%-60s ", direntry[fileview+c].name); break; case 1: - sprintf(textbuffer, "%-60s ", direntry[fileview+c].name); + std::sprintf(textbuffer, "%-60s ", direntry[fileview+c].name); break; case 2: - sprintf(textbuffer, "%-60s ", direntry[fileview+c].name); + std::sprintf(textbuffer, "%-60s ", direntry[fileview+c].name); break; } } else { - sprintf(textbuffer, " "); + std::sprintf(textbuffer, " "); } int color = colors.CNORMAL; if ((fileview+c) == filepos) color = colors.CEDIT; @@ -469,21 +473,21 @@ int fileselector(char *name, char *path, char *filter, const char *title, int fi } printtext(dpos.loadboxX-(MAX_FILENAME+10)/2+1, dpos.loadboxY+3+VISIBLEFILES, 15, "PATH: "); - sprintf(textbuffer, "%-60s", path); + std::sprintf(textbuffer, "%-60s", path); textbuffer[MAX_FILENAME] = 0; int color = (filemode == 1) ? colors.CEDIT : colors.CNORMAL; printtext(dpos.loadboxX-(MAX_FILENAME+10)/2+9, dpos.loadboxY+3+VISIBLEFILES, color, textbuffer); if ((filemode == 1) && (strlen(path) < MAX_FILENAME)) printbg(dpos.loadboxX-(MAX_FILENAME+10)/2+9+strlen(path), dpos.loadboxY+3+VISIBLEFILES, cc, 1); printtext(dpos.loadboxX-(MAX_FILENAME+10)/2+1, dpos.loadboxY+4+VISIBLEFILES, 15, "FILTER: "); - sprintf(textbuffer, "%-60s", filter); + std::sprintf(textbuffer, "%-60s", filter); textbuffer[MAX_FILENAME] = 0; color = (filemode == 2) ? colors.CEDIT : colors.CNORMAL; printtext(dpos.loadboxX-(MAX_FILENAME+10)/2+9, dpos.loadboxY+4+VISIBLEFILES, color, textbuffer); if (filemode == 2) printbg(dpos.loadboxX-(MAX_FILENAME+10)/2+9+strlen(filter), dpos.loadboxY+4+VISIBLEFILES, cc, 1); printtext(dpos.loadboxX-(MAX_FILENAME+10)/2+1, dpos.loadboxY+5+VISIBLEFILES, 15, "NAME: "); - sprintf(textbuffer, "%-60s", name); + std::sprintf(textbuffer, "%-60s", name); textbuffer[MAX_FILENAME] = 0; color = (filemode == 3) ? colors.CEDIT : colors.CNORMAL; printtext(dpos.loadboxX-(MAX_FILENAME+10)/2+9, dpos.loadboxY+5+VISIBLEFILES, color, textbuffer); @@ -503,7 +507,7 @@ int fileselector(char *name, char *path, char *filter, const char *title, int fi { if (direntry[c].name) { - free(direntry[c].name); + std::free(direntry[c].name); direntry[c].name = nullptr; } } diff --git a/src/help.cpp b/src/help.cpp index 76ca9de..eb893e5 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -28,6 +28,8 @@ extern "C" { } +#include + #define HELP_HEADER 15 #define HELP_NORMAL 7 @@ -361,7 +363,7 @@ void onlinehelp(int standalone,int context) printblank(0, 0, MAX_COLUMNS); printbg(0, 0, colors.CHDRBG, MAX_COLUMNS); - sprintf(textbuffer, "%s Online Help", programname); + std::sprintf(textbuffer, "%s Online Help", programname); printtext(1, 0, colors.CHEADER, textbuffer); if(standalone) { printtext(84, 0, colors.CHEADER, "Arrows/PgUp/PgDn/Home/End scroll, ESC exits"); diff --git a/src/loadtrk.cpp b/src/loadtrk.cpp index a7618fe..0395b51 100644 --- a/src/loadtrk.cpp +++ b/src/loadtrk.cpp @@ -1,20 +1,20 @@ -// -// LoadTracker -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// +/* + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ #define LOADTRK_C @@ -32,6 +32,12 @@ extern "C" { #include #include +#include +#include +#include + +#include +#include // Increase if configuration has incompatible changes #define CFG_VERSION 2 @@ -615,7 +621,7 @@ void converthex() hexnybble = -1; for (c = 0; c < 16; c++) { - if (tolower(key) == hexkeytbl[c]) + if (std::tolower(key) == hexkeytbl[c]) { if (c >= 10) { @@ -1611,7 +1617,7 @@ void getparam(FILE *handle, unsigned *value) configptr++; for (;;) { - char c = tolower(*configptr++); + char c = std::tolower(*configptr++); int h = -1; if ((c >= 'a') && (c <= 'f')) h = c - 'a' + 10; @@ -1630,7 +1636,7 @@ void getparam(FILE *handle, unsigned *value) *value = 0; for (;;) { - char c = tolower(*configptr++); + char c = std::tolower(*configptr++); int d = -1; if ((c >= '0') && (c <= '9')) d = c - '0'; @@ -1693,7 +1699,7 @@ void nextmultiplier(void) void calculatefreqtable() { - double basefreq = (double)basepitch * (16777216.0 / 985248.0) * pow(2.0, 0.25) / 32.0; + double basefreq = (double)basepitch * (16777216.0 / 985248.0) * std::pow(2.0, 0.25) / 32.0; double cyclebasefreq = basefreq; double freq = basefreq; @@ -1834,7 +1840,7 @@ void readscalatuningfile() else { std::sscanf(configptr, "%lf", ¢value); - tuning[i] = pow(2.0, centvalue / 1200.0); + tuning[i] = std::pow(2.0, centvalue / 1200.0); } } fclose(scalatuningfile); diff --git a/src/loadtrk.h b/src/loadtrk.h index dc7951c..5253537 100644 --- a/src/loadtrk.h +++ b/src/loadtrk.h @@ -1,16 +1,24 @@ +/* + * LoadTracker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + #ifndef LOADTRK_H #define LOADTRK_H -#include -#include -#include -#include -#include -#include -#include -#include - - #ifdef __cplusplus extern "C" { #endif diff --git a/src/play.cpp b/src/play.cpp index 71dcb97..75fc3d1 100644 --- a/src/play.cpp +++ b/src/play.cpp @@ -1798,6 +1798,7 @@ void playroutine_stereo(void) cptr->vibdelay--; break; } + // fall through case CMD_VIBRATO: { unsigned short speed = 0; diff --git a/src/reloc.cpp b/src/reloc.cpp index b33cabe..a577e4f 100644 --- a/src/reloc.cpp +++ b/src/reloc.cpp @@ -29,6 +29,8 @@ extern "C" { } #include +#include +#include const char *playeroptname[] = { @@ -667,7 +669,7 @@ void relocator() // Allocate memory for song-orderlists songtblsize = songs*6; - songwork = (unsigned char*)malloc(songdatasize); + songwork = (unsigned char*)std::malloc(songdatasize); if (!songwork) { clearscreen(); @@ -758,7 +760,7 @@ void relocator() } patttblsize = patterns*2; - pattwork = (unsigned char*)malloc(pattdatasize); + pattwork = (unsigned char*)std::malloc(pattdatasize); if (!pattwork) { clearscreen(); @@ -784,7 +786,7 @@ void relocator() // Then process instruments instrsize = instruments*9; - instrwork = (unsigned char*)malloc(instrsize); + instrwork = (unsigned char*)std::malloc(instrsize); if (!instrwork) { clearscreen(); @@ -1422,9 +1424,9 @@ void relocator() } /* { - FILE *handle = fopen("debug.s", "wb"); - fwrite(membuf_get(&src), membuf_memlen(&src), 1, handle); - fclose(handle); + FILE *handle = std::fopen("debug.s", "wb"); + std::fwrite(membuf_get(&src), membuf_memlen(&src), 1, handle); + std::fclose(handle); } */ // Assemble; on error fail in a rude way (the parser does so too) @@ -1589,7 +1591,7 @@ void relocator() } } } - songhandle = fopen(packedsongname, "wb"); + songhandle = std::fopen(packedsongname, "wb"); } if (fileformat == FORMAT_PRG) @@ -1601,7 +1603,7 @@ void relocator() unsigned char ident[] = {'P', 'S', 'I', 'D', 0x00, 0x02, 0x00, 0x7c}; unsigned char byte; // Identification - fwrite(ident, sizeof ident, 1, songhandle); + std::fwrite(ident, sizeof ident, 1, songhandle); // Load address byte = 0x00; @@ -1665,9 +1667,9 @@ void relocator() fwrite8(songhandle, byte); // Songname etc. - fwrite(songname, sizeof songname, 1, songhandle); - fwrite(authorname, sizeof authorname, 1, songhandle); - fwrite(copyrightname, sizeof copyrightname, 1, songhandle); + std::fwrite(songname, sizeof songname, 1, songhandle); + std::fwrite(authorname, sizeof authorname, 1, songhandle); + std::fwrite(copyrightname, sizeof copyrightname, 1, songhandle); // Flags byte = 0x00; @@ -1700,19 +1702,19 @@ void relocator() byte = (playeradr) >> 8; fwrite8(songhandle, byte); } - if ((multiplier > 1) || (!multiplier)) fwrite(speedcode, 10, 1, songhandle); + if ((multiplier > 1) || (!multiplier)) std::fwrite(speedcode, 10, 1, songhandle); } - fwrite(packeddata, packedsize, 1, songhandle); - fclose(songhandle); + std::fwrite(packeddata, packedsize, 1, songhandle); + std::fclose(songhandle); PRCLEANUP: membuf_free(&src); membuf_free(&dest); - if (pattwork) free(pattwork); - if (songwork) free(songwork); - if (instrwork) free(instrwork); + if (pattwork) std::free(pattwork); + if (songwork) std::free(songwork); + if (instrwork) std::free(instrwork); printmainscreen(); key = 0; rawkey = 0; @@ -3460,9 +3462,9 @@ void relocator_stereo() } //{ - // FILE *handle = fopen("debug.s", "wb"); - // fwrite(membuf_get(&src), membuf_memlen(&src), 1, handle); - // fclose(handle); + // FILE *handle = std::fopen("debug.s", "wb"); + // std::fwrite(membuf_get(&src), membuf_memlen(&src), 1, handle); + // std::fclose(handle); //} // Assemble; on error fail in a rude way (the parser does so too) @@ -3627,7 +3629,7 @@ void relocator_stereo() } } } - songhandle = fopen(packedsongname, "wb"); + songhandle = std::fopen(packedsongname, "wb"); } if (fileformat == FORMAT_PRG) @@ -3639,7 +3641,7 @@ void relocator_stereo() unsigned char ident[] = {'P', 'S', 'I', 'D', 0x00, 0x03, 0x00, 0x7c}; unsigned char byte; // Identification - fwrite(ident, sizeof ident, 1, songhandle); + std::fwrite(ident, sizeof ident, 1, songhandle); // Load address byte = 0x00; @@ -3703,9 +3705,9 @@ void relocator_stereo() fwrite8(songhandle, byte); // Songname etc. - fwrite(songname, sizeof songname, 1, songhandle); - fwrite(authorname, sizeof authorname, 1, songhandle); - fwrite(copyrightname, sizeof copyrightname, 1, songhandle); + std::fwrite(songname, sizeof songname, 1, songhandle); + std::fwrite(authorname, sizeof authorname, 1, songhandle); + std::fwrite(copyrightname, sizeof copyrightname, 1, songhandle); // Flags byte = 0x00; @@ -3739,19 +3741,19 @@ void relocator_stereo() byte = (playeradr) >> 8; fwrite8(songhandle, byte); } - if ((multiplier > 1) || (!multiplier)) fwrite(speedcode, 10, 1, songhandle); + if ((multiplier > 1) || (!multiplier)) std::fwrite(speedcode, 10, 1, songhandle); } - fwrite(packeddata, packedsize, 1, songhandle); - fclose(songhandle); + std::fwrite(packeddata, packedsize, 1, songhandle); + std::fclose(songhandle); PRCLEANUP_S: membuf_free(&src); membuf_free(&dest); - if (pattwork) free(pattwork); - if (songwork) free(songwork); - if (instrwork) free(instrwork); + if (pattwork) std::free(pattwork); + if (songwork) std::free(songwork); + if (instrwork) std::free(instrwork); printmainscreen(); key = 0; rawkey = 0; diff --git a/src/song.cpp b/src/song.cpp index c1a4fd5..2c638cc 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -27,6 +27,7 @@ extern "C" { } #include +#include INSTR instr[MAX_INSTR]; unsigned char ltable[MAX_TABLES][MAX_TABLELEN]; @@ -53,7 +54,7 @@ int savesong(void) int maxChns = MAX_CHN; if (numsids == 1) maxChns = 3; - if (strlen(songfilename) < MAX_FILENAME-4) + if (std::strlen(songfilename) < MAX_FILENAME-4) { int extfound = 0; for (int c = strlen(songfilename)-1; c >= 0; c--) @@ -62,13 +63,13 @@ int savesong(void) } if (!extfound) strcat(songfilename, ".sng"); } - handle = fopen(songfilename, "wb"); + handle = std::fopen(songfilename, "wb"); if (handle) { int length; int amount; int writebytes; - fwrite(ident, 4, 1, handle); + std::fwrite(ident, 4, 1, handle); // Determine amount of patterns & instruments countpatternlengths(); @@ -82,9 +83,9 @@ int savesong(void) } // Write infotexts - fwrite(songname, sizeof songname, 1, handle); - fwrite(authorname, sizeof authorname, 1, handle); - fwrite(copyrightname, sizeof copyrightname, 1, handle); + std::fwrite(songname, sizeof songname, 1, handle); + std::fwrite(authorname, sizeof authorname, 1, handle); + std::fwrite(copyrightname, sizeof copyrightname, 1, handle); // Determine amount of songs to be saved int c = MAX_SONGS - 1; @@ -124,7 +125,7 @@ int savesong(void) fwrite8(handle, length); writebytes = length; writebytes++; - fwrite(songorder[d][c], writebytes, 1, handle); + std::fwrite(songorder[d][c], writebytes, 1, handle); } else if (numsids == 2) { @@ -132,7 +133,7 @@ int savesong(void) fwrite8(handle, length); writebytes = length; writebytes++; - fwrite(songorder_stereo[d][c], writebytes, 1, handle); + std::fwrite(songorder_stereo[d][c], writebytes, 1, handle); } } } @@ -157,8 +158,8 @@ int savesong(void) { writebytes = gettablelen(c); fwrite8(handle, writebytes); - fwrite(ltable[c], writebytes, 1, handle); - fwrite(rtable[c], writebytes, 1, handle); + std::fwrite(ltable[c], writebytes, 1, handle); + std::fwrite(rtable[c], writebytes, 1, handle); } // Write patterns amount = highestusedpattern + 1; @@ -169,8 +170,8 @@ int savesong(void) fwrite8(handle, length); fwrite(pattern[c], length * 4, 1, handle); } - fclose(handle); - strcpy(loadedsongfilename, songfilename); + std::fclose(handle); + std::strcpy(loadedsongfilename, songfilename); return 1; } return 0; diff --git a/src/sound.cpp b/src/sound.cpp index 03cc1a9..6664409 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -35,6 +35,7 @@ extern "C" { #endif #include +#include // General / reSID output int playspeed; @@ -133,7 +134,7 @@ int sound_init(unsigned mr, unsigned writer, unsigned m, unsigned ntsc, if ((!buffer) || (!lbuffer) || (!rbuffer)) return 0; if (writer) - writehandle = fopen("sidaudio.raw", "wb"); + writehandle = std::fopen("sidaudio.raw", "wb"); playspeed = mr; if (playspeed < MINMIXRATE) playspeed = MINMIXRATE; @@ -181,7 +182,7 @@ void sound_uninit(void) if (writehandle) { - fclose(writehandle); + std::fclose(writehandle); writehandle = nullptr; } @@ -265,7 +266,7 @@ void sound_mixer(Sint32 *dest, unsigned samples) sid_fillbuffer(buffer, samples); if (writehandle) { - fwrite(buffer, samples * sizeof(Uint16), 1, writehandle); + std::fwrite(buffer, samples * sizeof(Uint16), 1, writehandle); } for (unsigned c = 0; c < samples; c++) @@ -280,8 +281,8 @@ void sound_mixer(Sint32 *dest, unsigned samples) { for (unsigned c = 0; c < samples; c++) { - fwrite(&lbuffer[c], sizeof(Sint16), 1, writehandle); - fwrite(&rbuffer[c], sizeof(Sint16), 1, writehandle); + std::fwrite(&lbuffer[c], sizeof(Sint16), 1, writehandle); + std::fwrite(&rbuffer[c], sizeof(Sint16), 1, writehandle); } } if (monomode) diff --git a/src/table.cpp b/src/table.cpp index b010380..f293931 100644 --- a/src/table.cpp +++ b/src/table.cpp @@ -26,6 +26,7 @@ extern "C" { #include "loadtrk.h" } +#include #include unsigned char ltablecopybuffer[MAX_TABLELEN]; @@ -295,7 +296,7 @@ void tablecommands(void) } } - time = abs(targetpulse - currentpulse) / speed; + time = std::abs(targetpulse - currentpulse) / speed; if (speed < 128) steps = (time + 126) / 127; else @@ -361,7 +362,7 @@ void tablecommands(void) } } - time = abs(targetfilter - currentfilter) / speed; + time = std::abs(targetfilter - currentfilter) / speed; steps = (time + 126) / 127; if (!steps) break; if (etpos + steps > MAX_TABLELEN) break; From b44737b2c535f36af419afba0f62e48bbe0a1570 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 18:31:22 +0200 Subject: [PATCH 30/39] Update --- src/bme/bme.h | 8 ++++++++ src/bme/bme_gfx.c | 20 ++++++++++---------- src/bme/bme_gfx.h | 9 +++++++-- src/bme/bme_main.h | 2 ++ src/console.cpp | 4 ---- src/display.cpp | 4 ---- src/file.cpp | 4 ---- src/help.cpp | 4 ---- src/instr.cpp | 4 ---- src/loadtrk.cpp | 4 +--- src/loadtrk.h | 10 ---------- src/order.cpp | 4 ---- src/pattern.cpp | 2 -- src/play.cpp | 2 -- src/reloc.cpp | 3 ++- src/song.cpp | 2 -- src/sound.cpp | 2 -- src/table.cpp | 2 -- 18 files changed, 30 insertions(+), 60 deletions(-) diff --git a/src/bme/bme.h b/src/bme/bme.h index e479815..9c0ef0b 100644 --- a/src/bme/bme.h +++ b/src/bme/bme.h @@ -3,6 +3,10 @@ #ifndef BME_H #define BME_H +#ifdef __cplusplus +extern "C" { +#endif + #include #include "bme_main.h" #include "bme_cfg.h" @@ -14,4 +18,8 @@ #include "bme_io.h" #include "bme_end.h" +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/bme/bme_gfx.c b/src/bme/bme_gfx.c index 9bce18f..17ab4de 100644 --- a/src/bme/bme_gfx.c +++ b/src/bme/bme_gfx.c @@ -16,9 +16,9 @@ // Prototypes int gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags); -int gfx_reinit(void); +int gfx_reinit(); void gfx_uninit(void); -int gfx_lock(void); +int gfx_lock(); void gfx_unlock(void); void gfx_flip(void); void gfx_setclipregion(unsigned left, unsigned top, unsigned right, unsigned bottom); @@ -150,7 +150,7 @@ int gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags) else return BME_ERROR; } -int gfx_reinit(void) +int gfx_reinit() { gfx_uninit(); return gfx_init(gfx_last_xsize, gfx_last_ysize, gfx_last_framerate, @@ -166,7 +166,7 @@ void gfx_uninit(void) return; } -int gfx_lock(void) +int gfx_lock() { if (gfx_locked) return 1; if (!gfx_initted) return 0; @@ -294,9 +294,9 @@ void gfx_setmaxspritefiles(unsigned num) { if (gfx_spriteheaders) return; - gfx_spriteheaders = malloc(num * sizeof(Uint8 *)); - gfx_spritedata = malloc(num * sizeof(Uint8 *)); - gfx_spriteamount = malloc(num * sizeof(unsigned)); + gfx_spriteheaders = (SPRITEHEADER**)malloc(num * sizeof(Uint8 *)); + gfx_spritedata = (Uint8**)malloc(num * sizeof(Uint8 *)); + gfx_spriteamount = (unsigned int*)malloc(num * sizeof(unsigned)); if ((gfx_spriteheaders) && (gfx_spritedata) && (gfx_spriteamount)) { unsigned c; @@ -336,11 +336,11 @@ int gfx_loadsprites(unsigned num, const char *name) gfx_spriteamount[num] = io_readle32(handle); - gfx_spriteheaders[num] = malloc(gfx_spriteamount[num] * sizeof(SPRITEHEADER)); + gfx_spriteheaders[num] = (SPRITEHEADER*)malloc(gfx_spriteamount[num] * sizeof(SPRITEHEADER)); if (!gfx_spriteheaders[num]) { - bme_error = BME_OUT_OF_MEMORY; + bme_error = BME_OUT_OF_MEMORY; io_close(handle); return BME_ERROR; } @@ -357,7 +357,7 @@ int gfx_loadsprites(unsigned num, const char *name) } datastart = io_lseek(handle, 0, SEEK_CUR); - gfx_spritedata[num] = malloc(size - datastart); + gfx_spritedata[num] = (Uint8*)malloc(size - datastart); if (!gfx_spritedata[num]) { bme_error = BME_OUT_OF_MEMORY; diff --git a/src/bme/bme_gfx.h b/src/bme/bme_gfx.h index 1302e89..b1814e0 100644 --- a/src/bme/bme_gfx.h +++ b/src/bme/bme_gfx.h @@ -1,9 +1,12 @@ // BME graphics module header file +#ifndef BME_GFX_H +#define BME_GFX_H + int gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags); -int gfx_reinit(void); +int gfx_reinit(); void gfx_uninit(void); -int gfx_lock(void); +int gfx_lock(); void gfx_unlock(void); void gfx_flip(void); void gfx_setclipregion(unsigned left, unsigned top, unsigned right, unsigned bottom); @@ -39,3 +42,5 @@ extern Uint8 *gfx_blocks; extern Uint8 gfx_palette[]; extern SDL_Surface *gfx_screen; extern SDL_Renderer *gfx_renderer; + +#endif diff --git a/src/bme/bme_main.h b/src/bme/bme_main.h index ea440df..7fedd41 100644 --- a/src/bme/bme_main.h +++ b/src/bme/bme_main.h @@ -1,5 +1,7 @@ // BME main definitions header file +#include + #define GFX_SCANLINES 1 #define GFX_DOUBLESIZE 2 #define GFX_USE1PAGE 0 diff --git a/src/console.cpp b/src/console.cpp index aa62042..4267a9f 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -22,12 +22,8 @@ #define CONSOLE_C -extern "C" { - #include "loadtrk.h" -} - #include #include #include diff --git a/src/display.cpp b/src/display.cpp index 158e4e1..1874e62 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -22,12 +22,8 @@ #define DISPLAY_C -extern "C" { - #include "loadtrk.h" -} - #include const char *notename[] = diff --git a/src/file.cpp b/src/file.cpp index 499ac14..81c535c 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -22,12 +22,8 @@ #define FILE_C -extern "C" { - #include "loadtrk.h" -} - #include #include #include diff --git a/src/help.cpp b/src/help.cpp index eb893e5..b0bf9cc 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -22,12 +22,8 @@ #define HELP_C -extern "C" { - #include "loadtrk.h" -} - #include #define HELP_HEADER 15 diff --git a/src/instr.cpp b/src/instr.cpp index 17903e4..3ca7c43 100644 --- a/src/instr.cpp +++ b/src/instr.cpp @@ -22,12 +22,8 @@ #define INSTR_C -extern "C" { - #include "loadtrk.h" -} - #include INSTR instrcopybuffer; diff --git a/src/loadtrk.cpp b/src/loadtrk.cpp index 0395b51..9fc7c79 100644 --- a/src/loadtrk.cpp +++ b/src/loadtrk.cpp @@ -24,9 +24,7 @@ #include "loadtrk.h" -extern "C" { #include "bme.h" -} #include @@ -606,7 +604,7 @@ void waitkeynoupdate(void) { for (;;) { - fliptoscreen(); + fliptoscreen(); getkey(); if ((rawkey) || (key)) break; if ((mouseb) && (!prevmouseb)) break; diff --git a/src/loadtrk.h b/src/loadtrk.h index 5253537..08b24ef 100644 --- a/src/loadtrk.h +++ b/src/loadtrk.h @@ -19,17 +19,7 @@ #ifndef LOADTRK_H #define LOADTRK_H -#ifdef __cplusplus -extern "C" { -#endif - #include "bme.h" - -#ifdef __cplusplus -} -#endif - - #include "common.h" #include "console.h" #include "sound.h" diff --git a/src/order.cpp b/src/order.cpp index 1b5f69e..bbb2057 100644 --- a/src/order.cpp +++ b/src/order.cpp @@ -22,12 +22,8 @@ #define ORDER_C -extern "C" { - #include "loadtrk.h" -} - #include unsigned char trackcopybuffer[MAX_SONGLEN+2]; diff --git a/src/pattern.cpp b/src/pattern.cpp index 6abd4c4..70aba75 100644 --- a/src/pattern.cpp +++ b/src/pattern.cpp @@ -22,9 +22,7 @@ #define PATTERN_C -extern "C" { #include "loadtrk.h" -} #include diff --git a/src/play.cpp b/src/play.cpp index 75fc3d1..cadecbb 100644 --- a/src/play.cpp +++ b/src/play.cpp @@ -22,9 +22,7 @@ #define PLAY_C -extern "C" { #include "loadtrk.h" -} #include diff --git a/src/reloc.cpp b/src/reloc.cpp index a577e4f..485251f 100644 --- a/src/reloc.cpp +++ b/src/reloc.cpp @@ -22,8 +22,9 @@ #define RELOC_C -extern "C" { #include "loadtrk.h" + +extern "C" { #include "membuf.h" #include "parse.h" } diff --git a/src/song.cpp b/src/song.cpp index 2c638cc..97b7797 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -22,9 +22,7 @@ #define SONG_C -extern "C" { #include "loadtrk.h" -} #include #include diff --git a/src/sound.cpp b/src/sound.cpp index 6664409..87dcb67 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -22,9 +22,7 @@ #define SOUND_C -extern "C" { #include "loadtrk.h" -} #ifdef __WIN32__ #include diff --git a/src/table.cpp b/src/table.cpp index f293931..831e13d 100644 --- a/src/table.cpp +++ b/src/table.cpp @@ -22,9 +22,7 @@ #define TABLE_C -extern "C" { #include "loadtrk.h" -} #include #include From f21e525490b6f0958b092c0f7737ececae9ab968 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 18:44:59 +0200 Subject: [PATCH 31/39] Cleanup unused stuff --- src/bme/bme.c | 1 - src/bme/bme.h | 1 - src/bme/bme_cfg.h | 11 ----------- src/bme/bme_gfx.c | 7 ++++--- src/bme/bme_gfx.h | 2 +- src/bme/bme_io.c | 3 ++- src/bme/bme_mou.c | 1 - src/bme/bme_snd.c | 1 - src/bme/bme_win.c | 26 -------------------------- src/bme/bme_win.h | 4 ---- 10 files changed, 7 insertions(+), 50 deletions(-) delete mode 100644 src/bme/bme_cfg.h diff --git a/src/bme/bme.c b/src/bme/bme.c index 2338bbe..14bcad5 100644 --- a/src/bme/bme.c +++ b/src/bme/bme.c @@ -3,6 +3,5 @@ // #include "bme_err.h" -#include "bme_cfg.h" int bme_error = BME_OK; diff --git a/src/bme/bme.h b/src/bme/bme.h index 9c0ef0b..89b6878 100644 --- a/src/bme/bme.h +++ b/src/bme/bme.h @@ -9,7 +9,6 @@ extern "C" { #include #include "bme_main.h" -#include "bme_cfg.h" #include "bme_err.h" #include "bme_snd.h" #include "bme_gfx.h" diff --git a/src/bme/bme_cfg.h b/src/bme/bme_cfg.h deleted file mode 100644 index d6e03ba..0000000 --- a/src/bme/bme_cfg.h +++ /dev/null @@ -1,11 +0,0 @@ -// BME configuration (some static things) - -#define MAX_JOYSTICKS 16 // Maximum joysticks -#define MAX_HANDLES 16 // Up to 16 simultaneous files open from the - // datafile - -#define MAX_COLORS 256 // 8bit oldskool mode - -#define DEFAULT_MAX_SPRFILES 256 // Default maximum of 256 spritefiles, though - // this can be set during running of program - diff --git a/src/bme/bme_gfx.c b/src/bme/bme_gfx.c index 17ab4de..555c596 100644 --- a/src/bme/bme_gfx.c +++ b/src/bme/bme_gfx.c @@ -8,11 +8,12 @@ #include #include "bme_main.h" -#include "bme_cfg.h" #include "bme_win.h" #include "bme_io.h" #include "bme_err.h" +#define MAX_COLORS 256 // 8bit oldskool mode + // Prototypes int gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags); @@ -320,7 +321,7 @@ int gfx_loadsprites(unsigned num, const char *name) if (!gfx_spriteheaders) { - gfx_setmaxspritefiles(DEFAULT_MAX_SPRFILES); + gfx_setmaxspritefiles(1); } bme_error = BME_OPEN_ERROR; @@ -360,7 +361,7 @@ int gfx_loadsprites(unsigned num, const char *name) gfx_spritedata[num] = (Uint8*)malloc(size - datastart); if (!gfx_spritedata[num]) { - bme_error = BME_OUT_OF_MEMORY; + bme_error = BME_OUT_OF_MEMORY; io_close(handle); return BME_ERROR; } diff --git a/src/bme/bme_gfx.h b/src/bme/bme_gfx.h index b1814e0..ae9a463 100644 --- a/src/bme/bme_gfx.h +++ b/src/bme/bme_gfx.h @@ -16,9 +16,9 @@ int gfx_loadpalette(const char *name); void gfx_calcpalette(int fade, int radd, int gadd, int badd); void gfx_setpalette(void); int gfx_loadblocks(char *name); -int gfx_loadsprites(unsigned num, const char *name); void gfx_freesprites(unsigned num); +int gfx_loadsprites(unsigned num, const char *name); void gfx_drawsprite(int x, int y, unsigned num); extern int gfx_initted; diff --git a/src/bme/bme_io.c b/src/bme/bme_io.c index 8e98701..ed6a967 100644 --- a/src/bme/bme_io.c +++ b/src/bme/bme_io.c @@ -10,7 +10,8 @@ #include "bme_main.h" #include "bme_err.h" -#include "bme_cfg.h" + +#define MAX_HANDLES 16 // Up to 16 simultaneous files open from the datafile typedef struct { diff --git a/src/bme/bme_mou.c b/src/bme/bme_mou.c index 0b67888..7ca1e69 100644 --- a/src/bme/bme_mou.c +++ b/src/bme/bme_mou.c @@ -8,7 +8,6 @@ #include #include "bme_main.h" -#include "bme_cfg.h" #include "bme_win.h" #include "bme_gfx.h" #include "bme_io.h" diff --git a/src/bme/bme_snd.c b/src/bme/bme_snd.c index aaecbd7..fed7114 100644 --- a/src/bme/bme_snd.c +++ b/src/bme/bme_snd.c @@ -17,7 +17,6 @@ #include #include "bme_main.h" -#include "bme_cfg.h" #include "bme_win.h" #include "bme_io.h" #include "bme_err.h" diff --git a/src/bme/bme_win.c b/src/bme/bme_win.c index 3cf6ff4..d217702 100644 --- a/src/bme/bme_win.c +++ b/src/bme/bme_win.c @@ -12,12 +12,7 @@ #include "bme_mou.h" #include "bme_io.h" #include "bme_err.h" -#include "bme_cfg.h" -SDL_Joystick *joy[MAX_JOYSTICKS] = {NULL}; -Sint16 joyx[MAX_JOYSTICKS]; -Sint16 joyy[MAX_JOYSTICKS]; -Uint32 joybuttons[MAX_JOYSTICKS]; SDL_Window *win_window = NULL; // Prototypes @@ -132,27 +127,6 @@ void win_checkmessages(void) { switch (event.type) { - case SDL_EVENT_JOYSTICK_BUTTON_DOWN: - joybuttons[event.jbutton.which] |= 1 << event.jbutton.button; - break; - - case SDL_EVENT_JOYSTICK_BUTTON_UP: - joybuttons[event.jbutton.which] &= ~(1 << event.jbutton.button); - break; - - case SDL_EVENT_JOYSTICK_AXIS_MOTION: - switch (event.jaxis.axis) - { - case 0: - joyx[event.jaxis.which] = event.jaxis.value; - break; - - case 1: - joyy[event.jaxis.which] = event.jaxis.value; - break; - } - break; - case SDL_EVENT_MOUSE_MOTION: win_mousexpos = event.motion.x; win_mouseypos = event.motion.y; diff --git a/src/bme/bme_win.h b/src/bme/bme_win.h index c1b59d1..c2579b0 100644 --- a/src/bme/bme_win.h +++ b/src/bme/bme_win.h @@ -20,9 +20,5 @@ extern unsigned win_mouseyrel; extern unsigned win_mousebuttons; extern int win_mousemode; extern float win_mouseywheel; -extern SDL_Joystick *joy[MAX_JOYSTICKS]; -extern Sint16 joyx[MAX_JOYSTICKS]; -extern Sint16 joyy[MAX_JOYSTICKS]; -extern Uint32 joybuttons[MAX_JOYSTICKS]; extern SDL_Window *win_window; From a0f6d444eaeeea5905aec2aeabde6326aed018ea Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 18:57:01 +0200 Subject: [PATCH 32/39] Update --- src/bme/bme_snd.c | 2 +- src/console.h | 2 -- src/display.cpp | 17 +++++++++++++++++ src/display.h | 17 ----------------- src/file.cpp | 37 ++++++++++++++++++++++--------------- src/file.h | 7 ------- src/loadtrk.cpp | 2 ++ src/play.h | 12 ++++++------ src/reloc.cpp | 15 +++++++++++++++ src/reloc.h | 15 --------------- src/sound.cpp | 2 ++ src/sound.h | 2 -- 12 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/bme/bme_snd.c b/src/bme/bme_snd.c index fed7114..f416613 100644 --- a/src/bme/bme_snd.c +++ b/src/bme/bme_snd.c @@ -81,7 +81,7 @@ RtMidiInPtr midi_device = NULL; void playtestnote(int note, int ins, int chnnum); void insertnote(int newnote); -#define VISIBLEPATTROWS 31 +#define VISIBLEPATTROWS 34 extern int einum; extern int epchn; diff --git a/src/console.h b/src/console.h index 9f87b7f..60f72e6 100644 --- a/src/console.h +++ b/src/console.h @@ -21,8 +21,6 @@ #define MAX_COLUMNS 128 #define MAX_ROWS 40 -#define HOLDDELAY 24 -#define DOUBLECLICKDELAY 15 #ifdef __cplusplus extern "C" { diff --git a/src/display.cpp b/src/display.cpp index 1874e62..444cec9 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -26,6 +26,23 @@ #include +#define CBLACK 0x0 +#define CDBLUE 0x1 +#define CDGREEN 0x2 +#define CDGREY 0x3 +#define CDRED 0x4 +#define CDBROWN 0x5 +#define CLBROWN 0x6 +#define CLGREY 0x7 +#define CGREY 0x8 +#define CLBLUE 0x9 +#define CLGREEN 0xA +#define CCYAN 0xB +#define CLRED 0xC +#define CPURPLE 0xD +#define CYELLOW 0xE +#define CWHITE 0xF + const char *notename[] = {"C-0", "C#0", "D-0", "D#0", "E-0", "F-0", "F#0", "G-0", "G#0", "A-0", "A#0", "B-0", "C-1", "C#1", "D-1", "D#1", "E-1", "F-1", "F#1", "G-1", "G#1", "A-1", "A#1", "B-1", diff --git a/src/display.h b/src/display.h index edf13d0..a5a1d4f 100644 --- a/src/display.h +++ b/src/display.h @@ -19,23 +19,6 @@ #ifndef DISPLAY_H #define DISPLAY_H -#define CBLACK 0x0 -#define CDBLUE 0x1 -#define CDGREEN 0x2 -#define CDGREY 0x3 -#define CDRED 0x4 -#define CDBROWN 0x5 -#define CLBROWN 0x6 -#define CLGREY 0x7 -#define CGREY 0x8 -#define CLBLUE 0x9 -#define CLGREEN 0xA -#define CCYAN 0xB -#define CLRED 0xC -#define CPURPLE 0xD -#define CYELLOW 0xE -#define CWHITE 0xF - #ifdef __cplusplus extern "C" { #endif diff --git a/src/file.cpp b/src/file.cpp index 81c535c..117e239 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -38,6 +38,15 @@ #include #endif +#define MAX_DIRFILES 16384 +#define DOUBLECLICKDELAY 15 + +typedef struct +{ + char *name; + int attribute; +} DIRENTRY; + DIRENTRY direntry[MAX_DIRFILES]; void initpaths(void) @@ -61,17 +70,9 @@ void initpaths(void) int fileselector(char *name, char *path, char *filter, const char *title, int filemode) { - int filepos = 0; - int fileview = 0; - int lastclick = 0; - int lastfile = 0; - - DIR *dir; - struct dirent *de; - struct stat st; - #ifdef __WIN32__ +#ifdef __WIN32__ char drivestr[] = "A:\\"; - char driveexists[26]; +char driveexists[26]; #endif char cmpbuf[MAX_PATHNAME]; char tempname[MAX_PATHNAME]; @@ -81,7 +82,7 @@ int fileselector(char *name, char *path, char *filter, const char *title, int fi // Scan for all existing drives #ifdef __WIN32__ - for (c = 0; c < 26; c++) + for (int c = 0; c < 26; c++) { drivestr[0] = 'A'+c; if (GetDriveType(drivestr) > 1) driveexists[c] = 1; @@ -117,6 +118,7 @@ int fileselector(char *name, char *path, char *filter, const char *title, int fi #endif // Process directory + DIR *dir; #ifdef __amigaos__ dir = opendir(""); #else @@ -124,16 +126,18 @@ int fileselector(char *name, char *path, char *filter, const char *title, int fi #endif if (dir) { - char *filtptr = strstr(filter, "*"); + char *filtptr = std::strstr(filter, "*"); if (!filtptr) filtptr = filter; else filtptr++; for (size_t i = 0; i < std::strlen(filter); i++) filter[i] = std::tolower(filter[i]); + struct dirent *de; while ((de = readdir(dir))) { if ((files < MAX_DIRFILES) && (std::strlen(de->d_name) < MAX_FILENAME)) { + struct stat st; direntry[files].name = strdup(de->d_name); direntry[files].attribute = 0; stat(de->d_name, &st); @@ -195,8 +199,11 @@ int fileselector(char *name, char *path, char *filter, const char *title, int fi } // Search for the current filename - fileview = 0; - filepos = 0; + int fileview = 0; + int filepos = 0; + int lastclick = 0; + int lastfile = 0; + for (int c = 0; c < files; c++) { if ((!direntry[c].attribute) && (!cmpname(name, direntry[c].name))) @@ -515,7 +522,7 @@ int fileselector(char *name, char *path, char *filter, const char *title, int fi void editstring(char *buffer, int maxlength) { - int len = strlen(buffer); + int len = std::strlen(buffer); if ((key >= 32) && (key < 256)) { diff --git a/src/file.h b/src/file.h index 7879f12..506a21d 100644 --- a/src/file.h +++ b/src/file.h @@ -19,7 +19,6 @@ #ifndef FILE_H #define FILE_H -#define MAX_DIRFILES 16384 #define MAX_FILENAME 60 #define MAX_PATHNAME 256 @@ -27,12 +26,6 @@ extern "C" { #endif -typedef struct -{ - char *name; - int attribute; -} DIRENTRY; - void initpaths(void); int fileselector(char *name, char *path, char *filter, const char *title, int filemode); void editstring(char *buffer, int maxlength); diff --git a/src/loadtrk.cpp b/src/loadtrk.cpp index 9fc7c79..0ef94dc 100644 --- a/src/loadtrk.cpp +++ b/src/loadtrk.cpp @@ -37,6 +37,8 @@ #include #include +#define HOLDDELAY 24 + // Increase if configuration has incompatible changes #define CFG_VERSION 2 diff --git a/src/play.h b/src/play.h index 63eab5a..4d2e5bf 100644 --- a/src/play.h +++ b/src/play.h @@ -19,12 +19,12 @@ #ifndef PLAY_H #define PLAY_H -#define PLAY_PLAYING 0x00 -#define PLAY_BEGINNING 0x01 -#define PLAY_POS 0x02 -#define PLAY_PATTERN 0x03 -#define PLAY_STOP 0x04 -#define PLAY_STOPPED 0x80 +#define PLAY_PLAYING 0x00 +#define PLAY_BEGINNING 0x01 +#define PLAY_POS 0x02 +#define PLAY_PATTERN 0x03 +#define PLAY_STOP 0x04 +#define PLAY_STOPPED 0x80 #ifdef __cplusplus extern "C" { diff --git a/src/reloc.cpp b/src/reloc.cpp index 485251f..97b4038 100644 --- a/src/reloc.cpp +++ b/src/reloc.cpp @@ -33,6 +33,21 @@ extern "C" { #include #include +#define PLAYER_BUFFERED 8 +#define PLAYER_SOUNDEFFECTS 16 +#define PLAYER_VOLUME 32 +#define PLAYER_AUTHORINFO 64 +#define PLAYER_ZPGHOSTREGS 128 +#define PLAYER_NOOPTIMIZATION 256 +#define PLAYER_FULLBUFFERED 512 + +#define CAUSE_NONE 0 +#define CAUSE_PATTERN 1 +#define CAUSE_INSTRUMENT 2 +#define CAUSE_WAVECMD 3 + +#define MAX_BYTES_PER_ROW 16 + const char *playeroptname[] = { "Buffered SID-writes", diff --git a/src/reloc.h b/src/reloc.h index b9c4d39..f73fc11 100644 --- a/src/reloc.h +++ b/src/reloc.h @@ -23,27 +23,12 @@ #define FORMAT_PRG 1 #define FORMAT_BIN 2 -#define PLAYER_BUFFERED 8 -#define PLAYER_SOUNDEFFECTS 16 -#define PLAYER_VOLUME 32 -#define PLAYER_AUTHORINFO 64 -#define PLAYER_ZPGHOSTREGS 128 -#define PLAYER_NOOPTIMIZATION 256 -#define PLAYER_FULLBUFFERED 512 - #define MAX_OPTIONS 7 #define TYPE_NONE 0 #define TYPE_OVERFLOW 1 #define TYPE_JUMP 2 -#define CAUSE_NONE 0 -#define CAUSE_PATTERN 1 -#define CAUSE_INSTRUMENT 2 -#define CAUSE_WAVECMD 3 - -#define MAX_BYTES_PER_ROW 16 - #ifdef __cplusplus extern "C" { #endif diff --git a/src/sound.cpp b/src/sound.cpp index 87dcb67..8b91205 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -35,6 +35,8 @@ #include #include +#define MIXBUFFERSIZE 65536 + // General / reSID output int playspeed; bool useexsid = false; diff --git a/src/sound.h b/src/sound.h index 93ed275..11eaae3 100644 --- a/src/sound.h +++ b/src/sound.h @@ -28,8 +28,6 @@ #define NTSCFRAMERATE 60 #define NTSCCLOCKRATE 1022727 -#define MIXBUFFERSIZE 65536 - #ifdef __cplusplus extern "C" { #endif From a00c7b64ef7f629a5e667263347ff6e36e10cbc2 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 20:03:48 +0200 Subject: [PATCH 33/39] Update --- src/bme/bme_main.h | 9 --------- src/file.cpp | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/bme/bme_main.h b/src/bme/bme_main.h index 7fedd41..e409b9c 100644 --- a/src/bme/bme_main.h +++ b/src/bme/bme_main.h @@ -21,15 +21,6 @@ #define MOUSEB_RIGHT 2 #define MOUSEB_MIDDLE 4 -#define JOY_LEFT 1 -#define JOY_RIGHT 2 -#define JOY_UP 4 -#define JOY_DOWN 8 -#define JOY_FIRE1 16 -#define JOY_FIRE2 32 -#define JOY_FIRE3 64 -#define JOY_FIRE4 128 - #define LEFT 0 #define MIDDLE 128 #define RIGHT 255 diff --git a/src/file.cpp b/src/file.cpp index 117e239..f87b0a0 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -105,7 +105,7 @@ char driveexists[26]; } #ifdef __WIN32__ // Create drive letters - for (c = 0; c < 26; c++) + for (int c = 0; c < 26; c++) { if (driveexists[c]) { From b2859fa369813f5b71ea313327d535a05d67b1be Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 20:22:23 +0200 Subject: [PATCH 34/39] Update --- CMakeLists.txt | 22 +++++++-------- src/bme/{bme.c => bme.cpp} | 0 src/bme/bme.h | 3 +- src/bme/{bme_end.c => bme_end.cpp} | 24 ++++++++-------- src/bme/bme_end.h | 14 ++++++++++ src/bme/{bme_gfx.c => bme_gfx.cpp} | 15 ++++++---- src/bme/bme_gfx.h | 8 ++++++ src/bme/{bme_io.c => bme_io.cpp} | 45 +++++++++++++++--------------- src/bme/bme_io.h | 15 +++++++++- src/bme/{bme_mou.c => bme_mou.cpp} | 24 ++++++++-------- src/bme/bme_mou.h | 19 +++++++++++-- src/bme/{bme_snd.c => bme_snd.cpp} | 45 ++++++++++++++++-------------- src/bme/bme_snd.h | 13 +++++++++ src/bme/{bme_win.c => bme_win.cpp} | 16 +++++++---- src/bme/bme_win.h | 12 ++++++++ src/bme/dat2inc.c | 3 +- 16 files changed, 181 insertions(+), 97 deletions(-) rename src/bme/{bme.c => bme.cpp} (100%) rename src/bme/{bme_end.c => bme_end.cpp} (73%) rename src/bme/{bme_gfx.c => bme_gfx.cpp} (99%) rename src/bme/{bme_io.c => bme_io.cpp} (91%) rename src/bme/{bme_mou.c => bme_mou.cpp} (73%) rename src/bme/{bme_snd.c => bme_snd.cpp} (96%) rename src/bme/{bme_win.c => bme_win.cpp} (98%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a041d5..3d0fa16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,13 +43,13 @@ set(LOADTRK_SOURCES src/asm/parse.c src/asm/pc.c src/asm/vec.c - src/bme/bme_gfx.c - src/bme/bme_snd.c - src/bme/bme_win.c - src/bme/bme_mou.c - src/bme/bme_io.c - src/bme/bme_end.c - src/bme/bme.c + src/bme/bme_gfx.cpp + src/bme/bme_snd.cpp + src/bme/bme_win.cpp + src/bme/bme_mou.cpp + src/bme/bme_io.cpp + src/bme/bme_end.cpp + src/bme/bme.cpp src/rtmidi/rtmidi_c.h src/rtmidi/rtmidi_c.cpp src/rtmidi/RtMidi.h @@ -63,15 +63,15 @@ endif(MINGW) set(MOD2SNG_SOURCES src/mod2sng.c - src/bme/bme_end.c) + src/bme/bme_end.cpp) set(INS2SND2_SOURCES src/ins2snd2.c - src/bme/bme_end.c) + src/bme/bme_end.cpp) set(SNGSPLI2_SOURCES src/sngspli2.c - src/bme/bme_end.c) + src/bme/bme_end.cpp) include_directories(${CMAKE_SOURCE_DIR}/src) include_directories(${CMAKE_SOURCE_DIR}/src/bme) @@ -80,7 +80,7 @@ include_directories(${CMAKE_BINARY_DIR}/src/residfp) find_package(SDL3 REQUIRED) -add_executable(datafile src/bme/datafile.c src/bme/bme_end.c) +add_executable(datafile src/bme/datafile.c src/bme/bme_end.cpp) add_executable(dat2inc src/bme/dat2inc.c) target_include_directories(datafile PUBLIC SDL3::Headers) diff --git a/src/bme/bme.c b/src/bme/bme.cpp similarity index 100% rename from src/bme/bme.c rename to src/bme/bme.cpp diff --git a/src/bme/bme.h b/src/bme/bme.h index 89b6878..72aa8ca 100644 --- a/src/bme/bme.h +++ b/src/bme/bme.h @@ -7,7 +7,6 @@ extern "C" { #endif -#include #include "bme_main.h" #include "bme_err.h" #include "bme_snd.h" @@ -17,6 +16,8 @@ extern "C" { #include "bme_io.h" #include "bme_end.h" +#include + #ifdef __cplusplus } #endif diff --git a/src/bme/bme_end.c b/src/bme/bme_end.cpp similarity index 73% rename from src/bme/bme_end.c rename to src/bme/bme_end.cpp index f3fc51b..3d3717e 100644 --- a/src/bme/bme_end.c +++ b/src/bme/bme_end.cpp @@ -1,12 +1,14 @@ -#include -#include +#include +#include + +extern "C" { void fwrite8(FILE *file, unsigned data) { uint8_t bytes[1]; bytes[0] = data; - fwrite(bytes, 1, 1, file); + std::fwrite(bytes, 1, 1, file); } void fwritele16(FILE *file, unsigned data) @@ -15,7 +17,7 @@ void fwritele16(FILE *file, unsigned data) bytes[0] = data; bytes[1] = data >> 8; - fwrite(bytes, 2, 1, file); + std::fwrite(bytes, 2, 1, file); } void fwritele32(FILE *file, unsigned data) @@ -26,14 +28,14 @@ void fwritele32(FILE *file, unsigned data) bytes[1] = data >> 8; bytes[2] = data >> 16; bytes[3] = data >> 24; - fwrite(bytes, 4, 1, file); + std::fwrite(bytes, 4, 1, file); } unsigned fread8(FILE *file) { uint8_t bytes[1]; - fread(bytes, 1, 1, file); + std::fread(bytes, 1, 1, file); return bytes[0]; } @@ -41,7 +43,7 @@ unsigned freadle16(FILE *file) { uint8_t bytes[2]; - fread(bytes, 2, 1, file); + std::fread(bytes, 2, 1, file); return (bytes[0]) | (bytes[1] << 8); } @@ -49,7 +51,7 @@ unsigned freadle32(FILE *file) { uint8_t bytes[4]; - fread(bytes, 4, 1, file); + std::fread(bytes, 4, 1, file); return (bytes[0]) | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24); } @@ -57,7 +59,7 @@ unsigned freadhe16(FILE *file) { uint8_t bytes[2]; - fread(bytes, 2, 1, file); + std::fread(bytes, 2, 1, file); return (bytes[1]) | (bytes[0] << 8); } @@ -65,8 +67,8 @@ unsigned freadhe32(FILE *file) { uint8_t bytes[4]; - fread(bytes, 4, 1, file); + std::fread(bytes, 4, 1, file); return (bytes[3]) | (bytes[2] << 8) | (bytes[1] << 16) | (bytes[0] << 24); } - +} diff --git a/src/bme/bme_end.h b/src/bme/bme_end.h index 31dbafd..1854f13 100644 --- a/src/bme/bme_end.h +++ b/src/bme/bme_end.h @@ -1,3 +1,11 @@ + +#ifndef BME_END_H +#define BME_END_H + +#ifdef __cplusplus +extern "C" { +#endif + void fwrite8(FILE *file, unsigned data); void fwritele16(FILE *file, unsigned data); void fwritele32(FILE *file, unsigned data); @@ -6,3 +14,9 @@ unsigned freadle16(FILE *file); unsigned freadle32(FILE *file); unsigned freadhe16(FILE *file); unsigned freadhe32(FILE *file); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/bme/bme_gfx.c b/src/bme/bme_gfx.cpp similarity index 99% rename from src/bme/bme_gfx.c rename to src/bme/bme_gfx.cpp index 555c596..44cfb87 100644 --- a/src/bme/bme_gfx.c +++ b/src/bme/bme_gfx.cpp @@ -2,18 +2,21 @@ // BME (Blasphemous Multimedia Engine) graphics main module // -#include -#include -#include -#include - #include "bme_main.h" #include "bme_win.h" #include "bme_io.h" #include "bme_err.h" +#include + +#include +#include +#include + #define MAX_COLORS 256 // 8bit oldskool mode +extern "C" { + // Prototypes int gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags); @@ -579,4 +582,4 @@ void gfx_drawsprite(int x, int y, unsigned num) } } - +} diff --git a/src/bme/bme_gfx.h b/src/bme/bme_gfx.h index ae9a463..543f310 100644 --- a/src/bme/bme_gfx.h +++ b/src/bme/bme_gfx.h @@ -3,6 +3,10 @@ #ifndef BME_GFX_H #define BME_GFX_H +#ifdef __cplusplus +extern "C" { +#endif + int gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags); int gfx_reinit(); void gfx_uninit(void); @@ -43,4 +47,8 @@ extern Uint8 gfx_palette[]; extern SDL_Surface *gfx_screen; extern SDL_Renderer *gfx_renderer; +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/bme/bme_io.c b/src/bme/bme_io.cpp similarity index 91% rename from src/bme/bme_io.c rename to src/bme/bme_io.cpp index ed6a967..51f6551 100644 --- a/src/bme/bme_io.c +++ b/src/bme/bme_io.cpp @@ -2,17 +2,20 @@ // BME (Blasphemous Multimedia Engine) datafile IO main module // -#include -#include -#include -#include -#include - #include "bme_main.h" #include "bme_err.h" +#include + +#include +#include +#include +#include + #define MAX_HANDLES 16 // Up to 16 simultaneous files open from the datafile +extern "C" { + typedef struct { Uint32 offset; @@ -31,7 +34,7 @@ static int io_usedatafile = 0; static HEADER *fileheaders; static unsigned files; static char ident[4]; -static char *idstring = "DAT!"; +static const char *idstring = "DAT!"; static HANDLE handle[MAX_HANDLES]; static FILE *fileptr[MAX_HANDLES] = {NULL}; static FILE *datafilehandle = NULL; @@ -50,8 +53,6 @@ void io_setfilemode(int usedf) int io_openlinkeddatafile(unsigned char *ptr) { - unsigned index; - if (datafilehandle) fclose(datafilehandle); datafilehandle = NULL; @@ -66,29 +67,27 @@ int io_openlinkeddatafile(unsigned char *ptr) } files = linkedreadle32(); - fileheaders = malloc(files * sizeof(HEADER)); + fileheaders = (HEADER*)std::malloc(files * sizeof(HEADER)); if (!fileheaders) { bme_error = BME_OUT_OF_MEMORY; return BME_ERROR; } - for (index = 0; index < files; index++) + for (unsigned index = 0; index < files; index++) { fileheaders[index].offset = linkedreadle32(); fileheaders[index].length = linkedreadle32(); linkedread(&fileheaders[index].name, 13); } - for (index = 0; index < MAX_HANDLES; index++) handle[index].open = 0; + for (unsigned index = 0; index < MAX_HANDLES; index++) handle[index].open = 0; io_usedatafile = 1; bme_error = BME_OK; return BME_OK; } -int io_opendatafile(char *name) +int io_opendatafile(const char *name) { - unsigned index; - if (name) { datafilehandle = fopen(name, "rb"); @@ -107,20 +106,20 @@ int io_opendatafile(char *name) } files = freadle32(datafilehandle); - fileheaders = malloc(files * sizeof(HEADER)); + fileheaders = (HEADER*)std::malloc(files * sizeof(HEADER)); if (!fileheaders) { bme_error = BME_OUT_OF_MEMORY; return BME_ERROR; } - for (index = 0; index < files; index++) + for (unsigned index = 0; index < files; index++) { fileheaders[index].offset = freadle32(datafilehandle); fileheaders[index].length = freadle32(datafilehandle); fread(&fileheaders[index].name, 13, 1, datafilehandle); } - for (index = 0; index < MAX_HANDLES; index++) handle[index].open = 0; + for (unsigned index = 0; index < MAX_HANDLES; index++) handle[index].open = 0; io_usedatafile = 1; bme_error = BME_OK; return BME_OK; @@ -162,7 +161,7 @@ int io_open(const char *name) namelength = strlen(name); if (namelength > 12) namelength = 12; - memcpy(namecopy, name, namelength + 1); + std::memcpy(namecopy, name, namelength + 1); for (index = 0; index < strlen(namecopy); index++) { namecopy[index] = toupper(namecopy[index]); @@ -177,7 +176,7 @@ int io_open(const char *name) while (count) { - if (!strcmp(namecopy, handle[index].currentheader->name)) + if (!std::strcmp(namecopy, handle[index].currentheader->name)) { handle[index].open = 1; handle[index].filepos = 0; @@ -248,7 +247,7 @@ int io_read(int index, void *buffer, int length) if (!handle[index].open) return -1; if (length + handle[index].filepos > handle[index].currentheader->length) length = handle[index].currentheader->length - handle[index].filepos; - + if (datafilehandle) { fseek(datafilehandle, handle[index].currentheader->offset + handle[index].filepos, SEEK_SET); @@ -350,5 +349,7 @@ static unsigned linkedreadle32(void) linkedread(&bytes, 4); return (bytes[3] << 24) | (bytes[2] << 16) | (bytes[1] << 8) | bytes[0]; -} +} + +} diff --git a/src/bme/bme_io.h b/src/bme/bme_io.h index 00e9467..d0c6b57 100644 --- a/src/bme/bme_io.h +++ b/src/bme/bme_io.h @@ -1,10 +1,17 @@ // BME IO module header file +#ifndef BME_IO_H +#define BME_IO_H + +#ifdef __cplusplus +extern "C" { +#endif + int io_open(const char *name); int io_lseek(int handle, int bytes, int whence); int io_read(int handle, void *buffer, int size); void io_close(int handle); -int io_opendatafile(char *name); +int io_opendatafile(const char *name); int io_openlinkeddatafile(unsigned char *ptr); void io_setfilemode(int usedf); unsigned io_read8(int handle); @@ -12,3 +19,9 @@ unsigned io_readle16(int handle); unsigned io_readle32(int handle); unsigned io_readhe16(int handle); unsigned io_readhe32(int handle); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/bme/bme_mou.c b/src/bme/bme_mou.cpp similarity index 73% rename from src/bme/bme_mou.c rename to src/bme/bme_mou.cpp index 7ca1e69..f8da16a 100644 --- a/src/bme/bme_mou.c +++ b/src/bme/bme_mou.cpp @@ -2,29 +2,24 @@ // BME (Blasphemous Multimedia Engine) mouse module // -#include -#include -#include -#include - #include "bme_main.h" #include "bme_win.h" #include "bme_gfx.h" #include "bme_io.h" #include "bme_err.h" -void mou_init(void); -void mou_uninit(void); -void mou_getpos(unsigned *x, unsigned *y); -void mou_getmove(int *dx, int *dy); -unsigned mou_getbuttons(void); +#include + +#ifdef __cplusplus +extern "C" { +#endif -void mou_init(void) +void mou_init() { win_mousebuttons = 0; } -void mou_uninit(void) +void mou_uninit() { } @@ -48,7 +43,6 @@ void mou_getmove(int *dx, int *dy) *dy = win_mouseyrel; win_mousexrel = 0; win_mouseyrel = 0; - } unsigned mou_getbuttons(void) @@ -56,3 +50,7 @@ unsigned mou_getbuttons(void) return win_mousebuttons; } +#ifdef __cplusplus +} +#endif + diff --git a/src/bme/bme_mou.h b/src/bme/bme_mou.h index f784e48..80d8ea5 100644 --- a/src/bme/bme_mou.h +++ b/src/bme/bme_mou.h @@ -1,7 +1,20 @@ // BME mouse functions header file -void mou_init(void); -void mou_uninit(void); +#ifndef BME_MOU__H +#define BME_MOU__H + +#ifdef __cplusplus +extern "C" { +#endif + +void mou_init(); +void mou_uninit(); void mou_getpos(unsigned *x, unsigned *y); void mou_getmove(int *dx, int *dy); -unsigned mou_getbuttons(void); +unsigned mou_getbuttons(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/bme/bme_snd.c b/src/bme/bme_snd.cpp similarity index 96% rename from src/bme/bme_snd.c rename to src/bme/bme_snd.cpp index f416613..76e0548 100644 --- a/src/bme/bme_snd.c +++ b/src/bme/bme_snd.cpp @@ -25,6 +25,8 @@ typedef jack_default_audio_sample_t sample_t; #endif +extern "C" { + // Prototypes int snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirectsound); void snd_uninit(void); @@ -48,8 +50,8 @@ static void snd_float_postprocess(Sint32 *src, float* dest, unsigned samples); static void snd_16bit_postprocess(Sint32 *src, Sint16 *dest, unsigned samples); static void snd_8bit_postprocess(Sint32 *src, Uint8 *dest, unsigned samples); -void (*snd_player)(void) = NULL; -CHANNEL *snd_channel = NULL; +void (*snd_player)(void) = nullptr; +CHANNEL *snd_channel = nullptr; int snd_channels = 0; int snd_sndinitted = 0; int snd_bpmcount; @@ -57,25 +59,25 @@ int snd_bpmtempo = 125; unsigned snd_mixmode; unsigned snd_mixrate; -static void (*snd_custommixer)(Sint32 *dest, unsigned samples) = NULL; +static void (*snd_custommixer)(Sint32 *dest, unsigned samples) = nullptr; static unsigned snd_buffersize; static unsigned snd_framesize; static unsigned snd_previouschannels = 0xffffffff; static int snd_atexit_registered = 0; -static Sint32 *snd_clipbuffer = NULL; -SDL_AudioStream *stream = NULL; +static Sint32 *snd_clipbuffer = nullptr; +SDL_AudioStream *stream = nullptr; static SDL_AudioSpec spec; #ifdef USE_JACK -static int use_jack = 1; -static int use_jack_audio = 0; +static bool use_jack = true; +static bool use_jack_audio = false; static jack_client_t* client; static jack_port_t* output_port; #endif #ifdef USE_MIDI_INPUT -RtMidiInPtr midi_device = NULL; +RtMidiInPtr midi_device = nullptr; #endif void playtestnote(int note, int ins, int chnnum); @@ -93,7 +95,7 @@ int current_note_on = -1; #ifdef USE_JACK int snd_jack_process(jack_nframes_t nframes, void *arg) { if (use_jack_audio) { - sample_t* buffer = jack_port_get_buffer(output_port, nframes); + sample_t* buffer = (sample_t*)jack_port_get_buffer(output_port, nframes); snd_mixdata((Uint8*)buffer, sizeof(sample_t) * nframes); } return 0; @@ -209,7 +211,7 @@ int snd_init_midi() { return BME_ERROR; } - rtmidi_in_set_callback(midi_device, snd_midi_process, NULL); + rtmidi_in_set_callback(midi_device, snd_midi_process, nullptr); if (!midi_device->ok) { fprintf(stderr, "failed to set midi callback: %s\n", midi_device->msg); return BME_ERROR; @@ -266,7 +268,7 @@ int snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirec snd_bpmcount = 0; - stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, snd_mixer_callback, NULL); + stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, snd_mixer_callback, nullptr); if (!stream) { @@ -332,19 +334,18 @@ int snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirec } int snd_initchannels(unsigned channels) { - int c; if (snd_previouschannels != channels) { CHANNEL *chptr; if (snd_channel) { - free(snd_channel); - snd_channel = NULL; + std::free(snd_channel); + snd_channel = nullptr; snd_channels = 0; } - snd_channel = malloc(channels * sizeof(CHANNEL)); + snd_channel = (CHANNEL*)std::malloc(channels * sizeof(CHANNEL)); if (!snd_channel) { bme_error = BME_OUT_OF_MEMORY; @@ -356,10 +357,10 @@ int snd_initchannels(unsigned channels) { snd_previouschannels = channels; // Init all channels (no sound played, no sample, mastervolume 64) - for (c = snd_channels; c > 0; c--) + for (int c = snd_channels; c > 0; c--) { chptr->voicemode = VM_OFF; - chptr->smp = NULL; + chptr->smp = nullptr; chptr->mastervol = 64; chptr++; } @@ -382,7 +383,7 @@ void snd_uninit(void) } snd_uninitmixer(); #ifdef USE_MIDI_INPUT - if (midi_device != NULL) + if (midi_device != nullptr) rtmidi_in_free(midi_device); #endif } @@ -402,7 +403,7 @@ static int snd_initmixer(void) bufSize *= 2; } - snd_clipbuffer = malloc(bufSize); + snd_clipbuffer = (Sint32*)std::malloc(bufSize); if (!snd_clipbuffer) return 0; return 1; @@ -412,8 +413,8 @@ static void snd_uninitmixer(void) { if (snd_clipbuffer) { - free(snd_clipbuffer); - snd_clipbuffer = NULL; + std::free(snd_clipbuffer); + snd_clipbuffer = nullptr; } } @@ -784,3 +785,5 @@ static void snd_mixchannel(CHANNEL *chptr, Sint32 *dest, unsigned samples) } } } + +} diff --git a/src/bme/bme_snd.h b/src/bme/bme_snd.h index b1c7826..1105759 100644 --- a/src/bme/bme_snd.h +++ b/src/bme/bme_snd.h @@ -1,5 +1,12 @@ // Sound functions header file +#ifndef BME_SND_H +#define BME_SND_H + +#ifdef __cplusplus +extern "C" { +#endif + int snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirectsound); void snd_uninit(void); void snd_setcustommixer(void (*custommixer)(Sint32 *dest, unsigned samples)); @@ -17,3 +24,9 @@ extern int snd_channels; extern int snd_buffers; extern unsigned snd_mixmode; extern unsigned snd_mixrate; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/bme/bme_win.c b/src/bme/bme_win.cpp similarity index 98% rename from src/bme/bme_win.c rename to src/bme/bme_win.cpp index d217702..68e7be9 100644 --- a/src/bme/bme_win.c +++ b/src/bme/bme_win.cpp @@ -2,18 +2,21 @@ // BME (Blasphemous Multimedia Engine) windows & timing module // -#include -#include -#include - -#include #include "bme_main.h" #include "bme_gfx.h" #include "bme_mou.h" #include "bme_io.h" #include "bme_err.h" -SDL_Window *win_window = NULL; +#include + +#include +#include +#include + +extern "C" { + +SDL_Window *win_window = nullptr; // Prototypes @@ -241,3 +244,4 @@ void win_setmousemode(int mode) } } +} diff --git a/src/bme/bme_win.h b/src/bme/bme_win.h index c2579b0..6f210b5 100644 --- a/src/bme/bme_win.h +++ b/src/bme/bme_win.h @@ -1,5 +1,12 @@ // BME windows, input & timing module header file +#ifndef BME_WIN_H +#define BME_WIN_H + +#ifdef __cplusplus +extern "C" { +#endif + int win_openwindow(unsigned xsize, unsigned ysize, const char *appname, char *icon); void win_closewindow(void); void win_checkmessages(void); @@ -22,3 +29,8 @@ extern int win_mousemode; extern float win_mouseywheel; extern SDL_Window *win_window; +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/bme/dat2inc.c b/src/bme/dat2inc.c index bda6c34..8f8402b 100644 --- a/src/bme/dat2inc.c +++ b/src/bme/dat2inc.c @@ -26,7 +26,7 @@ int main(int argc, char *argv[]) if (!out) { printf("Includefile open error!\n"); - fclose(in); + fclose(in); return 1; } fseek(in, 0, SEEK_END); @@ -48,4 +48,3 @@ int main(int argc, char *argv[]) fclose(out); return 0; } - From 4872feaa456a9b6db3ead0afb2128dc6502d7f61 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 20:37:01 +0200 Subject: [PATCH 35/39] Cleanup unused stuff --- src/bme/bme_gfx.cpp | 33 +++++++++++++-------------------- src/bme/bme_gfx.h | 16 +++++++--------- src/bme/bme_io.cpp | 11 +++-------- src/bme/bme_io.h | 1 - src/bme/bme_mou.cpp | 12 ------------ src/bme/bme_mou.h | 2 -- src/bme/bme_snd.cpp | 10 +++++----- src/bme/bme_snd.h | 8 ++------ src/bme/bme_win.cpp | 8 +++----- src/bme/bme_win.h | 3 --- src/console.cpp | 2 +- 11 files changed, 34 insertions(+), 72 deletions(-) diff --git a/src/bme/bme_gfx.cpp b/src/bme/bme_gfx.cpp index 44cfb87..2b59f13 100644 --- a/src/bme/bme_gfx.cpp +++ b/src/bme/bme_gfx.cpp @@ -21,25 +21,23 @@ extern "C" { int gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags); int gfx_reinit(); -void gfx_uninit(void); +void gfx_uninit(); int gfx_lock(); -void gfx_unlock(void); -void gfx_flip(void); +void gfx_unlock(); +void gfx_flip(); void gfx_setclipregion(unsigned left, unsigned top, unsigned right, unsigned bottom); void gfx_setmaxspritefiles(unsigned num); -void gfx_setmaxcolors(int num); int gfx_loadpalette(const char *name); void gfx_calcpalette(int fade, int radd, int gadd, int badd); -void gfx_setpalette(void); -int gfx_loadblocks(char *name); +void gfx_setpalette(); int gfx_loadsprites(unsigned num, const char *name); void gfx_freesprites(unsigned num); void gfx_drawsprite(int x, int y, unsigned num); void gfx_getspriteinfo(unsigned num); -int gfx_initted = 0; -int gfx_redraw = 0; +bool gfx_initted = false; +bool gfx_redraw = false; int gfx_scanlinemode = 0; int gfx_preventswitch = 0; unsigned gfx_virtualxsize; @@ -145,8 +143,8 @@ int gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags) gfx_initexec = 0; if (gfx_screen) { - gfx_initted = 1; - gfx_redraw = 1; + gfx_initted = true; + gfx_redraw = true; gfx_setpalette(); win_setmousemode(win_mousemode); return BME_OK; @@ -161,12 +159,12 @@ int gfx_reinit() gfx_last_flags); } -void gfx_uninit(void) +void gfx_uninit() { SDL_DestroyTexture(sdlTexture); SDL_DestroySurface(gfx_screen); SDL_DestroyRenderer(gfx_renderer); - gfx_initted = 0; + gfx_initted = false; return; } @@ -182,7 +180,7 @@ int gfx_lock() else return 0; } -void gfx_unlock(void) +void gfx_unlock() { if (gfx_locked) { @@ -199,12 +197,7 @@ void gfx_flip() SDL_RenderClear(gfx_renderer); SDL_RenderTexture(gfx_renderer, sdlTexture, NULL, NULL); SDL_RenderPresent(gfx_renderer); - gfx_redraw = 0; -} - -void gfx_setmaxcolors(int num) -{ - gfx_maxcolors = num; + gfx_redraw = false; } int gfx_loadpalette(const char *name) @@ -271,7 +264,7 @@ void gfx_calcpalette(int fade, int radd, int gadd, int badd) } } -void gfx_setpalette(void) +void gfx_setpalette() { if (!gfx_initted) return; diff --git a/src/bme/bme_gfx.h b/src/bme/bme_gfx.h index 543f310..e0d0281 100644 --- a/src/bme/bme_gfx.h +++ b/src/bme/bme_gfx.h @@ -9,27 +9,25 @@ extern "C" { int gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags); int gfx_reinit(); -void gfx_uninit(void); +void gfx_uninit(); int gfx_lock(); -void gfx_unlock(void); -void gfx_flip(void); +void gfx_unlock(); +void gfx_flip(); void gfx_setclipregion(unsigned left, unsigned top, unsigned right, unsigned bottom); void gfx_setmaxspritefiles(unsigned num); -void gfx_setmaxcolors(int num); int gfx_loadpalette(const char *name); void gfx_calcpalette(int fade, int radd, int gadd, int badd); -void gfx_setpalette(void); -int gfx_loadblocks(char *name); -void gfx_freesprites(unsigned num); +void gfx_setpalette(); int gfx_loadsprites(unsigned num, const char *name); void gfx_drawsprite(int x, int y, unsigned num); +void gfx_freesprites(unsigned num); -extern int gfx_initted; +extern bool gfx_initted; extern int gfx_scanlinemode; extern int gfx_preventswitch; extern int gfx_fullscreen; -extern int gfx_redraw; +extern bool gfx_redraw; extern unsigned gfx_windowxsize; extern unsigned gfx_windowysize; extern unsigned gfx_virtualxsize; diff --git a/src/bme/bme_io.cpp b/src/bme/bme_io.cpp index 51f6551..3c3d0d1 100644 --- a/src/bme/bme_io.cpp +++ b/src/bme/bme_io.cpp @@ -30,7 +30,7 @@ typedef struct int open; } HANDLE; -static int io_usedatafile = 0; +static bool io_usedatafile = false; static HEADER *fileheaders; static unsigned files; static char ident[4]; @@ -46,11 +46,6 @@ static void linkedseek(unsigned pos); static void linkedread(void *buffer, int length); static unsigned linkedreadle32(void); -void io_setfilemode(int usedf) -{ - io_usedatafile = usedf; -} - int io_openlinkeddatafile(unsigned char *ptr) { if (datafilehandle) fclose(datafilehandle); @@ -81,7 +76,7 @@ int io_openlinkeddatafile(unsigned char *ptr) } for (unsigned index = 0; index < MAX_HANDLES; index++) handle[index].open = 0; - io_usedatafile = 1; + io_usedatafile = true; bme_error = BME_OK; return BME_OK; } @@ -120,7 +115,7 @@ int io_opendatafile(const char *name) } for (unsigned index = 0; index < MAX_HANDLES; index++) handle[index].open = 0; - io_usedatafile = 1; + io_usedatafile = true; bme_error = BME_OK; return BME_OK; } diff --git a/src/bme/bme_io.h b/src/bme/bme_io.h index d0c6b57..05accbd 100644 --- a/src/bme/bme_io.h +++ b/src/bme/bme_io.h @@ -13,7 +13,6 @@ int io_read(int handle, void *buffer, int size); void io_close(int handle); int io_opendatafile(const char *name); int io_openlinkeddatafile(unsigned char *ptr); -void io_setfilemode(int usedf); unsigned io_read8(int handle); unsigned io_readle16(int handle); unsigned io_readle32(int handle); diff --git a/src/bme/bme_mou.cpp b/src/bme/bme_mou.cpp index f8da16a..2f6bd16 100644 --- a/src/bme/bme_mou.cpp +++ b/src/bme/bme_mou.cpp @@ -19,10 +19,6 @@ void mou_init() win_mousebuttons = 0; } -void mou_uninit() -{ -} - void mou_getpos(unsigned *x, unsigned *y) { if (!gfx_initted) @@ -37,14 +33,6 @@ void mou_getpos(unsigned *x, unsigned *y) } } -void mou_getmove(int *dx, int *dy) -{ - *dx = win_mousexrel; - *dy = win_mouseyrel; - win_mousexrel = 0; - win_mouseyrel = 0; -} - unsigned mou_getbuttons(void) { return win_mousebuttons; diff --git a/src/bme/bme_mou.h b/src/bme/bme_mou.h index 80d8ea5..8099d5e 100644 --- a/src/bme/bme_mou.h +++ b/src/bme/bme_mou.h @@ -8,9 +8,7 @@ extern "C" { #endif void mou_init(); -void mou_uninit(); void mou_getpos(unsigned *x, unsigned *y); -void mou_getmove(int *dx, int *dy); unsigned mou_getbuttons(); #ifdef __cplusplus diff --git a/src/bme/bme_snd.cpp b/src/bme/bme_snd.cpp index 76e0548..58fb6f7 100644 --- a/src/bme/bme_snd.cpp +++ b/src/bme/bme_snd.cpp @@ -53,7 +53,7 @@ static void snd_8bit_postprocess(Sint32 *src, Uint8 *dest, unsigned samples); void (*snd_player)(void) = nullptr; CHANNEL *snd_channel = nullptr; int snd_channels = 0; -int snd_sndinitted = 0; +bool snd_sndinitted = false; int snd_bpmcount; int snd_bpmtempo = 125; unsigned snd_mixmode; @@ -114,7 +114,7 @@ int snd_init_jack() { snd_mixrate = jack_get_sample_rate(client); snd_bpmcount = 0; - snd_sndinitted = 1; + snd_sndinitted = true; // force 16 bit snd_mixmode = SIXTEENBIT; @@ -276,7 +276,7 @@ int snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirec snd_uninit(); return BME_ERROR; } - snd_sndinitted = 1; + snd_sndinitted = true; snd_mixmode = 0; snd_framesize = 1; @@ -370,7 +370,7 @@ int snd_initchannels(unsigned channels) { } -void snd_uninit(void) +void snd_uninit() { if (snd_sndinitted #ifdef USE_JACK @@ -379,7 +379,7 @@ void snd_uninit(void) ) { SDL_DestroyAudioStream(stream); - snd_sndinitted = 0; + snd_sndinitted = false; } snd_uninitmixer(); #ifdef USE_MIDI_INPUT diff --git a/src/bme/bme_snd.h b/src/bme/bme_snd.h index 1105759..27412d4 100644 --- a/src/bme/bme_snd.h +++ b/src/bme/bme_snd.h @@ -8,16 +8,12 @@ extern "C" { #endif int snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirectsound); -void snd_uninit(void); +void snd_uninit(); void snd_setcustommixer(void (*custommixer)(Sint32 *dest, unsigned samples)); -void snd_preventdistortion(unsigned channels); -void snd_setmastervolume(unsigned chnum, unsigned char mastervol); -void snd_setmusicmastervolume(unsigned musicchannels, unsigned char mastervol); -void snd_setsfxmastervolume(unsigned musicchannels, unsigned char mastervol); extern void (*snd_player)(void); extern CHANNEL *snd_channel; -extern int snd_sndinitted; +extern bool snd_sndinitted; extern int snd_bpmtempo; extern int snd_bpmcount; extern int snd_channels; diff --git a/src/bme/bme_win.cpp b/src/bme/bme_win.cpp index 68e7be9..b1620c3 100644 --- a/src/bme/bme_win.cpp +++ b/src/bme/bme_win.cpp @@ -29,11 +29,10 @@ void win_setmousemode(int mode); // Global variables int win_fullscreen = 0; // By default windowed -int win_windowinitted = 0; +bool win_windowinitted = false; int win_quitted = 0; unsigned char win_keytable[SDL_SCANCODE_COUNT] = {0}; unsigned char win_asciikey = 0; -unsigned win_virtualkey = 0; unsigned win_mousexpos = 0; unsigned win_mouseypos = 0; unsigned win_mousexrel = 0; @@ -62,7 +61,7 @@ int win_openwindow(unsigned xsize, unsigned ysize, const char *appname, char *ic return BME_ERROR; } atexit(SDL_Quit); - win_windowinitted = 1; + win_windowinitted = true; } //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); @@ -184,7 +183,6 @@ void win_checkmessages(void) break; case SDL_EVENT_KEY_DOWN: - win_virtualkey = event.key.key; keynum = event.key.scancode; if (keynum < SDL_SCANCODE_COUNT) { @@ -211,7 +209,7 @@ void win_checkmessages(void) case SDL_EVENT_WINDOW_RESIZED: //case SDL_VIDEOEXPOSE: - gfx_redraw = 1; + gfx_redraw = true; break; } } diff --git a/src/bme/bme_win.h b/src/bme/bme_win.h index 6f210b5..38769f1 100644 --- a/src/bme/bme_win.h +++ b/src/bme/bme_win.h @@ -9,17 +9,14 @@ extern "C" { int win_openwindow(unsigned xsize, unsigned ysize, const char *appname, char *icon); void win_closewindow(void); -void win_checkmessages(void); int win_getspeed(int framerate); void win_setmousemode(int mode); -extern int win_windowinitted; extern int win_quitted; extern int win_fullscreen; extern unsigned char win_keytable[SDL_SCANCODE_COUNT]; extern unsigned char win_keystate[SDL_SCANCODE_COUNT]; extern unsigned char win_asciikey; -extern unsigned win_virtualkey; extern unsigned win_mousexpos; extern unsigned win_mouseypos; extern unsigned win_mousexrel; diff --git a/src/console.cpp b/src/console.cpp index 4267a9f..23666c8 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -369,7 +369,7 @@ void fliptoscreen(void) // If redraw requested, mark whole screen changed if (gfx_redraw) { - gfx_redraw = 0; + gfx_redraw = false; std::memset(prevscrbuffer, 0xff, MAX_COLUMNS*MAX_ROWS*sizeof(unsigned)); } From d1f137d11ea2f6680858201dcf25e3eb0b193d85 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 20:44:15 +0200 Subject: [PATCH 36/39] Update --- CMakeLists.txt | 4 +- src/bme/{dat2inc.c => dat2inc.cpp} | 27 ++++----- src/bme/{datafile.c => datafile.cpp} | 91 +++++++++++++--------------- 3 files changed, 55 insertions(+), 67 deletions(-) rename src/bme/{dat2inc.c => dat2inc.cpp} (65%) rename src/bme/{datafile.c => datafile.cpp} (63%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d0fa16..8272549 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,8 +80,8 @@ include_directories(${CMAKE_BINARY_DIR}/src/residfp) find_package(SDL3 REQUIRED) -add_executable(datafile src/bme/datafile.c src/bme/bme_end.cpp) -add_executable(dat2inc src/bme/dat2inc.c) +add_executable(datafile src/bme/datafile.cpp src/bme/bme_end.cpp) +add_executable(dat2inc src/bme/dat2inc.cpp) target_include_directories(datafile PUBLIC SDL3::Headers) diff --git a/src/bme/dat2inc.c b/src/bme/dat2inc.cpp similarity index 65% rename from src/bme/dat2inc.c rename to src/bme/dat2inc.cpp index 8f8402b..ecd8b8a 100644 --- a/src/bme/dat2inc.c +++ b/src/bme/dat2inc.cpp @@ -2,49 +2,44 @@ // Datafile -> C include file // -#include +#include int main(int argc, char *argv[]) { - FILE *in; - FILE *out; - int length; - int c; - if (argc < 3) { printf("Usage: dat2inc \n\n"); return 1; } - in = fopen(argv[1], "rb"); + FILE *in = std::fopen(argv[1], "rb"); if (!in) { printf("Datafile open error!\n"); return 1; } - out = fopen(argv[2], "wt"); + FILE *out = std::fopen(argv[2], "wt"); if (!out) { printf("Includefile open error!\n"); - fclose(in); + std::fclose(in); return 1; } - fseek(in, 0, SEEK_END); - length = ftell(in); - fseek(in, 0, SEEK_SET); + std::fseek(in, 0, SEEK_END); + int length = ftell(in); + std::fseek(in, 0, SEEK_SET); fprintf(out, "unsigned char datafile[] = {\n"); - for (c = 0; c < length; c++) + for (int c = 0; c < length; c++) { if (c) - { + { fprintf(out, ", "); if (!(c % 10)) fprintf(out, "\n"); } fprintf(out, "0x%02x", fgetc(in)); } fprintf(out, "};\n"); - fclose(in); - fclose(out); + std::fclose(in); + std::fclose(out); return 0; } diff --git a/src/bme/datafile.c b/src/bme/datafile.cpp similarity index 63% rename from src/bme/datafile.c rename to src/bme/datafile.cpp index 0ebf9ed..be8d2a3 100644 --- a/src/bme/datafile.c +++ b/src/bme/datafile.cpp @@ -2,11 +2,11 @@ // Datafile creator // -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "bme_end.h" @@ -24,17 +24,13 @@ static HEADER header[MAXFILES]; static char fullname[MAXFILES][MAXFILENAME]; static int files; -int main(int argc, char **argv); -int addfile(HEADER *header, FILE *dest, char *name); +bool addfile(HEADER *header, FILE *dest, char *name); void fwrite8(FILE *file, unsigned data); void fwritele16(FILE *file, unsigned data); void fwritele32(FILE *file, unsigned data); int main(int argc, char **argv) { - FILE *datafile, *listfile; - int c; - if (argc < 3) { printf("Usage: DATAFILE \n\n" @@ -46,36 +42,36 @@ int main(int argc, char **argv) "fonts.spr\n"); return 0; } - listfile = fopen(argv[2], "rt"); + FILE *listfile = std::fopen(argv[2], "rt"); if (!listfile) { printf("ERROR: Couldn't open filelist.\n"); return 1; } - datafile = fopen(argv[1], "wb"); + FILE *datafile = std::fopen(argv[1], "wb"); if (!datafile) { printf("ERROR: Couldn't create datafile.\n"); - fclose(listfile); + std::fclose(listfile); return 1; } - memset(&header[0], 0, MAXFILES * sizeof(HEADER)); + std::memset(&header[0], 0, MAXFILES * sizeof(HEADER)); // Get names from list for (;;) { char searchname[64]; - int d; FILE *test; - if (fscanf(listfile, "%63s", searchname) == EOF) break; - test = fopen(searchname, "rb"); + if (std::fscanf(listfile, "%63s", searchname) == EOF) break; + test = std::fopen(searchname, "rb"); if (test) { - fclose(test); + std::fclose(test); - strcpy(fullname[files], searchname); + std::strcpy(fullname[files], searchname); - for (c = strlen(fullname[files]) - 1; c >= 0; c--) + int c; + for (c = std::strlen(fullname[files]) - 1; c >= 0; c--) { if (fullname[files][c] == '\\') { @@ -84,8 +80,8 @@ int main(int argc, char **argv) } } if (c < 0) c = 0; - memset(header[files].name, 0, 13); - d = 0; + std::memset(header[files].name, 0, 13); + int d = 0; while (fullname[files][c]) { header[files].name[d] = toupper(fullname[files][c]); @@ -98,69 +94,66 @@ int main(int argc, char **argv) if (files == MAXFILES) break; } - fclose(listfile); + std::fclose(listfile); // Write datafile header - fwrite("DAT!", 4, 1, datafile); + std::fwrite("DAT!", 4, 1, datafile); fwritele32(datafile, files); // Write incomplete fileheaders - for (c = 0; c < files; c++) + for (int c = 0; c < files; c++) { fwritele32(datafile, header[c].offset); fwritele32(datafile, header[c].length); - fwrite(header[c].name, 13, 1, datafile); + std::fwrite(header[c].name, 13, 1, datafile); } // Process each file - for (c = 0; c < files; c++) + for (int c = 0; c < files; c++) { printf("Adding %s...\n", header[c].name); if (!addfile(&header[c], datafile, fullname[c])) { printf("Terminating & deleting datafile...\n"); - fclose(datafile); + std::fclose(datafile); remove(argv[1]); return 1; } } // Seek back to start & write correct headers - fseek(datafile, sizeof files + 4, SEEK_SET); - for (c = 0; c < files; c++) + std::fseek(datafile, sizeof files + 4, SEEK_SET); + for (int c = 0; c < files; c++) { fwritele32(datafile, header[c].offset); fwritele32(datafile, header[c].length); - fwrite(header[c].name, 13, 1, datafile); + std::fwrite(header[c].name, 13, 1, datafile); } - fclose(datafile); + std::fclose(datafile); printf("Everything OK!\n"); return 0; } -int addfile(HEADER *header, FILE *dest, char *name) +bool addfile(HEADER *header, FILE *dest, char *name) { - FILE *src; - unsigned char *originalbuf; - - src = fopen(name, "rb"); + FILE *src = std::fopen(name, "rb"); if (!src) { printf("ERROR: Couldn't open file %s\n", name); - return 0; + return false; } - header->offset = ftell(dest); - fseek(src, 0, SEEK_END); - header->length = ftell(src); - fseek(src, 0, SEEK_SET); - originalbuf = malloc(header->length); + header->offset = std::ftell(dest); + std::fseek(src, 0, SEEK_END); + header->length = std::ftell(src); + std::fseek(src, 0, SEEK_SET); + unsigned char *originalbuf = (unsigned char*)std::malloc(header->length); if (!originalbuf) { printf("ERROR: No memory to load file!\n"); fclose(src); - return 0; + return false; } printf("* Loading file\n"); - fread(originalbuf, header->length, 1, src); - fclose(src); + std::fread(originalbuf, header->length, 1, src); + std::fclose(src); printf("* Writing file (size was %d)\n", header->length); - fwrite(originalbuf, header->length, 1, dest); - free(originalbuf); - return 1; + std::fwrite(originalbuf, header->length, 1, dest); + std::free(originalbuf); + return true; } From 19e1cb2aa75b59b2eb9b47470cde4209291626d3 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 7 Jul 2026 20:56:27 +0200 Subject: [PATCH 37/39] Update --- CMakeLists.txt | 6 +- src/bme/bme_end.h | 2 + src/{ins2snd2.c => ins2snd2.cpp} | 70 ++++++++++---------- src/{mod2sng.c => mod2sng.cpp} | 61 +++++++++-------- src/{sngspli2.c => sngspli2.cpp} | 110 ++++++++++++++----------------- 5 files changed, 120 insertions(+), 129 deletions(-) rename src/{ins2snd2.c => ins2snd2.cpp} (81%) rename src/{mod2sng.c => mod2sng.cpp} (88%) rename src/{sngspli2.c => sngspli2.cpp} (86%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8272549..587b4bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,15 +62,15 @@ if(MINGW) endif(MINGW) set(MOD2SNG_SOURCES - src/mod2sng.c + src/mod2sng.cpp src/bme/bme_end.cpp) set(INS2SND2_SOURCES - src/ins2snd2.c + src/ins2snd2.cpp src/bme/bme_end.cpp) set(SNGSPLI2_SOURCES - src/sngspli2.c + src/sngspli2.cpp src/bme/bme_end.cpp) include_directories(${CMAKE_SOURCE_DIR}/src) diff --git a/src/bme/bme_end.h b/src/bme/bme_end.h index 1854f13..d8be70b 100644 --- a/src/bme/bme_end.h +++ b/src/bme/bme_end.h @@ -2,6 +2,8 @@ #ifndef BME_END_H #define BME_END_H +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/ins2snd2.c b/src/ins2snd2.cpp similarity index 81% rename from src/ins2snd2.c rename to src/ins2snd2.cpp index b2a05f3..4233a2b 100644 --- a/src/ins2snd2.c +++ b/src/ins2snd2.cpp @@ -2,13 +2,14 @@ * GoatTracker V2.0 Instrument -> Sound effect convertor */ -#include -#include -#include -#include #include "bme_end.h" #include "common.h" +#include +#include +#include +#include + unsigned char swapnybbles(unsigned char n); void outputbyte(unsigned char c); @@ -20,7 +21,6 @@ FILE *out; int main(int argc, char **argv) { - int c,d; int prevwave = 0xff; int currwave = 0; int fileok = 0; @@ -54,11 +54,11 @@ int main(int argc, char **argv) if (argc > 3) { - for (c = 3; c < argc; c++) + for (int c = 3; c < argc; c++) { if (((argv[c][0] == '-') || (argv[c][0] == '/')) && (strlen(argv[c]) > 1)) { - int ch = tolower(argv[c][1]); + int ch = std::tolower(argv[c][1]); switch(ch) { case 'b': @@ -74,19 +74,19 @@ int main(int argc, char **argv) } - handle = fopen(argv[1], "rb"); + handle = std::fopen(argv[1], "rb"); if (!handle) { printf("ERROR: Can't open instrumentfile\n"); return EXIT_FAILURE; } - memset(wavetable, 0, MAX_TABLELEN*2); - memset(pulsetable, 0, MAX_TABLELEN*2); - memset(filttable, 0, MAX_TABLELEN*2); + std::memset(wavetable, 0, MAX_TABLELEN*2); + std::memset(pulsetable, 0, MAX_TABLELEN*2); + std::memset(filttable, 0, MAX_TABLELEN*2); - fread(ident, 4, 1, handle); - if (!memcmp(ident, "GTI!", 4)) + std::fread(ident, 4, 1, handle); + if (!std::memcmp(ident, "GTI!", 4)) { fileok = 1; instr.ad = fread8(handle); @@ -97,10 +97,10 @@ int main(int argc, char **argv) fread8(handle); // Throw away pulse limit high fread8(handle); // Throw away filtersetting wavelen = fread8(handle); - fread(&instr.name, MAX_INSTRNAMELEN, 1, handle); - fread(wavetable, wavelen, 1, handle); + std::fread(&instr.name, MAX_INSTRNAMELEN, 1, handle); + std::fread(wavetable, wavelen, 1, handle); } - if (!memcmp(ident, "GTI2", 4)) + if (!std::memcmp(ident, "GTI2", 4)) { fileok = 1; instr.ad = fread8(handle); @@ -114,23 +114,23 @@ int main(int argc, char **argv) instr.firstwave = fread8(handle); fread(&instr.name, MAX_INSTRNAMELEN, 1, handle); wavelen = fread8(handle); - for (c = 0; c < wavelen; c++) + for (int c = 0; c < wavelen; c++) wavetable[c*2] = fread8(handle); - for (c = 0; c < wavelen; c++) + for (int c = 0; c < wavelen; c++) wavetable[c*2+1] = fread8(handle); pulselen = fread8(handle); - for (c = 0; c < pulselen; c++) + for (int c = 0; c < pulselen; c++) pulsetable[c*2] = fread8(handle); - for (c = 0; c < pulselen; c++) + for (int c = 0; c < pulselen; c++) pulsetable[c*2+1] = fread8(handle); filtlen = fread8(handle); - for (c = 0; c < filtlen; c++) + for (int c = 0; c < filtlen; c++) filttable[c*2] = fread8(handle); - for (c = 0; c < filtlen; c++) + for (int c = 0; c < filtlen; c++) filttable[c*2+1] = fread8(handle); pulse = (pulsetable[0] << 4) | (pulsetable[1] >> 4); } - if ((!memcmp(ident, "GTI3", 4)) || (!memcmp(ident, "GTI4", 4) || (!memcmp(ident, "GTI5", 4)))) + if ((!std::memcmp(ident, "GTI3", 4)) || (!std::memcmp(ident, "GTI4", 4) || (!std::memcmp(ident, "GTI5", 4)))) { fileok = 1; instr.ad = fread8(handle); @@ -142,25 +142,25 @@ int main(int argc, char **argv) instr.vibdelay = fread8(handle); instr.gatetimer = fread8(handle); instr.firstwave = fread8(handle); - fread(&instr.name, MAX_INSTRNAMELEN, 1, handle); + std::fread(&instr.name, MAX_INSTRNAMELEN, 1, handle); wavelen = fread8(handle); - for (c = 0; c < wavelen; c++) + for (int c = 0; c < wavelen; c++) wavetable[c*2] = fread8(handle); - for (c = 0; c < wavelen; c++) + for (int c = 0; c < wavelen; c++) wavetable[c*2+1] = fread8(handle); pulselen = fread8(handle); - for (c = 0; c < pulselen; c++) + for (int c = 0; c < pulselen; c++) pulsetable[c*2] = fread8(handle); - for (c = 0; c < pulselen; c++) + for (int c = 0; c < pulselen; c++) pulsetable[c*2+1] = fread8(handle); filtlen = fread8(handle); - for (c = 0; c < filtlen; c++) + for (int c = 0; c < filtlen; c++) filttable[c*2] = fread8(handle); - for (c = 0; c < filtlen; c++) + for (int c = 0; c < filtlen; c++) filttable[c*2+1] = fread8(handle); pulse = (pulsetable[0] << 4) | (pulsetable[1] >> 4); } - fclose(handle); + std::fclose(handle); if (!fileok) { printf("ERROR: File is not a GoatTracker instrument!\n"); @@ -178,7 +178,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - d = 0; + int d = 0; outputbyte(instr.ad); d++; outputbyte(instr.sr); @@ -186,7 +186,7 @@ int main(int argc, char **argv) outputbyte(swapnybbles(pulse)); d++; - for (c = 0; c < MAX_TABLELEN; c++) + for (int c = 0; c < MAX_TABLELEN; c++) { if (wavetable[c*2] == 0xff) { @@ -221,11 +221,11 @@ int main(int argc, char **argv) } if (d > 255) { - fclose(out); + std::fclose(out); printf("ERROR: Sound effect exceeds 255 bytes\n"); return EXIT_FAILURE; } - fclose(out); + std::fclose(out); return EXIT_SUCCESS; } diff --git a/src/mod2sng.c b/src/mod2sng.cpp similarity index 88% rename from src/mod2sng.c rename to src/mod2sng.cpp index 492c31a..579a571 100644 --- a/src/mod2sng.c +++ b/src/mod2sng.cpp @@ -3,11 +3,12 @@ * Dedicated to T.M.R! */ -#include -#include -#include #include "bme_end.h" +#include +#include +#include + typedef struct { unsigned char note; @@ -65,7 +66,6 @@ int goatpatt = 0; int main(int argc, char **argv) { FILE *in, *out; - int c, d; unsigned char *srcptr; NOTE *destptr; @@ -78,58 +78,58 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - in = fopen(argv[1], "rb"); + in = std::fopen(argv[1], "rb"); if (!in) { printf("Source open error.\n"); return EXIT_FAILURE; } - out = fopen(argv[2], "wb"); + out = std::fopen(argv[2], "wb"); if (!out) { printf("Destination open error.\n"); - fclose(in); + std::fclose(in); return EXIT_FAILURE; } if (argc > 3) { - sscanf(argv[3], "%d", &leaveout); + std::sscanf(argv[3], "%d", &leaveout); leaveout--; if ((leaveout < 0) || (leaveout > 3)) { printf("Illegal channel number.\n"); - fclose(in); - fclose(out); + std::fclose(in); + std::fclose(out); return EXIT_FAILURE; } } if (argc > 4) { - sscanf(argv[4], "%d", &transpose); + std::sscanf(argv[4], "%d", &transpose); } - for (c = 0; c < 1084; c++) + for (int c = 0; c < 1084; c++) { modheader[c] = fread8(in); } orderlen = modheader[950]; - for (c = 0; c < 128; c++) + for (int c = 0; c < 128; c++) { if (modheader[952+c] > maxpatt) maxpatt = modheader[952+c]; } maxpatt++; - for (c = 0; c < maxpatt * 1024; c++) + for (int c = 0; c < maxpatt * 1024; c++) { modpatterns[c] = fread8(in); } - fclose(in); + std::fclose(in); // Convert patterns into easier-to-read format destptr = modnotes; srcptr = modpatterns; - for (c = 0; c < maxpatt * 256; c++) + for (int c = 0; c < maxpatt * 256; c++) { // Note: FT2 saves the 13th bit of period into 5th bit of // samplenumber, and when loading it ofcourse cannot read @@ -162,11 +162,11 @@ int main(int argc, char **argv) } // Convert patterns into goatpatterns, and create orderlists - for (c = 0; c < 4; c++) + for (int c = 0; c < 4; c++) { if (c != leaveout) { - for (d = 0; d < orderlen; d++) + for (int d = 0; d < orderlen; d++) { int patt = modheader[952+d]; int e = 0; @@ -252,13 +252,12 @@ int main(int argc, char **argv) // No same pattern pattern if (e == goatpatt) { - int f; if (goatpatt >= 208) { printf("208 patterns exceeded!\n"); return EXIT_FAILURE; } - for (f = 0; f < 65; f++) + for (int f = 0; f < 65; f++) { goatnotes[goatpatt][f].note = tempnotes[f].note; goatnotes[goatpatt][f].command = tempnotes[f].command; @@ -271,17 +270,17 @@ int main(int argc, char **argv) goatchan++; } } - fwrite(ident, 4, 1, out); // Ident - fwrite(&modheader[0], 20, 1, out); // Infotexts - fwrite(zeroarray, 12, 1, out); - fwrite(zeroarray, 32, 1, out); - fwrite(zeroarray, 32, 1, out); + std::fwrite(ident, 4, 1, out); // Ident + std::fwrite(&modheader[0], 20, 1, out); // Infotexts + std::fwrite(zeroarray, 12, 1, out); + std::fwrite(zeroarray, 32, 1, out); + std::fwrite(zeroarray, 32, 1, out); fwrite8(out, 1); // Number of songs // Orderlist - for (c = 0; c < 3; c++) + for (int c = 0; c < 3; c++) { fwrite8(out, orderlen+1); - for (d = 0; d < orderlen; d++) + for (int d = 0; d < orderlen; d++) { fwrite8(out, orderlist[c][d]); } @@ -289,7 +288,7 @@ int main(int argc, char **argv) fwrite8(out, 0x0); // From beginning } // Instruments - for (c = 1; c < 32; c++) + for (int c = 1; c < 32; c++) { fwrite8(out, 0); fwrite8(out, 0); @@ -306,17 +305,17 @@ int main(int argc, char **argv) } // Patterns fwrite8(out, goatpatt); - for (c = 0; c < goatpatt; c++) + for (int c = 0; c < goatpatt; c++) { fwrite8(out, 65*3); - for (d = 0; d < 65; d++) + for (int d = 0; d < 65; d++) { fwrite8(out, goatnotes[c][d].note); fwrite8(out, goatnotes[c][d].command); fwrite8(out, goatnotes[c][d].data); } } - fclose(out); + std::fclose(out); printf("Converted successfully.\n"); return EXIT_SUCCESS; } diff --git a/src/sngspli2.c b/src/sngspli2.cpp similarity index 86% rename from src/sngspli2.c rename to src/sngspli2.cpp index aa88b43..22e52a5 100644 --- a/src/sngspli2.c +++ b/src/sngspli2.cpp @@ -2,13 +2,14 @@ * GoatTracker V2.xx pattern splitter */ -#include -#include -#include -#include #include "bme_end.h" #include "common.h" +#include +#include +#include +#include + #define MAX_SPLITS 16 INSTR instr[MAX_INSTR]; @@ -58,7 +59,7 @@ int main(int argc, char **argv) "Default length is 16.\n"); return EXIT_FAILURE; } - if (!strcmp(argv[1], argv[2])) + if (!std::strcmp(argv[1], argv[2])) { printf("ERROR: Source and destination are not allowed to be the same."); return EXIT_FAILURE; @@ -66,7 +67,7 @@ int main(int argc, char **argv) if (argc >= 4) { - sscanf(argv[3], "%d", &targetlen); + std::sscanf(argv[3], "%d", &targetlen); if (targetlen < 1) targetlen = 1; if (targetlen > MAX_PATTROWS) targetlen = MAX_PATTROWS; } @@ -90,28 +91,27 @@ int main(int argc, char **argv) int processsong(void) { - int c,d,e; int splitsize; int songs; int dsl; dp = 0; // Destination patterns - for (c = 0; c <= highestusedpattern; c++) + for (int c = 0; c <= highestusedpattern; c++) { destpattsplits[c] = 0; splitsize = targetlen; while (pattlen[c] / splitsize > MAX_SPLITS) splitsize *= 2; if (pattlen[c] <= splitsize) splitsize = pattlen[c]; - d = 0; + int d = 0; while (d < pattlen[c]) { int remain = pattlen[c] - d; int splitfound = 0; // Check existing patterns for matches - for (e = 0; e < dp; e++) + for (int e = 0; e < dp; e++) { if ((destpattlen[e] <= remain) && (destpattlen[e] >= splitsize) && (!memcmp(&pattern[c][d*4], destpattern[e], destpattlen[e]*4))) { @@ -169,7 +169,7 @@ int processsong(void) // Now convert all songs // Determine amount of songs to be processed - c = 0; + int c = 0; for (;;) { if (c == MAX_SONGS) break; @@ -180,12 +180,12 @@ int processsong(void) } songs = c; - for (c = 0; c < songs; c++) + for (int c = 0; c < songs; c++) { - for (d = 0; d < MAX_CHN; d++) + for (int d = 0; d < MAX_CHN; d++) { dsl = 0; - for (e = 0; e <= songlen[c][d]+1; e++) + for (int e = 0; e <= songlen[c][d]+1; e++) { int pattnum = songorder[c][d][e]; @@ -239,23 +239,23 @@ int processsong(void) int destpatttbl = 0, destpatt = 0, destsong = 0; int srcpatttbl = 0, srcpatt = 0, srcsong = 0; - for (c = 0; c < MAX_SONGS; c++) + for (int c = 0; c < MAX_SONGS; c++) { if ((songlen[c][0]) && (songlen[c][1]) && (songlen[c][2])) { - for (d = 0; d < MAX_CHN; d++) + for (int d = 0; d < MAX_CHN; d++) { srcsong += songlen[c][d]+1; destsong += destsonglen[c][d]+1; } } } - for (c = 0; c < highestusedpattern; c++) + for (int c = 0; c < highestusedpattern; c++) { srcpatt += pattlen[c]*4 + 4; srcpatttbl += 2; } - for (c = 0; c < dp; c++) + for (int c = 0; c < dp; c++) { destpatt += destpattlen[c]*4 + 4; destpatttbl += 2; @@ -272,8 +272,6 @@ int processsong(void) int loadsong(char *name) { - int c; - FILE *srchandle = fopen(name, "rb"); if (srchandle) { @@ -285,7 +283,6 @@ int loadsong(char *name) if (tables) { - int d; unsigned char length; unsigned char amount; int loadbytes; @@ -298,9 +295,9 @@ int loadsong(char *name) // Read songorderlists amount = fread8(srchandle); - for (d = 0; d < amount; d++) + for (int d = 0; d < amount; d++) { - for (c = 0; c < MAX_CHN; c++) + for (int c = 0; c < MAX_CHN; c++) { length = fread8(srchandle); loadbytes = length; @@ -310,7 +307,7 @@ int loadsong(char *name) } // Read instruments highestusedinstr = fread8(srchandle); - for (c = 1; c <= highestusedinstr; c++) + for (int c = 1; c <= highestusedinstr; c++) { instr[c].ad = fread8(srchandle); instr[c].sr = fread8(srchandle); @@ -324,7 +321,7 @@ int loadsong(char *name) fread(&instr[c].name, MAX_INSTRNAMELEN, 1, srchandle); } // Read tables - for (c = 0; c < tables; c++) + for (int c = 0; c < tables; c++) { loadbytes = fread8(srchandle); fread(ltable[c], loadbytes, 1, srchandle); @@ -332,7 +329,7 @@ int loadsong(char *name) } // Read patterns amount = fread8(srchandle); - for (c = 0; c < amount; c++) + for (int c = 0; c < amount; c++) { length = fread8(srchandle); fread(pattern[c], length*4, 1, srchandle); @@ -349,12 +346,10 @@ int loadsong(char *name) int savesong(char *name) { FILE *handle; - int c; handle = fopen(name, "wb"); if (handle) { - int d; unsigned char length; unsigned char amount; int writebytes; @@ -368,7 +363,7 @@ int savesong(char *name) fwrite(copyrightname, sizeof copyrightname, 1, handle); // Determine amount of songs to be saved - c = 0; + int c = 0; for (;;) { if (c == MAX_SONGS) break; @@ -381,9 +376,9 @@ int savesong(char *name) fwrite8(handle, amount); // Write songorderlists - for (d = 0; d < amount; d++) + for (int d = 0; d < amount; d++) { - for (c = 0; c < MAX_CHN; c++) + for (int c = 0; c < MAX_CHN; c++) { length = destsonglen[d][c]+1; fwrite8(handle, length); @@ -433,21 +428,21 @@ int savesong(char *name) void countpatternlengths(void) { - int c, d, e; - highestusedpattern = 0; - for (c = 0; c < MAX_PATT; c++) + for (int c = 0; c < MAX_PATT; c++) { + int d; for (d = 0; d <= MAX_PATTROWS; d++) { if (pattern[c][d*4] == ENDPATT) break; } pattlen[c] = d; } - for (e = 0; e < MAX_SONGS; e++) + for (int e = 0; e < MAX_SONGS; e++) { - for (c = 0; c < MAX_CHN; c++) + for (int c = 0; c < MAX_CHN; c++) { + int d; for (d = 0; d < MAX_SONGLEN; d++) { if (songorder[e][c][d] >= LOOPSONG) break; @@ -464,20 +459,20 @@ void countpatternlengths(void) void countdestpatternlengths(void) { - int c, d, e; - - for (c = 0; c < MAX_PATT; c++) + for (int c = 0; c < MAX_PATT; c++) { + int d; for (d = 0; d <= MAX_PATTROWS; d++) { if (destpattern[c][d*4] == ENDPATT) break; } destpattlen[c] = d; } - for (e = 0; e < MAX_SONGS; e++) + for (int e = 0; e < MAX_SONGS; e++) { - for (c = 0; c < MAX_CHN; c++) + for (int c = 0; c < MAX_CHN; c++) { + int d; for (d = 0; d < MAX_SONGLEN; d++) { if (destsongorder[e][c][d] >= LOOPSONG) break; @@ -489,17 +484,14 @@ void countdestpatternlengths(void) void clearsong(void) { - int c; - - for (c = 0; c < MAX_CHN; c++) + for (int c = 0; c < MAX_CHN; c++) { - int d; - for (d = 0; d < MAX_SONGS; d++) + for (int d = 0; d < MAX_SONGS; d++) { destsonglen[d][c] = 0; destsongorder[d][c][0] = LOOPSONG; - memset(&songorder[d][c][0], 0, MAX_SONGLEN); + std::memset(&songorder[d][c][0], 0, MAX_SONGLEN); if (!d) { songorder[d][c][0] = c; @@ -513,23 +505,22 @@ void clearsong(void) } } } - memset(songname, 0, sizeof songname); - memset(authorname, 0, sizeof authorname); - memset(copyrightname, 0, sizeof copyrightname); + std::memset(songname, 0, sizeof songname); + std::memset(authorname, 0, sizeof authorname); + std::memset(copyrightname, 0, sizeof copyrightname); - for (c = 0; c < MAX_PATT; c++) + for (int c = 0; c < MAX_PATT; c++) { - int d; - memset(&pattern[c][0], 0, MAX_PATTROWS*4); - for (d = 0; d < MAX_PATTROWS; d++) pattern[c][d*4] = REST; - for (d = MAX_PATTROWS; d <= MAX_PATTROWS; d++) pattern[c][d*4] = ENDPATT; + std::memset(&pattern[c][0], 0, MAX_PATTROWS*4); + for (int d = 0; d < MAX_PATTROWS; d++) pattern[c][d*4] = REST; + for (int d = MAX_PATTROWS; d <= MAX_PATTROWS; d++) pattern[c][d*4] = ENDPATT; } - for (c = 0; c < MAX_INSTR; c++) + for (int c = 0; c < MAX_INSTR; c++) { - memset(&instr[c], 0, sizeof(INSTR)); + std::memset(&instr[c], 0, sizeof(INSTR)); } - memset(ltable, 0, sizeof ltable); - memset(rtable, 0, sizeof rtable); + std::memset(ltable, 0, sizeof ltable); + std::memset(rtable, 0, sizeof rtable); countpatternlengths(); } @@ -537,7 +528,6 @@ void clearsong(void) int gettablelen(int num) { int c; - for (c = MAX_TABLELEN-1; c >= 0; c--) { if (ltable[num][c] | rtable[num][c]) break; From 7508b310cdb15806587fb6a9101f03cdb79bc5cf Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Wed, 8 Jul 2026 08:11:36 +0200 Subject: [PATCH 38/39] Update --- src/bme/bme_snd.cpp | 6 +++--- src/bme/bme_win.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bme/bme_snd.cpp b/src/bme/bme_snd.cpp index 58fb6f7..134692f 100644 --- a/src/bme/bme_snd.cpp +++ b/src/bme/bme_snd.cpp @@ -2,9 +2,9 @@ // BME (Blasphemous Multimedia Engine) sound main module // -#include -#include -#include +#include +#include +#include #ifdef USE_JACK # include diff --git a/src/bme/bme_win.cpp b/src/bme/bme_win.cpp index b1620c3..9875af7 100644 --- a/src/bme/bme_win.cpp +++ b/src/bme/bme_win.cpp @@ -44,8 +44,8 @@ unsigned char win_keystate[SDL_SCANCODE_COUNT] = {0}; // Static variables -static int win_lasttime = 0; -static int win_currenttime = 0; +static Uint64 win_lasttime = 0; +static Uint64 win_currenttime = 0; static int win_framecounter = 0; static int win_activateclick = 0; From 4ec0fb4df79d8d47b165631d86adc8851685eff1 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Wed, 8 Jul 2026 08:39:00 +0200 Subject: [PATCH 39/39] Update --- CMakeLists.txt | 1 - src/bme/bme.h | 1 - src/bme/bme_gfx.cpp | 118 +++++++++++++++++++------------------------- src/bme/bme_gfx.h | 9 ++-- src/bme/bme_main.h | 2 - src/bme/bme_mou.cpp | 44 ----------------- src/bme/bme_mou.h | 18 ------- src/bme/bme_snd.cpp | 69 +++++++++++++------------- src/bme/bme_snd.h | 2 +- src/bme/bme_win.cpp | 25 +++++++++- src/bme/bme_win.h | 3 ++ 11 files changed, 116 insertions(+), 176 deletions(-) delete mode 100644 src/bme/bme_mou.cpp delete mode 100644 src/bme/bme_mou.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 587b4bb..6b78c4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,6 @@ set(LOADTRK_SOURCES src/bme/bme_gfx.cpp src/bme/bme_snd.cpp src/bme/bme_win.cpp - src/bme/bme_mou.cpp src/bme/bme_io.cpp src/bme/bme_end.cpp src/bme/bme.cpp diff --git a/src/bme/bme.h b/src/bme/bme.h index 72aa8ca..39588fd 100644 --- a/src/bme/bme.h +++ b/src/bme/bme.h @@ -12,7 +12,6 @@ extern "C" { #include "bme_snd.h" #include "bme_gfx.h" #include "bme_win.h" -#include "bme_mou.h" #include "bme_io.h" #include "bme_end.h" diff --git a/src/bme/bme_gfx.cpp b/src/bme/bme_gfx.cpp index 2b59f13..11ef362 100644 --- a/src/bme/bme_gfx.cpp +++ b/src/bme/bme_gfx.cpp @@ -19,18 +19,18 @@ extern "C" { // Prototypes -int gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags); +bool gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags); int gfx_reinit(); void gfx_uninit(); -int gfx_lock(); +bool gfx_lock(); void gfx_unlock(); void gfx_flip(); void gfx_setclipregion(unsigned left, unsigned top, unsigned right, unsigned bottom); void gfx_setmaxspritefiles(unsigned num); -int gfx_loadpalette(const char *name); +bool gfx_loadpalette(const char *name); void gfx_calcpalette(int fade, int radd, int gadd, int badd); void gfx_setpalette(); -int gfx_loadsprites(unsigned num, const char *name); +bool gfx_loadsprites(unsigned num, const char *name); void gfx_freesprites(unsigned num); void gfx_drawsprite(int x, int y, unsigned num); @@ -39,7 +39,6 @@ void gfx_getspriteinfo(unsigned num); bool gfx_initted = false; bool gfx_redraw = false; int gfx_scanlinemode = 0; -int gfx_preventswitch = 0; unsigned gfx_virtualxsize; unsigned gfx_virtualysize; unsigned gfx_windowxsize; @@ -57,7 +56,7 @@ SDL_Renderer *gfx_renderer = NULL; // Static variables -static int gfx_initexec = 0; +static bool gfx_initexec = false; static unsigned gfx_last_xsize; static unsigned gfx_last_ysize; static unsigned gfx_last_framerate; @@ -72,14 +71,14 @@ static SPRITEHEADER **gfx_spriteheaders = NULL; static Uint8 **gfx_spritedata = NULL; static unsigned *gfx_spriteamount = NULL; static SDL_Color gfx_sdlpalette[MAX_COLORS]; -static int gfx_locked = 0; +static bool gfx_locked = false; static SDL_Texture *sdlTexture = NULL; -int gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags) +bool gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags) { // Prevent re-entry (by window procedure) - if (gfx_initexec) return BME_OK; - gfx_initexec = 1; + if (gfx_initexec) return true; + gfx_initexec = true; gfx_last_xsize = xsize; gfx_last_ysize = ysize; @@ -90,9 +89,6 @@ int gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags) gfx_scanlinemode = flags & (GFX_SCANLINES | GFX_DOUBLESIZE); - if (flags & GFX_NOSWITCHING) gfx_preventswitch = 1; - else gfx_preventswitch = 0; - SDL_SetWindowFullscreen(win_window, win_fullscreen); // Calculate virtual window size @@ -104,10 +100,10 @@ int gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags) if ((!gfx_virtualxsize) || (!gfx_virtualysize)) { - gfx_initexec = 0; + gfx_initexec = false; gfx_uninit(); bme_error = BME_ILLEGAL_CONFIG; - return BME_ERROR; + return false; } // Calculate actual window size (for scanline mode & doublesize mode @@ -140,16 +136,16 @@ int gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags) SDL_TEXTUREACCESS_STREAMING, xsize, ysize); - gfx_initexec = 0; + gfx_initexec = false; if (gfx_screen) { gfx_initted = true; gfx_redraw = true; gfx_setpalette(); win_setmousemode(win_mousemode); - return BME_OK; + return true; } - else return BME_ERROR; + else return false; } int gfx_reinit() @@ -168,16 +164,16 @@ void gfx_uninit() return; } -int gfx_lock() +bool gfx_lock() { - if (gfx_locked) return 1; - if (!gfx_initted) return 0; + if (gfx_locked) return true; + if (!gfx_initted) return false; if (SDL_LockSurface(gfx_screen)) { - gfx_locked = 1; - return 1; + gfx_locked = true; + return true; } - else return 0; + else return false; } void gfx_unlock() @@ -185,7 +181,7 @@ void gfx_unlock() if (gfx_locked) { SDL_UnlockSurface(gfx_screen); - gfx_locked = 0; + gfx_locked = false; } } @@ -200,38 +196,36 @@ void gfx_flip() gfx_redraw = false; } -int gfx_loadpalette(const char *name) +bool gfx_loadpalette(const char *name) { - int handle; - - handle = io_open(name); + int handle = io_open(name); if (handle == -1) { bme_error = BME_OPEN_ERROR; - return BME_ERROR; + return false; } if (io_read(handle, gfx_palette, sizeof gfx_palette) != sizeof gfx_palette) { bme_error = BME_READ_ERROR; io_close(handle); - return BME_ERROR; + return false; } io_close(handle); gfx_calcpalette(64, 0, 0, 0); bme_error = BME_OK; - return BME_OK; + return true; } void gfx_calcpalette(int fade, int radd, int gadd, int badd) { Uint8 *sptr = &gfx_palette[3]; - int c, cl; + int cl; if (radd < 0) radd = 0; if (gadd < 0) gadd = 0; if (badd < 0) badd = 0; - for (c = 1; c < 255; c++) + for (int c = 1; c < 255; c++) { cl = *sptr; cl *= fade; @@ -309,26 +303,22 @@ void gfx_setmaxspritefiles(unsigned num) else gfx_maxspritefiles = 0; } -int gfx_loadsprites(unsigned num, const char *name) +bool gfx_loadsprites(unsigned num, const char *name) { - unsigned c; - int handle, size; - int datastart; - if (!gfx_spriteheaders) { gfx_setmaxspritefiles(1); } bme_error = BME_OPEN_ERROR; - if (num >= gfx_maxspritefiles) return BME_ERROR; + if (num >= gfx_maxspritefiles) return false; gfx_freesprites(num); - handle = io_open(name); - if (handle == -1) return BME_ERROR; + int handle = io_open(name); + if (handle == -1) return false; - size = io_lseek(handle, 0, SEEK_END); + int size = io_lseek(handle, 0, SEEK_END); io_lseek(handle, 0, SEEK_SET); gfx_spriteamount[num] = io_readle32(handle); @@ -339,10 +329,10 @@ int gfx_loadsprites(unsigned num, const char *name) { bme_error = BME_OUT_OF_MEMORY; io_close(handle); - return BME_ERROR; + return false; } - for (c = 0; c < gfx_spriteamount[num]; c++) + for (unsigned c = 0; c < gfx_spriteamount[num]; c++) { SPRITEHEADER *hptr = gfx_spriteheaders[num] + c; @@ -353,18 +343,18 @@ int gfx_loadsprites(unsigned num, const char *name) hptr->offset = io_readle32(handle); } - datastart = io_lseek(handle, 0, SEEK_CUR); + int datastart = io_lseek(handle, 0, SEEK_CUR); gfx_spritedata[num] = (Uint8*)malloc(size - datastart); if (!gfx_spritedata[num]) { bme_error = BME_OUT_OF_MEMORY; io_close(handle); - return BME_ERROR; + return false; } io_read(handle, gfx_spritedata[num], size - datastart); io_close(handle); bme_error = BME_OK; - return BME_OK; + return true; } void gfx_freesprites(unsigned num) @@ -385,24 +375,21 @@ void gfx_freesprites(unsigned num) void gfx_copyscreen8(Uint8 *destaddress, Uint8 *srcaddress, unsigned pitch) { - unsigned c; - int d; - switch(gfx_scanlinemode) { default: - for (c = 0; c < gfx_virtualysize; c++) + for (unsigned c = 0; c < gfx_virtualysize; c++) { - memcpy(destaddress, srcaddress, gfx_virtualxsize); + std::memcpy(destaddress, srcaddress, gfx_virtualxsize); destaddress += pitch; srcaddress += gfx_virtualxsize; } break; case GFX_SCANLINES: - for (c = 0; c < gfx_virtualysize; c++) + for (unsigned c = 0; c < gfx_virtualysize; c++) { - d = gfx_virtualxsize; + int d = gfx_virtualxsize; while (d--) { *destaddress = *srcaddress; @@ -416,9 +403,9 @@ void gfx_copyscreen8(Uint8 *destaddress, Uint8 *srcaddress, unsigned pitch) break; case GFX_DOUBLESIZE: - for (c = 0; c < gfx_virtualysize; c++) + for (unsigned c = 0; c < gfx_virtualysize; c++) { - d = gfx_virtualxsize; + int d = gfx_virtualxsize; while (d--) { *destaddress = *srcaddress; @@ -452,7 +439,7 @@ void gfx_getspriteinfo(unsigned num) SPRITEHEADER *hptr; if ((sprf >= gfx_maxspritefiles) || (!gfx_spriteheaders[sprf]) || - (spr >= gfx_spriteamount[sprf])) hptr = NULL; + (spr >= gfx_spriteamount[sprf])) hptr = nullptr; else hptr = gfx_spriteheaders[sprf] + spr; if (!hptr) @@ -476,10 +463,6 @@ void gfx_drawsprite(int x, int y, unsigned num) unsigned spr = (num & 0xffff) - 1; SPRITEHEADER *hptr; - Uint8 *sptr; - Uint8 *dptr; - int cx; - if (!gfx_initted) return; if (!gfx_locked) return; @@ -494,7 +477,7 @@ void gfx_drawsprite(int x, int y, unsigned num) } else hptr = gfx_spriteheaders[sprf] + spr; - sptr = gfx_spritedata[sprf] + hptr->offset; + Uint8 *sptr = gfx_spritedata[sprf] + hptr->offset; spr_xsize = hptr->xsize; spr_ysize = hptr->ysize; spr_xhotspot = hptr->xhot; @@ -526,13 +509,12 @@ void gfx_drawsprite(int x, int y, unsigned num) } while (y < gfx_clipbottom) { - int dec; - cx = x; - dptr = (Uint8*)gfx_screen->pixels + y * gfx_screen->pitch + x; + int cx = x; + Uint8 *dptr = (Uint8*)gfx_screen->pixels + y * gfx_screen->pitch + x; for (;;) { - dec = *sptr++; + int dec = *sptr++; if (dec == 255) { @@ -561,7 +543,7 @@ void gfx_drawsprite(int x, int y, unsigned num) dptr++; dec--; } - SKIP: +SKIP: cx += dec; sptr += dec; dptr += dec; diff --git a/src/bme/bme_gfx.h b/src/bme/bme_gfx.h index e0d0281..2c7c555 100644 --- a/src/bme/bme_gfx.h +++ b/src/bme/bme_gfx.h @@ -7,25 +7,24 @@ extern "C" { #endif -int gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags); +bool gfx_init(unsigned xsize, unsigned ysize, unsigned framerate, unsigned flags); int gfx_reinit(); void gfx_uninit(); -int gfx_lock(); +bool gfx_lock(); void gfx_unlock(); void gfx_flip(); void gfx_setclipregion(unsigned left, unsigned top, unsigned right, unsigned bottom); void gfx_setmaxspritefiles(unsigned num); -int gfx_loadpalette(const char *name); +bool gfx_loadpalette(const char *name); void gfx_calcpalette(int fade, int radd, int gadd, int badd); void gfx_setpalette(); -int gfx_loadsprites(unsigned num, const char *name); +bool gfx_loadsprites(unsigned num, const char *name); void gfx_drawsprite(int x, int y, unsigned num); void gfx_freesprites(unsigned num); extern bool gfx_initted; extern int gfx_scanlinemode; -extern int gfx_preventswitch; extern int gfx_fullscreen; extern bool gfx_redraw; extern unsigned gfx_windowxsize; diff --git a/src/bme/bme_main.h b/src/bme/bme_main.h index e409b9c..a4afa73 100644 --- a/src/bme/bme_main.h +++ b/src/bme/bme_main.h @@ -10,8 +10,6 @@ #define GFX_WAITVBLANK 16 #define GFX_FULLSCREEN 32 #define GFX_WINDOW 64 -#define GFX_NOSWITCHING 128 -#define GFX_USEDIBSECTION 256 #define MOUSE_ALWAYS_VISIBLE 0 #define MOUSE_FULLSCREEN_HIDDEN 1 diff --git a/src/bme/bme_mou.cpp b/src/bme/bme_mou.cpp deleted file mode 100644 index 2f6bd16..0000000 --- a/src/bme/bme_mou.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// -// BME (Blasphemous Multimedia Engine) mouse module -// - -#include "bme_main.h" -#include "bme_win.h" -#include "bme_gfx.h" -#include "bme_io.h" -#include "bme_err.h" - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -void mou_init() -{ - win_mousebuttons = 0; -} - -void mou_getpos(unsigned *x, unsigned *y) -{ - if (!gfx_initted) - { - *x = win_mousexpos; - *y = win_mouseypos; - } - else - { - *x = win_mousexpos * gfx_virtualxsize / gfx_windowxsize; - *y = win_mouseypos * gfx_virtualysize / gfx_windowysize; - } -} - -unsigned mou_getbuttons(void) -{ - return win_mousebuttons; -} - -#ifdef __cplusplus -} -#endif - diff --git a/src/bme/bme_mou.h b/src/bme/bme_mou.h deleted file mode 100644 index 8099d5e..0000000 --- a/src/bme/bme_mou.h +++ /dev/null @@ -1,18 +0,0 @@ -// BME mouse functions header file - -#ifndef BME_MOU__H -#define BME_MOU__H - -#ifdef __cplusplus -extern "C" { -#endif - -void mou_init(); -void mou_getpos(unsigned *x, unsigned *y); -unsigned mou_getbuttons(); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/bme/bme_snd.cpp b/src/bme/bme_snd.cpp index 134692f..1145557 100644 --- a/src/bme/bme_snd.cpp +++ b/src/bme/bme_snd.cpp @@ -28,13 +28,13 @@ typedef jack_default_audio_sample_t sample_t; extern "C" { // Prototypes -int snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirectsound); -void snd_uninit(void); +bool snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirectsound); +void snd_uninit(); void snd_setcustommixer(void (*custommixer)(Sint32 *dest, unsigned samples)); -static int snd_initchannels(unsigned channels); -static int snd_initmixer(void); -static void snd_uninitmixer(void); +static bool snd_initchannels(unsigned channels); +static bool snd_initmixer(); +static void snd_uninitmixer(); static void snd_mixdata(Uint8 *dest, unsigned bytes); static void snd_mixchannels(Sint32 *dest, unsigned samples); static void snd_mixer_callback(void *userdata, SDL_AudioStream *stream, int additional_amount, int total_amount); @@ -101,13 +101,13 @@ int snd_jack_process(jack_nframes_t nframes, void *arg) { return 0; } -int snd_init_jack() { +bool snd_init_jack() { jack_status_t status; client = jack_client_open("goattracker2", JackNoStartServer, &status); if (client == 0) { fprintf(stderr, "failed to create jack client\n"); - return BME_ERROR; + return false; } if (use_jack_audio) { @@ -126,7 +126,7 @@ int snd_init_jack() { { bme_error = BME_OUT_OF_MEMORY; snd_uninit(); - return BME_ERROR; + return false; } } @@ -139,17 +139,17 @@ int snd_init_jack() { if (!output_port) { fprintf(stderr, "failed to register port\n"); - return BME_ERROR; + return false; } } if (jack_activate(client)) { fprintf(stderr, "failed to activate\n"); - return BME_ERROR; + return false; } bme_error = BME_OK; - return BME_OK; + return true; } #endif @@ -192,37 +192,37 @@ void snd_midi_process(double timeStamp, const unsigned char *message, size_t mes } } -int snd_init_midi() { +bool snd_init_midi() { RtMidiInPtr midi_device = rtmidi_in_create(RTMIDI_API_UNSPECIFIED, "goattracker2", 100); if (!midi_device->ok) { fprintf(stderr, "failed to activate midi: %s\n", midi_device->msg); - return BME_ERROR; + return false; } unsigned int ports = rtmidi_get_port_count(midi_device); if (!ports) { fprintf(stderr, "no available ports\n"); - return BME_ERROR; + return false; } rtmidi_open_port(midi_device, 0, "midi_in"); if (!midi_device->ok) { fprintf(stderr, "failed to open port: %s\n", midi_device->msg); - return BME_ERROR; + return false; } rtmidi_in_set_callback(midi_device, snd_midi_process, nullptr); if (!midi_device->ok) { fprintf(stderr, "failed to set midi callback: %s\n", midi_device->msg); - return BME_ERROR; + return false; } bme_error = BME_OK; - return BME_OK; + return true; } #endif -int snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirectsound) +bool snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirectsound) { // If user wants to re-initialize, shutdown first @@ -235,7 +235,7 @@ int snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirec #ifdef USE_JACK if (use_jack) { snd_init_jack(); - if (use_jack_audio) return BME_OK; + if (use_jack_audio) return true; } #endif // Register snd_uninit as an atexit function @@ -252,7 +252,7 @@ int snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirec { bme_error = BME_ILLEGAL_CONFIG; snd_uninit(); - return BME_ERROR; + return false; } spec.freq = mixrate; @@ -274,7 +274,7 @@ int snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirec { bme_error = BME_OPEN_ERROR; snd_uninit(); - return BME_ERROR; + return false; } snd_sndinitted = true; @@ -288,8 +288,8 @@ int snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirec } // (Re)allocate channels if necessary - if (snd_initchannels(spec.channels) != BME_OK) { - return BME_ERROR; + if (!snd_initchannels(spec.channels)) { + return false; } if ((SDL_AUDIO_BITSIZE(spec.format) == 16) && @@ -310,7 +310,7 @@ int snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirec { bme_error = BME_SOUND_ERROR; snd_uninit(); - return BME_ERROR; + return false; } int sample_frames; @@ -325,15 +325,15 @@ int snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirec { bme_error = BME_OUT_OF_MEMORY; snd_uninit(); - return BME_ERROR; + return false; } SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream)); bme_error = BME_OK; - return BME_OK; + return true; } -int snd_initchannels(unsigned channels) { +bool snd_initchannels(unsigned channels) { if (snd_previouschannels != channels) { @@ -350,7 +350,7 @@ int snd_initchannels(unsigned channels) { { bme_error = BME_OUT_OF_MEMORY; snd_uninit(); - return BME_ERROR; + return false; } chptr = &snd_channel[0]; snd_channels = channels; @@ -366,7 +366,7 @@ int snd_initchannels(unsigned channels) { } } - return BME_OK; + return true; } @@ -393,7 +393,7 @@ void snd_setcustommixer(void (*custommixer)(Sint32 *dest, unsigned samples)) snd_custommixer = custommixer; } -static int snd_initmixer(void) +static bool snd_initmixer() { snd_uninitmixer(); @@ -404,12 +404,12 @@ static int snd_initmixer(void) } snd_clipbuffer = (Sint32*)std::malloc(bufSize); - if (!snd_clipbuffer) return 0; + if (!snd_clipbuffer) return false; - return 1; + return true; } -static void snd_uninitmixer(void) +static void snd_uninitmixer() { if (snd_clipbuffer) { @@ -513,9 +513,8 @@ static void snd_mixdata(Uint8 *dest, unsigned bytes) static void snd_mixchannels(Sint32 *dest, unsigned samples) { CHANNEL *chptr = &snd_channel[0]; - int c; - for (c = snd_channels; c; c--) + for (int c = snd_channels; c; c--) { snd_mixchannel(chptr, dest, samples); chptr++; diff --git a/src/bme/bme_snd.h b/src/bme/bme_snd.h index 27412d4..b7cd6f8 100644 --- a/src/bme/bme_snd.h +++ b/src/bme/bme_snd.h @@ -7,7 +7,7 @@ extern "C" { #endif -int snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirectsound); +bool snd_init(unsigned mixrate, unsigned mixmode, unsigned channels, int usedirectsound); void snd_uninit(); void snd_setcustommixer(void (*custommixer)(Sint32 *dest, unsigned samples)); diff --git a/src/bme/bme_win.cpp b/src/bme/bme_win.cpp index 9875af7..3aa9ea2 100644 --- a/src/bme/bme_win.cpp +++ b/src/bme/bme_win.cpp @@ -4,7 +4,6 @@ #include "bme_main.h" #include "bme_gfx.h" -#include "bme_mou.h" #include "bme_io.h" #include "bme_err.h" @@ -242,4 +241,28 @@ void win_setmousemode(int mode) } } +void mou_init() +{ + win_mousebuttons = 0; +} + +void mou_getpos(unsigned *x, unsigned *y) +{ + if (!gfx_initted) + { + *x = win_mousexpos; + *y = win_mouseypos; + } + else + { + *x = win_mousexpos * gfx_virtualxsize / gfx_windowxsize; + *y = win_mouseypos * gfx_virtualysize / gfx_windowysize; + } +} + +unsigned mou_getbuttons(void) +{ + return win_mousebuttons; +} + } diff --git a/src/bme/bme_win.h b/src/bme/bme_win.h index 38769f1..66ef765 100644 --- a/src/bme/bme_win.h +++ b/src/bme/bme_win.h @@ -11,6 +11,9 @@ int win_openwindow(unsigned xsize, unsigned ysize, const char *appname, char *ic void win_closewindow(void); int win_getspeed(int framerate); void win_setmousemode(int mode); +void mou_init(); +void mou_getpos(unsigned *x, unsigned *y); +unsigned mou_getbuttons(); extern int win_quitted; extern int win_fullscreen;